settingswidget.cpp 26 KB

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