Added option to shutdown the computer when all jobs are completed.

This commit is contained in:
LoRd_MuldeR 2012-02-04 01:12:21 +01:00
parent 2077dd06f2
commit 4663c724ef
21 changed files with 359 additions and 72 deletions

View File

@ -49,6 +49,9 @@
</property> </property>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="toolTip">
<string>Select the source video file. This can be an Avisynth script or any type of video file supported by FFmpegSource2 (libavformat).</string>
</property>
<property name="text"> <property name="text">
<string>Source Media/Avisynth File:</string> <string>Source Media/Avisynth File:</string>
</property> </property>
@ -58,6 +61,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QLineEdit" name="editSource"> <widget class="QLineEdit" name="editSource">
<property name="toolTip">
<string>Select the source video file. This can be an Avisynth script or any type of video file supported by FFmpegSource2 (libavformat).</string>
</property>
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -100,6 +106,9 @@
</property> </property>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="toolTip">
<string>Select the output H.264/AVC file. This can be a Matroska (MKV,) MPEG-4 Part-14 (MP4) or &quot;raw&quot; H.264 file.</string>
</property>
<property name="text"> <property name="text">
<string>Output AVC/H.264 File:</string> <string>Output AVC/H.264 File:</string>
</property> </property>
@ -109,6 +118,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
<widget class="QLineEdit" name="editOutput"> <widget class="QLineEdit" name="editOutput">
<property name="toolTip">
<string>Select the output H.264/AVC file. This can be a Matroska (MKV,) MPEG-4 Part-14 (MP4) or &quot;raw&quot; H.264 file.</string>
</property>
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -157,6 +169,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="toolTip">
<string>Here you can load a user-defined template that you have saved before. Use the &quot;Save&quot; button to save your current configuration to a new profile.</string>
</property>
<property name="text"> <property name="text">
<string>Template:</string> <string>Template:</string>
</property> </property>
@ -176,6 +191,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Here you can load a user-defined template that you have saved before. Use the &quot;Save&quot; button to save your current configuration to a new profile.</string>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>-1</number> <number>-1</number>
</property> </property>
@ -281,6 +299,9 @@
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="toolTip">
<string>Select the x264 rate-control mode. Use 'CRF' mode to hit a specific level of quality or use '2-Pass' mode to hit a specific file size.</string>
</property>
<property name="text"> <property name="text">
<string>Mode:</string> <string>Mode:</string>
</property> </property>
@ -288,6 +309,9 @@
</item> </item>
<item> <item>
<widget class="QComboBox" name="cbxRateControlMode"> <widget class="QComboBox" name="cbxRateControlMode">
<property name="toolTip">
<string>Select the x264 rate-control mode. Use 'CRF' mode to hit a specific level of quality or use '2-Pass' mode to hit a specific file size.</string>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
@ -335,6 +359,9 @@
<layout class="QVBoxLayout" name="verticalLayout_7"> <layout class="QVBoxLayout" name="verticalLayout_7">
<item> <item>
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="toolTip">
<string>Select the quantizer or CRF value. Smaller value means better quality, but bigger file. Higher value means smaller file, but lower quality. A value of '0' triggers lossless mode.</string>
</property>
<property name="text"> <property name="text">
<string>Quantizer/CRF:</string> <string>Quantizer/CRF:</string>
</property> </property>
@ -342,6 +369,9 @@
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinQuantizer"> <widget class="QSpinBox" name="spinQuantizer">
<property name="toolTip">
<string>Select the quantizer or CRF value. Smaller value means better quality, but bigger file. Higher value means smaller file, but lower quality. A value of '0' triggers lossless mode.</string>
</property>
<property name="maximum"> <property name="maximum">
<number>52</number> <number>52</number>
</property> </property>
@ -372,6 +402,9 @@
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="toolTip">
<string>Select the target average(!) bitrate, in kilobit/sec. Higher value means better quality, but bigger file. Lower value means smaller file, but lower quality.</string>
</property>
<property name="text"> <property name="text">
<string>Target Bitrate (kbps):</string> <string>Target Bitrate (kbps):</string>
</property> </property>
@ -379,6 +412,9 @@
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBitrate"> <widget class="QSpinBox" name="spinBitrate">
<property name="toolTip">
<string>Select the target average(!) bitrate, in kilobit/sec. Higher value means better quality, but bigger file. Lower value means smaller file, but lower quality.</string>
</property>
<property name="minimum"> <property name="minimum">
<number>100</number> <number>100</number>
</property> </property>
@ -441,6 +477,9 @@
<layout class="QVBoxLayout" name="verticalLayout_11"> <layout class="QVBoxLayout" name="verticalLayout_11">
<item> <item>
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="toolTip">
<string>This option controls the &quot;Speed -vs- Quality&quot; trade-off. Use a slower preset to improve the quality at the same bitrate (file size). Use a faster preset to save encoding time, at the cost of reduced quality.</string>
</property>
<property name="text"> <property name="text">
<string>Preset:</string> <string>Preset:</string>
</property> </property>
@ -448,6 +487,9 @@
</item> </item>
<item> <item>
<widget class="QComboBox" name="cbxPreset"> <widget class="QComboBox" name="cbxPreset">
<property name="toolTip">
<string>This option controls the &quot;Speed -vs- Quality&quot; trade-off. Use a slower preset to improve the quality at the same bitrate (file size). Use a faster preset to save encoding time, at the cost of reduced quality.</string>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>5</number> <number>5</number>
</property> </property>
@ -525,6 +567,9 @@
<layout class="QVBoxLayout" name="verticalLayout_10"> <layout class="QVBoxLayout" name="verticalLayout_10">
<item> <item>
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="toolTip">
<string>This option tweaks x264 for a specific type of source/content. For real-life footage, CGI and most other stuff, use the &quot;Film&quot; option. For anime/cartoon use the &quot;Animation&quot; option.</string>
</property>
<property name="text"> <property name="text">
<string>Tuning:</string> <string>Tuning:</string>
</property> </property>
@ -532,6 +577,9 @@
</item> </item>
<item> <item>
<widget class="QComboBox" name="cbxTuning"> <widget class="QComboBox" name="cbxTuning">
<property name="toolTip">
<string>This option tweaks x264 for a specific type of source/content. For real-life footage, CGI and most other stuff, use the &quot;Film&quot; option. For anime/cartoon use the &quot;Animation&quot; option.</string>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>1</number>
</property> </property>
@ -609,6 +657,9 @@
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
<item> <item>
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="label_8">
<property name="toolTip">
<string>This option can be used to enforce the restrictions of a specific H.264/AVC Proifle, though it won't force a higher profile than needed. Use &quot;Auto&quot; for an unrestricted encode.</string>
</property>
<property name="text"> <property name="text">
<string>Profile:</string> <string>Profile:</string>
</property> </property>
@ -616,6 +667,9 @@
</item> </item>
<item> <item>
<widget class="QComboBox" name="cbxProfile"> <widget class="QComboBox" name="cbxProfile">
<property name="toolTip">
<string>This option can be used to enforce the restrictions of a specific H.264/AVC Proifle, though it won't force a higher profile than needed. Use &quot;Auto&quot; for an unrestricted encode.</string>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
@ -710,6 +764,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<widget class="QLabel" name="label_10"> <widget class="QLabel" name="label_10">
<property name="toolTip">
<string>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.</string>
</property>
<property name="text"> <property name="text">
<string>Custom x264 Parameters:</string> <string>Custom x264 Parameters:</string>
</property> </property>
@ -838,6 +895,9 @@
<property name="cursor"> <property name="cursor">
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
</property> </property>
<property name="toolTip">
<string>Click here to show a detailed list of all command-line options available in your build of x264!</string>
</property>
<property name="text"> <property name="text">
<string>Show Help Screen</string> <string>Show Help Screen</string>
</property> </property>
@ -847,6 +907,9 @@
</item> </item>
<item> <item>
<widget class="QLineEdit" name="editCustomParams"> <widget class="QLineEdit" name="editCustomParams">
<property name="toolTip">
<string>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.</string>
</property>
<property name="placeholderText"> <property name="placeholderText">
<string>You can enter custom command-line options here...</string> <string>You can enter custom command-line options here...</string>
</property> </property>

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>784</width> <width>800</width>
<height>384</height> <height>384</height>
</rect> </rect>
</property> </property>

