OSDN Git Service

Added option to shutdown the computer when all jobs are completed.
authorlordmulder <mulder2@gmx.de>
Sat, 4 Feb 2012 00:12:21 +0000 (01:12 +0100)
committerlordmulder <mulder2@gmx.de>
Sat, 4 Feb 2012 00:12:21 +0000 (01:12 +0100)
21 files changed:
gui/win_addJob.ui
gui/win_help.ui
gui/win_preferences.ui
res/buttons/power_off.png [new file with mode: 0644]
res/buttons/power_on.png [new file with mode: 0644]
res/resources.qrc
res/sounds/beep.wav [new file with mode: 0644]
res/sounds/beep2.wav [new file with mode: 0644]
res/sounds/shutdown.wav [new file with mode: 0644]
src/global.cpp
src/global.h
src/model_jobList.cpp
src/resource.h
src/thread_encode.cpp
src/thread_encode.h
src/win_main.cpp
src/win_main.h
src/win_preferences.cpp
src/win_preferences.h
x264_launcher.rc
x264_launcher.vcxproj

index 280af40..bb877d2 100644 (file)
@@ -49,6 +49,9 @@
         </property>
         <item>
          <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">
            <string>Source Media/Avisynth File:</string>
           </property>
@@ -58,6 +61,9 @@
          <layout class="QHBoxLayout" name="horizontalLayout_5">
           <item>
            <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">
              <bool>true</bool>
             </property>
         </property>
         <item>
          <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">
            <string>Output AVC/H.264 File:</string>
           </property>
          <layout class="QHBoxLayout" name="horizontalLayout_6">
           <item>
            <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">
              <bool>true</bool>
             </property>
        <layout class="QHBoxLayout" name="horizontalLayout_7">
         <item>
          <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">
            <string>Template:</string>
           </property>
             <height>0</height>
            </size>
           </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">
            <number>-1</number>
           </property>
             <layout class="QVBoxLayout" name="verticalLayout_4">
              <item>
               <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">
                 <string>Mode:</string>
                </property>
              </item>
              <item>
               <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">
                 <number>0</number>
                </property>
             <layout class="QVBoxLayout" name="verticalLayout_7">
              <item>
               <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">
                 <string>Quantizer/CRF:</string>
                </property>
              </item>
              <item>
               <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">
                 <number>52</number>
                </property>
             <layout class="QVBoxLayout" name="verticalLayout_6">
              <item>
               <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">
                 <string>Target Bitrate (kbps):</string>
                </property>
              </item>
              <item>
               <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">
                 <number>100</number>
                </property>
             <layout class="QVBoxLayout" name="verticalLayout_11">
              <item>
               <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">
                 <string>Preset:</string>
                </property>
              </item>
              <item>
               <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">
                 <number>5</number>
                </property>
             <layout class="QVBoxLayout" name="verticalLayout_10">
              <item>
               <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">
                 <string>Tuning:</string>
                </property>
              </item>
              <item>
               <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">
                 <number>1</number>
                </property>
             <layout class="QVBoxLayout" name="verticalLayout_9">
              <item>
               <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">
                 <string>Profile:</string>
                </property>
              </item>
              <item>
               <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">
                 <number>0</number>
                </property>
             <layout class="QHBoxLayout" name="horizontalLayout_4">
              <item>
               <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">
                 <string>Custom x264 Parameters:</string>
                </property>
                <property name="cursor">
                 <cursorShape>PointingHandCursor</cursorShape>
                </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">
                 <string>Show Help Screen</string>
                </property>
            </item>
            <item>
             <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">
               <string>You can enter custom command-line options here...</string>
              </property>
index 5de3565..b59b7f0 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>784</width>
+    <width>800</width>
     <height>384</height>
    </rect>
   </property>
index 375b675..16091a3 100644 (file)
@@ -9,8 +9,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>375</width>
-    <height>171</height>
+    <width>378</width>
+    <height>193</height>
    </rect>
   </property>
   <property name="windowTitle">
      <layout class="QVBoxLayout" name="verticalLayout_2">
       <item>
        <layout class="QGridLayout" name="gridLayout">
-        <item row="1" column="1" colspan="2">
+        <item row="2" column="2" colspan="2">
          <widget class="QLabel" name="labelJobCount">
           <property name="enabled">
            <bool>false</bool>
           </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">
            <string>Maximum number of running jobs:</string>
           </property>
          </widget>
         </item>
