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"
27 #include "compatibility/qurlqueryhelper.h"
30 NetworkAccess* http();
33 UpdateChecker::UpdateChecker() {
37 void UpdateChecker::checkForUpdate() {
38 QUrl url(QLatin1String(Constants::WEBSITE) + "-ws/release.xml");
41 QUrlQueryHelper urlHelper(url);
42 urlHelper.addQueryItem("v", Constants::VERSION);
45 urlHelper.addQueryItem("os", "mac");
48 urlHelper.addQueryItem("os", "win");
52 if (Activation::instance().isActivated()) t = "active";
53 urlHelper.addQueryItem("t", t);
56 urlHelper.addQueryItem("store", "mac");
60 QObject *reply = The::http()->get(url);
61 connect(reply, SIGNAL(data(QByteArray)), SLOT(requestFinished(QByteArray)));
65 void UpdateChecker::requestFinished(QByteArray data) {
66 UpdateCheckerStreamReader reader;
68 m_needUpdate = reader.needUpdate();
69 m_remoteVersion = reader.remoteVersion();
70 if (m_needUpdate && !m_remoteVersion.isEmpty()) emit newVersion(m_remoteVersion);
73 QString UpdateChecker::remoteVersion() {
74 return m_remoteVersion;
79 bool UpdateCheckerStreamReader::read(QByteArray data) {
84 if (isStartElement()) {
85 if (name() == QLatin1String("release")) {
88 if (isStartElement() && name() == QLatin1String("version")) {
89 QString remoteVersion = readElementText();
90 qDebug() << remoteVersion << QString(Constants::VERSION);
91 m_needUpdate = remoteVersion != QString(Constants::VERSION);
92 m_remoteVersion = remoteVersion;
103 QString UpdateCheckerStreamReader::remoteVersion() {
104 return m_remoteVersion;