fix(cpn): Selection of sound packs in update process (#3848)
* chore(cpn): increase github REST api page size for sound packs * chore(cpn): add selection mode parameter to chooser dialog * chore(cpn): remove cli debug messages when progress dialog available * chore(cpn): carve out filterAssets from setFilteredAssets and call new function * fix(cpn): refactor update sounds asset filtering * chore(cpn): move code block * fix(cpn): remove trailing hyphen from default sounds asset filter
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
#include "chooserdialog.h"
|
#include "chooserdialog.h"
|
||||||
#include "ui_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),
|
QDialog(parent),
|
||||||
ui(new Ui::ChooserDialog)
|
ui(new Ui::ChooserDialog)
|
||||||
{
|
{
|
||||||
@@ -32,6 +32,7 @@ ChooserDialog::ChooserDialog(QWidget * parent, QString title, QStandardItemModel
|
|||||||
|
|
||||||
ui->listView->setModel(itemModel);
|
ui->listView->setModel(itemModel);
|
||||||
ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
ui->listView->setSelectionMode(mode);
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]() {
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]() {
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
|
#include <QAbstractItemView>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ChooserDialog;
|
class ChooserDialog;
|
||||||
@@ -35,7 +36,8 @@ class ChooserDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel);
|
ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel,
|
||||||
|
QAbstractItemView::SelectionMode selMode = QAbstractItemView::SingleSelection);
|
||||||
virtual ~ChooserDialog();
|
virtual ~ChooserDialog();
|
||||||
|
|
||||||
QItemSelectionModel* selectedItems();
|
QItemSelectionModel* selectedItems();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="listView">
|
<widget class="QListView" name="listView">
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::MultiSelection</enum>
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -472,6 +472,25 @@ bool UpdateInterface::decompress()
|
|||||||
return true;
|
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()
|
bool UpdateInterface::flagAssets()
|
||||||
{
|
{
|
||||||
m_status->progressMessage(tr("Flagging assets"));
|
m_status->progressMessage(tr("Flagging assets"));
|
||||||
@@ -743,19 +762,8 @@ bool UpdateInterface::retrieveRepoJsonFile(const QString & filename, QJsonDocume
|
|||||||
|
|
||||||
bool UpdateInterface::setFilteredAssets(const UpdateParameters::AssetParams & ap)
|
bool UpdateInterface::setFilteredAssets(const UpdateParameters::AssetParams & ap)
|
||||||
{
|
{
|
||||||
QString pattern(m_params->buildFilterPattern(ap.filterType, ap.filter));
|
if (!filterAssets(ap))
|
||||||
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;
|
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++) {
|
for (int i = 0; i < m_repo->assets()->count(); i++) {
|
||||||
m_repo->assets()->getSetId(i);
|
m_repo->assets()->getSetId(i);
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ class UpdateInterface : public QWidget
|
|||||||
bool decompressFlaggedAssets();
|
bool decompressFlaggedAssets();
|
||||||
const QString downloadDir() const;
|
const QString downloadDir() const;
|
||||||
bool downloadFlaggedAssets();
|
bool downloadFlaggedAssets();
|
||||||
|
bool filterAssets(const UpdateParameters::AssetParams & ap);
|
||||||
void init(QString repo, QString nightly = "", int resultsPerPage = -1);
|
void init(QString repo, QString nightly = "", int resultsPerPage = -1);
|
||||||
const bool isSettingsIndexValid() const;
|
const bool isSettingsIndexValid() const;
|
||||||
UpdateNetwork* const network() const;
|
UpdateNetwork* const network() const;
|
||||||
|
|||||||
@@ -25,11 +25,12 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
|
#include <QAbstractItemView>
|
||||||
|
|
||||||
UpdateSounds::UpdateSounds(QWidget * parent) :
|
UpdateSounds::UpdateSounds(QWidget * parent) :
|
||||||
UpdateInterface(parent, CID_Sounds, tr("Sounds"))
|
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();
|
langPacks = new QStandardItemModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ void UpdateSounds::assetSettingsInit()
|
|||||||
cad.processes(UPDFLG_Common_Asset);
|
cad.processes(UPDFLG_Common_Asset);
|
||||||
cad.flags(cad.processes() | UPDFLG_CopyStructure);
|
cad.flags(cad.processes() | UPDFLG_CopyStructure);
|
||||||
cad.filterType(UpdateParameters::UFT_Startswith);
|
cad.filterType(UpdateParameters::UFT_Startswith);
|
||||||
cad.filter("edgetx-sdcard-sounds-%LANGUAGE%-");
|
cad.filter("edgetx-sdcard-sounds-%LANGUAGE%");
|
||||||
|
|
||||||
qDebug() << "Asset settings initialised";
|
qDebug() << "Asset settings initialised";
|
||||||
}
|
}
|
||||||
@@ -59,69 +60,18 @@ bool UpdateSounds::flagAssets()
|
|||||||
{
|
{
|
||||||
status()->progressMessage(tr("Processing available sounds"));
|
status()->progressMessage(tr("Processing available sounds"));
|
||||||
|
|
||||||
QJsonDocument *json = new QJsonDocument();
|
// always refresh to allow for language change in radio profile
|
||||||
|
|
||||||
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
|
|
||||||
langPacks->clear();
|
langPacks->clear();
|
||||||
|
|
||||||
if (json->isArray()) {
|
UpdateParameters::AssetParams ap = params()->assets[0];
|
||||||
const QJsonArray &arr = json->array();
|
if (!filterAssets(ap))
|
||||||
|
|
||||||
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);
|
|
||||||
return false;
|
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) {
|
if (langPacks->rowCount() > 1) {
|
||||||
@@ -139,26 +89,25 @@ bool UpdateSounds::flagAssets()
|
|||||||
|
|
||||||
QModelIndexList selIndexes = selItems->selectedIndexes();
|
QModelIndexList selIndexes = selItems->selectedIndexes();
|
||||||
|
|
||||||
for (int i = 0; i < selIndexes.size(); i++) {
|
if (!flagLanguageAsset(langPacks->data(selIndexes.at(0)).toString()))
|
||||||
if (!flagLanguageAsset(langPacks->data(selIndexes.at(i), IMDR_Directory).toString()))
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
dlg->deleteLater();
|
dlg->deleteLater();
|
||||||
}
|
}
|
||||||
else if (langPacks->rowCount() == 1) {
|
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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UpdateSounds::flagLanguageAsset(QString lang)
|
bool UpdateSounds::flagLanguageAsset(QString asset)
|
||||||
{
|
{
|
||||||
status()->progressMessage(tr("Flagging assets"));
|
status()->progressMessage(tr("Flagging assets"));
|
||||||
|
|
||||||
params()->language = lang;
|
|
||||||
UpdateParameters::AssetParams ap = params()->assets[0];
|
UpdateParameters::AssetParams ap = params()->assets[0];
|
||||||
|
ap.filter = asset;
|
||||||
|
ap.filterType = UpdateParameters::UFT_Exact;
|
||||||
return setFilteredAssets(ap);
|
return setFilteredAssets(ap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,13 +39,6 @@ class UpdateSounds : public UpdateInterface
|
|||||||
virtual void assetSettingsInit() override;
|
virtual void assetSettingsInit() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum ItemModelDataRoles {
|
|
||||||
IMDR_Language = Qt::UserRole,
|
|
||||||
IMDR_Name,
|
|
||||||
IMDR_Directory,
|
|
||||||
};
|
|
||||||
Q_ENUM(ItemModelDataRoles)
|
|
||||||
|
|
||||||
QStandardItemModel *langPacks;
|
QStandardItemModel *langPacks;
|
||||||
|
|
||||||
bool flagLanguageAsset(QString lang);
|
bool flagLanguageAsset(QString lang);
|
||||||
|
|||||||
@@ -36,11 +36,8 @@ void UpdateStatus::reportProgress(QString text, QtMsgType type)
|
|||||||
if (m_logLevel == QtDebugMsg ||
|
if (m_logLevel == QtDebugMsg ||
|
||||||
(m_logLevel == QtInfoMsg && type > QtDebugMsg) ||
|
(m_logLevel == QtInfoMsg && type > QtDebugMsg) ||
|
||||||
(type < QtInfoMsg && type >= m_logLevel)) {
|
(type < QtInfoMsg && type >= m_logLevel)) {
|
||||||
if (m_progress) {
|
if (m_progress)
|
||||||
m_progress->addMessage(text, type);
|
m_progress->addMessage(text, type);
|
||||||
if (m_logLevel == QtDebugMsg)
|
|
||||||
qDebug() << text;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
qDebug() << text;
|
qDebug() << text;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user