From c23a096a7325afe40d70e0424ca88f07ccf75fc0 Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Mon, 17 Feb 2014 23:47:40 +0100 Subject: [PATCH] Almost all global settings wrapped in protective object to guarantee type safety and protect against tag spelling errors (I have found and corrected a lot of those!). Joystick settings and burner configuration is not yet within the global object. --- companion/src/appdata.h | 99 +-- companion/src/apppreferencesdialog.cpp | 86 +-- companion/src/burndialog.cpp | 49 +- companion/src/customizesplashdialog.cpp | 34 +- companion/src/eeprominterface.cpp | 9 +- companion/src/fwpreferencesdialog.cpp | 22 +- companion/src/helpers.cpp | 4 +- companion/src/lcdwidget.h | 6 +- companion/src/logsdialog.cpp | 12 +- companion/src/main.cpp | 14 +- companion/src/mainwindow.cpp | 65 +- companion/src/mainwindow.h | 1 - companion/src/mdichild.cpp | 44 +- companion/src/preferencesdialog.cpp | 827 ------------------------ companion/src/preferencesdialog.h | 65 -- companion/src/simulatordialog.cpp | 12 +- companion/src/splashlibrary.cpp | 7 +- companion/src/xsimulatordialog.cpp | 4 +- 18 files changed, 204 insertions(+), 1156 deletions(-) delete mode 100644 companion/src/preferencesdialog.cpp delete mode 100644 companion/src/preferencesdialog.h diff --git a/companion/src/appdata.h b/companion/src/appdata.h index 0a1d33589..044bc9b48 100644 --- a/companion/src/appdata.h +++ b/companion/src/appdata.h @@ -187,6 +187,7 @@ class Profile:DataObj QString _SplashFileName; bool _burnFirmware; bool _rename_firmware_files; + bool _patchImage; int _default_channel_order; int _default_mode; @@ -212,6 +213,7 @@ class Profile:DataObj QString SplashFileName() { return _SplashFileName; } bool burnFirmware() { return _burnFirmware; } bool rename_firmware_files() { return _rename_firmware_files; } + bool patchImage() { return _patchImage; } int default_channel_order() { return _default_channel_order; } int default_mode() { return _default_mode; } @@ -240,6 +242,7 @@ class Profile:DataObj void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" ,"Profiles", QString("profile%1").arg(index));} void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" ,"Profiles", QString("profile%1").arg(index));} void rename_firmware_files (const bool bl) { store(bl, _rename_firmware_files, "rename_firmware_files" ,"Profiles", QString("profile%1").arg(index));} + void patchImage (const bool bl) { store(bl, _patchImage, "patchImage" ,"Profiles", QString("profile%1").arg(index));} void default_channel_order (const int it) { store(it, _default_channel_order, "default_channel_order" ,"Profiles", QString("profile%1").arg(index));} void default_mode (const int it) { store(it, _default_mode, "default_mode" ,"Profiles", QString("profile%1").arg(index));} @@ -295,6 +298,7 @@ class Profile:DataObj getset( _SplashFileName, "SplashFileName" ,"" ,"Profiles", QString("profile%1").arg(index)); getset( _burnFirmware, "burnFirmware" ,false ,"Profiles", QString("profile%1").arg(index)); getset( _rename_firmware_files, "rename_firmware_files" ,false ,"Profiles", QString("profile%1").arg(index)); + getset( _patchImage, "patchImage" ,false ,"Profiles", QString("profile%1").arg(index)); getset( _default_channel_order, "default_channel_order" ,0 ,"Profiles", QString("profile%1").arg(index)); getset( _default_mode, "default_mode" ,1 ,"Profiles", QString("profile%1").arg(index)); @@ -322,6 +326,7 @@ class Profile:DataObj _SplashFileName = ""; _burnFirmware = false; _rename_firmware_files = false; + _patchImage = false; _default_channel_order = 0; _default_mode = 1; @@ -353,18 +358,16 @@ class AppData:DataObj { // All the global variables public: - Profile profile[MAX_PROFILES]; + Profile pro[MAX_PROFILES]; - private: + private: QStringList _recentFileList; QByteArray _mainWindowGeometry; QByteArray _mainWindowState; - QString _firmware; QString _locale; QString _cpu_id; - QString _Name; - QString _SplashFileName; + QString _lastFw; QString _modelEditGeometry; QString _backupPath; @@ -372,16 +375,15 @@ class AppData:DataObj QString _lastDir; QString _lastFlashDir; QString _lastImagesDir; + QString _lastLogDir; QString _libraryPath; - QString _sdPath; QString _snapshotpath; bool _backupEnable; bool _backupOnFlash; - bool _burnFirmware; bool _maximized; bool _js_support; - bool _rename_firmware_files; + bool _rev4asupport; bool _show_splash; bool _snapshot_to_clipboard; bool _startup_check_companion; @@ -390,8 +392,6 @@ class AppData:DataObj bool _wizardEnable; int _backLight; - int _default_channel_order; - int _default_mode; int _embedded_splashes; // Shouldn't this be bool ?? int _fwserver; int _generalEditTab; @@ -403,8 +403,6 @@ class AppData:DataObj int _theme; int _warningId; - // Storage functions - public: // All the get declarations @@ -412,11 +410,9 @@ public: QByteArray mainWindowGeometry(){ return _mainWindowGeometry; } QByteArray mainWindowState() { return _mainWindowState; } - QString firmware() { return _firmware; } QString locale() { return _locale; } QString cpu_id() { return _cpu_id; } - QString Name() { return _Name; } - QString SplashFileName() { return _SplashFileName; } + QString lastFw() { return _lastFw; } QString modelEditGeometry() { return _modelEditGeometry; } QString backupPath() { return _backupPath; } @@ -424,16 +420,15 @@ public: QString lastDir() { return _lastDir; } QString lastFlashDir() { return _lastFlashDir; } QString lastImagesDir() { return _lastImagesDir; } + QString lastLogDir() { return _lastLogDir; } QString libraryPath() { return _libraryPath; } - QString sdPath() { return _sdPath; } QString snapshotpath() { return _snapshotpath; } bool backupEnable() { return _backupEnable; } bool backupOnFlash() { return _backupOnFlash; } - bool burnFirmware() { return _burnFirmware; } bool js_support() { return _js_support; } + bool rev4asupport() { return _rev4asupport; } bool maximized() { return _maximized; } - bool rename_firmware_files() { return _rename_firmware_files; } bool show_splash() { return _show_splash; } bool snapshot_to_clipboard() { return _snapshot_to_clipboard; } bool startup_check_companion() { return _startup_check_companion;} @@ -442,8 +437,6 @@ public: bool wizardEnable() { return _wizardEnable; } int backLight() { return _backLight; } - int default_channel_order() { return _default_channel_order; } - int default_mode() { return _default_mode; } int embedded_splashes() { return _embedded_splashes; } int fwserver() { return _fwserver; } int generalEditTab() { return _generalEditTab; } @@ -455,16 +448,14 @@ public: int theme() { return _theme; } int warningId() { return _warningId; } - // All the set declarations +// All the set declarations void recentFileList (const QStringList l) { store(l, _recentFileList, "recentFileList" );} void mainWindowGeometry (const QByteArray a) { store(a, _mainWindowGeometry, "mainWindowGeometry");} void mainWindowState (const QByteArray a) { store(a, _mainWindowState, "mainWindowState" );} - void firmware (const QString str) { store(str, _firmware, "firmware" );} void locale (const QString str) { store(str, _locale, "locale" );} void cpu_id (const QString str) { store(str, _cpu_id, "cpu_id" );} - void Name (const QString str) { store(str, _Name, "Name" );} - void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" );} + void lastFw (const QString str) { store(str, _lastFw, "lastFw" );} void modelEditGeometry (const QString str) { store(str, _modelEditGeometry, "modelEditGeometry" );} void backupPath (const QString str) { store(str, _backupPath, "backupPath" );} @@ -472,16 +463,15 @@ public: void lastDir (const QString str) { store(str, _lastDir, "lastDir" );} void lastFlashDir (const QString str) { store(str, _lastFlashDir, "lastFlashDir" );} void lastImagesDir (const QString str) { store(str, _lastImagesDir, "lastImagesDir" );} + void lastLogDir (const QString str) { store(str, _lastLogDir, "lastLogDir" );} void libraryPath (const QString str) { store(str, _libraryPath, "libraryPath" );} - void sdPath (const QString str) { store(str, _sdPath, "sdPath" );} void snapshotpath (const QString str) { store(str, _snapshotpath, "snapshotpath" );} void backupEnable (const bool bl) { store(bl, _backupEnable, "backupEnable" );} void backupOnFlash (const bool bl) { store(bl, _backupOnFlash, "backupOnFlash" );} - void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" );} void maximized (const bool bl) { store(bl, _maximized, "maximized" );} void js_support (const bool bl) { store(bl, _js_support, "js_support" );} - void rename_firmware_files (const bool bl) { store(bl, _rename_firmware_files, "rename_firmware_files" );} + void rev4asupport (const bool bl) { store(bl, _rev4asupport, "rev4asupport" );} void show_splash (const bool bl) { store(bl, _show_splash, "show_splash" );} void snapshot_to_clipboard (const bool bl) { store(bl, _snapshot_to_clipboard, "snapshot_to_clipboard" );} void startup_check_companion (const bool bl) { store(bl, _startup_check_companion, "startup_check_companion" );} @@ -490,8 +480,6 @@ public: void wizardEnable (const bool bl) { store(bl, _wizardEnable, "wizardEnable" );} void backLight (const int it) { store(it, _backLight, "backLight" );} - void default_channel_order (const int it) { store(it, _default_channel_order, "default_channel_order" );} - void default_mode (const int it) { store(it, _default_mode, "default_mode" );} void embedded_splashes (const int it) { store(it, _embedded_splashes, "embedded_splashes" );} void fwserver (const int it) { store(it, _fwserver, "fwserver" );} void generalEditTab (const int it) { store(it, _generalEditTab, "generalEditTab" );} @@ -506,22 +494,48 @@ public: // Constructor AppData() { - // Start by hijacking all left over settings from companion9x, but only do it one time + //Initialize the profiles + for (int i=0; ichannelorderCB->currentIndex()); - glob.default_mode(ui->stickmodeCB->currentIndex()); - glob.rename_firmware_files(ui->renameFirmware->isChecked()); - glob.burnFirmware(ui->burnFirmware->isChecked()); glob.profileId(ui->profileIndexLE->text().toInt()); - glob.Name(ui->profileNameLE->text()); - glob.sdPath(ui->sdPath->text()); - glob.SplashFileName(ui->SplashFileName->text()); - glob.firmware(ui->firmwareLE->text()); + + glob.pro[glob.profileId()].default_channel_order(ui->channelorderCB->currentIndex()); + glob.pro[glob.profileId()].default_mode(ui->stickmodeCB->currentIndex()); + glob.pro[glob.profileId()].rename_firmware_files(ui->renameFirmware->isChecked()); + glob.pro[glob.profileId()].burnFirmware(ui->burnFirmware->isChecked()); + glob.pro[glob.profileId()].Name(ui->profileNameLE->text()); + glob.pro[glob.profileId()].sdPath(ui->sdPath->text()); + glob.pro[glob.profileId()].SplashFileName(ui->SplashFileName->text()); + glob.pro[glob.profileId()].firmware(ui->firmwareLE->text()); saveProfile(); } @@ -82,7 +84,7 @@ void appPreferencesDialog::on_snapshotPathButton_clicked() void appPreferencesDialog::initSettings() { ui->snapshotClipboardCKB->setChecked(glob.snapshot_to_clipboard()); - ui->burnFirmware->setChecked(glob.burnFirmware()); + ui->burnFirmware->setChecked(glob.pro[glob.profileId()].burnFirmware()); ui->snapshotPath->setText(glob.snapshotpath()); ui->snapshotPath->setReadOnly(true); if (ui->snapshotClipboardCKB->isChecked()) @@ -141,15 +143,15 @@ void appPreferencesDialog::initSettings() } #endif // Profile Tab Inits - ui->channelorderCB->setCurrentIndex(glob.default_channel_order()); - ui->stickmodeCB->setCurrentIndex(glob.default_mode()); - ui->renameFirmware->setChecked(glob.rename_firmware_files()); - ui->sdPath->setText(glob.sdPath()); + ui->channelorderCB->setCurrentIndex(glob.pro[glob.profileId()].default_channel_order()); + ui->stickmodeCB->setCurrentIndex(glob.pro[glob.profileId()].default_mode()); + ui->renameFirmware->setChecked(glob.pro[glob.profileId()].rename_firmware_files()); + ui->sdPath->setText(glob.pro[glob.profileId()].sdPath()); ui->profileIndexLE->setText(QString("%1").arg(glob.profileId())); - ui->profileNameLE->setText(glob.Name()); - ui->firmwareLE->setText(glob.firmware()); - ui->SplashFileName->setText(glob.SplashFileName()); - displayImage( glob.SplashFileName() ); + ui->profileNameLE->setText(glob.pro[glob.profileId()].Name()); + ui->firmwareLE->setText(glob.pro[glob.profileId()].firmware()); + ui->SplashFileName->setText(glob.pro[glob.profileId()].SplashFileName()); + displayImage( glob.pro[glob.profileId()].SplashFileName() ); } void appPreferencesDialog::on_libraryPathButton_clicked() @@ -230,7 +232,7 @@ void appPreferencesDialog::on_joystickcalButton_clicked() { void appPreferencesDialog::on_sdPathButton_clicked() { - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), glob.sdPath()); + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), glob.pro[glob.profileId()].sdPath()); if (!fileName.isEmpty()) { ui->sdPath->setText(fileName); } @@ -242,63 +244,41 @@ void appPreferencesDialog::saveProfile() if (ui->profileNameLE->text().isEmpty()) ui->profileNameLE->setText("----"); - glob.profile[glob.profileId()].Name( ui->profileNameLE->text() ); - glob.profile[glob.profileId()].default_channel_order( ui->channelorderCB->currentIndex()); - glob.profile[glob.profileId()].default_mode( ui->stickmodeCB->currentIndex()); - glob.profile[glob.profileId()].burnFirmware( ui->burnFirmware->isChecked()); - glob.profile[glob.profileId()].rename_firmware_files( ui->renameFirmware->isChecked()); - glob.profile[glob.profileId()].sdPath( ui->sdPath->text()); - glob.profile[glob.profileId()].SplashFileName( ui->SplashFileName->text()); - glob.profile[glob.profileId()].firmware( ui->firmwareLE->text()); -} - -void appPreferencesDialog::loadFromProfile() -{ - int i = glob.profileId(); - glob.Name( glob.profile[i].Name() ); - glob.default_channel_order( glob.profile[i].default_channel_order()); - glob.default_mode( glob.profile[i].default_mode()); - glob.burnFirmware( glob.profile[i].burnFirmware()); - glob.rename_firmware_files( glob.profile[i].rename_firmware_files()); - glob.sdPath( glob.profile[i].sdPath()); - glob.SplashFileName( glob.profile[i].SplashFileName()); - glob.firmware( glob.profile[i].firmware()); + glob.pro[glob.profileId()].Name( ui->profileNameLE->text() ); + glob.pro[glob.profileId()].default_channel_order( ui->channelorderCB->currentIndex()); + glob.pro[glob.profileId()].default_mode( ui->stickmodeCB->currentIndex()); + glob.pro[glob.profileId()].burnFirmware( ui->burnFirmware->isChecked()); + glob.pro[glob.profileId()].rename_firmware_files( ui->renameFirmware->isChecked()); + glob.pro[glob.profileId()].sdPath( ui->sdPath->text()); + glob.pro[glob.profileId()].SplashFileName( ui->SplashFileName->text()); + glob.pro[glob.profileId()].firmware( ui->firmwareLE->text()); } void appPreferencesDialog::on_removeProfileButton_clicked() { - QSettings settings; if ( glob.profileId() == 0 ) QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); else { - glob.profile[glob.profileId()].remove(); + glob.pro[glob.profileId()].remove(); glob.profileId( 0 ); - loadFromProfile(); initSettings(); } } bool appPreferencesDialog::displayImage( QString fileName ) { - // Start by filling the pixmap with white + // Start by clearing the pixmap ui->imageLabel->setPixmap(QPixmap()); QImage image(fileName); if (image.isNull()) return false; -// This code below just figures out if the width of the latest firmware is 128 or 212. It works , but... - QString filePath1 = glob.lastFlashDir() + "/" + glob.firmware() + ".bin"; - QString filePath2 = glob.lastFlashDir() + "/" + glob.firmware() + ".hex"; - QFile file(filePath1); - if (!file.exists()) - filePath1 = filePath2; + // Use the firmware name to determine splash width int width = SPLASH_WIDTH; - FlashInterface flash(filePath1); - if (flash.hasSplash()) - width = flash.getSplashWidth(); // Returns SPLASHX9D_HEIGHT if filePath1 does not exist! -// There must be a cleaner way of finding out the width of the firmware splash! + if (glob.pro[glob.profileId()].firmware().contains("taranis")) + width = SPLASHX9D_WIDTH; ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(width, SPLASH_HEIGHT))); if (width==SPLASHX9D_WIDTH) { diff --git a/companion/src/burndialog.cpp b/companion/src/burndialog.cpp index bfdf0bc76..05c0692d7 100644 --- a/companion/src/burndialog.cpp +++ b/companion/src/burndialog.cpp @@ -7,6 +7,7 @@ #include "splashlibrary.h" #include "flashinterface.h" #include "hexinterface.h" +#include "appdata.h" burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * backupEE, QString DocName): QDialog(parent), @@ -58,15 +59,7 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac else { setWindowTitle(tr("Write Models and Settings in %1 to TX").arg(DocName)); } - QSettings settings; - int profileid=settings.value("profileId", 1).toInt(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profileid); - settings.beginGroup(profile); - QString Name=settings.value("Name","").toString(); - settings.endGroup(); - settings.endGroup(); - ui->profile_label->setText(tr("Current profile")+QString(": ")+Name); + ui->profile_label->setText(tr("Current profile")+QString(": ")+glob.pro[glob.profileId()].Name()); } if (!hexfileName->isEmpty()) { ui->FWFileName->setText(*hexfileName); @@ -77,9 +70,8 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac burnraw=false; if (checkeEprom(*hexfileName)) { QSettings settings; - int profileid=settings.value("profileId", 1).toInt(); settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profileid); + QString profile=QString("profile%1").arg(glob.profileId()); settings.beginGroup(profile); QString Name=settings.value("Name","").toString(); QString calib=settings.value("StickPotCalib","").toString(); @@ -119,9 +111,8 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac hexfileName->clear(); } else if (Type==2) { - QSettings settings; QString FileName; - FileName = settings.value("lastFw").toString(); + FileName = glob.lastFw(); QFile file(FileName); if (file.exists()) { checkFw(FileName); @@ -138,7 +129,7 @@ burnDialog::~burnDialog() void burnDialog::on_FlashLoadButton_clicked() { QString fileName; - QSettings settings; + ui->ImageLoadButton->setDisabled(true); ui->libraryButton->setDisabled(true); ui->InvertColorButton->setDisabled(true); @@ -155,11 +146,11 @@ void burnDialog::on_FlashLoadButton_clicked() ui->EEbackupCB->hide(); QTimer::singleShot(0, this, SLOT(shrink())); if (hexType==2) { - fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER); + fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastFlashDir(), FLASH_FILES_FILTER); checkFw(fileName); } else { - QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), settings.value("lastDir").toString(), tr(EXTERNAL_EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), glob.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); if (checkeEprom(fileName)) { if (burnraw==false) { ui->BurnFlashButton->setEnabled(true); @@ -191,7 +182,6 @@ void burnDialog::checkFw(QString fileName) if (fileName.isEmpty()) { return; } - QSettings settings; if (!IS_TARANIS(GetEepromInterface()->getBoard())) { ui->EEbackupCB->show(); } @@ -216,8 +206,8 @@ void burnDialog::checkFw(QString fileName) ui->imageLabel->setFixedSize(flash.getSplashWidth(), flash.getSplashHeight()); ui->FwImage->show(); ui->FwImage->setPixmap(QPixmap::fromImage(flash.getSplash())); - QString ImageStr = settings.value("SplashImage", "").toString(); - bool PatchFwCB = settings.value("patchImage", false).toBool(); + QString ImageStr = glob.pro[glob.profileId()].SplashFileName(); + bool PatchFwCB = glob.pro[glob.profileId()].patchImage(); if (!ImageStr.isEmpty()) { QImage Image = qstring2image(ImageStr); ui->imageLabel->setPixmap(QPixmap::fromImage(Image.convertToFormat(flash.getSplashFormat()))); @@ -260,7 +250,7 @@ void burnDialog::checkFw(QString fileName) ui->BurnFlashButton->setEnabled(true); } QTimer::singleShot(0, this, SLOT(shrink())); - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); } bool burnDialog::checkeEprom(QString fileName) @@ -360,12 +350,11 @@ void burnDialog::on_ImageLoadButton_clicked() supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; } - QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); if (!fileName.isEmpty()) { - settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); QImage image(fileName); if (image.isNull()) { QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName)); @@ -442,11 +431,10 @@ void burnDialog::on_BurnFlashButton_clicked() if (hexType==2) { QString fileName=ui->FWFileName->text(); if (!fileName.isEmpty()) { - QSettings settings; - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); - settings.setValue("lastFw", fileName); + glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); + glob.lastFw( fileName ); if (ui->PatchFWCB->isChecked()) { - settings.setValue("patchImage", true); + glob.pro[glob.profileId()].patchImage( true ); QImage image = ui->imageLabel->pixmap()->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height()); if (!image.isNull()) { QString tempDir = QDir::tempPath(); @@ -469,7 +457,7 @@ void burnDialog::on_BurnFlashButton_clicked() QMessageBox::critical(this, tr("Warning"), tr("Custom image not found")); } } else { - settings.setValue("patchImage", false); + glob.pro[glob.profileId()].patchImage( false ); hexfileName->clear(); hexfileName->append(fileName); } @@ -480,7 +468,7 @@ void burnDialog::on_BurnFlashButton_clicked() } if (hexType==1) { QSettings settings; - int profileid=settings.value("profileId", 1).toInt(); + int profileid=glob.profileId(); settings.beginGroup("Profiles"); QString profile=QString("profile%1").arg(profileid); settings.beginGroup(profile); @@ -656,8 +644,7 @@ void burnDialog::on_PreferredImageCB_toggled(bool checked) { QString tmpFileName; if (checked) { - QSettings settings; - QString ImageStr = settings.value("SplashImage", "").toString(); + QString ImageStr = glob.pro[glob.profileId()].SplashFileName(); if (!ImageStr.isEmpty()) { QImage Image = qstring2image(ImageStr); if (ui->imageLabel->width()!=128) { diff --git a/companion/src/customizesplashdialog.cpp b/companion/src/customizesplashdialog.cpp index 420266b7a..bb86ec500 100644 --- a/companion/src/customizesplashdialog.cpp +++ b/companion/src/customizesplashdialog.cpp @@ -2,6 +2,7 @@ #include "ui_customizesplashdialog.h" #include +#include "appdata.h" #include "helpers.h" #include "burndialog.h" #include "splashlibrary.h" @@ -28,9 +29,10 @@ bool Side::displayImage( QString fileName, Source pictSource ) { QImage image; - if (fileName.isEmpty()) { + if (fileName.isEmpty()) return false; - } + + // Determine which picture format to use if (pictSource == FW ){ FlashInterface flash(fileName); if (!flash.hasSplash()) @@ -40,13 +42,16 @@ bool Side::displayImage( QString fileName, Source pictSource ) *format = (flash.getSplashWidth()==WIDTH_TARANIS ? LCDTARANIS : LCD9X); } else { - image.load(fileName); - if (pictSource== PICT) - *format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X; + image.load(fileName); + if (pictSource== PICT) + *format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X; + else if (pictSource == PROFILE) + *format = (glob.pro[glob.profileId()].firmware().contains("taranis")) ? LCDTARANIS : LCD9X; } if (image.isNull()) { return false; } + // Prepare and display image if (*format==LCDTARANIS) { image=image.convertToFormat(QImage::Format_RGB32); QRgb col; @@ -102,8 +107,6 @@ bool Side::refreshImage() bool Side::saveImage() { - QSettings settings; - if (*source == FW ) { FlashInterface flash(*saveToFileName); @@ -112,7 +115,7 @@ bool Side::saveImage() } QImage image = imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight()); if (flash.setSplash(image) && (flash.saveFlash(*saveToFileName) > 0)) { - settings.setValue("lastFlashDir", QFileInfo(*saveToFileName).dir().absolutePath()); + glob.lastFlashDir( QFileInfo(*saveToFileName).dir().absolutePath() ); } else { return false; @@ -121,7 +124,7 @@ bool Side::saveImage() else if (*source == PICT) { QImage image = imageLabel->pixmap()->toImage().scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8); if (image.save(*saveToFileName)) { - settings.setValue("lastImagesDir", QFileInfo(*saveToFileName).dir().absolutePath()); + glob.lastImagesDir( QFileInfo(*saveToFileName).dir().absolutePath() ); } else { return false; @@ -178,13 +181,12 @@ void customizeSplashDialog::on_leftLoadFwButton_clicked() {loadFirmware(left);} void customizeSplashDialog::on_rightLoadFwButton_clicked() {loadFirmware(right);} void customizeSplashDialog::loadFirmware(Side side) { - QSettings settings; - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastFlashDir(), FLASH_FILES_FILTER); if (!fileName.isEmpty()) { if (!side.displayImage( fileName, FW )) QMessageBox::critical(this, tr("Error"), tr("Cannot load embedded FW image from %1.").arg(fileName)); else - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastFlashDir( QFileInfo(fileName).dir().absolutePath() ); } } @@ -196,15 +198,14 @@ void customizeSplashDialog::loadPicture(Side side) for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) { supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; } - QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats)); + tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats)); if (!fileName.isEmpty()) { if (!side.displayImage( fileName, PICT )) QMessageBox::critical(this, tr("Error"), tr("Cannot load the image file %1.").arg(fileName)); else - settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastImagesDir( QFileInfo(fileName).dir().absolutePath() ); } } @@ -212,8 +213,7 @@ void customizeSplashDialog::on_leftLoadProfileButton_clicked() {loadProfile(left void customizeSplashDialog::on_rightLoadProfileButton_clicked() {loadProfile(right);} void customizeSplashDialog::loadProfile(Side side) { - QSettings settings; - QString fileName=settings.value("SplashFileName","").toString(); + QString fileName=glob.pro[glob.profileId()].SplashFileName(); if (!fileName.isEmpty()) { if (!side.displayImage( fileName, PROFILE )) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index bb2861cf8..63dfc096c 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -7,6 +7,7 @@ #include "firmwares/opentx/opentxinterface.h" #include "firmwares/ersky9x/ersky9xinterface.h" #include "qsettings.h" +#include "appdata.h" #include "helpers.h" QString EEPROMWarnings; @@ -734,8 +735,8 @@ GeneralSettings::GeneralSettings() QSettings settings; templateSetup = settings.value("default_channel_order", 0).toInt(); stickMode = settings.value("default_mode", 1).toInt(); - int profile_id = settings.value("profileId", 0).toInt(); - if (profile_id>0) { + int profile_id = glob.profileId(); + if (profile_id>-1) { settings.beginGroup("Profiles"); QString profile=QString("profile%1").arg(profile_id); settings.beginGroup(profile); @@ -990,14 +991,12 @@ ModelData ModelData::removeGlobalVars() QList eepromInterfaces; void RegisterEepromInterfaces() { - QSettings settings; - int rev4a = settings.value("rev4asupport",0).toInt(); eepromInterfaces.push_back(new Open9xInterface(BOARD_STOCK)); eepromInterfaces.push_back(new Open9xInterface(BOARD_M128)); eepromInterfaces.push_back(new Open9xInterface(BOARD_GRUVIN9X)); eepromInterfaces.push_back(new Open9xInterface(BOARD_SKY9X)); eepromInterfaces.push_back(new Open9xInterface(BOARD_TARANIS)); - if (rev4a) + if (glob.rev4asupport()) eepromInterfaces.push_back(new Open9xInterface(BOARD_TARANIS_REV4a)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_STOCK)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_GRUVIN9X)); diff --git a/companion/src/fwpreferencesdialog.cpp b/companion/src/fwpreferencesdialog.cpp index 735e18acc..0113ee3cd 100644 --- a/companion/src/fwpreferencesdialog.cpp +++ b/companion/src/fwpreferencesdialog.cpp @@ -3,6 +3,7 @@ #include "mainwindow.h" #include "eeprominterface.h" #include "helpers.h" +#include "appdata.h" #include #include @@ -213,11 +214,9 @@ void fwPreferencesDialog::firmwareChanged() void fwPreferencesDialog::writeValues() { - QSettings settings; - - settings.setValue("cpu_id", ui->CPU_ID_LE->text()); + glob.cpu_id( ui->CPU_ID_LE->text() ); current_firmware_variant = getFirmwareVariant(); - settings.setValue("firmware", current_firmware_variant.id); + glob.pro[glob.profileId()].firmware( current_firmware_variant.id ); } void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware) @@ -275,9 +274,7 @@ void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware) void fwPreferencesDialog::initSettings() { - QSettings settings; - - ui->CPU_ID_LE->setText(settings.value("cpu_id", "").toString()); + ui->CPU_ID_LE->setText(glob.cpu_id()); FirmwareInfo * current_firmware = GetCurrentFirmware(); foreach(FirmwareInfo * firmware, firmwares) { @@ -293,12 +290,10 @@ void fwPreferencesDialog::initSettings() void fwPreferencesDialog::on_checkFWUpdates_clicked() { - QSettings settings; - FirmwareVariant variant = getFirmwareVariant(); - if (settings.value("burnFirmware", true).toBool()) { + if (glob.pro[glob.profileId()].burnFirmware()) { current_firmware_variant = variant; - settings.setValue("firmware", variant.id); + glob.pro[glob.profileId()].firmware( variant.id ); } MainWindow * mw = (MainWindow *)this->parent(); mw->checkForUpdates(true, variant.id); @@ -307,14 +302,13 @@ void fwPreferencesDialog::on_checkFWUpdates_clicked() void fwPreferencesDialog::on_fw_dnld_clicked() { - QSettings settings; MainWindow * mw = (MainWindow *)this->parent(); FirmwareVariant variant = getFirmwareVariant(); writeValues(); if (!variant.firmware->getUrl(variant.id).isNull()) { - if (settings.value("burnFirmware", true).toBool()) { + if (glob.pro[glob.profileId()].burnFirmware()) { current_firmware_variant = getFirmwareVariant(); - settings.setValue("firmware", current_firmware_variant.id); + glob.pro[glob.profileId()].firmware( current_firmware_variant.id ); } mw->downloadLatestFW(current_firmware_variant.firmware, current_firmware_variant.id); } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 9a9f2caf4..5a74c4afc 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -1,4 +1,5 @@ #include +#include "appdata.h" #include "helpers.h" QString getPhaseName(int val, char * phasename) @@ -913,8 +914,7 @@ QString getCenterBeep(ModelData * g_model) QString getTheme() { - QSettings settings; - int theme_set = settings.value("theme", 1).toInt(); + int theme_set = glob.theme(); QString Theme; switch(theme_set) { case 0: diff --git a/companion/src/lcdwidget.h b/companion/src/lcdwidget.h index 9f01a0b17..7433b640d 100644 --- a/companion/src/lcdwidget.h +++ b/companion/src/lcdwidget.h @@ -18,6 +18,7 @@ #define lcd_widget_h #include +#include "appdata.h" class lcdWidget : public QWidget { public: @@ -58,11 +59,10 @@ class lcdWidget : public QWidget { QPixmap buffer(2*lcdWidth, 2*lcdHeight); QPainter p(&buffer); doPaint(p); - QSettings settings; - bool toclipboard=settings.value("snapshot_to_clipboard", false).toBool(); + bool toclipboard=glob.snapshot_to_clipboard(); QApplication::clipboard()->setPixmap( buffer ); if (!toclipboard) { - QString Path=settings.value("snapshotPath", "").toString(); + QString Path=glob.snapshotpath(); if (Path.isEmpty() || !QDir(Path).exists()) { Path="."; } diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index 0c9702239..874ed21d3 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -1,4 +1,5 @@ #include "logsdialog.h" +#include "appdata.h" #include "ui_logsdialog.h" #include "qcustomplot.h" #if defined WIN32 || !defined __GNUC__ @@ -38,8 +39,7 @@ logsDialog::logsDialog(QWidget *parent) : ui->customPlot->legend->setSelectedFont(legendFont); ui->customPlot->legend->setSelectable(QCPLegend::spItems); // legend box shall not be selectable, only legend items ui->customPlot->legend->setVisible(false); - QSettings settings; - QString Path=settings.value("gePath", "").toString(); + QString Path=glob.gePath(); if (Path.isEmpty() || !QFile(Path).exists()) { ui->mapsButton->hide(); } @@ -202,8 +202,7 @@ void logsDialog::on_mapsButton_clicked() { ,F_F,F_F,F_F,F_F,I_F,I_F,I_F,I_F\ ,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F}; - QSettings settings; - QString gePath=settings.value("gePath", "").toString(); + QString gePath=glob.gePath(); if (gePath.isEmpty() || !QFile(gePath).exists()) { ui->FieldsTW->setDisabled(false); ui->logTable->setDisabled(false); @@ -585,10 +584,9 @@ void logsDialog::moveLegend() void logsDialog::on_fileOpen_BT_clicked() { - QSettings settings; - QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), settings.value("lastLogDir").toString()); + QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), glob.lastLogDir()); if (!fileName.isEmpty()) { - settings.setValue("lastLogDir", fileName); + glob.lastLogDir( fileName ); ui->FileName_LE->setText(fileName); if (cvsFileParse()) { ui->FieldsTW->clear(); diff --git a/companion/src/main.cpp b/companion/src/main.cpp index 93bd89123..960d06b7a 100644 --- a/companion/src/main.cpp +++ b/companion/src/main.cpp @@ -45,12 +45,12 @@ #include #include #include -#include #include #include #include #include "mainwindow.h" #include "eeprominterface.h" +#include "appdata.h" #if defined WIN32 || !defined __GNUC__ #include @@ -98,19 +98,15 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - if (glob.firmware().isEmpty()) - glob.firmware(default_firmware_variant.id); - QString tmp_id = glob.firmware(); - tmp_id.replace("open9x", "opentx"); - tmp_id.replace("x9da", "taranis"); - glob.firmware(tmp_id); + if (glob.pro[glob.profileId()].firmware().isEmpty()) + glob.pro[glob.profileId()].firmware(default_firmware_variant.id); - QPixmap pixmap = QPixmap(glob.firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); + QPixmap pixmap = QPixmap(glob.pro[glob.profileId()].firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); QSplashScreen *splash = new QSplashScreen(pixmap); RegisterFirmwares(); - current_firmware_variant = GetFirmwareVariant(glob.firmware()); + current_firmware_variant = GetFirmwareVariant(glob.pro[glob.profileId()].firmware()); MainWindow *mainWin = new MainWindow(); if (glob.show_splash()) { diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 8918796be..8625537e6 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -49,7 +49,6 @@ #include "avroutputdialog.h" #include "comparedialog.h" #include "logsdialog.h" -#include "preferencesdialog.h" #include "apppreferencesdialog.h" #include "fwpreferencesdialog.h" #include "flashinterface.h" @@ -63,6 +62,7 @@ #include "hexinterface.h" #include "warnings.h" #include "helpers.h" +#include "appdata.h" #include "firmwares/opentx/opentxinterface.h" // TODO get rid of this include #define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2" @@ -408,7 +408,7 @@ void MainWindow::reply1Accepted() int pos=rev.lastIndexOf("-r"); if (pos>0) { currentFWrev=rev.mid(pos+2).toInt(); - if (settings.value("rename_firmware_files", false).toBool() && needRename) { + if (glob.pro[glob.profileId()].rename_firmware_files() && needRename) { QFileInfo fi(downloadedFWFilename); QString path=fi.path()+QDir::separator (); path.append(fi.completeBaseName()); @@ -421,7 +421,7 @@ void MainWindow::reply1Accepted() downloadedFWFilename=path; } settings.setValue(downloadedFW, currentFWrev); - if (settings.value("burnFirmware", true).toBool()) { + if (glob.pro[glob.profileId()].burnFirmware()) { int ret = QMessageBox::question(this, "Companion", tr("Do you want to write the firmware to the transmitter now ?"), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes) { writeFlash(downloadedFWFilename); @@ -558,7 +558,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply) QString url = GetFirmware(fwToUpdate)->getUrl(fwToUpdate); QString ext = url.mid(url.lastIndexOf(".")); needRename=false; - bool addversion=glob.rename_firmware_files(); + bool addversion=glob.pro[glob.profileId()].rename_firmware_files(); QString fileName; if (addversion) { fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + newrev + ext); @@ -711,24 +711,8 @@ void MainWindow::loadProfile() //TODO Load all variables - Also HW! int profnum=action->data().toInt(); glob.profileId( profnum ); - // Upgrade old firmware names - QString firmware = glob.profile[profnum].firmware(); - firmware.replace("open9x","opentx"); - firmware.replace("x9da","taranis"); - glob.profile[profnum].firmware(firmware); - - // Copy profile data from profile to main variables - glob.Name( glob.profile[profnum].Name() ); - glob.default_channel_order( glob.profile[profnum].default_channel_order() ); - glob.default_mode( glob.profile[profnum].default_mode() ); - glob.burnFirmware( glob.profile[profnum].burnFirmware() ); - glob.rename_firmware_files( glob.profile[profnum].rename_firmware_files() ); - glob.sdPath( glob.profile[profnum].sdPath() ); - glob.SplashFileName( glob.profile[profnum].SplashFileName() ); - glob.firmware( glob.profile[profnum].firmware() ); - - // TODO Get rid of this global variable - glob.firmware is the real source - current_firmware_variant = GetFirmwareVariant(glob.firmware()); + // TODO Get rid of this global variable - The profile.firmware is the real source + current_firmware_variant = GetFirmwareVariant(glob.pro[glob.profileId()].firmware()); foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { MdiChild *mdiChild = qobject_cast(window->widget()); @@ -1543,7 +1527,7 @@ void MainWindow::updateMenus() updateIconSizeActions(); updateIconThemeActions(); - setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( glob.Name() )); + setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( glob.pro[glob.profileId()].Name() )); } MdiChild *MainWindow::createMdiChild() @@ -1909,20 +1893,25 @@ void MainWindow::setActiveSubWindow(QWidget *window) void MainWindow::updateRecentFileActions() { - int i,j, numRecentFiles; - QSettings settings; - QStringList files = settings.value("recentFileList").toStringList(); + int i, numRecentFiles; + // Hide all document slots + for ( i=0 ; i < glob.history_size(); i++) + recentFileActs[i]->setVisible(false); + + // Fill slots with content and unhide them + QStringList files = glob.recentFileList(); numRecentFiles = qMin(files.size(), glob.history_size()); - for ( i = 0; i < numRecentFiles; ++i) { - QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i])); - recentFileActs[i]->setText(text); - recentFileActs[i]->setData(files[i]); - recentFileActs[i]->setVisible(true); + for ( i = 0; i < numRecentFiles; i++) { + QString text = strippedName(files[i]); + if (!text.trimmed().isEmpty()) + { + recentFileActs[i]->setText(text); + recentFileActs[i]->setData(files[i]); + recentFileActs[i]->setVisible(true); + } } - for ( j = numRecentFiles; j < glob.history_size(); ++j) - recentFileActs[j]->setVisible(false); } void MainWindow::updateIconSizeActions() @@ -1982,9 +1971,9 @@ void MainWindow::updateProfilesActions() { for (int i=0; isetText(text); profileActs[i]->setData(i); profileActs[i]->setVisible(true); @@ -2000,14 +1989,14 @@ void MainWindow::updateProfilesActions() void MainWindow::createProfile() { int i; - for (i=0; i #include #include -#include "appdata.h" #include "downloaddialog.h" #include "eeprominterface.h" diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 97d737d09..c82e685fb 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -53,6 +53,7 @@ #include "printdialog.h" #include "burndialog.h" #include "helpers.h" +#include "appdata.h" #include #if defined WIN32 || !defined __GNUC__ @@ -179,8 +180,7 @@ void MdiChild::OpenEditWindow(bool wizard=false) } if (isNew && !wizard) { int ret; - QSettings settings; - bool wizardEnable=settings.value("wizardEnable", true).toBool(); + bool wizardEnable=glob.wizardEnable(); if (wizardEnable) { ret = QMessageBox::question(this, tr("Companion"), tr("Do you want to use model wizard? "), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes) { @@ -189,7 +189,7 @@ void MdiChild::OpenEditWindow(bool wizard=false) qSleep(500); ret = QMessageBox::question(this, tr("Companion"), tr("Ask this question again ? "), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::No) { - settings.setValue("wizardEnable", false); + glob.wizardEnable( false ); } } } @@ -346,34 +346,33 @@ bool MdiChild::save() bool MdiChild::saveAs(bool isNew) { - QSettings settings; QString fileName; if (GetEepromInterface()->getBoard() == BOARD_SKY9X) { curFile.replace(".eepe", ".bin"); QFileInfo fi(curFile); #ifdef __APPLE__ - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName()); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName()); #else - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName(), tr(BIN_FILES_FILTER)); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName(), tr(BIN_FILES_FILTER)); #endif } else { QFileInfo fi(curFile); #ifdef __APPLE__ - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName()); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName()); #else - fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER)); + fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastDir() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER)); #endif } if (fileName.isEmpty()) return false; if (fileName.contains("rev4a")) { - settings.setValue("rev4asupport", 1); + glob.rev4asupport( true ); } if (fileName.contains("norev4a")) { - settings.setValue("rev4asupport", 0); + glob.rev4asupport( false ); } - settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); + glob.lastDir( QFileInfo(fileName).dir().absolutePath() ); if (isNew) return saveFile(fileName); else @@ -490,15 +489,14 @@ void MdiChild::setCurrentFile(const QString &fileName) fileChanged = false; setWindowModified(false); updateTitle(); - QSettings settings; - int MaxRecentFiles =settings.value("history_size",10).toInt(); - QStringList files = settings.value("recentFileList").toStringList(); + int MaxRecentFiles = glob.history_size(); + QStringList files = glob.recentFileList(); files.removeAll(fileName); files.prepend(fileName); while (files.size() > MaxRecentFiles) files.removeLast(); - settings.setValue("recentFileList", files); + glob.recentFileList( files ); } QString MdiChild::strippedName(const QString &fullFileName) @@ -508,9 +506,8 @@ QString MdiChild::strippedName(const QString &fullFileName) void MdiChild::writeEeprom() // write to Tx { - QSettings settings; - bool backupEnable=settings.value("backupEnable", true).toBool(); - QString backupPath=settings.value("backupPath", "").toString(); + bool backupEnable=glob.backupEnable(); + QString backupPath=glob.backupPath(); if (!backupPath.isEmpty()) { if (!QDir(backupPath).exists()) { if (backupEnable) { @@ -521,13 +518,7 @@ void MdiChild::writeEeprom() // write to Tx } else { backupEnable=false; } - int profileid=settings.value("profileId", 1).toInt(); - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(profileid); - settings.beginGroup(profile); - QString stickCal=settings.value("StickPotCalib","").toString(); - settings.endGroup(); - settings.endGroup(); + QString stickCal=glob.pro[glob.profileId()].StickPotCalib(); burnConfigDialog bcd; QString tempDir = QDir::tempPath(); QString tempFile = tempDir + "/temp.bin"; @@ -690,8 +681,7 @@ void MdiChild::setEEpromAvail(int eavail) bool MdiChild::loadBackup() { - QSettings settings; - QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastDir").toString(),tr(EEPROM_FILES_FILTER)); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastDir(),tr(EEPROM_FILES_FILTER)); if (fileName.isEmpty()) return false; QFile file(fileName); diff --git a/companion/src/preferencesdialog.cpp b/companion/src/preferencesdialog.cpp deleted file mode 100644 index 7b4ce1707..000000000 --- a/companion/src/preferencesdialog.cpp +++ /dev/null @@ -1,827 +0,0 @@ -#include "preferencesdialog.h" -#include "ui_preferencesdialog.h" -#include "mainwindow.h" -#include "eeprominterface.h" -#include "splashlibrary.h" -#include "helpers.h" -#ifdef JOYSTICKS -#include "joystick.h" -#include "joystickdialog.h" -#endif -#include -#include - -preferencesDialog::preferencesDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::preferencesDialog), - updateLock(false) -{ - ui->setupUi(this); - setWindowIcon(CompanionIcon("preferences.png")); - ui->splashLibraryButton->setIcon(CompanionIcon("library.png")); - ui->clearImageButton->setIcon(CompanionIcon("clear.png")); - - QCheckBox * OptionCheckBox[]= { - ui->optionCheckBox_1, ui->optionCheckBox_2, ui->optionCheckBox_3, ui->optionCheckBox_4, ui->optionCheckBox_5, ui->optionCheckBox_6, ui->optionCheckBox_7, - ui->optionCheckBox_8, ui->optionCheckBox_9, ui->optionCheckBox_10, ui->optionCheckBox_11, ui->optionCheckBox_12, ui->optionCheckBox_13, ui->optionCheckBox_14, - ui->optionCheckBox_15,ui->optionCheckBox_16, ui->optionCheckBox_17, ui->optionCheckBox_18, ui->optionCheckBox_19, ui->optionCheckBox_20, ui->optionCheckBox_21, - ui->optionCheckBox_22, ui->optionCheckBox_23, ui->optionCheckBox_24, ui->optionCheckBox_25, ui->optionCheckBox_26, ui->optionCheckBox_27, ui->optionCheckBox_28, - ui->optionCheckBox_29, ui->optionCheckBox_30, ui->optionCheckBox_31, ui->optionCheckBox_32, ui->optionCheckBox_33, ui->optionCheckBox_34, ui->optionCheckBox_35, - ui->optionCheckBox_36, ui->optionCheckBox_37, ui->optionCheckBox_38, ui->optionCheckBox_39, ui->optionCheckBox_40, ui->optionCheckBox_41, ui->optionCheckBox_42, - NULL }; - - voice=NULL; - - connect(ui->langCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged())); - connect(ui->voiceCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged())); - - for (int i=0; OptionCheckBox[i]; i++) { - optionsCheckBoxes.push_back(OptionCheckBox[i]); - connect(OptionCheckBox[i], SIGNAL(toggled(bool)), this, SLOT(firmwareOptionChanged(bool))); - } - - initSettings(); - connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged())); - connect(this, SIGNAL(accepted()), this, SLOT(writeValues())); -#ifndef JOYSTICKS - ui->joystickCB->hide(); - ui->joystickCB->setDisabled(true); - ui->joystickcalButton->hide(); - ui->joystickChkB->hide(); - ui->label_11->hide(); -#endif - resize(0,0); -} - - -preferencesDialog::~preferencesDialog() -{ - delete ui; -} - -void preferencesDialog::baseFirmwareChanged() -{ - QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - voice=NULL; - foreach(FirmwareInfo * firmware, firmwares) { - if (firmware->id == selected_firmware) { - if (firmware->voice) { - ui->voiceLabel->show(); - ui->voiceCombo->show(); - ui->voice_dnld->show(); - ui->sdPathButton->show(); - ui->sdPath->show(); - ui->sdPathLabel->show(); - ui->voiceLabel->setEnabled(true); - ui->voiceCombo->setEnabled(true); - ui->voice_dnld->setEnabled(true); - ui->sdPathButton->setEnabled(true); - ui->sdPath->setEnabled(true); - ui->ge_label->show(); - ui->ge_lineedit->show(); - ui->ge_pathButton->show(); - } else { - ui->voiceLabel->hide(); - ui->voiceCombo->hide(); - ui->voice_dnld->hide(); - ui->sdPathButton->hide(); - ui->sdPath->hide(); - ui->sdPathLabel->hide(); - ui->ge_label->hide(); - ui->ge_lineedit->hide(); - ui->ge_pathButton->hide(); - } - populateFirmwareOptions(firmware); - int width=firmware->eepromInterface->getCapability(LCDWidth); - ui->imageLabel->setFixedWidth(width); - break; - } - } - firmwareChanged(); -} - -FirmwareVariant preferencesDialog::getFirmwareVariant() -{ - QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - bool voice=false; - foreach(FirmwareInfo * firmware, firmwares) { - if (firmware->id == selected_firmware) { - QString id = firmware->id; - foreach(QCheckBox *cb, optionsCheckBoxes) { - if (cb->isChecked()) { - if (cb->text()=="voice" && cb->isChecked()) - voice=true; - id += QString("-") + cb->text(); - } - } - if (! firmware->eepromInterface->getCapability(MultiLangVoice)) { - if (ui->voiceCombo->count() && (voice || firmware->voice)) - id += QString("-tts") + ui->voiceCombo->currentText(); - } - if (ui->langCombo->count()) - id += QString("-") + ui->langCombo->currentText(); - - return GetFirmwareVariant(id); - } - } - - // Should never occur... - return default_firmware_variant; -} - -void preferencesDialog::firmwareLangChanged() -{ - firmwareChanged(); -} - -void preferencesDialog::firmwareOptionChanged(bool state) -{ - QCheckBox *cb = qobject_cast(sender()); - FirmwareInfo * firmware=NULL; - if (cb && state) { - QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - foreach(firmware, firmwares) { - if (firmware->id == selected_firmware) { - foreach(QList