-        <item row="1" column="3">
+        <item row="2" column="4">
          <widget class="QSpinBox" name="spinBoxJobCount">
           <property name="enabled">
            <bool>false</bool>
@@ -55,6 +58,9 @@
             <height>0</height>
            </size>
           </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">
            <number>1</number>
           </property>
           </property>
          </widget>
         </item>
-        <item row="0" column="5" rowspan="2">
+        <item row="2" column="5">
+         <spacer name="horizontalSpacer_4">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>0</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <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>1024</width>
+            <width>12</width>
             <height>20</height>
            </size>
           </property>
          </spacer>
         </item>
-        <item row="0" column="0" rowspan="2">
+        <item row="1" column="0" rowspan="4">
          <spacer name="horizontalSpacer_2">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
          </spacer>
         </item>
-        <item row="1" column="4">
-         <spacer name="horizontalSpacer_4">
+        <item row="3" column="1" colspan="5">
+         <spacer name="verticalSpacer">
           <property name="orientation">
-           <enum>Qt::Horizontal</enum>
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeType">
+           <enum>QSizePolicy::Fixed</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
-            <width>0</width>
-            <height>20</height>
+            <width>20</width>
+            <height>8</height>
            </size>
           </property>
          </spacer>
         </item>
-        <item row="0" column="1" colspan="4">
-         <widget class="QCheckBox" name="checkRunNextJob">
+        <item row="4" column="1">
+         <widget class="QCheckBox" name="checkShutdownComputer">
           <property name="text">
-           <string>Automatically launch next job when a running job completes</string>
+           <string/>
+          </property>
+         </widget>
+        </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>
       </item>
      </layout>
diff --git a/res/buttons/power_off.png b/res/buttons/power_off.png
new file mode 100644 (file)
index 0000000..27661dc
Binary files /dev/null and b/res/buttons/power_off.png differ
diff --git a/res/buttons/power_on.png b/res/buttons/power_on.png
new file mode 100644 (file)
index 0000000..5e41522
Binary files /dev/null and b/res/buttons/power_on.png differ
index 9c2b219..6f13024 100644 (file)
@@ -24,6 +24,8 @@
     <file>buttons/pause.png</file>
     <file>buttons/play.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/trash.png</file>
     <file>buttons/world_link.png</file>
diff --git a/res/sounds/beep.wav b/res/sounds/beep.wav
new file mode 100644 (file)
index 0000000..2c740dd
Binary files /dev/null and b/res/sounds/beep.wav differ
diff --git a/res/sounds/beep2.wav b/res/sounds/beep2.wav
new file mode 100644 (file)
index 0000000..3be5e9f
Binary files /dev/null and b/res/sounds/beep2.wav differ
diff --git a/res/sounds/shutdown.wav b/res/sounds/shutdown.wav
new file mode 100644 (file)
index 0000000..6bfb8d6
Binary files /dev/null and b/res/sounds/shutdown.wav differ
index 6d2c7dd..a8f4ef1 100644 (file)
@@ -761,6 +761,33 @@ bool x264_init_qt(int argc, char* argv[])
 }
 
 /*
+ * 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)
  */
 static bool x264_check_for_debugger(void)
index cf1ac03..84cdd76 100644 (file)
@@ -102,5 +102,6 @@ const char *x264_version_arch(void);
 void x264_init_console(int argc, char* argv[]);
 bool x264_init_qt(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);
 void x264_finalization(void);
index 21a6247..38d2544 100644 (file)
@@ -22,6 +22,7 @@
 #include "model_jobList.h"
 #include "global.h"
 #include "thread_encode.h"
+#include "model_options.h"
 
 #include <QIcon>
 #include <QFileInfo>
@@ -227,9 +228,27 @@ QModelIndex JobListModel::insertJob(EncodeThread *thread)
        {
                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;
-       QString jobName = QFileInfo(thread->sourceFileName()).completeBaseName();
+       QString jobName = QString("%1 [%2]").arg(QFileInfo(thread->sourceFileName()).completeBaseName(), config);
 
        forever
        {
@@ -244,7 +263,7 @@ QModelIndex JobListModel::insertJob(EncodeThread *thread)
                }
                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;
                }
                break;
index ca52f9c..50c0694 100644 (file)
Binary files a/src/resource.h and b/src/resource.h differ
index f21421f..60cd7d9 100644 (file)
@@ -47,11 +47,13 @@ QMutex EncodeThread::m_mutex_startProcess;
        { \
                log("\nPROCESS ABORTED BY USER !!!"); \
                setStatus(JobStatus_Aborted); \
+               if(QFileInfo(indexFile).exists()) QFile::remove(indexFile); \
                return; \
        } \
        else if(!(OK_FLAG)) \
        { \
                setStatus(JobStatus_Failed); \
+               if(QFileInfo(indexFile).exists()) QFile::remove(indexFile); \
                return; \
        } \
 }
