From 0fd771282b100a5f9990796f9b88eaa91631be21 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 7 Apr 2017 19:18:55 +0200 Subject: [PATCH] GUI: refuse to close the preferences if any of the actions to execute is invalid --- .../main_window/preferences_dialog.cpp | 28 +++++++++++++++++++ .../main_window/preferences_dialog.h | 2 ++ .../main_window/prefs_run_program_widget.cpp | 6 ++++ .../main_window/prefs_run_program_widget.h | 1 + src/mkvtoolnix-gui/util/settings.cpp | 12 ++++++-- src/mkvtoolnix-gui/util/settings.h | 1 + 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp b/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp index cf3bf8d48..8dd369d1f 100644 --- a/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp +++ b/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp @@ -18,6 +18,7 @@ #include "mkvtoolnix-gui/main_window/prefs_run_program_widget.h" #include "mkvtoolnix-gui/merge/additional_command_line_options_dialog.h" #include "mkvtoolnix-gui/util/file_dialog.h" +#include "mkvtoolnix-gui/util/message_box.h" #include "mkvtoolnix-gui/util/model.h" #include "mkvtoolnix-gui/util/side_by_side_multi_select.h" #include "mkvtoolnix-gui/util/widget.h" @@ -826,4 +827,31 @@ PreferencesDialog::showPage(Page page) { ui->pages->setCurrentIndex(pageIndex); } +void +PreferencesDialog::accept() { + for (auto tabIdx = 0, numTabs = ui->twJobsPrograms->count(); tabIdx < numTabs; ++tabIdx) { + auto tab = qobject_cast(ui->twJobsPrograms->widget(tabIdx)); + auto error = tab->validate(); + + if (error.isEmpty()) + continue; + + showPage(Page::RunPrograms); + ui->twJobsPrograms->setCurrentIndex(tabIdx); + + Util::MessageBox::critical(this) + ->title(QY("Invalid settings")) + .text(Q("

%1 %2

" + "

%3

") + .arg(QY("This configuration is currently invalid.").toHtmlEscaped()) + .arg(error.toHtmlEscaped()) + .arg(QY("Either fix the error or remove the configuration before closing the preferences dialog.").toHtmlEscaped())) + .exec(); + + return; + } + + QDialog::accept(); +} + }} diff --git a/src/mkvtoolnix-gui/main_window/preferences_dialog.h b/src/mkvtoolnix-gui/main_window/preferences_dialog.h index 9a88d1fab..1277d238f 100644 --- a/src/mkvtoolnix-gui/main_window/preferences_dialog.h +++ b/src/mkvtoolnix-gui/main_window/preferences_dialog.h @@ -68,6 +68,8 @@ public slots: void enableOftendUsedCountriesOnly(); void enableOftendUsedCharacterSetsOnly(); + virtual void accept() override; + protected: void setupPageSelector(Page pageToShow); void setupToolTips(); diff --git a/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.cpp b/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.cpp index dbf7061e2..752c25bb8 100644 --- a/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.cpp +++ b/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.cpp @@ -436,4 +436,10 @@ PrefsRunProgramWidget::showPageForType(Util::Settings::RunProgramType type) { d->ui->gbTypeSpecificSettings->setVisible(d->pagesByType[type] != d->ui->emptyTypePage); } +QString +PrefsRunProgramWidget::validate() + const { + return config()->validate(); +} + }} diff --git a/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.h b/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.h index 456087d8e..6e17878d0 100644 --- a/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.h +++ b/src/mkvtoolnix-gui/main_window/prefs_run_program_widget.h @@ -26,6 +26,7 @@ public: bool isValid() const; Util::Settings::RunProgramConfigPtr config() const; + QString validate() const; signals: void titleChanged(); diff --git a/src/mkvtoolnix-gui/util/settings.cpp b/src/mkvtoolnix-gui/util/settings.cpp index 6b01c9840..11a11d9bf 100644 --- a/src/mkvtoolnix-gui/util/settings.cpp +++ b/src/mkvtoolnix-gui/util/settings.cpp @@ -37,12 +37,18 @@ defaultUiFont() { } +QString +Settings::RunProgramConfig::validate() + const { + return (m_type == RunProgramType::ExecuteProgram) && (m_commandLine.isEmpty() || m_commandLine.value(0).isEmpty()) ? QY("The program to execute hasn't been set yet.") + : (m_type == RunProgramType::PlayAudioFile) && m_audioFile.isEmpty() ? QY("The audio file to play hasn't been set yet.") + : QString{}; +} + bool Settings::RunProgramConfig::isValid() const { - return m_type == RunProgramType::ExecuteProgram ? !m_commandLine.value(0).isEmpty() - : m_type == RunProgramType::PlayAudioFile ? !m_audioFile.isEmpty() - : true; + return validate().isEmpty(); } QString diff --git a/src/mkvtoolnix-gui/util/settings.h b/src/mkvtoolnix-gui/util/settings.h index e99def9ff..7b34a178e 100644 --- a/src/mkvtoolnix-gui/util/settings.h +++ b/src/mkvtoolnix-gui/util/settings.h @@ -114,6 +114,7 @@ public: unsigned int m_volume{75}; bool isValid() const; + QString validate() const; QString name() const; private: