diff --git a/src/manager.cpp b/src/manager.cpp index 5184239..76c990e 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -185,6 +185,12 @@ void Manager::translated(const TaskPtr &task) representer_->represent(task); } +void Manager::applySettings(const Settings &settings) +{ + updateSettings(settings); + settings.save(); +} + void Manager::fatalError(const QString &text) { tray_->blockActions(false); @@ -216,7 +222,7 @@ void Manager::showLast() void Manager::settings() { - SettingsEditor editor(*updater_); + SettingsEditor editor(*this, *updater_); Settings settings; settings.load(); diff --git a/src/manager.h b/src/manager.h index 2ad58d2..df116e6 100644 --- a/src/manager.h +++ b/src/manager.h @@ -16,6 +16,7 @@ public: void corrected(const TaskPtr &task); void translated(const TaskPtr &task); + void applySettings(const Settings &settings); void fatalError(const QString &text); void capture(); void repeatCapture(); diff --git a/src/settings.cpp b/src/settings.cpp index ca364ae..f2336e3 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -93,7 +93,7 @@ void cleanupOutdated(QSettings& settings) } // namespace -Settings::Settings() +void Settings::save() const { const auto baseDataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); diff --git a/src/settings.h b/src/settings.h index 9cb3d5f..a67345c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -21,9 +21,7 @@ enum class AutoUpdate { Disabled, Daily, Weekly, Monthly }; class Settings { public: - Settings(); - - void save(); + void save() const; void load(); QString captureHotkey{"Ctrl+Alt+Z"}; diff --git a/src/settingseditor.cpp b/src/settingseditor.cpp index 7d0160e..f38af38 100644 --- a/src/settingseditor.cpp +++ b/src/settingseditor.cpp @@ -1,5 +1,7 @@ #include "settingseditor.h" +#include "debug.h" #include "languagecodes.h" +#include "manager.h" #include "ui_settingseditor.h" #include "updates.h" #include "widgetstate.h" @@ -9,12 +11,16 @@ #include #include -SettingsEditor::SettingsEditor(update::Loader &updater) +SettingsEditor::SettingsEditor(Manager &manager, update::Loader &updater) : ui(new Ui::SettingsEditor) + , manager_(manager) , updater_(updater) { ui->setupUi(this); + connect(ui->buttonBox, &QDialogButtonBox::clicked, // + this, &SettingsEditor::handleButtonBoxClicked); + { auto model = new QStringListModel(this); model->setStringList({tr("General"), tr("Recognition"), tr("Correction"), @@ -248,3 +254,22 @@ void SettingsEditor::adjustUpdatesView() updateTesseractLanguages(); updateTranslators(); } + +void SettingsEditor::handleButtonBoxClicked(QAbstractButton *button) +{ + if (!button) + return; + + if (button == ui->buttonBox->button(QDialogButtonBox::Ok)) { + accept(); + return; + } + if (button == ui->buttonBox->button(QDialogButtonBox::Cancel)) { + reject(); + return; + } + if (button == ui->buttonBox->button(QDialogButtonBox::Apply)) { + manager_.applySettings(settings()); + return; + } +} diff --git a/src/settingseditor.h b/src/settingseditor.h index 267320f..0da6f7e 100644 --- a/src/settingseditor.h +++ b/src/settingseditor.h @@ -8,13 +8,14 @@ namespace Ui { class SettingsEditor; } +class QAbstractButton; class SettingsEditor : public QDialog { Q_OBJECT public: - explicit SettingsEditor(update::Loader &updater); + SettingsEditor(Manager &manager, update::Loader &updater); ~SettingsEditor(); Settings settings() const; @@ -26,8 +27,10 @@ private: void updateTranslators(); void updateTranslationLanguages(); void adjustUpdatesView(); + void handleButtonBoxClicked(QAbstractButton *button); Ui::SettingsEditor *ui; + Manager &manager_; update::Loader &updater_; QStringList enabledTranslators_; }; diff --git a/src/settingseditor.ui b/src/settingseditor.ui index 76dadbe..bda1222 100644 --- a/src/settingseditor.ui +++ b/src/settingseditor.ui @@ -20,7 +20,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok @@ -541,38 +541,5 @@ proxySaveCheck - - - buttonBox - accepted() - SettingsEditor - accept() - - - 256 - 447 - - - 157 - 274 - - - - - buttonBox - rejected() - SettingsEditor - reject() - - - 324 - 447 - - - 286 - 274 - - - - +