View File

@ -9,8 +9,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>375</width> <width>378</width>
<height>171</height> <height>193</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -34,17 +34,20 @@
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="1" colspan="2"> <item row="2" column="2" colspan="2">
<widget class="QLabel" name="labelJobCount"> <widget class="QLabel" name="labelJobCount">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="toolTip">
<string>If the specified number of jobs (or even more) is already running, the next one will NOT be launched yet.</string>
</property>
<property name="text"> <property name="text">
<string>Maximum number of running jobs:</string> <string>Maximum number of running jobs:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="3"> <item row="2" column="4">
<widget class="QSpinBox" name="spinBoxJobCount"> <widget class="QSpinBox" name="spinBoxJobCount">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -55,6 +58,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>If the specified number of jobs (or even more) is already running, the next one will NOT be launched yet.</string>
</property>
<property name="minimum"> <property name="minimum">
<number>1</number> <number>1</number>
</property> </property>
@ -63,20 +69,50 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="5" rowspan="2"> <item row="2" column="5">
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_4">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>1024</width> <width>0</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="0" rowspan="2"> <item row="1" column="1">
<widget class="QCheckBox" name="checkRunNextJob">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="2" colspan="4">
<widget class="QLabel" name="labelRunNextJob">
<property name="text">
<string>Automatically launch next job when a running job completes</string>
</property>
</widget>
</item>
<item row="1" column="6" rowspan="4">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" rowspan="4">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -92,26 +128,68 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="4"> <item row="3" column="1" colspan="5">
<spacer name="horizontalSpacer_4"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>20</width>
<height>20</height> <height>8</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="1" colspan="4"> <item row="4" column="1">
<widget class="QCheckBox" name="checkRunNextJob"> <widget class="QCheckBox" name="checkShutdownComputer">
<property name="text"> <property name="text">
<string>Automatically launch next job when a running job completes</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="2" colspan="4">
<widget class="QLabel" name="labelShutdownComputer">
<property name="text">
<string>Shutdown computer as soon as the last job has completed</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="5">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>12</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="1" colspan="5">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>12</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

