OSDN Git Service

Extinguished some remaining uses of argv[] or QApplication::arguments().
[lamexp/LameXP.git] / src / Dialog_Processing.cpp
index 21ae249..d73b199 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -107,12 +107,16 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        m_shutdownFlag(shutdownFlag_None),
        m_diskObserver(NULL),
        m_cpuObserver(NULL),
-       m_ramObserver(NULL)
+       m_ramObserver(NULL),
+       m_firstShow(true)
 {
        //Init the dialog, from the .ui file
        setupUi(this);
        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
        
+       //Update header icon
+       label_headerIcon->setPixmap(lamexp_app_icon().pixmap(label_headerIcon->size()));
+       
        //Setup version info
        label_versionInfo->setText(QString().sprintf("v%d.%02d %s (Build %d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build()));
        label_versionInfo->installEventFilter(this);
@@ -182,6 +186,7 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        m_succeededJobs.clear();
        m_failedJobs.clear();
        m_userAborted = false;
+       m_forcedAbort = false;
        m_timerStart = 0I64;
 }
 
@@ -252,23 +257,29 @@ ProcessingDialog::~ProcessingDialog(void)
 
 void ProcessingDialog::showEvent(QShowEvent *event)
 {
-       static const char *NA = " N/A";
+       QDialog::showEvent(event);
 
-       setCloseButtonEnabled(false);
-       button_closeDialog->setEnabled(false);
-       button_AbortProcess->setEnabled(false);
-       m_systemTray->setVisible(true);
-       
-       if(!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS))
+       if(m_firstShow)
        {
-               SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
-       }
+               static const char *NA = " N/A";
+       
+               setCloseButtonEnabled(false);
+               button_closeDialog->setEnabled(false);
+               button_AbortProcess->setEnabled(false);
+               m_systemTray->setVisible(true);
+       
+               if(!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS))
+               {
+                       SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
+               }
 
-       label_cpu->setText(NA);
-       label_disk->setText(NA);
-       label_ram->setText(NA);
+               label_cpu->setText(NA);
+               label_disk->setText(NA);
+               label_ram->setText(NA);
 
-       QTimer::singleShot(1000, this, SLOT(initEncoding()));
+               QTimer::singleShot(1000, this, SLOT(initEncoding()));
+               m_firstShow = false;
+       }
 }
 
 void ProcessingDialog::closeEvent(QCloseEvent *event)
@@ -312,6 +323,31 @@ bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event)
        return false;
 }
 
+bool ProcessingDialog::event(QEvent *e)
+{
+       switch(e->type())
+       {
+       case lamexp_event_queryendsession:
+               qWarning("System is shutting down, preparing to abort...");
+               if(!m_userAborted) abortEncoding(true);
+               return true;
+       case lamexp_event_endsession:
+               qWarning("System is shutting down, encoding will be aborted now...");
+               if(isVisible())
+               {
+                       while(!close())
+                       {
+                               if(!m_userAborted) abortEncoding(true);
+                               QApplication::processEvents(QEventLoop::WaitForMoreEvents & QEventLoop::ExcludeUserInputEvents);
+                       }
+               }
+               m_pendingJobs.clear();
+               return true;
+       default:
+               return QDialog::event(e);
+       }
+}
+
 bool ProcessingDialog::winEvent(MSG *message, long *result)
 {
        return WinSevenTaskbar::handleWinEvent(message, result);
@@ -323,12 +359,15 @@ bool ProcessingDialog::winEvent(MSG *message, long *result)
 
 void ProcessingDialog::initEncoding(void)
 {
+       qDebug("Initializing encoding process...");
+       
        m_runningThreads = 0;
        m_currentFile = 0;
        m_allJobs.clear();
        m_succeededJobs.clear();
        m_failedJobs.clear();
        m_userAborted = false;
+       m_forcedAbort = false;
        m_playList.clear();
        
        CHANGE_BACKGROUND_COLOR(frame_header, QColor(Qt::white));
@@ -368,7 +407,7 @@ void ProcessingDialog::initEncoding(void)
        unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES);
        if(maximumInstances < 1)
        {
-               lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features();
+               lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(lamexp_arguments());
                maximumInstances = cores2instances(qBound(1, cpuFeatures.count, 64));
        }
 
@@ -390,11 +429,11 @@ void ProcessingDialog::initEncoding(void)
        }
 }
 
-void ProcessingDialog::abortEncoding(void)
+void ProcessingDialog::abortEncoding(bool force)
 {
        m_userAborted = true;
+       if(force) m_forcedAbort = true;
        button_AbortProcess->setEnabled(false);
-       
        SET_PROGRESS_TEXT(tr("Aborted! Waiting for running jobs to terminate..."));
 
        for(int i = 0; i < m_threadList.count(); i++)
@@ -452,7 +491,10 @@ void ProcessingDialog::doneEncoding(void)
                m_systemTray->showMessage(tr("LameXP - Aborted"), tr("Process was aborted by the user."), QSystemTrayIcon::Warning);
                m_systemTray->setIcon(QIcon(":/icons/cd_delete.png"));
                QApplication::processEvents();
-               if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
+               if(m_settings->soundsEnabled() && !m_forcedAbort)
+               {
+                       PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
+               }
        }
        else
        {
@@ -546,7 +588,7 @@ void ProcessingDialog::logViewDoubleClicked(const QModelIndex &index)
                }
                else
                {
-                       MessageBeep(MB_ICONWARNING);
+                       QMessageBox::information(this, windowTitle(), m_progressModel->data(m_progressModel->index(index.row(), 0)).toString());
                }
        }
        else
@@ -929,7 +971,7 @@ void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason rea
 {
        if(reason == QSystemTrayIcon::DoubleClick)
        {
-               SetForegroundWindow(this->winId());
+               SetForegroundWindow(reinterpret_cast<HWND>(this->winId()));
        }
 }