Skip to content

Commit

Permalink
Updater: Finishing touches
Browse files Browse the repository at this point in the history
Cannot quit or switch to fullscreen mode while a download is in progress.
This could be improved later by adding an in-game UI for the download
(needs Scripted UI) and asking whether the download should be cancelled
if the user tries to quit.
  • Loading branch information
skyjake committed Jun 7, 2012
1 parent fe493fa commit fc69d3f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 10 deletions.
7 changes: 7 additions & 0 deletions doomsday/engine/portable/src/con_main.c
Expand Up @@ -58,6 +58,7 @@
#include "de_filesys.h"

#include "displaymode.h"
#include "updater/downloaddialog.h"
#include "cbuffer.h"
#include "font.h"

Expand Down Expand Up @@ -2220,6 +2221,12 @@ D_CMD(Version)

D_CMD(Quit)
{
if(Updater_IsDownloadInProgress())
{
Con_Message("Cannot quit while downloading update.\n");
return false;
}

if(argv[0][4] == '!' || isDedicated || !DD_GameLoaded() ||
gx.TryShutdown == 0)
{
Expand Down
14 changes: 14 additions & 0 deletions doomsday/engine/portable/src/updater/downloaddialog.cpp
Expand Up @@ -13,6 +13,8 @@
#include <de/Log>
#include <QDebug>

static bool downloadInProgress;

struct DownloadDialog::Instance
{
DownloadDialog* self;
Expand Down Expand Up @@ -73,6 +75,9 @@ struct DownloadDialog::Instance
QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)), self, SLOT(progress(qint64,qint64)));

LOG_INFO("Downloading %s, saving as: %s") << uri.toString() << savedFilePath;

// Global state flag.
downloadInProgress = true;
}

void setProgressText(de::String text)
Expand All @@ -89,6 +94,7 @@ DownloadDialog::DownloadDialog(de::String downloadUri, QWidget *parent)

DownloadDialog::~DownloadDialog()
{
downloadInProgress = false;
delete d;
}

Expand All @@ -102,6 +108,7 @@ void DownloadDialog::finished(QNetworkReply* reply)
{
LOG_AS("Download");

downloadInProgress = false;
reply->deleteLater();
d->reply = 0;

Expand Down Expand Up @@ -167,6 +174,8 @@ void DownloadDialog::finished(QNetworkReply* reply)
emit downloadFailed(d->uri.toString());
}

raise();
activateWindow();
d->fileReady = true;
d->setProgressText(tr("Ready to install"));
d->install->setEnabled(true);
Expand Down Expand Up @@ -208,3 +217,8 @@ void DownloadDialog::replyMetaDataChanged()
LOG_DEBUG("Receiving content of type '%s'.") << contentType;
}
}

int Updater_IsDownloadInProgress(void)
{
return downloadInProgress;
}
15 changes: 15 additions & 0 deletions doomsday/engine/portable/src/updater/downloaddialog.h
@@ -1,6 +1,8 @@
#ifndef DOWNLOADDIALOG_H
#define DOWNLOADDIALOG_H

#ifdef __cplusplus

#include <QDialog>
#include <de/String>

Expand Down Expand Up @@ -39,4 +41,17 @@ public slots:
Instance* d;
};

#endif // __cplusplus

