From 37e70ab2524c089dd416507ddd4aca5520cfdb66 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Fri, 3 Jun 2022 21:08:18 +0300 Subject: [PATCH] - preferences dialog refactored --- client/config.h | 2 +- client/main.cpp | 12 +++-- client/preferencesdlg.cpp | 103 +++++++++++++++----------------------- client/preferencesdlg.h | 1 - client/preferencesdlg.ui | 22 -------- client/settings.cpp | 1 + 6 files changed, 51 insertions(+), 90 deletions(-) diff --git a/client/config.h b/client/config.h index 875bf39..666e2b3 100644 --- a/client/config.h +++ b/client/config.h @@ -2,7 +2,7 @@ #define __APP_CONFIG_H // Application name -#define APPNAME "Noo" +#define APPNAME "noo" // Company name #define COMPANY "voipobjects.com" diff --git a/client/main.cpp b/client/main.cpp index 016a60b..8899723 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -12,13 +12,17 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); helper::theme::applyCurrent(Settings::instance()); - QFont f = app.font(); - f.setPointSize(14); - app.setFont(f); app.setApplicationName(APPNAME); + auto& settings = Settings::instance(); + QFont f; + if (settings.data().count(KEY_APP_FONT) > 0) + { + if (f.fromString(settings.data()[KEY_APP_FONT].toString())) + app.setFont(f); + } // Path to database. - QString path = Settings::instance().getDatabasePath(); + QString path = settings.getDatabasePath(); QString folder = QFileInfo(path).absoluteDir().path(); Storage::instance().setPath(path); diff --git a/client/preferencesdlg.cpp b/client/preferencesdlg.cpp index e8a2535..be3f5e5 100644 --- a/client/preferencesdlg.cpp +++ b/client/preferencesdlg.cpp @@ -23,7 +23,7 @@ PreferencesDlg::PreferencesDlg(QWidget *parent, Settings& settings) : connect(ui->mChangePathButton, SIGNAL(clicked()), this, SLOT(onChangeDatabasePath())); connect(ui->mPauseOnIdleCheckbox, SIGNAL(toggled(bool)), this, SLOT(onPauseOnIdle(bool))); - connect(ui->mAskQuestionOnResumeCheckbox, SIGNAL(toggled(bool)), this, SLOT(smartStartSettingChanged(bool))); + connect(ui->mChangeAppFontButton, SIGNAL(clicked()), this, SLOT(onChangeAppFont())); // Autosave password ui->mAutosavePasswordCheckbox->setChecked(settings.data().value(KEY_AUTOSAVE_PASSWORD).toBool()); @@ -41,19 +41,15 @@ PreferencesDlg::PreferencesDlg(QWidget *parent, Settings& settings) : ui->mPathToDatabaseLabel->setText(settings.data().value(KEY_DB_FILENAME).toString()); // Use stop on idle ? - ui->mSmartStopTracking->setChecked(GET_BOOL(KEY_SMART_STOP)); - ui->mSmartStopIntervalInMinutes->setText(settings.data().value(KEY_SMART_STOP_MINUTES).toString()); - ui->mAskQuestionOnStopRadiobutton->setChecked(GET_BOOL(KEY_ASK_STOP)); - ui->mAutomaticallyOnStopRadiobutton->setChecked(!GET_BOOL(KEY_ASK_STOP)); - - // Use start after idle ? - ui->mSmartStartTracking->setChecked(GET_BOOL(KEY_SMART_START)); - //ui->mAskQuestionOnStartRadiobutton->setChecked(GET_BOOL(KEY_ASK_START)); - //ui->mAutomaticallyOnStartRadiobutton->setChecked(!GET_BOOL(KEY_ASK_START)); - - allowStartAfterIdleControls(); + ui->mPauseOnIdleCheckbox->setChecked(GET_BOOL(KEY_SMART_STOP)); + ui->mIdleTimeoutEdit->setText(settings.data().value(KEY_SMART_STOP_MINUTES).toString()); + ui->mAskQuestionOnResumeCheckbox->setChecked(GET_BOOL(KEY_ASK_STOP)); ui->mShowTrayIconCheckbox->setChecked(GET_BOOL(KEY_SHOW_TRAY_ICON)); + + QFont f = qApp->font(); + ui->mAppFontLabel->setText(QString("%1 %2pt").arg(f.family()).arg(f.pointSize())); + ui->mAppFontLabel->setFont(f); } @@ -62,7 +58,7 @@ PreferencesDlg::~PreferencesDlg() delete ui; } -void PreferencesDlg::selectDatabase() +void PreferencesDlg::onChangeDatabasePath() { QFileDialog dlg(this, tr("Select database to use"), helper::path::pathToDesktop()); dlg.setAcceptMode(QFileDialog::AcceptSave); @@ -70,7 +66,29 @@ void PreferencesDlg::selectDatabase() if (dlg.exec() == QDialog::Accepted) { QString filename = dlg.selectedFiles().front(); - ui->mDatabaseLocation->setText(filename); + ui->mPathToDatabaseLabel->setText(filename); + } +} + +void PreferencesDlg::onPauseOnIdle(bool value) +{ + if (value) + { + // It is possible to check idle time at all ? + if (!helper::activityTracker::ensureSmartTrackingIsPossible()) + ui->mPauseOnIdleCheckbox->setChecked(false); + } +} + +void PreferencesDlg::onChangeAppFont() +{ + QFontDialog dlg; + dlg.setCurrentFont(qApp->font()); + if (dlg.exec() == QDialog::Accepted) + { + QFont f = dlg.currentFont(); + ui->mAppFontLabel->setText(QString("%1 %2pt").arg(f.family()).arg(f.pointSize())); + ui->mAppFontLabel->setFont(f); } } @@ -82,60 +100,21 @@ void PreferencesDlg::accepted() mSettings.data()[KEY_SHOW_SECONDS] = ui->mShowSecondsCheckbox->isChecked(); mSettings.data()[KEY_ASK_BEFORE_DELETE] = ui->mAskBeforeDeleteCheckbox->isChecked(); - mSettings.data()[KEY_DB_FILENAME] = ui->mDatabaseLocation->text(); - mSettings.data()[KEY_SMART_STOP] = ui->mSmartStopTracking->isChecked(); - mSettings.data()[KEY_SMART_STOP_MINUTES] = ui->mSmartStopIntervalInMinutes->text().toInt(); - mSettings.data()[KEY_SMART_START] = ui->mSmartStartTracking->isChecked(); + mSettings.data()[KEY_DB_FILENAME] = ui->mPathToDatabaseLabel->text(); + mSettings.data()[KEY_SMART_STOP] = ui->mPauseOnIdleCheckbox->isChecked(); + mSettings.data()[KEY_SMART_STOP_MINUTES] = ui->mIdleTimeoutEdit->text().toInt(); mSettings.data()[KEY_SHOW_TRAY_ICON] = ui->mShowTrayIconCheckbox->isChecked(); - mSettings.data()[KEY_ASK_STOP] = ui->mAskQuestionOnStopRadiobutton->isChecked(); + mSettings.data()[KEY_ASK_STOP] = ui->mAskQuestionOnResumeCheckbox->isChecked(); if (mSettings.data()[KEY_DARK_THEME].toBool() != ui->mDarkThemeCheckbox->isChecked()) { mSettings.data()[KEY_DARK_THEME] = ui->mDarkThemeCheckbox->isChecked(); - applyTheme(); + helper::theme::applyCurrent(mSettings); } + + mSettings.data()[KEY_APP_FONT] = ui->mAppFontLabel->font().toString(); + mSettings.save(); } - -void PreferencesDlg::smartStopSettingChanged(bool v) -{ - if (v) - { - if (!helper::activityTracker::ensureSmartTrackingIsPossible()) - ui->mSmartStopTracking->setChecked(false); - } - allowStartAfterIdleControls(); -} - - -void PreferencesDlg::onPauseOnIdle(bool value) +void PreferencesDlg::rejected() { } - -void PreferencesDlg::allowStartAfterIdleControls() -{ - bool stopEnabled = ui->mSmartStopTracking->isChecked() && ui->mSmartStopIntervalInMinutes->text().toInt() > 0; - bool startEnabled = ui->mSmartStartTracking->isChecked(); - bool automaticStopEnabled = ui->mAutomaticallyOnStopRadiobutton->isChecked(); - //ui->mAskQuestionOnStartRadiobutton->setEnabled(stopEnabled && startEnabled); - //ui->mAutomaticallyOnStartRadiobutton->setEnabled(stopEnabled && startEnabled); - if (!stopEnabled || !automaticStopEnabled) - ui->mSmartStartTracking->setChecked(false); - ui->mSmartStartTracking->setEnabled(stopEnabled && automaticStopEnabled); - ui->mAskQuestionOnStopRadiobutton->setEnabled(stopEnabled); - ui->mAutomaticallyOnStopRadiobutton->setEnabled(stopEnabled); -} - -void PreferencesDlg::onChangeAppFont() -{ - QFontDialog dlg; - dlg.setCurrentFont(qApp->font()); - if (dlg.exec() == QDialog::Accepted) - { - // - } -} - -void PreferencesDlg::applyTheme() -{ - helper::theme::applyCurrent(mSettings); -} diff --git a/client/preferencesdlg.h b/client/preferencesdlg.h index 2db98cf..c641ae8 100644 --- a/client/preferencesdlg.h +++ b/client/preferencesdlg.h @@ -27,7 +27,6 @@ private slots: void rejected(); void onPauseOnIdle(bool v); - void onAskQuestionWhenResume(bool v); void onChangeAppFont(); void onChangeDatabasePath(); }; diff --git a/client/preferencesdlg.ui b/client/preferencesdlg.ui index 33f3251..a738b6b 100644 --- a/client/preferencesdlg.ui +++ b/client/preferencesdlg.ui @@ -295,27 +295,5 @@ - - buttonGroup - buttonClicked(int) - PreferencesDlg - smartStopWayChanged() - - - -1 - -1 - - - 215 - 162 - - - - - smartStopWayChanged() - - - - diff --git a/client/settings.cpp b/client/settings.cpp index afa7817..dc4af1e 100644 --- a/client/settings.cpp +++ b/client/settings.cpp @@ -31,6 +31,7 @@ void Settings::save() { settings.setValue(e, data().value(e)); } + settings.sync(); } void Settings::load()