1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-14 11:02:19 +01:00
falkonOfficial/src/lib/other/updater.cpp

132 lines
3.7 KiB
C++
Raw Normal View History

2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
2011-03-03 18:29:20 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
2011-03-02 16:57:41 +01:00
#include "updater.h"
#include "qupzilla.h"
#include "mainapplication.h"
2011-03-02 16:57:41 +01:00
#include "tabwidget.h"
#include "desktopnotificationsfactory.h"
2011-03-02 16:57:41 +01:00
#include <QTimer>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
Updater::Updater(QupZilla* mainClass, QObject* parent)
: QObject(parent)
, p_QupZilla(mainClass)
2011-03-02 16:57:41 +01:00
{
QTimer::singleShot(60 * 1000, this, SLOT(start())); //Start checking after 1 minute
2011-03-02 16:57:41 +01:00
}
Updater::Version Updater::parseVersionFromString(const QString &string)
{
Version ver;
ver.isValid = false;
QStringList v = string.split(".");
if (v.count() != 3) {
return ver;
}
QStringList r = v.at(2).split("-");
ver.majorVersion = v.at(0).toInt();
ver.minorVersion = v.at(1).toInt();
ver.revisionNumber = r.at(0).toInt();
if (r.count() == 2) {
ver.specialSymbol = r.at(1);
}
ver.isValid = true;
return ver;
}
bool Updater::isBiggerThan_SpecialSymbol(QString one, QString two)
{
if (one.contains("rc") && two.contains("b")) {
return true;
}
if (one.contains("b") && two.contains("rc")) {
return false;
}
if (one.isEmpty()) {
return true;
}
if (two.isEmpty()) {
return false;
}
if (one.contains("b")) {
int o = one.remove("b").toInt();
int t = two.remove("b").toInt();
return o > t;
}
if (one.contains("rc")) {
int o = one.remove("rc").toInt();
int t = two.remove("rc").toInt();
return o > t;
}
return false;
}
2011-03-02 16:57:41 +01:00
void Updater::start()
{
startDownloadingUpdateInfo(QUrl(QupZilla::WWWADDRESS + "/update.php?v=" + QupZilla::VERSION));
2011-03-02 16:57:41 +01:00
}
void Updater::startDownloadingUpdateInfo(const QUrl &url)
{
QNetworkAccessManager* manager = new QNetworkAccessManager();
manager->get(QNetworkRequest(QUrl(url)));
2011-03-02 16:57:41 +01:00
2011-03-17 17:03:04 +01:00
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downCompleted(QNetworkReply*)));
2011-03-02 16:57:41 +01:00
}
void Updater::downCompleted(QNetworkReply* reply)
{
QString html = QString(reply->readAll());
if (html.startsWith("Version:")) {
2011-03-02 16:57:41 +01:00
html.remove("Version:");
Version current = parseVersionFromString(QupZilla::VERSION);
Version updated = parseVersionFromString(html);
if (current < updated) {
mApp->desktopNotifications()->showNotifications(QPixmap(":icons/qupzillaupdate.png"), tr("Update available"), tr("New version of QupZilla is ready to download."));
2011-10-02 17:39:59 +02:00
// QAction* action = new QAction(QIcon(":icons/qupzillaupdate.png"), "Update", this);
// connect(action, SIGNAL(triggered()), this, SLOT(downloadNewVersion()));
// p_QupZilla->menuBar()->addAction(action);
}
}
2011-03-02 16:57:41 +01:00
reply->manager()->deleteLater();
}
void Updater::downloadNewVersion()
{
p_QupZilla->tabWidget()->addView(QUrl(QupZilla::WWWADDRESS + "/download"), tr("Update"), Qz::NT_NotSelectedTab);
}
2011-03-02 16:57:41 +01:00
Updater::~Updater()
{
}