diff --git a/NEWS.md b/NEWS.md
index c51bd0311..311b894fa 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,12 @@
# Version ?
+## New features and enhancements
+
+* MKVToolNix GUI: job queue: added a new setting in the preferences' "job
+ queue & job status" section that, when enabled, will cause the GUI to remove
+ all output files created by jobs that are either aborted by the user or that
+ end in an error. Implements #2614.
+
## Bug fixes
* MKVToolNix GUI: Hebrew was added to the list of often-used languages so that
diff --git a/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui b/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui
index 9e696b81c..e0733efdc 100644
--- a/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui
+++ b/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui
@@ -1678,6 +1678,13 @@
+ -
+
+
+ Remove the output &file when a job ends with errors or when it is aborted
+
+
+
-
-
@@ -2033,6 +2040,7 @@
cbGuiUseDefaultJobDescription
cbGuiShowOutputOfAllJobs
cbGuiResetJobWarningErrorCountersOnExit
+ cbGuiRemoveOutputFileOnJobFailure
cbGuiRemoveJobs
cbGuiJobRemovalPolicy
cbGuiRemoveOldJobs
diff --git a/src/mkvtoolnix-gui/jobs/job.cpp b/src/mkvtoolnix-gui/jobs/job.cpp
index db13285f3..0e131dd21 100644
--- a/src/mkvtoolnix-gui/jobs/job.cpp
+++ b/src/mkvtoolnix-gui/jobs/job.cpp
@@ -1,6 +1,8 @@
#include "common/common_pch.h"
+#include
#include
+#include
#include
#include
#include
@@ -9,6 +11,7 @@
#include "common/logger.h"
#include "common/qt.h"
#include "mkvtoolnix-gui/app.h"
+#include "mkvtoolnix-gui/info/job_settings.h"
#include "mkvtoolnix-gui/jobs/info_job.h"
#include "mkvtoolnix-gui/jobs/job.h"
#include "mkvtoolnix-gui/jobs/job_p.h"
@@ -457,6 +460,11 @@ void
Job::runProgramsAfterCompletion() {
auto p = p_func();
+ if (p->status == Aborted) {
+ maybeRemoveOutputFile();
+ return;
+ }
+
if (!mtx::included_in(p->status, DoneOk, DoneWarnings, Failed))
return;
@@ -467,6 +475,8 @@ Job::runProgramsAfterCompletion() {
});
App::programRunner().executeActionsAfterJobFinishes(*this);
+
+ maybeRemoveOutputFile();
}
void
@@ -480,4 +490,20 @@ Job::runProgramSetupVariables(ProgramRunner::VariableMap &variables)
variables[Q("JOB_EXIT_CODE")] << QString::number(p->exitCode);
}
+void
+Job::maybeRemoveOutputFile() {
+ auto p = p_func();
+
+ if ( !Util::Settings::get().m_removeOutputFileOnJobFailure
+ || !mtx::included_in(p->status, Aborted, Failed))
+ return;
+
+ auto fileName = destinationFileName();
+
+ qDebug() << "maybeRemoveOutputFile:" << fileName;
+
+ if (!fileName.isEmpty())
+ QFile::remove(fileName);
+}
+
}}}
diff --git a/src/mkvtoolnix-gui/jobs/job.h b/src/mkvtoolnix-gui/jobs/job.h
index 6077ba00a..a7385d885 100644
--- a/src/mkvtoolnix-gui/jobs/job.h
+++ b/src/mkvtoolnix-gui/jobs/job.h
@@ -112,6 +112,7 @@ protected:
virtual void loadJobBasis(Util::ConfigFile &settings);
virtual void runProgramsAfterCompletion();
void setupJobConnections();
+ virtual void maybeRemoveOutputFile();
public slots:
virtual void setStatus(Job::Status status);
diff --git a/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp b/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp
index 79c5e602c..b95347318 100644
--- a/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp
+++ b/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp
@@ -63,6 +63,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,
ui->cbGuiShowOutputOfAllJobs->setChecked(m_cfg.m_showOutputOfAllJobs);
ui->cbGuiSwitchToJobOutputAfterStarting->setChecked(m_cfg.m_switchToJobOutputAfterStarting);
ui->cbGuiResetJobWarningErrorCountersOnExit->setChecked(m_cfg.m_resetJobWarningErrorCountersOnExit);
+ ui->cbGuiRemoveOutputFileOnJobFailure->setChecked(m_cfg.m_removeOutputFileOnJobFailure);
ui->cbGuiRemoveOldJobs->setChecked(m_cfg.m_removeOldJobs);
ui->sbGuiRemoveOldJobsDays->setValue(m_cfg.m_removeOldJobsDays);
adjustRemoveOldJobsControls();
@@ -246,6 +247,7 @@ PreferencesDialog::setupToolTips() {
Util::setToolTip(ui->cbGuiShowOutputOfAllJobs, QY("If enabled, the first tab in the \"job output\" tool will not be cleared when a new job starts."));
Util::setToolTip(ui->cbGuiSwitchToJobOutputAfterStarting, QY("If enabled, the GUI will automatically switch to the job output tool whenever you start a job (e.g. by pressing \"start multiplexing\")."));
Util::setToolTip(ui->cbGuiResetJobWarningErrorCountersOnExit, QY("If enabled, the warning and error counters of all jobs and the global counters in the status bar will be reset to 0 when the program exits."));
+ Util::setToolTip(ui->cbGuiRemoveOutputFileOnJobFailure, QY("If enabled, the GUI will remove the output file created by a job if that job ends with an error or if the user aborts the job."));
Util::setToolTip(ui->cbGuiRemoveOldJobs, QY("If enabled, the GUI will remove completed jobs older than the configured number of days no matter their status on exit."));
Util::setToolTip(ui->sbGuiRemoveOldJobsDays, QY("If enabled, the GUI will remove completed jobs older than the configured number of days no matter their status on exit."));
@@ -788,6 +790,7 @@ PreferencesDialog::save() {
m_cfg.m_showOutputOfAllJobs = ui->cbGuiShowOutputOfAllJobs->isChecked();
m_cfg.m_switchToJobOutputAfterStarting = ui->cbGuiSwitchToJobOutputAfterStarting->isChecked();
m_cfg.m_resetJobWarningErrorCountersOnExit = ui->cbGuiResetJobWarningErrorCountersOnExit->isChecked();
+ m_cfg.m_removeOutputFileOnJobFailure = ui->cbGuiRemoveOutputFileOnJobFailure->isChecked();
auto idx = !ui->cbGuiRemoveJobs->isChecked() ? 0 : ui->cbGuiJobRemovalPolicy->currentIndex() + 1;
m_cfg.m_jobRemovalPolicy = static_cast(idx);
m_cfg.m_removeOldJobs = ui->cbGuiRemoveOldJobs->isChecked();
diff --git a/src/mkvtoolnix-gui/util/settings.cpp b/src/mkvtoolnix-gui/util/settings.cpp
index 2336b1f99..953712043 100644
--- a/src/mkvtoolnix-gui/util/settings.cpp
+++ b/src/mkvtoolnix-gui/util/settings.cpp
@@ -327,6 +327,7 @@ Settings::load() {
m_showOutputOfAllJobs = reg.value(s_valShowOutputOfAllJobs, true).toBool();
m_switchToJobOutputAfterStarting = reg.value(s_valSwitchToJobOutputAfterStarting, false).toBool();
m_resetJobWarningErrorCountersOnExit = reg.value(s_valResetJobWarningErrorCountersOnExit, false).toBool();
+ m_removeOutputFileOnJobFailure = reg.value(s_valRemoveOutputFileOnJobFailure, false).toBool();
m_jobRemovalPolicy = static_cast(reg.value(s_valJobRemovalPolicy, static_cast(JobRemovalPolicy::Never)).toInt());
m_removeOldJobs = reg.value(s_valRemoveOldJobs, true).toBool();
m_removeOldJobsDays = reg.value(s_valRemoveOldJobsDays, 14).toInt();
@@ -664,6 +665,7 @@ Settings::save()
reg.setValue(s_valShowOutputOfAllJobs, m_showOutputOfAllJobs);
reg.setValue(s_valSwitchToJobOutputAfterStarting, m_switchToJobOutputAfterStarting);
reg.setValue(s_valResetJobWarningErrorCountersOnExit, m_resetJobWarningErrorCountersOnExit);
+ reg.setValue(s_valRemoveOutputFileOnJobFailure, m_removeOutputFileOnJobFailure);
reg.setValue(s_valJobRemovalPolicy, static_cast(m_jobRemovalPolicy));
reg.setValue(s_valRemoveOldJobs, m_removeOldJobs);
reg.setValue(s_valRemoveOldJobsDays, m_removeOldJobsDays);
diff --git a/src/mkvtoolnix-gui/util/settings.h b/src/mkvtoolnix-gui/util/settings.h
index 74956cb0e..c606d77b8 100644
--- a/src/mkvtoolnix-gui/util/settings.h
+++ b/src/mkvtoolnix-gui/util/settings.h
@@ -174,6 +174,7 @@ public:
bool m_removeOldJobs;
int m_removeOldJobsDays;
bool m_useDefaultJobDescription, m_showOutputOfAllJobs, m_switchToJobOutputAfterStarting, m_resetJobWarningErrorCountersOnExit;
+ bool m_removeOutputFileOnJobFailure;
bool m_uiDisableHighDPIScaling;
bool m_checkForUpdates;
diff --git a/src/mkvtoolnix-gui/util/settings_names.h b/src/mkvtoolnix-gui/util/settings_names.h
index 437216e9d..e3813edf8 100644
--- a/src/mkvtoolnix-gui/util/settings_names.h
+++ b/src/mkvtoolnix-gui/util/settings_names.h
@@ -89,6 +89,7 @@ char const * const s_valRecognizedTrackLanguagesInFileNames = "recognizedTrackLa
char const * const s_valRelativeOutputDir = "relativeOutputDir";
char const * const s_valRemoveOldJobs = "removeOldJobs";
char const * const s_valRemoveOldJobsDays = "removeOldJobsDays";
+char const * const s_valRemoveOutputFileOnJobFailure = "removeOutputFileOnJobFailure";
char const * const s_valResetJobWarningErrorCountersOnExit = "resetJobWarningErrorCountersOnExit";
char const * const s_valScanForPlaylistsPolicy = "scanForPlaylistsPolicy";
char const * const s_valSetAudioDelayFromFileName = "setAudioDelayFromFileName";