|
|
@ -28,23 +28,20 @@ |
|
|
|
* Contact : chris@qbittorrent.org |
|
|
|
* Contact : chris@qbittorrent.org |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <QNetworkAccessManager> |
|
|
|
|
|
|
|
#include <QNetworkRequest> |
|
|
|
|
|
|
|
#include <QNetworkReply> |
|
|
|
|
|
|
|
#include <QXmlStreamReader> |
|
|
|
#include <QXmlStreamReader> |
|
|
|
#include <QNetworkProxy> |
|
|
|
|
|
|
|
#include <QDesktopServices> |
|
|
|
#include <QDesktopServices> |
|
|
|
#include <QDebug> |
|
|
|
#include <QDebug> |
|
|
|
#include <QRegExp> |
|
|
|
#include <QRegExp> |
|
|
|
#include <QStringList> |
|
|
|
#include <QStringList> |
|
|
|
|
|
|
|
|
|
|
|
#include "programupdater.h" |
|
|
|
|
|
|
|
#include "base/utils/fs.h" |
|
|
|
#include "base/utils/fs.h" |
|
|
|
#include "base/preferences.h" |
|
|
|
#include "base/net/downloadmanager.h" |
|
|
|
|
|
|
|
#include "base/net/downloadhandler.h" |
|
|
|
|
|
|
|
#include "programupdater.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
namespace |
|
|
|
{ |
|
|
|
{ |
|
|
|
const QUrl RSS_URL("http://www.fosshub.com/software/feedqBittorent"); |
|
|
|
const QString RSS_URL("http://www.fosshub.com/software/feedqBittorent"); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC |
|
|
|
#ifdef Q_OS_MAC |
|
|
|
const QString OS_TYPE("Mac OS X"); |
|
|
|
const QString OS_TYPE("Mac OS X"); |
|
|
@ -59,58 +56,27 @@ ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser) |
|
|
|
: QObject(parent) |
|
|
|
: QObject(parent) |
|
|
|
, m_invokedByUser(invokedByUser) |
|
|
|
, m_invokedByUser(invokedByUser) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_networkManager = new QNetworkAccessManager(this); |
|
|
|
|
|
|
|
Preferences* const pref = Preferences::instance(); |
|
|
|
|
|
|
|
// Proxy support
|
|
|
|
|
|
|
|
if (pref->isProxyEnabled()) { |
|
|
|
|
|
|
|
QNetworkProxy proxy; |
|
|
|
|
|
|
|
switch(pref->getProxyType()) { |
|
|
|
|
|
|
|
case Proxy::SOCKS4: |
|
|
|
|
|
|
|
case Proxy::SOCKS5: |
|
|
|
|
|
|
|
case Proxy::SOCKS5_PW: |
|
|
|
|
|
|
|
proxy.setType(QNetworkProxy::Socks5Proxy); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
proxy.setType(QNetworkProxy::HttpProxy); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
proxy.setHostName(pref->getProxyIp()); |
|
|
|
|
|
|
|
proxy.setPort(pref->getProxyPort()); |
|
|
|
|
|
|
|
// Proxy authentication
|
|
|
|
|
|
|
|
if (pref->isProxyAuthEnabled()) { |
|
|
|
|
|
|
|
proxy.setUser(pref->getProxyUsername()); |
|
|
|
|
|
|
|
proxy.setPassword(pref->getProxyPassword()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
m_networkManager->setProxy(proxy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProgramUpdater::~ProgramUpdater() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
delete m_networkManager; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ProgramUpdater::checkForUpdates() |
|
|
|
void ProgramUpdater::checkForUpdates() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// SIGNAL/SLOT
|
|
|
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl( |
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
RSS_URL, false, 0, false, |
|
|
|
this, SLOT(rssDownloadFinished(QNetworkReply*))); |
|
|
|
// Don't change this User-Agent. In case our updater goes haywire,
|
|
|
|
// Send the request
|
|
|
|
// the filehost can identify it and contact us.
|
|
|
|
QNetworkRequest request(RSS_URL); |
|
|
|
QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION)); |
|
|
|
// Don't change this User-Agent. In case our updater goes haywire, the filehost can indetify it and contact us.
|
|
|
|
connect(handler, SIGNAL(downloadFinished(QString,QByteArray)), SLOT(rssDownloadFinished(QString,QByteArray))); |
|
|
|
request.setRawHeader("User-Agent", QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION).toLocal8Bit()); |
|
|
|
connect(handler, SIGNAL(downloadFailed(QString,QString)), SLOT(rssDownloadFailed(QString,QString))); |
|
|
|
m_networkManager->get(request); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply) |
|
|
|
void ProgramUpdater::rssDownloadFinished(const QString &url, const QByteArray &data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Disconnect SIGNAL/SLOT
|
|
|
|
Q_UNUSED(url); |
|
|
|
disconnect(m_networkManager, 0, this, 0); |
|
|
|
|
|
|
|
qDebug("Finished downloading the new qBittorrent updates RSS"); |
|
|
|
qDebug("Finished downloading the new qBittorrent updates RSS"); |
|
|
|
QString version; |
|
|
|
QString version; |
|
|
|
|
|
|
|
|
|
|
|
if (!reply->error()) { |
|
|
|
QXmlStreamReader xml(data); |
|
|
|
qDebug("No download error, good."); |
|
|
|
|
|
|
|
QXmlStreamReader xml(reply); |
|
|
|
|
|
|
|
bool inItem = false; |
|
|
|
bool inItem = false; |
|
|
|
QString updateLink; |
|
|
|
QString updateLink; |
|
|
|
QString type; |
|
|
|
QString type; |
|
|
@ -147,11 +113,16 @@ void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit updateCheckFinished(!m_updateUrl.isEmpty(), version, m_invokedByUser); |
|
|
|
emit updateCheckFinished(!m_updateUrl.isEmpty(), version, m_invokedByUser); |
|
|
|
// Clean up
|
|
|
|
} |
|
|
|
reply->deleteLater(); |
|
|
|
|
|
|
|
|
|
|
|
void ProgramUpdater::rssDownloadFailed(const QString &url, const QString &error) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(url); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "Downloading the new qBittorrent updates RSS failed:" << error; |
|
|
|
|
|
|
|
emit updateCheckFinished(false, QString(), m_invokedByUser); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ProgramUpdater::updateProgram() |
|
|
|
void ProgramUpdater::updateProgram() |
|
|
|