OSDN Git Service

Added an option to shutdown the computer as soon as all files are completed.
authorlordmulder <mulder2@gmx.de>
Fri, 18 Mar 2011 00:12:17 +0000 (01:12 +0100)
committerlordmulder <mulder2@gmx.de>
Fri, 18 Mar 2011 00:12:17 +0000 (01:12 +0100)
22 files changed:
LameXP.rc
LameXP.vcproj
doc/Changelog.html
doc/FAQ.html
etc/Translation/Blank.ts
etc/Translation/LameXP_DE.ts
etc/Translation/LameXP_ES.ts
etc/Translation/LameXP_FR.ts
etc/Translation/LameXP_IT.ts
etc/Translation/LameXP_RU.ts
etc/Translation/LameXP_UK.ts
gui/ProcessingDialog.ui
res/Icons.qrc
res/localization/LameXP_DE.qm
res/sounds/shutdown.wav [new file with mode: 0644]
src/Config.h
src/Dialog_Processing.cpp
src/Dialog_Processing.h
src/Global.cpp
src/Global.h
src/Main.cpp
src/Resource.h

index 9adcef2..2b6612d 100644 (file)
--- a/LameXP.rc
+++ b/LameXP.rc
@@ -111,6 +111,7 @@ IDR_WAVE_ERROR          WAVE                    "res\\sounds\\error.wav"
 IDR_WAVE_ABORTED        WAVE                    "res\\sounds\\aborted.wav"
 IDR_WAVE_WHAMMY         WAVE                    "res\\sounds\\whammy.wav"
 IDR_WAVE_WOOHOO         WAVE                    "res\\sounds\\woohoo.wav"
+IDR_WAVE_SHUTDOWN       WAVE                    "res\\sounds\\shutdown.wav"
 
 /////////////////////////////////////////////////////////////////////////////
 //
index ef0c66f..7fdf474 100644 (file)
                                AdditionalOptions="&quot;/MANIFESTDEPENDENCY:type=&apos;win32&apos; name=&apos;Microsoft.Windows.Common-Controls&apos; version=&apos;6.0.0.0&apos; publicKeyToken=&apos;6595b64144ccf1df&apos; language=&apos;*&apos; processorArchitecture=&apos;*&apos;&quot;"
                                AdditionalDependencies="qtmain.lib QtCore4.lib QtGui4.lib Winmm.lib Shlwapi.lib"
                                ShowProgress="2"
+                               Version=""
                                LinkIncremental="1"
                                AdditionalLibraryDirectories="&quot;$(QTDIR)\lib&quot;;&quot;$(QTDIR)\plugins\imageformats&quot;"
                                GenerateDebugInformation="false"
                                AdditionalOptions="&quot;/MANIFESTDEPENDENCY:type=&apos;win32&apos; name=&apos;Microsoft.Windows.Common-Controls&apos; version=&apos;6.0.0.0&apos; publicKeyToken=&apos;6595b64144ccf1df&apos; language=&apos;*&apos; processorArchitecture=&apos;*&apos;&quot;"
                                AdditionalDependencies="qtmain.lib QtCore.lib QtGui.lib QtSvg.lib qsvg.lib qico.lib Winmm.lib imm32.lib ws2_32.lib Shlwapi.lib"
                                ShowProgress="2"
-                               Version=""
                                LinkIncremental="1"
                                AdditionalLibraryDirectories="&quot;$(SolutionDir)\etc\Prerequisites\qt4_static\lib&quot;;&quot;$(SolutionDir)\etc\Prerequisites\qt4_static\plugins\imageformats&quot;"
                                IgnoreDefaultLibraryNames=""
index 0d3f6f3..81b1e4e 100644 (file)
@@ -10,6 +10,7 @@
 <a name="4.01">Changes between v4.00 and v4.01:</a><br><ul>
 <li>Added an option to manually specify the number of parallel instances
 <li>Added an option to select a user-defined TEMP directory
+<li>Added an option to shutdown the computer as soon as all files are completed
 <li>Updated Qt runtime libraries to v4.7.2
 <li>Updated LAME encoder to v3.99.0.14 (2011-02-28), compiled with ICL 12.0.2
 <li>Updated Vorbis encoder to v2.87 using aoTuV Beta-6.02 (2011-02-28), compiled with ICL 11.1 and MSVC 9.0