BIN
res/buttons/power_off.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

BIN
res/buttons/power_on.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

View File

@ -24,6 +24,8 @@
<file>buttons/pause.png</file> <file>buttons/pause.png</file>
<file>buttons/play.png</file> <file>buttons/play.png</file>
<file>buttons/play_big.png</file> <file>buttons/play_big.png</file>
<file>buttons/power_off.png</file>
<file>buttons/power_on.png</file>
<file>buttons/suspended.png</file> <file>buttons/suspended.png</file>
<file>buttons/trash.png</file> <file>buttons/trash.png</file>
<file>buttons/world_link.png</file> <file>buttons/world_link.png</file>

BIN
res/sounds/beep.wav Normal file

Binary file not shown.

BIN
res/sounds/beep2.wav Normal file

Binary file not shown.

BIN
res/sounds/shutdown.wav Normal file

Binary file not shown.

View File

@ -760,6 +760,33 @@ bool x264_init_qt(int argc, char* argv[])
return true; return true;
} }
/*
* Shutdown the computer
*/
bool x264_shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown)
{
HANDLE hToken = NULL;
if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
TOKEN_PRIVILEGES privileges;
memset(&privileges, 0, sizeof(TOKEN_PRIVILEGES));
privileges.PrivilegeCount = 1;
privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &privileges.Privileges[0].Luid))
{
if(AdjustTokenPrivileges(hToken, FALSE, &privileges, NULL, NULL, NULL))
{
const DWORD reason = SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_FLAG_PLANNED;
return InitiateSystemShutdownEx(NULL, const_cast<wchar_t*>(QWCHAR(message)), timeout, forceShutdown ? TRUE : FALSE, FALSE, reason);
}
}
}
return false;
}
/* /*
* Check for debugger (detect routine) * Check for debugger (detect routine)
*/ */

View File

@ -102,5 +102,6 @@ const char *x264_version_arch(void);
void x264_init_console(int argc, char* argv[]); void x264_init_console(int argc, char* argv[]);
bool x264_init_qt(int argc, char* argv[]); bool x264_init_qt(int argc, char* argv[]);
x264_cpu_t x264_detect_cpu_features(int argc, char **argv); x264_cpu_t x264_detect_cpu_features(int argc, char **argv);
bool x264_shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown);
SIZE_T x264_dbg_private_bytes(void); SIZE_T x264_dbg_private_bytes(void);
void x264_finalization(void); void x264_finalization(void);

View File

