Mercurial > public > ostc_companion
comparison SettingsDialog.cpp @ 1:0b3630a29ad8
Initial version based on previous repository.
Project was ported to QT6 and in now cmake based.
| author | Ideenmodellierer <tiefenrauscher@web.de> |
|---|---|
| date | Thu, 27 Nov 2025 18:40:28 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:76ccd6ce50c0 | 1:0b3630a29ad8 |
|---|---|
| 1 ////////////////////////////////////////////////////////////////////////////// | |
| 2 /// \file SettingsDialog.cpp | |
| 3 /// \brief Preference dialog for OSTC Companion. | |
| 4 /// \author JD Gascuel. | |
| 5 /// | |
| 6 /// \copyright (c) 2011-2014 JD Gascuel. All rights reserved. | |
| 7 /// $Id$ | |
| 8 ////////////////////////////////////////////////////////////////////////////// | |
| 9 // | |
| 10 // BSD 2-Clause License: | |
| 11 // | |
| 12 // Redistribution and use in source and binary forms, with or without | |
| 13 // modification, are permitted provided that the following conditions | |
| 14 // are met: | |
| 15 // | |
| 16 // 1. Redistributions of source code must retain the above copyright notice, | |
| 17 // this list of conditions and the following disclaimer. | |
| 18 // | |
| 19 // 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 20 // this list of conditions and the following disclaimer in the documentation | |
| 21 // and/or other materials provided with the distribution. | |
| 22 // | |
| 23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 24 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 25 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 26 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 27 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 28 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 29 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 30 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 31 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 32 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 33 // THE POSSIBILITY OF SUCH DAMAGE. | |
| 34 // | |
| 35 ////////////////////////////////////////////////////////////////////////////// | |
| 36 | |
| 37 #include "SettingsDialog.h" | |
| 38 #include "ui_Settings.h" | |
| 39 | |
| 40 #include "MainWindow.h" // Needed to propagare retranslate() | |
| 41 | |
| 42 #include "Utils/Log.h" | |
| 43 | |
| 44 #include <QApplication> | |
| 45 #include <QDialogButtonBox> | |
| 46 #include <QDir> | |
| 47 #include <QLibraryInfo> | |
| 48 #include <QPushButton> | |
| 49 #include <QSettings> | |
| 50 #include <QTranslator> | |
| 51 | |
| 52 #ifdef Q_OS_WIN | |
| 53 # define NOMINMAX 1 | |
| 54 # include <Windows.h> | |
| 55 # undef NOMINMAX | |
| 56 #endif | |
| 57 | |
| 58 #include "Export.h" | |
| 59 #include "HardwareOperations.h" | |
| 60 | |
| 61 QString EXPORT Settings::language = ""; | |
| 62 QString EXPORT Settings::port = ""; | |
| 63 QString EXPORT Settings::currentPath = ""; | |
| 64 | |
| 65 bool EXPORT Settings::autoSetDateTime = true; | |
| 66 | |
| 67 bool EXPORT Settings::forceFirmwareUpdate = false; | |
| 68 bool EXPORT Settings::forceRTEUpdate = false; | |
| 69 bool EXPORT Settings::forceFontlibUpdate = false; | |
| 70 | |
| 71 bool EXPORT Settings::useFastMode = false; | |
| 72 | |
| 73 extern QSettings* settings; | |
| 74 | |
| 75 ////////////////////////////////////////////////////////////////////////////// | |
| 76 | |
| 77 Settings::Settings(QWidget* parent, HardwareOperations *op) | |
| 78 : QDialog(parent), | |
| 79 _ui(new Ui::Settings), | |
| 80 _op(op) | |
| 81 { | |
| 82 _ui->setupUi(this); | |
| 83 reload(this); | |
| 84 } | |
| 85 | |
| 86 Settings::~Settings() | |
| 87 { | |
| 88 delete _ui; | |
| 89 } | |
| 90 | |
| 91 ////////////////////////////////////////////////////////////////////////////// | |
| 92 | |
| 93 void Settings::reload(Settings* dialog) | |
| 94 { | |
| 95 //---- Restore options from settings ------------------------------------- | |
| 96 language = settings->value("Interface/lang", | |
| 97 QLocale::system().name().right(2) ).toString(); | |
| 98 port = settings->value("OSTC/port", "").toString(); | |
| 99 currentPath = settings->value("OSTC/currentPath", "").toString(); | |
| 100 autoSetDateTime = settings->value("OSTC/autoSetDateTime", true).toBool(); | |
| 101 forceFirmwareUpdate = settings->value("OSTC/forceFirmwareUpdate", false).toBool(); | |
| 102 forceRTEUpdate = settings->value("OSTC/forceRTEUpdate", false).toBool(); | |
| 103 forceFontlibUpdate = settings->value("OSTC/forceFontlibUpdate", false).toBool(); | |
| 104 | |
| 105 useFastMode = settings->value("OSTC/useFastMode", false).toBool(); | |
| 106 | |
| 107 setLanguage(); | |
| 108 | |
| 109 if( !dialog ) | |
| 110 return; | |
| 111 | |
| 112 //---- Update interface -------------------------------------------------- | |
| 113 if( language == "DE" ) dialog->_ui->languageMenu->setCurrentIndex(0); | |
| 114 if( language == "EN" ) dialog->_ui->languageMenu->setCurrentIndex(1); | |
| 115 if( language == "ES" ) dialog->_ui->languageMenu->setCurrentIndex(2); | |
| 116 if( language == "FR" ) dialog->_ui->languageMenu->setCurrentIndex(3); | |
| 117 if( language == "IT" ) dialog->_ui->languageMenu->setCurrentIndex(4); | |
| 118 if( language == "RU" ) dialog->_ui->languageMenu->setCurrentIndex(5); | |
| 119 | |
| 120 dialog->updatePortsSlot(); | |
| 121 | |
| 122 dialog->_ui->autoSetDateTimeCB->setChecked( autoSetDateTime ); | |
| 123 dialog->_ui->forceFirmwareUpdate->setChecked( forceFirmwareUpdate ); | |
| 124 dialog->_ui->forceRTEUpdate->setChecked( forceRTEUpdate ); | |
| 125 dialog->_ui->forceFontlibUpdate->setChecked( forceFontlibUpdate ); | |
| 126 dialog->_ui->useFastMode->setChecked( useFastMode ); | |
| 127 | |
| 128 } | |
| 129 | |
| 130 ////////////////////////////////////////////////////////////////////////////// | |
| 131 | |
| 132 void Settings::languageSlot(int i) | |
| 133 { | |
| 134 switch(i) { | |
| 135 case 0: language = "DE"; break; | |
| 136 case 1: language = "EN"; break; | |
| 137 case 2: language = "ES"; break; | |
| 138 case 3: language = "FR"; break; | |
| 139 case 4: language = "IT"; break; | |
| 140 case 5: language = "RU"; break; | |
| 141 } | |
| 142 setLanguage(); | |
| 143 } | |
| 144 | |
| 145 | |
| 146 void Settings::updatePortsSlot() | |
| 147 { | |
| 148 //---- search for possible ports ---------------------------------------- | |
| 149 QStringList list; | |
| 150 if( _op ) { // Known driver type ? | |
| 151 list = _op->listPorts(); | |
| 152 | |
| 153 #ifndef Q_OS_LINUX | |
| 154 if( list.isEmpty() ) | |
| 155 _ui->noPortLabel->setText( | |
| 156 QString("<font color='red'>%1</font>: %2 - %3") | |
| 157 .arg(tr("Warning")) | |
| 158 .arg(tr("no port", "USB connection to OSTC not found")) | |
| 159 .arg(tr("Did you installed the %1 driver ?") | |
| 160 #ifdef Q_OS_WIN | |
| 161 .arg("<a href='http://www.ftdichip.com/Drivers/CDM/CDM%20v2.12.00%20WHQL%20Certified.zip'>FTDI VCP</a>"))); | |
| 162 #elif defined(Q_OS_MACX) | |
| 163 .arg("<a href='http://www.ftdichip.com/drivers/VCP/MacOSX/FTDIUSBSerialDriver_v2_2_18.dmg'>FTDI VCP</a>"))); | |
| 164 #else | |
| 165 .arg("USB"))); | |
| 166 #endif | |
| 167 else | |
| 168 #endif | |
| 169 _ui->noPortLabel->clear(); | |
| 170 } | |
| 171 | |
| 172 QString myPort = port + " (current)"; | |
| 173 if( ! port.isEmpty() ) | |
| 174 list += myPort; | |
| 175 list.sort(); | |
| 176 | |
| 177 _ui->portMenu->clear(); | |
| 178 _ui->portMenu->addItems(list); | |
| 179 _ui->portMenu->setCurrentText( port.isEmpty() ? "" : myPort ); | |
| 180 } | |
| 181 | |
| 182 ////////////////////////////////////////////////////////////////////////////// | |
| 183 | |
| 184 void Settings::setLanguage() | |
| 185 { | |
| 186 static QTranslator myappTranslator; | |
| 187 if( myappTranslator.load(":/Translations/companion_" + language) ) | |
| 188 qApp->installTranslator(&myappTranslator); | |
| 189 } | |
| 190 | |
| 191 void Settings::changeEvent(QEvent *e) | |
| 192 { | |
| 193 if( e->type() == QEvent::LanguageChange ) | |
| 194 { | |
| 195 _ui->retranslateUi(this); | |
| 196 | |
| 197 // FIX: also update the warning text... | |
| 198 updatePortsSlot(); | |
| 199 | |
| 200 // FIX: propagate to main windows. | |
| 201 if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) | |
| 202 main->retranslate(); | |
| 203 } | |
| 204 } | |
| 205 | |
| 206 ////////////////////////////////////////////////////////////////////////////// | |
| 207 | |
| 208 void Settings::accept() | |
| 209 { | |
| 210 port = _ui->portMenu->currentText().section(" ", 0, 0); | |
| 211 autoSetDateTime = _ui->autoSetDateTimeCB->isChecked(); | |
| 212 forceFirmwareUpdate = _ui->forceFirmwareUpdate->isChecked(); | |
| 213 forceRTEUpdate = _ui->forceRTEUpdate->isChecked(); | |
| 214 forceFontlibUpdate = _ui->forceFontlibUpdate->isChecked(); | |
| 215 | |
| 216 useFastMode = _ui->useFastMode->isChecked(); | |
| 217 save(); | |
| 218 QDialog::accept(); | |
| 219 } | |
| 220 | |
| 221 void Settings::save() | |
| 222 { | |
| 223 settings->setValue("Interface/lang", language); | |
| 224 settings->setValue("OSTC/port", port); | |
| 225 settings->setValue("OSTC/currentPath", currentPath); | |
| 226 settings->setValue("OSTC/autoSetDateTime", autoSetDateTime); | |
| 227 settings->setValue("OSTC/forceFirmwareUpdate", forceFirmwareUpdate); | |
| 228 settings->setValue("OSTC/forceRTEUpdate", forceRTEUpdate); | |
| 229 settings->setValue("OSTC/forceFontlibUpdate", forceFontlibUpdate); | |
| 230 settings->setValue("OSTC/useFastMode", useFastMode); | |
| 231 settings->sync(); | |
| 232 } | |
| 233 | |
| 234 ////////////////////////////////////////////////////////////////////////////// | |
| 235 | |
| 236 void Settings::reject() | |
| 237 { | |
| 238 reload(this); | |
| 239 if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) | |
| 240 main->retranslate(); | |
| 241 QDialog::reject(); | |
| 242 } | |
| 243 | |
| 244 ////////////////////////////////////////////////////////////////////////////// | |
| 245 | |
| 246 void Settings::resetSettingsSlot() | |
| 247 { | |
| 248 //---- Clear everything ------------------------------------------------- | |
| 249 settings->clear(); | |
| 250 settings->sync(); | |
| 251 //---- Set defaults | |
| 252 reload(this); | |
| 253 //---- Search connected ports | |
| 254 updatePortsSlot(); | |
| 255 } |
