|
|
@ -50,10 +50,11 @@ const QUrl RSS_URL("http://sourceforge.net/projects/qbittorrent/rss?path=/qbitto |
|
|
|
const QString FILE_EXT = "EXE"; |
|
|
|
const QString FILE_EXT = "EXE"; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser) : |
|
|
|
ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser) |
|
|
|
QObject(parent), m_invokedByUser(invokedByUser) |
|
|
|
: QObject(parent) |
|
|
|
|
|
|
|
, m_invokedByUser(invokedByUser) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mp_manager = new QNetworkAccessManager(this); |
|
|
|
m_networkManager = new QNetworkAccessManager(this); |
|
|
|
Preferences* const pref = Preferences::instance(); |
|
|
|
Preferences* const pref = Preferences::instance(); |
|
|
|
// Proxy support
|
|
|
|
// Proxy support
|
|
|
|
if (pref->isProxyEnabled()) { |
|
|
|
if (pref->isProxyEnabled()) { |
|
|
@ -74,34 +75,36 @@ ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser) : |
|
|
|
proxy.setUser(pref->getProxyUsername()); |
|
|
|
proxy.setUser(pref->getProxyUsername()); |
|
|
|
proxy.setPassword(pref->getProxyPassword()); |
|
|
|
proxy.setPassword(pref->getProxyPassword()); |
|
|
|
} |
|
|
|
} |
|
|
|
mp_manager->setProxy(proxy); |
|
|
|
m_networkManager->setProxy(proxy); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ProgramUpdater::~ProgramUpdater() { |
|
|
|
ProgramUpdater::~ProgramUpdater() |
|
|
|
delete mp_manager; |
|
|
|
{ |
|
|
|
|
|
|
|
delete m_networkManager; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ProgramUpdater::checkForUpdates() |
|
|
|
void ProgramUpdater::checkForUpdates() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// SIGNAL/SLOT
|
|
|
|
// SIGNAL/SLOT
|
|
|
|
connect(mp_manager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
this, SLOT(rssDownloadFinished(QNetworkReply*))); |
|
|
|
this, SLOT(rssDownloadFinished(QNetworkReply*))); |
|
|
|
// Send the request
|
|
|
|
// Send the request
|
|
|
|
QNetworkRequest request(RSS_URL); |
|
|
|
QNetworkRequest request(RSS_URL); |
|
|
|
request.setRawHeader("User-Agent", QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION).toLocal8Bit()); |
|
|
|
request.setRawHeader("User-Agent", QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION).toLocal8Bit()); |
|
|
|
mp_manager->get(request); |
|
|
|
m_networkManager->get(request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ProgramUpdater::setUpdateUrl(QString title) { |
|
|
|
void ProgramUpdater::setUpdateUrl(QString title) |
|
|
|
m_updateUrl = "http://downloads.sourceforge.net/project/qbittorrent"+title; |
|
|
|
{ |
|
|
|
|
|
|
|
m_updateUrl = "http://downloads.sourceforge.net/project/qbittorrent" + title; |
|
|
|
qDebug("The Update URL is %s", qPrintable(m_updateUrl)); |
|
|
|
qDebug("The Update URL is %s", qPrintable(m_updateUrl)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply) |
|
|
|
void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Disconnect SIGNAL/SLOT
|
|
|
|
// Disconnect SIGNAL/SLOT
|
|
|
|
disconnect(mp_manager, 0, this, 0); |
|
|
|
disconnect(m_networkManager, 0, this, 0); |
|
|
|
qDebug("Finished downloading the new qBittorrent updates RSS"); |
|
|
|
qDebug("Finished downloading the new qBittorrent updates RSS"); |
|
|
|
QString new_version; |
|
|
|
QString new_version; |
|
|
|
if (!reply->error()) { |
|
|
|
if (!reply->error()) { |
|
|
@ -116,10 +119,12 @@ void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply) |
|
|
|
if (in_item && xml.name() == "title") { |
|
|
|
if (in_item && xml.name() == "title") { |
|
|
|
in_title = true; |
|
|
|
in_title = true; |
|
|
|
item_title = ""; |
|
|
|
item_title = ""; |
|
|
|
} else if (xml.name() == "item") { |
|
|
|
} |
|
|
|
|
|
|
|
else if (xml.name() == "item") { |
|
|
|
in_item = true; |
|
|
|
in_item = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (xml.isEndElement()) { |
|
|
|
} |
|
|
|
|
|
|
|
else if (xml.isEndElement()) { |
|
|
|
if (in_item && xml.name() == "title") { |
|
|
|
if (in_item && xml.name() == "title") { |
|
|
|
in_title = false; |
|
|
|
in_title = false; |
|
|
|
const QString ext = Utils::Fs::fileExtension(item_title).toUpper(); |
|
|
|
const QString ext = Utils::Fs::fileExtension(item_title).toUpper(); |
|
|
@ -134,10 +139,12 @@ void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply) |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (xml.name() == "item") { |
|
|
|
} |
|
|
|
|
|
|
|
else if (xml.name() == "item") { |
|
|
|
in_item = false; |
|
|
|
in_item = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (xml.isCharacters() && !xml.isWhitespace()) { |
|
|
|
} |
|
|
|
|
|
|
|
else if (xml.isCharacters() && !xml.isWhitespace()) { |
|
|
|
if (in_item && in_title) |
|
|
|
if (in_item && in_title) |
|
|
|
item_title += xml.text().toString(); |
|
|
|
item_title += xml.text().toString(); |
|
|
|
} |
|
|
|
} |
|
|
@ -164,29 +171,30 @@ QString ProgramUpdater::extractVersionNumber(const QString& title) const |
|
|
|
if (regVer.indexIn(title) < 0) { |
|
|
|
if (regVer.indexIn(title) < 0) { |
|
|
|
qWarning() << Q_FUNC_INFO << "Failed to extract version from file name:" << title; |
|
|
|
qWarning() << Q_FUNC_INFO << "Failed to extract version from file name:" << title; |
|
|
|
return QString::null; |
|
|
|
return QString::null; |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
QString version = regVer.cap(1); |
|
|
|
QString version = regVer.cap(1); |
|
|
|
qDebug() << Q_FUNC_INFO << "Extracted version:" << version; |
|
|
|
qDebug() << Q_FUNC_INFO << "Extracted version:" << version; |
|
|
|
return version; |
|
|
|
return version; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ProgramUpdater::isVersionMoreRecent(const QString& remote_version) const |
|
|
|
bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
QRegExp regVer("([0-9.]+)"); |
|
|
|
QRegExp regVer("([0-9.]+)"); |
|
|
|
if (regVer.indexIn(QString(VERSION)) >= 0) { |
|
|
|
if (regVer.indexIn(QString(VERSION)) >= 0) { |
|
|
|
QString local_version = regVer.cap(1); |
|
|
|
QString localVersion = regVer.cap(1); |
|
|
|
qDebug() << Q_FUNC_INFO << "local version:" << local_version << "/" << VERSION; |
|
|
|
qDebug() << Q_FUNC_INFO << "local version:" << localVersion << "/" << VERSION; |
|
|
|
QStringList remote_parts = remote_version.split('.'); |
|
|
|
QStringList remoteParts = remoteVersion.split('.'); |
|
|
|
QStringList local_parts = local_version.split('.'); |
|
|
|
QStringList localParts = localVersion.split('.'); |
|
|
|
for (int i=0; i<qMin(remote_parts.size(), local_parts.size()); ++i) { |
|
|
|
for (int i = 0; i<qMin(remoteParts.size(), localParts.size()); ++i) { |
|
|
|
if (remote_parts[i].toInt() > local_parts[i].toInt()) |
|
|
|
if (remoteParts[i].toInt() > localParts[i].toInt()) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
if (remote_parts[i].toInt() < local_parts[i].toInt()) |
|
|
|
if (remoteParts[i].toInt() < localParts[i].toInt()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
// Compared parts were equal, if remote version is longer, then it's more recent (2.9.2.1 > 2.9.2)
|
|
|
|
// Compared parts were equal, if remote version is longer, then it's more recent (2.9.2.1 > 2.9.2)
|
|
|
|
if (remote_parts.size() > local_parts.size()) |
|
|
|
if (remoteParts.size() > localParts.size()) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
// versions are equal, check if the local version is a development release, in which case it is older (2.9.2beta < 2.9.2)
|
|
|
|
// versions are equal, check if the local version is a development release, in which case it is older (2.9.2beta < 2.9.2)
|
|
|
|
QRegExp regDevel("(alpha|beta|rc)"); |
|
|
|
QRegExp regDevel("(alpha|beta|rc)"); |
|
|
|