///////////////////////////////////////////////////////////////////////////////
// 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
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);
m_succeededJobs.clear();
m_failedJobs.clear();
m_userAborted = false;
+ m_forcedAbort = false;
m_timerStart = 0I64;
}
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)
{
- if(lamexp_session_ending() && !m_userAborted)
- {
- qWarning("Computer is shutting down, LameXP will abort and exit!");
- abortEncoding();
- }
-
if(!button_closeDialog->isEnabled())
{
event->ignore();
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);
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));
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));
}
}
}
-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++)
m_threadList.takeAt(index)->deleteLater();
}
- if(!m_pendingJobs.isEmpty() && !m_userAborted && !lamexp_session_ending())
+ if(!m_pendingJobs.isEmpty() && !m_userAborted)
{
startNextJob();
qDebug("Running jobs: %u", m_runningThreads);
QApplication::setOverrideCursor(Qt::WaitCursor);
qDebug("Running jobs: %u", m_runningThreads);
- if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir() && !lamexp_session_ending())
+ if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir())
{
SET_PROGRESS_TEXT(tr("Creating the playlist file, please wait..."));
QApplication::processEvents();
writePlayList();
}
- if(m_userAborted || lamexp_session_ending())
+ if(m_userAborted)
{
CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFF3BA"));
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
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() && !lamexp_session_ending())
+ if(m_settings->soundsEnabled() && !m_forcedAbort)
{
PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
}
QApplication::restoreOverrideCursor();
- if(lamexp_session_ending())
- {
- accept();
- }
- else if(!m_userAborted && checkBox_shutdownComputer->isChecked())
+ if(!m_userAborted && checkBox_shutdownComputer->isChecked())
{
if(shutdownComputer())
{
{
if(reason == QSystemTrayIcon::DoubleClick)
{
- SetForegroundWindow(this->winId());
+ SetForegroundWindow(reinterpret_cast<HWND>(this->winId()));
}
}