diff --git a/companion/src/updates/chooserdialog.cpp b/companion/src/updates/chooserdialog.cpp index 16c064b40eb..e2b876ffd5e 100644 --- a/companion/src/updates/chooserdialog.cpp +++ b/companion/src/updates/chooserdialog.cpp @@ -22,7 +22,7 @@ #include "chooserdialog.h" #include "ui_chooserdialog.h" -ChooserDialog::ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel) : +ChooserDialog::ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel, QAbstractItemView::SelectionMode mode) : QDialog(parent), ui(new Ui::ChooserDialog) { @@ -32,6 +32,7 @@ ChooserDialog::ChooserDialog(QWidget * parent, QString title, QStandardItemModel ui->listView->setModel(itemModel); ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->listView->setSelectionMode(mode); connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]() { QDialog::accept(); diff --git a/companion/src/updates/chooserdialog.h b/companion/src/updates/chooserdialog.h index e31f5c98ec7..fccb1f3e529 100644 --- a/companion/src/updates/chooserdialog.h +++ b/companion/src/updates/chooserdialog.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace Ui { class ChooserDialog; @@ -35,7 +36,8 @@ class ChooserDialog : public QDialog Q_OBJECT public: - ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel); + ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel, + QAbstractItemView::SelectionMode selMode = QAbstractItemView::SingleSelection); virtual ~ChooserDialog(); QItemSelectionModel* selectedItems(); diff --git a/companion/src/updates/chooserdialog.ui b/companion/src/updates/chooserdialog.ui index 7a43a07bbff..ea3aa64b994 100644 --- a/companion/src/updates/chooserdialog.ui +++ b/companion/src/updates/chooserdialog.ui @@ -17,7 +17,7 @@ - QAbstractItemView::MultiSelection + QAbstractItemView::SingleSelection diff --git a/companion/src/updates/updateinterface.cpp b/companion/src/updates/updateinterface.cpp index 0dcfc612c95..1695269ac50 100644 --- a/companion/src/updates/updateinterface.cpp +++ b/companion/src/updates/updateinterface.cpp @@ -472,6 +472,25 @@ bool UpdateInterface::decompress() return true; } +bool UpdateInterface::filterAssets(const UpdateParameters::AssetParams & ap) +{ + QString pattern(m_params->buildFilterPattern(ap.filterType, ap.filter)); + m_repo->assets()->setFilterPattern(pattern); + m_status->reportProgress(tr("Asset filter applied: %1 - %2 found").arg(pattern).arg(m_repo->assets()->count()), QtDebugMsg); + + if (m_repo->assets()->count() < 1) { + m_status->reportProgress(tr("No assets found in release '%1' using filter '%2'").arg(m_repo->releases()->name()).arg(pattern), QtCriticalMsg); + return false; + } + else if (ap.maxExpected > 0 && m_repo->assets()->count() > ap.maxExpected) { + m_status->reportProgress(tr("%1 assets found when %2 expected in release '%3' using filter '%4'") + .arg(m_repo->assets()->count() + 1).arg(ap.maxExpected).arg(m_repo->releases()->name().arg(pattern)), QtCriticalMsg); + return false; + } + + return true; +} + bool UpdateInterface::flagAssets() { m_status->progressMessage(tr("Flagging assets")); @@ -743,19 +762,8 @@ bool UpdateInterface::retrieveRepoJsonFile(const QString & filename, QJsonDocume bool UpdateInterface::setFilteredAssets(const UpdateParameters::AssetParams & ap) { - QString pattern(m_params->buildFilterPattern(ap.filterType, ap.filter)); - m_repo->assets()->setFilterPattern(pattern); - m_status->reportProgress(tr("Asset filter applied: %1 - %2 found").arg(pattern).arg(m_repo->assets()->count()), QtDebugMsg); - - if (m_repo->assets()->count() < 1) { - m_status->reportProgress(tr("No assets found in release '%1' using filter '%2'").arg(m_repo->releases()->name()).arg(pattern), QtCriticalMsg); + if (!filterAssets(ap)) return false; - } - else if (ap.maxExpected > 0 && m_repo->assets()->count() > ap.maxExpected) { - m_status->reportProgress(tr("%1 assets found when %2 expected in release '%3' using filter '%4'") - .arg(m_repo->assets()->count() + 1).arg(ap.maxExpected).arg(m_repo->releases()->name().arg(pattern)), QtCriticalMsg); - return false; - } for (int i = 0; i < m_repo->assets()->count(); i++) { m_repo->assets()->getSetId(i); diff --git a/companion/src/updates/updateinterface.h b/companion/src/updates/updateinterface.h index 16b905b760f..5d6421c9c32 100644 --- a/companion/src/updates/updateinterface.h +++ b/companion/src/updates/updateinterface.h @@ -113,6 +113,7 @@ class UpdateInterface : public QWidget bool decompressFlaggedAssets(); const QString downloadDir() const; bool downloadFlaggedAssets(); + bool filterAssets(const UpdateParameters::AssetParams & ap); void init(QString repo, QString nightly = "", int resultsPerPage = -1); const bool isSettingsIndexValid() const; UpdateNetwork* const network() const; diff --git a/companion/src/updates/updatesounds.cpp b/companion/src/updates/updatesounds.cpp index ee8f3f77c2d..027bc7e34ec 100644 --- a/companion/src/updates/updatesounds.cpp +++ b/companion/src/updates/updatesounds.cpp @@ -25,11 +25,12 @@ #include #include #include +#include UpdateSounds::UpdateSounds(QWidget * parent) : UpdateInterface(parent, CID_Sounds, tr("Sounds")) { - init(QString(GH_API_REPOS_EDGETX).append("/edgetx-sdcard-sounds")); + init(QString(GH_API_REPOS_EDGETX).append("/edgetx-sdcard-sounds"), "", 50); langPacks = new QStandardItemModel(); } @@ -50,7 +51,7 @@ void UpdateSounds::assetSettingsInit() cad.processes(UPDFLG_Common_Asset); cad.flags(cad.processes() | UPDFLG_CopyStructure); cad.filterType(UpdateParameters::UFT_Startswith); - cad.filter("edgetx-sdcard-sounds-%LANGUAGE%-"); + cad.filter("edgetx-sdcard-sounds-%LANGUAGE%"); qDebug() << "Asset settings initialised"; } @@ -59,69 +60,18 @@ bool UpdateSounds::flagAssets() { status()->progressMessage(tr("Processing available sounds")); - QJsonDocument *json = new QJsonDocument(); - - const QString jsonFile("sounds.json"); - - if (!retrieveAssetsJsonFile(jsonFile, json)) { - status()->reportProgress(tr("Unable to retrieve asset '%1' from release '%2'").arg(jsonFile).arg(repo()->releases()->name()), QtDebugMsg); - // assume older release where file not an asset - if (!retrieveRepoJsonFile(jsonFile, json)) { - status()->reportProgress(tr("Unable to retrieve file '%1' from repo '%2'").arg(jsonFile).arg(repo()->path()), QtCriticalMsg); - delete json; - return false; - } - } - - /* - { - "language": "en-GB", - "name": "British English Female", - "description": "British English Female Voice (en-GB-Libby)", - "directory": "en_gb-libby" - }, - */ - - // always refresh to allow for language change in radio profile + // always refresh to allow for language change in radio profile langPacks->clear(); - if (json->isArray()) { - const QJsonArray &arr = json->array(); - - foreach (const QJsonValue &v, arr) { - if (v.isObject()) { - const QJsonObject obj = v.toObject(); - QString langVariant; - QString lang; - - if (!obj.value("language").isUndefined()) { - langVariant = obj.value("language").toString(); - lang = langVariant.split("-").at(0); - } - - if (lang == params()->language) { - QStandardItem * item = new QStandardItem(); - - if (!obj.value("language").isUndefined()) - item->setData(obj.value("language").toString(), IMDR_Language); - if (!obj.value("name").isUndefined()) - item->setData(obj.value("name").toString(), IMDR_Name); - if (!obj.value("description").isUndefined()) - item->setData(obj.value("description").toString(), Qt::DisplayRole); - if (!obj.value("directory").isUndefined()) - item->setData(obj.value("directory").toString(), IMDR_Directory); - - langPacks->appendRow(item); - } - } - } - } - - delete json; - - if (langPacks->rowCount() < 1) { - status()->reportProgress(tr("Language '%1' not listed in '%2'").arg(params()->language).arg(jsonFile), QtCriticalMsg); + UpdateParameters::AssetParams ap = params()->assets[0]; + if (!filterAssets(ap)) return false; + + for (int i = 0; i < repo()->assets()->count(); i++) { + repo()->assets()->getSetId(i); + QStandardItem * item = new QStandardItem(); + item->setText(repo()->assets()->name()); + langPacks->appendRow(item); } if (langPacks->rowCount() > 1) { @@ -139,26 +89,25 @@ bool UpdateSounds::flagAssets() QModelIndexList selIndexes = selItems->selectedIndexes(); - for (int i = 0; i < selIndexes.size(); i++) { - if (!flagLanguageAsset(langPacks->data(selIndexes.at(i), IMDR_Directory).toString())) - return false; - } + if (!flagLanguageAsset(langPacks->data(selIndexes.at(0)).toString())) + return false; dlg->deleteLater(); } else if (langPacks->rowCount() == 1) { - if (!flagLanguageAsset(langPacks->data(langPacks->index(0, 0), IMDR_Directory).toString())) + if (!flagLanguageAsset(langPacks->data(langPacks->index(0, 0)).toString())) return false; } return true; } -bool UpdateSounds::flagLanguageAsset(QString lang) +bool UpdateSounds::flagLanguageAsset(QString asset) { status()->progressMessage(tr("Flagging assets")); - params()->language = lang; UpdateParameters::AssetParams ap = params()->assets[0]; + ap.filter = asset; + ap.filterType = UpdateParameters::UFT_Exact; return setFilteredAssets(ap); } diff --git a/companion/src/updates/updatesounds.h b/companion/src/updates/updatesounds.h index 946275fc06e..39e42c9cfd6 100644 --- a/companion/src/updates/updatesounds.h +++ b/companion/src/updates/updatesounds.h @@ -39,13 +39,6 @@ class UpdateSounds : public UpdateInterface virtual void assetSettingsInit() override; private: - enum ItemModelDataRoles { - IMDR_Language = Qt::UserRole, - IMDR_Name, - IMDR_Directory, - }; - Q_ENUM(ItemModelDataRoles) - QStandardItemModel *langPacks; bool flagLanguageAsset(QString lang); diff --git a/companion/src/updates/updatestatus.cpp b/companion/src/updates/updatestatus.cpp index db5fc54c78e..a69ff0195df 100644 --- a/companion/src/updates/updatestatus.cpp +++ b/companion/src/updates/updatestatus.cpp @@ -36,11 +36,8 @@ void UpdateStatus::reportProgress(QString text, QtMsgType type) if (m_logLevel == QtDebugMsg || (m_logLevel == QtInfoMsg && type > QtDebugMsg) || (type < QtInfoMsg && type >= m_logLevel)) { - if (m_progress) { + if (m_progress) m_progress->addMessage(text, type); - if (m_logLevel == QtDebugMsg) - qDebug() << text; - } else qDebug() << text; }