3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #include "updatechecker.h"
22 #include "networkaccess.h"
23 #include "constants.h"
25 #include "activation.h"
29 NetworkAccess* http();
32 UpdateChecker::UpdateChecker() {
36 void UpdateChecker::checkForUpdate() {
37 QUrl updateUrl(QLatin1String(Constants::WEBSITE) + "-ws/release.xml");
38 updateUrl.addQueryItem("v", Constants::VERSION);
41 updateUrl.addQueryItem("os", "mac");
44 updateUrl.addQueryItem("os", "win");
48 if (Activation::instance().isActivated()) t = "active";
49 updateUrl.addQueryItem("t", t);
52 updateUrl.addQueryItem("store", "mac");
55 QObject *reply = The::http()->get(updateUrl);
56 connect(reply, SIGNAL(data(QByteArray)), SLOT(requestFinished(QByteArray)));
60 void UpdateChecker::requestFinished(QByteArray data) {
61 UpdateCheckerStreamReader reader;
63 m_needUpdate = reader.needUpdate();
64 m_remoteVersion = reader.remoteVersion();
65 if (m_needUpdate && !m_remoteVersion.isEmpty()) emit newVersion(m_remoteVersion);
68 QString UpdateChecker::remoteVersion() {
69 return m_remoteVersion;
74 bool UpdateCheckerStreamReader::read(QByteArray data) {
79 if (isStartElement()) {
80 if (name() == QLatin1String("release")) {
83 if (isStartElement() && name() == QLatin1String("version")) {
84 QString remoteVersion = readElementText();
85 qDebug() << remoteVersion << QString(Constants::VERSION);
86 m_needUpdate = remoteVersion != QString(Constants::VERSION);
87 m_remoteVersion = remoteVersion;
98 QString UpdateCheckerStreamReader::remoteVersion() {
99 return m_remoteVersion;