index 2bd4cc1..5611e30 100644 (file)
@@ -317,8 +317,7 @@ LameXP setup/update program on a platform that is NOT supported, such as Windows
 Millennium Edition or Windows NT 4.0. There is nothing you can do about that, except for updating to a less<br>
 antiquated OS. Running an outdated/unsupported OS is a severe security risk anyway!<br>
 <br>
-Remark: Executable files compiled with Microsoft Visual Studio 2005 (or later) won't load on Windows 9x.<br>
-<br><br>
+Remark: Executable files compiled with Microsoft Visual Studio 2005 (or later) won't load on Windows 9x.<br><br>
 
 <br><br>
 
index 1b81163..401a901 100644 (file)
         <translation type="unfinished"></translation>
     </message>
     <message>
+        <source>Shutdown the computer as soon as all files have been converted</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
         <source>Abort</source>
         <translation type="unfinished"></translation>
     </message>
         <source>The playlist file could not be created:</source>
         <translation type="unfinished"></translation>
     </message>
+    <message>
+        <source>Warning: Computer will shutdown in %1 seconds...</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Cancel Shutdown</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>ProgressModel</name>
index 53b761f..92dc332 100644 (file)
         <source>Browse Output File Location</source>
         <translation>Ausgabedatei suchen</translation>
     </message>
+    <message>
+        <source>Shutdown the computer as soon as all files have been converted</source>
+        <translation>Computer herunterfahren sobald alle Dateien fertiggestellt sind</translation>
+    </message>
+    <message>
+        <source>Warning: Computer will shutdown in %1 seconds...</source>
+        <translation>Achtung: Computer wird in %1 Sekunden heruntergefahren...</translation>
+    </message>
+    <message>
+        <source>Cancel Shutdown</source>
+        <translation>Herunterfahren abbrechen</translation>
+    </message>
 </context>
 <context>
     <name>ProgressModel</name>
index ed9fab1..8967be7 100644 (file)
         <source>Browse Output File Location</source>
         <translation>Navegar hasta la ubicación del archivo de salida</translation>
     </message>
+    <message>
+        <source>Shutdown the computer as soon as all files have been converted</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Warning: Computer will shutdown in %1 seconds...</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Cancel Shutdown</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>ProgressModel</name>
index 6e14050..88a205f 100644 (file)
@@ -1553,6 +1553,18 @@ Sélection automatique (par défaut)</translation>
         <source>Browse Output File Location</source>
         <translation>Rechercher l&apos;emplacement du fichier de sortie</translation>
     </message>
+    <message>
+        <source>Shutdown the computer as soon as all files have been converted</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Warning: Computer will shutdown in %1 seconds...</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Cancel Shutdown</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>ProgressModel</name>
index 6a3293a..37ab152 100644 (file)
         <source>Browse Output File Location</source>
         <translation type="unfinished"></translation>
     </message>
+    <message>
+        <source>Shutdown the computer as soon as all files have been converted</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Warning: Computer will shutdown in %1 seconds...</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Cancel Shutdown</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>ProgressModel</name>
index 6b9d7a6..13df047 100644 (file)
         <source>The playlist file could not be created:</source>
         <translation type="unfinished">Плэйлист неможет быть создан:</translation>
     </message>
+    <message>
+        <source>Shutdown the computer as soon as all files have been converted</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Warning: Computer will shutdown in %1 seconds...</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Cancel Shutdown</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>ProgressModel</name>
index a7c4974..113fd94 100644 (file)
         <source>Browse Output File Location</source>
         <translation type="unfinished"></translation>
     </message>
+    <message>
+        <source>Shutdown the computer as soon as all files have been converted</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Warning: Computer will shutdown in %1 seconds...</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Cancel Shutdown</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>ProgressModel</name>
index 1f37b2f..5225d7f 100644 (file)
         </widget>
        </item>
        <item>
+        <widget class="QCheckBox" name="checkBox_shutdownComputer">
+         <property name="text">
+          <string>Shutdown the computer as soon as all files have been converted</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QFrame" name="frame">
+         <property name="frameShape">
+          <enum>QFrame::HLine</enum>
+         </property>
+         <property name="frameShadow">
+          <enum>QFrame::Sunken</enum>
+         </property>
+        </widget>
+       </item>
+       <item>
         <layout class="QHBoxLayout" name="layout_horizontal">
          <item>
           <widget class="QLabel" name="label_versionInfo">
   <include location="../res/Images.qrc"/>
   <include location="../res/Icons.qrc"/>
   <include location="../res/Images.qrc"/>
