Skip to content

Commit

Permalink
Updater: Added option to download available updates automatically
Browse files Browse the repository at this point in the history
When enabled, the download is started in the background (with the
progress notification visible) and when ready, the download popup
opens.
  • Loading branch information
skyjake committed Sep 23, 2013
1 parent 8967105 commit 176247c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/updater/updatersettings.h
Expand Up @@ -56,6 +56,7 @@ class UpdaterSettings
Channel channel() const;
de::Time lastCheckTime() const;
bool onlyCheckManually() const;
bool autoDownload() const;
bool deleteAfterUpdate() const;
bool isDefaultDownloadPath() const;
de::NativePath downloadPath() const;
Expand All @@ -71,6 +72,7 @@ class UpdaterSettings
void setChannel(Channel channel);
void setLastCheckTime(const de::Time& time);
void setOnlyCheckManually(bool onlyManually);
void setAutoDownload(bool autoDl);
void setDeleteAfterUpdate(bool deleteAfter);
void setDownloadPath(de::NativePath downloadPath);
void useDefaultDownloadPath();
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/modules/appconfig.de
Expand Up @@ -91,7 +91,7 @@ def setDefaults(d)

const d.updater.CHANNEL_STABLE = 0
const d.updater.CHANNEL_UNSTABLE = 1

d.updater.frequency = d.updater.WEEKLY
if Version.STABLE
d.updater.channel = d.updater.CHANNEL_STABLE
Expand All @@ -100,6 +100,7 @@ def setDefaults(d)
end
d.updater.lastChecked = Time("")
d.updater.onlyManually = (Version.OS == 'unix')
d.updater.autoDownload = False
d.updater.delete = True
d.updater.downloadPath = "${DEFAULT}"
d.updater.deleteAtStartup = ""
Expand Down
48 changes: 32 additions & 16 deletions doomsday/client/src/updater/updater.cpp
Expand Up @@ -340,11 +340,22 @@ DENG2_OBSERVES(App, StartupComplete)
return;
}

// Is this newer than what we're running?
if(latestVersion > currentVersion || alwaysShowNotification)
bool const gotUpdate = latestVersion > currentVersion;

if(gotUpdate)
{
LOG_INFO("Found an update: " _E(b)) << latestVersion.asText();

if(!alwaysShowNotification && UpdaterSettings().autoDownload())
{
startDownload();
return;
}
}

// Is this newer than what we're running?
if(gotUpdate || alwaysShowNotification)
{
// Modal dialogs will interrupt gameplay.
ClientWindow::main().taskBar().openAndPauseGame();

Expand All @@ -367,24 +378,29 @@ DENG2_OBSERVES(App, StartupComplete)

if(availableDlg->exec(ClientWindow::main().root()))
{
//availableDlg = 0;
startDownload();
download->open();
}
availableDlg = 0;
}

void startDownload()
{
DENG2_ASSERT(download == 0);

// The notification provides access to the download dialog.
showDownloadNotification();
// The notification provides access to the download dialog.
showDownloadNotification();

LOG_MSG("Download and install.");
LOG_MSG("Download and install.");

download = new DownloadDialog(latestPackageUri, latestPackageUri2);
download->setAnchorAndOpeningDirection(status->rule(), ui::Down);
QObject::connect(download, SIGNAL(closed()), thisPublic, SLOT(downloadDialogClosed()));
QObject::connect(download, SIGNAL(downloadProgress(int)),thisPublic, SLOT(downloadProgressed(int)));
QObject::connect(download, SIGNAL(downloadFailed(QString)), thisPublic, SLOT(downloadFailed(QString)));
QObject::connect(download, SIGNAL(accepted(int)), thisPublic, SLOT(downloadCompleted(int)));
download = new DownloadDialog(latestPackageUri, latestPackageUri2);
download->setAnchorAndOpeningDirection(status->rule(), ui::Down);
QObject::connect(download, SIGNAL(closed()), thisPublic, SLOT(downloadDialogClosed()));
QObject::connect(download, SIGNAL(downloadProgress(int)),thisPublic, SLOT(downloadProgressed(int)));
QObject::connect(download, SIGNAL(downloadFailed(QString)), thisPublic, SLOT(downloadFailed(QString)));
QObject::connect(download, SIGNAL(accepted(int)), thisPublic, SLOT(downloadCompleted(int)));

ClientWindow::main().root().add(download);
download->open();
}
availableDlg = 0;
ClientWindow::main().root().add(download);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions doomsday/client/src/updater/updatersettings.cpp
Expand Up @@ -39,6 +39,7 @@ using namespace de;
#define VAR_DELETE "delete"
#define VAR_DOWNLOAD_PATH "downloadPath"
#define VAR_DELETE_PATH "deleteAtStartup"
#define VAR_AUTO_DOWNLOAD "autoDownload"

