GUI: refuse to close the preferences if any of the actions to execute is invalid

This commit is contained in:
Moritz Bunkus 2017-04-07 19:18:55 +02:00
parent 9e00fac77a
commit 0fd771282b
6 changed files with 47 additions and 3 deletions

View File

@ -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<PrefsRunProgramWidget *>(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("<p>%1 %2</p>"
"<p>%3</p>")
.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();
}
}}

View File

@ -68,6 +68,8 @@ public slots:
void enableOftendUsedCountriesOnly();
void enableOftendUsedCharacterSetsOnly();
virtual void accept() override;
protected:
void setupPageSelector(Page pageToShow);
void setupToolTips();

View File

@ -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();
}
}}

View File

@ -26,6 +26,7 @@ public:
bool isValid() const;
Util::Settings::RunProgramConfigPtr config() const;
QString validate() const;
signals:
void titleChanged();

View File

@ -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

View File

@ -114,6 +114,7 @@ public:
unsigned int m_volume{75};
bool isValid() const;
QString validate() const;
QString name() const;
private: