Sounds language pack choice
This commit is contained in:
@@ -20,34 +20,130 @@
|
||||
*/
|
||||
|
||||
#include "updatesounds.h"
|
||||
#include "chooserdialog.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QStandardItem>
|
||||
#include <QItemSelectionModel>
|
||||
|
||||
UpdateSounds::UpdateSounds(QWidget * parent) :
|
||||
UpdateInterface(parent)
|
||||
UpdateInterface(parent),
|
||||
langPacks(new QStandardItemModel())
|
||||
{
|
||||
setName("Sounds");
|
||||
setRepo(QString(GH_REPOS_EDGETX).append("/edgetx-sdcard-sounds"));
|
||||
|
||||
/*
|
||||
file: sounds.json
|
||||
[
|
||||
{
|
||||
"language": "cs_CZ",
|
||||
"name": "Czech Female",
|
||||
"description": "Czech Female Voice (cs-CZ-Vlasta)",
|
||||
"directory": "cz"
|
||||
},
|
||||
|
||||
TODO support multiple language sub variants
|
||||
// eg edgetx-sdcard-sounds-en_gb-libby-2.7.0.zip
|
||||
ap.filter = QString("^edgetx-sdcard-sounds-%1").arg(language); //return all variants of each language
|
||||
*/
|
||||
|
||||
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
|
||||
// only supports default for each language
|
||||
// eg edgetx-sdcard-sounds-en-2.7.0.zip
|
||||
ap.filterType = UpdateParameters::UFT_Startswith;
|
||||
ap.filter = QString("edgetx-sdcard-sounds-%LANGUAGE%-");
|
||||
// if user changes filter then more than one could be returned
|
||||
//ap.maxExpected = 1;
|
||||
ap.flags = dfltParams->data.flags | UPDFLG_CopyStructure;
|
||||
}
|
||||
|
||||
UpdateSounds::~UpdateSounds()
|
||||
{
|
||||
delete langPacks;
|
||||
}
|
||||
|
||||
bool UpdateSounds::flagAssets()
|
||||
{
|
||||
progressMessage(tr("Flagging assets"));
|
||||
|
||||
const QString mappingfile = "sounds.json";
|
||||
|
||||
if (!downloadTextFileToBuffer(mappingfile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonDocument *json = new QJsonDocument();
|
||||
|
||||
if (!convertDownloadToJson(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();
|
||||
|
||||
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 == runParams->data.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) {
|
||||
reportProgress(tr("Language %1 not listed in %2").arg(runParams->data.language).arg(mappingfile), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (langPacks->rowCount() > 1) {
|
||||
ChooserDialog *dlg = new ChooserDialog(nullptr, tr("Choose Language Packs"), langPacks);
|
||||
|
||||
dlg->exec();
|
||||
|
||||
QItemSelectionModel *selItems = dlg->selectedItems();
|
||||
|
||||
if (!selItems->hasSelection()) {
|
||||
QMessageBox::warning(this, CPN_STR_APP_NAME, tr("No language packs have been selected. Sounds update will be skipped!"));
|
||||
dlg->deleteLater();
|
||||
return true;
|
||||
}
|
||||
|
||||
QModelIndexList selIndexes = selItems->selectedIndexes();
|
||||
|
||||
for (int i = 0; i < selIndexes.size(); i++) {
|
||||
if (!flagLanguageAsset(langPacks->data(selIndexes.at(i), IMDR_Directory).toString()))
|
||||
return false;
|
||||
}
|
||||
|
||||
dlg->deleteLater();
|
||||
}
|
||||
else if (langPacks->rowCount() == 1) {
|
||||
if (!flagLanguageAsset(langPacks->data(langPacks->index(0, 0), IMDR_Directory).toString()))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UpdateSounds::flagLanguageAsset(QString lang)
|
||||
{
|
||||
runParams->data.language = lang;
|
||||
UpdateParameters::AssetParams ap = runParams->data.assets[0];
|
||||
return getSetAssets(ap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user