Mercurial > public > ostc_companion
view SettingsDialog.cpp @ 4:e30f00f760d3 default tip
Cleanup OSTC label and removed url
The computer type will now show OSTC 4/5 instead of only 4. The url has
been removed because it is no longer maintained. The ui header have been
deleted because they are generated files shich should not be under
version controll. Delete locally if you want to force an update of the
dialog layout.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 30 Nov 2025 18:37:32 +0100 |
| parents | 0b3630a29ad8 |
| children |
line wrap: on
line source
////////////////////////////////////////////////////////////////////////////// /// \file SettingsDialog.cpp /// \brief Preference dialog for OSTC Companion. /// \author JD Gascuel. /// /// \copyright (c) 2011-2014 JD Gascuel. All rights reserved. /// $Id$ ////////////////////////////////////////////////////////////////////////////// // // BSD 2-Clause License: // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF // THE POSSIBILITY OF SUCH DAMAGE. // ////////////////////////////////////////////////////////////////////////////// #include "SettingsDialog.h" #include "ui_Settings.h" #include "MainWindow.h" // Needed to propagare retranslate() #include "Utils/Log.h" #include <QApplication> #include <QDialogButtonBox> #include <QDir> #include <QLibraryInfo> #include <QPushButton> #include <QSettings> #include <QTranslator> #ifdef Q_OS_WIN # define NOMINMAX 1 # include <Windows.h> # undef NOMINMAX #endif #include "Export.h" #include "HardwareOperations.h" QString EXPORT Settings::language = ""; QString EXPORT Settings::port = ""; QString EXPORT Settings::currentPath = ""; bool EXPORT Settings::autoSetDateTime = true; bool EXPORT Settings::forceFirmwareUpdate = false; bool EXPORT Settings::forceRTEUpdate = false; bool EXPORT Settings::forceFontlibUpdate = false; bool EXPORT Settings::useFastMode = false; extern QSettings* settings; ////////////////////////////////////////////////////////////////////////////// Settings::Settings(QWidget* parent, HardwareOperations *op) : QDialog(parent), _ui(new Ui::Settings), _op(op) { _ui->setupUi(this); reload(this); } Settings::~Settings() { delete _ui; } ////////////////////////////////////////////////////////////////////////////// void Settings::reload(Settings* dialog) { //---- Restore options from settings ------------------------------------- language = settings->value("Interface/lang", QLocale::system().name().right(2) ).toString(); port = settings->value("OSTC/port", "").toString(); currentPath = settings->value("OSTC/currentPath", "").toString(); autoSetDateTime = settings->value("OSTC/autoSetDateTime", true).toBool(); forceFirmwareUpdate = settings->value("OSTC/forceFirmwareUpdate", false).toBool(); forceRTEUpdate = settings->value("OSTC/forceRTEUpdate", false).toBool(); forceFontlibUpdate = settings->value("OSTC/forceFontlibUpdate", false).toBool(); useFastMode = settings->value("OSTC/useFastMode", false).toBool(); setLanguage(); if( !dialog ) return; //---- Update interface -------------------------------------------------- if( language == "DE" ) dialog->_ui->languageMenu->setCurrentIndex(0); if( language == "EN" ) dialog->_ui->languageMenu->setCurrentIndex(1); if( language == "ES" ) dialog->_ui->languageMenu->setCurrentIndex(2); if( language == "FR" ) dialog->_ui->languageMenu->setCurrentIndex(3); if( language == "IT" ) dialog->_ui->languageMenu->setCurrentIndex(4); if( language == "RU" ) dialog->_ui->languageMenu->setCurrentIndex(5); dialog->updatePortsSlot(); dialog->_ui->autoSetDateTimeCB->setChecked( autoSetDateTime ); dialog->_ui->forceFirmwareUpdate->setChecked( forceFirmwareUpdate ); dialog->_ui->forceRTEUpdate->setChecked( forceRTEUpdate ); dialog->_ui->forceFontlibUpdate->setChecked( forceFontlibUpdate ); dialog->_ui->useFastMode->setChecked( useFastMode ); } ////////////////////////////////////////////////////////////////////////////// void Settings::languageSlot(int i) { switch(i) { case 0: language = "DE"; break; case 1: language = "EN"; break; case 2: language = "ES"; break; case 3: language = "FR"; break; case 4: language = "IT"; break; case 5: language = "RU"; break; } setLanguage(); } void Settings::updatePortsSlot() { //---- search for possible ports ---------------------------------------- QStringList list; if( _op ) { // Known driver type ? list = _op->listPorts(); #ifndef Q_OS_LINUX if( list.isEmpty() ) _ui->noPortLabel->setText( QString("<font color='red'>%1</font>: %2 - %3") .arg(tr("Warning")) .arg(tr("no port", "USB connection to OSTC not found")) .arg(tr("Did you installed the %1 driver ?") #ifdef Q_OS_WIN .arg("<a href='http://www.ftdichip.com/Drivers/CDM/CDM%20v2.12.00%20WHQL%20Certified.zip'>FTDI VCP</a>"))); #elif defined(Q_OS_MACX) .arg("<a href='http://www.ftdichip.com/drivers/VCP/MacOSX/FTDIUSBSerialDriver_v2_2_18.dmg'>FTDI VCP</a>"))); #else .arg("USB"))); #endif else #endif _ui->noPortLabel->clear(); } QString myPort = port + " (current)"; if( ! port.isEmpty() ) list += myPort; list.sort(); _ui->portMenu->clear(); _ui->portMenu->addItems(list); _ui->portMenu->setCurrentText( port.isEmpty() ? "" : myPort ); } ////////////////////////////////////////////////////////////////////////////// void Settings::setLanguage() { static QTranslator myappTranslator; if( myappTranslator.load(":/Translations/companion_" + language) ) qApp->installTranslator(&myappTranslator); } void Settings::changeEvent(QEvent *e) { if( e->type() == QEvent::LanguageChange ) { _ui->retranslateUi(this); // FIX: also update the warning text... updatePortsSlot(); // FIX: propagate to main windows. if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) main->retranslate(); } } ////////////////////////////////////////////////////////////////////////////// void Settings::accept() { port = _ui->portMenu->currentText().section(" ", 0, 0); autoSetDateTime = _ui->autoSetDateTimeCB->isChecked(); forceFirmwareUpdate = _ui->forceFirmwareUpdate->isChecked(); forceRTEUpdate = _ui->forceRTEUpdate->isChecked(); forceFontlibUpdate = _ui->forceFontlibUpdate->isChecked(); useFastMode = _ui->useFastMode->isChecked(); save(); QDialog::accept(); } void Settings::save() { settings->setValue("Interface/lang", language); settings->setValue("OSTC/port", port); settings->setValue("OSTC/currentPath", currentPath); settings->setValue("OSTC/autoSetDateTime", autoSetDateTime); settings->setValue("OSTC/forceFirmwareUpdate", forceFirmwareUpdate); settings->setValue("OSTC/forceRTEUpdate", forceRTEUpdate); settings->setValue("OSTC/forceFontlibUpdate", forceFontlibUpdate); settings->setValue("OSTC/useFastMode", useFastMode); settings->sync(); } ////////////////////////////////////////////////////////////////////////////// void Settings::reject() { reload(this); if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) main->retranslate(); QDialog::reject(); } ////////////////////////////////////////////////////////////////////////////// void Settings::resetSettingsSlot() { //---- Clear everything ------------------------------------------------- settings->clear(); settings->sync(); //---- Set defaults reload(this); //---- Search connected ports updatePortsSlot(); }
