Some updates to the updater dialog.

This commit is contained in:
LoRd_MuldeR 2013-12-13 15:25:36 +01:00
parent c78a3c4990
commit 4b9a244f24
6 changed files with 107 additions and 27 deletions

View File

@ -1715,6 +1715,18 @@ unsigned int x264_process_id(void)
return GetCurrentProcessId(); return GetCurrentProcessId();
} }
/*
* Current process ID
*/
unsigned int x264_process_id(QProcess &process)
{
if(Q_PID pid = process.pid())
{
return pid->dwProcessId;
}
return NULL;
}
/* /*
* Make a window blink (to draw user's attention) * Make a window blink (to draw user's attention)
*/ */
@ -1766,14 +1778,54 @@ void x264_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay
} }
} }
/*
* Bring the specifed window to the front
*/
static bool x264_bring_to_front(const HWND hWin)
{
if(hWin)
{
const bool ret = (SetForegroundWindow(hWin) != FALSE);
SwitchToThisWindow(hWin, TRUE);
return ret;
}
return false;
}
/* /*
* Bring the specifed window to the front * Bring the specifed window to the front
*/ */
bool x264_bring_to_front(const QWidget *win) bool x264_bring_to_front(const QWidget *win)
{ {
const bool ret = (SetForegroundWindow(win->winId()) == TRUE); if(win)
SwitchToThisWindow(win->winId(), TRUE); {
return ret; return x264_bring_to_front(win->winId());
}
return false;
}
/*
* Bring window of the specifed process to the front (callback)
*/
static BOOL CALLBACK x264_bring_process_to_front_helper(HWND hwnd, LPARAM lParam)
{
DWORD processId = *reinterpret_cast<WORD*>(lParam);
DWORD windowProcessId = NULL;
GetWindowThreadProcessId(hwnd, &windowProcessId);
if(windowProcessId == processId)
{
x264_bring_to_front(hwnd);
return FALSE;
}
return TRUE;
}
/*
* Bring window of the specifed process to the front
*/
bool x264_bring_process_to_front(const unsigned long pid)
{
return EnumWindows(x264_bring_process_to_front_helper, reinterpret_cast<LPARAM>(&pid)) == TRUE;
} }
/* /*

View File

@ -120,6 +120,7 @@ extern const x264_os_version_t x264_winver_win81;
const QStringList &x264_arguments(void); const QStringList &x264_arguments(void);
bool x264_beep(int beepType); bool x264_beep(int beepType);
void x264_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay); void x264_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay);
bool x264_bring_process_to_front(const unsigned long pid);
bool x264_bring_to_front(const QWidget *win); bool x264_bring_to_front(const QWidget *win);
bool x264_change_process_priority(const QProcess *proc, const int priority); bool x264_change_process_priority(const QProcess *proc, const int priority);
bool x264_change_process_priority(const int priority); bool x264_change_process_priority(const int priority);
@ -143,6 +144,7 @@ QString x264_path2ansi(const QString &longPath, bool makeLowercase = false);
bool x264_play_sound(const unsigned short uiSoundIdx, const bool bAsync, const wchar_t *alias = NULL); bool x264_play_sound(const unsigned short uiSoundIdx, const bool bAsync, const wchar_t *alias = NULL);
bool x264_portable(void); bool x264_portable(void);
unsigned int x264_process_id(void); unsigned int x264_process_id(void);
unsigned int x264_process_id(QProcess &process);
QString x264_query_reg_string(const bool bUser, const QString &path, const QString &name); QString x264_query_reg_string(const bool bUser, const QString &path, const QString &name);
unsigned int x264_rand(void); unsigned int x264_rand(void);
QString x264_rand_str(const bool bLong = false); QString x264_rand_str(const bool bLong = false);

View File

@ -36,7 +36,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static const char *header_id = "!Update"; static const char *header_id = "!Update";
static const char *section_id = "x264_launcher"; static const char *section_id = "Simple x264 Launcher";
static const char *mirror_url_postfix[] = static const char *mirror_url_postfix[] =
{ {

View File

@ -985,6 +985,7 @@ void MainWindow::checkUpdates(void)
X264_DELETE(updater); X264_DELETE(updater);
qWarning("Exitting to install update..."); qWarning("Exitting to install update...");
close(); close();
QApplication::quit();
} }
X264_DELETE(updater); X264_DELETE(updater);

View File

@ -49,6 +49,7 @@
ui->labelLoadingRight->setVisible((FLAG)); \ ui->labelLoadingRight->setVisible((FLAG)); \
ui->labelInfo->setVisible(!(FLAG)); \ ui->labelInfo->setVisible(!(FLAG)); \
ui->labelUrl->setVisible(!(FLAG)); \ ui->labelUrl->setVisible(!(FLAG)); \
if((FLAG)) m_animator->start(); else m_animator->stop(); \
} \ } \
while(0) while(0)
@ -64,6 +65,7 @@ UpdaterDialog::UpdaterDialog(QWidget *parent, const QString &binDir)
m_binDir(binDir), m_binDir(binDir),
m_status(UpdateCheckThread::UpdateStatus_NotStartedYet), m_status(UpdateCheckThread::UpdateStatus_NotStartedYet),
m_thread(NULL), m_thread(NULL),
m_updaterProcess(NULL),
m_firstShow(true) m_firstShow(true)
{ {
//Init the dialog, from the .ui file //Init the dialog, from the .ui file
@ -130,6 +132,15 @@ UpdaterDialog::~UpdaterDialog(void)
// Events // Events
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
bool UpdaterDialog::event(QEvent *e)
{
if((e->type() == QEvent::ActivationChange) && (m_updaterProcess != NULL))
{
x264_bring_process_to_front(m_updaterProcess);
}
return QDialog::event(e);
}
void UpdaterDialog::showEvent(QShowEvent *event) void UpdaterDialog::showEvent(QShowEvent *event)
{ {
if(m_firstShow) if(m_firstShow)
@ -220,7 +231,6 @@ void UpdaterDialog::checkForUpdates(void)
//Start animation //Start animation
SHOW_ANIMATION(true); SHOW_ANIMATION(true);
m_animator->start();
//Update cursor //Update cursor
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@ -284,25 +294,27 @@ void UpdaterDialog::threadFinished(void)
//Restore cursor //Restore cursor
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
//Stop animation //If update was successfull, process final updater state
m_animator->stop(); if(m_thread->getSuccess())
//Process final updater state
switch(m_status)
{ {
case UpdateCheckThread::UpdateStatus_CompletedUpdateAvailable: switch(m_status)
UPDATE_ICON(3, "shield_exclamation"); {
UPDATE_TEXT(3, tr("A newer version is available!")); case UpdateCheckThread::UpdateStatus_CompletedUpdateAvailable:
ui->buttonDownload->show(); UPDATE_ICON(3, "shield_exclamation");
break; UPDATE_TEXT(3, tr("A newer version is available!"));
case UpdateCheckThread::UpdateStatus_CompletedNoUpdates: ui->buttonDownload->show();
UPDATE_ICON(3, "shield_green"); break;
UPDATE_TEXT(3, tr("Your version is up-to-date.")); case UpdateCheckThread::UpdateStatus_CompletedNoUpdates:
break; UPDATE_ICON(3, "shield_green");
case UpdateCheckThread::UpdateStatus_CompletedNewVersionOlder: UPDATE_TEXT(3, tr("Your version is up-to-date."));
UPDATE_ICON(3, "shield_error"); break;
UPDATE_TEXT(3, tr("Your are using a pre-release version!")); case UpdateCheckThread::UpdateStatus_CompletedNewVersionOlder:
break; UPDATE_ICON(3, "shield_error");
UPDATE_TEXT(3, tr("Your are using a pre-release version!"));
break;
default:
qWarning("Update thread succeeded with unexpected status code: %d", m_status);
}
} }
//Show update info or retry button //Show update info or retry button
@ -317,8 +329,11 @@ void UpdaterDialog::threadFinished(void)
case UpdateCheckThread::UpdateStatus_ErrorNoConnection: case UpdateCheckThread::UpdateStatus_ErrorNoConnection:
case UpdateCheckThread::UpdateStatus_ErrorConnectionTestFailed: case UpdateCheckThread::UpdateStatus_ErrorConnectionTestFailed:
case UpdateCheckThread::UpdateStatus_ErrorFetchUpdateInfo: case UpdateCheckThread::UpdateStatus_ErrorFetchUpdateInfo:
m_animator->stop();
ui->buttonRetry->show(); ui->buttonRetry->show();
break; break;
default:
qWarning("Update thread finished with unexpected status code: %d", m_status);
} }
//Re-enbale cancel button //Re-enbale cancel button
@ -345,6 +360,11 @@ void UpdaterDialog::installUpdate(void)
return; return;
} }
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->buttonDownload->hide();
ui->buttonCancel->setEnabled(false);
SHOW_ANIMATION(true);
const UpdateInfo *updateInfo = m_thread->getUpdateInfo(); const UpdateInfo *updateInfo = m_thread->getUpdateInfo();
QProcess process; QProcess process;
@ -366,14 +386,15 @@ void UpdaterDialog::installUpdate(void)
process.start(m_wupdFile, args); process.start(m_wupdFile, args);
if(!process.waitForStarted()) if(!process.waitForStarted())
{ {
QApplication::restoreOverrideCursor();
SHOW_ANIMATION(false);
QMessageBox::critical(this, tr("Update Failed"), tr("Sorry, failed to launch web-update program!")); QMessageBox::critical(this, tr("Update Failed"), tr("Sorry, failed to launch web-update program!"));
ui->buttonDownload->show();
ui->buttonCancel->setEnabled(true);
return; return;
} }
QApplication::setOverrideCursor(Qt::WaitCursor); m_updaterProcess = x264_process_id(process);
ui->buttonDownload->hide();
ui->buttonCancel->setEnabled(false);
loop.exec(QEventLoop::ExcludeUserInputEvents); loop.exec(QEventLoop::ExcludeUserInputEvents);
if(!process.waitForFinished()) if(!process.waitForFinished())
@ -382,9 +403,11 @@ void UpdaterDialog::installUpdate(void)
process.waitForFinished(); process.waitForFinished();
} }
m_updaterProcess = NULL;
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
ui->buttonDownload->show(); ui->buttonDownload->show();
ui->buttonCancel->setEnabled(true); ui->buttonCancel->setEnabled(true);
SHOW_ANIMATION(false);
if(process.exitCode() == 0) if(process.exitCode() == 0)
{ {

View File

@ -40,6 +40,7 @@ public:
~UpdaterDialog(void); ~UpdaterDialog(void);
protected: protected:
virtual bool event(QEvent *e);
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);
virtual void closeEvent(QCloseEvent *e); virtual void closeEvent(QCloseEvent *e);
virtual void keyPressEvent(QKeyEvent *event); virtual void keyPressEvent(QKeyEvent *event);
@ -63,6 +64,7 @@ private:
const QString m_binDir; const QString m_binDir;
QMovie *m_animator; QMovie *m_animator;
UpdateCheckThread *m_thread; UpdateCheckThread *m_thread;
unsigned long m_updaterProcess;
QStringList m_logFile; QStringList m_logFile;
QString m_keysFile; QString m_keysFile;
QString m_wupdFile; QString m_wupdFile;