From da68c593cfd0941bcea70b4eb5309e0834685e73 Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Tue, 18 Feb 2014 23:48:57 +0100 Subject: [PATCH] Changed every single QSetting in Companion. Next step: Function renaming --- companion/src/appdata.h | 1143 ++++++++++------- companion/src/apppreferencesdialog.cpp | 152 +-- companion/src/burnconfigdialog.cpp | 71 +- companion/src/burndialog.cpp | 77 +- companion/src/customizesplashdialog.cpp | 16 +- companion/src/eeprominterface.cpp | 44 +- .../src/firmwares/er9x/er9xinterface.cpp | 4 +- .../firmwares/gruvin9x/gruvin9xinterface.cpp | 4 +- .../firmwares/opentx/opentxSky9xsimulator.cpp | 4 +- .../opentx/opentxTaranisSimulator.cpp | 4 +- .../src/firmwares/opentx/opentxinterface.cpp | 27 +- .../src/firmwares/th9x/th9xinterface.cpp | 4 +- companion/src/fwpreferencesdialog.cpp | 21 +- companion/src/generaledit.cpp | 101 +- companion/src/helpers.cpp | 2 +- companion/src/joystickdialog.cpp | 22 +- companion/src/lcdwidget.h | 16 +- companion/src/logsdialog.cpp | 8 +- companion/src/main.cpp | 16 +- companion/src/mainwindow.cpp | 136 +- companion/src/mdichild.cpp | 32 +- companion/src/modeledit/customfunctions.cpp | 4 +- companion/src/modeledit/modeledit.cpp | 4 +- companion/src/modeledit/setup.cpp | 4 +- companion/src/modeledit/telemetry.cpp | 2 +- companion/src/simulatordialog.cpp | 25 +- companion/src/splashlibrary.cpp | 4 +- companion/src/xsimulatordialog.cpp | 25 +- 28 files changed, 1048 insertions(+), 924 deletions(-) diff --git a/companion/src/appdata.h b/companion/src/appdata.h index cd51802e6..cd893dac4 100644 --- a/companion/src/appdata.h +++ b/companion/src/appdata.h @@ -11,578 +11,759 @@ #define COMPANY "OpenTX Companion" #define PRODUCT "OpenTX" #define MAX_PROFILES 15 +#define MAX_JOYSTICKS 8 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); +public: + void clear (const QString tag1="", const QString tag2="", const QString tag3="") + { + QSettings settings(PRODUCT, COMPANY); + if (tag2.isEmpty()) + { + settings.remove(tag1); + } + else if (tag3.isEmpty()) + { + settings.beginGroup(tag1); + settings.remove(tag2); + settings.endGroup(); + } + else + { + settings.beginGroup(tag1); + settings.beginGroup(tag2); + settings.remove(tag3); + settings.endGroup(); + settings.endGroup(); + } + } - settings.setValue(tag, newArray); - array = newArray; + void store(const QByteArray newArray, QByteArray &array, const QString tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + settings.setValue(tag, newArray); + array = newArray; - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - settings.setValue(tag, newSList); - stringList = newSList; + void store(const QStringList newSList, QStringList &stringList, const QString tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + settings.setValue(tag, newSList); + stringList = newSList; - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - settings.setValue(tag, newString); - string = newString; + void store(const QString newString, QString &string, const QString tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + settings.setValue(tag, newString); + string = newString; - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - settings.setValue(tag, newTruth); - truth = newTruth; + void store(const bool newTruth, bool &truth, const QString tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + settings.setValue(tag, newTruth); + truth = newTruth; - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - settings.setValue(tag, newNumber); - number = newNumber; + void store(const int newNumber, int &number, const QString tag, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + settings.setValue(tag, newNumber); + number = newNumber; - // 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - array = settings.value(tag, def).toByteArray(); + // Retrieval functions + void retrieve( QByteArray &array, const QString tag, const QString def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + array = settings.value(tag, def).toByteArray(); - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - stringList = settings.value(tag, def).toStringList(); + void retrieve( QStringList &stringList, const QString tag, const QString def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + stringList = settings.value(tag, def).toStringList(); - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - string = settings.value(tag, def).toString(); + void retrieve( QString &string, const QString tag, const QString def, const QString group1="", const QString group2="" ) + { + QSettings settings(PRODUCT, COMPANY); + if (!group1.isEmpty()) settings.beginGroup(group1); + if (!group2.isEmpty()) settings.beginGroup(group2); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + string = settings.value(tag, def).toString(); - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - truth = settings.value(tag, def).toBool(); + void retrieve( bool &truth, const QString 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); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + truth = settings.value(tag, def).toBool(); - 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); + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - number = settings.value(tag, def).toInt(); + void retrieve( int &number, const QString 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); - if (!group1.isEmpty()) settings.endGroup(); - if (!group2.isEmpty()) settings.endGroup(); - } + number = settings.value(tag, def).toInt(); - // 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); - } + if (!group1.isEmpty()) settings.endGroup(); + if (!group2.isEmpty()) settings.endGroup(); + } - 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); - } + // Retrieve and Store functions + void getset( QByteArray &array, const QString tag, const QString def, const QString group1="", const QString group2="" ) + { + retrieve( array, tag, def, group1, group2); + store(array, array, 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( QStringList &stringList, const QString tag, const QString def, const QString group1="", const QString group2="" ) + { + retrieve( stringList, tag, def, group1, group2); + store(stringList, stringList, 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( QString &string, const QString tag, const QString def, const QString group1="", const QString group2="" ) + { + retrieve( string, tag, def, group1, group2); + store(string, string, 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); - } + void getset( bool &truth, const QString 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 QString tag, const int def, const QString group1="", const QString group2="" ) + { + retrieve( number, tag, def, group1, group2); + store(number, number, tag, group1, group2); + } }; +class FwRevision:DataObj +{ +public: + int get( const QString fwName ) + { + QString result; + retrieve( result, fwName, "", "FwRevisions" ); + return result.toInt(); + } + + void set( const QString fwName, const int fwRevision ) + { + QString tempString= QString("%1").arg(fwRevision); + store( tempString, tempString, fwName, "FwRevisions" ); + } + + void remove( const QString tag ) + { + clear( "FwRevisions", tag ); + } +}; + +class JStickData:DataObj +{ +private: + int index; + + int _stick_axe; + int _stick_min; + int _stick_med; + int _stick_max; + int _stick_inv; + +public: +public: + // All the get declarations + int stick_axe() { return _stick_axe; } + int stick_min() { return _stick_min; } + int stick_med() { return _stick_med; } + int stick_max() { return _stick_max; } + int stick_inv() { return _stick_inv; } + + // All the set declarations + void stick_axe(const int it) { store( it, _stick_axe, QString("stick%1_axe").arg(index), "JsCalibration" );} + void stick_min(const int it) { store( it, _stick_min, QString("stick%1_min").arg(index), "JsCalibration" );} + void stick_med(const int it) { store( it, _stick_med, QString("stick%1_med").arg(index), "JsCalibration" );} + void stick_max(const int it) { store( it, _stick_max, QString("stick%1_max").arg(index), "JsCalibration" );} + void stick_inv(const int it) { store( it, _stick_inv, QString("stick%1_inv").arg(index), "JsCalibration" );} + + // Constructor + JStickData() + { + index = -1; + } + + void remove() + { + // Remove all JStickData values from settings file + QSettings settings(PRODUCT, COMPANY); + settings.beginGroup( "JsCalibration" ); + settings.remove( QString( "stick%1_axe").arg(index) ); + settings.remove( QString( "stick%1_min").arg(index) ); + settings.remove( QString( "stick%1_med").arg(index) ); + settings.remove( QString( "stick%1_max").arg(index) ); + settings.remove( QString( "stick%1_inv").arg(index) ); + settings.endGroup(); + + // Reset all JStickData variables to initial values + init(index); + } + + bool existsOnDisk() + { + QSettings settings(PRODUCT, COMPANY); + settings.beginGroup("JsCalibration"); + int axe = settings.value( QString("stick%1_axe").arg(index), -1 ).toInt(); + settings.endGroup(); + + return (axe > -1); + } + + void init(int newIndex) + { + index = newIndex; + _stick_axe = -1; + _stick_min = -32767; + _stick_med = 0; + _stick_max = 0; + _stick_inv = 0; + + // Do not write empty joystick calibrations to disk. + if ( !existsOnDisk() ) + return; + + flush(); + } + + void flush() + { + getset( _stick_axe, QString("stick%1_axe").arg(index), -1, "JsCalibration" ); + getset( _stick_min, QString("stick%1_min").arg(index), -32767, "JsCalibration" ); + getset( _stick_med, QString("stick%1_med").arg(index), 0, "JsCalibration" ); + getset( _stick_max, QString("stick%1_max").arg(index), 0, "JsCalibration" ); + getset( _stick_inv, QString("stick%1_inv").arg(index), 0, "JsCalibration" ); + } +}; + class Profile:DataObj { +private: + // Class Internal Variable + int index; - private: - // Class Internal Variable - int index; + // Application Variables + QString _firmware; + QString _Name; + QString _sdPath; + QString _SplashFileName; + bool _burnFirmware; + bool _rename_firmware_files; + bool _patchImage; + int _default_channel_order; + int _default_mode; - // Application Variables - QString _firmware; - QString _Name; - QString _sdPath; - QString _SplashFileName; - bool _burnFirmware; - bool _rename_firmware_files; - bool _patchImage; - int _default_channel_order; - int _default_mode; + // Firmware Variables + QString _Beeper; + QString _countryCode; + QString _Display; + QString _Haptic; + QString _Speaker; + QString _StickPotCalib; + QString _TrainerCalib; + int _currentCalib; + int _GSStickMode; + int _PPM_Multiplier; + int _VbatCalib; + int _vBatWarn; - // 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; } + bool patchImage() { return _patchImage; } + int default_channel_order() { return _default_channel_order; } + int default_mode() { return _default_mode; } - 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; } - bool patchImage() { return _patchImage; } - int default_channel_order() { return _default_channel_order; } - int default_mode() { return _default_mode; } + QString Beeper() { return _Beeper; } + QString countryCode() { return _countryCode; } + QString Display() { return _Display; } + QString Haptic() { return _Haptic; } + QString Speaker() { return _Speaker; } + QString StickPotCalib() { return _StickPotCalib; } + QString TrainerCalib() { return _TrainerCalib; } + int currentCalib() { return _currentCalib; } + int GSStickMode() { return _GSStickMode; } + int PPM_Multiplier() { return _PPM_Multiplier; } + int VbatCalib() { return _VbatCalib; } + int vBatWarn() { return _vBatWarn; } - 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 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 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 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));} - // 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 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 Display (const QString str) { store(str, _Display, "Display" ,"Profiles", QString("profile%1").arg(index));} + void Haptic (const QString str) { store(str, _Haptic, "Haptic" ,"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 currentCalib (const int it) { store(it, _currentCalib, "currentCalib" ,"Profiles", QString("profile%1").arg(index));} + void GSStickMode (const int it) { store(it, _GSStickMode, "GSStickMode" ,"Profiles", QString("profile%1").arg(index));} + void PPM_Multiplier (const int it) { store(it, _PPM_Multiplier, "PPM_Multiplier" ,"Profiles", QString("profile%1").arg(index));} + void VbatCalib (const int it) { store(it, _VbatCalib, "VbatCalib" ,"Profiles", QString("profile%1").arg(index));} + void vBatWarn (const int it) { store(it, _vBatWarn, "vBatWarn" ,"Profiles", QString("profile%1").arg(index));} - void firmware (const QString str) { store(str, _firmware, "firmware" ,"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 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));} + // Constructor + Profile() + { + index = -1; + } - 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));} + 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(); - // Constructor - Profile() - { - index = -1; - } + // Reset all profile variables to initial values + init(index); + } - 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(); + bool existsOnDisk() + { + QSettings settings(PRODUCT, COMPANY); + settings.beginGroup("Profiles"); + settings.beginGroup(QString("profile%1").arg(index)); + QStringList keyList = settings.allKeys(); + settings.endGroup(); + settings.endGroup(); - // Reset all profile variables to initial values - init(index); - } + return (keyList.length() > 0); + } - bool existsOnDisk() - { - QSettings settings(PRODUCT, COMPANY); - settings.beginGroup("Profiles"); - settings.beginGroup(QString("profile%1").arg(index)); - QStringList keyList = settings.allKeys(); - settings.endGroup(); - settings.endGroup(); + void init(int newIndex) + { + index = newIndex; - return (keyList.length() > 0); - } + _firmware = ""; + _Name = ""; + _sdPath = ""; + _SplashFileName = ""; + _burnFirmware = false; + _rename_firmware_files = false; + _patchImage = false; + _default_channel_order = 0; + _default_mode = 1; - 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)); - 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)); + _Beeper = ""; + _countryCode = ""; + _Display = ""; + _Haptic = ""; + _Speaker = ""; + _StickPotCalib = ""; + _TrainerCalib = ""; - 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)); - } + _currentCalib = 0; + _GSStickMode = 0; + _PPM_Multiplier = 0; + _VbatCalib = 0; + _vBatWarn = 0; - void init(int newIndex) - { - index = newIndex; + QString pName; + retrieve( pName, "Name", "", "Profiles", QString("profile%1").arg(index)); - _firmware = ""; - _Name = ""; - _sdPath = ""; - _SplashFileName = ""; - _burnFirmware = false; - _rename_firmware_files = false; - _patchImage = false; - _default_channel_order = 0; - _default_mode = 1; + // Do not write empty profiles to disk except the default (0) profile. + if ( index > 0 && !existsOnDisk()) + return; - _Beeper = ""; - _countryCode = ""; - _currentCalib = ""; - _Display = ""; - _GSStickMode = ""; - _Haptic = ""; - _PPM_Multiplier = ""; - _Speaker = ""; - _StickPotCalib = ""; - _TrainerCalib = ""; - _VbatCalib = ""; - _vBatWarn = ""; - - QString pName; - retrieve( pName, "Name", "", "Profiles", QString("profile%1").arg(index)); + flush(); + } - // Do not write empty profiles to disk except the default (0) profile. - if ( index > 0 && !existsOnDisk()) - return; + 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)); + 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)); - flush(); - } + getset( _Beeper, "Beeper" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _countryCode, "countryCode" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _Display, "Display" ,"" ,"Profiles", QString("profile%1").arg(index)); + getset( _Haptic, "Haptic" ,"" ,"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( _currentCalib, "currentCalib" ,0 ,"Profiles", QString("profile%1").arg(index)); + getset( _GSStickMode, "GSStickMode" ,0 ,"Profiles", QString("profile%1").arg(index)); + getset( _PPM_Multiplier, "PPM_Multiplier" ,0 ,"Profiles", QString("profile%1").arg(index)); + getset( _VbatCalib, "VbatCalib" ,0 ,"Profiles", QString("profile%1").arg(index)); + getset( _vBatWarn, "vBatWarn" ,0 ,"Profiles", QString("profile%1").arg(index)); + } }; class AppData:DataObj { - // All the global variables - public: - Profile pro[MAX_PROFILES]; + // All the global variables +public: + Profile profile[MAX_PROFILES]; + JStickData joystick[MAX_JOYSTICKS]; + FwRevision fwRev; - private: - QStringList _recentFileList; - QByteArray _mainWindowGeometry; - QByteArray _mainWindowState; - QByteArray _modelEditGeometry; +private: + QStringList _recentFileList; + QByteArray _mainWindowGeometry; + QByteArray _mainWindowState; + QByteArray _modelEditGeometry; - QString _locale; - QString _cpu_id; - QString _lastFw; + QString _arm_mcu; + QString _avr_arguments; + QString _avr_port; + QString _avrdude_location; + QString _cpu_id; + QString _dfu_arguments; + QString _dfu_location; + QString _lastFw; + QString _locale; + QString _mcu; + QString _programmer; + QString _samba_location; + QString _samba_port; - QString _backupPath; - QString _gePath; - QString _lastDir; - QString _lastFlashDir; - QString _lastImagesDir; - QString _lastLogDir; - QString _libraryPath; - QString _snapshotpath; + QString _backupPath; + QString _compilationServer; + QString _gePath; + QString _lastDir; + QString _lastFlashDir; + QString _lastImagesDir; + QString _lastLogDir; + QString _libraryPath; + QString _snapshotpath; - bool _backupEnable; - bool _backupOnFlash; - bool _maximized; - bool _js_support; - bool _rev4asupport; - bool _show_splash; - bool _snapshot_to_clipboard; - bool _startup_check_companion; - bool _startup_check_fw; - bool _simuSW; - bool _wizardEnable; + bool _backupEnable; + bool _backupOnFlash; + bool _maximized; + bool _js_support; + bool _rev4asupport; + bool _show_splash; + bool _snapshot_to_clipboard; + bool _startup_check_companion; + bool _startup_check_fw; + bool _simuSW; + bool _wizardEnable; - int _backLight; - 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; + int _backLight; + 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; public: - // All the get declarations - QStringList recentFileList() { return _recentFileList; } - QByteArray mainWindowGeometry(){ return _mainWindowGeometry; } - QByteArray mainWindowState() { return _mainWindowState; } - QByteArray modelEditGeometry() { return _modelEditGeometry; } + // All the get declarations + QStringList recentFileList() { return _recentFileList; } + QByteArray mainWindowGeometry(){ return _mainWindowGeometry; } + QByteArray mainWindowState() { return _mainWindowState; } + QByteArray modelEditGeometry() { return _modelEditGeometry; } - QString locale() { return _locale; } - QString cpu_id() { return _cpu_id; } - QString lastFw() { return _lastFw; } + QString arm_mcu() { return _arm_mcu; } + QString avr_arguments() { return _avr_arguments; } + QString avr_port() { return _avr_port; } + QString avrdude_location() { return _avrdude_location; } + QString cpu_id() { return _cpu_id; } + QString dfu_arguments() { return _dfu_arguments; } + QString dfu_location() { return _dfu_location; } + QString lastFw() { return _lastFw; } + QString locale() { return _locale; } + QString mcu() { return _mcu; } + QString programmer() { return _programmer; } + QString samba_location() { return _samba_location; } + QString samba_port() { return _samba_port; } - QString backupPath() { return _backupPath; } - QString gePath() { return _gePath; } - QString lastDir() { return _lastDir; } - QString lastFlashDir() { return _lastFlashDir; } - QString lastImagesDir() { return _lastImagesDir; } - QString lastLogDir() { return _lastLogDir; } - QString libraryPath() { return _libraryPath; } - QString snapshotpath() { return _snapshotpath; } + QString backupPath() { return _backupPath; } + QString compilationServer() { return _compilationServer; } + QString gePath() { return _gePath; } + QString lastDir() { return _lastDir; } + QString lastFlashDir() { return _lastFlashDir; } + QString lastImagesDir() { return _lastImagesDir; } + QString lastLogDir() { return _lastLogDir; } + QString libraryPath() { return _libraryPath; } + QString snapshotpath() { return _snapshotpath; } - bool backupEnable() { return _backupEnable; } - bool backupOnFlash() { return _backupOnFlash; } - bool js_support() { return _js_support; } - bool rev4asupport() { return _rev4asupport; } - bool maximized() { return _maximized; } - 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; } + bool backupEnable() { return _backupEnable; } + bool backupOnFlash() { return _backupOnFlash; } + bool js_support() { return _js_support; } + bool rev4asupport() { return _rev4asupport; } + bool maximized() { return _maximized; } + 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 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_ctrl() { return _js_ctrl; } - int modelEditTab() { return _modelEditTab; } - int profileId() { return _profileId; } - int theme() { return _theme; } - int warningId() { return _warningId; } + int backLight() { return _backLight; } + 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_ctrl() { return _js_ctrl; } + int modelEditTab() { return _modelEditTab; } + int id() { 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 modelEditGeometry (const QByteArray a) { store(a, _modelEditGeometry, "modelEditGeometry" );} + // 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 modelEditGeometry (const QByteArray a) { store(a, _modelEditGeometry, "modelEditGeometry" );} - void locale (const QString str) { store(str, _locale, "locale" );} - void cpu_id (const QString str) { store(str, _cpu_id, "cpu_id" );} - void lastFw (const QString str) { store(str, _lastFw, "lastFw" );} + void arm_mcu (const QString str) { store(str, _arm_mcu, "arm_mcu" );} + void avr_arguments (const QString str) { store(str, _avr_arguments, "avr_arguments" );} + void avr_port (const QString str) { store(str, _avr_port, "avr_port" );} + void avrdude_location (const QString str) { store(str, _avrdude_location, "avrdude_location" );} + void cpu_id (const QString str) { store(str, _cpu_id, "cpu_id" );} + void dfu_arguments (const QString str) { store(str, _dfu_arguments, "dfu_arguments" );} + void dfu_location (const QString str) { store(str, _dfu_location, "dfu_location" );} + void lastFw (const QString str) { store(str, _lastFw, "lastFw" );} + void locale (const QString str) { store(str, _locale, "locale" );} + void mcu (const QString str) { store(str, _mcu, "mcu" );} + void programmer (const QString str) { store(str, _programmer, "programmer" );} + void samba_location (const QString str) { store(str, _samba_location, "samba_location" );} + void samba_port (const QString str) { store(str, _samba_port, "samba_port" );} - 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 lastLogDir (const QString str) { store(str, _lastLogDir, "lastLogDir" );} - void libraryPath (const QString str) { store(str, _libraryPath, "libraryPath" );} - void snapshotpath (const QString str) { store(str, _snapshotpath, "snapshotpath" );} + void backupPath (const QString str) { store(str, _backupPath, "backupPath" );} + void compilationServer (const QString str) { store(str, _compilationServer, "compilation-server");} + 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 lastLogDir (const QString str) { store(str, _lastLogDir, "lastLogDir" );} + void libraryPath (const QString str) { store(str, _libraryPath, "libraryPath" );} + 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 maximized (const bool bl) { store(bl, _maximized, "maximized" );} - void js_support (const bool bl) { store(bl, _js_support, "js_support" );} - 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" );} - 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 backupEnable (const bool bl) { store(bl, _backupEnable, "backupEnable" );} + void backupOnFlash (const bool bl) { store(bl, _backupOnFlash, "backupOnFlash" );} + void maximized (const bool bl) { store(bl, _maximized, "maximized" );} + void js_support (const bool bl) { store(bl, _js_support, "js_support" );} + 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" );} + 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 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" );} + void backLight (const int it) { store(it, _backLight, "backLight" );} + 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 id (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() - { - //Initialize the profiles - for (int i=0; istartupCheck_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()); + g.startup_check_companion(ui->startupCheck_companion9x->isChecked()); + g.startup_check_fw(ui->startupCheck_fw->isChecked()); + g.wizardEnable(ui->wizardEnable_ChkB->isChecked()); + g.show_splash(ui->showSplash->isChecked()); + g.simuSW(ui->simuSW->isChecked()); + g.history_size(ui->historySize->value()); + g.backLight(ui->backLightColor->currentIndex()); + g.libraryPath(ui->libraryPath->text()); + g.gePath(ui->ge_lineedit->text()); + g.embedded_splashes(ui->splashincludeCB->currentIndex()); + g.backupEnable(ui->backupEnable->isChecked()); if (ui->joystickChkB ->isChecked() && ui->joystickCB->isEnabled()) { - glob.js_support(ui->joystickChkB ->isChecked()); - glob.js_ctrl(ui->joystickCB ->currentIndex()); + g.js_support(ui->joystickChkB ->isChecked()); + g.js_ctrl(ui->joystickCB ->currentIndex()); } else { - glob.js_support(false); - glob.js_ctrl(0); + g.js_support(false); + g.js_ctrl(0); } - glob.profileId(ui->profileIndexLE->text().toInt()); + g.id(ui->profileIndexLE->text().toInt()); - 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()); + g.profile[g.id()].default_channel_order(ui->channelorderCB->currentIndex()); + g.profile[g.id()].default_mode(ui->stickmodeCB->currentIndex()); + g.profile[g.id()].rename_firmware_files(ui->renameFirmware->isChecked()); + g.profile[g.id()].burnFirmware(ui->burnFirmware->isChecked()); + g.profile[g.id()].Name(ui->profileNameLE->text()); + g.profile[g.id()].sdPath(ui->sdPath->text()); + g.profile[g.id()].SplashFileName(ui->SplashFileName->text()); + g.profile[g.id()].firmware(ui->firmwareLE->text()); saveProfile(); } void appPreferencesDialog::on_snapshotPathButton_clicked() { - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), glob.snapshotpath()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), g.snapshotpath()); if (!fileName.isEmpty()) { - glob.snapshotpath(fileName); - glob.snapshot_to_clipboard(false); + g.snapshotpath(fileName); + g.snapshot_to_clipboard(false); ui->snapshotPath->setText(fileName); } } void appPreferencesDialog::initSettings() { - ui->snapshotClipboardCKB->setChecked(glob.snapshot_to_clipboard()); - ui->burnFirmware->setChecked(glob.pro[glob.profileId()].burnFirmware()); - ui->snapshotPath->setText(glob.snapshotpath()); + ui->snapshotClipboardCKB->setChecked(g.snapshot_to_clipboard()); + ui->burnFirmware->setChecked(g.profile[g.id()].burnFirmware()); + ui->snapshotPath->setText(g.snapshotpath()); ui->snapshotPath->setReadOnly(true); if (ui->snapshotClipboardCKB->isChecked()) { ui->snapshotPath->setDisabled(true); ui->snapshotPathButton->setDisabled(true); } - 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()); - ui->libraryPath->setText(glob.libraryPath()); - ui->ge_lineedit->setText(glob.gePath()); + ui->startupCheck_companion9x->setChecked(g.startup_check_companion()); + ui->startupCheck_fw->setChecked(g.startup_check_fw()); + ui->wizardEnable_ChkB->setChecked(g.wizardEnable()); + ui->showSplash->setChecked(g.show_splash()); + ui->historySize->setValue(g.history_size()); + ui->backLightColor->setCurrentIndex(g.backLight()); + ui->simuSW->setChecked(g.simuSW()); + ui->libraryPath->setText(g.libraryPath()); + ui->ge_lineedit->setText(g.gePath()); - if (!glob.backupPath().isEmpty()) { - if (QDir(glob.backupPath()).exists()) { - ui->backupPath->setText(glob.backupPath()); + if (!g.backupPath().isEmpty()) { + if (QDir(g.backupPath()).exists()) { + ui->backupPath->setText(g.backupPath()); ui->backupEnable->setEnabled(true); - ui->backupEnable->setChecked(glob.backupEnable()); + ui->backupEnable->setChecked(g.backupEnable()); } else { ui->backupEnable->setDisabled(true); } } else { ui->backupEnable->setDisabled(true); } - ui->splashincludeCB->setCurrentIndex(glob.embedded_splashes()); + ui->splashincludeCB->setCurrentIndex(g.embedded_splashes()); #ifdef JOYSTICKS - ui->joystickChkB->setChecked(glob.js_support()); + ui->joystickChkB->setChecked(g.js_support()); if (ui->joystickChkB->isChecked()) { QStringList joystickNames; joystickNames << tr("No joysticks found"); @@ -134,7 +134,7 @@ void appPreferencesDialog::initSettings() } ui->joystickCB->clear(); ui->joystickCB->insertItems(0, joystickNames); - ui->joystickCB->setCurrentIndex(glob.js_ctrl()); + ui->joystickCB->setCurrentIndex(g.js_ctrl()); } else { ui->joystickCB->clear(); @@ -143,22 +143,22 @@ void appPreferencesDialog::initSettings() } #endif // Profile Tab Inits - 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.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() ); + ui->channelorderCB->setCurrentIndex(g.profile[g.id()].default_channel_order()); + ui->stickmodeCB->setCurrentIndex(g.profile[g.id()].default_mode()); + ui->renameFirmware->setChecked(g.profile[g.id()].rename_firmware_files()); + ui->sdPath->setText(g.profile[g.id()].sdPath()); + ui->profileIndexLE->setText(QString("%1").arg(g.id())); + ui->profileNameLE->setText(g.profile[g.id()].Name()); + ui->firmwareLE->setText(g.profile[g.id()].firmware()); + ui->SplashFileName->setText(g.profile[g.id()].SplashFileName()); + displayImage( g.profile[g.id()].SplashFileName() ); } void appPreferencesDialog::on_libraryPathButton_clicked() { - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), glob.libraryPath()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), g.libraryPath()); if (!fileName.isEmpty()) { - glob.libraryPath(fileName); + g.libraryPath(fileName); ui->libraryPath->setText(fileName); } } @@ -168,20 +168,20 @@ void appPreferencesDialog::on_snapshotClipboardCKB_clicked() if (ui->snapshotClipboardCKB->isChecked()) { ui->snapshotPath->setDisabled(true); ui->snapshotPathButton->setDisabled(true); - glob.snapshot_to_clipboard(true); + g.snapshot_to_clipboard(true); } else { ui->snapshotPath->setEnabled(true); ui->snapshotPath->setReadOnly(true); ui->snapshotPathButton->setEnabled(true); - glob.snapshot_to_clipboard(false); + g.snapshot_to_clipboard(false); } } void appPreferencesDialog::on_backupPathButton_clicked() { - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), glob.backupPath()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), g.backupPath()); if (!fileName.isEmpty()) { - glob.backupPath(fileName); + g.backupPath(fileName); ui->backupPath->setText(fileName); } ui->backupEnable->setEnabled(true); @@ -232,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.pro[glob.profileId()].sdPath()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), g.profile[g.id()].sdPath()); if (!fileName.isEmpty()) { ui->sdPath->setText(fileName); } @@ -244,24 +244,24 @@ void appPreferencesDialog::saveProfile() if (ui->profileNameLE->text().isEmpty()) ui->profileNameLE->setText("----"); - 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()); + g.profile[g.id()].Name( ui->profileNameLE->text() ); + g.profile[g.id()].default_channel_order( ui->channelorderCB->currentIndex()); + g.profile[g.id()].default_mode( ui->stickmodeCB->currentIndex()); + g.profile[g.id()].burnFirmware( ui->burnFirmware->isChecked()); + g.profile[g.id()].rename_firmware_files( ui->renameFirmware->isChecked()); + g.profile[g.id()].sdPath( ui->sdPath->text()); + g.profile[g.id()].SplashFileName( ui->SplashFileName->text()); + g.profile[g.id()].firmware( ui->firmwareLE->text()); } void appPreferencesDialog::on_removeProfileButton_clicked() { - if ( glob.profileId() == 0 ) + if ( g.id() == 0 ) QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); else { - glob.pro[glob.profileId()].remove(); - glob.profileId( 0 ); + g.profile[g.id()].remove(); + g.id( 0 ); initSettings(); } } @@ -277,7 +277,7 @@ bool appPreferencesDialog::displayImage( QString fileName ) // Use the firmware name to determine splash width int width = SPLASH_WIDTH; - if (glob.pro[glob.profileId()].firmware().contains("taranis")) + if (g.profile[g.id()].firmware().contains("taranis")) width = SPLASHX9D_WIDTH; ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(width, SPLASH_HEIGHT))); @@ -313,10 +313,10 @@ void appPreferencesDialog::on_SplashSelect_clicked() } QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), g.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); if (!fileName.isEmpty()){ - glob.lastImagesDir(QFileInfo(fileName).dir().absolutePath()); + g.lastImagesDir(QFileInfo(fileName).dir().absolutePath()); displayImage(fileName); ui->SplashFileName->setText(fileName); diff --git a/companion/src/burnconfigdialog.cpp b/companion/src/burnconfigdialog.cpp index e0ea4a63e..0b3d89691 100644 --- a/companion/src/burnconfigdialog.cpp +++ b/companion/src/burnconfigdialog.cpp @@ -3,6 +3,7 @@ #include "avroutputdialog.h" #include "eeprominterface.h" #include "helpers.h" +#include "appdata.h" #include #if !defined WIN32 && defined __GNUC__ @@ -83,33 +84,42 @@ burnConfigDialog::~burnConfigDialog() void burnConfigDialog::getSettings() { - QSettings settings; + avrLoc = g.avrdude_location(); + sambaLoc = g.samba_location(); + dfuLoc = g.dfu_location(); + #if defined WIN32 || !defined __GNUC__ - avrLoc = settings.value("avrdude_location", QFileInfo("avrdude.exe").absoluteFilePath()).toString(); - sambaLoc = settings.value("samba_location", QFileInfo("sam-ba.exe").absoluteFilePath()).toString(); - dfuLoc = settings.value("dfu_location", QFileInfo("dfu-util.exe").absoluteFilePath()).toString(); + if ( avrLoc.isEmpty()) + avrLoc = QFileInfo("avrdude.exe").absoluteFilePath(); + if ( sambaLoc.isEmpty()) + sambaLoc = QFileInfo("sam-ba.exe").absoluteFilePath(); + if ( dfuLoc.isEmpty()) + dfuLoc = QFileInfo("dfu-util.exe").absoluteFilePath(); #elif defined __APPLE__ - avrLoc = settings.value("avrdude_location", "/usr/local/bin/avrdude").toString(); - sambaLoc = settings.value("samba_location", "/usr/local/bin/sam-ba").toString(); - dfuLoc = settings.value("dfu_location", QFileInfo("/opt/local/bin/dfu-util").absoluteFilePath()).toString(); + if ( avrLoc.isEmpty()) + avrLoc = "/usr/local/bin/avrdude"; + if ( sambaLoc.isEmpty()) + sambaLoc = "/usr/local/bin/sam-ba"; + if ( dfuLoc.isEmpty()) + dfuLoc = QFileInfo("/opt/local/bin/dfu-util").absoluteFilePath(); #else - avrLoc = settings.value("avrdude_location", "/usr/bin/avrdude").toString(); - sambaLoc = settings.value("samba_location", "/usr/bin/sam-ba").toString(); - dfuLoc = settings.value("dfu_location", QFileInfo("/usr/bin/dfu-util").absoluteFilePath()).toString(); + if ( avrLoc.isEmpty()) + avrLoc = "/usr/bin/avrdude"; + if ( sambaLoc.isEmpty()) + sambaLoc = "/usr/bin/sam-ba"; + if ( dfuLoc.isEmpty()) + dfuLoc = QFileInfo("/usr/bin/dfu-util").absoluteFilePath(); #endif - QString str = settings.value("avr_arguments").toString(); - avrArgs = str.split(" ", QString::SkipEmptyParts); - avrProgrammer = settings.value("programmer", QString("usbasp")).toString(); - avrMCU = settings.value("mcu", QString("m64")).toString(); - armMCU = settings.value("arm_mcu", QString("at91sam3s4-9x")).toString(); + dfuArgs = g.dfu_arguments().split(" ", QString::SkipEmptyParts); + avrArgs = g.avr_arguments().split(" ", QString::SkipEmptyParts); + avrProgrammer = g.programmer(); + avrPort = g.avr_port(); + avrMCU = g.mcu(); + armMCU = g.arm_mcu(); + sambaPort = g.samba_port(); - avrPort = settings.value("avr_port", "").toString(); - sambaPort = settings.value("samba_port", "\\USBserial\\COM23").toString(); - - str = settings.value("dfu_arguments", "-a 0").toString(); - dfuArgs = str.split(" ", QString::SkipEmptyParts); ui->avrdude_location->setText(getAVRDUDE()); ui->avrArgs->setText(getAVRArgs().join(" ")); @@ -137,17 +147,16 @@ void burnConfigDialog::getSettings() void burnConfigDialog::putSettings() { - QSettings settings; - settings.setValue("avrdude_location", avrLoc); - settings.setValue("programmer", avrProgrammer); - settings.setValue("mcu", avrMCU); - settings.setValue("avr_port", avrPort); - settings.setValue("avr_arguments", avrArgs.join(" ")); - settings.setValue("samba_location", sambaLoc); - settings.setValue("samba_port", sambaPort); - settings.setValue("arm_mcu", armMCU); - settings.setValue("dfu_location", dfuLoc); - settings.setValue("dfu_arguments", dfuArgs.join(" ")); + g.avrdude_location( avrLoc ); + g.programmer( avrProgrammer); + g.mcu( avrMCU ); + g.avr_port( avrPort ); + g.avr_arguments( avrArgs.join(" ") ); + g.samba_location( sambaLoc ); + g.samba_port( sambaPort ); + g.arm_mcu( armMCU ); + g.dfu_location( dfuLoc ); + g.dfu_arguments( dfuArgs.join(" ") ); } void burnConfigDialog::populateProgrammers() diff --git a/companion/src/burndialog.cpp b/companion/src/burndialog.cpp index 05c0692d7..276a6c21a 100644 --- a/companion/src/burndialog.cpp +++ b/companion/src/burndialog.cpp @@ -59,7 +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)); } - ui->profile_label->setText(tr("Current profile")+QString(": ")+glob.pro[glob.profileId()].Name()); + ui->profile_label->setText(tr("Current profile")+QString(": ")+g.profile[g.id()].Name()); } if (!hexfileName->isEmpty()) { ui->FWFileName->setText(*hexfileName); @@ -69,19 +69,13 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac else { burnraw=false; if (checkeEprom(*hexfileName)) { - QSettings settings; - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(glob.profileId()); - settings.beginGroup(profile); - QString Name=settings.value("Name","").toString(); - QString calib=settings.value("StickPotCalib","").toString(); - QString trainercalib=settings.value("TrainerCalib","").toString(); - QString DisplaySet=settings.value("Display","").toString(); - QString BeeperSet=settings.value("Beeper","").toString(); - QString HapticSet=settings.value("Haptic","").toString(); - QString SpeakerSet=settings.value("Speaker","").toString(); - settings.endGroup(); - settings.endGroup(); + QString Name = g.profile[g.id()].Name(); + QString calib = g.profile[g.id()].StickPotCalib(); + QString trainercalib = g.profile[g.id()].TrainerCalib(); + QString DisplaySet = g.profile[g.id()].Display(); + QString BeeperSet = g.profile[g.id()].Beeper(); + QString HapticSet = g.profile[g.id()].Haptic(); + QString SpeakerSet = g.profile[g.id()].Speaker(); if (!Name.isEmpty()) { ui->profile_label->show(); ui->patchcalib_CB->show(); @@ -112,7 +106,7 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac } else if (Type==2) { QString FileName; - FileName = glob.lastFw(); + FileName = g.lastFw(); QFile file(FileName); if (file.exists()) { checkFw(FileName); @@ -146,11 +140,11 @@ void burnDialog::on_FlashLoadButton_clicked() ui->EEbackupCB->hide(); QTimer::singleShot(0, this, SLOT(shrink())); if (hexType==2) { - fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastFlashDir(), FLASH_FILES_FILTER); + fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.lastFlashDir(), FLASH_FILES_FILTER); checkFw(fileName); } else { - QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), glob.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), g.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); if (checkeEprom(fileName)) { if (burnraw==false) { ui->BurnFlashButton->setEnabled(true); @@ -206,8 +200,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 = glob.pro[glob.profileId()].SplashFileName(); - bool PatchFwCB = glob.pro[glob.profileId()].patchImage(); + QString ImageStr = g.profile[g.id()].SplashFileName(); + bool PatchFwCB = g.profile[g.id()].patchImage(); if (!ImageStr.isEmpty()) { QImage Image = qstring2image(ImageStr); ui->imageLabel->setPixmap(QPixmap::fromImage(Image.convertToFormat(flash.getSplashFormat()))); @@ -250,7 +244,7 @@ void burnDialog::checkFw(QString fileName) ui->BurnFlashButton->setEnabled(true); } QTimer::singleShot(0, this, SLOT(shrink())); - glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); + g.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); } bool burnDialog::checkeEprom(QString fileName) @@ -351,10 +345,10 @@ void burnDialog::on_ImageLoadButton_clicked() } QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), g.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); if (!fileName.isEmpty()) { - glob.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); + g.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); QImage image(fileName); if (image.isNull()) { QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName)); @@ -431,10 +425,10 @@ void burnDialog::on_BurnFlashButton_clicked() if (hexType==2) { QString fileName=ui->FWFileName->text(); if (!fileName.isEmpty()) { - glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); - glob.lastFw( fileName ); + g.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); + g.lastFw( fileName ); if (ui->PatchFWCB->isChecked()) { - glob.pro[glob.profileId()].patchImage( true ); + g.profile[g.id()].patchImage( true ); QImage image = ui->imageLabel->pixmap()->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height()); if (!image.isNull()) { QString tempDir = QDir::tempPath(); @@ -457,7 +451,7 @@ void burnDialog::on_BurnFlashButton_clicked() QMessageBox::critical(this, tr("Warning"), tr("Custom image not found")); } } else { - glob.pro[glob.profileId()].patchImage( false ); + g.profile[g.id()].patchImage( false ); hexfileName->clear(); hexfileName->append(fileName); } @@ -467,26 +461,19 @@ void burnDialog::on_BurnFlashButton_clicked() } } if (hexType==1) { - QSettings settings; - int profileid=glob.profileId(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profileid); - settings.beginGroup(profile); - QString calib=settings.value("StickPotCalib","").toString(); - QString trainercalib=settings.value("TrainerCalib","").toString(); + QString calib = g.profile[g.id()].StickPotCalib(); + QString trainercalib = g.profile[g.id()].TrainerCalib(); int potsnum=GetEepromInterface()->getCapability(Pots); - int8_t vBatCalib=(int8_t)settings.value("VbatCalib", radioData.generalSettings.vBatCalib).toInt(); - int8_t currentCalib=(int8_t)settings.value("currentCalib", radioData.generalSettings.currentCalib).toInt(); - int8_t PPM_Multiplier=(int8_t)settings.value("PPM_Multiplier", radioData.generalSettings.PPM_Multiplier).toInt(); - uint8_t GSStickMode=(uint8_t)settings.value("GSStickMode", radioData.generalSettings.stickMode).toUInt(); - uint8_t vBatWarn=(uint8_t)settings.value("vBatWarn",radioData.generalSettings.vBatWarn).toUInt(); + int8_t vBatCalib=(int8_t) g.profile[g.id()].VbatCalib(); + int8_t currentCalib=(int8_t) g.profile[g.id()].currentCalib(); + int8_t PPM_Multiplier=(int8_t) g.profile[g.id()].PPM_Multiplier(); + uint8_t GSStickMode=(uint8_t) g.profile[g.id()].GSStickMode(); + uint8_t vBatWarn=(uint8_t) g.profile[g.id()].vBatWarn(); - QString DisplaySet=settings.value("Display","").toString(); - QString BeeperSet=settings.value("Beeper","").toString(); - QString HapticSet=settings.value("Haptic","").toString(); - QString SpeakerSet=settings.value("Speaker","").toString(); - settings.endGroup(); - settings.endGroup(); + QString DisplaySet= g.profile[g.id()].Display(); + QString BeeperSet= g.profile[g.id()].Beeper(); + QString HapticSet= g.profile[g.id()].Haptic(); + QString SpeakerSet= g.profile[g.id()].Speaker(); bool patch=false; if (ui->patchcalib_CB->isChecked()) { if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) { @@ -644,7 +631,7 @@ void burnDialog::on_PreferredImageCB_toggled(bool checked) { QString tmpFileName; if (checked) { - QString ImageStr = glob.pro[glob.profileId()].SplashFileName(); + QString ImageStr = g.profile[g.id()].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 bb86ec500..1c5d3930e 100644 --- a/companion/src/customizesplashdialog.cpp +++ b/companion/src/customizesplashdialog.cpp @@ -46,7 +46,7 @@ bool Side::displayImage( QString fileName, Source pictSource ) if (pictSource== PICT) *format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X; else if (pictSource == PROFILE) - *format = (glob.pro[glob.profileId()].firmware().contains("taranis")) ? LCDTARANIS : LCD9X; + *format = (g.profile[g.id()].firmware().contains("taranis")) ? LCDTARANIS : LCD9X; } if (image.isNull()) { return false; @@ -115,7 +115,7 @@ bool Side::saveImage() } QImage image = imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight()); if (flash.setSplash(image) && (flash.saveFlash(*saveToFileName) > 0)) { - glob.lastFlashDir( QFileInfo(*saveToFileName).dir().absolutePath() ); + g.lastFlashDir( QFileInfo(*saveToFileName).dir().absolutePath() ); } else { return false; @@ -124,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)) { - glob.lastImagesDir( QFileInfo(*saveToFileName).dir().absolutePath() ); + g.lastImagesDir( QFileInfo(*saveToFileName).dir().absolutePath() ); } else { return false; @@ -181,12 +181,12 @@ void customizeSplashDialog::on_leftLoadFwButton_clicked() {loadFirmware(left);} void customizeSplashDialog::on_rightLoadFwButton_clicked() {loadFirmware(right);} void customizeSplashDialog::loadFirmware(Side side) { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastFlashDir(), FLASH_FILES_FILTER); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.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 - glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); + g.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); } } @@ -199,13 +199,13 @@ void customizeSplashDialog::loadPicture(Side side) supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; } QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), g.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 - glob.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); + g.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); } } @@ -213,7 +213,7 @@ void customizeSplashDialog::on_leftLoadProfileButton_clicked() {loadProfile(left void customizeSplashDialog::on_rightLoadProfileButton_clicked() {loadProfile(right);} void customizeSplashDialog::loadProfile(Side side) { - QString fileName=glob.pro[glob.profileId()].SplashFileName(); + QString fileName=g.profile[g.id()].SplashFileName(); if (!fileName.isEmpty()) { if (!side.displayImage( fileName, PROFILE )) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 63dfc096c..e830a5bee 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -6,7 +6,6 @@ #include "firmwares/gruvin9x/gruvin9xinterface.h" #include "firmwares/opentx/opentxinterface.h" #include "firmwares/ersky9x/ersky9xinterface.h" -#include "qsettings.h" #include "appdata.h" #include "helpers.h" @@ -732,34 +731,25 @@ GeneralSettings::GeneralSettings() calibSpanNeg[i] = 0x180; calibSpanPos[i] = 0x180; } - QSettings settings; - templateSetup = settings.value("default_channel_order", 0).toInt(); - stickMode = settings.value("default_mode", 1).toInt(); - int profile_id = glob.profileId(); - if (profile_id>-1) { - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profile_id); - settings.beginGroup(profile); - QString t_calib=settings.value("StickPotCalib","").toString(); + templateSetup = g.profile[g.id()].default_channel_order(); + stickMode = g.profile[g.id()].default_mode(); + + QString t_calib=g.profile[g.id()].StickPotCalib(); int potsnum=GetEepromInterface()->getCapability(Pots); if (t_calib.isEmpty()) { - settings.endGroup(); - settings.endGroup(); return; } else { - QString t_trainercalib=settings.value("TrainerCalib","").toString(); - int8_t t_vBatCalib=(int8_t)settings.value("VbatCalib", vBatCalib).toInt(); - int8_t t_currentCalib=(int8_t)settings.value("currentCalib", currentCalib).toInt(); - int8_t t_PPM_Multiplier=(int8_t)settings.value("PPM_Multiplier", PPM_Multiplier).toInt(); - uint8_t t_stickMode=(uint8_t)settings.value("GSStickMode", stickMode).toUInt(); - uint8_t t_vBatWarn=(uint8_t)settings.value("vBatWarn",vBatWarn).toUInt(); - QString t_DisplaySet=settings.value("Display","").toString(); - QString t_BeeperSet=settings.value("Beeper","").toString(); - QString t_HapticSet=settings.value("Haptic","").toString(); - QString t_SpeakerSet=settings.value("Speaker","").toString(); - QString t_CountrySet=settings.value("countryCode","").toString(); - settings.endGroup(); - settings.endGroup(); + QString t_trainercalib=g.profile[g.id()].TrainerCalib(); + int8_t t_vBatCalib=(int8_t)g.profile[g.id()].VbatCalib(); + int8_t t_currentCalib=(int8_t)g.profile[g.id()].currentCalib(); + int8_t t_PPM_Multiplier=(int8_t)g.profile[g.id()].PPM_Multiplier(); + uint8_t t_stickMode=(uint8_t)g.profile[g.id()].GSStickMode(); + uint8_t t_vBatWarn=(uint8_t)g.profile[g.id()].vBatWarn(); + QString t_DisplaySet=g.profile[g.id()].Display(); + QString t_BeeperSet=g.profile[g.id()].Beeper(); + QString t_HapticSet=g.profile[g.id()].Haptic(); + QString t_SpeakerSet=g.profile[g.id()].Speaker(); + QString t_CountrySet=g.profile[g.id()].countryCode(); if ((t_calib.length()==(NUM_STICKS+potsnum)*12) && (t_trainercalib.length()==16)) { QString Byte; @@ -841,7 +831,7 @@ GeneralSettings::GeneralSettings() } } } - } + } ModelData::ModelData() @@ -996,7 +986,7 @@ void RegisterEepromInterfaces() eepromInterfaces.push_back(new Open9xInterface(BOARD_GRUVIN9X)); eepromInterfaces.push_back(new Open9xInterface(BOARD_SKY9X)); eepromInterfaces.push_back(new Open9xInterface(BOARD_TARANIS)); - if (glob.rev4asupport()) + if (g.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/firmwares/er9x/er9xinterface.cpp b/companion/src/firmwares/er9x/er9xinterface.cpp index d28b472b2..a7137641f 100644 --- a/companion/src/firmwares/er9x/er9xinterface.cpp +++ b/companion/src/firmwares/er9x/er9xinterface.cpp @@ -19,6 +19,7 @@ #include "er9xeeprom.h" #include "er9xsimulator.h" #include "file.h" +#include "appdata.h" #define FILE_TYP_GENERAL 1 #define FILE_TYP_MODEL 2 @@ -44,8 +45,7 @@ const char * Er9xInterface::getName() const int Er9xInterface::getEEpromSize() { - QSettings settings; - QString avrMCU = settings.value("mcu", QString("m64")).toString(); + QString avrMCU = g.mcu(); if (avrMCU==QString("m128")) { return 2*EESIZE_STOCK; } diff --git a/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp b/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp index c3d52923f..a7d1d6f1a 100644 --- a/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp +++ b/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp @@ -18,6 +18,7 @@ #include "gruvin9xinterface.h" #include "gruvin9xeeprom.h" #include "file.h" +#include "appdata.h" #define FILE_TYP_GENERAL 1 #define FILE_TYP_MODEL 2 @@ -47,8 +48,7 @@ const char * Gruvin9xInterface::getName() const int Gruvin9xInterface::getEEpromSize() { if (board == BOARD_STOCK) { - QSettings settings; - QString avrMCU = settings.value("mcu", QString("m64")).toString(); + QString avrMCU = g.mcu(); if (avrMCU==QString("m128")) { return EESIZE_STOCK*2; } diff --git a/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp b/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp index b9f5f294e..61110d399 100644 --- a/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp +++ b/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp @@ -16,6 +16,7 @@ #include "opentxSky9xsimulator.h" #include "opentxinterface.h" +#include "appdata.h" #define SIMU #define SIMU_EXCEPTIONS @@ -135,8 +136,7 @@ using namespace Open9xSky9x; Open9xSky9xSimulator::Open9xSky9xSimulator(Open9xInterface * open9xInterface): open9xInterface(open9xInterface) { - QSettings settings; - QString path=settings.value("sdPath", ".").toString()+"/"; + QString path=g.profile[g.id()].sdPath()+"/"; int i=0; for (i=0; i< std::min(path.length(),1022); i++) { simuSdDirectory[i]=path.at(i).toAscii(); diff --git a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp index 266dd8c7f..49a317870 100644 --- a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp +++ b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp @@ -16,6 +16,7 @@ #include "opentxTaranisSimulator.h" #include "opentxinterface.h" +#include "appdata.h" #define SIMU #define SIMU_EXCEPTIONS @@ -181,8 +182,7 @@ OpentxTaranisSimulator::OpentxTaranisSimulator(Open9xInterface * open9xInterface open9xInterface(open9xInterface) { taranisSimulatorBoard = GetEepromInterface()->getBoard(); - QSettings settings; - QString path=settings.value("sdPath", ".").toString()+"/"; + QString path=g.profile[g.id()].sdPath()+"/"; int i=0; for (i=0; i< std::min(path.length(),1022); i++) { simuSdDirectory[i]=path.at(i).toAscii(); diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 16dbfeca9..35a0c48a3 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -26,6 +26,7 @@ #include "opentxSky9xsimulator.h" #include "opentxTaranisSimulator.h" #include "file.h" +#include "appdata.h" #define FILE_TYP_GENERAL 1 #define FILE_TYP_MODEL 2 @@ -933,9 +934,11 @@ bool Open9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esiz QString geturl( int board) { - QSettings settings; - QString url = settings.value("compilation-server", OPENTX_FIRMWARE_DOWNLOADS).toString(); - + QString url = g.compilationServer(); + if (url.isEmpty()){ + url= OPENTX_FIRMWARE_DOWNLOADS; + g.compilationServer(url); + } switch(board) { case BOARD_STOCK: case BOARD_M128: @@ -956,8 +959,11 @@ QString geturl( int board) QString getstamp( int board) { - QSettings settings; - QString url = settings.value("compilation-server", OPENTX_FIRMWARE_DOWNLOADS).toString(); + QString url = g.compilationServer(); + if (url.isEmpty()){ + url= OPENTX_FIRMWARE_DOWNLOADS; + g.compilationServer(url); + } url.append("/stamp-opentx-"); switch(board) { case BOARD_STOCK: @@ -985,8 +991,11 @@ QString getstamp( int board) QString getrnurl( int board) { - QSettings settings; - QString url = settings.value("compilation-server", OPENTX_FIRMWARE_DOWNLOADS).toString(); + QString url = g.compilationServer(); + if (url.isEmpty()){ + url= OPENTX_FIRMWARE_DOWNLOADS; + g.compilationServer(url); + } url.append("/releasenotes-"); switch(board) { case BOARD_STOCK: @@ -1212,9 +1221,7 @@ void RegisterOpen9xFirmwares() open9x->addOptions(fai_options); firmwares.push_back(open9x); - QSettings settings; - int rev4a = settings.value("rev4asupport",0).toInt(); - if (rev4a) { + if (g.rev4asupport()) { open9x = new Open9xFirmware("opentx-taranisrev4a", QObject::tr("OpenTX for FrSky Taranis Rev4a"), new Open9xInterface(BOARD_TARANIS_REV4a), geturl(BOARD_TARANIS_REV4a), getstamp(BOARD_TARANIS_REV4a),getrnurl(BOARD_TARANIS), true); open9x->addOption("noheli", QObject::tr("Disable HELI menu and cyclic mix support")); open9x->addOption("notemplates", QObject::tr("Disable TEMPLATES menu")); diff --git a/companion/src/firmwares/th9x/th9xinterface.cpp b/companion/src/firmwares/th9x/th9xinterface.cpp index 8e3e36ab6..dda8b5e6c 100644 --- a/companion/src/firmwares/th9x/th9xinterface.cpp +++ b/companion/src/firmwares/th9x/th9xinterface.cpp @@ -19,6 +19,7 @@ #include "th9xeeprom.h" #include "th9xsimulator.h" #include "file.h" +#include "appdata.h" #define FILE_TYP_GENERAL 1 #define FILE_TYP_MODEL 2 @@ -44,8 +45,7 @@ const char * Th9xInterface::getName() const int Th9xInterface::getEEpromSize() { - QSettings settings; - QString avrMCU = settings.value("mcu", QString("m64")).toString(); + QString avrMCU = g.mcu(); if (avrMCU==QString("m128")) { return 2*EESIZE_STOCK; } diff --git a/companion/src/fwpreferencesdialog.cpp b/companion/src/fwpreferencesdialog.cpp index 0113ee3cd..630c7a23c 100644 --- a/companion/src/fwpreferencesdialog.cpp +++ b/companion/src/fwpreferencesdialog.cpp @@ -188,11 +188,8 @@ void fwPreferencesDialog::firmwareChanged() ui->CPU_ID_LE->hide(); ui->CPU_ID_LABEL->hide(); } - QSettings settings; - settings.beginGroup("FwRevisions"); - int fwrev = settings.value(variant.id, -1).toInt(); - settings.endGroup(); - if (fwrev != -1) { + int fwrev = g.fwRev.get(variant.id); + if (fwrev != 0) { ui->FwInfo->setText(tr("Last downloaded release: %1").arg(fwrev)); if (!stamp.isEmpty()) { ui->checkFWUpdates->show(); @@ -214,9 +211,9 @@ void fwPreferencesDialog::firmwareChanged() void fwPreferencesDialog::writeValues() { - glob.cpu_id( ui->CPU_ID_LE->text() ); + g.cpu_id( ui->CPU_ID_LE->text() ); current_firmware_variant = getFirmwareVariant(); - glob.pro[glob.profileId()].firmware( current_firmware_variant.id ); + g.profile[g.id()].firmware( current_firmware_variant.id ); } void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware) @@ -274,7 +271,7 @@ void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware) void fwPreferencesDialog::initSettings() { - ui->CPU_ID_LE->setText(glob.cpu_id()); + ui->CPU_ID_LE->setText(g.cpu_id()); FirmwareInfo * current_firmware = GetCurrentFirmware(); foreach(FirmwareInfo * firmware, firmwares) { @@ -291,9 +288,9 @@ void fwPreferencesDialog::initSettings() void fwPreferencesDialog::on_checkFWUpdates_clicked() { FirmwareVariant variant = getFirmwareVariant(); - if (glob.pro[glob.profileId()].burnFirmware()) { + if (g.profile[g.id()].burnFirmware()) { current_firmware_variant = variant; - glob.pro[glob.profileId()].firmware( variant.id ); + g.profile[g.id()].firmware( variant.id ); } MainWindow * mw = (MainWindow *)this->parent(); mw->checkForUpdates(true, variant.id); @@ -306,9 +303,9 @@ void fwPreferencesDialog::on_fw_dnld_clicked() FirmwareVariant variant = getFirmwareVariant(); writeValues(); if (!variant.firmware->getUrl(variant.id).isNull()) { - if (glob.pro[glob.profileId()].burnFirmware()) { + if (g.profile[g.id()].burnFirmware()) { current_firmware_variant = getFirmwareVariant(); - glob.pro[glob.profileId()].firmware( current_firmware_variant.id ); + g.profile[g.id()].firmware( current_firmware_variant.id ); } mw->downloadLatestFW(current_firmware_variant.firmware, current_firmware_variant.id); } diff --git a/companion/src/generaledit.cpp b/companion/src/generaledit.cpp index f197eb7b1..2ac657bde 100644 --- a/companion/src/generaledit.cpp +++ b/companion/src/generaledit.cpp @@ -1,9 +1,9 @@ #include "generaledit.h" #include "ui_generaledit.h" #include "helpers.h" +#include "appdata.h" #include -#define MAX_PROFILES 10 #define BIT_WARN_THR ( 0x01 ) #define BIT_WARN_SW ( 0x02 ) #define BIT_WARN_MEM ( 0x04 ) @@ -20,18 +20,12 @@ GeneralEdit::GeneralEdit(RadioData &radioData, QWidget *parent) : ui->setupUi(this); this->setWindowIcon(QIcon(":/icon.png")); - QSettings settings; - QString firmware_id = settings.value("firmware", default_firmware_variant.id).toString(); - ui->tabWidget->setCurrentIndex(settings.value("generalEditTab", 0).toInt()); - int profile_id=settings.value("profileId", 0).toInt(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profile_id); - settings.beginGroup(profile); - QString name=settings.value("Name","").toString(); + QString firmware_id = g.profile[g.id()].firmware(); + ui->tabWidget->setCurrentIndex( g.generalEditTab() ); + QString name=g.profile[g.id()].Name(); if (name.isEmpty()) { ui->calstore_PB->setDisabled(true); } - settings.endGroup(); EEPROMInterface *eepromInterface = GetEepromInterface(); QLabel * pmsl[] = {ui->ro_label,ui->ro1_label,ui->ro2_label,ui->ro3_label,ui->ro4_label,ui->ro5_label,ui->ro6_label,ui->ro7_label,ui->ro8_label, NULL}; QSlider * tpmsld[] = {ui->chkSA, ui->chkSB, ui->chkSC, ui->chkSD, ui->chkSE, ui->chkSF, ui->chkSG, ui->chkSH, NULL}; @@ -76,18 +70,14 @@ GeneralEdit::GeneralEdit(RadioData &radioData, QWidget *parent) : } ui->profile_CB->clear(); for ( int i = 0; i < MAX_PROFILES; ++i) { - QString profile=QString("profile%1").arg(i+1); - settings.beginGroup(profile); - QString name=settings.value("Name","").toString(); + QString name=g.profile[i].Name(); if (!name.isEmpty()) { - ui->profile_CB->addItem(name, i+1); - if ((i+1)==profile_id) { - ui->profile_CB->setCurrentIndex(ui->profile_CB->count()-1); + ui->profile_CB->addItem(name, i); + if (i==g.id()) { + ui->profile_CB->setCurrentIndex(ui->profile_CB->count()); } } - settings.endGroup(); } - settings.endGroup(); QRegExp rx(CHAR_FOR_NAMES_REGEX); ui->ownerNameLE->setValidator(new QRegExpValidator(rx, this)); @@ -970,9 +960,7 @@ void GeneralEdit::on_PPM4_editingFinished() void GeneralEdit::on_tabWidget_currentChanged(int index) { - // TODO why er9x here - QSettings settings; - settings.setValue("generalEditTab",index);//ui->tabWidget->currentIndex()); + g.generalEditTab(index); } @@ -1220,31 +1208,23 @@ void GeneralEdit::on_swGEAChkB_stateChanged(int ) void GeneralEdit::on_calretrieve_PB_clicked() { - QSettings settings; int profile_id=ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profile_id); - settings.beginGroup(profile); - QString calib=settings.value("StickPotCalib","").toString(); + QString calib=g.profile[profile_id].StickPotCalib(); int potsnum=GetEepromInterface()->getCapability(Pots); if (calib.isEmpty()) { - settings.endGroup(); - settings.endGroup(); return; } else { - QString trainercalib=settings.value("TrainerCalib","").toString(); - int8_t vBatCalib=(int8_t)settings.value("VbatCalib", g_eeGeneral.vBatCalib).toInt(); - int8_t currentCalib=(int8_t)settings.value("currentCalib", g_eeGeneral.currentCalib).toInt(); - int8_t PPM_Multiplier=(int8_t)settings.value("PPM_Multiplier", g_eeGeneral.PPM_Multiplier).toInt(); - uint8_t GSStickMode=(uint8_t)settings.value("GSStickMode", g_eeGeneral.stickMode).toUInt(); - uint8_t vBatWarn=(uint8_t)settings.value("vBatWarn",g_eeGeneral.vBatWarn).toUInt(); - QString DisplaySet=settings.value("Display","").toString(); - QString BeeperSet=settings.value("Beeper","").toString(); - QString HapticSet=settings.value("Haptic","").toString(); - QString SpeakerSet=settings.value("Speaker","").toString(); - QString CountrySet=settings.value("countryCode","").toString(); - settings.endGroup(); - settings.endGroup(); + QString trainercalib = g.profile[profile_id].TrainerCalib(); + int8_t vBatCalib = (int8_t)g.profile[profile_id].VbatCalib(); + int8_t currentCalib = (int8_t)g.profile[profile_id].currentCalib(); + int8_t PPM_Multiplier = (int8_t)g.profile[profile_id].PPM_Multiplier(); + uint8_t GSStickMode = (uint8_t)g.profile[profile_id].GSStickMode(); + uint8_t vBatWarn = (uint8_t)g.profile[profile_id].vBatWarn(); + QString DisplaySet = g.profile[profile_id].Display(); + QString BeeperSet = g.profile[profile_id].Beeper(); + QString HapticSet = g.profile[profile_id].Haptic(); + QString SpeakerSet = g.profile[profile_id].Speaker(); + QString CountrySet = g.profile[profile_id].countryCode(); if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) { QString Byte; @@ -1337,27 +1317,20 @@ void GeneralEdit::on_calretrieve_PB_clicked() void GeneralEdit::on_calstore_PB_clicked() { - QSettings settings; int profile_id=ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profile_id); - settings.beginGroup(profile); - QString name=settings.value("Name","").toString(); + + QString name=g.profile[profile_id].Name(); int potsnum=GetEepromInterface()->getCapability(Pots); if (name.isEmpty()) { ui->calstore_PB->setDisabled(true); - settings.endGroup(); - settings.endGroup(); return; } else { - QString calib=settings.value("StickPotCalib","").toString(); + QString calib=g.profile[profile_id].StickPotCalib(); if (!(calib.isEmpty())) { int ret = QMessageBox::question(this, "Companion", tr("Do you want to store calibration in %1 profile
overwriting existing calibration?").arg(name) , QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::No) { - settings.endGroup(); - settings.endGroup(); return; } } @@ -1367,24 +1340,22 @@ void GeneralEdit::on_calstore_PB_clicked() calib.append(QString("%1").arg((uint16_t)g_eeGeneral.calibSpanNeg[i], 4, 16, QChar('0'))); calib.append(QString("%1").arg((uint16_t)g_eeGeneral.calibSpanPos[i], 4, 16, QChar('0'))); } - settings.setValue("StickPotCalib",calib); + g.profile[profile_id].StickPotCalib( calib ); calib.clear(); for (int i=0; i< 4; i++) { calib.append(QString("%1").arg((uint16_t)g_eeGeneral.trainer.calib[i], 4, 16, QChar('0'))); } - settings.setValue("TrainerCalib",calib); - settings.setValue("VbatCalib",g_eeGeneral.vBatCalib); - settings.setValue("currentCalib",g_eeGeneral.currentCalib); - settings.setValue("vBatWarn",g_eeGeneral.vBatWarn); - settings.setValue("PPM_Multiplier",g_eeGeneral.PPM_Multiplier); - settings.setValue("GSStickMode",g_eeGeneral.stickMode); - settings.setValue("Display",QString("%1%2%3").arg((g_eeGeneral.optrexDisplay ? 1:0), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.contrast, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.backlightBright, 2, 16, QChar('0'))); - settings.setValue("Beeper",QString("%1%2").arg(((uint8_t)g_eeGeneral.beeperMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.beeperLength, 2, 16, QChar('0'))); - settings.setValue("Haptic",QString("%1%2%3").arg(((uint8_t)g_eeGeneral.hapticMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticStrength, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticLength, 2, 16, QChar('0'))); - settings.setValue("Speaker",QString("%1%2%3").arg((uint8_t)g_eeGeneral.speakerMode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerPitch, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerVolume, 2, 16, QChar('0'))); - settings.setValue("countryCode",QString("%1%2%3").arg((uint8_t)g_eeGeneral.countryCode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.imperial, 2, 16, QChar('0')).arg(g_eeGeneral.ttsLanguage)); - settings.endGroup(); - settings.endGroup(); + g.profile[profile_id].TrainerCalib( calib ); + g.profile[profile_id].VbatCalib( g_eeGeneral.vBatCalib ); + g.profile[profile_id].currentCalib( g_eeGeneral.currentCalib ); + g.profile[profile_id].vBatWarn( g_eeGeneral.vBatWarn ); + g.profile[profile_id].PPM_Multiplier( g_eeGeneral.PPM_Multiplier ); + g.profile[profile_id].GSStickMode( g_eeGeneral.stickMode ); + g.profile[profile_id].Display( QString("%1%2%3").arg((g_eeGeneral.optrexDisplay ? 1:0), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.contrast, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.backlightBright, 2, 16, QChar('0')) ); + g.profile[profile_id].Beeper( QString("%1%2").arg(((uint8_t)g_eeGeneral.beeperMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.beeperLength, 2, 16, QChar('0'))); + g.profile[profile_id].Haptic( QString("%1%2%3").arg(((uint8_t)g_eeGeneral.hapticMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticStrength, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticLength, 2, 16, QChar('0'))); + g.profile[profile_id].Speaker( QString("%1%2%3").arg((uint8_t)g_eeGeneral.speakerMode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerPitch, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerVolume, 2, 16, QChar('0'))); + g.profile[profile_id].countryCode( QString("%1%2%3").arg((uint8_t)g_eeGeneral.countryCode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.imperial, 2, 16, QChar('0')).arg(g_eeGeneral.ttsLanguage)); QMessageBox::information(this, "Companion", tr("Calibration and HW parameters saved.")); } } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 5a74c4afc..2f1f3a650 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -914,7 +914,7 @@ QString getCenterBeep(ModelData * g_model) QString getTheme() { - int theme_set = glob.theme(); + int theme_set = g.theme(); QString Theme; switch(theme_set) { case 0: diff --git a/companion/src/joystickdialog.cpp b/companion/src/joystickdialog.cpp index 2c77359a8..431717324 100644 --- a/companion/src/joystickdialog.cpp +++ b/companion/src/joystickdialog.cpp @@ -1,5 +1,6 @@ #include "joystickdialog.h" #include "ui_joystickdialog.h" +#include "appdata.h" #include joystickDialog::joystickDialog(QWidget *parent, int stick) : @@ -130,27 +131,20 @@ void joystickDialog::on_okButton_clicked() { return; } joystick->close(); - QSettings settings; - settings.beginGroup("JsCalibration"); for (int i=0; i<8;i++) { - settings.remove(QString("stick%1_axe").arg(i)); - settings.remove(QString("stick%1_max").arg(i)); - settings.remove(QString("stick%1_med").arg(i)); - settings.remove(QString("stick%1_min").arg(i)); - settings.remove(QString("stick%1_inv").arg(i)); + g.joystick[i].remove(); } QCheckBox * ib[]={ui->ChInv_1, ui->ChInv_2, ui->ChInv_3, ui->ChInv_4, ui->ChInv_5, ui->ChInv_6, ui->ChInv_7, ui->ChInv_8}; foreach(QComboBox *cb, findChildren(QRegExp("jsmapCB_[0-9]+"))) { int axe=cb->objectName().mid(cb->objectName().lastIndexOf("_")+1).toInt()-1; int stick=cb->currentIndex(); - if (stick>0) { - settings.setValue(QString("stick%1_axe").arg(stick),axe); - settings.setValue(QString("stick%1_max").arg(stick),jscal[axe][2]); - settings.setValue(QString("stick%1_med").arg(stick),jscal[axe][1]); - settings.setValue(QString("stick%1_min").arg(stick),jscal[axe][0]); - settings.setValue(QString("stick%1_inv").arg(stick),ib[axe]->isChecked() ? 1 : 0); + if (stick > 0) { + g.joystick[stick].stick_axe( axe ); + g.joystick[stick].stick_max( jscal[axe][2] ); + g.joystick[stick].stick_med( jscal[axe][1] ); + g.joystick[stick].stick_min( jscal[axe][0] ); + g.joystick[stick].stick_inv( ib[axe]->isChecked() ? 1 : 0 ); } } - settings.endGroup(); this->close(); } diff --git a/companion/src/lcdwidget.h b/companion/src/lcdwidget.h index 7433b640d..1e4362a72 100644 --- a/companion/src/lcdwidget.h +++ b/companion/src/lcdwidget.h @@ -49,9 +49,9 @@ class lcdWidget : public QWidget { void setBackgroundColor(int red, int green, int blue) { - r = red; - g = green; - b = blue; + _r = red; + _g = green; + _b = blue; } void makeScreenshot(const QString & fileName) @@ -59,10 +59,10 @@ class lcdWidget : public QWidget { QPixmap buffer(2*lcdWidth, 2*lcdHeight); QPainter p(&buffer); doPaint(p); - bool toclipboard=glob.snapshot_to_clipboard(); + bool toclipboard=g.snapshot_to_clipboard(); QApplication::clipboard()->setPixmap( buffer ); if (!toclipboard) { - QString Path=glob.snapshotpath(); + QString Path=g.snapshotpath(); if (Path.isEmpty() || !QDir(Path).exists()) { Path="."; } @@ -98,14 +98,14 @@ class lcdWidget : public QWidget { unsigned char *previousBuf; bool lightEnable; - int r, g, b; + int _r, _g, _b; inline void doPaint(QPainter & p) { QRgb rgb; if (lightEnable) - rgb = qRgb(r, g, b); + rgb = qRgb(_r, _g, _b); else rgb = qRgb(161, 161, 161); @@ -136,7 +136,7 @@ class lcdWidget : public QWidget { if (z != previousDepth) { previousDepth = z; if (lightEnable) - rgb = qRgb(r-(z*r)/15, g-(z*g)/15, b-(z*b)/15); + rgb = qRgb(_r-(z*_r)/15, _g-(z*_g)/15, _b-(z*_b)/15); else rgb = qRgb(161-(z*161)/15, 161-(z*161)/15, 161-(z*161)/15); p.setPen(rgb); diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index 874ed21d3..e9f6c189f 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -39,7 +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); - QString Path=glob.gePath(); + QString Path=g.gePath(); if (Path.isEmpty() || !QFile(Path).exists()) { ui->mapsButton->hide(); } @@ -202,7 +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}; - QString gePath=glob.gePath(); + QString gePath=g.gePath(); if (gePath.isEmpty() || !QFile(gePath).exists()) { ui->FieldsTW->setDisabled(false); ui->logTable->setDisabled(false); @@ -584,9 +584,9 @@ void logsDialog::moveLegend() void logsDialog::on_fileOpen_BT_clicked() { - QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), glob.lastLogDir()); + QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), g.lastLogDir()); if (!fileName.isEmpty()) { - glob.lastLogDir( fileName ); + g.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 960d06b7a..bf70e6a2d 100644 --- a/companion/src/main.cpp +++ b/companion/src/main.cpp @@ -75,7 +75,7 @@ class MyProxyStyle : public QProxyStyle #endif // Global data and storge object -AppData glob; +AppData g; int main(int argc, char *argv[]) { @@ -90,26 +90,26 @@ int main(int argc, char *argv[]) #endif QTranslator companionTranslator; - companionTranslator.load(":/companion_" + glob.locale()); + companionTranslator.load(":/companion_" + g.locale()); QTranslator qtTranslator; - qtTranslator.load((QString)"qt_" + glob.locale().left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + qtTranslator.load((QString)"qt_" + g.locale().left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); app.installTranslator(&companionTranslator); app.installTranslator(&qtTranslator); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - if (glob.pro[glob.profileId()].firmware().isEmpty()) - glob.pro[glob.profileId()].firmware(default_firmware_variant.id); + if (g.profile[g.id()].firmware().isEmpty()) + g.profile[g.id()].firmware(default_firmware_variant.id); - QPixmap pixmap = QPixmap(glob.pro[glob.profileId()].firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); + QPixmap pixmap = QPixmap(g.profile[g.id()].firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); QSplashScreen *splash = new QSplashScreen(pixmap); RegisterFirmwares(); - current_firmware_variant = GetFirmwareVariant(glob.pro[glob.profileId()].firmware()); + current_firmware_variant = GetFirmwareVariant(g.profile[g.id()].firmware()); MainWindow *mainWin = new MainWindow(); - if (glob.show_splash()) { + if (g.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.cpp b/companion/src/mainwindow.cpp index 8625537e6..95217ba60 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -100,7 +100,7 @@ MainWindow::MainWindow(): createStatusBar(); updateMenus(); - restoreState(glob.mainWindowState()); + restoreState(g.mainWindowState()); setUnifiedTitleAndToolBarOnMac(true); this->setWindowIcon(QIcon(":/icon.png")); @@ -110,7 +110,7 @@ MainWindow::MainWindow(): // give time to the splash to disappear and main window to open before starting updates int updateDelay = 1000; - bool showSplash = glob.show_splash(); + bool showSplash = g.show_splash(); if (showSplash) { updateDelay += (SPLASH_TIME*1000); } @@ -163,7 +163,7 @@ MainWindow::MainWindow(): void MainWindow::displayWarnings() { - int warnId=glob.warningId(); + int warnId=g.warningId(); if (warnId0) { @@ -174,10 +174,10 @@ void MainWindow::displayWarnings() res = QMessageBox::question(this, "Companion",tr("Display previous message again at startup ?"),QMessageBox::Yes | QMessageBox::No); } if (res == QMessageBox::No) { - glob.warningId(WARNING_ID); + g.warningId(WARNING_ID); } } else if (warnId==0) { - glob.warningId(WARNING_ID); + g.warningId(WARNING_ID); } } @@ -200,7 +200,7 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId) QString stamp = GetFirmware(fwToUpdate)->stamp; if (!stamp.isEmpty()) { - if (glob.startup_check_fw() || ignoreSettings) { + if (g.startup_check_fw() || ignoreSettings) { check1done=false; manager1 = new QNetworkAccessManager(this); connect(manager1, SIGNAL(finished(QNetworkReply*)), this, SLOT(reply1Finished(QNetworkReply*))); @@ -211,7 +211,7 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId) } } - if (glob.startup_check_companion() || ignoreSettings) { + if (g.startup_check_companion() || ignoreSettings) { check2done = false; manager2 = new QNetworkAccessManager(this); connect(manager2, SIGNAL(finished(QNetworkReply*)),this, SLOT(checkForUpdateFinished(QNetworkReply*))); @@ -263,12 +263,12 @@ void MainWindow::checkForUpdateFinished(QNetworkReply * reply) if (ret == QMessageBox::Yes) { #if defined __APPLE__ - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version)); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version)); #else - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version), tr("Executable (*.exe)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version), tr("Executable (*.exe)")); #endif if (!fileName.isEmpty()) { - glob.lastUpdatesDir(QFileInfo(fileName).dir().absolutePath()); + g.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())); @@ -302,9 +302,9 @@ void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmw { QString url, ext, cpuid; url = firmware->getUrl(firmwareId); - cpuid=glob.cpu_id(); + cpuid=g.cpu_id(); ext = url.mid(url.lastIndexOf(".")); - QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + firmwareId + ext); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.lastFlashDir() + "/" + firmwareId + ext); if (!fileName.isEmpty()) { downloadedFW = firmwareId; needRename=true; @@ -313,7 +313,7 @@ void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmw url.append("&cpuid="); url.append(cpuid); } - glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); + g.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); downloadDialog * dd = new downloadDialog(this, url, fileName); connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted())); dd->exec(); @@ -323,8 +323,6 @@ void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmw void MainWindow::reply1Accepted() { QString errormsg; - QSettings settings; - settings.beginGroup("FwRevisions"); if (downloadedFWFilename.isEmpty()) { if (!(downloadedFW.isEmpty())) { QFile file(downloadedFW); @@ -359,12 +357,11 @@ void MainWindow::reply1Accepted() } file.close(); QMessageBox::critical(this, tr("Error"), errormsg); - settings.endGroup(); return; } file.close(); currentFWrev = currentFWrev_temp; - settings.setValue(downloadedFW, currentFWrev); + g.fwRev.set(downloadedFW, currentFWrev); } } else { QFile file(downloadedFWFilename); @@ -399,7 +396,6 @@ void MainWindow::reply1Accepted() } file.close(); QMessageBox::critical(this, tr("Error"), errormsg); - settings.endGroup(); return; } file.close(); @@ -408,7 +404,7 @@ void MainWindow::reply1Accepted() int pos=rev.lastIndexOf("-r"); if (pos>0) { currentFWrev=rev.mid(pos+2).toInt(); - if (glob.pro[glob.profileId()].rename_firmware_files() && needRename) { + if (g.profile[g.id()].rename_firmware_files() && needRename) { QFileInfo fi(downloadedFWFilename); QString path=fi.path()+QDir::separator (); path.append(fi.completeBaseName()); @@ -420,8 +416,8 @@ void MainWindow::reply1Accepted() qd.rename(downloadedFWFilename,path); downloadedFWFilename=path; } - settings.setValue(downloadedFW, currentFWrev); - if (glob.pro[glob.profileId()].burnFirmware()) { + g.fwRev.set(downloadedFW, currentFWrev); + if (g.profile[g.id()].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); @@ -429,7 +425,6 @@ void MainWindow::reply1Accepted() } } } - settings.endGroup(); } void MainWindow::reply1Finished(QNetworkReply * reply) @@ -445,8 +440,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) // TODO delete downloadDialog_forWait? } - QSettings settings; - cpuid=glob.cpu_id(); + cpuid=g.cpu_id(); QByteArray qba = reply->readAll(); int i = qba.indexOf("SVN_VERS"); int warning = qba.indexOf("WARNING"); @@ -460,15 +454,13 @@ void MainWindow::reply1Finished(QNetworkReply * reply) if(!cres) { QMessageBox::warning(this, "Companion", tr("Unable to check for updates.")); - glob.fwserver(glob.fwserver()+1); + g.fwserver(g.fwserver()+1); return; } if(rev>0) { NewFwRev=rev; - settings.beginGroup("FwRevisions"); - OldFwRev = settings.value(fwToUpdate, 0).toInt(); - settings.endGroup(); + OldFwRev = g.fwRev.get(fwToUpdate); QMessageBox msgBox; QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); QGridLayout* layout = (QGridLayout*)msgBox.layout(); @@ -539,9 +531,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) if (ignore) { int res = QMessageBox::question(this, "Companion",tr("Ignore this version (r%1)?").arg(rev), QMessageBox::Yes | QMessageBox::No); if (res==QMessageBox::Yes) { - settings.beginGroup("FwRevisions"); - settings.setValue(fwToUpdate, NewFwRev); - settings.endGroup(); + g.fwRev.set(fwToUpdate, NewFwRev); } } else if (download == true) { if (warning>0) { @@ -558,12 +548,12 @@ void MainWindow::reply1Finished(QNetworkReply * reply) QString url = GetFirmware(fwToUpdate)->getUrl(fwToUpdate); QString ext = url.mid(url.lastIndexOf(".")); needRename=false; - bool addversion=glob.pro[glob.profileId()].rename_firmware_files(); + bool addversion=g.profile[g.id()].rename_firmware_files(); QString fileName; if (addversion) { - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + newrev + ext); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.lastFlashDir() + "/" + fwToUpdate + newrev + ext); } else { - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + ext); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.lastFlashDir() + "/" + fwToUpdate + ext); } if (!fileName.isEmpty()) { if (!cpuid.isEmpty()) { @@ -571,7 +561,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) url.append(cpuid); } downloadedFWFilename = fileName; - glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); + g.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); downloadDialog * dd = new downloadDialog(this, url, fileName); currentFWrev_temp = NewFwRev; connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted())); @@ -585,7 +575,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) } else { if(check1done && check2done) { QMessageBox::warning(this, "Companion", tr("Unable to check for updates.")); - glob.fwserver(glob.fwserver()+1); + g.fwserver(g.fwserver()+1); return; } } @@ -593,8 +583,8 @@ void MainWindow::reply1Finished(QNetworkReply * reply) void MainWindow::closeEvent(QCloseEvent *event) { - glob.mainWindowGeometry(saveGeometry()); - glob.mainWindowState(saveState()); + g.mainWindowGeometry(saveGeometry()); + g.mainWindowState(saveState()); mdiArea->closeAllSubWindows(); if (mdiArea->currentSubWindow()) { event->ignore(); @@ -606,7 +596,7 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::setLanguage(QString langString) { - glob.locale( langString ); + g.locale( langString ); QMessageBox msgBox; msgBox.setText(tr("The selected language will be used the next time you start Companion.")); @@ -617,7 +607,7 @@ void MainWindow::setLanguage(QString langString) void MainWindow::setTheme(int index) { - glob.theme( index ); + g.theme( index ); QMessageBox msgBox; msgBox.setText(tr("The new theme will be loaded the next time you start Companion.")); @@ -628,7 +618,7 @@ void MainWindow::setTheme(int index) void MainWindow::setIconThemeSize(int index) { - glob.icon_size( index ); + g.icon_size( index ); QMessageBox msgBox; msgBox.setText(tr("The icon size will be used the next time you start Companion.")); @@ -652,9 +642,9 @@ void MainWindow::openDocURL() void MainWindow::openFile() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastDir(), tr(EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.lastDir(), tr(EEPROM_FILES_FILTER)); if (!fileName.isEmpty()) { - glob.lastDir(QFileInfo(fileName).dir().absolutePath()); + g.lastDir(QFileInfo(fileName).dir().absolutePath()); QMdiSubWindow *existing = findMdiChild(fileName); if (existing) { @@ -709,10 +699,10 @@ void MainWindow::loadProfile() //TODO Load all variables - Also HW! if (action) { // Set the new profile number int profnum=action->data().toInt(); - glob.profileId( profnum ); + g.id( profnum ); // TODO Get rid of this global variable - The profile.firmware is the real source - current_firmware_variant = GetFirmwareVariant(glob.pro[glob.profileId()].firmware()); + current_firmware_variant = GetFirmwareVariant(g.profile[g.id()].firmware()); foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { MdiChild *mdiChild = qobject_cast(window->widget()); @@ -1065,14 +1055,14 @@ void MainWindow::writeFileToEeprom() burnDialog *cd = new burnDialog(this, 1, &fileName, &backup); cd->exec(); if (!fileName.isEmpty()) { - glob.lastDir(QFileInfo(fileName).dir().absolutePath()); + g.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 = glob.backupEnable(); - QString backupPath = glob.backupPath(); + bool backupEnable = g.backupEnable(); + QString backupPath = g.backupPath(); if (!backupPath.isEmpty()) { if (!QDir(backupPath).exists()) { if (backupEnable) { @@ -1314,7 +1304,7 @@ bool MainWindow::convertEEPROM(QString backupFile, QString restoreFile, QString void MainWindow::writeFlash(QString fileToFlash) { QString fileName; - bool backup = glob.backupOnFlash(); + bool backup = g.backupOnFlash(); if(!fileToFlash.isEmpty()) fileName = fileToFlash; burnDialog *cd = new burnDialog(this, 2, &fileName, &backup); @@ -1322,12 +1312,12 @@ void MainWindow::writeFlash(QString fileToFlash) if (IS_TARANIS(GetEepromInterface()->getBoard())) backup=false; if (!fileName.isEmpty()) { - glob.backupOnFlash(backup); + g.backupOnFlash(backup); if (backup) { QString tempDir = QDir::tempPath(); QString backupFile = tempDir + "/backup.bin"; - bool backupEnable=glob.backupEnable(); - QString backupPath=glob.backupPath(); + bool backupEnable=g.backupEnable(); + QString backupPath=g.backupPath(); if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) { if (!QDir(backupPath).exists()) { if (backupEnable) { @@ -1381,8 +1371,8 @@ void MainWindow::writeFlash(QString fileToFlash) } } else { - bool backupEnable=glob.backupEnable(); - QString backupPath=glob.backupPath(); + bool backupEnable=g.backupEnable(); + QString backupPath=g.backupPath(); if (!QDir(backupPath).exists()) { if (backupEnable) { QMessageBox::warning(this, tr("Backup is impossible"), tr("The backup dir set in preferences does not exist")); @@ -1411,7 +1401,7 @@ void MainWindow::writeFlash(QString fileToFlash) void MainWindow::readEepromToFile() { - QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), glob.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), g.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); if (!fileName.isEmpty()) { EEPROMInterface *eepromInterface = GetEepromInterface(); if (IS_TARANIS(eepromInterface->getBoard())) { @@ -1430,7 +1420,7 @@ void MainWindow::readEepromToFile() } } else { - glob.lastDir(QFileInfo(fileName).dir().absolutePath()); + g.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")); @@ -1442,13 +1432,13 @@ void MainWindow::readEepromToFile() void MainWindow::readFlash() { - QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), glob.lastFlashDir(),tr(FLASH_FILES_FILTER)); + QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), g.lastFlashDir(),tr(FLASH_FILES_FILTER)); if (!fileName.isEmpty()) { QFile file(fileName); if (file.exists()) { file.remove(); } - glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath()); + g.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")); @@ -1527,7 +1517,7 @@ void MainWindow::updateMenus() updateIconSizeActions(); updateIconThemeActions(); - setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( glob.pro[glob.profileId()].Name() )); + setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( g.profile[g.id()].Name() )); } MdiChild *MainWindow::createMdiChild() @@ -1780,7 +1770,7 @@ QMenu *MainWindow::createProfilesMenu() void MainWindow::createToolBars() { QSize size; - switch(glob.icon_size()) { + switch(g.icon_size()) { case 0: size=QSize(16,16); break; @@ -1896,12 +1886,12 @@ void MainWindow::updateRecentFileActions() int i, numRecentFiles; // Hide all document slots - for ( i=0 ; i < glob.history_size(); i++) + for ( i=0 ; i < g.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()); + QStringList files = g.recentFileList(); + numRecentFiles = qMin(files.size(), g.history_size()); for ( i = 0; i < numRecentFiles; i++) { QString text = strippedName(files[i]); @@ -1916,7 +1906,7 @@ void MainWindow::updateRecentFileActions() void MainWindow::updateIconSizeActions() { - switch (glob.icon_size()) + switch (g.icon_size()) { case 0: smallIconAct->setChecked(true); break; case 1: normalIconAct->setChecked(true); break; @@ -1927,7 +1917,7 @@ void MainWindow::updateIconSizeActions() void MainWindow::updateLanguageActions() { - QString langId = glob.locale(); + QString langId = g.locale(); if (langId=="") sysLangAct->setChecked(true); @@ -1957,7 +1947,7 @@ void MainWindow::updateLanguageActions() void MainWindow::updateIconThemeActions() { - switch (glob.theme()) + switch (g.theme()) { case 0: classicThemeAct->setChecked(true); break; case 1: newThemeAct->setChecked(true); break; @@ -1971,13 +1961,13 @@ void MainWindow::updateProfilesActions() { for (int i=0; isetText(text); profileActs[i]->setData(i); profileActs[i]->setVisible(true); - if (i == glob.profileId()) + if (i == g.id()) profileActs[i]->setChecked(true); } else @@ -1989,14 +1979,14 @@ void MainWindow::updateProfilesActions() void MainWindow::createProfile() { int i; - for (i=0; i MaxRecentFiles) files.removeLast(); - glob.recentFileList( files ); + g.recentFileList( files ); } QString MdiChild::strippedName(const QString &fullFileName) @@ -506,8 +506,8 @@ QString MdiChild::strippedName(const QString &fullFileName) void MdiChild::writeEeprom() // write to Tx { - bool backupEnable=glob.backupEnable(); - QString backupPath=glob.backupPath(); + bool backupEnable=g.backupEnable(); + QString backupPath=g.backupPath(); if (!backupPath.isEmpty()) { if (!QDir(backupPath).exists()) { if (backupEnable) { @@ -518,7 +518,7 @@ void MdiChild::writeEeprom() // write to Tx } else { backupEnable=false; } - QString stickCal=glob.pro[glob.profileId()].StickPotCalib(); + QString stickCal=g.profile[g.id()].StickPotCalib(); burnConfigDialog bcd; QString tempDir = QDir::tempPath(); QString tempFile = tempDir + "/temp.bin"; @@ -681,7 +681,7 @@ void MdiChild::setEEpromAvail(int eavail) bool MdiChild::loadBackup() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastDir(),tr(EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.lastDir(),tr(EEPROM_FILES_FILTER)); if (fileName.isEmpty()) return false; QFile file(fileName); diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 441e11afb..c9ba53ba5 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -75,7 +75,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model, } } - QString path = glob.pro[glob.profileId()].sdPath(); + QString path = g.profile[g.id()].sdPath(); path.append("/SOUNDS/"); QString lang = generalSettings.ttsLanguage; if (lang.isEmpty()) @@ -225,7 +225,7 @@ void CustomFunctionsPanel::playMusic() QPushButton *playButton = qobject_cast(sender()); int index=playButton->objectName().mid(5,2).toInt(); QString function=playButton->objectName().left(4); - QString path = glob.pro[glob.profileId()].sdPath(); + QString path = g.profile[g.id()].sdPath(); QDir qd(path); QString track; if (qd.exists()) { diff --git a/companion/src/modeledit/modeledit.cpp b/companion/src/modeledit/modeledit.cpp index 6d43049b8..5e41fc217 100644 --- a/companion/src/modeledit/modeledit.cpp +++ b/companion/src/modeledit/modeledit.cpp @@ -22,7 +22,7 @@ ModelEdit::ModelEdit(RadioData & radioData, int modelId, bool openWizard, bool i generalSettings(radioData.generalSettings) { ui->setupUi(this); - restoreGeometry(glob.modelEditGeometry()); + restoreGeometry(g.modelEditGeometry()); ui->pushButton->setIcon(CompanionIcon("simulate.png")); addTab(new Setup(this, model), tr("Setup")); addTab(new HeliPanel(this, model), tr("Heli")); @@ -45,7 +45,7 @@ ModelEdit::~ModelEdit() void ModelEdit::closeEvent(QCloseEvent *event) { - glob.modelEditGeometry( saveGeometry() ); + g.modelEditGeometry( saveGeometry() ); } class VerticalScrollArea : public QScrollArea diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index e02383b06..7ce61eafd 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -348,7 +348,7 @@ Setup::Setup(QWidget *parent, ModelData & model): if (GetEepromInterface()->getCapability(ModelImage)) { QStringList items; items.append(""); - QString path = glob.pro[glob.profileId()].sdPath(); + QString path = g.profile[g.id()].sdPath(); path.append("/BMP/"); QDir qd(path); int vml = GetEepromInterface()->getCapability(VoicesMaxLength)+4; @@ -515,7 +515,7 @@ void Setup::on_image_currentIndexChanged(int index) { if (!lock) { strncpy(model.bitmap, ui->image->currentText().toAscii(), GetEepromInterface()->getCapability(VoicesMaxLength)); - QString path=glob.pro[glob.profileId()].sdPath(); + QString path=g.profile[g.id()].sdPath(); path.append("/BMP/"); QDir qd(path); if (qd.exists()) { diff --git a/companion/src/modeledit/telemetry.cpp b/companion/src/modeledit/telemetry.cpp index 9ac46bbc3..099ba56ab 100644 --- a/companion/src/modeledit/telemetry.cpp +++ b/companion/src/modeledit/telemetry.cpp @@ -457,7 +457,7 @@ TelemetryPanel::~TelemetryPanel() void TelemetryPanel::setup() { - QString firmware_id = glob.pro[glob.profileId()].firmware(); + QString firmware_id = g.profile[g.id()].firmware(); lock=true; diff --git a/companion/src/simulatordialog.cpp b/companion/src/simulatordialog.cpp index 7d70f3423..35bf3bb74 100644 --- a/companion/src/simulatordialog.cpp +++ b/companion/src/simulatordialog.cpp @@ -33,9 +33,8 @@ simulatorDialog::simulatorDialog(QWidget *parent) : beepVal = 0; beepShow = 0; - QSettings settings; - backLight = glob.backLight(); - bool simuSW=glob.simuSW(); + backLight = g.backLight(); + bool simuSW=g.simuSW(); switch (backLight) { case 1: ui->lcd->setBackgroundColor(166,247,159); @@ -76,23 +75,21 @@ simulatorDialog::simulatorDialog(QWidget *parent) : } #ifdef JOYSTICKS - bool js_enable=glob.js_support(); - int js_ctrl=glob.js_ctrl(); + bool js_enable=g.js_support(); + int js_ctrl=g.js_ctrl(); if (js_enable) { - settings.beginGroup("JsCalibration"); int count=0; for (int j=0; j<8;j++){ - int axe=settings.value(QString("stick%1_axe").arg(j),-1).toInt(); + int axe = g.joystick[j].stick_axe(); if (axe>=0 && axe<8) { jsmap[axe]=j; - jscal[axe][0]=settings.value(QString("stick%1_min").arg(j),-32767).toInt(); - jscal[axe][1]=settings.value(QString("stick%1_med").arg(j),0).toInt(); - jscal[axe][2]=settings.value(QString("stick%1_max").arg(j),0).toInt(); - jscal[axe][3]=settings.value(QString("stick%1_inv").arg(j),0).toInt(); + jscal[axe][0]=g.joystick[j].stick_min(); + jscal[axe][1]=g.joystick[j].stick_med(); + jscal[axe][2]=g.joystick[j].stick_max(); + jscal[axe][3]=g.joystick[j].stick_inv(); count++; } } - settings.endGroup(); if (count<3) { QMessageBox::critical(this, tr("Warning"), tr("Joystick enabled but not configured correctly")); } @@ -212,7 +209,7 @@ void simulatorDialog::setupTimer() void simulatorDialog::onButtonPressed(int value) { if (value==Qt::Key_Print) { - bool toclipboard=glob.snapshot_to_clipboard(); + bool toclipboard=g.snapshot_to_clipboard(); QString fileName =""; if (!toclipboard) { fileName = QString("screenshot-%1.png").arg(++screenshotIdx); @@ -493,6 +490,7 @@ void simulatorDialog::on_trimVRight_valueChanged(int value) simulator->setTrim(2, value); } + void simulatorDialog::setValues() { TxOutputs outputs; @@ -667,6 +665,7 @@ void simulatorDialog::on_holdRightX_clicked(bool checked) void simulatorDialog::on_holdRightY_clicked(bool checked) { nodeRight->setCenteringY(!checked); + } diff --git a/companion/src/splashlibrary.cpp b/companion/src/splashlibrary.cpp index 00a511402..3515e2da6 100644 --- a/companion/src/splashlibrary.cpp +++ b/companion/src/splashlibrary.cpp @@ -62,7 +62,7 @@ void splashLibrary::setupPage(int page) { void splashLibrary::getFileList() { imageList.clear(); - if (glob.embedded_splashes() == 0) { + if (g.embedded_splashes() == 0) { QDir myRes(":/images/library"); QStringList tmp = myRes.entryList(); for (int i = 0; i < tmp.size(); i++) { @@ -70,7 +70,7 @@ void splashLibrary::getFileList() { imageList.append(":/images/library/" + fileInfo.fileName()); } } - QString libraryPath = glob.libraryPath(); + QString libraryPath = g.libraryPath(); if (!libraryPath.isEmpty()) { if (QDir(libraryPath).exists()) { QStringList supportedImageFormats; diff --git a/companion/src/xsimulatordialog.cpp b/companion/src/xsimulatordialog.cpp index f1493c668..35059d71f 100644 --- a/companion/src/xsimulatordialog.cpp +++ b/companion/src/xsimulatordialog.cpp @@ -31,30 +31,27 @@ xsimulatorDialog::xsimulatorDialog(QWidget *parent) : ui->setupUi(this); ui->lcd->setFocus(); - QSettings settings; ui->lcd->setBackgroundColor(47, 123, 227); setupSticks(); resize(0, 0); // to force min height, min width this->setFixedSize(this->width(), this->height()); - bool simuSW=settings.value("simuSW",false).toBool(); + bool simuSW = g.simuSW(); #ifdef JOYSTICKS - bool js_enable=settings.value("js_support",false).toBool(); - int js_ctrl=settings.value("js_ctrl",-1).toInt(); - if (js_enable) { - settings.beginGroup("JsCalibration"); + int js_ctrl = g.js_ctrl(); + + if (g.js_support()) { int count=0; for (int j=0; j<8;j++){ - int axe=settings.value(QString("stick%1_axe").arg(j),-1).toInt(); + int axe=g.joystick[j].stick_axe(); if (axe>=0 && axe<8) { jsmap[axe]=j; - jscal[axe][0]=settings.value(QString("stick%1_min").arg(j),-32767).toInt(); - jscal[axe][1]=settings.value(QString("stick%1_med").arg(j),0).toInt(); - jscal[axe][2]=settings.value(QString("stick%1_max").arg(j),0).toInt(); - jscal[axe][3]=settings.value(QString("stick%1_inv").arg(j),0).toInt(); + jscal[axe][0]=g.joystick[j].stick_min(); + jscal[axe][1]=g.joystick[j].stick_med(); + jscal[axe][2]=g.joystick[j].stick_max(); + jscal[axe][3]=g.joystick[j].stick_inv(); count++; } } - settings.endGroup(); if (count<3) { QMessageBox::critical(this, tr("Warning"), tr("Joystick enabled but not configured correctly")); } @@ -180,7 +177,7 @@ void xsimulatorDialog::setupTimer() void xsimulatorDialog::onButtonPressed(int value) { if (value==Qt::Key_Print) { - bool toclipboard=glob.snapshot_to_clipboard(); + bool toclipboard=g.snapshot_to_clipboard(); QString fileName =""; if (!toclipboard) { fileName = QString("screenshot-%1.png").arg(++screenshotIdx); @@ -287,6 +284,7 @@ void xsimulatorDialog::loadParams(RadioData &radioData, const int model_idx) setupTimer(); } + void xsimulatorDialog::setTrims() { Trims trims; @@ -460,6 +458,7 @@ void xsimulatorDialog::setValues() ui->labelCSW_24->setStyleSheet(outputs.vsw[23] ? CSWITCH_ON : CSWITCH_OFF); ui->labelCSW_25->setStyleSheet(outputs.vsw[24] ? CSWITCH_ON : CSWITCH_OFF); ui->labelCSW_26->setStyleSheet(outputs.vsw[25] ? CSWITCH_ON : CSWITCH_OFF); + ui->labelCSW_27->setStyleSheet(outputs.vsw[26] ? CSWITCH_ON : CSWITCH_OFF); ui->labelCSW_28->setStyleSheet(outputs.vsw[27] ? CSWITCH_ON : CSWITCH_OFF); ui->labelCSW_29->setStyleSheet(outputs.vsw[28] ? CSWITCH_ON : CSWITCH_OFF);