@@ -178,6 +180,7 @@ void EncodeThread::encode(void)
 
        //Use Avisynth?
        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
        log(tr("\n--- CHECK VERSION ---\n"));
@@ -242,27 +245,28 @@ void EncodeThread::encode(void)
                }
                
                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);
 
                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);
        }
        else
        {
                log(tr("\n--- ENCODING ---\n"));
-               ok = runEncodingPass(m_x64, usePipe, frames);
+               ok = runEncodingPass(m_x64, usePipe, frames, indexFile);
                CHECK_STATUS(m_abort, ok);
        }
 
        log(tr("\n--- DONE ---\n"));
+       if(QFileInfo(indexFile).exists()) QFile::remove(indexFile);
        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)));
        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;
        
@@ -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:");
        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;
 }
 
-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;
 
@@ -514,7 +518,6 @@ QStringList EncodeThread::buildCommandLine(bool usePipe, unsigned int frames, in
        }
        else
        {
-               QString indexFile = QString("%1/%2.ffindex").arg(QDir::tempPath(), m_jobId.toString());
                cmdLine << "--index" << QDir::toNativeSeparators(indexFile);
                cmdLine << QDir::toNativeSeparators(m_sourceFileName);
        }
index 3526947..5cd3b7d 100644 (file)
@@ -57,9 +57,10 @@ public:
        ~EncodeThread(void);
 
        QUuid getId(void) { return this->m_jobId; };
-       const QString &sourceFileName(void) { return this->m_sourceFileName; };
-       const QString &outputFileName(void) { return this->m_outputFileName; };
-
+       const QString &sourceFileName(void) { return this->m_sourceFileName; }
+       const QString &outputFileName(void) { return this->m_outputFileName; }
+       const OptionsModel *options(void) { return m_options; }
+       
        void pauseJob(void)
        {
                m_pause = true;
@@ -108,8 +109,8 @@ protected:
        
        //Encode functions
        void encode(void);
-       bool runEncodingPass(bool x64, bool usePipe, unsigned int frames, int pass = 0, const QString &passLogFile = QString());
-       QStringList buildCommandLine(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, const QString &indexFile, int pass = 0, const QString &passLogFile = QString());
        unsigned int checkVersionX264(bool x64, bool &modified);
        unsigned int checkVersionAvs2yuv(void);
        bool checkProperties(unsigned int &frames);
index df5493b..e6e7190 100644 (file)
@@ -26,6 +26,7 @@
 #include "model_options.h"
 #include "win_addJob.h"
 #include "win_preferences.h"
+#include "resource.h"
 
 #include <QDate>
 #include <QTimer>
@@ -36,8 +37,9 @@
 #include <QDir>
 #include <QLibrary>
 #include <QProcess>
+#include <QProgressDialog>
 
-//#include <Shellapi.h>
+#include <Mmsystem.h>
 
 const char *home_url = "http://mulder.brhack.net/";
 
@@ -154,13 +156,12 @@ void MainWindow::addButtonPressed(const QString &filePath, bool *ok)
        if(ok) *ok = false;
        
        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);
+
        int result = addDialog->exec();
