Sounds language pack choice
This commit is contained in:
@@ -12,6 +12,7 @@ set(updates_NAMES
|
||||
updatesounds
|
||||
updatethemes
|
||||
updatemultiprotocol
|
||||
chooserdialog
|
||||
)
|
||||
|
||||
foreach(name ${updates_NAMES})
|
||||
@@ -22,6 +23,7 @@ endforeach()
|
||||
set(updates_UIS
|
||||
updatesdialog.ui
|
||||
updateoptionsdialog.ui
|
||||
chooserdialog.ui
|
||||
)
|
||||
|
||||
set(updates_QTS
|
||||
@@ -30,6 +32,7 @@ set(updates_QTS
|
||||
updateoptionsdialog.h
|
||||
repomodels.h
|
||||
updateinterface.h
|
||||
chooserdialog.h
|
||||
)
|
||||
|
||||
qt5_wrap_ui(updates_SRCS ${updates_UIS})
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "chooserdialog.h"
|
||||
#include "ui_chooserdialog.h"
|
||||
|
||||
ChooserDialog::ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ChooserDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setWindowTitle(title);
|
||||
|
||||
ui->listView->setModel(itemModel);
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]() {
|
||||
QDialog::accept();
|
||||
});
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, [=]() {
|
||||
QDialog::reject();
|
||||
});
|
||||
}
|
||||
|
||||
ChooserDialog::~ChooserDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QItemSelectionModel* ChooserDialog::selectedItems()
|
||||
{
|
||||
return ui->listView->selectionModel();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
#include <QStandardItemModel>
|
||||
#include <QItemSelectionModel>
|
||||
|
||||
namespace Ui {
|
||||
class ChooserDialog;
|
||||
}
|
||||
|
||||
class ChooserDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChooserDialog(QWidget * parent, QString title, QStandardItemModel * itemModel);
|
||||
virtual ~ChooserDialog();
|
||||
|
||||
QItemSelectionModel* selectedItems();
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
|
||||
private:
|
||||
Ui::ChooserDialog *ui;
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ChooserDialog</class>
|
||||
<widget class="QDialog" name="ChooserDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>385</width>
|
||||
<height>234</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::MultiSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -104,18 +104,18 @@ QString UpdateParameters::buildFilterPattern(const UpdateFilterType filterType,
|
||||
pattern.replace("%LANGUAGE%", data.language);
|
||||
|
||||
switch ((int)filterType) {
|
||||
case UpdateParameters::UFT_Exact:
|
||||
case UFT_Exact:
|
||||
pattern.prepend("^");
|
||||
pattern.append("$");
|
||||
break;
|
||||
case UpdateParameters::UFT_Startswith:
|
||||
case UFT_Startswith:
|
||||
pattern.prepend("^");
|
||||
break;
|
||||
case UpdateParameters::UFT_Endswith:
|
||||
case UFT_Endswith:
|
||||
pattern.append("$");
|
||||
break;
|
||||
case UpdateParameters::UFT_Contains:
|
||||
case UpdateParameters::UFT_Expression:
|
||||
case UFT_Contains:
|
||||
case UFT_Expression:
|
||||
break;
|
||||
default:
|
||||
pattern = "";
|
||||
|
||||
@@ -48,7 +48,7 @@ class UpdateParameters : public QWidget
|
||||
|
||||
static QString updateFilterTypeToString(UpdateFilterType uft);
|
||||
|
||||
struct AssetParams{
|
||||
struct AssetParams {
|
||||
int flags;
|
||||
UpdateFilterType filterType;
|
||||
QString filter;
|
||||
@@ -58,7 +58,7 @@ class UpdateParameters : public QWidget
|
||||
QString copyFilter;
|
||||
};
|
||||
|
||||
struct GeneralParams{
|
||||
struct GeneralParams {
|
||||
int flags;
|
||||
QString fwFlavour;
|
||||
QString language;
|
||||
|
||||
@@ -88,13 +88,13 @@ bool UpdateSDCard::flagAssets()
|
||||
}
|
||||
}
|
||||
|
||||
delete json;
|
||||
|
||||
if (!found) {
|
||||
reportProgress(tr("Radio flavour %1 not listed in %2").arg(runParams->data.fwFlavour).arg(mappingfile), QtCriticalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
delete json;
|
||||
|
||||
UpdateParameters::AssetParams sd = ap;
|
||||
sd.filterType = UpdateParameters::UFT_Startswith;
|
||||
sd.filter = sdimage;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "updateinterface.h"
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
class UpdateSounds : public UpdateInterface
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(UpdateSounds)
|
||||
@@ -30,6 +32,20 @@ class UpdateSounds : public UpdateInterface
|
||||
public:
|
||||
|
||||
explicit UpdateSounds(QWidget * parent);
|
||||
virtual ~UpdateSounds() {}
|
||||
virtual ~UpdateSounds();
|
||||
|
||||
protected:
|
||||
virtual bool flagAssets() override;
|
||||
|
||||
private:
|
||||
enum ItemModelDataRoles {
|
||||
IMDR_Language = Qt::UserRole,
|
||||
IMDR_Name,
|
||||
IMDR_Directory,
|
||||
};
|
||||
Q_ENUM(ItemModelDataRoles)
|
||||
|
||||
QStandardItemModel *langPacks;
|
||||
|
||||
bool flagLanguageAsset(QString lang);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user