chore(cpn): Refactor component updates (#3218)
* Refactoring * Fix current release id and process dlg events * enh: Process updates dialog add select/deselect all components * Change Expression to Pattern
This commit is contained in:
@@ -27,9 +27,9 @@
|
||||
#include <QItemSelectionModel>
|
||||
|
||||
UpdateSounds::UpdateSounds(QWidget * parent) :
|
||||
UpdateInterface(parent)
|
||||
UpdateInterface(parent, CID_Sounds, tr("Sounds"))
|
||||
{
|
||||
init(CID_Sounds, tr("Sounds"), QString(GH_REPOS_EDGETX).append("/edgetx-sdcard-sounds"));
|
||||
init(QString(GH_API_REPOS_EDGETX).append("/edgetx-sdcard-sounds"));
|
||||
langPacks = new QStandardItemModel();
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ UpdateSounds::~UpdateSounds()
|
||||
delete langPacks;
|
||||
}
|
||||
|
||||
void UpdateSounds::initAssetSettings()
|
||||
void UpdateSounds::assetSettingsInit()
|
||||
{
|
||||
if (!isValidSettingsIndex())
|
||||
if (!isSettingsIndexValid())
|
||||
return;
|
||||
|
||||
g.component[id()].initAllAssets();
|
||||
@@ -57,29 +57,20 @@ void UpdateSounds::initAssetSettings()
|
||||
|
||||
bool UpdateSounds::flagAssets()
|
||||
{
|
||||
progressMessage(tr("Processing available sounds"));
|
||||
|
||||
QString pattern("sounds.json");
|
||||
assets->setFilterPattern(pattern);
|
||||
|
||||
if (assets->count() < 0) {
|
||||
reportProgress(tr("Asset not found in release '%1' using filter pattern '%2'").arg(releases->name()).arg(pattern), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
else if (assets->count() > 1) {
|
||||
reportProgress(tr("%1 assets found when %2 expected in release '%3' using filter pattern '%4'")
|
||||
.arg(assets->count()).arg(1).arg(releases->name()).arg(pattern), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!downloadAssetToBuffer(assets->getSetId(0))) {
|
||||
return false;
|
||||
}
|
||||
status()->progressMessage(tr("Processing available sounds"));
|
||||
|
||||
QJsonDocument *json = new QJsonDocument();
|
||||
|
||||
if (!convertDownloadToJson(json)) {
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -108,7 +99,7 @@ bool UpdateSounds::flagAssets()
|
||||
lang = langVariant.split("-").at(0);
|
||||
}
|
||||
|
||||
if (lang == params->language) {
|
||||
if (lang == params()->language) {
|
||||
QStandardItem * item = new QStandardItem();
|
||||
|
||||
if (!obj.value("language").isUndefined())
|
||||
@@ -129,7 +120,7 @@ bool UpdateSounds::flagAssets()
|
||||
delete json;
|
||||
|
||||
if (langPacks->rowCount() < 1) {
|
||||
reportProgress(tr("Language %1 not listed in %2").arg(params->language).arg(pattern), QtCriticalMsg);
|
||||
status()->reportProgress(tr("Language '%1' not listed in '%2'").arg(params()->language).arg(jsonFile), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -141,7 +132,7 @@ bool UpdateSounds::flagAssets()
|
||||
QItemSelectionModel *selItems = dlg->selectedItems();
|
||||
|
||||
if (!ok || !selItems->hasSelection()) {
|
||||
QMessageBox::warning(progress, CPN_STR_APP_NAME, tr("No language packs have been selected. Sounds update will be skipped!"));
|
||||
QMessageBox::warning(status()->progress(), CPN_STR_APP_NAME, tr("No language packs have been selected. Sounds update will be skipped!"));
|
||||
dlg->deleteLater();
|
||||
return true;
|
||||
}
|
||||
@@ -165,9 +156,9 @@ bool UpdateSounds::flagAssets()
|
||||
|
||||
bool UpdateSounds::flagLanguageAsset(QString lang)
|
||||
{
|
||||
progressMessage(tr("Flagging assets"));
|
||||
status()->progressMessage(tr("Flagging assets"));
|
||||
|
||||
params->language = lang;
|
||||
UpdateParameters::AssetParams ap = params->assets[0];
|
||||
return getSetAssets(ap);
|
||||
params()->language = lang;
|
||||
UpdateParameters::AssetParams ap = params()->assets[0];
|
||||
return setFilteredAssets(ap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user