+  <include location="../res/Icons.qrc"/>
+  <include location="../res/Images.qrc"/>
+  <include location="../res/Icons.qrc"/>
+  <include location="../res/Images.qrc"/>
  </resources>
  <connections>
   <connection>
index ffa71e4..1d4e07f 100644 (file)
@@ -50,6 +50,7 @@
     <file>icons/house.png</file>
     <file>icons/hourglass.png</file>
     <file>icons/information.png</file>
+    <file>icons/lightning.png</file>
     <file>icons/media_play.png</file>
     <file>icons/money_dollar.png</file>
     <file>icons/monitor.png</file>
index fb86f81..97b6dec 100644 (file)
Binary files a/res/localization/LameXP_DE.qm and b/res/localization/LameXP_DE.qm differ
diff --git a/res/sounds/shutdown.wav b/res/sounds/shutdown.wav
new file mode 100644 (file)
index 0000000..ec64b4a
Binary files /dev/null and b/res/sounds/shutdown.wav differ
index 458b479..e39bc95 100644 (file)
@@ -25,8 +25,8 @@
 #define VER_LAMEXP_MAJOR                               4
 #define VER_LAMEXP_MINOR_HI                            0
 #define VER_LAMEXP_MINOR_LO                            1
-#define VER_LAMEXP_BUILD                               367
-#define VER_LAMEXP_SUFFIX                              Beta-8
+#define VER_LAMEXP_BUILD                               372
+#define VER_LAMEXP_SUFFIX                              Beta-9
 
 /*
  * Tools versions
index 9524dd6..e4dd2b0 100644 (file)
@@ -53,6 +53,7 @@
 #include <QMenu>
 #include <QSystemTrayIcon>
 #include <QProcess>
+#include <QProgressDialog>
 
 #include <Windows.h>
 
@@ -90,7 +91,8 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        QDialog(parent),
        m_systemTray(new QSystemTrayIcon(QIcon(":/icons/cd_go.png"), this)),
        m_settings(settings),
-       m_metaInfo(metaInfo)
+       m_metaInfo(metaInfo),
+       m_shutdownFlag(false)
 {
        //Init the dialog, from the .ui file
        setupUi(this);
@@ -269,6 +271,8 @@ void ProcessingDialog::initEncoding(void)
        button_closeDialog->setEnabled(false);
        button_AbortProcess->setEnabled(true);
        progressBar->setRange(0, m_pendingJobs.count());
+       checkBox_shutdownComputer->setEnabled(true);
+       checkBox_shutdownComputer->setChecked(false);
 
        WinSevenTaskbar::initTaskbar();
        WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
@@ -387,6 +391,7 @@ void ProcessingDialog::doneEncoding(void)
        setCloseButtonEnabled(true);
        button_closeDialog->setEnabled(true);
        button_AbortProcess->setEnabled(false);
+       checkBox_shutdownComputer->setEnabled(false);
 
        view_log->scrollToBottom();
        m_progressIndicator->stop();
@@ -394,6 +399,12 @@ void ProcessingDialog::doneEncoding(void)
        WinSevenTaskbar::setTaskbarProgress(this, progressBar->value(), progressBar->maximum());
 
        QApplication::restoreOverrideCursor();
+
+       if(!m_userAborted && checkBox_shutdownComputer->isChecked())
+       {
+               qWarning("Initiating shutdown sequence!");
+               shutdownComputer();
+       }
 }
 
 void ProcessingDialog::processFinished(const QUuid &jobId, const QString &outFileName, bool success)
@@ -699,3 +710,51 @@ void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason rea
                SetForegroundWindow(this->winId());
        }
 }
+
+void ProcessingDialog::shutdownComputer(void)
+{
+       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..."));
+       
+       QProgressDialog progressDialog(text.arg(iTimeout), tr("Cancel Shutdown"), 0, iTimeout + 1, this, flags);
+       progressDialog.setModal(true);
+       progressDialog.setAutoClose(false);
+       progressDialog.setAutoReset(false);
+       progressDialog.setWindowIcon(QIcon(":/icons/lightning.png"));
+       progressDialog.show();
+       
+       QApplication::processEvents();
+
+       if(m_settings->soundsEnabled())
+       {
+               PlaySound(MAKEINTRESOURCE(IDR_WAVE_SHUTDOWN), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
+       }
+
+       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()) break;
+               progressDialog.setValue(i+1);
+               progressDialog.setLabelText(text.arg(iTimeout-i));
+               if(iTimeout-i == 3) progressDialog.setCancelButtonText(QString());
+               QApplication::processEvents();
+               Beep(4000, (i < iTimeout) ? 100 : 1000);
+       }
+       
+       if(!progressDialog.wasCanceled())
+       {
+               m_shutdownFlag = true;
+               accept();
+       }
+
+       progressDialog.close();
+}
index 8a16052..96647b9 100644 (file)
@@ -41,6 +41,8 @@ class ProcessingDialog : public QDialog, private Ui::ProcessingDialog
 public:
        ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent = 0);
        ~ProcessingDialog(void);
+       
+       bool getShutdownFlag(void) { return m_shutdownFlag; }
 
 private slots:
        void initEncoding(void);
@@ -64,6 +66,7 @@ private:
        void startNextJob(void);
        AudioFileModel updateMetaInfo(const AudioFileModel &audioFile);
        void writePlayList(void);
+       void shutdownComputer(void);
        
        QList<AudioFileModel> m_pendingJobs;
        SettingsModel *m_settings;
@@ -80,4 +83,5 @@ private:
        QList<QUuid> m_failedJobs;
        bool m_userAborted;
        QSystemTrayIcon *m_systemTray;
+       bool m_shutdownFlag;
 };
index 06710c1..98119d8 100644 (file)
@@ -690,6 +690,18 @@ bool lamexp_init_qt(int argc, char* argv[])
                }
        }
 
+       //Update console icon, if a console is attached
+       if(g_lamexp_console_attached)
+       {
+               typedef DWORD (__stdcall *SetConsoleIconFun)(HICON);
+               QLibrary kernel32("kernel32.dll");
+               SetConsoleIconFun SetConsoleIconPtr = (SetConsoleIconFun) kernel32.resolve("SetConsoleIcon");
+               if(SetConsoleIconPtr)
+               {
+                       SetConsoleIconPtr(QIcon(":/icons/sound.png").pixmap(16, 16).toWinHICON());
+               }
+       }
+
        //Done
        qt_initialized = true;
        return true;
@@ -1306,6 +1318,30 @@ __int64 lamexp_free_diskspace(const QString &path)
        }
 }
 
+bool lamexp_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, FALSE, reason);
+                       }
+               }
+       }
+       
+       return false;
+}
+
 /*
  * Finalization function (final clean-up)
  */
