Skip to content

Commit da8ed5f

Browse files
committed
Support/requirement for new supportedFeatures property for devices and OSes + fix minor QML bug
Signed-off-by: paulober <[email protected]>
1 parent bd69720 commit da8ed5f

File tree

5 files changed

+56
-22
lines changed

5 files changed

+56
-22
lines changed

src/OptionsPopup.qml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Window {
3434
property string cloudinitrun
3535
property string cloudinitwrite
3636
property string cloudinitnetwork
37-
property bool deviceUsbOtgSupport
37+
property bool deviceUsbOtgSupport: false
3838
property bool enableEtherGadget
3939

4040
signal saveSettingsSignal(var settings)
@@ -637,16 +637,12 @@ Window {
637637
}
638638
}
639639

640-
var hwFilterList = imageWriter.getHWFilterList()
641-
var hwFilterIsModelZero = imageWriter.getHWFilterIsModelZero()
642-
643-
if (hwFilterList) {
644-
var targetTags = ["pi5-64bit", "pi4-64bit", "pi5-32bit", "pi4-32bit"]
645-
deviceUsbOtgSupport = targetTags.some(tag => hwFilterList.includes(tag)) || hwFilterIsModelZero
646-
if (!deviceUsbOtgSupport) {
647-
// make sure it isn't disabled and selected
648-
chkUSBEther = false;
649-
}
640+
if (imageWriter.andSupportedFeatures("ether_gadget")) {
641+
deviceUsbOtgSupport = true
642+
} else {
643+
deviceUsbOtgSupport = false
644+
// make sure it isn't disabled and selected
645+
chkUSBEther.checked = false
650646
}
651647

652648
//open()

src/imagewriter.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,21 @@ namespace {
477477
} // namespace anonymous
478478

479479

480-
void ImageWriter::setHWFilterList(const QByteArray &json, const bool &inclusive, const bool &isModelZero) {
480+
void ImageWriter::setHWFilterList(const QByteArray &json, const bool &inclusive) {
481481
QJsonDocument json_document = QJsonDocument::fromJson(json);
482482
_deviceFilter = json_document.array();
483483
_deviceFilterIsInclusive = inclusive;
484-
_isModelZero = isModelZero;
484+
}
485+
486+
void ImageWriter::setHWSupportedFeaturesList(const QByteArray &json) {
487+
QJsonDocument json_document = QJsonDocument::fromJson(json);
488+
// TODO: maybe also clear the sw supported features as in the UI the OS is unselected when this changes
489+
_hwSupportedFeatures = json_document.array();
490+
}
491+
492+
void ImageWriter::setSWSupportedFeaturesList(const QByteArray &json) {
493+
QJsonDocument json_document = QJsonDocument::fromJson(json);
494+
_swSupportedFeatures = json_document.array();
485495
}
486496

487497
QJsonArray ImageWriter::getHWFilterList() {
@@ -492,8 +502,16 @@ bool ImageWriter::getHWFilterListInclusive() {
492502
return _deviceFilterIsInclusive;
493503
}
494504

495-
bool ImageWriter::getHWFilterIsModelZero() {
496-
return _isModelZero;
505+
bool ImageWriter::andSupportedFeatures(const QString &feature) {
506+
return this->checkHWFeatureSupport(feature) && this->checkSWFeatureSupport(feature);
507+
}
508+
509+
bool ImageWriter::checkHWFeatureSupport(const QString &feature) {
510+
return _hwSupportedFeatures.contains(feature.toLower());
511+
}
512+
513+
bool ImageWriter::checkSWFeatureSupport(const QString &feature) {
514+
return _swSupportedFeatures.contains(feature.toLower());
497515
}
498516

499517
void ImageWriter::handleNetworkRequestFinished(QNetworkReply *data) {

src/imagewriter.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,28 @@ class ImageWriter : public QObject
8888
Q_INVOKABLE void beginOSListFetch();
8989

9090
/** Set the HW filter, for a filtered view of the OS list */
91-
Q_INVOKABLE void setHWFilterList(const QByteArray &json, const bool &inclusive, const bool &isModelZero);
91+
Q_INVOKABLE void setHWFilterList(const QByteArray &json, const bool &inclusive);
92+
93+
/* Set the features supported by the hardware, for a filtered view of options that require certain features beeing supported by the hardware. */
94+
Q_INVOKABLE void setHWSupportedFeaturesList(const QByteArray &json);
95+
96+
/* Set the features supported by the hardware, for a filtered view of options that require certain features beeing supported by the software. */
97+
Q_INVOKABLE void setSWSupportedFeaturesList(const QByteArray &json);
9298

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

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

99-
/* Get if HW filter tags are from a Pi Zero model */
100-
Q_INVOKABLE bool getHWFilterIsModelZero();
105+
/* Get if both hard and software support a certain feature */
106+
Q_INVOKABLE bool andSupportedFeatures(const QString &feature);
107+
108+
/* Check if the hardware supports a certain feature. */
109+
Q_INVOKABLE bool checkHWFeatureSupport(const QString &feature);
110+
111+
/* Check if the software supports a certain feature. */
112+
Q_INVOKABLE bool checkSWFeatureSupport(const QString &feature);
101113

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

204214
protected:
205215
QUrl _src, _repo;

src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ int main(int argc, char *argv[])
198198
QString customRepo;
199199
QUrl url;
200200
QStringList args = app.arguments();
201+
bool disableRepoFetch = false;
201202
for (int i=1; i < args.size(); i++)
202203
{
203204
if (!args[i].startsWith("-") && url.isEmpty())
@@ -243,6 +244,7 @@ int main(int argc, char *argv[])
243244
}
244245

245246
imageWriter.setCustomOsListUrl(QUrl::fromLocalFile(customRepo));
247+
disableRepoFetch = true;
246248
}
247249
}
248250
else if (args[i] == "--qm")

src/main.qml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ ApplicationWindow {
498498
icon: ""
499499
description: ""
500500
matching_type: "exclusive"
501+
supported_features: "[]"
501502
}
502503
}
503504
currentIndex: -1
@@ -1488,6 +1489,9 @@ ApplicationWindow {
14881489
if ("subitems" in entry) {
14891490
entry["subitems_json"] = JSON.stringify(entry["subitems"])
14901491
delete entry["subitems"]
1492+
} else if ("supportedFeatures" in entry) {
1493+
entry["supported_features_json"] = JSON.stringify(entry["supportedFeatures"])
1494+
delete entry["supportedFeatures"]
14911495
}
14921496
}
14931497

@@ -1530,6 +1534,8 @@ ApplicationWindow {
15301534
for (var j in devices)
15311535
{
15321536
devices[j]["tags"] = JSON.stringify(devices[j]["tags"])
1537+
devices[j]["supported_features"] = JSON.stringify(devices[j]["supportedFeatures"])
1538+
delete devices[j]["supportedFeatures"];
15331539
deviceModel.append(devices[j])
15341540
if ("default" in devices[j] && devices[j]["default"])
15351541
{
@@ -1614,7 +1620,8 @@ ApplicationWindow {
16141620
}
16151621
}
16161622

1617-
imageWriter.setHWFilterList(hwmodel.tags, inclusive, hwmodel.name.toLowerCase().includes("zero"))
1623+
imageWriter.setHWFilterList(hwmodel.tags, inclusive)
1624+
imageWriter.setHWSupportedFeaturesList(hwmodel.supported_features);
16181625

16191626
/* Reload list */
16201627
var oslist_json = imageWriter.getFilteredOSlist();
@@ -1731,6 +1738,7 @@ ApplicationWindow {
17311738
}
17321739
} else {
17331740
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 : "")
1741+
imageWriter.setSWSupportedFeaturesList(d.supported_features_json);
17341742
osbutton.text = d.name
17351743
ospopup.close()
17361744
osswipeview.decrementCurrentIndex()

0 commit comments

Comments
 (0)