From ea3f47c7f23ffdc98d0791f56d29b1a141782ecd Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Sun, 16 Feb 2014 16:48:55 +0100 Subject: [PATCH 01/13] I will wrap the unsafe global settings operations in a application data object. I have found several bugs in the current model, where settings labels have been spelled badly or been of the wrong type. --- companion/src/appdata.h | 331 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 companion/src/appdata.h diff --git a/companion/src/appdata.h b/companion/src/appdata.h new file mode 100644 index 000000000..1610d39ea --- /dev/null +++ b/companion/src/appdata.h @@ -0,0 +1,331 @@ +// Companion Application Data Class. +// All temporary and permanent global variables are defined here to make +// initialization and storage safe and visible. +// Do not access variables in QSettings directly, it is not type safe! + + +#ifndef APPDATA_H +#define APPDATA_H +#include + +#define COMPANY "OpenTX Companion" +#define PRODUCT "OpenTX" + +class AppData +{ + private: + // All the global variables + QStringList _recentFileList; + QByteArray _mainWindowGeometry; + QByteArray _mainWindowState; + + QString _firmware; + QString _locale; + QString _cpu_id; + QString _SplashImage; + QString _Name; + QString _SplashFileName; + QString _modelEditGeometry; + + QString _backupPath; + QString _gePath; + QString _lastDir; + QString _lastFlashDir; + QString _lastImagesDir; + QString _libraryPath; + QString _sdPath; + QString _snapshotpath; + + bool _backupEnable; + bool _backupOnFlash; + bool _burnFirmware; + bool _maximized; + bool _js_support; + bool _rename_firmware_files; + bool _show_splash; + bool _snapshot_to_clipboard; + bool _startup_check_companion; + bool _startup_check_fw; + bool _simuSW; + bool _wizardEnable; + + int _backLight; + int _default_channel_order; + int _default_mode; + int _embedded_splashes; // Shouldn't this be bool ?? + int _fwserver; + int _generalEditTab; + int _icon_size; + int _js_ctrl; + int _history_size; + int _modelEditTab; + int _profileId; + int _theme; + int _warningId; + + // Storage functions + + void store(const QByteArray newArray, QByteArray &array, const char *tag) + { + QSettings settings(PRODUCT, COMPANY); + settings.setValue(tag, newArray); + array = newArray; + } + + void store(const QStringList newSList, QStringList &stringList, const char *tag) + { + QSettings settings(PRODUCT, COMPANY); + settings.setValue(tag, newSList); + stringList = newSList; + } + + void store(const QString newString, QString &string, const char *tag) + { + QSettings settings(PRODUCT, COMPANY); + settings.setValue(tag, newString); + string = newString; + } + + void store(const bool newTruth, bool &truth, const char *tag) + { + QSettings settings(PRODUCT, COMPANY); + settings.setValue(tag, newTruth); + truth = newTruth; + } + + void store(const int newNumber, int &number, const char *tag) + { + QSettings settings(PRODUCT, COMPANY); + settings.setValue(tag, newNumber); + number = newNumber; + } + + // Retrieval functions + void retrieve( QByteArray &array, const char *tag, const char *def) + { + QSettings settings(PRODUCT, COMPANY); + array = settings.value(tag, def).toByteArray(); + } + void retrieve( QStringList &stringList, const char *tag, const char *def) + { + QSettings settings(PRODUCT, COMPANY); + stringList = settings.value(tag, def).toStringList(); + } + + void retrieve( QString &string, const char *tag, const char *def) + { + QSettings settings(PRODUCT, COMPANY); + string = settings.value(tag, def).toString(); + } + + void retrieve( bool &truth, const char *tag, const bool def) + { + QSettings settings(PRODUCT, COMPANY); + truth = settings.value(tag, def).toBool(); + } + + void retrieve( int &number, const char *tag, const int def) + { + QSettings settings(PRODUCT, COMPANY); + number = settings.value(tag, def).toInt(); + } + + // Retrieve and Store functions + void getset( QByteArray &array, const char *tag, const char *def) + { + retrieve( array, tag, def); + store(array, array, tag); + } + + void getset( QStringList &stringList, const char *tag, const char *def) + { + retrieve( stringList, tag, def); + store(stringList, stringList, tag); + } + + void getset( QString &string, const char *tag, const char *def) + { + retrieve( string, tag, def); + store(string, string, tag); + } + + void getset( bool &truth, const char *tag, const bool def) + { + retrieve( truth, tag, def); + store(truth, truth, tag); + } + + void getset( int &number, const char *tag, const int def) + { + retrieve( number, tag, def); + store(number, number, tag); + } + +public: + // All the get declarations + QStringList recentFileList() { return _recentFileList; } + QByteArray mainWindowGeometry(){ return _mainWindowGeometry; } + QByteArray mainWindowState() { return _mainWindowState; } + + QString firmware() { return _firmware; } + QString locale() { return _locale; } + QString cpu_id() { return _cpu_id; } + QString SplashImage() { return _SplashImage; } + QString Name() { return _Name; } + QString SplashFileName() { return _SplashFileName; } + QString modelEditGeometry() { return _modelEditGeometry; } + + QString backupPath() { return _backupPath; } + QString gePath() { return _gePath; } + QString lastDir() { return _lastDir; } + QString lastFlashDir() { return _lastFlashDir; } + QString lastImagesDir() { return _lastImagesDir; } + QString libraryPath() { return _libraryPath; } + QString sdPath() { return _sdPath; } + QString snapshotpath() { return _snapshotpath; } + + bool backupEnable() { return _backupEnable; } + bool backupOnFlash() { return _backupOnFlash; } + bool burnFirmware() { return _burnFirmware; } + bool js_support() { return _js_support; } + bool maximized() { return _maximized; } + bool rename_firmware_files() { return _rename_firmware_files; } + bool show_splash() { return _show_splash; } + bool snapshot_to_clipboard() { return _snapshot_to_clipboard; } + bool startup_check_companion() { return _startup_check_companion;} + bool startup_check_fw() { return _startup_check_fw; } + bool simuSW() { return _simuSW; } + bool wizardEnable() { return _wizardEnable; } + + int backLight() { return _backLight; } + int default_channel_order() { return _default_channel_order; } + int default_mode() { return _default_mode; } + int embedded_splashes() { return _embedded_splashes; } + int fwserver() { return _fwserver; } + int generalEditTab() { return _generalEditTab; } + int icon_size() { return _icon_size; } + int history_size() { return _history_size; } + int js_ctr() { return _js_ctrl; } + int modelEditTab() { return _modelEditTab; } + int profileId() { return _profileId; } + int theme() { return _theme; } + int warningId() { return _warningId; } + + // All the set declarations + void recentFileList (const QStringList l) { store(l, _recentFileList, "recentFileList" );} + void mainWindowGeometry (const QByteArray a) { store(a, _mainWindowGeometry, "mainWindowGeometry");} + void mainWindowState (const QByteArray a) { store(a, _mainWindowState, "mainWindowState" );} + + void firmware (const QString str) { store(str, _firmware, "firmware" );} + void locale (const QString str) { store(str, _locale, "locale" );} + void cpu_id (const QString str) { store(str, _cpu_id, "cpu_id" );} + void SplashImage (const QString str) { store(str, _SplashImage, "SplashImage" );} + void Name (const QString str) { store(str, _Name, "Name" );} + void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" );} + void modelEditGeometry (const QString str) { store(str, _modelEditGeometry, "modelEditGeometry" );} + + void backupPath (const QString str) { store(str, _backupPath, "backupPath" );} + void gePath (const QString str) { store(str, _gePath, "gePath" );} + void lastDir (const QString str) { store(str, _lastDir, "lastDir" );} + void lastFlashDir (const QString str) { store(str, _lastFlashDir, "lastFlashDir" );} + void lastImagesDir (const QString str) { store(str, _lastImagesDir, "lastImagesDir" );} + void libraryPath (const QString str) { store(str, _libraryPath, "libraryPath" );} + void sdPath (const QString str) { store(str, _sdPath, "sdPath" );} + void snapshotpath (const QString str) { store(str, _snapshotpath, "snapshotpath" );} + + void backupEnable (const bool bl) { store(bl, _backupEnable, "backupEnable" );} + void backupOnFlash (const bool bl) { store(bl, _backupOnFlash, "backupOnFlash" );} + void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" );} + void maximized (const bool bl) { store(bl, _maximized, "maximized" );} + void js_support (const bool bl) { store(bl, _js_support, "js_support" );} + void rename_firmware_files (const bool bl) { store(bl, _rename_firmware_files, "rename_firmware_files" );} + void show_splash (const bool bl) { store(bl, _show_splash, "show_splash" );} + void snapshot_to_clipboard (const bool bl) { store(bl, _snapshot_to_clipboard, "snapshot_to_clipboard" );} + void startup_check_companion (const bool bl) { store(bl, _startup_check_companion, "startup_check_companion" );} + void startup_check_fw (const bool bl) { store(bl, _startup_check_fw, "startup_check_fw" );} + void simuSW (const bool bl) { store(bl, _simuSW, "simuSW" );} + void wizardEnable (const bool bl) { store(bl, _wizardEnable, "wizardEnable" );} + + void backLight (const int it) { store(it, _backLight, "backLight" );} + void default_channel_order (const int it) { store(it, _default_channel_order, "default_channel_order" );} + void default_mode (const int it) { store(it, _default_mode, "default_mode" );} + void embedded_splashes (const int it) { store(it, _embedded_splashes, "embedded_splashes" );} + void fwserver (const int it) { store(it, _fwserver, "fwserver" );} + void generalEditTab (const int it) { store(it, _generalEditTab, "generalEditTab" );} + void icon_size (const int it) { store(it, _icon_size, "icon_size" );} + void history_size (const int it) { store(it, _history_size, "history_size" );} + void js_ctrl (const int it) { store(it, _js_ctrl, "js_ctrl" );} + void modelEditTab (const int it) { store(it, _modelEditTab, "modelEditTab" );} + void profileId (const int it) { store(it, _profileId, "profileId" );} + void theme (const int it) { store(it, _theme, "theme" );} + void warningId (const int it) { store(it, _warningId, "warningId" );} + + // Constructor + AppData() + { + // Start by hijacking all left over settings from companion9x, but only do it one time + // Use "location" tag as an indicator that the settings are missing + QSettings c9x_settings("companion9x", "companion9x"); + QSettings settings(PRODUCT, COMPANY); + if (!settings.contains("locale")) { + QStringList keys = c9x_settings.allKeys(); + for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++) { + settings.setValue(*i, c9x_settings.value(*i)); + } + } + + // Load and store all variables. Use default values if setting values are missing + + getset( _recentFileList, "recentFileList" ,"" ); + getset( _mainWindowGeometry, "mainWindowGeometry" ,"" ); + getset( _mainWindowState, "mainWindowState" ,"" ); + + getset( _firmware, "firmware" ,"" ); + getset( _locale, "locale" ,"" ); + getset( _cpu_id, "cpu_id" ,"" ); + getset( _SplashImage, "SplashImage" ,"" ); + getset( _Name, "Name" ,"" ); + getset( _SplashFileName, "SplashFileName" ,"" ); + getset( _modelEditGeometry, "modelEditGeometry" ,"" ); + + getset( _backupPath, "backupPath" ,"" ); + getset( _gePath, "gePath" ,"" ); + getset( _lastDir, "lastDir" ,"" ); + getset( _lastFlashDir, "lastFlashDir" ,"" ); + getset( _lastImagesDir, "lastImagesDir" ,"" ); + getset( _libraryPath, "libraryPath" ,"" ); + getset( _sdPath, "sdPath" ,"" ); + getset( _snapshotpath, "snapshotpath" ,"" ); + + getset( _backupEnable, "backupEnable" ,false ); + getset( _backupOnFlash, "backupOnFlash" ,true ); + getset( _burnFirmware, "burnFirmware" ,false ); + getset( _js_support, "js_support" ,false ); + getset( _maximized, "maximized" ,false ); + getset( _rename_firmware_files, "rename_firmware_files" ,false ); + getset( _show_splash, "show_splash" ,true ); + getset( _snapshot_to_clipboard, "snapshot_to_clipboard" ,false ); + getset( _startup_check_companion, "startup_check_companion" ,true ); + getset( _startup_check_fw, "startup_check_fw" ,true ); + getset( _simuSW, "simuSW" ,false ); + getset( _wizardEnable, "wizardEnable" ,true ); + + getset( _backLight, "backLight" ,0 ); + getset( _default_channel_order, "default_channel_order" ,0 ); + getset( _default_mode, "default_mode" ,1 ); + getset( _embedded_splashes, "embedded_splashes" ,0 ); + getset( _fwserver, "fwserver" ,0 ); + getset( _generalEditTab, "generalEditTab" ,0 ); + getset( _icon_size, "icon_size" ,2 ); + getset( _js_ctrl, "js_ctrl" ,0 ); + getset( _history_size, "history_size" ,6 ); + getset( _modelEditTab, "modelEditTab" ,0 ); + getset( _profileId, "profileId" ,0 ); + getset( _theme, "theme" ,1 ); + getset( _warningId, "warningId" ,0 ); + } + }; + +extern AppData glob; + +#endif // APPDATA_H From acbe17e4bc3bad79b6b04eb75165953b653cadf5 Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Sun, 16 Feb 2014 18:17:10 +0100 Subject: [PATCH 02/13] Main and the preferences dialog are done. At least as far as the simple values. I have not made support for complex values like profiles yet. --- companion/src/appdata.h | 2 +- companion/src/apppreferencesdialog.cpp | 149 +++++++++++-------------- companion/src/main.cpp | 40 +++---- companion/src/mainwindow.h | 1 + 4 files changed, 84 insertions(+), 108 deletions(-) diff --git a/companion/src/appdata.h b/companion/src/appdata.h index 1610d39ea..007f96c42 100644 --- a/companion/src/appdata.h +++ b/companion/src/appdata.h @@ -205,7 +205,7 @@ public: int generalEditTab() { return _generalEditTab; } int icon_size() { return _icon_size; } int history_size() { return _history_size; } - int js_ctr() { return _js_ctrl; } + int js_ctrl() { return _js_ctrl; } int modelEditTab() { return _modelEditTab; } int profileId() { return _profileId; } int theme() { return _theme; } diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index cfcb0b3de..0f97b0f1e 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -35,61 +35,58 @@ appPreferencesDialog::~appPreferencesDialog() void appPreferencesDialog::writeValues() { - QSettings settings; - settings.setValue("startup_check_companion", ui->startupCheck_companion9x->isChecked()); - settings.setValue("startup_check_fw", ui->startupCheck_fw->isChecked()); - settings.setValue("wizardEnable", ui->wizardEnable_ChkB->isChecked()); - settings.setValue("show_splash", ui->showSplash->isChecked()); - settings.setValue("simuSW", ui->simuSW->isChecked()); - settings.setValue("history_size", ui->historySize->value()); - settings.setValue("backLight", ui->backLightColor->currentIndex()); - settings.setValue("libraryPath", ui->libraryPath->text()); - settings.setValue("gePath", ui->ge_lineedit->text()); - settings.setValue("embedded_splashes", ui->splashincludeCB->currentIndex()); - settings.setValue("backupEnable", ui->backupEnable->isChecked()); + glob.startup_check_companion(ui->startupCheck_companion9x->isChecked()); + glob.startup_check_fw(ui->startupCheck_fw->isChecked()); + glob.wizardEnable(ui->wizardEnable_ChkB->isChecked()); + glob.show_splash(ui->showSplash->isChecked()); + glob.simuSW(ui->simuSW->isChecked()); + glob.history_size(ui->historySize->value()); + glob.backLight(ui->backLightColor->currentIndex()); + glob.libraryPath(ui->libraryPath->text()); + glob.gePath(ui->ge_lineedit->text()); + glob.embedded_splashes(ui->splashincludeCB->currentIndex()); + glob.backupEnable(ui->backupEnable->isChecked()); if (ui->joystickChkB ->isChecked() && ui->joystickCB->isEnabled()) { - settings.setValue("js_support", ui->joystickChkB ->isChecked()); - settings.setValue("js_ctrl", ui->joystickCB ->currentIndex()); + glob.js_support(ui->joystickChkB ->isChecked()); + glob.js_ctrl(ui->joystickCB ->currentIndex()); } else { - settings.remove("js_support"); - settings.remove("js_ctrl"); + glob.js_support(false); + glob.js_ctrl(0); } - settings.setValue("default_channel_order", ui->channelorderCB->currentIndex()); - settings.setValue("default_mode", ui->stickmodeCB->currentIndex()); - settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked()); - settings.setValue("burnFirmware", ui->burnFirmware->isChecked()); - settings.setValue("profileId", ui->profileIndexLE->text()); - settings.setValue("Name", ui->profileNameLE->text()); - settings.setValue("sdPath", ui->sdPath->text()); - settings.setValue("SplashFileName", ui->SplashFileName->text()); + glob.default_channel_order(ui->channelorderCB->currentIndex()); + glob.default_mode(ui->stickmodeCB->currentIndex()); + glob.rename_firmware_files(ui->renameFirmware->isChecked()); + glob.burnFirmware(ui->burnFirmware->isChecked()); + glob.profileId(ui->profileIndexLE->text().toInt()); + glob.Name(ui->profileNameLE->text()); + glob.sdPath(ui->sdPath->text()); + glob.SplashFileName(ui->SplashFileName->text()); if (!ui->SplashFileName->text().isEmpty()) - settings.setValue("SplashImage", ""); - settings.setValue("firmware", ui->firmwareLE->text()); + glob.SplashImage(""); + glob.firmware(ui->firmwareLE->text()); saveProfile(); } void appPreferencesDialog::on_snapshotPathButton_clicked() { - QSettings settings; - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), settings.value("snapshotPath").toString()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), glob.snapshotpath()); if (!fileName.isEmpty()) { - settings.setValue("snapshotpath", fileName); - settings.setValue("snapshot_to_clipboard", false); + glob.snapshotpath(fileName); + glob.snapshot_to_clipboard(false); ui->snapshotPath->setText(fileName); } } void appPreferencesDialog::initSettings() { - QSettings settings; - ui->snapshotClipboardCKB->setChecked(settings.value("snapshot_to_clipboard", false).toBool()); - ui->burnFirmware->setChecked(settings.value("burnFirmware", true).toBool()); + ui->snapshotClipboardCKB->setChecked(glob.snapshot_to_clipboard()); + ui->burnFirmware->setChecked(glob.burnFirmware()); - QString Path=settings.value("snapshotPath", "").toString(); + QString Path=glob.snapshotpath(); if (QDir(Path).exists()) { ui->snapshotPath->setText(Path); ui->snapshotPath->setReadOnly(true); @@ -98,38 +95,38 @@ void appPreferencesDialog::initSettings() ui->snapshotPath->setDisabled(true); ui->snapshotPathButton->setDisabled(true); } - ui->startupCheck_companion9x->setChecked(settings.value("startup_check_companion", true).toBool()); - ui->startupCheck_fw->setChecked(settings.value("startup_check_fw", true).toBool()); - ui->wizardEnable_ChkB->setChecked(settings.value("wizardEnable", true).toBool()); - ui->showSplash->setChecked(settings.value("show_splash", true).toBool()); - ui->historySize->setValue(settings.value("history_size", 10).toInt()); - ui->backLightColor->setCurrentIndex(settings.value("backLight", 0).toInt()); - ui->simuSW->setChecked(settings.value("simuSW", false).toBool()); + ui->startupCheck_companion9x->setChecked(glob.startup_check_companion()); + ui->startupCheck_fw->setChecked(glob.startup_check_fw()); + ui->wizardEnable_ChkB->setChecked(glob.wizardEnable()); + ui->showSplash->setChecked(glob.show_splash()); + ui->historySize->setValue(glob.history_size()); + ui->backLightColor->setCurrentIndex(glob.backLight()); + ui->simuSW->setChecked(glob.simuSW()); - Path=settings.value("libraryPath", "").toString(); + Path=glob.libraryPath(); if (QDir(Path).exists()) { ui->libraryPath->setText(Path); } - Path=settings.value("gePath", "").toString(); + Path=glob.gePath(); if (QFile(Path).exists()) { ui->ge_lineedit->setText(Path); } - Path=settings.value("backupPath", "").toString(); + Path=glob.backupPath(); if (!Path.isEmpty()) { if (QDir(Path).exists()) { ui->backupPath->setText(Path); ui->backupEnable->setEnabled(true); - ui->backupEnable->setChecked(settings.value("backupEnable", true).toBool()); + ui->backupEnable->setChecked(glob.backupEnable()); } else { ui->backupEnable->setDisabled(true); } } else { ui->backupEnable->setDisabled(true); } - ui->splashincludeCB->setCurrentIndex(settings.value("embedded_splashes", 0).toInt()); + ui->splashincludeCB->setCurrentIndex(glob.embedded_splashes()); #ifdef JOYSTICKS - ui->joystickChkB->setChecked(settings.value("js_support", false).toBool()); + ui->joystickChkB->setChecked(glob.js_support()); if (ui->joystickChkB->isChecked()) { QStringList joystickNames; joystickNames << tr("No joysticks found"); @@ -147,7 +144,7 @@ void appPreferencesDialog::initSettings() } ui->joystickCB->clear(); ui->joystickCB->insertItems(0, joystickNames); - ui->joystickCB->setCurrentIndex(settings.value("js_ctrl", 0).toInt()); + ui->joystickCB->setCurrentIndex(glob.js_ctrl()); } else { ui->joystickCB->clear(); @@ -156,17 +153,17 @@ void appPreferencesDialog::initSettings() } #endif // Profile Tab Inits - ui->channelorderCB->setCurrentIndex(settings.value("default_channel_order", 0).toInt()); - ui->stickmodeCB->setCurrentIndex(settings.value("default_mode", 1).toInt()); - ui->renameFirmware->setChecked(settings.value("rename_firmware_files", false).toBool()); - Path=settings.value("sdPath", "").toString(); + ui->channelorderCB->setCurrentIndex(glob.default_channel_order()); + ui->stickmodeCB->setCurrentIndex(glob.default_mode()); + ui->renameFirmware->setChecked(glob.rename_firmware_files()); + Path=glob.sdPath(); if (QDir(Path).exists()) { ui->sdPath->setText(Path); } - ui->profileIndexLE->setText(settings.value("profileId", "").toString()); - ui->profileNameLE->setText(settings.value("Name", "").toString()); + ui->profileIndexLE->setText(QString(glob.profileId())); + ui->profileNameLE->setText(glob.Name()); - QString fileName=settings.value("SplashFileName","").toString(); + QString fileName=glob.SplashFileName(); if (!fileName.isEmpty()) { QFile file(fileName); if (file.exists()){ @@ -174,40 +171,37 @@ void appPreferencesDialog::initSettings() displayImage( fileName ); } } - ui->firmwareLE->setText(settings.value("firmware","").toString()); + ui->firmwareLE->setText(glob.firmware()); } void appPreferencesDialog::on_libraryPathButton_clicked() { - QSettings settings; - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), settings.value("libraryPath").toString()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), glob.libraryPath()); if (!fileName.isEmpty()) { - settings.setValue("libraryPath", fileName); + glob.libraryPath(fileName); ui->libraryPath->setText(fileName); } } void appPreferencesDialog::on_snapshotClipboardCKB_clicked() { - QSettings settings; if (ui->snapshotClipboardCKB->isChecked()) { ui->snapshotPath->setDisabled(true); ui->snapshotPathButton->setDisabled(true); - settings.setValue("snapshot_to_clipboard", true); + glob.snapshot_to_clipboard(true); } else { ui->snapshotPath->setEnabled(true); ui->snapshotPath->setReadOnly(true); ui->snapshotPathButton->setEnabled(true); - settings.setValue("snapshot_to_clipboard", false); + glob.snapshot_to_clipboard(false); } } void appPreferencesDialog::on_backupPathButton_clicked() { - QSettings settings; - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), settings.value("backupPath").toString()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), glob.backupPath()); if (!fileName.isEmpty()) { - settings.setValue("backupPath", fileName); + glob.backupPath(fileName); ui->backupPath->setText(fileName); } ui->backupEnable->setEnabled(true); @@ -215,7 +209,6 @@ void appPreferencesDialog::on_backupPathButton_clicked() void appPreferencesDialog::on_ge_pathButton_clicked() { - QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, tr("Select Google Earth executable"),ui->ge_lineedit->text()); if (!fileName.isEmpty()) { ui->ge_lineedit->setText(fileName); @@ -259,8 +252,7 @@ void appPreferencesDialog::on_joystickcalButton_clicked() { void appPreferencesDialog::on_sdPathButton_clicked() { - QSettings settings; - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), settings.value("sdPath").toString()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), glob.sdPath()); if (!fileName.isEmpty()) { ui->sdPath->setText(fileName); } @@ -270,7 +262,7 @@ void appPreferencesDialog::saveProfile() { QSettings settings; - QString profile=QString("profile") + settings.value("profileId").toString(); + QString profile=QString("profile") + glob.profileId(); QString name=ui->profileNameLE->text(); if (name.isEmpty()) { name = profile; @@ -306,8 +298,7 @@ void appPreferencesDialog::loadProfileString(QString profile, QString label) void appPreferencesDialog::loadProfile() { - QSettings settings; - QString profile=QString("profile") + settings.value("profileId").toString(); + QString profile=QString("profile") + glob.profileId(); loadProfileString( profile, "Name" ); loadProfileString( profile, "default_channel_order" ); @@ -322,12 +313,11 @@ void appPreferencesDialog::loadProfile() void appPreferencesDialog::on_removeProfileButton_clicked() { QSettings settings; - QString profileId = settings.value("profileId").toString(); - if ( profileId == "1" ) + if ( glob.profileId() == 1 ) QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); else { - QString profile=QString("profile") + profileId; + QString profile=QString("profile") + glob.profileId(); settings.beginGroup("Profiles"); settings.remove(profile); settings.endGroup(); @@ -340,15 +330,13 @@ void appPreferencesDialog::on_removeProfileButton_clicked() bool appPreferencesDialog::displayImage( QString fileName ) { - QSettings settings; - QImage image(fileName); if (image.isNull()) return false; // This code below just figures out if the width of the latest firmware is 128 or 212. It works , but... - QString filePath1 = settings.value("lastFlashDir", "").toString() + "/" + settings.value("firmware", "").toString() + ".bin"; - QString filePath2 = settings.value("lastFlashDir", "").toString() + "/" + settings.value("firmware", "").toString() + ".hex"; + QString filePath1 = glob.lastFlashDir() + "/" + glob.firmware() + ".bin"; + QString filePath2 = glob.lastFlashDir() + "/" + glob.firmware() + ".hex"; QFile file(filePath1); if (!file.exists()) filePath1 = filePath2; @@ -390,12 +378,11 @@ void appPreferencesDialog::on_SplashSelect_clicked() supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; } - QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); if (!fileName.isEmpty()) { - settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastImagesDir(QFileInfo(fileName).dir().absolutePath()); if (displayImage(fileName)) ui->SplashFileName->setText(fileName); diff --git a/companion/src/main.cpp b/companion/src/main.cpp index ffaea6801..93bd89123 100644 --- a/companion/src/main.cpp +++ b/companion/src/main.cpp @@ -74,6 +74,9 @@ class MyProxyStyle : public QProxyStyle }; #endif +// Global data and storge object +AppData glob; + int main(int argc, char *argv[]) { Q_INIT_RESOURCE(companion); @@ -86,46 +89,31 @@ int main(int argc, char *argv[]) app.setStyle(new MyProxyStyle); #endif - // Start by borrowing any left over settings from companion9x - QSettings c9x_settings("companion9x", "companion9x"); - QSettings settings; - - if (!settings.contains("pos")) { - QStringList keys = c9x_settings.allKeys(); - for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++) { - settings.setValue(*i, c9x_settings.value(*i)); - } - } - - QString dir; - if (argc) dir = QFileInfo(argv[0]).canonicalPath() + "/lang"; - - QString locale = settings.value("locale",QLocale::system().name()).toString(); - bool showSplash = settings.value("show_splash", true).toBool(); - QTranslator companionTranslator; - companionTranslator.load(":/companion_" + locale); + companionTranslator.load(":/companion_" + glob.locale()); QTranslator qtTranslator; - qtTranslator.load((QString)"qt_" + locale.left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + qtTranslator.load((QString)"qt_" + glob.locale().left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); app.installTranslator(&companionTranslator); app.installTranslator(&qtTranslator); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - QString firmware_id = settings.value("firmware", default_firmware_variant.id).toString(); - firmware_id.replace("open9x", "opentx"); - firmware_id.replace("x9da", "taranis"); + if (glob.firmware().isEmpty()) + glob.firmware(default_firmware_variant.id); + QString tmp_id = glob.firmware(); + tmp_id.replace("open9x", "opentx"); + tmp_id.replace("x9da", "taranis"); + glob.firmware(tmp_id); - QPixmap pixmap = QPixmap(firmware_id.contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); + QPixmap pixmap = QPixmap(glob.firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); QSplashScreen *splash = new QSplashScreen(pixmap); RegisterFirmwares(); - settings.setValue("firmware", firmware_id); - current_firmware_variant = GetFirmwareVariant(firmware_id); + current_firmware_variant = GetFirmwareVariant(glob.firmware()); MainWindow *mainWin = new MainWindow(); - if (showSplash) { + if (glob.show_splash()) { splash->show(); QTimer::singleShot(1000*SPLASH_TIME, splash, SLOT(close())); QTimer::singleShot(1000*SPLASH_TIME, mainWin, SLOT(show())); diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index 505878ef2..517158f0f 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -45,6 +45,7 @@ #include #include #include +#include "appdata.h" #include "downloaddialog.h" #include "eeprominterface.h" From fdc9873ab8fe282a723c2506a48c11cb31e1599a Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Mon, 17 Feb 2014 01:16:24 +0100 Subject: [PATCH 03/13] Profile date is now type safe. Semi working, not complete yet. --- companion/src/appdata.h | 416 ++++++++++++++++++------- companion/src/apppreferencesdialog.cpp | 68 ++-- companion/src/apppreferencesdialog.h | 2 +- companion/src/mainwindow.cpp | 166 ++++------ companion/src/mainwindow.h | 8 +- 5 files changed, 396 insertions(+), 264 deletions(-) diff --git a/companion/src/appdata.h b/companion/src/appdata.h index 007f96c42..2d7add453 100644 --- a/companion/src/appdata.h +++ b/companion/src/appdata.h @@ -10,11 +10,296 @@ #define COMPANY "OpenTX Companion" #define PRODUCT "OpenTX" +#define MAX_PROFILES 15 -class AppData +class DataObj { + public: + void store(const QByteArray newArray, QByteArray &array, const char *tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + settings.setValue(tag, newArray); + array = newArray; + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void store(const QStringList newSList, QStringList &stringList, const char *tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + settings.setValue(tag, newSList); + stringList = newSList; + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void store(const QString newString, QString &string, const char *tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + settings.setValue(tag, newString); + string = newString; + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void store(const bool newTruth, bool &truth, const char *tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + settings.setValue(tag, newTruth); + truth = newTruth; + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void store(const int newNumber, int &number, const char *tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + settings.setValue(tag, newNumber); + number = newNumber; + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + // Retrieval functions + void retrieve( QByteArray &array, const char *tag, const char *def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + array = settings.value(tag, def).toByteArray(); + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void retrieve( QStringList &stringList, const char *tag, const char *def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + stringList = settings.value(tag, def).toStringList(); + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void retrieve( QString &string, const char *tag, const char *def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + string = settings.value(tag, def).toString(); + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void retrieve( bool &truth, const char *tag, const bool def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + truth = settings.value(tag, def).toBool(); + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + void retrieve( int &number, const char *tag, const int def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); + + number = settings.value(tag, def).toInt(); + + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } + + // Retrieve and Store functions + void getset( QByteArray &array, const char *tag, const char *def, const QString group1="", const QString group2="" ) + { + retrieve( array, tag, def, group1, group2); + store(array, array, tag, group1, group2); + } + + void getset( QStringList &stringList, const char *tag, const char *def, const QString group1="", const QString group2="" ) + { + retrieve( stringList, tag, def, group1, group2); + store(stringList, stringList, tag, group1, group2); + } + + void getset( QString &string, const char *tag, const char *def, const QString group1="", const QString group2="" ) + { + retrieve( string, tag, def, group1, group2); + store(string, string, tag, group1, group2); + } + + void getset( bool &truth, const char *tag, const bool def, const QString group1="", const QString group2="" ) + { + retrieve( truth, tag, def, group1, group2); + store(truth, truth, tag, group1, group2); + } + + void getset( int &number, const char *tag, const int def, const QString group1="", const QString group2="" ) + { + retrieve( number, tag, def, group1, group2); + store(number, number, tag, group1, group2); + } +}; + +class Profile:DataObj +{ + private: + // Class Internal Variable + int index; + + // Application Variables + QString _firmware; + QString _Name; + QString _sdPath; + QString _SplashFileName; + bool _burnFirmware; + bool _rename_firmware_files; + int _default_channel_order; + int _default_mode; + + // Firmware Variables + QString _Beeper; + QString _countryCode; + QString _currentCalib; + QString _Display; + QString _GSStickMode; + QString _Haptic; + QString _PPM_Multiplier; + QString _Speaker; + QString _StickPotCalib; + QString _TrainerCalib; + QString _VbatCalib; + QString _vBatWarn; + + public: + // All the get declarations + QString firmware() { return _firmware; } + QString Name() { return _Name; } + QString sdPath() { return _sdPath; } + QString SplashFileName() { return _SplashFileName; } + bool burnFirmware() { return _burnFirmware; } + bool rename_firmware_files() { return _rename_firmware_files; } + int default_channel_order() { return _default_channel_order; } + int default_mode() { return _default_mode; } + + QString Beeper() { return _Beeper; } + QString countryCode() { return _countryCode; } + QString currentCalib() { return _currentCalib; } + QString Display() { return _Display; } + QString GSStickMode() { return _GSStickMode; } + QString Haptic() { return _Haptic; } + QString PPM_Multiplier() { return _PPM_Multiplier; } + QString Speaker() { return _Speaker; } + QString StickPotCalib() { return _StickPotCalib; } + QString TrainerCalib() { return _TrainerCalib; } + QString VbatCalib() { return _VbatCalib; } + QString vBatWarn() { return _vBatWarn; } + + + // All the set declarations + void firmware (const QString str) { store(str, _firmware, "firmware" ,"Profiles", QString("profile%1").arg(index));} + void Name (const QString str) { store(str, _Name, "Name" ,"Profiles", QString("profile%1").arg(index));} + void sdPath (const QString str) { store(str, _sdPath, "sdPath" ,"Profiles", QString("profile%1").arg(index));} + void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" ,"Profiles", QString("profile%1").arg(index));} + void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" ,"Profiles", QString("profile%1").arg(index));} + void rename_firmware_files (const bool bl) { store(bl, _rename_firmware_files, "rename_firmware_files" ,"Profiles", QString("profile%1").arg(index));} + void default_channel_order (const int it) { store(it, _default_channel_order, "default_channel_order" ,"Profiles", QString("profile%1").arg(index));} + void default_mode (const int it) { store(it, _default_mode, "default_mode" ,"Profiles", QString("profile%1").arg(index));} + + void Beeper (const QString str) { store(str, _Beeper, "Beeper" ,"Profiles", QString("profile%1").arg(index));} + void countryCode (const QString str) { store(str, _countryCode, "countryCode" ,"Profiles", QString("profile%1").arg(index));} + void currentCalib (const QString str) { store(str, _currentCalib, "currentCalib" ,"Profiles", QString("profile%1").arg(index));} + void Display (const QString str) { store(str, _Display, "Display" ,"Profiles", QString("profile%1").arg(index));} + void GSStickMode (const QString str) { store(str, _GSStickMode, "GSStickMode" ,"Profiles", QString("profile%1").arg(index));} + void Haptic (const QString str) { store(str, _Haptic, "Haptic" ,"Profiles", QString("profile%1").arg(index));} + void PPM_Multiplier (const QString str) { store(str, _PPM_Multiplier, "PPM_Multiplier" ,"Profiles", QString("profile%1").arg(index));} + void Speaker (const QString str) { store(str, _Speaker, "Speaker" ,"Profiles", QString("profile%1").arg(index));} + void StickPotCalib (const QString str) { store(str, _StickPotCalib, "StickPotCalib" ,"Profiles", QString("profile%1").arg(index));} + void TrainerCalib (const QString str) { store(str, _TrainerCalib, "TrainerCalib" ,"Profiles", QString("profile%1").arg(index));} + void VbatCalib (const QString str) { store(str, _VbatCalib, "VbatCalib" ,"Profiles", QString("profile%1").arg(index));} + void vBatWarn (const QString str) { store(str, _vBatWarn, "vBatWarn" ,"Profiles", QString("profile%1").arg(index));} + + // Constructor + Profile() + { + index = -1; + } + + void init(int newIndex) + { + index = newIndex; + + QString pName; + retrieve( pName, "Name", "", "Profiles", QString("profile%1").arg(newIndex)); + if ( newIndex > 1 && pName.isEmpty()) + return; + + // Load and store all variables. Use default values if setting values are missing + + getset( _firmware, "firmware" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _Name, "Name" ,"----" ,"Profiles", QString("profile%1").arg(index)); + getset( _sdPath, "sdPath" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _SplashFileName, "SplashFileName" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _burnFirmware, "burnFirmware" ,false ,"Profiles", QString("profile%1").arg(index)); + getset( _rename_firmware_files, "rename_firmware_files" ,false ,"Profiles", QString("profile%1").arg(index)); + getset( _default_channel_order, "default_channel_order" ,0 ,"Profiles", QString("profile%1").arg(index)); + getset( _default_mode, "default_mode" ,1 ,"Profiles", QString("profile%1").arg(index)); + + getset( _Beeper, "Beeper" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _countryCode, "countryCode" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _currentCalib, "currentCalib" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _Display, "Display" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _GSStickMode, "GSStickMode" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _Haptic, "Haptic" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _PPM_Multiplier, "PPM_Multiplier" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _Speaker, "Speaker" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _StickPotCalib, "StickPotCalib" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _TrainerCalib, "TrainerCalib" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _VbatCalib, "VbatCalib" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _vBatWarn, "vBatWarn" ,"" ,"Profiles", QString("profile%1").arg(index)); + } +}; + +class AppData:DataObj +{ // All the global variables + public: + Profile profile[MAX_PROFILES]; + + private: QStringList _recentFileList; QByteArray _mainWindowGeometry; QByteArray _mainWindowState; @@ -65,101 +350,6 @@ class AppData // Storage functions - void store(const QByteArray newArray, QByteArray &array, const char *tag) - { - QSettings settings(PRODUCT, COMPANY); - settings.setValue(tag, newArray); - array = newArray; - } - - void store(const QStringList newSList, QStringList &stringList, const char *tag) - { - QSettings settings(PRODUCT, COMPANY); - settings.setValue(tag, newSList); - stringList = newSList; - } - - void store(const QString newString, QString &string, const char *tag) - { - QSettings settings(PRODUCT, COMPANY); - settings.setValue(tag, newString); - string = newString; - } - - void store(const bool newTruth, bool &truth, const char *tag) - { - QSettings settings(PRODUCT, COMPANY); - settings.setValue(tag, newTruth); - truth = newTruth; - } - - void store(const int newNumber, int &number, const char *tag) - { - QSettings settings(PRODUCT, COMPANY); - settings.setValue(tag, newNumber); - number = newNumber; - } - - // Retrieval functions - void retrieve( QByteArray &array, const char *tag, const char *def) - { - QSettings settings(PRODUCT, COMPANY); - array = settings.value(tag, def).toByteArray(); - } - void retrieve( QStringList &stringList, const char *tag, const char *def) - { - QSettings settings(PRODUCT, COMPANY); - stringList = settings.value(tag, def).toStringList(); - } - - void retrieve( QString &string, const char *tag, const char *def) - { - QSettings settings(PRODUCT, COMPANY); - string = settings.value(tag, def).toString(); - } - - void retrieve( bool &truth, const char *tag, const bool def) - { - QSettings settings(PRODUCT, COMPANY); - truth = settings.value(tag, def).toBool(); - } - - void retrieve( int &number, const char *tag, const int def) - { - QSettings settings(PRODUCT, COMPANY); - number = settings.value(tag, def).toInt(); - } - - // Retrieve and Store functions - void getset( QByteArray &array, const char *tag, const char *def) - { - retrieve( array, tag, def); - store(array, array, tag); - } - - void getset( QStringList &stringList, const char *tag, const char *def) - { - retrieve( stringList, tag, def); - store(stringList, stringList, tag); - } - - void getset( QString &string, const char *tag, const char *def) - { - retrieve( string, tag, def); - store(string, string, tag); - } - - void getset( bool &truth, const char *tag, const bool def) - { - retrieve( truth, tag, def); - store(truth, truth, tag); - } - - void getset( int &number, const char *tag, const int def) - { - retrieve( number, tag, def); - store(number, number, tag); - } public: // All the get declarations @@ -273,6 +463,12 @@ public: settings.setValue(*i, c9x_settings.value(*i)); } } + + //Initialize the index variables of the profiles + for (int i=0; isdPath->setText(Path); } - ui->profileIndexLE->setText(QString(glob.profileId())); + ui->profileIndexLE->setText(QString("%1").arg(glob.profileId())); ui->profileNameLE->setText(glob.Name()); QString fileName=glob.SplashFileName(); @@ -260,54 +260,34 @@ void appPreferencesDialog::on_sdPathButton_clicked() void appPreferencesDialog::saveProfile() { - QSettings settings; - - QString profile=QString("profile") + glob.profileId(); + // The profile name may NEVER be empty + QString profile=QString("profile") + QString("%1").arg(glob.profileId()); QString name=ui->profileNameLE->text(); if (name.isEmpty()) { name = profile; ui->profileNameLE->setText(name); } - settings.beginGroup("Profiles"); - settings.beginGroup(profile); - settings.setValue("Name",name); - settings.setValue("default_channel_order", ui->channelorderCB->currentIndex()); - settings.setValue("default_mode", ui->stickmodeCB->currentIndex()); - settings.setValue("burnFirmware", ui->burnFirmware->isChecked()); - settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked()); - settings.setValue("sdPath", ui->sdPath->text()); - settings.setValue("SplashFileName", ui->SplashFileName->text()); - settings.setValue("firmware", ui->firmwareLE->text()); - settings.endGroup(); - settings.endGroup(); + glob.profile[glob.profileId()].Name( name ); + glob.profile[glob.profileId()].default_channel_order( ui->channelorderCB->currentIndex()); + glob.profile[glob.profileId()].default_mode( ui->stickmodeCB->currentIndex()); + glob.profile[glob.profileId()].burnFirmware( ui->burnFirmware->isChecked()); + glob.profile[glob.profileId()].rename_firmware_files( ui->renameFirmware->isChecked()); + glob.profile[glob.profileId()].sdPath( ui->sdPath->text()); + glob.profile[glob.profileId()].SplashFileName( ui->SplashFileName->text()); + glob.profile[glob.profileId()].firmware( ui->firmwareLE->text()); } -void appPreferencesDialog::loadProfileString(QString profile, QString label) +void appPreferencesDialog::loadFromProfile() { - QSettings settings; - QString value; - - settings.beginGroup("Profiles"); - settings.beginGroup(profile); - value = settings.value(label).toString(); - settings.endGroup(); - settings.endGroup(); - - settings.setValue( label, value ); -} - -void appPreferencesDialog::loadProfile() -{ - QString profile=QString("profile") + glob.profileId(); - - loadProfileString( profile, "Name" ); - loadProfileString( profile, "default_channel_order" ); - loadProfileString( profile, "default_mode" ); - loadProfileString( profile, "burnFirmware" ); - loadProfileString( profile, "rename_firmware_files" ); - loadProfileString( profile, "sdPath" ); - loadProfileString( profile, "SplashFileName" ); - loadProfileString( profile, "firmware" ); + int i = glob.profileId(); + glob.Name( glob.profile[i].Name() ); + glob.default_channel_order( glob.profile[i].default_channel_order()); + glob.default_mode( glob.profile[i].default_mode()); + glob.burnFirmware( glob.profile[i].burnFirmware()); + glob.rename_firmware_files( glob.profile[i].rename_firmware_files()); + glob.sdPath( glob.profile[i].sdPath()); + glob.SplashFileName( glob.profile[i].SplashFileName()); + glob.firmware( glob.profile[i].firmware()); } void appPreferencesDialog::on_removeProfileButton_clicked() @@ -317,13 +297,13 @@ void appPreferencesDialog::on_removeProfileButton_clicked() QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); else { - QString profile=QString("profile") + glob.profileId(); + QString profile=QString("profile") + QString("%1").arg(glob.profileId()); settings.beginGroup("Profiles"); settings.remove(profile); settings.endGroup(); - settings.setValue("profileId", "1"); + glob.profileId( 1 ); - loadProfile(); + loadFromProfile(); initSettings(); } } diff --git a/companion/src/apppreferencesdialog.h b/companion/src/apppreferencesdialog.h index b6f6c3896..18ce2f1e3 100644 --- a/companion/src/apppreferencesdialog.h +++ b/companion/src/apppreferencesdialog.h @@ -26,7 +26,7 @@ private: bool displayImage( QString fileName ); void saveProfile(); void loadProfileString(QString profile, QString label); - void loadProfile(); + void loadFromProfile(); private slots: void writeValues(); diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 991861451..8d395e570 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -90,23 +90,23 @@ MainWindow::MainWindow(): mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setCentralWidget(mdiArea); - connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), - this, SLOT(updateMenus())); + connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(updateMenus())); windowMapper = new QSignalMapper(this); - connect(windowMapper, SIGNAL(mapped(QWidget*)), - this, SLOT(setActiveSubWindow(QWidget*))); + connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); - MaxRecentFiles=MAX_RECENT; - QSettings settings; - - restoreGeometry(settings.value("mainWindowGeometry").toByteArray()); createActions(); - createMenus(); createToolBars(); createStatusBar(); updateMenus(); - readSettings(); + + restoreState(glob.mainWindowState()); + + if (glob.profileId() == 0) + { + createProfile(); + glob.profileId( 1 ); + } setUnifiedTitleAndToolBarOnMac(true); this->setWindowIcon(QIcon(":/icon.png")); @@ -116,7 +116,7 @@ MainWindow::MainWindow(): // give time to the splash to disappear and main window to open before starting updates int updateDelay = 1000; - bool showSplash = settings.value("show_splash", true).toBool(); + bool showSplash = glob.show_splash(); if (showSplash) { updateDelay += (SPLASH_TIME*1000); } @@ -169,8 +169,7 @@ MainWindow::MainWindow(): void MainWindow::displayWarnings() { - QSettings settings; - int warnId=settings.value("warningId", 0 ).toInt(); + int warnId=glob.warningId(); if (warnId0) { @@ -181,10 +180,10 @@ void MainWindow::displayWarnings() res = QMessageBox::question(this, "Companion",tr("Display previous message again at startup ?"),QMessageBox::Yes | QMessageBox::No); } if (res == QMessageBox::No) { - settings.setValue("warningId", WARNING_ID); + glob.warningId(WARNING_ID); } } else if (warnId==0) { - settings.setValue("warningId", WARNING_ID); + glob.warningId(WARNING_ID); } } @@ -203,12 +202,11 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId) showcheckForUpdatesResult = ignoreSettings; check1done = true; check2done = true; - QSettings settings; fwToUpdate = fwId; QString stamp = GetFirmware(fwToUpdate)->stamp; if (!stamp.isEmpty()) { - if (checkFW || ignoreSettings) { + if (glob.startup_check_fw() || ignoreSettings) { check1done=false; manager1 = new QNetworkAccessManager(this); connect(manager1, SIGNAL(finished(QNetworkReply*)), this, SLOT(reply1Finished(QNetworkReply*))); @@ -219,7 +217,7 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId) } } - if (checkCompanion || ignoreSettings) { + if (glob.startup_check_companion() || ignoreSettings) { check2done = false; manager2 = new QNetworkAccessManager(this); connect(manager2, SIGNAL(finished(QNetworkReply*)),this, SLOT(checkForUpdateFinished(QNetworkReply*))); @@ -269,16 +267,14 @@ void MainWindow::checkForUpdateFinished(QNetworkReply * reply) "Would you like to download it?").arg(version) , QMessageBox::Yes | QMessageBox::No); - QSettings settings; - if (ret == QMessageBox::Yes) { #if defined __APPLE__ - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastUpdatesDir").toString() + QString(C9X_INSTALLER).arg(version)); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version)); #else - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastUpdatesDir").toString() + QString(C9X_INSTALLER).arg(version), tr("Executable (*.exe)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version), tr("Executable (*.exe)")); #endif if (!fileName.isEmpty()) { - settings.setValue("lastUpdatesDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastUpdatesDir(QFileInfo(fileName).dir().absolutePath()); downloadDialog * dd = new downloadDialog(this, QString(OPENTX_COMPANION_DOWNLOADS C9X_INSTALLER).arg(version), fileName); installer_fileName = fileName; connect(dd, SIGNAL(accepted()), this, SLOT(updateDownloaded())); @@ -311,11 +307,10 @@ void MainWindow::updateDownloaded() void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmwareId) { QString url, ext, cpuid; - QSettings settings; url = firmware->getUrl(firmwareId); - cpuid=settings.value("cpuid","").toString(); + cpuid=glob.cpu_id(); ext = url.mid(url.lastIndexOf(".")); - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + firmwareId + ext); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + firmwareId + ext); if (!fileName.isEmpty()) { downloadedFW = firmwareId; needRename=true; @@ -324,7 +319,7 @@ void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmw url.append("&cpuid="); url.append(cpuid); } - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); downloadDialog * dd = new downloadDialog(this, url, fileName); connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted())); dd->exec(); @@ -457,7 +452,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) } QSettings settings; - cpuid=settings.value("cpuid","").toString(); + cpuid=glob.cpu_id(); QByteArray qba = reply->readAll(); int i = qba.indexOf("SVN_VERS"); int warning = qba.indexOf("WARNING"); @@ -471,9 +466,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) if(!cres) { QMessageBox::warning(this, "Companion", tr("Unable to check for updates.")); - int server = settings.value("fwserver",0).toInt(); - server++; - settings.setValue("fwserver",server); + glob.fwserver(glob.fwserver()+1); return; } @@ -571,12 +564,12 @@ void MainWindow::reply1Finished(QNetworkReply * reply) QString url = GetFirmware(fwToUpdate)->getUrl(fwToUpdate); QString ext = url.mid(url.lastIndexOf(".")); needRename=false; - bool addversion=settings.value("rename_firmware_files", false).toBool(); + bool addversion=glob.rename_firmware_files(); QString fileName; if (addversion) { - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + fwToUpdate + newrev + ext); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + newrev + ext); } else { - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + fwToUpdate + ext); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + ext); } if (!fileName.isEmpty()) { if (!cpuid.isEmpty()) { @@ -584,7 +577,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) url.append(cpuid); } downloadedFWFilename = fileName; - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); downloadDialog * dd = new downloadDialog(this, url, fileName); currentFWrev_temp = NewFwRev; connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted())); @@ -598,9 +591,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) } else { if(check1done && check2done) { QMessageBox::warning(this, "Companion", tr("Unable to check for updates.")); - int server = settings.value("fwserver",0).toInt(); - server++; - settings.setValue("fwserver",server); + glob.fwserver(glob.fwserver()+1); return; } } @@ -608,9 +599,8 @@ void MainWindow::reply1Finished(QNetworkReply * reply) void MainWindow::closeEvent(QCloseEvent *event) { - QSettings settings; - settings.setValue("mainWindowGeometry", saveGeometry()); - settings.setValue("mainWindowState", saveState()); + glob.mainWindowGeometry(saveGeometry()); + glob.mainWindowState(saveState()); mdiArea->closeAllSubWindows(); if (mdiArea->currentSubWindow()) { event->ignore(); @@ -622,8 +612,7 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::setLanguage(QString langString) { - QSettings settings; - settings.setValue("locale", langString ); + glob.locale( langString ); QMessageBox msgBox; msgBox.setText(tr("The selected language will be used the next time you start Companion.")); @@ -634,8 +623,7 @@ void MainWindow::setLanguage(QString langString) void MainWindow::setTheme(int index) { - QSettings settings; - settings.setValue("theme", index ); + glob.theme( index ); QMessageBox msgBox; msgBox.setText(tr("The new theme will be loaded the next time you start Companion.")); @@ -646,8 +634,7 @@ void MainWindow::setTheme(int index) void MainWindow::setIconThemeSize(int index) { - QSettings settings; - settings.setValue("icon_size", index ); + glob.icon_size( index ); QMessageBox msgBox; msgBox.setText(tr("The icon size will be used the next time you start Companion.")); @@ -671,10 +658,9 @@ void MainWindow::openDocURL() void MainWindow::openFile() { - QSettings settings; - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastDir").toString(),tr(EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastDir(), tr(EEPROM_FILES_FILTER)); if (!fileName.isEmpty()) { - settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastDir(QFileInfo(fileName).dir().absolutePath()); QMdiSubWindow *existing = findMdiChild(fileName); if (existing) { @@ -704,11 +690,9 @@ void MainWindow::saveAs() void MainWindow::openRecentFile() { - QSettings settings; QAction *action = qobject_cast(sender()); if (action) { QString fileName=action->data().toString(); - // settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); QMdiSubWindow *existing = findMdiChild(fileName); if (existing) { @@ -1113,14 +1097,14 @@ void MainWindow::writeFileToEeprom() burnDialog *cd = new burnDialog(this, 1, &fileName, &backup); cd->exec(); if (!fileName.isEmpty()) { - settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastDir(QFileInfo(fileName).dir().absolutePath()); int ret = QMessageBox::question(this, "Companion", tr("Write Models and settings from %1 to the Tx?").arg(QFileInfo(fileName).fileName()), QMessageBox::Yes | QMessageBox::No); if (ret != QMessageBox::Yes) return; if (!isValidEEPROM(fileName)) ret = QMessageBox::question(this, "Companion", tr("The file %1\nhas not been recognized as a valid Models and Settings file\nWrite anyway ?").arg(QFileInfo(fileName).fileName()), QMessageBox::Yes | QMessageBox::No); if (ret != QMessageBox::Yes) return; - bool backupEnable = settings.value("backupEnable", true).toBool(); - QString backupPath = settings.value("backupPath", "").toString(); + bool backupEnable = glob.backupEnable(); + QString backupPath = glob.backupPath(); if (!backupPath.isEmpty()) { if (!QDir(backupPath).exists()) { if (backupEnable) { @@ -1361,9 +1345,8 @@ bool MainWindow::convertEEPROM(QString backupFile, QString restoreFile, QString void MainWindow::writeFlash(QString fileToFlash) { - QSettings settings; QString fileName; - bool backup = settings.value("backupOnFlash", false).toBool(); + bool backup = glob.backupOnFlash(); if(!fileToFlash.isEmpty()) fileName = fileToFlash; burnDialog *cd = new burnDialog(this, 2, &fileName, &backup); @@ -1371,12 +1354,12 @@ void MainWindow::writeFlash(QString fileToFlash) if (IS_TARANIS(GetEepromInterface()->getBoard())) backup=false; if (!fileName.isEmpty()) { - settings.setValue("backupOnFlash", backup); + glob.backupOnFlash(backup); if (backup) { QString tempDir = QDir::tempPath(); QString backupFile = tempDir + "/backup.bin"; - bool backupEnable=settings.value("backupEnable", true).toBool(); - QString backupPath=settings.value("backupPath", "").toString(); + bool backupEnable=glob.backupEnable(); + QString backupPath=glob.backupPath(); if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) { if (!QDir(backupPath).exists()) { if (backupEnable) { @@ -1430,8 +1413,8 @@ void MainWindow::writeFlash(QString fileToFlash) } } else { - bool backupEnable=settings.value("backupEnable", true).toBool(); - QString backupPath=settings.value("backupPath", "").toString(); + bool backupEnable=glob.backupEnable(); + QString backupPath=glob.backupPath(); if (!QDir(backupPath).exists()) { if (backupEnable) { QMessageBox::warning(this, tr("Backup is impossible"), tr("The backup dir set in preferences does not exist")); @@ -1460,8 +1443,7 @@ void MainWindow::writeFlash(QString fileToFlash) void MainWindow::readEepromToFile() { - QSettings settings; - QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), settings.value("lastDir").toString(), tr(EXTERNAL_EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), glob.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); if (!fileName.isEmpty()) { EEPROMInterface *eepromInterface = GetEepromInterface(); if (IS_TARANIS(eepromInterface->getBoard())) { @@ -1480,7 +1462,7 @@ void MainWindow::readEepromToFile() } } else { - settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastDir(QFileInfo(fileName).dir().absolutePath()); QStringList str = GetReceiveEEpromCommand(fileName); avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Read Models and Settings From Tx")); ad->setWindowIcon(CompanionIcon("read_eeprom.png")); @@ -1492,14 +1474,13 @@ void MainWindow::readEepromToFile() void MainWindow::readFlash() { - QSettings settings; - QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), settings.value("lastFlashDir").toString(),tr(FLASH_FILES_FILTER)); + QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), glob.lastFlashDir(),tr(FLASH_FILES_FILTER)); if (!fileName.isEmpty()) { QFile file(fileName); if (file.exists()) { file.remove(); } - settings.setValue("lastFlashDir",QFileInfo(fileName).dir().absolutePath()); + glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); QStringList str = GetReceiveFlashCommand(fileName); avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Read Firmware From Tx"); ad->setWindowIcon(CompanionIcon("read_flash.png")); @@ -1578,8 +1559,7 @@ void MainWindow::updateMenus() updateIconSizeActions(); updateIconThemeActions(); - QSettings settings; - setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg(settings.value("profileId").toString())); + setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( QString("%1").arg(glob.profileId()) )); } MdiChild *MainWindow::createMdiChild() @@ -1630,7 +1610,7 @@ void MainWindow::createActions() separatorAct = new QAction(this); separatorAct->setSeparator(true); - for (int i = 0; i < MaxRecentFiles; ++i) { + for (int i = 0; i < MAX_RECENT; ++i) { recentFileActs[i] = new QAction(this); recentFileActs[i]->setVisible(false); connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); @@ -1728,7 +1708,7 @@ void MainWindow::createMenus() fileMenu->addAction(saveAsAct); fileMenu->addMenu(recentFileMenu); recentFileMenu->setIcon(CompanionIcon("recentdocument.png")); - for (int i=0; iaddAction(recentFileActs[i]); fileMenu->addSeparator(); fileMenu->addAction(logsAct); @@ -1810,7 +1790,7 @@ void MainWindow::createMenus() QMenu *MainWindow::createRecentFileMenu() { QMenu *recentFileMenu = new QMenu(this); - for ( int i = 0; i < MaxRecentFiles; ++i) + for ( int i = 0; i < MAX_RECENT; ++i) recentFileMenu->addAction(recentFileActs[i]); return recentFileMenu; } @@ -1831,10 +1811,8 @@ QMenu *MainWindow::createProfilesMenu() void MainWindow::createToolBars() { - QSettings settings; - int icon_size=settings.value("icon_size",2 ).toInt(); QSize size; - switch(icon_size) { + switch(glob.icon_size()) { case 0: size=QSize(16,16); break; @@ -1919,20 +1897,6 @@ void MainWindow::createStatusBar() statusBar()->showMessage(tr("Ready")); } -void MainWindow::readSettings() -{ - QSettings settings; - restoreState(settings.value("mainWindowState").toByteArray()); - checkCompanion = settings.value("startup_check_companion", true).toBool(); - checkFW = settings.value("startup_check_fw", true).toBool(); - MaxRecentFiles =settings.value("history_size",10).toInt(); - if (settings.value("profileId",0).toInt() == 0) - { - createProfile(); - settings.setValue("profileId", "1"); - } -} - MdiChild *MainWindow::activeMdiChild() { if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow()) @@ -1965,7 +1929,7 @@ void MainWindow::updateRecentFileActions() QSettings settings; QStringList files = settings.value("recentFileList").toStringList(); - numRecentFiles = qMin(files.size(), (int)MaxRecentFiles); + numRecentFiles = qMin(files.size(), glob.history_size()); for ( i = 0; i < numRecentFiles; ++i) { QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i])); @@ -1973,15 +1937,14 @@ void MainWindow::updateRecentFileActions() recentFileActs[i]->setData(files[i]); recentFileActs[i]->setVisible(true); } - for ( j = numRecentFiles; j < MaxRecentFiles; ++j) + for ( j = numRecentFiles; j < glob.history_size(); ++j) recentFileActs[j]->setVisible(false); } void MainWindow::updateIconSizeActions() { - QSettings settings; - int size = settings.value("icon_size","0").toInt(); - switch (size){ + switch (glob.icon_size()) + { case 0: smallIconAct->setChecked(true); break; case 1: normalIconAct->setChecked(true); break; case 2: bigIconAct->setChecked(true); break; @@ -1991,8 +1954,7 @@ void MainWindow::updateIconSizeActions() void MainWindow::updateLanguageActions() { - QSettings settings; - QString langId = settings.value("locale","").toString(); + QString langId = glob.locale(); if (langId=="") sysLangAct->setChecked(true); @@ -2022,9 +1984,8 @@ void MainWindow::updateLanguageActions() void MainWindow::updateIconThemeActions() { - QSettings settings; - int size = settings.value("theme","1").toInt(); - switch (size){ + switch (glob.theme()) + { case 0: classicThemeAct->setChecked(true); break; case 1: newThemeAct->setChecked(true); break; case 2: monoWhiteAct->setChecked(true); break; @@ -2037,7 +1998,7 @@ void MainWindow::updateProfilesActions() { int i; QSettings settings; - int activeProfile = settings.value("profileId").toInt(); + int activeProfile = glob.profileId(); settings.beginGroup("Profiles"); for (i=0; i Date: Mon, 17 Feb 2014 15:28:50 +0100 Subject: [PATCH 04/13] Profiles working. Next all duplicated variables will be removed from global and only exists in profile. --- companion/src/appdata.h | 84 ++++++++++++++---- companion/src/apppreferencesdialog.cpp | 78 ++++++---------- companion/src/apppreferencesdialog.ui | 74 ++++++++-------- companion/src/mainwindow.cpp | 118 +++++++++---------------- 4 files changed, 173 insertions(+), 181 deletions(-) diff --git a/companion/src/appdata.h b/companion/src/appdata.h index 2d7add453..0a1d33589 100644 --- a/companion/src/appdata.h +++ b/companion/src/appdata.h @@ -230,8 +230,12 @@ class Profile:DataObj // All the set declarations + void Name (const QString str) { if (str.isEmpty()) // Name may never be empty! + store("----", _Name, "Name" ,"Profiles", QString("profile%1").arg(index)); + else + store(str, _Name, "Name" ,"Profiles", QString("profile%1").arg(index));} + void firmware (const QString str) { store(str, _firmware, "firmware" ,"Profiles", QString("profile%1").arg(index));} - void Name (const QString str) { store(str, _Name, "Name" ,"Profiles", QString("profile%1").arg(index));} void sdPath (const QString str) { store(str, _sdPath, "sdPath" ,"Profiles", QString("profile%1").arg(index));} void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" ,"Profiles", QString("profile%1").arg(index));} void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" ,"Profiles", QString("profile%1").arg(index));} @@ -258,17 +262,33 @@ class Profile:DataObj index = -1; } - void init(int newIndex) + void remove() + { + // Remove all profile values from settings file + QSettings settings(PRODUCT, COMPANY); + settings.beginGroup("Profiles"); + settings.remove(QString("profile%1").arg(index)); + settings.endGroup(); + + // Reset all profile variables to initial values + init(index); + } + + bool existsOnDisk() { - index = newIndex; + QSettings settings(PRODUCT, COMPANY); + settings.beginGroup("Profiles"); + settings.beginGroup(QString("profile%1").arg(index)); + QStringList keyList = settings.allKeys(); + settings.endGroup(); + settings.endGroup(); - QString pName; - retrieve( pName, "Name", "", "Profiles", QString("profile%1").arg(newIndex)); - if ( newIndex > 1 && pName.isEmpty()) - return; + return (keyList.length() > 0); + } + void flush() + { // Load and store all variables. Use default values if setting values are missing - getset( _firmware, "firmware" ,"" ,"Profiles", QString("profile%1").arg(index)); getset( _Name, "Name" ,"----" ,"Profiles", QString("profile%1").arg(index)); getset( _sdPath, "sdPath" ,"" ,"Profiles", QString("profile%1").arg(index)); @@ -289,7 +309,43 @@ class Profile:DataObj getset( _StickPotCalib, "StickPotCalib" ,"" ,"Profiles", QString("profile%1").arg(index)); getset( _TrainerCalib, "TrainerCalib" ,"" ,"Profiles", QString("profile%1").arg(index)); getset( _VbatCalib, "VbatCalib" ,"" ,"Profiles", QString("profile%1").arg(index)); - getset( _vBatWarn, "vBatWarn" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _vBatWarn, "vBatWarn" ,"" ,"Profiles", QString("profile%1").arg(index)); + } + + void init(int newIndex) + { + index = newIndex; + + _firmware = ""; + _Name = ""; + _sdPath = ""; + _SplashFileName = ""; + _burnFirmware = false; + _rename_firmware_files = false; + _default_channel_order = 0; + _default_mode = 1; + + _Beeper = ""; + _countryCode = ""; + _currentCalib = ""; + _Display = ""; + _GSStickMode = ""; + _Haptic = ""; + _PPM_Multiplier = ""; + _Speaker = ""; + _StickPotCalib = ""; + _TrainerCalib = ""; + _VbatCalib = ""; + _vBatWarn = ""; + + QString pName; + retrieve( pName, "Name", "", "Profiles", QString("profile%1").arg(index)); + + // Do not write empty profiles to disk except the default (0) profile. + if ( index > 0 && !existsOnDisk()) + return; + + flush(); } }; @@ -307,7 +363,6 @@ class AppData:DataObj QString _firmware; QString _locale; QString _cpu_id; - QString _SplashImage; QString _Name; QString _SplashFileName; QString _modelEditGeometry; @@ -360,7 +415,6 @@ public: QString firmware() { return _firmware; } QString locale() { return _locale; } QString cpu_id() { return _cpu_id; } - QString SplashImage() { return _SplashImage; } QString Name() { return _Name; } QString SplashFileName() { return _SplashFileName; } QString modelEditGeometry() { return _modelEditGeometry; } @@ -409,7 +463,6 @@ public: void firmware (const QString str) { store(str, _firmware, "firmware" );} void locale (const QString str) { store(str, _locale, "locale" );} void cpu_id (const QString str) { store(str, _cpu_id, "cpu_id" );} - void SplashImage (const QString str) { store(str, _SplashImage, "SplashImage" );} void Name (const QString str) { store(str, _Name, "Name" );} void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" );} void modelEditGeometry (const QString str) { store(str, _modelEditGeometry, "modelEditGeometry" );} @@ -466,7 +519,7 @@ public: //Initialize the index variables of the profiles for (int i=0; iprofileNameLE->text()); glob.sdPath(ui->sdPath->text()); glob.SplashFileName(ui->SplashFileName->text()); - if (!ui->SplashFileName->text().isEmpty()) - glob.SplashImage(""); glob.firmware(ui->firmwareLE->text()); saveProfile(); @@ -85,13 +83,10 @@ void appPreferencesDialog::initSettings() { ui->snapshotClipboardCKB->setChecked(glob.snapshot_to_clipboard()); ui->burnFirmware->setChecked(glob.burnFirmware()); - - QString Path=glob.snapshotpath(); - if (QDir(Path).exists()) { - ui->snapshotPath->setText(Path); - ui->snapshotPath->setReadOnly(true); - } - if (ui->snapshotClipboardCKB->isChecked()) { + ui->snapshotPath->setText(glob.snapshotpath()); + ui->snapshotPath->setReadOnly(true); + if (ui->snapshotClipboardCKB->isChecked()) + { ui->snapshotPath->setDisabled(true); ui->snapshotPathButton->setDisabled(true); } @@ -102,19 +97,12 @@ void appPreferencesDialog::initSettings() ui->historySize->setValue(glob.history_size()); ui->backLightColor->setCurrentIndex(glob.backLight()); ui->simuSW->setChecked(glob.simuSW()); + ui->libraryPath->setText(glob.libraryPath()); + ui->ge_lineedit->setText(glob.gePath()); - Path=glob.libraryPath(); - if (QDir(Path).exists()) { - ui->libraryPath->setText(Path); - } - Path=glob.gePath(); - if (QFile(Path).exists()) { - ui->ge_lineedit->setText(Path); - } - Path=glob.backupPath(); - if (!Path.isEmpty()) { - if (QDir(Path).exists()) { - ui->backupPath->setText(Path); + if (!glob.backupPath().isEmpty()) { + if (QDir(glob.backupPath()).exists()) { + ui->backupPath->setText(glob.backupPath()); ui->backupEnable->setEnabled(true); ui->backupEnable->setChecked(glob.backupEnable()); } else { @@ -156,22 +144,12 @@ void appPreferencesDialog::initSettings() ui->channelorderCB->setCurrentIndex(glob.default_channel_order()); ui->stickmodeCB->setCurrentIndex(glob.default_mode()); ui->renameFirmware->setChecked(glob.rename_firmware_files()); - Path=glob.sdPath(); - if (QDir(Path).exists()) { - ui->sdPath->setText(Path); - } + ui->sdPath->setText(glob.sdPath()); ui->profileIndexLE->setText(QString("%1").arg(glob.profileId())); ui->profileNameLE->setText(glob.Name()); - - QString fileName=glob.SplashFileName(); - if (!fileName.isEmpty()) { - QFile file(fileName); - if (file.exists()){ - ui->SplashFileName->setText(fileName); - displayImage( fileName ); - } - } ui->firmwareLE->setText(glob.firmware()); + ui->SplashFileName->setText(glob.SplashFileName()); + displayImage( glob.SplashFileName() ); } void appPreferencesDialog::on_libraryPathButton_clicked() @@ -261,13 +239,10 @@ void appPreferencesDialog::on_sdPathButton_clicked() void appPreferencesDialog::saveProfile() { // The profile name may NEVER be empty - QString profile=QString("profile") + QString("%1").arg(glob.profileId()); - QString name=ui->profileNameLE->text(); - if (name.isEmpty()) { - name = profile; - ui->profileNameLE->setText(name); - } - glob.profile[glob.profileId()].Name( name ); + if (ui->profileNameLE->text().isEmpty()) + ui->profileNameLE->setText("----"); + + glob.profile[glob.profileId()].Name( ui->profileNameLE->text() ); glob.profile[glob.profileId()].default_channel_order( ui->channelorderCB->currentIndex()); glob.profile[glob.profileId()].default_mode( ui->stickmodeCB->currentIndex()); glob.profile[glob.profileId()].burnFirmware( ui->burnFirmware->isChecked()); @@ -293,16 +268,12 @@ void appPreferencesDialog::loadFromProfile() void appPreferencesDialog::on_removeProfileButton_clicked() { QSettings settings; - if ( glob.profileId() == 1 ) + if ( glob.profileId() == 0 ) QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); else { - QString profile=QString("profile") + QString("%1").arg(glob.profileId()); - settings.beginGroup("Profiles"); - settings.remove(profile); - settings.endGroup(); - glob.profileId( 1 ); - + glob.profile[glob.profileId()].remove(); + glob.profileId( 0 ); loadFromProfile(); initSettings(); } @@ -310,6 +281,9 @@ void appPreferencesDialog::on_removeProfileButton_clicked() bool appPreferencesDialog::displayImage( QString fileName ) { + // Start by filling the pixmap with white + ui->imageLabel->setPixmap(QPixmap()); + QImage image(fileName); if (image.isNull()) return false; @@ -361,11 +335,11 @@ void appPreferencesDialog::on_SplashSelect_clicked() QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); - if (!fileName.isEmpty()) { + if (!fileName.isEmpty()){ glob.lastImagesDir(QFileInfo(fileName).dir().absolutePath()); - - if (displayImage(fileName)) - ui->SplashFileName->setText(fileName); + + displayImage(fileName); + ui->SplashFileName->setText(fileName); } } diff --git a/companion/src/apppreferencesdialog.ui b/companion/src/apppreferencesdialog.ui index 9a7680a42..c15874915 100644 --- a/companion/src/apppreferencesdialog.ui +++ b/companion/src/apppreferencesdialog.ui @@ -7,7 +7,7 @@ 0 0 685 - 462 + 446 @@ -839,16 +839,6 @@ This is used by the templated to determine which channel goes to what number out - - - - - 0 - 0 - - - - @@ -872,7 +862,35 @@ This is used by the templated to determine which channel goes to what number out - + + + + Firmware + + + + + + + false + + + + + + + Select Image + + + + + + + Clear Image + + + + false @@ -885,17 +903,13 @@ This is used by the templated to determine which channel goes to what number out - - - - Firmware - - - - - - - false + + + + + 0 + 0 + @@ -933,20 +947,6 @@ This is used by the templated to determine which channel goes to what number out - - - - Select Image - - - - - - - Clear Image - - - diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 8d395e570..8918796be 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -102,12 +102,6 @@ MainWindow::MainWindow(): restoreState(glob.mainWindowState()); - if (glob.profileId() == 0) - { - createProfile(); - glob.profileId( 1 ); - } - setUnifiedTitleAndToolBarOnMac(true); this->setWindowIcon(QIcon(":/icon.png")); this->setIconSize(QSize(32,32)); @@ -708,42 +702,33 @@ void MainWindow::openRecentFile() } } -void MainWindow::loadProfile() +void MainWindow::loadProfile() //TODO Load all variables - Also HW! { - QSettings settings; QAction *action = qobject_cast(sender()); if (action) { + // Set the new profile number int profnum=action->data().toInt(); - QSettings settings; - settings.setValue("profileId",profnum); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profnum); - settings.beginGroup(profile); - QString profileName=settings.value("Name", "").toString(); - int chord=settings.value("default_channel_order", 0).toInt(); - int defmod=settings.value("default_mode", 0).toInt(); - bool burnfw=settings.value("burnFirmware", false).toBool(); - QString sdPath=settings.value("sdPath", ".").toString(); - bool renfw=settings.value("rename_firmware_files", false).toBool(); - QString SplashFileName=settings.value("SplashFileName","").toString(); - QString SplashImage=settings.value("SplashImage", "").toString(); - QString firmware_id=settings.value("firmware", default_firmware_variant.id).toString(); - firmware_id.replace("open9x","opentx"); - firmware_id.replace("x9da","taranis"); - settings.setValue("firmware", firmware_id); - settings.endGroup(); - settings.endGroup(); - settings.setValue("Name", profileName ); - settings.setValue("default_channel_order", chord); - settings.setValue("default_mode", defmod); - settings.setValue("burnFirmware", burnfw); - settings.setValue("rename_firmware_files", renfw); - settings.setValue("sdPath", sdPath); - settings.setValue("SplashFileName", SplashFileName); - settings.setValue("SplashImage", SplashImage); - settings.setValue("firmware", firmware_id); - current_firmware_variant = GetFirmwareVariant(firmware_id); + glob.profileId( profnum ); + + // Upgrade old firmware names + QString firmware = glob.profile[profnum].firmware(); + firmware.replace("open9x","opentx"); + firmware.replace("x9da","taranis"); + glob.profile[profnum].firmware(firmware); + + // Copy profile data from profile to main variables + glob.Name( glob.profile[profnum].Name() ); + glob.default_channel_order( glob.profile[profnum].default_channel_order() ); + glob.default_mode( glob.profile[profnum].default_mode() ); + glob.burnFirmware( glob.profile[profnum].burnFirmware() ); + glob.rename_firmware_files( glob.profile[profnum].rename_firmware_files() ); + glob.sdPath( glob.profile[profnum].sdPath() ); + glob.SplashFileName( glob.profile[profnum].SplashFileName() ); + glob.firmware( glob.profile[profnum].firmware() ); + + // TODO Get rid of this global variable - glob.firmware is the real source + current_firmware_variant = GetFirmwareVariant(glob.firmware()); foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { MdiChild *mdiChild = qobject_cast(window->widget()); @@ -1091,7 +1076,6 @@ void MainWindow::readEeprom() void MainWindow::writeFileToEeprom() { - QSettings settings; QString fileName; bool backup = false; burnDialog *cd = new burnDialog(this, 1, &fileName, &backup); @@ -1559,7 +1543,7 @@ void MainWindow::updateMenus() updateIconSizeActions(); updateIconThemeActions(); - setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( QString("%1").arg(glob.profileId()) )); + setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( glob.Name() )); } MdiChild *MainWindow::createMdiChild() @@ -1802,8 +1786,8 @@ QMenu *MainWindow::createProfilesMenu() for ( i = 0; i < MAX_PROFILES; ++i) { profilesMenu->addAction(profileActs[i]); } - if ( i>0 ) - profilesMenu->addSeparator(); + profilesMenu->addSeparator(); + profilesMenu->addAction(createProfileAct); profilesMenu->setIcon(CompanionIcon("profiles.png")); return profilesMenu; @@ -1996,52 +1980,34 @@ void MainWindow::updateIconThemeActions() void MainWindow::updateProfilesActions() { - int i; - QSettings settings; - int activeProfile = glob.profileId(); - - settings.beginGroup("Profiles"); - for (i=0; isetText(text); - profileActs[i]->setData(i+1); + profileActs[i]->setData(i); profileActs[i]->setVisible(true); - if ((i+1) == activeProfile) + if (i == glob.profileId()) profileActs[i]->setChecked(true); } - else { + else + { profileActs[i]->setVisible(false); } - settings.endGroup(); } } void MainWindow::createProfile() -{ - int firstFreeIndex = 0; - QSettings settings; - settings.beginGroup("Profiles"); - for (int i=0; firstFreeIndex ==0 && i Date: Mon, 17 Feb 2014 23:47:40 +0100 Subject: [PATCH 05/13] Almost all global settings wrapped in protective object to guarantee type safety and protect against tag spelling errors (I have found and corrected a lot of those!). Joystick settings and burner configuration is not yet within the global object. --- companion/src/appdata.h | 99 +-- companion/src/apppreferencesdialog.cpp | 86 +-- companion/src/burndialog.cpp | 49 +- companion/src/customizesplashdialog.cpp | 34 +- companion/src/eeprominterface.cpp | 9 +- companion/src/fwpreferencesdialog.cpp | 22 +- companion/src/helpers.cpp | 4 +- companion/src/lcdwidget.h | 6 +- companion/src/logsdialog.cpp | 12 +- companion/src/main.cpp | 14 +- companion/src/mainwindow.cpp | 65 +- companion/src/mainwindow.h | 1 - companion/src/mdichild.cpp | 44 +- companion/src/preferencesdialog.cpp | 827 ------------------------ companion/src/preferencesdialog.h | 65 -- companion/src/simulatordialog.cpp | 12 +- companion/src/splashlibrary.cpp | 7 +- companion/src/xsimulatordialog.cpp | 4 +- 18 files changed, 204 insertions(+), 1156 deletions(-) delete mode 100644 companion/src/preferencesdialog.cpp delete mode 100644 companion/src/preferencesdialog.h diff --git a/companion/src/appdata.h b/companion/src/appdata.h index 0a1d33589..044bc9b48 100644 --- a/companion/src/appdata.h +++ b/companion/src/appdata.h @@ -187,6 +187,7 @@ class Profile:DataObj QString _SplashFileName; bool _burnFirmware; bool _rename_firmware_files; + bool _patchImage; int _default_channel_order; int _default_mode; @@ -212,6 +213,7 @@ class Profile:DataObj QString SplashFileName() { return _SplashFileName; } bool burnFirmware() { return _burnFirmware; } bool rename_firmware_files() { return _rename_firmware_files; } + bool patchImage() { return _patchImage; } int default_channel_order() { return _default_channel_order; } int default_mode() { return _default_mode; } @@ -240,6 +242,7 @@ class Profile:DataObj void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" ,"Profiles", QString("profile%1").arg(index));} void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" ,"Profiles", QString("profile%1").arg(index));} void rename_firmware_files (const bool bl) { store(bl, _rename_firmware_files, "rename_firmware_files" ,"Profiles", QString("profile%1").arg(index));} + void patchImage (const bool bl) { store(bl, _patchImage, "patchImage" ,"Profiles", QString("profile%1").arg(index));} void default_channel_order (const int it) { store(it, _default_channel_order, "default_channel_order" ,"Profiles", QString("profile%1").arg(index));} void default_mode (const int it) { store(it, _default_mode, "default_mode" ,"Profiles", QString("profile%1").arg(index));} @@ -295,6 +298,7 @@ class Profile:DataObj getset( _SplashFileName, "SplashFileName" ,"" ,"Profiles", QString("profile%1").arg(index)); getset( _burnFirmware, "burnFirmware" ,false ,"Profiles", QString("profile%1").arg(index)); getset( _rename_firmware_files, "rename_firmware_files" ,false ,"Profiles", QString("profile%1").arg(index)); + getset( _patchImage, "patchImage" ,false ,"Profiles", QString("profile%1").arg(index)); getset( _default_channel_order, "default_channel_order" ,0 ,"Profiles", QString("profile%1").arg(index)); getset( _default_mode, "default_mode" ,1 ,"Profiles", QString("profile%1").arg(index)); @@ -322,6 +326,7 @@ class Profile:DataObj _SplashFileName = ""; _burnFirmware = false; _rename_firmware_files = false; + _patchImage = false; _default_channel_order = 0; _default_mode = 1; @@ -353,18 +358,16 @@ class AppData:DataObj { // All the global variables public: - Profile profile[MAX_PROFILES]; + Profile pro[MAX_PROFILES]; - private: + private: QStringList _recentFileList; QByteArray _mainWindowGeometry; QByteArray _mainWindowState; - QString _firmware; QString _locale; QString _cpu_id; - QString _Name; - QString _SplashFileName; + QString _lastFw; QString _modelEditGeometry; QString _backupPath; @@ -372,16 +375,15 @@ class AppData:DataObj QString _lastDir; QString _lastFlashDir; QString _lastImagesDir; + QString _lastLogDir; QString _libraryPath; - QString _sdPath; QString _snapshotpath; bool _backupEnable; bool _backupOnFlash; - bool _burnFirmware; bool _maximized; bool _js_support; - bool _rename_firmware_files; + bool _rev4asupport; bool _show_splash; bool _snapshot_to_clipboard; bool _startup_check_companion; @@ -390,8 +392,6 @@ class AppData:DataObj bool _wizardEnable; int _backLight; - int _default_channel_order; - int _default_mode; int _embedded_splashes; // Shouldn't this be bool ?? int _fwserver; int _generalEditTab; @@ -403,8 +403,6 @@ class AppData:DataObj int _theme; int _warningId; - // Storage functions - public: // All the get declarations @@ -412,11 +410,9 @@ public: QByteArray mainWindowGeometry(){ return _mainWindowGeometry; } QByteArray mainWindowState() { return _mainWindowState; } - QString firmware() { return _firmware; } QString locale() { return _locale; } QString cpu_id() { return _cpu_id; } - QString Name() { return _Name; } - QString SplashFileName() { return _SplashFileName; } + QString lastFw() { return _lastFw; } QString modelEditGeometry() { return _modelEditGeometry; } QString backupPath() { return _backupPath; } @@ -424,16 +420,15 @@ public: QString lastDir() { return _lastDir; } QString lastFlashDir() { return _lastFlashDir; } QString lastImagesDir() { return _lastImagesDir; } + QString lastLogDir() { return _lastLogDir; } QString libraryPath() { return _libraryPath; } - QString sdPath() { return _sdPath; } QString snapshotpath() { return _snapshotpath; } bool backupEnable() { return _backupEnable; } bool backupOnFlash() { return _backupOnFlash; } - bool burnFirmware() { return _burnFirmware; } bool js_support() { return _js_support; } + bool rev4asupport() { return _rev4asupport; } bool maximized() { return _maximized; } - bool rename_firmware_files() { return _rename_firmware_files; } bool show_splash() { return _show_splash; } bool snapshot_to_clipboard() { return _snapshot_to_clipboard; } bool startup_check_companion() { return _startup_check_companion;} @@ -442,8 +437,6 @@ public: bool wizardEnable() { return _wizardEnable; } int backLight() { return _backLight; } - int default_channel_order() { return _default_channel_order; } - int default_mode() { return _default_mode; } int embedded_splashes() { return _embedded_splashes; } int fwserver() { return _fwserver; } int generalEditTab() { return _generalEditTab; } @@ -455,16 +448,14 @@ public: int theme() { return _theme; } int warningId() { return _warningId; } - // All the set declarations +// All the set declarations void recentFileList (const QStringList l) { store(l, _recentFileList, "recentFileList" );} void mainWindowGeometry (const QByteArray a) { store(a, _mainWindowGeometry, "mainWindowGeometry");} void mainWindowState (const QByteArray a) { store(a, _mainWindowState, "mainWindowState" );} - void firmware (const QString str) { store(str, _firmware, "firmware" );} void locale (const QString str) { store(str, _locale, "locale" );} void cpu_id (const QString str) { store(str, _cpu_id, "cpu_id" );} - void Name (const QString str) { store(str, _Name, "Name" );} - void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" );} + void lastFw (const QString str) { store(str, _lastFw, "lastFw" );} void modelEditGeometry (const QString str) { store(str, _modelEditGeometry, "modelEditGeometry" );} void backupPath (const QString str) { store(str, _backupPath, "backupPath" );} @@ -472,16 +463,15 @@ public: void lastDir (const QString str) { store(str, _lastDir, "lastDir" );} void lastFlashDir (const QString str) { store(str, _lastFlashDir, "lastFlashDir" );} void lastImagesDir (const QString str) { store(str, _lastImagesDir, "lastImagesDir" );} + void lastLogDir (const QString str) { store(str, _lastLogDir, "lastLogDir" );} void libraryPath (const QString str) { store(str, _libraryPath, "libraryPath" );} - void sdPath (const QString str) { store(str, _sdPath, "sdPath" );} void snapshotpath (const QString str) { store(str, _snapshotpath, "snapshotpath" );} void backupEnable (const bool bl) { store(bl, _backupEnable, "backupEnable" );} void backupOnFlash (const bool bl) { store(bl, _backupOnFlash, "backupOnFlash" );} - void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" );} void maximized (const bool bl) { store(bl, _maximized, "maximized" );} void js_support (const bool bl) { store(bl, _js_support, "js_support" );} - void rename_firmware_files (const bool bl) { store(bl, _rename_firmware_files, "rename_firmware_files" );} + void rev4asupport (const bool bl) { store(bl, _rev4asupport, "rev4asupport" );} void show_splash (const bool bl) { store(bl, _show_splash, "show_splash" );} void snapshot_to_clipboard (const bool bl) { store(bl, _snapshot_to_clipboard, "snapshot_to_clipboard" );} void startup_check_companion (const bool bl) { store(bl, _startup_check_companion, "startup_check_companion" );} @@ -490,8 +480,6 @@ public: void wizardEnable (const bool bl) { store(bl, _wizardEnable, "wizardEnable" );} void backLight (const int it) { store(it, _backLight, "backLight" );} - void default_channel_order (const int it) { store(it, _default_channel_order, "default_channel_order" );} - void default_mode (const int it) { store(it, _default_mode, "default_mode" );} void embedded_splashes (const int it) { store(it, _embedded_splashes, "embedded_splashes" );} void fwserver (const int it) { store(it, _fwserver, "fwserver" );} void generalEditTab (const int it) { store(it, _generalEditTab, "generalEditTab" );} @@ -506,22 +494,48 @@ public: // Constructor AppData() { - // Start by hijacking all left over settings from companion9x, but only do it one time + //Initialize the profiles + for (int i=0; ichannelorderCB->currentIndex()); - glob.default_mode(ui->stickmodeCB->currentIndex()); - glob.rename_firmware_files(ui->renameFirmware->isChecked()); - glob.burnFirmware(ui->burnFirmware->isChecked()); glob.profileId(ui->profileIndexLE->text().toInt()); - glob.Name(ui->profileNameLE->text()); - glob.sdPath(ui->sdPath->text()); - glob.SplashFileName(ui->SplashFileName->text()); - glob.firmware(ui->firmwareLE->text()); + + glob.pro[glob.profileId()].default_channel_order(ui->channelorderCB->currentIndex()); + glob.pro[glob.profileId()].default_mode(ui->stickmodeCB->currentIndex()); + glob.pro[glob.profileId()].rename_firmware_files(ui->renameFirmware->isChecked()); + glob.pro[glob.profileId()].burnFirmware(ui->burnFirmware->isChecked()); + glob.pro[glob.profileId()].Name(ui->profileNameLE->text()); + glob.pro[glob.profileId()].sdPath(ui->sdPath->text()); + glob.pro[glob.profileId()].SplashFileName(ui->SplashFileName->text()); + glob.pro[glob.profileId()].firmware(ui->firmwareLE->text()); saveProfile(); } @@ -82,7 +84,7 @@ void appPreferencesDialog::on_snapshotPathButton_clicked() void appPreferencesDialog::initSettings() { ui->snapshotClipboardCKB->setChecked(glob.snapshot_to_clipboard()); - ui->burnFirmware->setChecked(glob.burnFirmware()); + ui->burnFirmware->setChecked(glob.pro[glob.profileId()].burnFirmware()); ui->snapshotPath->setText(glob.snapshotpath()); ui->snapshotPath->setReadOnly(true); if (ui->snapshotClipboardCKB->isChecked()) @@ -141,15 +143,15 @@ void appPreferencesDialog::initSettings() } #endif // Profile Tab Inits - ui->channelorderCB->setCurrentIndex(glob.default_channel_order()); - ui->stickmodeCB->setCurrentIndex(glob.default_mode()); - ui->renameFirmware->setChecked(glob.rename_firmware_files()); - ui->sdPath->setText(glob.sdPath()); + ui->channelorderCB->setCurrentIndex(glob.pro[glob.profileId()].default_channel_order()); + ui->stickmodeCB->setCurrentIndex(glob.pro[glob.profileId()].default_mode()); + ui->renameFirmware->setChecked(glob.pro[glob.profileId()].rename_firmware_files()); + ui->sdPath->setText(glob.pro[glob.profileId()].sdPath()); ui->profileIndexLE->setText(QString("%1").arg(glob.profileId())); - ui->profileNameLE->setText(glob.Name()); - ui->firmwareLE->setText(glob.firmware()); - ui->SplashFileName->setText(glob.SplashFileName()); - displayImage( glob.SplashFileName() ); + ui->profileNameLE->setText(glob.pro[glob.profileId()].Name()); + ui->firmwareLE->setText(glob.pro[glob.profileId()].firmware()); + ui->SplashFileName->setText(glob.pro[glob.profileId()].SplashFileName()); + displayImage( glob.pro[glob.profileId()].SplashFileName() ); } void appPreferencesDialog::on_libraryPathButton_clicked() @@ -230,7 +232,7 @@ void appPreferencesDialog::on_joystickcalButton_clicked() { void appPreferencesDialog::on_sdPathButton_clicked() { - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), glob.sdPath()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), glob.pro[glob.profileId()].sdPath()); if (!fileName.isEmpty()) { ui->sdPath->setText(fileName); } @@ -242,63 +244,41 @@ void appPreferencesDialog::saveProfile() if (ui->profileNameLE->text().isEmpty()) ui->profileNameLE->setText("----"); - glob.profile[glob.profileId()].Name( ui->profileNameLE->text() ); - glob.profile[glob.profileId()].default_channel_order( ui->channelorderCB->currentIndex()); - glob.profile[glob.profileId()].default_mode( ui->stickmodeCB->currentIndex()); - glob.profile[glob.profileId()].burnFirmware( ui->burnFirmware->isChecked()); - glob.profile[glob.profileId()].rename_firmware_files( ui->renameFirmware->isChecked()); - glob.profile[glob.profileId()].sdPath( ui->sdPath->text()); - glob.profile[glob.profileId()].SplashFileName( ui->SplashFileName->text()); - glob.profile[glob.profileId()].firmware( ui->firmwareLE->text()); -} - -void appPreferencesDialog::loadFromProfile() -{ - int i = glob.profileId(); - glob.Name( glob.profile[i].Name() ); - glob.default_channel_order( glob.profile[i].default_channel_order()); - glob.default_mode( glob.profile[i].default_mode()); - glob.burnFirmware( glob.profile[i].burnFirmware()); - glob.rename_firmware_files( glob.profile[i].rename_firmware_files()); - glob.sdPath( glob.profile[i].sdPath()); - glob.SplashFileName( glob.profile[i].SplashFileName()); - glob.firmware( glob.profile[i].firmware()); + glob.pro[glob.profileId()].Name( ui->profileNameLE->text() ); + glob.pro[glob.profileId()].default_channel_order( ui->channelorderCB->currentIndex()); + glob.pro[glob.profileId()].default_mode( ui->stickmodeCB->currentIndex()); + glob.pro[glob.profileId()].burnFirmware( ui->burnFirmware->isChecked()); + glob.pro[glob.profileId()].rename_firmware_files( ui->renameFirmware->isChecked()); + glob.pro[glob.profileId()].sdPath( ui->sdPath->text()); + glob.pro[glob.profileId()].SplashFileName( ui->SplashFileName->text()); + glob.pro[glob.profileId()].firmware( ui->firmwareLE->text()); } void appPreferencesDialog::on_removeProfileButton_clicked() { - QSettings settings; if ( glob.profileId() == 0 ) QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); else { - glob.profile[glob.profileId()].remove(); + glob.pro[glob.profileId()].remove(); glob.profileId( 0 ); - loadFromProfile(); initSettings(); } } bool appPreferencesDialog::displayImage( QString fileName ) { - // Start by filling the pixmap with white + // Start by clearing the pixmap ui->imageLabel->setPixmap(QPixmap()); QImage image(fileName); if (image.isNull()) return false; -// This code below just figures out if the width of the latest firmware is 128 or 212. It works , but... - QString filePath1 = glob.lastFlashDir() + "/" + glob.firmware() + ".bin"; - QString filePath2 = glob.lastFlashDir() + "/" + glob.firmware() + ".hex"; - QFile file(filePath1); - if (!file.exists()) - filePath1 = filePath2; + // Use the firmware name to determine splash width int width = SPLASH_WIDTH; - FlashInterface flash(filePath1); - if (flash.hasSplash()) - width = flash.getSplashWidth(); // Returns SPLASHX9D_HEIGHT if filePath1 does not exist! -// There must be a cleaner way of finding out the width of the firmware splash! + if (glob.pro[glob.profileId()].firmware().contains("taranis")) + width = SPLASHX9D_WIDTH; ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(width, SPLASH_HEIGHT))); if (width==SPLASHX9D_WIDTH) { diff --git a/companion/src/burndialog.cpp b/companion/src/burndialog.cpp index bfdf0bc76..05c0692d7 100644 --- a/companion/src/burndialog.cpp +++ b/companion/src/burndialog.cpp @@ -7,6 +7,7 @@ #include "splashlibrary.h" #include "flashinterface.h" #include "hexinterface.h" +#include "appdata.h" burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * backupEE, QString DocName): QDialog(parent), @@ -58,15 +59,7 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac else { setWindowTitle(tr("Write Models and Settings in %1 to TX").arg(DocName)); } - QSettings settings; - int profileid=settings.value("profileId", 1).toInt(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profileid); - settings.beginGroup(profile); - QString Name=settings.value("Name","").toString(); - settings.endGroup(); - settings.endGroup(); - ui->profile_label->setText(tr("Current profile")+QString(": ")+Name); + ui->profile_label->setText(tr("Current profile")+QString(": ")+glob.pro[glob.profileId()].Name()); } if (!hexfileName->isEmpty()) { ui->FWFileName->setText(*hexfileName); @@ -77,9 +70,8 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac burnraw=false; if (checkeEprom(*hexfileName)) { QSettings settings; - int profileid=settings.value("profileId", 1).toInt(); settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profileid); + QString profile=QString("profile%1").arg(glob.profileId()); settings.beginGroup(profile); QString Name=settings.value("Name","").toString(); QString calib=settings.value("StickPotCalib","").toString(); @@ -119,9 +111,8 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac hexfileName->clear(); } else if (Type==2) { - QSettings settings; QString FileName; - FileName = settings.value("lastFw").toString(); + FileName = glob.lastFw(); QFile file(FileName); if (file.exists()) { checkFw(FileName); @@ -138,7 +129,7 @@ burnDialog::~burnDialog() void burnDialog::on_FlashLoadButton_clicked() { QString fileName; - QSettings settings; + ui->ImageLoadButton->setDisabled(true); ui->libraryButton->setDisabled(true); ui->InvertColorButton->setDisabled(true); @@ -155,11 +146,11 @@ void burnDialog::on_FlashLoadButton_clicked() ui->EEbackupCB->hide(); QTimer::singleShot(0, this, SLOT(shrink())); if (hexType==2) { - fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER); + fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastFlashDir(), FLASH_FILES_FILTER); checkFw(fileName); } else { - QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), settings.value("lastDir").toString(), tr(EXTERNAL_EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), glob.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); if (checkeEprom(fileName)) { if (burnraw==false) { ui->BurnFlashButton->setEnabled(true); @@ -191,7 +182,6 @@ void burnDialog::checkFw(QString fileName) if (fileName.isEmpty()) { return; } - QSettings settings; if (!IS_TARANIS(GetEepromInterface()->getBoard())) { ui->EEbackupCB->show(); } @@ -216,8 +206,8 @@ void burnDialog::checkFw(QString fileName) ui->imageLabel->setFixedSize(flash.getSplashWidth(), flash.getSplashHeight()); ui->FwImage->show(); ui->FwImage->setPixmap(QPixmap::fromImage(flash.getSplash())); - QString ImageStr = settings.value("SplashImage", "").toString(); - bool PatchFwCB = settings.value("patchImage", false).toBool(); + QString ImageStr = glob.pro[glob.profileId()].SplashFileName(); + bool PatchFwCB = glob.pro[glob.profileId()].patchImage(); if (!ImageStr.isEmpty()) { QImage Image = qstring2image(ImageStr); ui->imageLabel->setPixmap(QPixmap::fromImage(Image.convertToFormat(flash.getSplashFormat()))); @@ -260,7 +250,7 @@ void burnDialog::checkFw(QString fileName) ui->BurnFlashButton->setEnabled(true); } QTimer::singleShot(0, this, SLOT(shrink())); - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); } bool burnDialog::checkeEprom(QString fileName) @@ -360,12 +350,11 @@ void burnDialog::on_ImageLoadButton_clicked() supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; } - QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); if (!fileName.isEmpty()) { - settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); QImage image(fileName); if (image.isNull()) { QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName)); @@ -442,11 +431,10 @@ void burnDialog::on_BurnFlashButton_clicked() if (hexType==2) { QString fileName=ui->FWFileName->text(); if (!fileName.isEmpty()) { - QSettings settings; - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); - settings.setValue("lastFw", fileName); + glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); + glob.lastFw( fileName ); if (ui->PatchFWCB->isChecked()) { - settings.setValue("patchImage", true); + glob.pro[glob.profileId()].patchImage( true ); QImage image = ui->imageLabel->pixmap()->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height()); if (!image.isNull()) { QString tempDir = QDir::tempPath(); @@ -469,7 +457,7 @@ void burnDialog::on_BurnFlashButton_clicked() QMessageBox::critical(this, tr("Warning"), tr("Custom image not found")); } } else { - settings.setValue("patchImage", false); + glob.pro[glob.profileId()].patchImage( false ); hexfileName->clear(); hexfileName->append(fileName); } @@ -480,7 +468,7 @@ void burnDialog::on_BurnFlashButton_clicked() } if (hexType==1) { QSettings settings; - int profileid=settings.value("profileId", 1).toInt(); + int profileid=glob.profileId(); settings.beginGroup("Profiles"); QString profile=QString("profile%1").arg(profileid); settings.beginGroup(profile); @@ -656,8 +644,7 @@ void burnDialog::on_PreferredImageCB_toggled(bool checked) { QString tmpFileName; if (checked) { - QSettings settings; - QString ImageStr = settings.value("SplashImage", "").toString(); + QString ImageStr = glob.pro[glob.profileId()].SplashFileName(); if (!ImageStr.isEmpty()) { QImage Image = qstring2image(ImageStr); if (ui->imageLabel->width()!=128) { diff --git a/companion/src/customizesplashdialog.cpp b/companion/src/customizesplashdialog.cpp index 420266b7a..bb86ec500 100644 --- a/companion/src/customizesplashdialog.cpp +++ b/companion/src/customizesplashdialog.cpp @@ -2,6 +2,7 @@ #include "ui_customizesplashdialog.h" #include +#include "appdata.h" #include "helpers.h" #include "burndialog.h" #include "splashlibrary.h" @@ -28,9 +29,10 @@ bool Side::displayImage( QString fileName, Source pictSource ) { QImage image; - if (fileName.isEmpty()) { + if (fileName.isEmpty()) return false; - } + + // Determine which picture format to use if (pictSource == FW ){ FlashInterface flash(fileName); if (!flash.hasSplash()) @@ -40,13 +42,16 @@ bool Side::displayImage( QString fileName, Source pictSource ) *format = (flash.getSplashWidth()==WIDTH_TARANIS ? LCDTARANIS : LCD9X); } else { - image.load(fileName); - if (pictSource== PICT) - *format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X; + image.load(fileName); + if (pictSource== PICT) + *format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X; + else if (pictSource == PROFILE) + *format = (glob.pro[glob.profileId()].firmware().contains("taranis")) ? LCDTARANIS : LCD9X; } if (image.isNull()) { return false; } + // Prepare and display image if (*format==LCDTARANIS) { image=image.convertToFormat(QImage::Format_RGB32); QRgb col; @@ -102,8 +107,6 @@ bool Side::refreshImage() bool Side::saveImage() { - QSettings settings; - if (*source == FW ) { FlashInterface flash(*saveToFileName); @@ -112,7 +115,7 @@ bool Side::saveImage() } QImage image = imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight()); if (flash.setSplash(image) && (flash.saveFlash(*saveToFileName) > 0)) { - settings.setValue("lastFlashDir", QFileInfo(*saveToFileName).dir().absolutePath()); + glob.lastFlashDir( QFileInfo(*saveToFileName).dir().absolutePath() ); } else { return false; @@ -121,7 +124,7 @@ bool Side::saveImage() else if (*source == PICT) { QImage image = imageLabel->pixmap()->toImage().scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8); if (image.save(*saveToFileName)) { - settings.setValue("lastImagesDir", QFileInfo(*saveToFileName).dir().absolutePath()); + glob.lastImagesDir( QFileInfo(*saveToFileName).dir().absolutePath() ); } else { return false; @@ -178,13 +181,12 @@ void customizeSplashDialog::on_leftLoadFwButton_clicked() {loadFirmware(left);} void customizeSplashDialog::on_rightLoadFwButton_clicked() {loadFirmware(right);} void customizeSplashDialog::loadFirmware(Side side) { - QSettings settings; - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastFlashDir(), FLASH_FILES_FILTER); if (!fileName.isEmpty()) { if (!side.displayImage( fileName, FW )) QMessageBox::critical(this, tr("Error"), tr("Cannot load embedded FW image from %1.").arg(fileName)); else - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); } } @@ -196,15 +198,14 @@ void customizeSplashDialog::loadPicture(Side side) for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) { supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; } - QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); if (!fileName.isEmpty()) { if (!side.displayImage( fileName, PICT )) QMessageBox::critical(this, tr("Error"), tr("Cannot load the image file %1.").arg(fileName)); else - settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); } } @@ -212,8 +213,7 @@ void customizeSplashDialog::on_leftLoadProfileButton_clicked() {loadProfile(left void customizeSplashDialog::on_rightLoadProfileButton_clicked() {loadProfile(right);} void customizeSplashDialog::loadProfile(Side side) { - QSettings settings; - QString fileName=settings.value("SplashFileName","").toString(); + QString fileName=glob.pro[glob.profileId()].SplashFileName(); if (!fileName.isEmpty()) { if (!side.displayImage( fileName, PROFILE )) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index bb2861cf8..63dfc096c 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -7,6 +7,7 @@ #include "firmwares/opentx/opentxinterface.h" #include "firmwares/ersky9x/ersky9xinterface.h" #include "qsettings.h" +#include "appdata.h" #include "helpers.h" QString EEPROMWarnings; @@ -734,8 +735,8 @@ GeneralSettings::GeneralSettings() QSettings settings; templateSetup = settings.value("default_channel_order", 0).toInt(); stickMode = settings.value("default_mode", 1).toInt(); - int profile_id = settings.value("profileId", 0).toInt(); - if (profile_id>0) { + int profile_id = glob.profileId(); + if (profile_id>-1) { settings.beginGroup("Profiles"); QString profile=QString("profile%1").arg(profile_id); settings.beginGroup(profile); @@ -990,14 +991,12 @@ ModelData ModelData::removeGlobalVars() QList eepromInterfaces; void RegisterEepromInterfaces() { - QSettings settings; - int rev4a = settings.value("rev4asupport",0).toInt(); eepromInterfaces.push_back(new Open9xInterface(BOARD_STOCK)); eepromInterfaces.push_back(new Open9xInterface(BOARD_M128)); eepromInterfaces.push_back(new Open9xInterface(BOARD_GRUVIN9X)); eepromInterfaces.push_back(new Open9xInterface(BOARD_SKY9X)); eepromInterfaces.push_back(new Open9xInterface(BOARD_TARANIS)); - if (rev4a) + if (glob.rev4asupport()) eepromInterfaces.push_back(new Open9xInterface(BOARD_TARANIS_REV4a)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_STOCK)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_GRUVIN9X)); diff --git a/companion/src/fwpreferencesdialog.cpp b/companion/src/fwpreferencesdialog.cpp index 735e18acc..0113ee3cd 100644 --- a/companion/src/fwpreferencesdialog.cpp +++ b/companion/src/fwpreferencesdialog.cpp @@ -3,6 +3,7 @@ #include "mainwindow.h" #include "eeprominterface.h" #include "helpers.h" +#include "appdata.h" #include #include @@ -213,11 +214,9 @@ void fwPreferencesDialog::firmwareChanged() void fwPreferencesDialog::writeValues() { - QSettings settings; - - settings.setValue("cpu_id", ui->CPU_ID_LE->text()); + glob.cpu_id( ui->CPU_ID_LE->text() ); current_firmware_variant = getFirmwareVariant(); - settings.setValue("firmware", current_firmware_variant.id); + glob.pro[glob.profileId()].firmware( current_firmware_variant.id ); } void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware) @@ -275,9 +274,7 @@ void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware) void fwPreferencesDialog::initSettings() { - QSettings settings; - - ui->CPU_ID_LE->setText(settings.value("cpu_id", "").toString()); + ui->CPU_ID_LE->setText(glob.cpu_id()); FirmwareInfo * current_firmware = GetCurrentFirmware(); foreach(FirmwareInfo * firmware, firmwares) { @@ -293,12 +290,10 @@ void fwPreferencesDialog::initSettings() void fwPreferencesDialog::on_checkFWUpdates_clicked() { - QSettings settings; - FirmwareVariant variant = getFirmwareVariant(); - if (settings.value("burnFirmware", true).toBool()) { + if (glob.pro[glob.profileId()].burnFirmware()) { current_firmware_variant = variant; - settings.setValue("firmware", variant.id); + glob.pro[glob.profileId()].firmware( variant.id ); } MainWindow * mw = (MainWindow *)this->parent(); mw->checkForUpdates(true, variant.id); @@ -307,14 +302,13 @@ void fwPreferencesDialog::on_checkFWUpdates_clicked() void fwPreferencesDialog::on_fw_dnld_clicked() { - QSettings settings; MainWindow * mw = (MainWindow *)this->parent(); FirmwareVariant variant = getFirmwareVariant(); writeValues(); if (!variant.firmware->getUrl(variant.id).isNull()) { - if (settings.value("burnFirmware", true).toBool()) { + if (glob.pro[glob.profileId()].burnFirmware()) { current_firmware_variant = getFirmwareVariant(); - settings.setValue("firmware", current_firmware_variant.id); + glob.pro[glob.profileId()].firmware( current_firmware_variant.id ); } mw->downloadLatestFW(current_firmware_variant.firmware, current_firmware_variant.id); } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 9a9f2caf4..5a74c4afc 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -1,4 +1,5 @@ #include +#include "appdata.h" #include "helpers.h" QString getPhaseName(int val, char * phasename) @@ -913,8 +914,7 @@ QString getCenterBeep(ModelData * g_model) QString getTheme() { - QSettings settings; - int theme_set = settings.value("theme", 1).toInt(); + int theme_set = glob.theme(); QString Theme; switch(theme_set) { case 0: diff --git a/companion/src/lcdwidget.h b/companion/src/lcdwidget.h index 9f01a0b17..7433b640d 100644 --- a/companion/src/lcdwidget.h +++ b/companion/src/lcdwidget.h @@ -18,6 +18,7 @@ #define lcd_widget_h #include +#include "appdata.h" class lcdWidget : public QWidget { public: @@ -58,11 +59,10 @@ class lcdWidget : public QWidget { QPixmap buffer(2*lcdWidth, 2*lcdHeight); QPainter p(&buffer); doPaint(p); - QSettings settings; - bool toclipboard=settings.value("snapshot_to_clipboard", false).toBool(); + bool toclipboard=glob.snapshot_to_clipboard(); QApplication::clipboard()->setPixmap( buffer ); if (!toclipboard) { - QString Path=settings.value("snapshotPath", "").toString(); + QString Path=glob.snapshotpath(); if (Path.isEmpty() || !QDir(Path).exists()) { Path="."; } diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index 0c9702239..874ed21d3 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -1,4 +1,5 @@ #include "logsdialog.h" +#include "appdata.h" #include "ui_logsdialog.h" #include "qcustomplot.h" #if defined WIN32 || !defined __GNUC__ @@ -38,8 +39,7 @@ logsDialog::logsDialog(QWidget *parent) : ui->customPlot->legend->setSelectedFont(legendFont); ui->customPlot->legend->setSelectable(QCPLegend::spItems); // legend box shall not be selectable, only legend items ui->customPlot->legend->setVisible(false); - QSettings settings; - QString Path=settings.value("gePath", "").toString(); + QString Path=glob.gePath(); if (Path.isEmpty() || !QFile(Path).exists()) { ui->mapsButton->hide(); } @@ -202,8 +202,7 @@ void logsDialog::on_mapsButton_clicked() { ,F_F,F_F,F_F,F_F,I_F,I_F,I_F,I_F\ ,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F}; - QSettings settings; - QString gePath=settings.value("gePath", "").toString(); + QString gePath=glob.gePath(); if (gePath.isEmpty() || !QFile(gePath).exists()) { ui->FieldsTW->setDisabled(false); ui->logTable->setDisabled(false); @@ -585,10 +584,9 @@ void logsDialog::moveLegend() void logsDialog::on_fileOpen_BT_clicked() { - QSettings settings; - QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), settings.value("lastLogDir").toString()); + QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), glob.lastLogDir()); if (!fileName.isEmpty()) { - settings.setValue("lastLogDir", fileName); + glob.lastLogDir( fileName ); ui->FileName_LE->setText(fileName); if (cvsFileParse()) { ui->FieldsTW->clear(); diff --git a/companion/src/main.cpp b/companion/src/main.cpp index 93bd89123..960d06b7a 100644 --- a/companion/src/main.cpp +++ b/companion/src/main.cpp @@ -45,12 +45,12 @@ #include #include #include -#include #include #include #include #include "mainwindow.h" #include "eeprominterface.h" +#include "appdata.h" #if defined WIN32 || !defined __GNUC__ #include @@ -98,19 +98,15 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - if (glob.firmware().isEmpty()) - glob.firmware(default_firmware_variant.id); - QString tmp_id = glob.firmware(); - tmp_id.replace("open9x", "opentx"); - tmp_id.replace("x9da", "taranis"); - glob.firmware(tmp_id); + if (glob.pro[glob.profileId()].firmware().isEmpty()) + glob.pro[glob.profileId()].firmware(default_firmware_variant.id); - QPixmap pixmap = QPixmap(glob.firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); + QPixmap pixmap = QPixmap(glob.pro[glob.profileId()].firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); QSplashScreen *splash = new QSplashScreen(pixmap); RegisterFirmwares(); - current_firmware_variant = GetFirmwareVariant(glob.firmware()); + current_firmware_variant = GetFirmwareVariant(glob.pro[glob.profileId()].firmware()); MainWindow *mainWin = new MainWindow(); if (glob.show_splash()) { diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 8918796be..8625537e6 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -49,7 +49,6 @@ #include "avroutputdialog.h" #include "comparedialog.h" #include "logsdialog.h" -#include "preferencesdialog.h" #include "apppreferencesdialog.h" #include "fwpreferencesdialog.h" #include "flashinterface.h" @@ -63,6 +62,7 @@ #include "hexinterface.h" #include "warnings.h" #include "helpers.h" +#include "appdata.h" #include "firmwares/opentx/opentxinterface.h" // TODO get rid of this include #define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2" @@ -408,7 +408,7 @@ void MainWindow::reply1Accepted() int pos=rev.lastIndexOf("-r"); if (pos>0) { currentFWrev=rev.mid(pos+2).toInt(); - if (settings.value("rename_firmware_files", false).toBool() && needRename) { + if (glob.pro[glob.profileId()].rename_firmware_files() && needRename) { QFileInfo fi(downloadedFWFilename); QString path=fi.path()+QDir::separator (); path.append(fi.completeBaseName()); @@ -421,7 +421,7 @@ void MainWindow::reply1Accepted() downloadedFWFilename=path; } settings.setValue(downloadedFW, currentFWrev); - if (settings.value("burnFirmware", true).toBool()) { + if (glob.pro[glob.profileId()].burnFirmware()) { int ret = QMessageBox::question(this, "Companion", tr("Do you want to write the firmware to the transmitter now ?"), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes) { writeFlash(downloadedFWFilename); @@ -558,7 +558,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) QString url = GetFirmware(fwToUpdate)->getUrl(fwToUpdate); QString ext = url.mid(url.lastIndexOf(".")); needRename=false; - bool addversion=glob.rename_firmware_files(); + bool addversion=glob.pro[glob.profileId()].rename_firmware_files(); QString fileName; if (addversion) { fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + newrev + ext); @@ -711,24 +711,8 @@ void MainWindow::loadProfile() //TODO Load all variables - Also HW! int profnum=action->data().toInt(); glob.profileId( profnum ); - // Upgrade old firmware names - QString firmware = glob.profile[profnum].firmware(); - firmware.replace("open9x","opentx"); - firmware.replace("x9da","taranis"); - glob.profile[profnum].firmware(firmware); - - // Copy profile data from profile to main variables - glob.Name( glob.profile[profnum].Name() ); - glob.default_channel_order( glob.profile[profnum].default_channel_order() ); - glob.default_mode( glob.profile[profnum].default_mode() ); - glob.burnFirmware( glob.profile[profnum].burnFirmware() ); - glob.rename_firmware_files( glob.profile[profnum].rename_firmware_files() ); - glob.sdPath( glob.profile[profnum].sdPath() ); - glob.SplashFileName( glob.profile[profnum].SplashFileName() ); - glob.firmware( glob.profile[profnum].firmware() ); - - // TODO Get rid of this global variable - glob.firmware is the real source - current_firmware_variant = GetFirmwareVariant(glob.firmware()); + // TODO Get rid of this global variable - The profile.firmware is the real source + current_firmware_variant = GetFirmwareVariant(glob.pro[glob.profileId()].firmware()); foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { MdiChild *mdiChild = qobject_cast(window->widget()); @@ -1543,7 +1527,7 @@ void MainWindow::updateMenus() updateIconSizeActions(); updateIconThemeActions(); - setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( glob.Name() )); + setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( glob.pro[glob.profileId()].Name() )); } MdiChild *MainWindow::createMdiChild() @@ -1909,20 +1893,25 @@ void MainWindow::setActiveSubWindow(QWidget *window) void MainWindow::updateRecentFileActions() { - int i,j, numRecentFiles; - QSettings settings; - QStringList files = settings.value("recentFileList").toStringList(); + int i, numRecentFiles; + // Hide all document slots + for ( i=0 ; i < glob.history_size(); i++) + recentFileActs[i]->setVisible(false); + + // Fill slots with content and unhide them + QStringList files = glob.recentFileList(); numRecentFiles = qMin(files.size(), glob.history_size()); - for ( i = 0; i < numRecentFiles; ++i) { - QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i])); - recentFileActs[i]->setText(text); - recentFileActs[i]->setData(files[i]); - recentFileActs[i]->setVisible(true); + for ( i = 0; i < numRecentFiles; i++) { + QString text = strippedName(files[i]); + if (!text.trimmed().isEmpty()) + { + recentFileActs[i]->setText(text); + recentFileActs[i]->setData(files[i]); + recentFileActs[i]->setVisible(true); + } } - for ( j = numRecentFiles; j < glob.history_size(); ++j) - recentFileActs[j]->setVisible(false); } void MainWindow::updateIconSizeActions() @@ -1982,9 +1971,9 @@ void MainWindow::updateProfilesActions() { for (int i=0; isetText(text); profileActs[i]->setData(i); profileActs[i]->setVisible(true); @@ -2000,14 +1989,14 @@ void MainWindow::updateProfilesActions() void MainWindow::createProfile() { int i; - for (i=0; i #include #include -#include "appdata.h" #include "downloaddialog.h" #include "eeprominterface.h" diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 97d737d09..c82e685fb 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -53,6 +53,7 @@ #include "printdialog.h" #include "burndialog.h" #include "helpers.h" +#include "appdata.h" #include #if defined WIN32 || !defined __GNUC__ @@ -179,8 +180,7 @@ void MdiChild::OpenEditWindow(bool wizard=false) } if (isNew && !wizard) { int ret; - QSettings settings; - bool wizardEnable=settings.value("wizardEnable", true).toBool(); + bool wizardEnable=glob.wizardEnable(); if (wizardEnable) { ret = QMessageBox::question(this, tr("Companion"), tr("Do you want to use model wizard? "), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes) { @@ -189,7 +189,7 @@ void MdiChild::OpenEditWindow(bool wizard=false) qSleep(500); ret = QMessageBox::question(this, tr("Companion"), tr("Ask this question again ? "), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::No) { - settings.setValue("wizardEnable", false); + glob.wizardEnable( false ); } } } @@ -346,34 +346,33 @@ bool MdiChild::save() bool MdiChild::saveAs(bool isNew) { - QSettings settings; QString fileName; if (GetEepromInterface()->getBoard() == BOARD_SKY9X) { curFile.replace(".eepe", ".bin"); QFileInfo fi(curFile); #ifdef __APPLE__ - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName()); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName()); #else - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName(), tr(BIN_FILES_FILTER)); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName(), tr(BIN_FILES_FILTER)); #endif } else { QFileInfo fi(curFile); #ifdef __APPLE__ - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName()); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName()); #else - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER)); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER)); #endif } if (fileName.isEmpty()) return false; if (fileName.contains("rev4a")) { - settings.setValue("rev4asupport", 1); + glob.rev4asupport( true ); } if (fileName.contains("norev4a")) { - settings.setValue("rev4asupport", 0); + glob.rev4asupport( false ); } - settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastDir( QFileInfo(fileName).dir().absolutePath() ); if (isNew) return saveFile(fileName); else @@ -490,15 +489,14 @@ void MdiChild::setCurrentFile(const QString &fileName) fileChanged = false; setWindowModified(false); updateTitle(); - QSettings settings; - int MaxRecentFiles =settings.value("history_size",10).toInt(); - QStringList files = settings.value("recentFileList").toStringList(); + int MaxRecentFiles = glob.history_size(); + QStringList files = glob.recentFileList(); files.removeAll(fileName); files.prepend(fileName); while (files.size() > MaxRecentFiles) files.removeLast(); - settings.setValue("recentFileList", files); + glob.recentFileList( files ); } QString MdiChild::strippedName(const QString &fullFileName) @@ -508,9 +506,8 @@ QString MdiChild::strippedName(const QString &fullFileName) void MdiChild::writeEeprom() // write to Tx { - QSettings settings; - bool backupEnable=settings.value("backupEnable", true).toBool(); - QString backupPath=settings.value("backupPath", "").toString(); + bool backupEnable=glob.backupEnable(); + QString backupPath=glob.backupPath(); if (!backupPath.isEmpty()) { if (!QDir(backupPath).exists()) { if (backupEnable) { @@ -521,13 +518,7 @@ void MdiChild::writeEeprom() // write to Tx } else { backupEnable=false; } - int profileid=settings.value("profileId", 1).toInt(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profileid); - settings.beginGroup(profile); - QString stickCal=settings.value("StickPotCalib","").toString(); - settings.endGroup(); - settings.endGroup(); + QString stickCal=glob.pro[glob.profileId()].StickPotCalib(); burnConfigDialog bcd; QString tempDir = QDir::tempPath(); QString tempFile = tempDir + "/temp.bin"; @@ -690,8 +681,7 @@ void MdiChild::setEEpromAvail(int eavail) bool MdiChild::loadBackup() { - QSettings settings; - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastDir").toString(),tr(EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastDir(),tr(EEPROM_FILES_FILTER)); if (fileName.isEmpty()) return false; QFile file(fileName); diff --git a/companion/src/preferencesdialog.cpp b/companion/src/preferencesdialog.cpp deleted file mode 100644 index 7b4ce1707..000000000 --- a/companion/src/preferencesdialog.cpp +++ /dev/null @@ -1,827 +0,0 @@ -#include "preferencesdialog.h" -#include "ui_preferencesdialog.h" -#include "mainwindow.h" -#include "eeprominterface.h" -#include "splashlibrary.h" -#include "helpers.h" -#ifdef JOYSTICKS -#include "joystick.h" -#include "joystickdialog.h" -#endif -#include -#include - -preferencesDialog::preferencesDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::preferencesDialog), - updateLock(false) -{ - ui->setupUi(this); - setWindowIcon(CompanionIcon("preferences.png")); - ui->splashLibraryButton->setIcon(CompanionIcon("library.png")); - ui->clearImageButton->setIcon(CompanionIcon("clear.png")); - - QCheckBox * OptionCheckBox[]= { - ui->optionCheckBox_1, ui->optionCheckBox_2, ui->optionCheckBox_3, ui->optionCheckBox_4, ui->optionCheckBox_5, ui->optionCheckBox_6, ui->optionCheckBox_7, - ui->optionCheckBox_8, ui->optionCheckBox_9, ui->optionCheckBox_10, ui->optionCheckBox_11, ui->optionCheckBox_12, ui->optionCheckBox_13, ui->optionCheckBox_14, - ui->optionCheckBox_15,ui->optionCheckBox_16, ui->optionCheckBox_17, ui->optionCheckBox_18, ui->optionCheckBox_19, ui->optionCheckBox_20, ui->optionCheckBox_21, - ui->optionCheckBox_22, ui->optionCheckBox_23, ui->optionCheckBox_24, ui->optionCheckBox_25, ui->optionCheckBox_26, ui->optionCheckBox_27, ui->optionCheckBox_28, - ui->optionCheckBox_29, ui->optionCheckBox_30, ui->optionCheckBox_31, ui->optionCheckBox_32, ui->optionCheckBox_33, ui->optionCheckBox_34, ui->optionCheckBox_35, - ui->optionCheckBox_36, ui->optionCheckBox_37, ui->optionCheckBox_38, ui->optionCheckBox_39, ui->optionCheckBox_40, ui->optionCheckBox_41, ui->optionCheckBox_42, - NULL }; - - voice=NULL; - - connect(ui->langCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged())); - connect(ui->voiceCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged())); - - for (int i=0; OptionCheckBox[i]; i++) { - optionsCheckBoxes.push_back(OptionCheckBox[i]); - connect(OptionCheckBox[i], SIGNAL(toggled(bool)), this, SLOT(firmwareOptionChanged(bool))); - } - - initSettings(); - connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged())); - connect(this, SIGNAL(accepted()), this, SLOT(writeValues())); -#ifndef JOYSTICKS - ui->joystickCB->hide(); - ui->joystickCB->setDisabled(true); - ui->joystickcalButton->hide(); - ui->joystickChkB->hide(); - ui->label_11->hide(); -#endif - resize(0,0); -} - - -preferencesDialog::~preferencesDialog() -{ - delete ui; -} - -void preferencesDialog::baseFirmwareChanged() -{ - QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - voice=NULL; - foreach(FirmwareInfo * firmware, firmwares) { - if (firmware->id == selected_firmware) { - if (firmware->voice) { - ui->voiceLabel->show(); - ui->voiceCombo->show(); - ui->voice_dnld->show(); - ui->sdPathButton->show(); - ui->sdPath->show(); - ui->sdPathLabel->show(); - ui->voiceLabel->setEnabled(true); - ui->voiceCombo->setEnabled(true); - ui->voice_dnld->setEnabled(true); - ui->sdPathButton->setEnabled(true); - ui->sdPath->setEnabled(true); - ui->ge_label->show(); - ui->ge_lineedit->show(); - ui->ge_pathButton->show(); - } else { - ui->voiceLabel->hide(); - ui->voiceCombo->hide(); - ui->voice_dnld->hide(); - ui->sdPathButton->hide(); - ui->sdPath->hide(); - ui->sdPathLabel->hide(); - ui->ge_label->hide(); - ui->ge_lineedit->hide(); - ui->ge_pathButton->hide(); - } - populateFirmwareOptions(firmware); - int width=firmware->eepromInterface->getCapability(LCDWidth); - ui->imageLabel->setFixedWidth(width); - break; - } - } - firmwareChanged(); -} - -FirmwareVariant preferencesDialog::getFirmwareVariant() -{ - QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - bool voice=false; - foreach(FirmwareInfo * firmware, firmwares) { - if (firmware->id == selected_firmware) { - QString id = firmware->id; - foreach(QCheckBox *cb, optionsCheckBoxes) { - if (cb->isChecked()) { - if (cb->text()=="voice" && cb->isChecked()) - voice=true; - id += QString("-") + cb->text(); - } - } - if (! firmware->eepromInterface->getCapability(MultiLangVoice)) { - if (ui->voiceCombo->count() && (voice || firmware->voice)) - id += QString("-tts") + ui->voiceCombo->currentText(); - } - if (ui->langCombo->count()) - id += QString("-") + ui->langCombo->currentText(); - - return GetFirmwareVariant(id); - } - } - - // Should never occur... - return default_firmware_variant; -} - -void preferencesDialog::firmwareLangChanged() -{ - firmwareChanged(); -} - -void preferencesDialog::firmwareOptionChanged(bool state) -{ - QCheckBox *cb = qobject_cast(sender()); - FirmwareInfo * firmware=NULL; - if (cb && state) { - QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - foreach(firmware, firmwares) { - if (firmware->id == selected_firmware) { - foreach(QList