From 10b495bfa57b41ca2bfd3f05e6e982559c22fff6 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Tue, 14 Feb 2012 23:36:44 +0100 Subject: [PATCH] Added a "restart" button and extended JobListModel API as required. --- gui/win_addJob.ui | 10 ++++++++-- gui/win_main.ui | 16 +++++++++++++++- res/resources.qrc | 1 + src/model_jobList.cpp | 26 +++++++++++++++++++++++++ src/model_jobList.h | 2 ++ src/version.h | 2 +- src/win_addJob.h | 1 + src/win_main.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++-------- src/win_main.h | 3 ++- 9 files changed, 101 insertions(+), 13 deletions(-) diff --git a/gui/win_addJob.ui b/gui/win_addJob.ui index 00461a8..8189820 100644 --- a/gui/win_addJob.ui +++ b/gui/win_addJob.ui @@ -774,7 +774,7 @@ - All command-line parameters you enter here will be passed to x264 unmodified and unchecked. Some parameters are forbidden, as they are reserved for the GUI. + <nobr>All command&minus;line parameters you enter here will be passed to x264 unmodified and unchecked. Some parameters are forbidden, as they are reserved for the GUI.<br>The following macros can be used:<tt> $(INPUT)</tt> expands to the current source file path and<tt> $(OUTPUT)</tt> expands to the current output file path.</nobr> Custom x264 Parameters: @@ -954,7 +954,7 @@ - All command-line parameters you enter here will be passed to x264 unmodified and unchecked. Some parameters are forbidden, as they are reserved for the GUI. + <nobr>All command&minus;line parameters you enter here will be passed to x264 unmodified and unchecked. Some parameters are forbidden, as they are reserved for the GUI.<br>The following macros can be used:<tt> $(INPUT)</tt> expands to the current source file path and<tt> $(OUTPUT)</tt> expands to the current output file path.</nobr> You can enter custom command-line options here... @@ -1007,6 +1007,9 @@ + + Your custom parameters will be ignored entirely, if you don't fix them! + @@ -1076,6 +1079,9 @@ true + + Your custom parameters will be ignored entirely, if you don't fix them! + Invalid parameter entered! diff --git a/gui/win_main.ui b/gui/win_main.ui index 0cd8b8e..239a1cd 100644 --- a/gui/win_main.ui +++ b/gui/win_main.ui @@ -364,8 +364,10 @@ + + @@ -449,7 +451,7 @@ :/buttons/add.png:/buttons/add.png - Add New Job + Create Job @@ -569,6 +571,18 @@ Avisynth Usage Wiki + + + false + + + + :/buttons/restart.png:/buttons/restart.png + + + Restart Job + + buttonAddJob diff --git a/res/resources.qrc b/res/resources.qrc index f425826..0d710e4 100644 --- a/res/resources.qrc +++ b/res/resources.qrc @@ -27,6 +27,7 @@ buttons/play_big.png buttons/power_off.png buttons/power_on.png + buttons/restart.png buttons/setup.png buttons/suspended.png buttons/trash.png diff --git a/src/model_jobList.cpp b/src/model_jobList.cpp index 74e2d6c..f5b359a 100644 --- a/src/model_jobList.cpp +++ b/src/model_jobList.cpp @@ -400,6 +400,19 @@ LogFileModel *JobListModel::getLogFile(const QModelIndex &index) return NULL; } +const QString &JobListModel::getJobSourceFile(const QModelIndex &index) +{ + static QString nullStr; + + if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count()) + { + EncodeThread *thread = m_threads.value(m_jobs.at(index.row())); + return (thread != NULL) ? thread->sourceFileName() : nullStr; + } + + return nullStr; +} + const QString &JobListModel::getJobOutputFile(const QModelIndex &index) { static QString nullStr; @@ -433,6 +446,19 @@ unsigned int JobListModel::getJobProgress(const QModelIndex &index) return 0; } +const OptionsModel *JobListModel::getJobOptions(const QModelIndex &index) +{ + static QString nullStr; + + if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count()) + { + EncodeThread *thread = m_threads.value(m_jobs.at(index.row())); + return (thread != NULL) ? thread->options() : NULL; + } + + return NULL; +} + QModelIndex JobListModel::getJobIndexById(const QUuid &id) { if(m_jobs.contains(id)) diff --git a/src/model_jobList.h b/src/model_jobList.h index c9c0457..9880b7a 100644 --- a/src/model_jobList.h +++ b/src/model_jobList.h @@ -51,9 +51,11 @@ public: bool abortJob(const QModelIndex &index); bool deleteJob(const QModelIndex &index); LogFileModel *getLogFile(const QModelIndex &index); + const QString &getJobSourceFile(const QModelIndex &index); const QString &getJobOutputFile(const QModelIndex &index); EncodeThread::JobStatus getJobStatus(const QModelIndex &index); unsigned int getJobProgress(const QModelIndex &index); + const OptionsModel *getJobOptions(const QModelIndex &index); QModelIndex getJobIndexById(const QUuid &id); protected: diff --git a/src/version.h b/src/version.h index d9279b1..ddcf6f8 100644 --- a/src/version.h +++ b/src/version.h @@ -22,7 +22,7 @@ #define VER_X264_MAJOR 2 #define VER_X264_MINOR 0 #define VER_X264_PATCH 2 -#define VER_X264_BUILD 185 +#define VER_X264_BUILD 196 #define VER_X264_MINIMUM_REV 2146 #define VER_X264_CURRENT_API 120 diff --git a/src/win_addJob.h b/src/win_addJob.h index 109de6f..99dd1e2 100644 --- a/src/win_addJob.h +++ b/src/win_addJob.h @@ -44,6 +44,7 @@ public: bool runImmediately(void) { return checkBoxRun->isChecked(); } void setRunImmediately(bool run) { checkBoxRun->setChecked(run); } void setSourceFile(const QString &path) { editSource->setText(QDir::toNativeSeparators(path)); } + void setOutputFile(const QString &path) { editOutput->setText(QDir::toNativeSeparators(path)); } protected: OptionsModel *m_options; diff --git a/src/win_main.cpp b/src/win_main.cpp index 1bc9852..f934172 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -142,6 +142,7 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures) connect(buttonAbortJob, SIGNAL(clicked()), this, SLOT(abortButtonPressed())); connect(buttonPauseJob, SIGNAL(toggled(bool)), this, SLOT(pauseButtonPressed(bool))); connect(actionJob_Delete, SIGNAL(triggered()), this, SLOT(deleteButtonPressed())); + connect(actionJob_Restart, SIGNAL(triggered()), this, SLOT(restartButtonPressed())); connect(actionJob_Browse, SIGNAL(triggered()), this, SLOT(browseButtonPressed())); //Enable menu @@ -198,16 +199,28 @@ MainWindow::~MainWindow(void) /* * The "add" button was clicked */ -void MainWindow::addButtonPressed(const QString &filePath, int fileNo, int fileTotal, bool *ok) +void MainWindow::addButtonPressed(const QString &filePathIn, const QString &filePathOut, const OptionsModel *options, int fileNo, int fileTotal, bool *ok) { qDebug("MainWindow::addButtonPressed"); if(ok) *ok = false; - AddJobDialog *addDialog = new AddJobDialog(this, m_options, m_cpuFeatures->x64); + OptionsModel *optionsTemp = m_options; + bool ownsOptions = false; + + if(options) + { + optionsTemp = new OptionsModel(*options); + ownsOptions = true; + } + + AddJobDialog *addDialog = new AddJobDialog(this, optionsTemp, m_cpuFeatures->x64); addDialog->setRunImmediately(countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1)); + + if(ownsOptions) addDialog->setWindowTitle(tr("Restart Job")); if((fileNo >= 0) && (fileTotal > 1)) addDialog->setWindowTitle(addDialog->windowTitle().append(tr(" (File %1 of %2)").arg(QString::number(fileNo+1), QString::number(fileTotal)))); - if(!filePath.isEmpty()) addDialog->setSourceFile(filePath); + if(!filePathIn.isEmpty()) addDialog->setSourceFile(filePathIn); + if(!filePathOut.isEmpty()) addDialog->setOutputFile(filePathOut); int result = addDialog->exec(); if(result == QDialog::Accepted) @@ -216,7 +229,7 @@ void MainWindow::addButtonPressed(const QString &filePath, int fileNo, int fileT ( addDialog->sourceFile(), addDialog->outputFile(), - m_options, + optionsTemp, QString("%1/toolset").arg(m_appDir), m_cpuFeatures->x64, m_cpuFeatures->x64 && m_preferences.useAvisyth64Bit @@ -235,10 +248,16 @@ void MainWindow::addButtonPressed(const QString &filePath, int fileNo, int fileT if(ok) *ok = true; } - } - m_label->setVisible(m_jobList->rowCount(QModelIndex()) == 0); + m_label->setVisible(m_jobList->rowCount(QModelIndex()) == 0); + } + X264_DELETE(addDialog); + + if(ownsOptions) + { + X264_DELETE(optionsTemp); + } } /* @@ -298,6 +317,23 @@ void MainWindow::pauseButtonPressed(bool checked) } /* + * The "restart" button was clicked + */ +void MainWindow::restartButtonPressed(void) +{ + const QModelIndex index = jobsView->currentIndex(); + + const QString &source = m_jobList->getJobSourceFile(index); + const QString &output = m_jobList->getJobOutputFile(index); + const OptionsModel *options = m_jobList->getJobOptions(index); + + if((options) && (!source.isEmpty()) && (!output.isEmpty())) + { + addButtonPressed(source, output, options); + } +} + +/* * Job item selected by user */ void MainWindow::jobSelected(const QModelIndex & current, const QModelIndex & previous) @@ -738,7 +774,7 @@ void MainWindow::init(void) { QString currentFile = files.takeFirst(); qDebug("Adding file: %s", currentFile.toUtf8().constData()); - addButtonPressed(currentFile, n++, totalFiles, &ok); + addButtonPressed(currentFile, QString(), NULL, n++, totalFiles, &ok); } } } @@ -782,7 +818,7 @@ void MainWindow::handleDroppedFiles(void) { QString currentFile = droppedFiles.takeFirst(); qDebug("Adding file: %s", currentFile.toUtf8().constData()); - addButtonPressed(currentFile, n++, totalFiles, &ok); + addButtonPressed(currentFile, QString(), NULL, n++, totalFiles, &ok); } } qDebug("Leave from MainWindow::handleDroppedFiles!"); @@ -974,6 +1010,7 @@ void MainWindow::updateButtons(EncodeThread::JobStatus status) buttonPauseJob->setChecked(status == EncodeThread::JobStatus_Paused || status == EncodeThread::JobStatus_Pausing); actionJob_Delete->setEnabled(status == EncodeThread::JobStatus_Completed || status == EncodeThread::JobStatus_Aborted || status == EncodeThread::JobStatus_Failed || status == EncodeThread::JobStatus_Enqueued); + actionJob_Restart->setEnabled(status == EncodeThread::JobStatus_Completed || status == EncodeThread::JobStatus_Aborted || status == EncodeThread::JobStatus_Failed || status == EncodeThread::JobStatus_Enqueued); actionJob_Browse->setEnabled(status == EncodeThread::JobStatus_Completed); actionJob_Start->setEnabled(buttonStartJob->isEnabled()); diff --git a/src/win_main.h b/src/win_main.h index aa68149..6471140 100644 --- a/src/win_main.h +++ b/src/win_main.h @@ -69,7 +69,7 @@ private: double detectAvisynthVersion(QLibrary *avsLib); private slots: - void addButtonPressed(const QString &filePath = QString(), int fileNo = -1, int fileTotal = 0, bool *ok = NULL); + void addButtonPressed(const QString &filePathIn = QString(), const QString &filePathOut = QString(), const OptionsModel *options = NULL, int fileNo = -1, int fileTotal = 0, bool *ok = NULL); void abortButtonPressed(void); void browseButtonPressed(void); void deleteButtonPressed(void); @@ -81,6 +81,7 @@ private slots: void jobLogExtended(const QModelIndex & parent, int start, int end); void launchNextJob(); void pauseButtonPressed(bool checked); + void restartButtonPressed(void); void showAbout(void); void showPreferences(void); void showWebLink(void); -- 2.11.0