Mercurial > public > ostc_companion
comparison SettingsDialog.cpp @ 8:21ce6187d32e
Minor changes done by automatic style checker
| author | Ideenmodellierer |
|---|---|
| date | Mon, 12 Jan 2026 13:51:17 +0000 |
| parents | 0b3630a29ad8 |
| children |
comparison
equal
deleted
inserted
replaced
| 7:0969ef86c42d | 8:21ce6187d32e |
|---|---|
| 35 ////////////////////////////////////////////////////////////////////////////// | 35 ////////////////////////////////////////////////////////////////////////////// |
| 36 | 36 |
| 37 #include "SettingsDialog.h" | 37 #include "SettingsDialog.h" |
| 38 #include "ui_Settings.h" | 38 #include "ui_Settings.h" |
| 39 | 39 |
| 40 #include "MainWindow.h" // Needed to propagare retranslate() | 40 #include "MainWindow.h" // Needed to propagare retranslate() |
| 41 | 41 |
| 42 #include "Utils/Log.h" | 42 #include "Utils/Log.h" |
| 43 | 43 |
| 44 #include <QApplication> | 44 #include <QApplication> |
| 45 #include <QDialogButtonBox> | 45 #include <QDialogButtonBox> |
| 48 #include <QPushButton> | 48 #include <QPushButton> |
| 49 #include <QSettings> | 49 #include <QSettings> |
| 50 #include <QTranslator> | 50 #include <QTranslator> |
| 51 | 51 |
| 52 #ifdef Q_OS_WIN | 52 #ifdef Q_OS_WIN |
| 53 # define NOMINMAX 1 | 53 #define NOMINMAX 1 |
| 54 # include <Windows.h> | 54 #include <Windows.h> |
| 55 # undef NOMINMAX | 55 #undef NOMINMAX |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 #include "Export.h" | 58 #include "Export.h" |
| 59 #include "HardwareOperations.h" | 59 #include "HardwareOperations.h" |
| 60 | 60 |
| 68 bool EXPORT Settings::forceRTEUpdate = false; | 68 bool EXPORT Settings::forceRTEUpdate = false; |
| 69 bool EXPORT Settings::forceFontlibUpdate = false; | 69 bool EXPORT Settings::forceFontlibUpdate = false; |
| 70 | 70 |
| 71 bool EXPORT Settings::useFastMode = false; | 71 bool EXPORT Settings::useFastMode = false; |
| 72 | 72 |
| 73 extern QSettings* settings; | 73 extern QSettings *settings; |
| 74 | 74 |
| 75 ////////////////////////////////////////////////////////////////////////////// | 75 ////////////////////////////////////////////////////////////////////////////// |
| 76 | 76 |
| 77 Settings::Settings(QWidget* parent, HardwareOperations *op) | 77 Settings::Settings(QWidget *parent, HardwareOperations *op) |
| 78 : QDialog(parent), | 78 : QDialog(parent) |
| 79 _ui(new Ui::Settings), | 79 , _ui(new Ui::Settings) |
| 80 _op(op) | 80 , _op(op) |
| 81 { | 81 { |
| 82 _ui->setupUi(this); | 82 _ui->setupUi(this); |
| 83 reload(this); | 83 reload(this); |
| 84 } | 84 } |
| 85 | 85 |
| 88 delete _ui; | 88 delete _ui; |
| 89 } | 89 } |
| 90 | 90 |
| 91 ////////////////////////////////////////////////////////////////////////////// | 91 ////////////////////////////////////////////////////////////////////////////// |
| 92 | 92 |
| 93 void Settings::reload(Settings* dialog) | 93 void Settings::reload(Settings *dialog) |
| 94 { | 94 { |
| 95 //---- Restore options from settings ------------------------------------- | 95 //---- Restore options from settings ------------------------------------- |
| 96 language = settings->value("Interface/lang", | 96 language = settings->value("Interface/lang", QLocale::system().name().right(2)).toString(); |
| 97 QLocale::system().name().right(2) ).toString(); | 97 port = settings->value("OSTC/port", "").toString(); |
| 98 port = settings->value("OSTC/port", "").toString(); | 98 currentPath = settings->value("OSTC/currentPath", "").toString(); |
| 99 currentPath = settings->value("OSTC/currentPath", "").toString(); | |
| 100 autoSetDateTime = settings->value("OSTC/autoSetDateTime", true).toBool(); | 99 autoSetDateTime = settings->value("OSTC/autoSetDateTime", true).toBool(); |
| 101 forceFirmwareUpdate = settings->value("OSTC/forceFirmwareUpdate", false).toBool(); | 100 forceFirmwareUpdate = settings->value("OSTC/forceFirmwareUpdate", false).toBool(); |
| 102 forceRTEUpdate = settings->value("OSTC/forceRTEUpdate", false).toBool(); | 101 forceRTEUpdate = settings->value("OSTC/forceRTEUpdate", false).toBool(); |
| 103 forceFontlibUpdate = settings->value("OSTC/forceFontlibUpdate", false).toBool(); | 102 forceFontlibUpdate = settings->value("OSTC/forceFontlibUpdate", false).toBool(); |
| 104 | 103 |
| 105 useFastMode = settings->value("OSTC/useFastMode", false).toBool(); | 104 useFastMode = settings->value("OSTC/useFastMode", false).toBool(); |
| 106 | 105 |
| 107 setLanguage(); | 106 setLanguage(); |
| 108 | 107 |
| 109 if( !dialog ) | 108 if (!dialog) |
| 110 return; | 109 return; |
| 111 | 110 |
| 112 //---- Update interface -------------------------------------------------- | 111 //---- Update interface -------------------------------------------------- |
| 113 if( language == "DE" ) dialog->_ui->languageMenu->setCurrentIndex(0); | 112 if (language == "DE") |
| 114 if( language == "EN" ) dialog->_ui->languageMenu->setCurrentIndex(1); | 113 dialog->_ui->languageMenu->setCurrentIndex(0); |
| 115 if( language == "ES" ) dialog->_ui->languageMenu->setCurrentIndex(2); | 114 if (language == "EN") |
| 116 if( language == "FR" ) dialog->_ui->languageMenu->setCurrentIndex(3); | 115 dialog->_ui->languageMenu->setCurrentIndex(1); |
| 117 if( language == "IT" ) dialog->_ui->languageMenu->setCurrentIndex(4); | 116 if (language == "ES") |
| 118 if( language == "RU" ) dialog->_ui->languageMenu->setCurrentIndex(5); | 117 dialog->_ui->languageMenu->setCurrentIndex(2); |
| 118 if (language == "FR") | |
| 119 dialog->_ui->languageMenu->setCurrentIndex(3); | |
| 120 if (language == "IT") | |
| 121 dialog->_ui->languageMenu->setCurrentIndex(4); | |
| 122 if (language == "RU") | |
| 123 dialog->_ui->languageMenu->setCurrentIndex(5); | |
| 119 | 124 |
| 120 dialog->updatePortsSlot(); | 125 dialog->updatePortsSlot(); |
| 121 | 126 |
| 122 dialog->_ui->autoSetDateTimeCB->setChecked( autoSetDateTime ); | 127 dialog->_ui->autoSetDateTimeCB->setChecked(autoSetDateTime); |
| 123 dialog->_ui->forceFirmwareUpdate->setChecked( forceFirmwareUpdate ); | 128 dialog->_ui->forceFirmwareUpdate->setChecked(forceFirmwareUpdate); |
| 124 dialog->_ui->forceRTEUpdate->setChecked( forceRTEUpdate ); | 129 dialog->_ui->forceRTEUpdate->setChecked(forceRTEUpdate); |
| 125 dialog->_ui->forceFontlibUpdate->setChecked( forceFontlibUpdate ); | 130 dialog->_ui->forceFontlibUpdate->setChecked(forceFontlibUpdate); |
| 126 dialog->_ui->useFastMode->setChecked( useFastMode ); | 131 dialog->_ui->useFastMode->setChecked(useFastMode); |
| 127 | |
| 128 } | 132 } |
| 129 | 133 |
| 130 ////////////////////////////////////////////////////////////////////////////// | 134 ////////////////////////////////////////////////////////////////////////////// |
| 131 | 135 |
| 132 void Settings::languageSlot(int i) | 136 void Settings::languageSlot(int i) |
| 133 { | 137 { |
| 134 switch(i) { | 138 switch (i) { |
| 135 case 0: language = "DE"; break; | 139 case 0: |
| 136 case 1: language = "EN"; break; | 140 language = "DE"; |
| 137 case 2: language = "ES"; break; | 141 break; |
| 138 case 3: language = "FR"; break; | 142 case 1: |
| 139 case 4: language = "IT"; break; | 143 language = "EN"; |
| 140 case 5: language = "RU"; break; | 144 break; |
| 145 case 2: | |
| 146 language = "ES"; | |
| 147 break; | |
| 148 case 3: | |
| 149 language = "FR"; | |
| 150 break; | |
| 151 case 4: | |
| 152 language = "IT"; | |
| 153 break; | |
| 154 case 5: | |
| 155 language = "RU"; | |
| 156 break; | |
| 141 } | 157 } |
| 142 setLanguage(); | 158 setLanguage(); |
| 143 } | 159 } |
| 144 | 160 |
| 145 | |
| 146 void Settings::updatePortsSlot() | 161 void Settings::updatePortsSlot() |
| 147 { | 162 { |
| 148 //---- search for possible ports ---------------------------------------- | 163 //---- search for possible ports ---------------------------------------- |
| 149 QStringList list; | 164 QStringList list; |
| 150 if( _op ) { // Known driver type ? | 165 if (_op) { // Known driver type ? |
| 151 list = _op->listPorts(); | 166 list = _op->listPorts(); |
| 152 | 167 |
| 153 #ifndef Q_OS_LINUX | 168 #ifndef Q_OS_LINUX |
| 154 if( list.isEmpty() ) | 169 if (list.isEmpty()) |
| 155 _ui->noPortLabel->setText( | 170 _ui->noPortLabel->setText( |
| 156 QString("<font color='red'>%1</font>: %2 - %3") | 171 QString("<font color='red'>%1</font>: %2 - %3") |
| 157 .arg(tr("Warning")) | 172 .arg(tr("Warning")) |
| 158 .arg(tr("no port", "USB connection to OSTC not found")) | 173 .arg(tr("no port", "USB connection to OSTC not found")) |
| 159 .arg(tr("Did you installed the %1 driver ?") | 174 .arg(tr("Did you installed the %1 driver ?") |
| 160 #ifdef Q_OS_WIN | 175 #ifdef Q_OS_WIN |
| 161 .arg("<a href='http://www.ftdichip.com/Drivers/CDM/CDM%20v2.12.00%20WHQL%20Certified.zip'>FTDI VCP</a>"))); | 176 .arg("<a " |
| 177 "href='http://www.ftdichip.com/Drivers/CDM/" | |
| 178 "CDM%20v2.12.00%20WHQL%20Certified.zip'>FTDI VCP</a>"))); | |
| 162 #elif defined(Q_OS_MACX) | 179 #elif defined(Q_OS_MACX) |
| 163 .arg("<a href='http://www.ftdichip.com/drivers/VCP/MacOSX/FTDIUSBSerialDriver_v2_2_18.dmg'>FTDI VCP</a>"))); | 180 .arg("<a " |
| 181 "href='http://www.ftdichip.com/drivers/VCP/MacOSX/" | |
| 182 "FTDIUSBSerialDriver_v2_2_18.dmg'>FTDI VCP</a>"))); | |
| 164 #else | 183 #else |
| 165 .arg("USB"))); | 184 .arg("USB"))); |
| 166 #endif | 185 #endif |
| 167 else | 186 else |
| 168 #endif | 187 #endif |
| 169 _ui->noPortLabel->clear(); | 188 _ui->noPortLabel->clear(); |
| 170 } | 189 } |
| 171 | 190 |
| 172 QString myPort = port + " (current)"; | 191 QString myPort = port + " (current)"; |
| 173 if( ! port.isEmpty() ) | 192 if (!port.isEmpty()) |
| 174 list += myPort; | 193 list += myPort; |
| 175 list.sort(); | 194 list.sort(); |
| 176 | 195 |
| 177 _ui->portMenu->clear(); | 196 _ui->portMenu->clear(); |
| 178 _ui->portMenu->addItems(list); | 197 _ui->portMenu->addItems(list); |
| 179 _ui->portMenu->setCurrentText( port.isEmpty() ? "" : myPort ); | 198 _ui->portMenu->setCurrentText(port.isEmpty() ? "" : myPort); |
| 180 } | 199 } |
| 181 | 200 |
| 182 ////////////////////////////////////////////////////////////////////////////// | 201 ////////////////////////////////////////////////////////////////////////////// |
| 183 | 202 |
| 184 void Settings::setLanguage() | 203 void Settings::setLanguage() |
| 185 { | 204 { |
| 186 static QTranslator myappTranslator; | 205 static QTranslator myappTranslator; |
| 187 if( myappTranslator.load(":/Translations/companion_" + language) ) | 206 if (myappTranslator.load(":/Translations/companion_" + language)) |
| 188 qApp->installTranslator(&myappTranslator); | 207 qApp->installTranslator(&myappTranslator); |
| 189 } | 208 } |
| 190 | 209 |
| 191 void Settings::changeEvent(QEvent *e) | 210 void Settings::changeEvent(QEvent *e) |
| 192 { | 211 { |
| 193 if( e->type() == QEvent::LanguageChange ) | 212 if (e->type() == QEvent::LanguageChange) { |
| 194 { | |
| 195 _ui->retranslateUi(this); | 213 _ui->retranslateUi(this); |
| 196 | 214 |
| 197 // FIX: also update the warning text... | 215 // FIX: also update the warning text... |
| 198 updatePortsSlot(); | 216 updatePortsSlot(); |
| 199 | 217 |
| 200 // FIX: propagate to main windows. | 218 // FIX: propagate to main windows. |
| 201 if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) | 219 if (MainWindow *main = dynamic_cast<MainWindow *>(parent())) |
| 202 main->retranslate(); | 220 main->retranslate(); |
| 203 } | 221 } |
| 204 } | 222 } |
| 205 | 223 |
| 206 ////////////////////////////////////////////////////////////////////////////// | 224 ////////////////////////////////////////////////////////////////////////////// |
| 218 QDialog::accept(); | 236 QDialog::accept(); |
| 219 } | 237 } |
| 220 | 238 |
| 221 void Settings::save() | 239 void Settings::save() |
| 222 { | 240 { |
| 223 settings->setValue("Interface/lang", language); | 241 settings->setValue("Interface/lang", language); |
| 224 settings->setValue("OSTC/port", port); | 242 settings->setValue("OSTC/port", port); |
| 225 settings->setValue("OSTC/currentPath", currentPath); | 243 settings->setValue("OSTC/currentPath", currentPath); |
| 226 settings->setValue("OSTC/autoSetDateTime", autoSetDateTime); | 244 settings->setValue("OSTC/autoSetDateTime", autoSetDateTime); |
| 227 settings->setValue("OSTC/forceFirmwareUpdate", forceFirmwareUpdate); | 245 settings->setValue("OSTC/forceFirmwareUpdate", forceFirmwareUpdate); |
| 228 settings->setValue("OSTC/forceRTEUpdate", forceRTEUpdate); | 246 settings->setValue("OSTC/forceRTEUpdate", forceRTEUpdate); |
| 229 settings->setValue("OSTC/forceFontlibUpdate", forceFontlibUpdate); | 247 settings->setValue("OSTC/forceFontlibUpdate", forceFontlibUpdate); |
| 230 settings->setValue("OSTC/useFastMode", useFastMode); | 248 settings->setValue("OSTC/useFastMode", useFastMode); |
| 234 ////////////////////////////////////////////////////////////////////////////// | 252 ////////////////////////////////////////////////////////////////////////////// |
| 235 | 253 |
| 236 void Settings::reject() | 254 void Settings::reject() |
| 237 { | 255 { |
| 238 reload(this); | 256 reload(this); |
| 239 if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) | 257 if (MainWindow *main = dynamic_cast<MainWindow *>(parent())) |
| 240 main->retranslate(); | 258 main->retranslate(); |
| 241 QDialog::reject(); | 259 QDialog::reject(); |
| 242 } | 260 } |
| 243 | 261 |
| 244 ////////////////////////////////////////////////////////////////////////////// | 262 ////////////////////////////////////////////////////////////////////////////// |
