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();
}
/*
* 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)
*/
@ -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
*/
bool x264_bring_to_front(const QWidget *win)
{
const bool ret = (SetForegroundWindow(win->winId()) == TRUE);
SwitchToThisWindow(win->winId(), TRUE);
return ret;
if(win)
{
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);
bool x264_beep(int beepType);
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_change_process_priority(const QProcess *proc, 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_portable(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);
unsigned int x264_rand(void);
QString x264_rand_str(const bool bLong = false);

View File

@ -36,7 +36,7 @@
///////////////////////////////////////////////////////////////////////////////
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[] =
{

View File

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

View File

@ -49,6 +49,7 @@
ui->labelLoadingRight->setVisible((FLAG)); \
ui->labelInfo->setVisible(!(FLAG)); \
ui->labelUrl->setVisible(!(FLAG)); \
if((FLAG)) m_animator->start(); else m_animator->stop(); \
} \
while(0)
@ -64,6 +65,7 @@ UpdaterDialog::UpdaterDialog(QWidget *parent, const QString &binDir)
m_binDir(binDir),
m_status(UpdateCheckThread::UpdateStatus_NotStartedYet),
m_thread(NULL),
m_updaterProcess(NULL),
m_firstShow(true)
{
//Init the dialog, from the .ui file
@ -130,6 +132,15 @@ UpdaterDialog::~UpdaterDialog(void)
// 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)
{
if(m_firstShow)
@ -220,7 +231,6 @@ void UpdaterDialog::checkForUpdates(void)
//Start animation
SHOW_ANIMATION(true);
m_animator->start();
//Update cursor
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@ -284,10 +294,9 @@ void UpdaterDialog::threadFinished(void)
//Restore cursor
QApplication::restoreOverrideCursor();
//Stop animation
m_animator->stop();
//Process final updater state
//If update was successfull, process final updater state
if(m_thread->getSuccess())
{
switch(m_status)
{
case UpdateCheckThread::UpdateStatus_CompletedUpdateAvailable:
@ -303,6 +312,9 @@ void UpdaterDialog::threadFinished(void)
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
@ -317,8 +329,11 @@ void UpdaterDialog::threadFinished(void)
case UpdateCheckThread::UpdateStatus_ErrorNoConnection:
case UpdateCheckThread::UpdateStatus_ErrorConnectionTestFailed:
case UpdateCheckThread::UpdateStatus_ErrorFetchUpdateInfo:
m_animator->stop();
ui->buttonRetry->show();
break;
default:
qWarning("Update thread finished with unexpected status code: %d", m_status);
}
//Re-enbale cancel button
@ -345,6 +360,11 @@ void UpdaterDialog::installUpdate(void)
return;
}
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->buttonDownload->hide();
ui->buttonCancel->setEnabled(false);
SHOW_ANIMATION(true);
const UpdateInfo *updateInfo = m_thread->getUpdateInfo();
QProcess process;
@ -366,14 +386,15 @@ void UpdaterDialog::installUpdate(void)
process.start(m_wupdFile, args);
if(!process.waitForStarted())
{
QApplication::restoreOverrideCursor();
SHOW_ANIMATION(false);
QMessageBox::critical(this, tr("Update Failed"), tr("Sorry, failed to launch web-update program!"));
ui->buttonDownload->show();
ui->buttonCancel->setEnabled(true);
return;
}
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->buttonDownload->hide();
ui->buttonCancel->setEnabled(false);
m_updaterProcess = x264_process_id(process);
loop.exec(QEventLoop::ExcludeUserInputEvents);
if(!process.waitForFinished())
@ -382,9 +403,11 @@ void UpdaterDialog::installUpdate(void)
process.waitForFinished();
}
m_updaterProcess = NULL;
QApplication::restoreOverrideCursor();
ui->buttonDownload->show();
ui->buttonCancel->setEnabled(true);
SHOW_ANIMATION(false);
if(process.exitCode() == 0)
{

View File

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