@ -22,6 +22,7 @@
#include "model_jobList.h" #include "model_jobList.h"
#include "global.h" #include "global.h"
#include "thread_encode.h" #include "thread_encode.h"
#include "model_options.h"
#include <QIcon> #include <QIcon>
#include <QFileInfo> #include <QFileInfo>
@ -228,8 +229,26 @@ QModelIndex JobListModel::insertJob(EncodeThread *thread)
return QModelIndex(); return QModelIndex();
} }
QString config = "N/A";
switch(thread->options()->rcMode())
{
case OptionsModel::RCMode_CQ:
config = QString("CQ@%1").arg(QString::number(thread->options()->quantizer()));
break;
case OptionsModel::RCMode_CRF:
config = QString("CRF@%1").arg(QString::number(thread->options()->quantizer()));
break;
case OptionsModel::RCMode_2Pass:
config = QString("2Pass@%1").arg(QString::number(thread->options()->bitrate()));
break;
case OptionsModel::RCMode_ABR:
config = QString("ABR@%1").arg(QString::number(thread->options()->bitrate()));
break;
}
int n = 2; int n = 2;
QString jobName = QFileInfo(thread->sourceFileName()).completeBaseName(); QString jobName = QString("%1 [%2]").arg(QFileInfo(thread->sourceFileName()).completeBaseName(), config);
forever forever
{ {
@ -244,7 +263,7 @@ QModelIndex JobListModel::insertJob(EncodeThread *thread)
} }
if(!unique) if(!unique)
{ {
jobName = QString("%1 (%2)").arg(QFileInfo(thread->sourceFileName()).completeBaseName(), QString::number(n++)); jobName = QString("%1 (%2) [%3]").arg(QFileInfo(thread->sourceFileName()).completeBaseName(), QString::number(n++), config);
continue; continue;
} }
break; break;

Binary file not shown.

View File

