diff --git a/doomsday/engine/portable/include/updater.h b/doomsday/engine/portable/include/updater.h index d9bcd2108f..0565945586 100644 --- a/doomsday/engine/portable/include/updater.h +++ b/doomsday/engine/portable/include/updater.h @@ -34,6 +34,8 @@ */ class Updater : public QObject { + Q_OBJECT + public: explicit Updater(QObject* parent = 0); ~Updater(); diff --git a/doomsday/engine/portable/src/updater.cpp b/doomsday/engine/portable/src/updater.cpp index fe45b99595..063235a1bf 100644 --- a/doomsday/engine/portable/src/updater.cpp +++ b/doomsday/engine/portable/src/updater.cpp @@ -21,52 +21,119 @@ */ #include "updater.h" +#include "dd_version.h" +#include "dd_types.h" +#include "json.h" #include #include +#include #include #include +#include static Updater* updater = 0; -#define WEBSITE_URL "http://dengine.net/" +#define STK_FREQUENCY "updater/frequency" +#define STK_CHANNEL "updater/channel" +#define STK_LAST_CHECKED "updater/lastChecked" +#define STK_ONLY_MANUAL "updater/onlyManually" +#define STK_DELETE "updater/delete" +#define STK_DOWNLOAD_PATH "updater/downloadPath" + +/// @todo The platform ID should come from the Builder. +#if defined(WIN32) +# define PLATFORM_ID "win-x86" + +#elif defined(MACOSX) +# if defined(__64BIT__) +# define PLATFORM_ID "mac10_6-x86-x86_64" +# else +# define PLATFORM_ID "mac10_4-x86-ppc" +# endif + +#else +# if defined(__64BIT__) +# define PLATFORM_ID "linux-x86_64" +# else +# define PLATFORM_ID "linux-x86" +# endif +#endif struct Updater::Instance { enum Frequency { - Daily, - Biweekly, // 3.5 days - Weekly, // 7 days - Monthly // 30 days + Daily = 0, + Biweekly = 1, // 3.5 days + Weekly = 2, // 7 days + Monthly = 3 // 30 days }; enum Channel { - Stable, - Unstable + Stable = 0, + Unstable = 1 }; Updater* self; QNetworkAccessManager* network; + Frequency checkFrequency; Channel channel; ///< What kind of updates to check for. QDateTime lastCheckTime;///< Time of last check (automatic or manual). bool onlyCheckManually; ///< Should only check when manually requested. - bool trashAfterUpdate; ///< Downloaded file is moved to trash afterwards. + bool deleteAfterUpdate; ///< Downloaded file is deleted afterwards. QString downloadPath; ///< Path where the downloaded file is saved. Instance(Updater* up) : self(up) { + // Fetch the current settings. + QSettings st; + checkFrequency = Frequency(st.value(STK_FREQUENCY, Weekly).toInt()); + channel = Channel(st.value(STK_CHANNEL, QString(DOOMSDAY_RELEASE_TYPE) == "Stable"? Stable : Unstable).toInt()); + lastCheckTime = st.value(STK_LAST_CHECKED).toDateTime(); + onlyCheckManually = st.value(STK_ONLY_MANUAL, false).toBool(); + deleteAfterUpdate = st.value(STK_DELETE, true).toBool(); + downloadPath = st.value(STK_DOWNLOAD_PATH, + QDesktopServices::storageLocation(QDesktopServices::TempLocation)).toString(); + network = new QNetworkAccessManager(self); } ~Instance() - {} + { + // Save settings. + QSettings st; + st.setValue(STK_FREQUENCY, int(checkFrequency)); + st.setValue(STK_CHANNEL, int(channel)); + st.setValue(STK_LAST_CHECKED, lastCheckTime); + st.setValue(STK_ONLY_MANUAL, onlyCheckManually); + st.setValue(STK_DELETE, deleteAfterUpdate); + st.setValue(STK_DOWNLOAD_PATH, downloadPath); + } + + QString composeCheckUri() + { + QString uri = QString(DOOMSDAY_HOMEURL) + "/latestbuild?"; + uri += QString("platform=") + PLATFORM_ID; + uri += (channel == Stable? "&stable" : "&unstable"); + uri += "&graph"; + + LOG_DEBUG("Check URI: ") << uri; + return uri; + } + + void queryLatestVersion() + { + lastCheckTime = QDateTime::currentDateTime(); + network->get(QNetworkRequest(composeCheckUri())); + } void handleReply(QNetworkReply* reply) { reply->deleteLater(); // make sure it gets deleted - + QVariant result = parseJSON(QString::fromUtf8(reply->readAll())); + qDebug() << result; } }; @@ -74,6 +141,8 @@ Updater::Updater(QObject *parent) : QObject(parent) { d = new Instance(this); connect(d->network, SIGNAL(finished(QNetworkReply*)), this, SLOT(gotReply(QNetworkReply*))); + + d->queryLatestVersion(); } Updater::~Updater()