settingswidget.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2022 Felix Turowsky
  4. *
  5. *This program is free software: you can redistribute it and/or modify
  6. *it under the terms of the GNU General Public License as published by
  7. *the Free Software Foundation, either version 3 of the License, or
  8. *(at your option) any later version.
  9. *
  10. *This program is distributed in the hope that it will be useful,
  11. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *GNU General Public License for more details.
  14. *
  15. *You should have received a copy of the GNU General Public License
  16. *along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #include "settingswidget.h"
  19. #include "src/gui/dialogues/exporttocsvdialog.h"
  20. #include "ui_settingswidget.h"
  21. #include "src/classes/style.h"
  22. #include "src/classes/settings.h"
  23. #include "src/database/database.h"
  24. #include "src/database/row.h"
  25. #include "src/opl.h"
  26. #include "src/functions/datetime.h"
  27. #include "src/gui/widgets/backupwidget.h"
  28. SettingsWidget::SettingsWidget(QWidget *parent) :
  29. QWidget(parent),
  30. ui(new Ui::SettingsWidget)
  31. {
  32. ui->setupUi(this);
  33. ui->tabWidget->setCurrentIndex(0);
  34. loadBackupWidget();
  35. setupComboBoxes();
  36. setupDateEdits();
  37. setupValidators();
  38. readSettings();
  39. }
  40. SettingsWidget::~SettingsWidget()
  41. {
  42. delete ui;
  43. }
  44. void SettingsWidget::changeEvent(QEvent *event)
  45. {
  46. if (event != nullptr)
  47. if(event->type() == QEvent::LanguageChange)
  48. ui->retranslateUi(this);
  49. }
  50. void SettingsWidget::setupComboBoxes(){
  51. {
  52. // Set up Combo Boxes
  53. OPL::Style::loadStylesComboBox(ui->styleComboBox);
  54. OPL::GLOBALS->loadApproachTypes(ui->approachComboBox);
  55. OPL::GLOBALS->loadPilotFunctios(ui->functionComboBox);
  56. OPL::GLOBALS->fillViewNamesComboBox(ui->logbookViewComboBox);
  57. OPL::GLOBALS->fillLanguageComboBox(ui->languageComboBox);
  58. }
  59. }
  60. void SettingsWidget::setupDateEdits()
  61. {
  62. // Read Display Format Setting
  63. int date_format_index = Settings::read(Settings::Main::DateFormat).toInt();
  64. const QString date_format_string = OPL::DateTime::getFormatString(
  65. static_cast<OPL::DateFormat>(date_format_index));
  66. const auto date_edits = this->findChildren<QDateEdit*>();
  67. for (const auto &date_edit : date_edits) {
  68. date_edit->setDisplayFormat(date_format_string);
  69. }
  70. // Fill currencies
  71. const QList<QPair<OPL::CurrencyName, QDateEdit*>> currencies_list = {
  72. {OPL::CurrencyName::Licence, ui->currLicDateEdit},
  73. {OPL::CurrencyName::TypeRating, ui->currTrDateEdit},
  74. {OPL::CurrencyName::LineCheck, ui->currLckDateEdit},
  75. {OPL::CurrencyName::Medical, ui->currMedDateEdit},
  76. {OPL::CurrencyName::Custom1, ui->currCustom1DateEdit},
  77. {OPL::CurrencyName::Custom2, ui->currCustom2DateEdit},
  78. };
  79. for (const auto &pair : currencies_list) {
  80. const QSignalBlocker signal_blocker(pair.second);
  81. const auto entry = DB->getCurrencyEntry(static_cast<int>(pair.first));
  82. if (entry.isValid()) { // set date
  83. const auto date = QDate::fromString(
  84. entry.getData().value(OPL::Db::CURRENCIES_EXPIRYDATE).toString(),
  85. Qt::ISODate);
  86. if(date.isValid())
  87. pair.second->setDate(date);
  88. } else { // set current date
  89. pair.second->setDate(QDate::currentDate());
  90. }
  91. }
  92. }
  93. void SettingsWidget::loadBackupWidget()
  94. {
  95. auto bw = new BackupWidget(this);
  96. ui->backupStackedWidget->addWidget(bw);
  97. ui->backupStackedWidget->setCurrentWidget(bw);
  98. }
  99. /*!
  100. * \brief SettingsWidget::readSettings Reads settings from Settings and sets up the UI accordingly
  101. */
  102. void SettingsWidget::readSettings()
  103. {
  104. //const QSignalBlocker blocker(this); // don't emit editing finished for setting these values
  105. // Personal Data Tab
  106. auto user_data = DB->getPilotEntry(1).getData();
  107. ui->lastnameLineEdit->setText(user_data.value(OPL::Db::PILOTS_LASTNAME).toString());
  108. ui->firstnameLineEdit->setText(user_data.value(OPL::Db::PILOTS_FIRSTNAME).toString());
  109. ui->companyLineEdit->setText(user_data.value(OPL::Db::PILOTS_COMPANY).toString());
  110. ui->employeeidLineEdit->setText(user_data.value(OPL::Db::PILOTS_EMPLOYEEID).toString());
  111. ui->phoneLineEdit->setText(user_data.value(OPL::Db::PILOTS_PHONE).toString());
  112. ui->emailLineEdit->setText(user_data.value(OPL::Db::PILOTS_EMAIL).toString());
  113. // FLight Logging Tab
  114. ui->functionComboBox->setCurrentIndex(Settings::read(Settings::FlightLogging::Function).toInt());
  115. ui->rulesComboBox->setCurrentIndex(Settings::read(Settings::FlightLogging::LogIFR).toInt());
  116. ui->approachComboBox->setCurrentIndex(Settings::read(Settings::FlightLogging::Approach).toInt());
  117. ui->nightComboBox->setCurrentIndex(Settings::read(Settings::FlightLogging::NightLoggingEnabled).toInt());
  118. ui->prefixLineEdit->setText(Settings::read(Settings::FlightLogging::FlightNumberPrefix).toString());
  119. ui->logbookViewComboBox->setCurrentIndex(Settings::read(Settings::Main::LogbookView).toInt());
  120. ui->aliasComboBox->setCurrentIndex(Settings::read(Settings::UserData::DisplaySelfAs).toInt());
  121. // Currencies Tab
  122. ui->currToLdgCheckBox->setChecked(Settings::read(Settings::UserData::ShowToLgdCurrency).toBool());
  123. ui->currLicCheckBox->setChecked(Settings::read(Settings::UserData::ShowLicCurrency).toBool());
  124. ui->currTrCheckBox->setChecked(Settings::read(Settings::UserData::ShowTrCurrency).toBool());
  125. ui->currLckCheckBox->setChecked(Settings::read(Settings::UserData::ShowLckCurrency).toBool());
  126. ui->currMedCheckBox->setChecked(Settings::read(Settings::UserData::ShowMedCurrency).toBool());
  127. ui->currCustom1CheckBox->setChecked(Settings::read(Settings::UserData::ShowCustom1Currency).toBool());
  128. ui->currCustom2CheckBox->setChecked(Settings::read(Settings::UserData::ShowCustom2Currency).toBool());
  129. ui->currCustom1LineEdit->setText(Settings::read(Settings::UserData::Custom1CurrencyName).toString());
  130. ui->currCustom2LineEdit->setText(Settings::read(Settings::UserData::Custom2CurrencyName).toString());
  131. // Misc Tab
  132. ui->acftSortComboBox->setCurrentIndex(Settings::read(Settings::UserData::TailSortColumn).toInt());
  133. ui->pilotSortComboBox->setCurrentIndex(Settings::read(Settings::UserData::PilotSortColumn).toInt());
  134. // Don't emit signals for OPL::Style changes during setup
  135. const QSignalBlocker style_blocker(ui->styleComboBox);
  136. const QSignalBlocker font_blocker_1(ui->fontSpinBox);
  137. const QSignalBlocker font_blocker_2(ui->fontComboBox);
  138. const QSignalBlocker font_blocker_3(ui->fontCheckBox);
  139. ui->styleComboBox->setCurrentText(Settings::read(Settings::Main::Style).toString());
  140. ui->fontSpinBox->setValue(Settings::read(Settings::Main::FontSize).toUInt());
  141. ui->fontComboBox->setCurrentFont(QFont(Settings::read(Settings::Main::Font).toString()));
  142. bool use_system_font = Settings::read(Settings::Main::UseSystemFont).toBool();
  143. ui->fontCheckBox->setChecked(use_system_font);
  144. if (!use_system_font) {
  145. ui->fontComboBox->setEnabled(true);
  146. ui->fontSpinBox->setEnabled(true);
  147. }
  148. }
  149. void SettingsWidget::setupValidators()
  150. {
  151. const QHash<QLineEdit*, QRegularExpression> validator_map = {
  152. {ui->firstnameLineEdit, QRegularExpression(QLatin1String("\\w+"))},
  153. {ui->lastnameLineEdit, QRegularExpression(QLatin1String("\\w+"))},
  154. {ui->phoneLineEdit, QRegularExpression(QLatin1String("^[+]{0,1}[0-9\\-\\s]+"))},
  155. {ui->emailLineEdit, QRegularExpression(QString("\\A[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@"
  156. "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\z"))},
  157. {ui->companyLineEdit, QRegularExpression(QLatin1String("\\w+"))},
  158. {ui->employeeidLineEdit, QRegularExpression(QLatin1String("\\w+"))},
  159. {ui->prefixLineEdit, QRegularExpression(QLatin1String("\\w+"))},
  160. };
  161. QHash<QLineEdit*, QRegularExpression>::const_iterator i;
  162. for (i = validator_map.constBegin(); i != validator_map.constEnd(); ++i) {
  163. auto validator = new QRegularExpressionValidator(i.value(),i.key());
  164. i.key()->setValidator(validator);
  165. }
  166. }
  167. /*!
  168. * \brief SettingsWidget::updatePersonalDetails Updates the database with the users personal details.
  169. */
  170. void SettingsWidget::updatePersonalDetails()
  171. {
  172. OPL::RowData_T user_data;
  173. switch (ui->aliasComboBox->currentIndex()) {
  174. case 0:
  175. user_data.insert(OPL::Db::PILOTS_ALIAS, QStringLiteral("self"));
  176. break;
  177. case 1:
  178. user_data.insert(OPL::Db::PILOTS_ALIAS, QStringLiteral("SELF"));
  179. break;
  180. case 2:{
  181. QString name;
  182. name.append(ui->lastnameLineEdit->text());
  183. name.append(QLatin1String(", "));
  184. name.append(ui->firstnameLineEdit->text().at(0));
  185. name.append(QLatin1Char('.'));
  186. user_data.insert(OPL::Db::PILOTS_ALIAS, name);
  187. }
  188. break;
  189. default:
  190. break;
  191. }
  192. user_data.insert(OPL::Db::PILOTS_LASTNAME, ui->lastnameLineEdit->text());
  193. user_data.insert(OPL::Db::PILOTS_FIRSTNAME, ui->firstnameLineEdit->text());
  194. user_data.insert(OPL::Db::PILOTS_COMPANY, ui->companyLineEdit->text());
  195. user_data.insert(OPL::Db::PILOTS_EMPLOYEEID, ui->employeeidLineEdit->text());
  196. user_data.insert(OPL::Db::PILOTS_PHONE, ui->phoneLineEdit->text());
  197. user_data.insert(OPL::Db::PILOTS_EMAIL, ui->emailLineEdit->text());
  198. auto user = OPL::PilotEntry(1, user_data);
  199. TODO << "Changing DB does not currently refresh logbook view";
  200. TODO << "Check for empty line edits (First, last name should not be empty...validators not a good way because it gives no user feedback)";
  201. if(!DB->commit(user))
  202. WARN(tr("Unable to update Database:<br>") + DB->lastError.text());
  203. else
  204. LOG << "User updated successfully.";
  205. }
  206. /*
  207. * Personal Tab
  208. */
  209. void SettingsWidget::on_lastnameLineEdit_editingFinished()
  210. {
  211. updatePersonalDetails();
  212. }
  213. void SettingsWidget::on_firstnameLineEdit_editingFinished()
  214. {
  215. updatePersonalDetails();
  216. }
  217. void SettingsWidget::on_companyLineEdit_editingFinished()
  218. {
  219. updatePersonalDetails();
  220. }
  221. void SettingsWidget::on_employeeidLineEdit_editingFinished()
  222. {
  223. updatePersonalDetails();
  224. }
  225. void SettingsWidget::on_emailLineEdit_editingFinished()
  226. {
  227. updatePersonalDetails();
  228. }
  229. void SettingsWidget::on_phoneLineEdit_editingFinished()
  230. {
  231. updatePersonalDetails();
  232. }
  233. /*
  234. * Flight Logging Tab
  235. */
  236. void SettingsWidget::on_aliasComboBox_currentIndexChanged(int index)
  237. {
  238. Settings::write(Settings::UserData::DisplaySelfAs, index);
  239. updatePersonalDetails();
  240. }
  241. void SettingsWidget::on_functionComboBox_currentIndexChanged(int arg1)
  242. {
  243. Settings::write(Settings::FlightLogging::Function, arg1);
  244. }
  245. void SettingsWidget::on_rulesComboBox_currentIndexChanged(int arg1)
  246. {
  247. Settings::write(Settings::FlightLogging::LogIFR, arg1);
  248. }
  249. void SettingsWidget::on_approachComboBox_currentIndexChanged(int arg1)
  250. {
  251. Settings::write(Settings::FlightLogging::Approach, arg1);
  252. }
  253. void SettingsWidget::on_nightComboBox_currentIndexChanged(int index)
  254. {
  255. Settings::write(Settings::FlightLogging::NightLoggingEnabled, index);
  256. switch (index) {
  257. case 1:
  258. Settings::write(Settings::FlightLogging::NightAngle, -6);
  259. break;
  260. case 2:
  261. Settings::write(Settings::FlightLogging::NightAngle, 0);
  262. break;
  263. default:
  264. Settings::write(Settings::FlightLogging::NightAngle, -6);
  265. }
  266. }
  267. void SettingsWidget::on_prefixLineEdit_textChanged(const QString &arg1)
  268. {
  269. Settings::write(Settings::FlightLogging::FlightNumberPrefix, arg1);
  270. }
  271. /*
  272. * Misc Tab
  273. */
  274. void SettingsWidget::on_logbookViewComboBox_currentIndexChanged(int index)
  275. {
  276. Settings::write(Settings::Main::LogbookView, index);
  277. emit settingChanged(SettingSignal::LogbookWidget);
  278. }
  279. void SettingsWidget::on_pilotSortComboBox_currentIndexChanged(int index)
  280. {
  281. Settings::write(Settings::UserData::PilotSortColumn, index);
  282. emit settingChanged(PilotsWidget);
  283. }
  284. void SettingsWidget::on_acftSortComboBox_currentIndexChanged(int index)
  285. {
  286. Settings::write(Settings::UserData::TailSortColumn, index);
  287. emit settingChanged(AircraftWidget);
  288. }
  289. /*
  290. * About Tab
  291. */
  292. /*!
  293. * \brief SettingsWidget::on_aboutPushButton_clicked Displays Application Version and Licensing information
  294. */
  295. void SettingsWidget::on_aboutPushButton_clicked()
  296. {
  297. QMessageBox message_box(this);
  298. QPixmap icon = QPixmap(OPL::Assets::ICON_MAIN);
  299. message_box.setIconPixmap(icon.scaledToWidth(64, Qt::TransformationMode::SmoothTransformation));
  300. QString SQLITE_VERSION = DB->sqliteVersion();
  301. QString text = QMessageBox::tr(
  302. "<h3><center>About</center></h3>"
  303. "<br>"
  304. "&#169; 2020 - 2022 Felix Turowsky"
  305. "<br>"
  306. "<p>This is a collaboratively developed Free and Open Source Application. "
  307. "Visit us <a href=\"https://%1/\">here</a> for more information.</p>"
  308. "<p>This program is free software: you can redistribute it and/or modify "
  309. "it under the terms of the GNU General Public License as published by "
  310. "the Free Software Foundation, either version 3 of the License, or "
  311. "(at your option) any later version.</p>"
  312. "<p>This program is distributed in the hope that it will be useful, "
  313. "but WITHOUT ANY WARRANTY; without even the implied warranty of "
  314. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
  315. "GNU General Public License for more details.</p> "
  316. "<p>You should have received a copy of the GNU General Public License "
  317. "along with this program. If not, "
  318. "please click <a href=\"https://%2\">here</a>.</p>"
  319. "<br>"
  320. "You are using openPilotLog version %3."
  321. "<br>"
  322. "<p>This program uses <a href=\"http://%4/\">Qt</a> version %5 and "
  323. "<a href=\"https://%6/\">SQLite</a> version %7</p>"
  324. ).arg(
  325. QStringLiteral("github.com/fiffty-50/openpilotlog"),
  326. QStringLiteral("gnu.org/licenses/"),
  327. OPL_VERSION_STRING,
  328. QStringLiteral("qt.io"),
  329. QT_VERSION_STR,
  330. QStringLiteral("sqlite.org/about.html"),
  331. SQLITE_VERSION);
  332. message_box.setText(text);
  333. message_box.exec();
  334. }
  335. void SettingsWidget::on_aboutBackupsPushButton_clicked()
  336. {
  337. QString text = tr(
  338. "<h3><center>About Backups</center></h3>"
  339. "<br>"
  340. "<p>By creating a backup, you create a copy of your logbook for safekeeping. This copy includes all your "
  341. "flights, pilots, aircraft and currencies. By creating a backup, you are creating a snapshot of your logbook to date. This backup can "
  342. "later be restored. OpenPilotLog offers two kinds of backups: Local and External Backups.<br><br>Local backups "
  343. "are automatically stored in a folder on this computer and will show up in the list below. They can easily be created by selecting <b>Create Local backup</b> and restored with "
  344. "<b>Restore Local Backup</b>.<br><br>"
  345. "When using <b>Create External Backup</b>, you will be asked where to save your backup file. This can be an external hard drive, USB stick, a cloud location or any other location of your choice. "
  346. "This functionality can also be used to sync your database across devices or to take it with you when you buy a new PC. You can then import your backup file by selecting "
  347. "it with <b>Restore external backup</b>.</p>"
  348. "<p>Frequent backups are recommended to prevent data loss or corruption. It is also recommended to keep a backup copy in a location physically seperated from your main "
  349. "computer to prevent data loss due to system failures.</p>"
  350. //todo "<p>By default, OpenPilotLog creates a weekly automatic backup. If you would like to change this behaviour, you can adjust it in the settings.</p>"
  351. "<br>"
  352. );
  353. QMessageBox msg_box(QMessageBox::Information, "About backups", text, QMessageBox::Ok, this);
  354. msg_box.exec();
  355. }
  356. void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& new_style_setting)
  357. {
  358. if (new_style_setting == QLatin1String("Dark-Palette")) {
  359. OPL::Style::setStyle(OPL::Style::darkPalette());
  360. Settings::write(Settings::Main::Style, new_style_setting);
  361. emit settingChanged(MainWindow);
  362. return;
  363. }
  364. for (const auto &style_name : OPL::Style::styles) {
  365. if (new_style_setting == style_name) {
  366. OPL::Style::setStyle(style_name);
  367. Settings::write(Settings::Main::Style, new_style_setting);
  368. emit settingChanged(MainWindow);
  369. return;
  370. }
  371. }
  372. for (const auto &style_sheet : OPL::Style::styleSheets) {
  373. if (new_style_setting == style_sheet.styleSheetName) {
  374. OPL::Style::setStyle(style_sheet);
  375. Settings::write(Settings::Main::Style, new_style_setting);
  376. emit settingChanged(MainWindow);
  377. return;
  378. }
  379. }
  380. }
  381. void SettingsWidget::on_fontComboBox_currentFontChanged(const QFont &f)
  382. {
  383. qApp->setFont(f);
  384. Settings::write(Settings::Main::Font, f.toString());
  385. DEB << "Setting Font:" << f.toString();
  386. }
  387. void SettingsWidget::on_fontSpinBox_valueChanged(int arg1)
  388. {
  389. QFont f = qApp->font();
  390. f.setPointSize(arg1);
  391. qApp->setFont(f);
  392. Settings::write(Settings::Main::FontSize, arg1);
  393. DEB << "Setting Font:" << f.toString();
  394. }
  395. void SettingsWidget::on_fontCheckBox_stateChanged(int arg1)
  396. {
  397. if (usingStylesheet() && arg1 == Qt::Unchecked) {
  398. WARN(tr("The OPL::Style you have currently selected may not be fully compatible "
  399. "with changing to a custom font while the application is running.<br><br>"
  400. "Applying your changes may require restarting the application.<br>"));
  401. }
  402. switch (arg1) {
  403. case Qt::Unchecked:
  404. {
  405. ui->fontComboBox->setEnabled(true);
  406. ui->fontSpinBox->setEnabled(true);
  407. Settings::write(Settings::Main::UseSystemFont, false);
  408. QFont font(ui->fontComboBox->currentFont());
  409. font.setPointSize(ui->fontSpinBox->value());
  410. qApp->setFont(font);
  411. LOG << "Setting Font:" << font.toString();
  412. break;
  413. }
  414. case Qt::Checked:
  415. {
  416. ui->fontComboBox->setEnabled(false);
  417. ui->fontSpinBox->setEnabled(false);
  418. Settings::write(Settings::Main::UseSystemFont, true);
  419. INFO(tr("The application will be restarted for this change to take effect."));
  420. qApp->quit();
  421. QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
  422. }
  423. break;
  424. default:
  425. break;
  426. }
  427. }
  428. /*!
  429. * \brief Determines if the user has selected a OPL::Stylesheet or is using a Qt OPL::Style Factory Style
  430. */
  431. bool SettingsWidget::usingStylesheet()
  432. {
  433. for (const auto &style_sheet : OPL::Style::styleSheets) {
  434. if (style_sheet.styleSheetName == ui->styleComboBox->currentText())
  435. return true;
  436. }
  437. return false;
  438. }
  439. void SettingsWidget::on_resetStylePushButton_clicked()
  440. {
  441. LOG << "Resetting OPL::Style to default...";
  442. ui->styleComboBox->setCurrentText(OPL::Style::defaultStyle);
  443. ui->fontCheckBox->setChecked(true);
  444. }
  445. void SettingsWidget::on_currLicDateEdit_userDateChanged(const QDate &date)
  446. {
  447. const OPL::RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
  448. const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Licence), row_data);
  449. if (!DB->commit(entry))
  450. WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
  451. emit settingChanged(HomeWidget);
  452. }
  453. void SettingsWidget::on_currTrDateEdit_userDateChanged(const QDate &date)
  454. {
  455. const OPL::RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
  456. const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::TypeRating), row_data);
  457. if (!DB->commit(entry))
  458. WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
  459. emit settingChanged(HomeWidget);
  460. }
  461. void SettingsWidget::on_currLckDateEdit_userDateChanged(const QDate &date)
  462. {
  463. const OPL::RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
  464. const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::LineCheck), row_data);
  465. if (!DB->commit(entry))
  466. WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
  467. emit settingChanged(HomeWidget);
  468. }
  469. void SettingsWidget::on_currMedDateEdit_userDateChanged(const QDate &date)
  470. {
  471. const OPL::RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)}};
  472. const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Medical), row_data);
  473. if (!DB->commit(entry))
  474. WARN(tr("Unable to update currency. The following error has ocurred:<br>%1").arg(DB->lastError.text()));
  475. emit settingChanged(HomeWidget);
  476. }
  477. void SettingsWidget::on_currCustom1DateEdit_userDateChanged(const QDate &date)
  478. {
  479. const OPL::RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)},
  480. {OPL::Db::CURRENCIES_CURRENCYNAME, ui->currCustom1LineEdit->text()}};
  481. const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Custom1), row_data);
  482. DEB << entry;
  483. if (!DB->commit(entry))
  484. WARN(tr("Unable to update currency. The following error has ocurred:<br><br>%1").arg(DB->lastError.text()));
  485. emit settingChanged(HomeWidget);
  486. }
  487. void SettingsWidget::on_currCustom2DateEdit_userDateChanged(const QDate &date)
  488. {
  489. const OPL::RowData_T row_data = {{OPL::Db::CURRENCIES_EXPIRYDATE, date.toString(Qt::ISODate)},
  490. {OPL::Db::CURRENCIES_CURRENCYNAME, ui->currCustom2LineEdit->text()}};
  491. const OPL::CurrencyEntry entry(static_cast<int>(OPL::CurrencyName::Custom2), row_data);
  492. if (!DB->commit(entry))
  493. WARN(tr("Unable to update currency. The following error has ocurred:<br><br>%1").arg(DB->lastError.text()));
  494. emit settingChanged(HomeWidget);
  495. }
  496. void SettingsWidget::on_currToLdgCheckBox_stateChanged(int arg1)
  497. {
  498. switch (arg1) {
  499. case Qt::CheckState::Checked:
  500. Settings::write(Settings::UserData::ShowToLgdCurrency, true);
  501. break;
  502. case Qt::CheckState::Unchecked:
  503. Settings::write(Settings::UserData::ShowToLgdCurrency, false);
  504. break;
  505. default:
  506. break;
  507. }
  508. emit settingChanged(HomeWidget);
  509. }
  510. void SettingsWidget::on_currLicCheckBox_stateChanged(int arg1)
  511. {
  512. switch (arg1) {
  513. case Qt::CheckState::Checked:
  514. Settings::write(Settings::UserData::ShowLicCurrency, true);
  515. break;
  516. case Qt::CheckState::Unchecked:
  517. Settings::write(Settings::UserData::ShowLicCurrency, false);
  518. break;
  519. default:
  520. break;
  521. }
  522. emit settingChanged(HomeWidget);
  523. }
  524. void SettingsWidget::on_currTrCheckBox_stateChanged(int arg1)
  525. {
  526. switch (arg1) {
  527. case Qt::CheckState::Checked:
  528. Settings::write(Settings::UserData::ShowTrCurrency, true);
  529. break;
  530. case Qt::CheckState::Unchecked:
  531. Settings::write(Settings::UserData::ShowTrCurrency, false);
  532. break;
  533. default:
  534. break;
  535. }
  536. emit settingChanged(HomeWidget);
  537. }
  538. void SettingsWidget::on_currLckCheckBox_stateChanged(int arg1)
  539. {
  540. switch (arg1) {
  541. case Qt::CheckState::Checked:
  542. Settings::write(Settings::UserData::ShowLckCurrency, true);
  543. break;
  544. case Qt::CheckState::Unchecked:
  545. Settings::write(Settings::UserData::ShowLckCurrency, false);
  546. break;
  547. default:
  548. break;
  549. }
  550. emit settingChanged(HomeWidget);
  551. }
  552. void SettingsWidget::on_currMedCheckBox_stateChanged(int arg1)
  553. {
  554. switch (arg1) {
  555. case Qt::CheckState::Checked:
  556. Settings::write(Settings::UserData::ShowMedCurrency, true);
  557. break;
  558. case Qt::CheckState::Unchecked:
  559. Settings::write(Settings::UserData::ShowMedCurrency, false);
  560. break;
  561. default:
  562. break;
  563. }
  564. emit settingChanged(HomeWidget);
  565. }
  566. void SettingsWidget::on_currCustom1CheckBox_stateChanged(int arg1)
  567. {
  568. switch (arg1) {
  569. case Qt::CheckState::Checked:
  570. Settings::write(Settings::UserData::ShowCustom1Currency, true);
  571. break;
  572. case Qt::CheckState::Unchecked:
  573. Settings::write(Settings::UserData::ShowCustom1Currency, false);
  574. break;
  575. default:
  576. break;
  577. }
  578. emit settingChanged(HomeWidget);
  579. }
  580. void SettingsWidget::on_currCustom2CheckBox_stateChanged(int arg1)
  581. {
  582. switch (arg1) {
  583. case Qt::CheckState::Checked:
  584. Settings::write(Settings::UserData::ShowCustom2Currency, true);
  585. break;
  586. case Qt::CheckState::Unchecked:
  587. Settings::write(Settings::UserData::ShowCustom2Currency, false);
  588. break;
  589. default:
  590. break;
  591. }
  592. emit settingChanged(HomeWidget);
  593. }
  594. void SettingsWidget::on_currCustom1LineEdit_editingFinished()
  595. {
  596. Settings::write(Settings::UserData::Custom1CurrencyName, ui->currCustom1LineEdit->text());
  597. }
  598. void SettingsWidget::on_currCustom2LineEdit_editingFinished()
  599. {
  600. Settings::write(Settings::UserData::Custom2CurrencyName, ui->currCustom2LineEdit->text());
  601. }
  602. void SettingsWidget::on_languageComboBox_activated(int arg1)
  603. {
  604. if (arg1 != 0) {
  605. INFO(tr("Translations are not yet available. If you are interested in making openPilotLog available in your native "
  606. "language, visit us <a href=\"https://%1/\">here</a> for more information."
  607. ).arg(QStringLiteral("github.com/fiffty-50/openpilotlog/wiki/Translations")));
  608. ui->languageComboBox->setCurrentIndex(0);
  609. }
  610. }
  611. void SettingsWidget::on_exportPushButton_clicked()
  612. {
  613. auto exp = new ExportToCsvDialog(this);
  614. exp->exec();
  615. }