@ -47,11 +47,13 @@ QMutex EncodeThread::m_mutex_startProcess;
{ \ { \
log("\nPROCESS ABORTED BY USER !!!"); \ log("\nPROCESS ABORTED BY USER !!!"); \
setStatus(JobStatus_Aborted); \ setStatus(JobStatus_Aborted); \
if(QFileInfo(indexFile).exists()) QFile::remove(indexFile); \
return; \ return; \
} \ } \
else if(!(OK_FLAG)) \ else if(!(OK_FLAG)) \
{ \ { \
setStatus(JobStatus_Failed); \ setStatus(JobStatus_Failed); \
if(QFileInfo(indexFile).exists()) QFile::remove(indexFile); \
return; \ return; \
} \ } \
} }
@ -178,6 +180,7 @@ void EncodeThread::encode(void)
//Use Avisynth? //Use Avisynth?
const bool usePipe = (QFileInfo(m_sourceFileName).suffix().compare("avs", Qt::CaseInsensitive) == 0); const bool usePipe = (QFileInfo(m_sourceFileName).suffix().compare("avs", Qt::CaseInsensitive) == 0);
const QString indexFile = QString("%1/%2.ffindex").arg(QDir::tempPath(), m_jobId.toString());
//Checking x264 version //Checking x264 version
log(tr("\n--- CHECK VERSION ---\n")); log(tr("\n--- CHECK VERSION ---\n"));
@ -242,27 +245,28 @@ void EncodeThread::encode(void)
} }
log(tr("\n--- PASS 1 ---\n")); log(tr("\n--- PASS 1 ---\n"));
ok = runEncodingPass(m_x64, usePipe, frames, 1, passLogFile); ok = runEncodingPass(m_x64, usePipe, frames, indexFile, 1, passLogFile);
CHECK_STATUS(m_abort, ok); CHECK_STATUS(m_abort, ok);
log(tr("\n--- PASS 2 ---\n")); log(tr("\n--- PASS 2 ---\n"));
ok = runEncodingPass(m_x64, usePipe, frames, 2, passLogFile); ok = runEncodingPass(m_x64, usePipe, frames, indexFile, 2, passLogFile);
CHECK_STATUS(m_abort, ok); CHECK_STATUS(m_abort, ok);
} }
else else
{ {
log(tr("\n--- ENCODING ---\n")); log(tr("\n--- ENCODING ---\n"));
ok = runEncodingPass(m_x64, usePipe, frames); ok = runEncodingPass(m_x64, usePipe, frames, indexFile);
CHECK_STATUS(m_abort, ok); CHECK_STATUS(m_abort, ok);
} }
log(tr("\n--- DONE ---\n")); log(tr("\n--- DONE ---\n"));
if(QFileInfo(indexFile).exists()) QFile::remove(indexFile);
int timePassed = startTime.secsTo(QDateTime::currentDateTime()); int timePassed = startTime.secsTo(QDateTime::currentDateTime());
log(tr("Job finished at %1, %2. Process took %3 minutes, %4 seconds.").arg(QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString( Qt::ISODate), QString::number(timePassed / 60), QString::number(timePassed % 60))); log(tr("Job finished at %1, %2. Process took %3 minutes, %4 seconds.").arg(QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString( Qt::ISODate), QString::number(timePassed / 60), QString::number(timePassed % 60)));
setStatus(JobStatus_Completed); setStatus(JobStatus_Completed);
} }
bool EncodeThread::runEncodingPass(bool x64, bool usePipe, unsigned int frames, int pass, const QString &passLogFile) bool EncodeThread::runEncodingPass(bool x64, bool usePipe, unsigned int frames, const QString &indexFile, int pass, const QString &passLogFile)
{ {
QProcess processEncode, processAvisynth; QProcess processEncode, processAvisynth;
@ -280,7 +284,7 @@ bool EncodeThread::runEncodingPass(bool x64, bool usePipe, unsigned int frames,
} }
} }
QStringList cmdLine_Encode = buildCommandLine(usePipe, frames, pass, passLogFile); QStringList cmdLine_Encode = buildCommandLine(usePipe, frames, indexFile, pass, passLogFile);
log("Creating x264 process:"); log("Creating x264 process:");
if(!startProcess(processEncode, QString("%1/%2.exe").arg(m_binDir, x64 ? "x264_x64" : "x264"), cmdLine_Encode)) if(!startProcess(processEncode, QString("%1/%2.exe").arg(m_binDir, x64 ? "x264_x64" : "x264"), cmdLine_Encode))
@ -458,7 +462,7 @@ bool EncodeThread::runEncodingPass(bool x64, bool usePipe, unsigned int frames,
return true; return true;
} }
QStringList EncodeThread::buildCommandLine(bool usePipe, unsigned int frames, int pass, const QString &passLogFile) QStringList EncodeThread::buildCommandLine(bool usePipe, unsigned int frames, const QString &indexFile, int pass, const QString &passLogFile)
{ {
QStringList cmdLine; QStringList cmdLine;
@ -514,7 +518,6 @@ QStringList EncodeThread::buildCommandLine(bool usePipe, unsigned int frames, in
} }
else else
{ {
QString indexFile = QString("%1/%2.ffindex").arg(QDir::tempPath(), m_jobId.toString());
cmdLine << "--index" << QDir::toNativeSeparators(indexFile); cmdLine << "--index" << QDir::toNativeSeparators(indexFile);
cmdLine << QDir::toNativeSeparators(m_sourceFileName); cmdLine << QDir::toNativeSeparators(m_sourceFileName);
} }

View File

@ -57,8 +57,9 @@ public:
~EncodeThread(void); ~EncodeThread(void);
QUuid getId(void) { return this->m_jobId; }; QUuid getId(void) { return this->m_jobId; };
const QString &sourceFileName(void) { return this->m_sourceFileName; }; const QString &sourceFileName(void) { return this->m_sourceFileName; }
const QString &outputFileName(void) { return this->m_outputFileName; }; const QString &outputFileName(void) { return this->m_outputFileName; }
const OptionsModel *options(void) { return m_options; }
void pauseJob(void) void pauseJob(void)
{ {
@ -108,8 +109,8 @@ protected:
//Encode functions //Encode functions
void encode(void); void encode(void);
bool runEncodingPass(bool x64, bool usePipe, unsigned int frames, int pass = 0, const QString &passLogFile = QString()); bool runEncodingPass(bool x64, bool usePipe, unsigned int frames, const QString &indexFile, int pass = 0, const QString &passLogFile = QString());
QStringList buildCommandLine(bool usePipe, unsigned int frames, int pass = 0, const QString &passLogFile = QString()); QStringList buildCommandLine(bool usePipe, unsigned int frames, const QString &indexFile, int pass = 0, const QString &passLogFile = QString());
unsigned int checkVersionX264(bool x64, bool &modified); unsigned int checkVersionX264(bool x64, bool &modified);
unsigned int checkVersionAvs2yuv(void); unsigned int checkVersionAvs2yuv(void);
bool checkProperties(unsigned int &frames); bool checkProperties(unsigned int &frames);

View File

@ -26,6 +26,7 @@
#include "model_options.h" #include "model_options.h"
#include "win_addJob.h" #include "win_addJob.h"
#include "win_preferences.h" #include "win_preferences.h"
#include "resource.h"
#include <QDate> #include <QDate>
#include <QTimer> #include <QTimer>
@ -36,8 +37,9 @@
#include <QDir> #include <QDir>
#include <QLibrary> #include <QLibrary>
#include <QProcess> #include <QProcess>
#include <QProgressDialog>
//#include <Shellapi.h> #include <Mmsystem.h>
const char *home_url = "http://mulder.brhack.net/"; const char *home_url = "http://mulder.brhack.net/";
@ -154,13 +156,12 @@ void MainWindow::addButtonPressed(const QString &filePath, bool *ok)
if(ok) *ok = false; if(ok) *ok = false;
AddJobDialog *addDialog = new AddJobDialog(this, m_options, m_x64supported); AddJobDialog *addDialog = new AddJobDialog(this, m_options, m_x64supported);
addDialog->setRunImmediately(countPendingJobs() < m_preferences.maxRunningJobCount); addDialog->setRunImmediately(countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1));
if(!filePath.isEmpty()) addDialog->setSourceFile(filePath); if(!filePath.isEmpty()) addDialog->setSourceFile(filePath);
int result = addDialog->exec();
int result = addDialog->exec();
if(result == QDialog::Accepted) if(result == QDialog::Accepted)
{ {
EncodeThread *thrd = new EncodeThread EncodeThread *thrd = new EncodeThread
( (
addDialog->sourceFile(), addDialog->sourceFile(),
@ -276,9 +277,10 @@ void MainWindow::jobChangedData(const QModelIndex &topLeft, const QModelIndex &
qDebug("Current job changed status!"); qDebug("Current job changed status!");
updateButtons(status); updateButtons(status);
} }
if((status == EncodeThread::JobStatus_Completed || status == EncodeThread::JobStatus_Failed) && m_preferences.autoRunNextJob) if((status == EncodeThread::JobStatus_Completed) || (status == EncodeThread::JobStatus_Failed))
{ {
QTimer::singleShot(0, this, SLOT(launchNextJob())); if(m_preferences.autoRunNextJob) QTimer::singleShot(0, this, SLOT(launchNextJob()));
if(m_preferences.shutdownComputer) QTimer::singleShot(0, this, SLOT(shutdownComputer()));
} }
} }
} }
@ -325,7 +327,7 @@ void MainWindow::showAbout(void)
forever forever
{ {
int ret = QMessageBox::information(this, tr("About..."), text.replace("-", "&minus;"), tr("About x264"), tr("About Qt"), tr("Close")); int ret = QMessageBox::information(this, tr("About..."), text.replace("-", "&minus;"), tr("About x264"), tr("About Qt"), tr("Close"), 0, 2);
switch(ret) switch(ret)
{ {
@ -367,44 +369,96 @@ void MainWindow::showPreferences(void)
void MainWindow::launchNextJob(void) void MainWindow::launchNextJob(void)
{ {
const int rows = m_jobList->rowCount(QModelIndex()); qDebug("launchNextJob(void)");
unsigned int running = countRunningJobs();
if(running >= m_preferences.maxRunningJobCount)
const int rows = m_jobList->rowCount(QModelIndex());
if(countRunningJobs() >= m_preferences.maxRunningJobCount)
{ {
qWarning("Still have too many jobs running, won't launch next one yet!"); qDebug("Still have too many jobs running, won't launch next one yet!");
return; return;
} }
bool first = true; int startIdx= jobsView->currentIndex().isValid() ? qBound(0, jobsView->currentIndex().row(), rows-1) : 0;
while(running < m_preferences.maxRunningJobCount)
{
bool ok = false;
for(int i = 0; i < rows; i++) for(int i = 0; i < rows; i++)
{ {
EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex())); int currentIdx = (i + startIdx) % rows;
EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(currentIdx, 0, QModelIndex()));
if(status == EncodeThread::JobStatus_Enqueued) if(status == EncodeThread::JobStatus_Enqueued)
{ {
if(m_jobList->startJob(m_jobList->index(i, 0, QModelIndex()))) if(m_jobList->startJob(m_jobList->index(currentIdx, 0, QModelIndex())))
{ {
if(first) jobsView->selectRow(currentIdx);
{ return;
first = false;
jobsView->selectRow(i);
}
running++;
ok = true;
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
break;
} }
} }
} }
if(!ok)
{
qWarning("No enqueued jobs left!"); qWarning("No enqueued jobs left!");
break; }
void MainWindow::shutdownComputer(void)
{
qDebug("shutdownComputer(void)");
if(countPendingJobs() > 0)
{
qDebug("Still have pending jobs, won't shutdown yet!");
return;
} }
const int iTimeout = 30;
const Qt::WindowFlags flags = Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowSystemMenuHint;
const QString text = QString("%1%2%1").arg(QString().fill(' ', 18), tr("Warning: Computer will shutdown in %1 seconds..."));
qWarning("Initiating shutdown sequence!");
QProgressDialog progressDialog(text.arg(iTimeout), tr("Cancel Shutdown"), 0, iTimeout + 1, this, flags);
QPushButton *cancelButton = new QPushButton(tr("Cancel Shutdown"), &progressDialog);
cancelButton->setIcon(QIcon(":/buttons/power_on.png"));
progressDialog.setModal(true);
progressDialog.setAutoClose(false);
progressDialog.setAutoReset(false);
progressDialog.setWindowIcon(QIcon(":/buttons/power_off.png"));
progressDialog.setWindowTitle(windowTitle());
progressDialog.setCancelButton(cancelButton);
progressDialog.show();
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QApplication::setOverrideCursor(Qt::WaitCursor);
PlaySound(MAKEINTRESOURCE(IDR_WAVE1), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
QApplication::restoreOverrideCursor();
QTimer timer;
timer.setInterval(1000);
timer.start();
QEventLoop eventLoop(this);
connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
connect(&progressDialog, SIGNAL(canceled()), &eventLoop, SLOT(quit()));
for(int i = 1; i <= iTimeout; i++)
{
eventLoop.exec();
if(progressDialog.wasCanceled())
{
progressDialog.close();
return;
}
progressDialog.setValue(i+1);
progressDialog.setLabelText(text.arg(iTimeout-i));
if(iTimeout-i == 3) progressDialog.setCancelButton(NULL);
QApplication::processEvents();
PlaySound(MAKEINTRESOURCE((i < iTimeout) ? IDR_WAVE2 : IDR_WAVE3), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
}
qWarning("Shutting down !!!");
if(x264_shutdown_computer("Simple x264 Launcher: All jobs completed, shutting down!", 10, true))
{
qApp->closeAllWindows();
} }
} }

View File

@ -72,11 +72,12 @@ private slots:
void jobSelected(const QModelIndex & current, const QModelIndex & previous); void jobSelected(const QModelIndex & current, const QModelIndex & previous);
void jobChangedData(const QModelIndex &top, const QModelIndex &bottom); void jobChangedData(const QModelIndex &top, const QModelIndex &bottom);
void jobLogExtended(const QModelIndex & parent, int start, int end); void jobLogExtended(const QModelIndex & parent, int start, int end);
void launchNextJob(void); void launchNextJob();
void pauseButtonPressed(bool checked); void pauseButtonPressed(bool checked);
void showAbout(void); void showAbout(void);
void showPreferences(void); void showPreferences(void);
void showWebLink(void); void showWebLink(void);
void shutdownComputer(void);
void startButtonPressed(void); void startButtonPressed(void);
void updateLabel(void); void updateLabel(void);
}; };

View File

@ -25,6 +25,7 @@
#include <QSettings> #include <QSettings>
#include <QDesktopServices> #include <QDesktopServices>
#include <QMouseEvent>
PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences) PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences)
: :
@ -32,10 +33,10 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences)
{ {
setupUi(this); setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
setFixedSize(size()); setFixedSize(minimumSize());
HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE); labelRunNextJob->installEventFilter(this);
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); labelShutdownComputer->installEventFilter(this);
m_preferences = preferences; m_preferences = preferences;
} }
@ -46,17 +47,50 @@ PreferencesDialog::~PreferencesDialog(void)
void PreferencesDialog::showEvent(QShowEvent *event) void PreferencesDialog::showEvent(QShowEvent *event)
{ {
QDialog::showEvent(event);
while(checkRunNextJob->isChecked() != m_preferences->autoRunNextJob) while(checkRunNextJob->isChecked() != m_preferences->autoRunNextJob)
{ {
checkRunNextJob->click(); checkRunNextJob->click();
} }
while(checkShutdownComputer->isChecked() != m_preferences->shutdownComputer)
{
checkShutdownComputer->click();
}
spinBoxJobCount->setValue(m_preferences->maxRunningJobCount); spinBoxJobCount->setValue(m_preferences->maxRunningJobCount);
} }
bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
{
if(o == labelRunNextJob && e->type() == QEvent::MouseButtonRelease)
{
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(e);
if(mouseEvent)
{
if(qApp->widgetAt(mouseEvent->globalPos()) == labelRunNextJob)
{
checkRunNextJob->click();
}
}
}
if(o == labelShutdownComputer && e->type() == QEvent::MouseButtonRelease)
{
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(e);
if(mouseEvent)
{
if(qApp->widgetAt(mouseEvent->globalPos()) == labelShutdownComputer)
{
checkShutdownComputer->click();
}
}
}
return false;
}
void PreferencesDialog::accept(void) void PreferencesDialog::accept(void)
{ {
m_preferences->autoRunNextJob = checkRunNextJob->isChecked(); m_preferences->autoRunNextJob = checkRunNextJob->isChecked();
m_preferences->shutdownComputer = checkShutdownComputer->isChecked();
m_preferences->maxRunningJobCount = spinBoxJobCount->value(); m_preferences->maxRunningJobCount = spinBoxJobCount->value();
savePreferences(m_preferences); savePreferences(m_preferences);
@ -71,6 +105,7 @@ void PreferencesDialog::loadPreferences(Preferences *preferences)
settings.beginGroup("preferences"); settings.beginGroup("preferences");
preferences->autoRunNextJob = settings.value("auto_run_next_job", QVariant(true)).toBool(); preferences->autoRunNextJob = settings.value("auto_run_next_job", QVariant(true)).toBool();
preferences->maxRunningJobCount = qBound(1U, settings.value("max_running_job_count", QVariant(1U)).toUInt(), 16U); preferences->maxRunningJobCount = qBound(1U, settings.value("max_running_job_count", QVariant(1U)).toUInt(), 16U);
preferences->shutdownComputer = settings.value("shutdown_computer_on_completion", QVariant(false)).toBool();
} }
void PreferencesDialog::savePreferences(Preferences *preferences) void PreferencesDialog::savePreferences(Preferences *preferences)
@ -80,6 +115,7 @@ void PreferencesDialog::savePreferences(Preferences *preferences)
settings.beginGroup("preferences"); settings.beginGroup("preferences");
settings.setValue("auto_run_next_job", preferences->autoRunNextJob); settings.setValue("auto_run_next_job", preferences->autoRunNextJob);
settings.setValue("shutdown_computer_on_completion", preferences->shutdownComputer);
settings.setValue("max_running_job_count", preferences->maxRunningJobCount); settings.setValue("max_running_job_count", preferences->maxRunningJobCount);
settings.sync(); settings.sync();
} }

View File

@ -32,6 +32,7 @@ public:
{ {
bool autoRunNextJob; bool autoRunNextJob;
unsigned int maxRunningJobCount; unsigned int maxRunningJobCount;
bool shutdownComputer;
} }
Preferences; Preferences;
@ -44,6 +45,7 @@ public:
protected: protected:
virtual void accept(void); virtual void accept(void);
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);
virtual bool eventFilter(QObject *o, QEvent *e);
private: private:
Preferences *m_preferences; Preferences *m_preferences;

Binary file not shown.

View File

@ -60,7 +60,7 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(QTDIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(QTDIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>QtMaind.lib;QtCored4.lib;QtGuid4.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>QtMaind.lib;QtCored4.lib;QtGuid4.lib;Winmm.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -88,7 +88,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(QTDIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(QTDIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>QtMain.lib;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>QtMain.lib;QtCore4.lib;QtGui4.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link> </Link>
<PreBuildEvent> <PreBuildEvent>