From eedc5ea68f13d103c55a4c967d8e47a843354009 Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Tue, 11 Feb 2014 08:37:07 +0100 Subject: [PATCH] Profiles can now be added and removed in a proper way. --- companion/src/CMakeLists.txt | 3 - companion/src/apppreferencesdialog.cpp | 86 ++-- companion/src/apppreferencesdialog.h | 3 +- companion/src/apppreferencesdialog.ui | 686 ++++++++++++------------- companion/src/eeprominterface.cpp | 2 +- companion/src/fwpreferencesdialog.cpp | 3 - companion/src/mainwindow.cpp | 136 ++--- companion/src/mainwindow.h | 5 +- 8 files changed, 428 insertions(+), 496 deletions(-) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 3a8dd26b7..20c86879c 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -155,7 +155,6 @@ SET( companion_SRCS modelslist.cpp mountlist.cpp avroutputdialog.cpp - preferencesdialog.cpp apppreferencesdialog.cpp fwpreferencesdialog.cpp burnconfigdialog.cpp @@ -178,7 +177,6 @@ SET( companion_SRCS SET( companion_MOC_HDRS avroutputdialog.h - preferencesdialog.h apppreferencesdialog.h fwpreferencesdialog.h burnconfigdialog.h @@ -214,7 +212,6 @@ SET( companion_UIS comparedialog.ui fusesdialog.ui logsdialog.ui - preferencesdialog.ui apppreferencesdialog.ui fwpreferencesdialog.ui simulatordialog.ui diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index cba2bda1e..ebbb5bb55 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -60,16 +60,13 @@ void appPreferencesDialog::writeValues() settings.setValue("default_mode", ui->stickmodeCB->currentIndex()); settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked()); settings.setValue("burnFirmware", ui->burnFirmware->isChecked()); - settings.setValue("profileId", ui->ProfSlot_SB->value()); + settings.setValue("profileId", ui->profileIndexLE->text()); settings.setValue("sdPath", ui->sdPath->text()); settings.setValue("SplashFileName", ui->SplashFileName->text()); if (!ui->SplashFileName->text().isEmpty()) settings.setValue("SplashImage", ""); saveProfile(); - - MainWindow * mw = (MainWindow *)this->parent(); - mw->unloadProfile(); } void appPreferencesDialog::on_snapshotPathButton_clicked() @@ -163,8 +160,8 @@ void appPreferencesDialog::initSettings() if (QDir(Path).exists()) { ui->sdPath->setText(Path); } - ui->ProfSlot_SB->setValue(settings.value("profileId", 1).toInt()); - on_ProfSlot_SB_valueChanged(); + ui->profileIndexLE->setText(settings.value("profileId", "").toString()); + QString fileName=settings.value("SplashFileName","").toString(); if (!fileName.isEmpty()) { QFile file(fileName); @@ -264,40 +261,11 @@ void appPreferencesDialog::on_sdPathButton_clicked() } } -void appPreferencesDialog::on_ProfSlot_SB_valueChanged() -{ - QSettings settings; - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(ui->ProfSlot_SB->value()); - settings.beginGroup(profile); - QString name=settings.value("Name","").toString(); - ui->ProfName_LE->setText(name); -/* if (!(name.isEmpty())) { - QString firmwarename=settings.value("firmware", default_firmware_id).toString(); - FirmwareInfo * fw = getFirmware(firmwarename); - int i=0; - foreach(FirmwareInfo * firmware, firmwares) { - if (fw == firmware) { - qDebug() << fw->id; - qDebug() << firmware->id; - qDebug() << i; - ui->downloadVerCB->setCurrentIndex(i); - break; - } - i++; - } - baseFirmwareChanged(); - populateFirmwareOptions(fw); - }*/ - settings.endGroup(); - settings.endGroup(); -} - - void appPreferencesDialog::saveProfile() { QSettings settings; - QString profile=QString("profile%1").arg(ui->ProfSlot_SB->value()); + + QString profile=QString("profile") + settings.value("profileId").toString(); QString name=ui->ProfName_LE->text(); if (name.isEmpty()) { name = profile; @@ -316,11 +284,51 @@ void appPreferencesDialog::saveProfile() settings.endGroup(); } +void appPreferencesDialog::loadProfileString(QString profile, QString label) +{ + QSettings settings; + QString value; + + settings.beginGroup("Profiles"); + settings.beginGroup(profile); + value = settings.value(label).toString(); + settings.endGroup(); + settings.endGroup(); + + settings.setValue( label, value ); +} + +void appPreferencesDialog::loadProfile() +{ + QSettings settings; + QString profile=QString("profile") + settings.value("profileId").toString(); + + loadProfileString( profile, "Name" ); + loadProfileString( profile, "default_channel_order" ); + loadProfileString( profile, "default_mode" ); + loadProfileString( profile, "burnFirmware" ); + loadProfileString( profile, "rename_firmware_files" ); + loadProfileString( profile, "sdPath" ); + loadProfileString( profile, "SplashFileName" ); +} + void appPreferencesDialog::on_removeProfileButton_clicked() { QSettings settings; - QString profile=QString("profile%1").arg(ui->ProfSlot_SB->value()); - settings.remove(profile); + QString profileId = settings.value("profileId").toString(); + if ( profileId == "1" ) + QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); + else + { + QString profile=QString("profile") + profileId; + settings.beginGroup("Profiles"); + settings.remove(profile); + settings.endGroup(); + settings.setValue("profileId", "1"); + + loadProfile(); + initSettings(); + } } bool appPreferencesDialog::displayImage( QString fileName ) diff --git a/companion/src/apppreferencesdialog.h b/companion/src/apppreferencesdialog.h index 5934d79d2..b6f6c3896 100644 --- a/companion/src/apppreferencesdialog.h +++ b/companion/src/apppreferencesdialog.h @@ -25,6 +25,8 @@ private: void initSettings(); bool displayImage( QString fileName ); void saveProfile(); + void loadProfileString(QString profile, QString label); + void loadProfile(); private slots: void writeValues(); @@ -35,7 +37,6 @@ private slots: void on_ge_pathButton_clicked(); void on_sdPathButton_clicked(); - void on_ProfSlot_SB_valueChanged(); void on_removeProfileButton_clicked(); void on_SplashSelect_clicked(); void on_clearImageButton_clicked(); diff --git a/companion/src/apppreferencesdialog.ui b/companion/src/apppreferencesdialog.ui index 73faa9bbd..cea4246f6 100644 --- a/companion/src/apppreferencesdialog.ui +++ b/companion/src/apppreferencesdialog.ui @@ -7,7 +7,7 @@ 0 0 685 - 462 + 431 @@ -493,324 +493,11 @@ Radio Settings - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - - 128 - 64 - - - - - 128 - 64 - - - - QFrame::Panel - - - QFrame::Raised - - - - - - true - - - - - - - - 0 - 0 - - - - Channel Order - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - true - - - - 350 - 0 - - - - true - - - - - - - true - - - - 350 - 0 - - - - true - - - - - - - Offer to write FW to Tx after download - - - - - - - - 0 - 0 - - - - - - - - Remove Profile - - - - - - - Open Folder - - - - - - - Clear Image - - - - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 100 - 16777215 - - - - Channel order - -This is used by the templated to determine which channel goes to what number output. - - - 0 - - - - R E T A - - - - - R E A T - - - - - R T E A - - - - - R T A E - - - - - R A E T - - - - - R A T E - - - - - E R T A - - - - - E R A T - - - - - E T R A - - - - - E T A R - - - - - E A R T - - - - - E A T R - - - - - T R E A - - - - - T R A E - - - - - T E R A - - - - - T E A R - - - - - T A R E - - - - - T A E R - - - - - A R E T - - - - - A R T E - - - - - A E R T - - - - - A E T R - - - - - A T R E - - - - - A T E R - - - - - - - - - 0 - 0 - - - - SD Structure path - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + - 200 + 16777215 16777215 @@ -860,7 +547,164 @@ Mode 4: - + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Channel order + +This is used by the templated to determine which channel goes to what number output. + + + 0 + + + + R E T A + + + + + R E A T + + + + + R T E A + + + + + R T A E + + + + + R A E T + + + + + R A T E + + + + + E R T A + + + + + E R A T + + + + + E T R A + + + + + E T A R + + + + + E A R T + + + + + E A T R + + + + + T R E A + + + + + T R A E + + + + + T E R A + + + + + T E A R + + + + + T A R E + + + + + T A E R + + + + + A R E T + + + + + A R T E + + + + + A E R T + + + + + A E T R + + + + + A T R E + + + + + A T E R + + + + + + + + Qt::Horizontal + + + + @@ -873,13 +717,26 @@ Mode 4: - - + + - Select Image + Settings Profile + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -893,53 +750,186 @@ Mode 4: - + + + + + 0 + 0 + + + + Channel Order + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + Append version number to FW file name - - + + + + + 0 + 0 + + - Settings Profile Name + SD Structure path + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - + + + + true + + + + 350 + 0 + + + + true + + + + + + + Select Image + + + + + + + + 0 + 0 + + + + + 128 + 64 + + + + + 128 + 64 + + + + QFrame::Panel + + + QFrame::Raised + + + + + + true + + + + + - Qt::Vertical + Qt::Horizontal - 20 - 40 + 40 + 20 - - - - - 50 - 16777215 - - - - 1 - - - 10 + + + + Offer to write FW to Tx after download - - + + - Profile Index + Remove Profile + + + + + + + Clear Image + + + + + + + Open Folder + + + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + + + + true + + + + 0 + 0 + + + + true + + + + + + + false + + + + 30 + 16777215 + @@ -973,18 +963,12 @@ Mode 4: joystickCB joystickChkB joystickcalButton - ProfName_LE - ProfSlot_SB sdPath - sdPathButton SplashFileName - SplashSelect - clearImageButton stickmodeCB channelorderCB renameFirmware burnFirmware - removeProfileButton diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 3864b9f41..6a3806b21 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -734,7 +734,7 @@ GeneralSettings::GeneralSettings() QSettings settings; templateSetup = settings.value("default_channel_order", 0).toInt(); stickMode = settings.value("default_mode", 1).toInt(); - int profile_id = settings.value("ActiveProfile", 0).toInt(); + int profile_id = settings.value("profileId", 0).toInt(); if (profile_id>0) { settings.beginGroup("Profiles"); QString profile=QString("profile%1").arg(profile_id); diff --git a/companion/src/fwpreferencesdialog.cpp b/companion/src/fwpreferencesdialog.cpp index 832262ef2..735e18acc 100644 --- a/companion/src/fwpreferencesdialog.cpp +++ b/companion/src/fwpreferencesdialog.cpp @@ -218,9 +218,6 @@ void fwPreferencesDialog::writeValues() settings.setValue("cpu_id", ui->CPU_ID_LE->text()); current_firmware_variant = getFirmwareVariant(); settings.setValue("firmware", current_firmware_variant.id); - - MainWindow * mw = (MainWindow *)this->parent(); - mw->unloadProfile(); } void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 35fce6fff..f43b7f2c1 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -124,12 +124,6 @@ MainWindow::MainWindow(): updateMenus(); readSettings(); - FirmwareInfo *firmware = GetCurrentFirmware(); - if (ActiveProfile) { - setWindowTitle(tr("Companion - Models and Settings Editor - %1 - profile %2").arg(firmware->name).arg(ActiveProfileName)); - } else { - setWindowTitle(tr("Companion - Models and Settings Editor - %1").arg(firmware->name)); - } setUnifiedTitleAndToolBarOnMac(true); this->setWindowIcon(QIcon(":/icon.png")); this->setIconSize(QSize(32,32)); @@ -758,11 +752,10 @@ void MainWindow::loadProfile() if (action) { int profnum=action->data().toInt(); QSettings settings; - settings.setValue("ActiveProfile",profnum); + settings.setValue("profileId",profnum); settings.beginGroup("Profiles"); QString profile=QString("profile%1").arg(profnum); settings.beginGroup(profile); - ActiveProfile=profnum; ActiveProfileName=settings.value("Name", "").toString(); chord=settings.value("default_channel_order", 0).toInt(); defmod=settings.value("default_mode", 0).toInt(); @@ -785,46 +778,15 @@ void MainWindow::loadProfile() settings.setValue("SplashFileName", SplashFileName); settings.setValue("SplashImage", SplashImage); settings.setValue("firmware", firmware_id); - settings.setValue("profileId", profnum); current_firmware_variant = GetFirmwareVariant(firmware_id); - FirmwareInfo *firmware = GetCurrentFirmware(); - setWindowTitle(tr("Companion - Models and Settings Editor - %1").arg(firmware->name)); - // settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); + foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { MdiChild *mdiChild = qobject_cast(window->widget()); mdiChild->eepromInterfaceChanged(); } - setWindowTitle(tr("Companion - Models and Settings Editor - %1 - profile %2").arg(firmware->name).arg(ActiveProfileName)); - } -} -void MainWindow::unloadProfile() -{ - ActiveProfile=0; - ActiveProfileName=""; - QSettings settings; - settings.setValue("ActiveProfile", 0); - FirmwareInfo *firmware = GetCurrentFirmware(); - setWindowTitle(tr("Companion - Models and Settings Editor - %1").arg(firmware->name)); -} - -void MainWindow::preferences() -{ - preferencesDialog *pd = new preferencesDialog(this); - pd->exec(); - FirmwareInfo *firmware = GetCurrentFirmware(); - if (ActiveProfile) { - setWindowTitle(tr("Companion - Models and Settings Editor - %1 - profile %2").arg(firmware->name).arg(ActiveProfileName)); + updateMenus(); } - else { - setWindowTitle(tr("Companion - Models and Settings Editor - %1").arg(firmware->name)); - } - - foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { - MdiChild *mdiChild = qobject_cast(window->widget()); - mdiChild->eepromInterfaceChanged(); - } - updateMenus(); } void MainWindow::appPreferences() @@ -838,14 +800,6 @@ void MainWindow::fwPreferences() { fwPreferencesDialog *pd = new fwPreferencesDialog(this); pd->exec(); - FirmwareInfo *firmware = GetCurrentFirmware(); - if (ActiveProfile) { - setWindowTitle(tr("Companion - Models and Settings Editor - %1 - profile %2").arg(firmware->name).arg(ActiveProfileName)); - } - else { - setWindowTitle(tr("Companion - Models and Settings Editor - %1").arg(firmware->name)); - } - foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { MdiChild *mdiChild = qobject_cast(window->widget()); mdiChild->eepromInterfaceChanged(); @@ -1640,19 +1594,9 @@ void MainWindow::updateMenus() compareAct->setEnabled(activeMdiChild()); updateRecentFileActions(); updateProfilesActions(); - bool notfound=true; + QSettings settings; - settings.beginGroup("Profiles"); - for (int i=0; isetDisabled(notfound); + setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg(settings.value("profileId").toString())); } MdiChild *MainWindow::createMdiChild() @@ -2015,8 +1959,12 @@ QMenu *MainWindow::createRecentFileMenu() QMenu *MainWindow::createProfilesMenu() { QMenu *profilesMenu=new QMenu(tr("Radio Settings Profiles")); - for ( int i = 0; i < MAX_PROFILES; ++i) + int i; + for ( i = 0; i < MAX_PROFILES; ++i) { profilesMenu->addAction(profileActs[i]); + } + if ( i>0 ) + profilesMenu->addSeparator(); profilesMenu->addAction(createProfileAct); profilesMenu->setIcon(CompanionIcon("profiles.png")); return profilesMenu; @@ -2034,11 +1982,14 @@ void MainWindow::createToolBars() case 1: size=QSize(24,24); break; + case 2: + size=QSize(32,32); + break; case 3: size=QSize(48,48); break; default: - size=QSize(32,32); + size=QSize(24,24); break; } fileToolBar = addToolBar(tr("File")); @@ -2046,11 +1997,11 @@ void MainWindow::createToolBars() fileToolBar->setObjectName("File"); fileToolBar->addAction(newAct); fileToolBar->addAction(openAct); - QToolButton * recentToolButton = new QToolButton; - recentToolButton->setPopupMode(QToolButton::InstantPopup); - recentToolButton->setMenu(createRecentFileMenu()); - recentToolButton->setIcon(CompanionIcon("recentdocument.png")); - recentToolButton->setToolTip(tr("Recent Files")); + QToolButton * recentToolButton = new QToolButton; + recentToolButton->setPopupMode(QToolButton::InstantPopup); + recentToolButton->setMenu(createRecentFileMenu()); + recentToolButton->setIcon(CompanionIcon("recentdocument.png")); + recentToolButton->setToolTip(tr("Recent Files")); fileToolBar->addWidget(recentToolButton); fileToolBar->addAction(saveAct); fileToolBar->addAction(logsAct); @@ -2058,24 +2009,12 @@ void MainWindow::createToolBars() fileToolBar->addAction(appPreferencesAct); fileToolBar->addAction(fwPreferencesAct); fileToolBar->addAction(customizeSplashAct); - profileButton = new QToolButton; - profileButton->setPopupMode(QToolButton::InstantPopup); - profileButton->setMenu(createProfilesMenu()); - profileButton->setIcon(CompanionIcon("profiles.png")); - profileButton->setToolTip(tr("Firmware Profiles")); + profileButton = new QToolButton; + profileButton->setPopupMode(QToolButton::InstantPopup); + profileButton->setMenu(createProfilesMenu()); + profileButton->setIcon(CompanionIcon("profiles.png")); + profileButton->setToolTip(tr("Firmware Profiles")); fileToolBar->addWidget(profileButton); - bool notfound=true; - settings.beginGroup("Profiles"); - for (int i=0; isetDisabled(notfound); fileToolBar->addSeparator(); fileToolBar->addAction(simulateAct); fileToolBar->addAction(printAct); @@ -2087,7 +2026,6 @@ void MainWindow::createToolBars() editToolBar->addAction(cutAct); editToolBar->addAction(copyAct); editToolBar->addAction(pasteAct); - burnToolBar = new QToolBar(tr("Write")); addToolBar( Qt::LeftToolBarArea, burnToolBar ); @@ -2123,15 +2061,18 @@ void MainWindow::readSettings() checkCompanion9x = settings.value("startup_check_companion", true).toBool(); checkFW = settings.value("startup_check_fw", true).toBool(); MaxRecentFiles =settings.value("history_size",10).toInt(); - ActiveProfile=settings.value("activeprofile",0).toInt(); - if (ActiveProfile) { - settings.beginGroup("Profiles"); - QString profile=QString("profile%1").arg(ActiveProfile); - settings.beginGroup(profile); - ActiveProfileName=settings.value("Name","").toString(); - settings.endGroup(); - settings.endGroup(); + if (settings.value("profileId",0).toInt() == 0) + { + createProfile(); + settings.setValue("profileId", "1"); } + int activeProfile=settings.value("profileId",0).toInt(); + settings.beginGroup("Profiles"); + QString profile=QString("profile%1").arg(activeProfile); + settings.beginGroup(profile); + ActiveProfileName=settings.value("Name","").toString(); + settings.endGroup(); + settings.endGroup(); } MdiChild *MainWindow::activeMdiChild() @@ -2184,6 +2125,8 @@ void MainWindow::updateProfilesActions() { int i; QSettings settings; + int activeProfile = settings.value("profileId").toInt(); + settings.beginGroup("Profiles"); for (i=0; isetText(text); profileActs[i]->setData(i+1); profileActs[i]->setVisible(true); + if ((i+1) == activeProfile) + profileActs[i]->setIcon(CompanionIcon("arrow-right.png")); + else + profileActs[i]->setIcon(CompanionIcon("")); + } else { profileActs[i]->setVisible(false); } diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index e3e082b90..e5b7eecce 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -63,7 +63,6 @@ QT_END_NAMESPACE class MainWindow : public QMainWindow { - friend class preferencesDialog; friend class fwPreferencesDialog; friend class MdiChild; // TODO GetAvrdudeArgs could be external to this class @@ -80,7 +79,6 @@ protected: public slots: void downloadLatestFW(FirmwareInfo *firmware, const QString & firmwareId); - void unloadProfile(); private slots: void openDocumentURL(); @@ -146,7 +144,6 @@ private slots: void compare(); void print(); void loadBackup(); - void preferences(); void appPreferences(); void fwPreferences(); void updateMenus(); @@ -200,7 +197,7 @@ private: bool needRename; bool showcheckForUpdatesResult; int MaxRecentFiles; - int ActiveProfile; +// int ActiveProfile; int currentFWrev; int currentFWrev_temp; int NewFwRev;