// C API
#ifdef __cplusplus
extern "C" {
#endif

int Updater_IsDownloadInProgress(void);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // DOWNLOADDIALOG_H
36 changes: 27 additions & 9 deletions doomsday/engine/portable/src/updater/updateavailabledialog.cpp
Expand Up @@ -20,7 +20,7 @@ struct UpdateAvailableDialog::Instance
VersionInfo latestVersion;
de::String changeLog;

Instance(UpdateAvailableDialog* d) : self(d)
Instance(UpdateAvailableDialog* d, const VersionInfo& latest) : self(d), latestVersion(latest)
{
QVBoxLayout* mainLayout = new QVBoxLayout(self);
self->setLayout(mainLayout);
Expand All @@ -32,6 +32,7 @@ struct UpdateAvailableDialog::Instance
de::String channel = (UpdaterSettings().channel() == UpdaterSettings::Stable?
"stable" : "unstable");
bool askUpgrade = false;
bool askDowngrade = false;

if(latestVersion > currentVersion)
{
Expand All @@ -44,7 +45,7 @@ struct UpdateAvailableDialog::Instance
.arg(latestVersion.asText())
.arg(currentVersion.asText()));
}
else
else if(!channel.compareWithoutCase(DOOMSDAY_RELEASE_TYPE)) // same release type
{
info->setText(("<span style=\"font-weight:bold; font-size:%1pt;\">" +
tr("You are up to date.") + "</span><p>" +
Expand All @@ -53,25 +54,42 @@ struct UpdateAvailableDialog::Instance
.arg(currentVersion.asText())
.arg(channel));
}
else if(latestVersion < currentVersion)
{
askDowngrade = true;
info->setText(("<span style=\"font-weight:bold; font-size:%1pt;\">" +
tr("You are up to date.") + "</span><p>" +
tr("The installed %2 is newer than the latest available %3 build."))
.arg(bigFontSize)
.arg(currentVersion.asText())
.arg(channel));
}

neverCheck = new QCheckBox(tr("N&ever check for updates automatically"));
neverCheck->setChecked(UpdaterSettings().onlyCheckManually());
QObject::connect(neverCheck, SIGNAL(toggled(bool)), self, SLOT(neverCheckToggled(bool)));

QDialogButtonBox* bbox = new QDialogButtonBox;

if(!askUpgrade)
if(askDowngrade)
{
QPushButton* ok = bbox->addButton(tr("&Close"), QDialogButtonBox::RejectRole);
QObject::connect(ok, SIGNAL(clicked()), self, SLOT(reject()));
QPushButton* yes = bbox->addButton(tr("Downgrade to &Older"), QDialogButtonBox::YesRole);
QPushButton* no = bbox->addButton(tr("&Close"), QDialogButtonBox::RejectRole);
QObject::connect(yes, SIGNAL(clicked()), self, SLOT(accept()));
QObject::connect(no, SIGNAL(clicked()), self, SLOT(reject()));
}
else
else if(askUpgrade)
{
QPushButton* yes = bbox->addButton(tr("&Download Update"), QDialogButtonBox::YesRole);
QPushButton* yes = bbox->addButton(tr("&Upgrade"), QDialogButtonBox::YesRole);
QPushButton* no = bbox->addButton(tr("&Not Now"), QDialogButtonBox::NoRole);
QObject::connect(yes, SIGNAL(clicked()), self, SLOT(accept()));
QObject::connect(no, SIGNAL(clicked()), self, SLOT(reject()));
}
else
{
QPushButton* ok = bbox->addButton(tr("&Close"), QDialogButtonBox::RejectRole);
QObject::connect(ok, SIGNAL(clicked()), self, SLOT(reject()));
}

QPushButton* cfg = bbox->addButton(tr("&Settings..."), QDialogButtonBox::ActionRole);
QObject::connect(cfg, SIGNAL(clicked()), self, SLOT(editSettings()));
Expand All @@ -94,8 +112,7 @@ UpdateAvailableDialog::UpdateAvailableDialog(const VersionInfo& latestVersion, d
QWidget *parent)
: QDialog(parent)
{
d = new Instance(this);
d->latestVersion = latestVersion;
d = new Instance(this, latestVersion);
d->changeLog = changeLogUri;
}

Expand All @@ -121,5 +138,6 @@ void UpdateAvailableDialog::editSettings()
if(st.exec())
{
d->neverCheck->setChecked(UpdaterSettings().onlyCheckManually());
close();
}
}
7 changes: 6 additions & 1 deletion doomsday/engine/portable/src/updater/updatersettings.cpp
Expand Up @@ -32,7 +32,12 @@ de::Time UpdaterSettings::lastCheckTime() const

bool UpdaterSettings::onlyCheckManually() const
{
return QSettings().value(STK_ONLY_MANUAL, false).toBool();
bool byDefault = false;
#if defined(UNIX) && !defined(MACOSX)
// On Unix platforms don't do automatic checks by default.
byDefault = true;
#endif
return QSettings().value(STK_ONLY_MANUAL, byDefault).toBool();
}

bool UpdaterSettings::deleteAfterUpdate() const
Expand Down
6 changes: 6 additions & 0 deletions doomsday/engine/portable/src/window.cpp
Expand Up @@ -39,6 +39,7 @@
#include "consolewindow.h"
#include "canvaswindow.h"
#include "displaymode.h"
#include "updater/downloaddialog.h"
#include "sys_system.h"
#include "dd_main.h"
#include "con_main.h"
Expand Down Expand Up @@ -385,6 +386,11 @@ struct ddwindow_s
case DDWA_FULLSCREEN:
if(IS_NONZERO(attribs[i]) != IS_NONZERO(checkFlag(DDWF_FULLSCREEN)))
{
if(IS_NONZERO(attribs[i]) && Updater_IsDownloadInProgress())
{
// Can't go to fullscreen when downloading.
return false;
}
setFlag(DDWF_FULLSCREEN, attribs[i]);
changed = true;
}
Expand Down

0 comments on commit fc69d3f

Please sign in to comment.