-       
        if(result == QDialog::Accepted)
        {
-               
                EncodeThread *thrd = new EncodeThread
                (
                        addDialog->sourceFile(),
@@ -270,15 +271,16 @@ void MainWindow::jobChangedData(const QModelIndex &topLeft, const  QModelIndex &
        {
                for(int i = topLeft.row(); i <= bottomRight.row(); i++)
                {
-                       EncodeThread::JobStatus status =  m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
+                       EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
                        if(i == selected)
                        {
                                qDebug("Current job changed 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
        {
-               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)
                {
@@ -367,44 +369,96 @@ void MainWindow::showPreferences(void)
 
 void MainWindow::launchNextJob(void)
 {
+       qDebug("launchNextJob(void)");
+
+       
        const int rows = m_jobList->rowCount(QModelIndex());
-       unsigned int running = countRunningJobs();
 
-       if(running >= m_preferences.maxRunningJobCount)
+       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;
        }
 
-       bool first = true;
-       while(running < m_preferences.maxRunningJobCount)
+       int startIdx= jobsView->currentIndex().isValid() ? qBound(0, jobsView->currentIndex().row(), rows-1) : 0;
+
+       for(int i = 0; i < rows; i++)
        {
-               bool ok = false;
-               for(int i = 0; i < rows; i++)
+               int currentIdx = (i + startIdx) % rows;
+               EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(currentIdx, 0, QModelIndex()));
+               if(status == EncodeThread::JobStatus_Enqueued)
                {
-                       EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
-                       if(status == EncodeThread::JobStatus_Enqueued)
+                       if(m_jobList->startJob(m_jobList->index(currentIdx, 0, QModelIndex())))
                        {
-                               if(m_jobList->startJob(m_jobList->index(i, 0, QModelIndex())))
-                               {
-                                       if(first)
-                                       {
-                                               first = false;
-                                               jobsView->selectRow(i);
-                                       }
-                                       running++;
-                                       ok = true;
-                                       qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
-                                       break;
-                               }
+                               jobsView->selectRow(currentIdx);
+                               return;
                        }
                }
+       }
                
-               if(!ok)
+       qWarning("No enqueued jobs left!");
+}
+
+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())
                {
-                       qWarning("No enqueued jobs left!");
-                       break;
+                       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();
        }
 }
 
index 8fc5103..f6746e9 100644 (file)
@@ -72,11 +72,12 @@ private slots:
        void jobSelected(const QModelIndex & current, const QModelIndex & previous);
        void jobChangedData(const  QModelIndex &top, const  QModelIndex &bottom);
        void jobLogExtended(const QModelIndex & parent, int start, int end);
-       void launchNextJob(void);
+       void launchNextJob();
        void pauseButtonPressed(bool checked);
        void showAbout(void);
        void showPreferences(void);
        void showWebLink(void);
+       void shutdownComputer(void);
        void startButtonPressed(void);
        void updateLabel(void);
 };
index f09bf9c..e03d9bc 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QSettings>
 #include <QDesktopServices>
+#include <QMouseEvent>
 
 PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences)
 :
@@ -32,10 +33,10 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences)
 {
        setupUi(this);
        setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
-       setFixedSize(size());
+       setFixedSize(minimumSize());
 
-       HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
-       EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
+       labelRunNextJob->installEventFilter(this);
+       labelShutdownComputer->installEventFilter(this);
 
        m_preferences = preferences;
 }
@@ -46,17 +47,50 @@ PreferencesDialog::~PreferencesDialog(void)
 
 void PreferencesDialog::showEvent(QShowEvent *event)
 {
+       QDialog::showEvent(event);
+       
        while(checkRunNextJob->isChecked() != m_preferences->autoRunNextJob)
        {
                checkRunNextJob->click();
        }
-
+       while(checkShutdownComputer->isChecked() != m_preferences->shutdownComputer)
+       {
+               checkShutdownComputer->click();
+       }
        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)
 {
        m_preferences->autoRunNextJob = checkRunNextJob->isChecked();
+       m_preferences->shutdownComputer = checkShutdownComputer->isChecked();
        m_preferences->maxRunningJobCount = spinBoxJobCount->value();
 
        savePreferences(m_preferences);
@@ -71,6 +105,7 @@ void PreferencesDialog::loadPreferences(Preferences *preferences)
        settings.beginGroup("preferences");
        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->shutdownComputer = settings.value("shutdown_computer_on_completion", QVariant(false)).toBool();
 }
 
 void PreferencesDialog::savePreferences(Preferences *preferences)
@@ -80,6 +115,7 @@ void PreferencesDialog::savePreferences(Preferences *preferences)
 
        settings.beginGroup("preferences");
        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.sync();
 }
index aee5e44..59e5970 100644 (file)
@@ -32,6 +32,7 @@ public:
        {
                bool autoRunNextJob;
                unsigned int maxRunningJobCount;
+               bool shutdownComputer;
        }
        Preferences;
 
@@ -44,6 +45,7 @@ public:
 protected:
        virtual void accept(void);
        virtual void showEvent(QShowEvent *event);
+       virtual bool eventFilter(QObject *o, QEvent *e);
 
 private:
        Preferences *m_preferences;
index b5869ba..2c8f572 100644 (file)
Binary files a/x264_launcher.rc and b/x264_launcher.rc differ
index ba56db3..134f490 100644 (file)
@@ -60,7 +60,7 @@
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <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>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -88,7 +88,7 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <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>
     </Link>
     <PreBuildEvent>