Explicitly handle WM_QUERYENDSESSION and WM_ENDSESSION messages to make sure LameXP won't block Windows from shutting down.
This commit is contained in:
parent
a96237e6b2
commit
9a9d2e6819
@ -30,7 +30,7 @@
|
||||
#define VER_LAMEXP_MINOR_LO 4
|
||||
#define VER_LAMEXP_TYPE Alpha
|
||||
#define VER_LAMEXP_PATCH 12
|
||||
#define VER_LAMEXP_BUILD 845
|
||||
#define VER_LAMEXP_BUILD 851
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Tool versions (minimum expected versions!)
|
||||
|
@ -276,6 +276,12 @@ void ProcessingDialog::showEvent(QShowEvent *event)
|
||||
|
||||
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();
|
||||
@ -423,7 +429,7 @@ void ProcessingDialog::doneEncoding(void)
|
||||
m_threadList.takeAt(index)->deleteLater();
|
||||
}
|
||||
|
||||
if(!m_pendingJobs.isEmpty() && !m_userAborted)
|
||||
if(!m_pendingJobs.isEmpty() && !m_userAborted && !lamexp_session_ending())
|
||||
{
|
||||
startNextJob();
|
||||
qDebug("Running jobs: %u", m_runningThreads);
|
||||
@ -439,14 +445,14 @@ void ProcessingDialog::doneEncoding(void)
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
qDebug("Running jobs: %u", m_runningThreads);
|
||||
|
||||
if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir())
|
||||
if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir() && !lamexp_session_ending())
|
||||
{
|
||||
SET_PROGRESS_TEXT(tr("Creating the playlist file, please wait..."));
|
||||
QApplication::processEvents();
|
||||
writePlayList();
|
||||
}
|
||||
|
||||
if(m_userAborted)
|
||||
if(m_userAborted || lamexp_session_ending())
|
||||
{
|
||||
CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFF3BA"));
|
||||
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
|
||||
@ -455,7 +461,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() && !lamexp_session_ending())
|
||||
{
|
||||
PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -506,7 +515,11 @@ void ProcessingDialog::doneEncoding(void)
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
if(!m_userAborted && checkBox_shutdownComputer->isChecked())
|
||||
if(lamexp_session_ending())
|
||||
{
|
||||
accept();
|
||||
}
|
||||
else if(!m_userAborted && checkBox_shutdownComputer->isChecked())
|
||||
{
|
||||
if(shutdownComputer())
|
||||
{
|
||||
|
@ -226,6 +226,8 @@ static QMutex g_lamexp_message_mutex;
|
||||
//Main thread ID
|
||||
static const DWORD g_main_thread_id = GetCurrentThreadId();
|
||||
|
||||
//Session ending flag
|
||||
static bool g_sessionIsEnding = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GLOBAL FUNCTIONS
|
||||
@ -788,6 +790,47 @@ QIcon lamexp_app_icon(const QDate *date, const QTime *time)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Qt event filter
|
||||
*/
|
||||
static bool lamexp_event_filter(void *message, long *result)
|
||||
{
|
||||
switch(reinterpret_cast<MSG*>(message)->message)
|
||||
{
|
||||
case WM_QUERYENDSESSION:
|
||||
qWarning("WM_QUERYENDSESSION message received!");
|
||||
if(!g_sessionIsEnding)
|
||||
{
|
||||
g_sessionIsEnding = true;
|
||||
if(QApplication *app = reinterpret_cast<QApplication*>(QApplication::instance()))
|
||||
{
|
||||
for(int i = 0; i < 128; i++)
|
||||
{
|
||||
app->closeAllWindows();
|
||||
app->processEvents();
|
||||
Sleep(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
*result = TRUE;
|
||||
return true;
|
||||
case WM_ENDSESSION:
|
||||
qWarning("WM_ENDSESSION message received!");
|
||||
if(reinterpret_cast<MSG*>(message)->wParam == TRUE)
|
||||
{
|
||||
if(QApplication *app = reinterpret_cast<QApplication*>(QApplication::instance()))
|
||||
{
|
||||
app->quit();
|
||||
}
|
||||
}
|
||||
*result = 0;
|
||||
return true;
|
||||
default:
|
||||
/*ignore this message and let Qt handle it*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for process elevation
|
||||
*/
|
||||
@ -929,7 +972,8 @@ bool lamexp_init_qt(int argc, char* argv[])
|
||||
application->setOrganizationName("LoRd_MuldeR");
|
||||
application->setOrganizationDomain("mulder.at.gg");
|
||||
application->setWindowIcon(lamexp_app_icon());
|
||||
|
||||
application->setEventFilter(lamexp_event_filter);
|
||||
|
||||
//Set text Codec for locale
|
||||
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
@ -1770,6 +1814,14 @@ QStringList lamexp_available_codepages(bool noAliases)
|
||||
return codecList;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the session is about to end
|
||||
*/
|
||||
bool lamexp_session_ending(void)
|
||||
{
|
||||
return g_sessionIsEnding;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finalization function (final clean-up)
|
||||
*/
|
||||
|
@ -111,6 +111,7 @@ bool lamexp_portable_mode(void);
|
||||
bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout = 30, const bool forceShutdown = true, const bool hibernate = false);
|
||||
bool lamexp_is_hibernation_supported(void);
|
||||
QIcon lamexp_app_icon(const QDate *date = NULL, const QTime *time = NULL);
|
||||
bool lamexp_session_ending(void);
|
||||
|
||||
//Translation support
|
||||
QStringList lamexp_query_translations(void);
|
||||
|
@ -153,7 +153,7 @@ static int lamexp_main(int argc, char* argv[])
|
||||
MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);
|
||||
|
||||
//Main application loop
|
||||
while(bAccepted && (iShutdown <= shutdownFlag_None))
|
||||
while(bAccepted && (iShutdown <= shutdownFlag_None) && (!lamexp_session_ending()))
|
||||
{
|
||||
//Show main window
|
||||
poMainWindow->show();
|
||||
@ -161,7 +161,7 @@ static int lamexp_main(int argc, char* argv[])
|
||||
bAccepted = poMainWindow->isAccepted();
|
||||
|
||||
//Show processing dialog
|
||||
if(bAccepted && fileListModel->rowCount() > 0)
|
||||
if(bAccepted && (fileListModel->rowCount() > 0) && (!lamexp_session_ending()))
|
||||
{
|
||||
ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
|
||||
processingDialog->exec();
|
||||
|
Loading…
x
Reference in New Issue
Block a user