#define SUBREC_NAME "updater"
#define CONF(name) SUBREC_NAME "." name
Expand Down Expand Up @@ -105,6 +106,11 @@ bool UpdaterSettings::onlyCheckManually() const
return App::config().getb(CONF(VAR_ONLY_MANUAL));
}

bool UpdaterSettings::autoDownload() const
{
return App::config().getb(CONF(VAR_AUTO_DOWNLOAD));
}

bool UpdaterSettings::deleteAfterUpdate() const
{
return App::config().getb(CONF(VAR_DELETE));
Expand Down Expand Up @@ -166,6 +172,11 @@ void UpdaterSettings::setOnlyCheckManually(bool onlyManually)
App::config().set(CONF(VAR_ONLY_MANUAL), onlyManually);
}

void UpdaterSettings::setAutoDownload(bool autoDl)
{
App::config().set(CONF(VAR_AUTO_DOWNLOAD), autoDl);
}

void UpdaterSettings::setDeleteAfterUpdate(bool deleteAfter)
{
App::config().set(CONF(VAR_DELETE), deleteAfter);
Expand Down
10 changes: 8 additions & 2 deletions doomsday/client/src/updater/updatersettingsdialog.cpp
Expand Up @@ -54,6 +54,7 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
LabelWidget *lastChecked;
ChoiceWidget *channels;
ChoiceWidget *paths;
ToggleWidget *autoDown;
ToggleWidget *deleteAfter;

Instance(Public *i, Mode mode) : Base(i)
Expand All @@ -65,6 +66,7 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
area.add(freqs = new ChoiceWidget);
area.add(lastChecked = new LabelWidget);
area.add(channels = new ChoiceWidget);
area.add(autoDown = new ToggleWidget);
area.add(paths = new ChoiceWidget);
area.add(deleteAfter = new ToggleWidget);

Expand Down Expand Up @@ -97,6 +99,7 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
<< new ChoiceItem(defaultLocationName(),
UpdaterSettings::defaultDownloadPath().toString());

autoDown->setText(tr("Download automatically"));
deleteAfter->setText(tr("Delete file after install"));

fetch();
Expand All @@ -111,8 +114,9 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
layout << *autoCheck << *freqs
<< Const(0) << *lastChecked
<< *releaseLabel << *channels
<< *pathLabel << *paths
<< Const(0) << *deleteAfter;
<< Const(0) << *autoDown
<< Const(0) << *deleteAfter
<< *pathLabel << *paths;

area.setContentSize(layout.width(), layout.height());

Expand Down Expand Up @@ -147,6 +151,7 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
freqs->setSelected(freqs->items().findData(st.frequency()));
channels->setSelected(channels->items().findData(st.channel()));
setDownloadPath(st.downloadPath());
autoDown->setActive(st.autoDownload());
deleteAfter->setActive(st.deleteAfterUpdate());
}

Expand Down Expand Up @@ -174,6 +179,7 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
st.setChannel(UpdaterSettings::Channel(channels->items().at(sel).data().toInt()));
}
//st.setDownloadPath(pathList->itemData(pathList->currentIndex()).toString());
st.setAutoDownload(autoDown->isActive());
st.setDeleteAfterUpdate(deleteAfter->isActive());
}

Expand Down

0 comments on commit 176247c

Please sign in to comment.