diff --git a/src/OptionsPopup.qml b/src/OptionsPopup.qml index 3f1945a6..42ce38f0 100644 --- a/src/OptionsPopup.qml +++ b/src/OptionsPopup.qml @@ -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) @@ -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() diff --git a/src/imagewriter.cpp b/src/imagewriter.cpp index 39a55283..0909c225 100644 --- a/src/imagewriter.cpp +++ b/src/imagewriter.cpp @@ -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() { @@ -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) { diff --git a/src/imagewriter.h b/src/imagewriter.h index f17bb9f9..4cc17233 100644 --- a/src/imagewriter.h +++ b/src/imagewriter.h @@ -88,7 +88,13 @@ 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(); @@ -96,8 +102,14 @@ class ImageWriter : public QObject /* 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); @@ -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; diff --git a/src/main.qml b/src/main.qml index 6894b4a0..6afebc49 100644 --- a/src/main.qml +++ b/src/main.qml @@ -498,6 +498,7 @@ ApplicationWindow { icon: "" description: "" matching_type: "exclusive" + supported_features: "[]" } } currentIndex: -1 @@ -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"] } } @@ -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"]) { @@ -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(); @@ -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()