Skip to content

Commit

Permalink
Support/requirement for new supportedFeatures property for devices an…
Browse files Browse the repository at this point in the history
…d OSes + fix minor QML bug

Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 20, 2024
1 parent bd69720 commit da8ed5f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
18 changes: 7 additions & 11 deletions src/OptionsPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Window {
property string cloudinitrun
property string cloudinitwrite
property string cloudinitnetwork
property bool deviceUsbOtgSupport
property bool deviceUsbOtgSupport: false
property bool enableEtherGadget

signal saveSettingsSignal(var settings)
Expand Down Expand Up @@ -637,16 +637,12 @@ Window {
}
}

var hwFilterList = imageWriter.getHWFilterList()
var hwFilterIsModelZero = imageWriter.getHWFilterIsModelZero()

if (hwFilterList) {
var targetTags = ["pi5-64bit", "pi4-64bit", "pi5-32bit", "pi4-32bit"]
deviceUsbOtgSupport = targetTags.some(tag => hwFilterList.includes(tag)) || hwFilterIsModelZero
if (!deviceUsbOtgSupport) {
// make sure it isn't disabled and selected
chkUSBEther = false;
}
if (imageWriter.andSupportedFeatures("ether_gadget")) {
deviceUsbOtgSupport = true
} else {
deviceUsbOtgSupport = false
// make sure it isn't disabled and selected
chkUSBEther.checked = false
}

//open()
Expand Down
26 changes: 22 additions & 4 deletions src/imagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,21 @@ namespace {
} // namespace anonymous


void ImageWriter::setHWFilterList(const QByteArray &json, const bool &inclusive, const bool &isModelZero) {
void ImageWriter::setHWFilterList(const QByteArray &json, const bool &inclusive) {
QJsonDocument json_document = QJsonDocument::fromJson(json);
_deviceFilter = json_document.array();
_deviceFilterIsInclusive = inclusive;
_isModelZero = isModelZero;
}

void ImageWriter::setHWSupportedFeaturesList(const QByteArray &json) {
QJsonDocument json_document = QJsonDocument::fromJson(json);
// TODO: maybe also clear the sw supported features as in the UI the OS is unselected when this changes
_hwSupportedFeatures = json_document.array();
}

void ImageWriter::setSWSupportedFeaturesList(const QByteArray &json) {
QJsonDocument json_document = QJsonDocument::fromJson(json);
_swSupportedFeatures = json_document.array();
}

QJsonArray ImageWriter::getHWFilterList() {
Expand All @@ -492,8 +502,16 @@ bool ImageWriter::getHWFilterListInclusive() {
return _deviceFilterIsInclusive;
}

bool ImageWriter::getHWFilterIsModelZero() {
return _isModelZero;
bool ImageWriter::andSupportedFeatures(const QString &feature) {
return this->checkHWFeatureSupport(feature) && this->checkSWFeatureSupport(feature);
}

bool ImageWriter::checkHWFeatureSupport(const QString &feature) {
return _hwSupportedFeatures.contains(feature.toLower());
}

bool ImageWriter::checkSWFeatureSupport(const QString &feature) {
return _swSupportedFeatures.contains(feature.toLower());
}

void ImageWriter::handleNetworkRequestFinished(QNetworkReply *data) {
Expand Down
22 changes: 16 additions & 6 deletions src/imagewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,28 @@ class ImageWriter : public QObject
Q_INVOKABLE void beginOSListFetch();

/** Set the HW filter, for a filtered view of the OS list */
Q_INVOKABLE void setHWFilterList(const QByteArray &json, const bool &inclusive, const bool &isModelZero);
Q_INVOKABLE void setHWFilterList(const QByteArray &json, const bool &inclusive);

/* Set the features supported by the hardware, for a filtered view of options that require certain features beeing supported by the hardware. */
Q_INVOKABLE void setHWSupportedFeaturesList(const QByteArray &json);

/* Set the features supported by the hardware, for a filtered view of options that require certain features beeing supported by the software. */
Q_INVOKABLE void setSWSupportedFeaturesList(const QByteArray &json);

/* Get the HW filter list */
Q_INVOKABLE QJsonArray getHWFilterList();

/* Get if the HW filter is in inclusive mode */
Q_INVOKABLE bool getHWFilterListInclusive();

/* Get if HW filter tags are from a Pi Zero model */
Q_INVOKABLE bool getHWFilterIsModelZero();
/* Get if both hard and software support a certain feature */
Q_INVOKABLE bool andSupportedFeatures(const QString &feature);

/* Check if the hardware supports a certain feature. */
Q_INVOKABLE bool checkHWFeatureSupport(const QString &feature);

/* Check if the software supports a certain feature. */
Q_INVOKABLE bool checkSWFeatureSupport(const QString &feature);

/* Set custom cache file */
void setCustomCacheFile(const QString &cacheFile, const QByteArray &sha256);
Expand Down Expand Up @@ -196,10 +208,8 @@ protected slots:
void fillSubLists(QJsonArray &topLevel);
QNetworkAccessManager _networkManager;
QJsonDocument _completeOsList;
QJsonArray _deviceFilter;
QJsonArray _deviceFilter, _hwSupportedFeatures, _swSupportedFeatures;
bool _deviceFilterIsInclusive;
/* As there is no distinction between normal pi models and zeros (in the tags), this flag can be used to differentiate */
bool _isModelZero;

protected:
QUrl _src, _repo;
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ int main(int argc, char *argv[])
QString customRepo;
QUrl url;
QStringList args = app.arguments();
bool disableRepoFetch = false;
for (int i=1; i < args.size(); i++)
{
if (!args[i].startsWith("-") && url.isEmpty())
Expand Down Expand Up @@ -243,6 +244,7 @@ int main(int argc, char *argv[])
}

imageWriter.setCustomOsListUrl(QUrl::fromLocalFile(customRepo));
disableRepoFetch = true;
}
}
else if (args[i] == "--qm")
Expand Down
10 changes: 9 additions & 1 deletion src/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ ApplicationWindow {
icon: ""
description: ""
matching_type: "exclusive"
supported_features: "[]"
}
}
currentIndex: -1
Expand Down Expand Up @@ -1488,6 +1489,9 @@ ApplicationWindow {
if ("subitems" in entry) {
entry["subitems_json"] = JSON.stringify(entry["subitems"])
delete entry["subitems"]
} else if ("supportedFeatures" in entry) {
entry["supported_features_json"] = JSON.stringify(entry["supportedFeatures"])
delete entry["supportedFeatures"]
}
}

Expand Down Expand Up @@ -1530,6 +1534,8 @@ ApplicationWindow {
for (var j in devices)
{
devices[j]["tags"] = JSON.stringify(devices[j]["tags"])
devices[j]["supported_features"] = JSON.stringify(devices[j]["supportedFeatures"])
delete devices[j]["supportedFeatures"];
deviceModel.append(devices[j])
if ("default" in devices[j] && devices[j]["default"])
{
Expand Down Expand Up @@ -1614,7 +1620,8 @@ ApplicationWindow {
}
}

imageWriter.setHWFilterList(hwmodel.tags, inclusive, hwmodel.name.toLowerCase().includes("zero"))
imageWriter.setHWFilterList(hwmodel.tags, inclusive)
imageWriter.setHWSupportedFeaturesList(hwmodel.supported_features);

/* Reload list */
var oslist_json = imageWriter.getFilteredOSlist();
Expand Down Expand Up @@ -1731,6 +1738,7 @@ ApplicationWindow {
}
} else {
imageWriter.setSrc(d.url, d.image_download_size, d.extract_size, typeof(d.extract_sha256) != "undefined" ? d.extract_sha256 : "", typeof(d.contains_multiple_files) != "undefined" ? d.contains_multiple_files : false, ospopup.categorySelected, d.name, typeof(d.init_format) != "undefined" ? d.init_format : "")
imageWriter.setSWSupportedFeaturesList(d.supported_features_json);
osbutton.text = d.name
ospopup.close()
osswipeview.decrementCurrentIndex()
Expand Down

0 comments on commit da8ed5f

Please sign in to comment.