Skip to content

Commit

Permalink
Updater: Silent checks, "updatesettings" command
Browse files Browse the repository at this point in the history
The settings dialog is now created persistently.
  • Loading branch information
skyjake committed Jun 9, 2012
1 parent fb38ad1 commit 85dd0ee
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
16 changes: 14 additions & 2 deletions doomsday/engine/portable/include/updater.h
Expand Up @@ -23,6 +23,8 @@
#ifndef LIBDENG_UPDATER_H
#define LIBDENG_UPDATER_H

#include "dd_types.h"

#ifdef __cplusplus

#include <QObject>
Expand All @@ -43,7 +45,15 @@ class Updater : public QObject
public slots:
void gotReply(QNetworkReply*);
void downloadCompleted(int result);
void checkNow();
void showSettings();

/**
* Checks for available updates.
*
* @param notify Show the update notification dialog even though
* the current version is up to date.
*/
void checkNow(bool notify = true);

private:
struct Instance;
Expand Down Expand Up @@ -76,8 +86,10 @@ void Updater_Shutdown(void);
/**
* Tells the updater to check for updates now. This is called when a manual
* check is requested.
*
* @param notify Show the notification dialog even when up to date.
*/
void Updater_CheckNow(void);
void Updater_CheckNow(boolean notify);

/**
* Shows the Updater Settings dialog.
Expand Down
14 changes: 5 additions & 9 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -128,18 +128,14 @@ static Game* nullGame; // Special "null-game" object.
D_CMD(CheckForUpdates)
{
Con_Message("Checking for available updates...\n");
Updater_CheckNow();
Updater_CheckNow(false);
return true;
}

D_CMD(Update)
D_CMD(ShowUpdateSettings)
{
if(!stricmp(argv[1], "config"))
{
Updater_ShowSettings();
return true;
}
return false;
Updater_ShowSettings();
return true;
}

/**
Expand All @@ -148,7 +144,7 @@ D_CMD(Update)
void DD_Register(void)
{
C_CMD("update", "", CheckForUpdates);
C_CMD("update", "s", Update);
C_CMD("updatesettings", "", ShowUpdateSettings);

DD_RegisterLoop();
DD_RegisterInput();
Expand Down
42 changes: 34 additions & 8 deletions doomsday/engine/portable/src/updater.cpp
Expand Up @@ -24,6 +24,7 @@
#include "sys_system.h"
#include "dd_version.h"
#include "dd_types.h"
#include "con_main.h"
#include "nativeui.h"
#include "window.h"
#include "json.h"
Expand Down Expand Up @@ -109,12 +110,13 @@ struct Updater::Instance
QNetworkAccessManager* network;
DownloadDialog* download;
bool alwaysShowNotification;
UpdaterSettingsDialog* settingsDlg;

VersionInfo latestVersion;
QString latestPackageUri;
QString latestLogUri;

Instance(Updater* up) : self(up), network(0), download(0)
Instance(Updater* up) : self(up), network(0), download(0), settingsDlg(0)
{
network = new QNetworkAccessManager(self);

Expand All @@ -138,6 +140,8 @@ struct Updater::Instance

~Instance()
{
if(settingsDlg) delete settingsDlg;

// Delete the ongoing download.
if(download) delete download;
}
Expand Down Expand Up @@ -196,6 +200,15 @@ struct Updater::Instance
return false;
}

void showSettingsNonModal()
{
if(!settingsDlg)
{
settingsDlg = new UpdaterSettingsDialog(Window_Widget(Window_Main()));
}
settingsDlg->open();
}

void queryLatestVersion(bool notifyAlways)
{
UpdaterSettings().setLastCheckTime(de::Time());
Expand Down Expand Up @@ -229,6 +242,8 @@ struct Updater::Instance
// Is this newer than what we're running?
if(latestVersion > currentVersion || alwaysShowNotification)
{
Con_Message("Found an update: %s\n", latestVersion.asText().toUtf8().constData());

// Automatically switch to windowed mode for convenience.
bool wasFull = switchToWindowedMode();

Expand All @@ -245,6 +260,11 @@ struct Updater::Instance
switchBackToFullscreen(wasFull);
}
}
else
{
Con_Message("You are running the latest available %s release.\n",
UpdaterSettings().channel() == UpdaterSettings::Stable? "stable" : "unstable");
}
}

/**
Expand Down Expand Up @@ -387,12 +407,17 @@ void Updater::downloadCompleted(int result)
d->download = 0;
}

void Updater::checkNow()
void Updater::showSettings()
{
d->showSettingsNonModal();
}

void Updater::checkNow(bool notify)
{
// Not if there is an ongoing download.
if(d->download) return;

d->queryLatestVersion(true /* manual check: show notification always */);
d->queryLatestVersion(notify);
}

void Updater_Init(void)
Expand All @@ -410,18 +435,19 @@ Updater* Updater_Instance(void)
return updater;
}

void Updater_CheckNow(void)
void Updater_CheckNow(boolean notify)
{
if(novideo || !updater) return;

updater->checkNow();
updater->checkNow(notify);
}

static void showSettingsDialog(void)
{
UpdaterSettingsDialog* st = new UpdaterSettingsDialog(Window_Widget(Window_Main()));
QObject::connect(st, SIGNAL(finished(int)), st, SLOT(deleteLater()));
st->open();
if(updater)
{
updater->showSettings();
}
}

void Updater_ShowSettings(void)
Expand Down

0 comments on commit 85dd0ee

Please sign in to comment.