index 99ba52a..cb3784e 100644 (file)
@@ -94,6 +94,7 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
 void lamexp_ipc_send(unsigned int command, const char* message);
 lamexp_cpu_t lamexp_detect_cpu_features(void);
 bool lamexp_portable_mode(void);
+bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout = 30, const bool forceShutdown = true);
 
 //Translation support
 QStringList lamexp_query_translations(void);
index 3c8b63e..060de10 100644 (file)
@@ -47,6 +47,7 @@ int lamexp_main(int argc, char* argv[])
 {
        int iResult = -1;
        bool bAccepted = true;
+       bool bShutdown = false;
        
        //Init console
        lamexp_init_console(argc, argv);
@@ -132,7 +133,7 @@ int lamexp_main(int argc, char* argv[])
        MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);
        
        //Main application loop
-       while(bAccepted)
+       while(bAccepted && !bShutdown)
        {
                //Show main window
                poMainWindow->show();
@@ -144,6 +145,7 @@ int lamexp_main(int argc, char* argv[])
                {
                        ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
                        processingDialog->exec();
+                       bShutdown = processingDialog->getShutdownFlag();
                        LAMEXP_DELETE(processingDialog);
                }
        }
@@ -157,6 +159,15 @@ int lamexp_main(int argc, char* argv[])
        //Final clean-up
        qDebug("Shutting down, please wait...\n");
 
+       //Shotdown computer
+       if(bShutdown)
+       {
+               if(!lamexp_shutdown_computer("LameXP planned computer shutdown!", 12))
+               {
+                       QMessageBox messageBox(QMessageBox::Critical, "LameXP", "Sorry, LameXP was unable to shutdown your computer!", QMessageBox::NoButton, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
+               }
+       }
+
        //Terminate
        return iResult;
 }
index a2379d9..0572fac 100644 (file)
@@ -32,6 +32,7 @@
 #define IDR_WAVE_ABORTED                669
 #define IDR_WAVE_WHAMMY                 670
 #define IDR_WAVE_WOOHOO                 671
+#define IDR_WAVE_SHUTDOWN               672
 
 /*
  * Next default values for new objects