mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-13 16:53:08 -07:00
FEATURE: qBittorrent can update itself from Sourceforge (Windows/Mac OS X only)
This commit is contained in:
parent
e3ccea3b17
commit
166dad51d5
11 changed files with 426 additions and 78 deletions
|
@ -2,6 +2,7 @@
|
||||||
- FEATURE: qBittorrent can now act as a tracker
|
- FEATURE: qBittorrent can now act as a tracker
|
||||||
- FEATURE: Added feature to shutdown qbittorrent on torrents completion
|
- FEATURE: Added feature to shutdown qbittorrent on torrents completion
|
||||||
- FEATURE: Added a torrent import assistant to seed or keep downloading outside torrents
|
- FEATURE: Added a torrent import assistant to seed or keep downloading outside torrents
|
||||||
|
- FEATURE: qBittorrent can update itself from Sourceforge (Windows/Mac OS X only)
|
||||||
- FEATURE: Added a transfer list column to display the current tracker
|
- FEATURE: Added a transfer list column to display the current tracker
|
||||||
- COSMETIC: Replaced message box by on-screen notification for download errors
|
- COSMETIC: Replaced message box by on-screen notification for download errors
|
||||||
|
|
||||||
|
|
115
src/GUI.cpp
115
src/GUI.cpp
|
@ -74,6 +74,9 @@ void qt_mac_set_dock_menu(QMenu *menu);
|
||||||
#endif
|
#endif
|
||||||
#include "lineedit.h"
|
#include "lineedit.h"
|
||||||
#include "sessionapplication.h"
|
#include "sessionapplication.h"
|
||||||
|
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
|
||||||
|
#include "programupdater.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
@ -246,6 +249,12 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
qt_mac_set_dock_menu(getTrayIconMenu());
|
qt_mac_set_dock_menu(getTrayIconMenu());
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
|
||||||
|
// Check for update
|
||||||
|
ProgramUpdater *updater = new ProgramUpdater(this);
|
||||||
|
connect(updater, SIGNAL(updateCheckFinished(bool, QString)), SLOT(handleUpdateCheckFinished(bool, QString)));
|
||||||
|
updater->checkForUpdates();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::deleteBTSession() {
|
void GUI::deleteBTSession() {
|
||||||
|
@ -523,17 +532,17 @@ void GUI::askRecursiveTorrentDownloadConfirmation(QTorrentHandle &h) {
|
||||||
QMessageBox confirmBox(QMessageBox::Question, tr("Recursive download confirmation"), tr("The torrent %1 contains torrent files, do you want to proceed with their download?").arg(h.name()));
|
QMessageBox confirmBox(QMessageBox::Question, tr("Recursive download confirmation"), tr("The torrent %1 contains torrent files, do you want to proceed with their download?").arg(h.name()));
|
||||||
QPushButton *yes = confirmBox.addButton(tr("Yes"), QMessageBox::YesRole);
|
QPushButton *yes = confirmBox.addButton(tr("Yes"), QMessageBox::YesRole);
|
||||||
/*QPushButton *no = */confirmBox.addButton(tr("No"), QMessageBox::NoRole);
|
/*QPushButton *no = */confirmBox.addButton(tr("No"), QMessageBox::NoRole);
|
||||||
QPushButton *never = confirmBox.addButton(tr("Never"), QMessageBox::NoRole);
|
QPushButton *never = confirmBox.addButton(tr("Never"), QMessageBox::NoRole);
|
||||||
confirmBox.exec();
|
confirmBox.exec();
|
||||||
if(confirmBox.clickedButton() == 0) return;
|
if(confirmBox.clickedButton() == 0) return;
|
||||||
if(confirmBox.clickedButton() == yes) {
|
if(confirmBox.clickedButton() == yes) {
|
||||||
BTSession->recursiveTorrentDownload(h);
|
BTSession->recursiveTorrentDownload(h);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(confirmBox.clickedButton() == never) {
|
if(confirmBox.clickedButton() == never) {
|
||||||
Preferences::disableRecursiveDownload();
|
Preferences::disableRecursiveDownload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
|
void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
|
||||||
// Display a message box
|
// Display a message box
|
||||||
|
@ -724,42 +733,42 @@ void GUI::on_actionCreate_torrent_triggered() {
|
||||||
bool GUI::event(QEvent * e) {
|
bool GUI::event(QEvent * e) {
|
||||||
switch(e->type()) {
|
switch(e->type()) {
|
||||||
case QEvent::WindowStateChange: {
|
case QEvent::WindowStateChange: {
|
||||||
qDebug("Window change event");
|
qDebug("Window change event");
|
||||||
//Now check to see if the window is minimised
|
//Now check to see if the window is minimised
|
||||||
if(isMinimized()) {
|
if(isMinimized()) {
|
||||||
qDebug("minimisation");
|
qDebug("minimisation");
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
if(systrayIcon && settings.value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool()) {
|
if(systrayIcon && settings.value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool()) {
|
||||||
qDebug("Has active window: %d", (int)(qApp->activeWindow() != 0));
|
qDebug("Has active window: %d", (int)(qApp->activeWindow() != 0));
|
||||||
// Check if there is a modal window
|
// Check if there is a modal window
|
||||||
bool has_modal_window = false;
|
bool has_modal_window = false;
|
||||||
foreach (QWidget *widget, QApplication::allWidgets()) {
|
foreach (QWidget *widget, QApplication::allWidgets()) {
|
||||||
if(widget->isModal()) {
|
if(widget->isModal()) {
|
||||||
has_modal_window = true;
|
has_modal_window = true;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
// Iconify if there is no modal window
|
|
||||||
if(!has_modal_window) {
|
|
||||||
qDebug("Minimize to Tray enabled, hiding!");
|
|
||||||
e->accept();
|
|
||||||
QTimer::singleShot(0, this, SLOT(hide()));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Iconify if there is no modal window
|
||||||
|
if(!has_modal_window) {
|
||||||
|
qDebug("Minimize to Tray enabled, hiding!");
|
||||||
|
e->accept();
|
||||||
|
QTimer::singleShot(0, this, SLOT(hide()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
case QEvent::ToolBarChange: {
|
case QEvent::ToolBarChange: {
|
||||||
qDebug("MAC: Received a toolbar change event!");
|
qDebug("MAC: Received a toolbar change event!");
|
||||||
bool ret = QMainWindow::event(e);
|
bool ret = QMainWindow::event(e);
|
||||||
|
|
||||||
qDebug("MAC: new toolbar visibility is %d", !actionTop_tool_bar->isChecked());
|
qDebug("MAC: new toolbar visibility is %d", !actionTop_tool_bar->isChecked());
|
||||||
actionTop_tool_bar->toggle();
|
actionTop_tool_bar->toggle();
|
||||||
Preferences::setToolbarDisplayed(actionTop_tool_bar->isChecked());
|
Preferences::setToolbarDisplayed(actionTop_tool_bar->isChecked());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1210,3 +1219,29 @@ void GUI::on_actionDownload_from_URL_triggered() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
|
||||||
|
|
||||||
|
void GUI::handleUpdateCheckFinished(bool update_available, QString new_version)
|
||||||
|
{
|
||||||
|
if(update_available) {
|
||||||
|
if(QMessageBox::question(this, tr("A newer version is available"),
|
||||||
|
tr("A newer version of qBittorrent is available on Sourceforge.\nWould you like to update qBittorrent to version %1?").arg(new_version),
|
||||||
|
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
|
||||||
|
// The user want to update, let's download the update
|
||||||
|
ProgramUpdater* updater = dynamic_cast<ProgramUpdater*>(sender());
|
||||||
|
connect(updater, SIGNAL(updateInstallFinished(QString)), SLOT(handleUpdateInstalled(QString)));
|
||||||
|
updater->updateProgram();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender()->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::handleUpdateInstalled(QString error_msg)
|
||||||
|
{
|
||||||
|
if(!error_msg.isEmpty()) {
|
||||||
|
QMessageBox::critical(this, tr("Impossible to update qBittorrent"), tr("qBittorrent failed to update, reason: %1").arg(error_msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -129,6 +129,10 @@ protected slots:
|
||||||
void optionsSaved();
|
void optionsSaved();
|
||||||
// HTTP slots
|
// HTTP slots
|
||||||
void on_actionDownload_from_URL_triggered();
|
void on_actionDownload_from_URL_triggered();
|
||||||
|
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
|
||||||
|
void handleUpdateCheckFinished(bool update_available, QString new_version);
|
||||||
|
void handleUpdateInstalled(QString error_msg);
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
|
@ -39,8 +39,6 @@
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
#include "qinisettings.h"
|
#include "qinisettings.h"
|
||||||
|
|
||||||
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5};
|
|
||||||
|
|
||||||
/** Download Thread **/
|
/** Download Thread **/
|
||||||
|
|
||||||
downloadThread::downloadThread(QObject* parent) : QObject(parent) {
|
downloadThread::downloadThread(QObject* parent) : QObject(parent) {
|
||||||
|
@ -180,7 +178,7 @@ void downloadThread::applyProxySettings() {
|
||||||
qDebug("Using proxy: %s", qPrintable(IP));
|
qDebug("Using proxy: %s", qPrintable(IP));
|
||||||
proxy.setPort(port.toUShort());
|
proxy.setPort(port.toUShort());
|
||||||
// Default proxy type is HTTP, we must change if it is SOCKS5
|
// Default proxy type is HTTP, we must change if it is SOCKS5
|
||||||
if(intValue == SOCKS5 || intValue == SOCKS5_PW) {
|
if(intValue == Proxy::SOCKS5 || intValue == Proxy::SOCKS5_PW) {
|
||||||
qDebug("Proxy is SOCKS5, not HTTP");
|
qDebug("Proxy is SOCKS5, not HTTP");
|
||||||
proxy.setType(QNetworkProxy::Socks5Proxy);
|
proxy.setType(QNetworkProxy::Socks5Proxy);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -56,7 +56,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
|
||||||
QString savePath;
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
hsplitter->setCollapsible(0, false);
|
hsplitter->setCollapsible(0, false);
|
||||||
hsplitter->setCollapsible(1, false);
|
hsplitter->setCollapsible(1, false);
|
||||||
|
@ -516,18 +515,18 @@ bool options_imp::isFilteringEnabled() const{
|
||||||
int options_imp::getPeerProxyType() const{
|
int options_imp::getPeerProxyType() const{
|
||||||
switch(comboProxyType->currentIndex()) {
|
switch(comboProxyType->currentIndex()) {
|
||||||
case 1:
|
case 1:
|
||||||
return SOCKS4;
|
return Proxy::SOCKS4;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if(isPeerProxyAuthEnabled()){
|
if(isPeerProxyAuthEnabled()){
|
||||||
return SOCKS5_PW;
|
return Proxy::SOCKS5_PW;
|
||||||
}
|
}
|
||||||
return SOCKS5;
|
return Proxy::SOCKS5;
|
||||||
case 3:
|
case 3:
|
||||||
if(isPeerProxyAuthEnabled()){
|
if(isPeerProxyAuthEnabled()){
|
||||||
return HTTP_PW;
|
return Proxy::HTTP_PW;
|
||||||
}
|
}
|
||||||
return HTTP;
|
return Proxy::HTTP;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -537,15 +536,15 @@ int options_imp::getHTTPProxyType() const {
|
||||||
switch(comboProxyType_http->currentIndex()) {
|
switch(comboProxyType_http->currentIndex()) {
|
||||||
case 1: {
|
case 1: {
|
||||||
if(isHTTPProxyAuthEnabled()){
|
if(isHTTPProxyAuthEnabled()){
|
||||||
return HTTP_PW;
|
return Proxy::HTTP_PW;
|
||||||
}
|
}
|
||||||
return HTTP;
|
return Proxy::HTTP;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
if(isHTTPProxyAuthEnabled()) {
|
if(isHTTPProxyAuthEnabled()) {
|
||||||
return SOCKS5_PW;
|
return Proxy::SOCKS5_PW;
|
||||||
}
|
}
|
||||||
return SOCKS5;
|
return Proxy::SOCKS5;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return -1; // Disabled
|
return -1; // Disabled
|
||||||
|
@ -672,15 +671,15 @@ void options_imp::loadOptions(){
|
||||||
|
|
||||||
intValue = Preferences::getPeerProxyType();
|
intValue = Preferences::getPeerProxyType();
|
||||||
switch(intValue) {
|
switch(intValue) {
|
||||||
case SOCKS4:
|
case Proxy::SOCKS4:
|
||||||
comboProxyType->setCurrentIndex(1);
|
comboProxyType->setCurrentIndex(1);
|
||||||
break;
|
break;
|
||||||
case SOCKS5:
|
case Proxy::SOCKS5:
|
||||||
case SOCKS5_PW:
|
case Proxy::SOCKS5_PW:
|
||||||
comboProxyType->setCurrentIndex(2);
|
comboProxyType->setCurrentIndex(2);
|
||||||
break;
|
break;
|
||||||
case HTTP:
|
case Proxy::HTTP:
|
||||||
case HTTP_PW:
|
case Proxy::HTTP_PW:
|
||||||
comboProxyType->setCurrentIndex(3);
|
comboProxyType->setCurrentIndex(3);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -698,12 +697,12 @@ void options_imp::loadOptions(){
|
||||||
//}
|
//}
|
||||||
intValue = Preferences::getHTTPProxyType();
|
intValue = Preferences::getHTTPProxyType();
|
||||||
switch(intValue) {
|
switch(intValue) {
|
||||||
case HTTP:
|
case Proxy::HTTP:
|
||||||
case HTTP_PW:
|
case Proxy::HTTP_PW:
|
||||||
comboProxyType_http->setCurrentIndex(1);
|
comboProxyType_http->setCurrentIndex(1);
|
||||||
break;
|
break;
|
||||||
case SOCKS5:
|
case Proxy::SOCKS5:
|
||||||
case SOCKS5_PW:
|
case Proxy::SOCKS5_PW:
|
||||||
comboProxyType_http->setCurrentIndex(2);
|
comboProxyType_http->setCurrentIndex(2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
#include "ui_options.h"
|
#include "ui_options.h"
|
||||||
#include <libtorrent/ip_filter.hpp>
|
#include <libtorrent/ip_filter.hpp>
|
||||||
|
|
||||||
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5};
|
|
||||||
|
|
||||||
// actions on double-click on torrents
|
// actions on double-click on torrents
|
||||||
enum DoubleClickAction {TOGGLE_PAUSE, OPEN_DEST, NO_ACTION};
|
enum DoubleClickAction {TOGGLE_PAUSE, OPEN_DEST, NO_ACTION};
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,9 @@
|
||||||
#define QBT_REALM "Web UI Access"
|
#define QBT_REALM "Web UI Access"
|
||||||
enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN };
|
enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN };
|
||||||
enum maxRatioAction {PAUSE_ACTION, REMOVE_ACTION};
|
enum maxRatioAction {PAUSE_ACTION, REMOVE_ACTION};
|
||||||
|
namespace Proxy {
|
||||||
|
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5};
|
||||||
|
}
|
||||||
|
|
||||||
class Preferences {
|
class Preferences {
|
||||||
public:
|
public:
|
||||||
|
|
233
src/programupdater.cpp
Normal file
233
src/programupdater.cpp
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt4 and libtorrent.
|
||||||
|
* Copyright (C) 2010 Christophe Dumez
|
||||||
|
*
|
||||||
|
* 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 2
|
||||||
|
* 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, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*
|
||||||
|
* Contact : chris@qbittorrent.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
#include <QNetworkProxy>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
#include "programupdater.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "preferences.h"
|
||||||
|
|
||||||
|
#ifdef Q_WS_MAC
|
||||||
|
const QString RSS_URL = "http://sourceforge.net/api/file/index/project-id/163414/mtime/desc/rss?path=/qbittorrent-mac";
|
||||||
|
const QString FILE_EXT = "DMG";
|
||||||
|
#else
|
||||||
|
const QString RSS_URL = "http://sourceforge.net/api/file/index/project-id/163414/mtime/desc/rss?path=/qbittorrent-win32";
|
||||||
|
const QString FILE_EXT = "EXE";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ProgramUpdater::ProgramUpdater(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
mp_manager = new QNetworkAccessManager(this);
|
||||||
|
// Proxy support
|
||||||
|
if(Preferences::isHTTPProxyEnabled()) {
|
||||||
|
QNetworkProxy proxy;
|
||||||
|
switch(Preferences::getHTTPProxyType()) {
|
||||||
|
case Proxy::SOCKS4:
|
||||||
|
case Proxy::SOCKS5:
|
||||||
|
case Proxy::SOCKS5_PW:
|
||||||
|
proxy.setType(QNetworkProxy::Socks5Proxy);
|
||||||
|
default:
|
||||||
|
proxy.setType(QNetworkProxy::HttpProxy);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
proxy.setHostName(Preferences::getHTTPProxyIp());
|
||||||
|
proxy.setPort(Preferences::getHTTPProxyPort());
|
||||||
|
// Proxy authentication
|
||||||
|
if(Preferences::isHTTPProxyAuthEnabled()) {
|
||||||
|
proxy.setUser(Preferences::getHTTPProxyUsername());
|
||||||
|
proxy.setPassword(Preferences::getHTTPProxyPassword());
|
||||||
|
}
|
||||||
|
mp_manager->setProxy(proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgramUpdater::~ProgramUpdater() {
|
||||||
|
delete mp_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramUpdater::checkForUpdates()
|
||||||
|
{
|
||||||
|
// SIGNAL/SLOT
|
||||||
|
connect(mp_manager, SIGNAL(finished(QNetworkReply*)),
|
||||||
|
this, SLOT(rssDownloadFinished(QNetworkReply*)));
|
||||||
|
// Send the request
|
||||||
|
mp_manager->get(QNetworkRequest(QUrl(RSS_URL)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramUpdater::setUpdateUrl(QString title) {
|
||||||
|
m_updateUrl = "http://downloads.sourceforge.net/project/qbittorrent"+title;
|
||||||
|
qDebug("The Update URL is %s", qPrintable(m_updateUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
// Disconnect SIGNAL/SLOT
|
||||||
|
disconnect(mp_manager, 0, this, 0);
|
||||||
|
qDebug("Finished downloading the new qBittorrent updates RSS");
|
||||||
|
QString new_version;
|
||||||
|
if(!reply->error()) {
|
||||||
|
qDebug("No download error, good.");
|
||||||
|
QXmlStreamReader xml(reply);
|
||||||
|
QString item_title;
|
||||||
|
bool in_title = false;
|
||||||
|
bool in_item = false;
|
||||||
|
while (!xml.atEnd()) {
|
||||||
|
xml.readNext();
|
||||||
|
if (xml.isStartElement()) {
|
||||||
|
if (in_item && xml.name() == "title") {
|
||||||
|
in_title = true;
|
||||||
|
item_title = "";
|
||||||
|
} else if (xml.name() == "item") {
|
||||||
|
in_item = true;
|
||||||
|
}
|
||||||
|
} else if (xml.isEndElement()) {
|
||||||
|
if(in_item && xml.name() == "title") {
|
||||||
|
in_title = false;
|
||||||
|
const QString ext = misc::file_extension(item_title).toUpper();
|
||||||
|
qDebug("Found an update with file extension: %s", qPrintable(ext));
|
||||||
|
if(ext == FILE_EXT) {
|
||||||
|
qDebug("The last update available is %s", qPrintable(item_title));
|
||||||
|
new_version = extractVersionNumber(item_title);
|
||||||
|
if(!new_version.isEmpty()) {
|
||||||
|
qDebug("Detected version is %s", qPrintable(new_version));
|
||||||
|
if(isVersionMoreRecent(new_version))
|
||||||
|
setUpdateUrl(item_title);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (xml.name() == "item") {
|
||||||
|
in_item = false;
|
||||||
|
}
|
||||||
|
} else if (xml.isCharacters() && !xml.isWhitespace()) {
|
||||||
|
if(in_item && in_title)
|
||||||
|
item_title += xml.text().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit updateCheckFinished(!m_updateUrl.isEmpty(), new_version);
|
||||||
|
// Clean up
|
||||||
|
reply->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramUpdater::updateProgram()
|
||||||
|
{
|
||||||
|
Q_ASSERT(!m_updateUrl.isEmpty());
|
||||||
|
connect(mp_manager, SIGNAL(finished(QNetworkReply*)),
|
||||||
|
this, SLOT(saveUpdate(QNetworkReply*)));
|
||||||
|
// Send the request
|
||||||
|
mp_manager->get(QNetworkRequest(QUrl(m_updateUrl)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramUpdater::saveUpdate(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
// Disconnect SIGNAL/SLOT
|
||||||
|
disconnect(mp_manager, 0, this, 0);
|
||||||
|
// Process the download
|
||||||
|
if(!reply->error()) {
|
||||||
|
// Save the file
|
||||||
|
const QString installer_path = QDir::temp().absoluteFilePath("qbittorrent_update."+FILE_EXT.toLower());
|
||||||
|
QFile update_installer(installer_path);
|
||||||
|
if(update_installer.exists()) {
|
||||||
|
update_installer.remove();
|
||||||
|
}
|
||||||
|
if(update_installer.open(QIODevice::WriteOnly)) {
|
||||||
|
update_installer.write(reply->readAll());
|
||||||
|
reply->close();
|
||||||
|
update_installer.close();
|
||||||
|
// Install the update
|
||||||
|
installUpdate(installer_path);
|
||||||
|
} else {
|
||||||
|
emit updateInstallFinished(tr("Could not create the file %1").arg(installer_path));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emit updateInstallFinished(tr("Failed to download the update at %1", "%1 is an URL").arg(m_updateUrl));
|
||||||
|
}
|
||||||
|
reply->deleteLater();
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramUpdater::installUpdate(QString update_path)
|
||||||
|
{
|
||||||
|
qDebug("Installing the update...");
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
QDesktopServices::openUrl(QUrl(QString("file:///")+update_path, QUrl::TolerantMode));
|
||||||
|
#else
|
||||||
|
QDesktopServices::openUrl(QUrl(QString("file://")+update_path, QUrl::TolerantMode));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// title on Windows: /qbittorrent-win32/qbittorrent-2.4.7/qbittorrent_2.4.7_setup.exe
|
||||||
|
// title on Mac: /qbittorrent-mac/qbittorrent-2.4.4/qbittorrent-2.4.4.dmg
|
||||||
|
QString ProgramUpdater::extractVersionNumber(QString title) const
|
||||||
|
{
|
||||||
|
QString version;
|
||||||
|
QStringList parts = title.split("/");
|
||||||
|
if(parts.size() != 4) {
|
||||||
|
qDebug("ProgramUpdater: Unrecognized title: %s", qPrintable(title));
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
QString folder = parts.at(2);
|
||||||
|
if(!folder.contains("-")) {
|
||||||
|
qDebug("ProgramUpdater: Unrecognized folder name: %s", qPrintable(folder));
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
version = folder.mid(folder.lastIndexOf("-")+1);
|
||||||
|
if(version.split(".").size() != 3) {
|
||||||
|
qDebug("ProgramUpdater: Unrecognized version format: %s", qPrintable(version));
|
||||||
|
return QString::null;
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProgramUpdater::isVersionMoreRecent(QString new_version) const
|
||||||
|
{
|
||||||
|
/*DEFINES += VERSION_MAJOR=2
|
||||||
|
DEFINES += VERSION_MINOR=5
|
||||||
|
DEFINES += VERSION_BUGFIX=0*/
|
||||||
|
const QStringList parts = new_version.split(".");
|
||||||
|
Q_ASSERT(parts.size() == 3);
|
||||||
|
const int major = parts.at(0).toInt();
|
||||||
|
const int minor = parts.at(1).toInt();
|
||||||
|
const int bugfix = parts.at(2).toInt();
|
||||||
|
if(major < VERSION_MAJOR)
|
||||||
|
return false;
|
||||||
|
if(minor < VERSION_MINOR)
|
||||||
|
return false;
|
||||||
|
if(bugfix <= VERSION_BUGFIX)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
68
src/programupdater.h
Normal file
68
src/programupdater.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt4 and libtorrent.
|
||||||
|
* Copyright (C) 2010 Christophe Dumez
|
||||||
|
*
|
||||||
|
* 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 2
|
||||||
|
* 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, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*
|
||||||
|
* Contact : chris@qbittorrent.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PROGRAMUPDATER_H
|
||||||
|
#define PROGRAMUPDATER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
class QNetworkReply;
|
||||||
|
class QNetworkAccessManager;
|
||||||
|
|
||||||
|
class ProgramUpdater : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ProgramUpdater(QObject *parent = 0);
|
||||||
|
~ProgramUpdater();
|
||||||
|
void checkForUpdates();
|
||||||
|
void updateProgram();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString extractVersionNumber(QString title) const;
|
||||||
|
bool isVersionMoreRecent(QString new_version) const;
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void rssDownloadFinished(QNetworkReply* reply);
|
||||||
|
void installUpdate(QString update_path);
|
||||||
|
void saveUpdate(QNetworkReply* reply);
|
||||||
|
void setUpdateUrl(QString title);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void updateCheckFinished(bool update_available, QString version);
|
||||||
|
void updateInstallFinished(QString error);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_updateUrl;
|
||||||
|
QNetworkAccessManager *mp_manager;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PROGRAMUPDATER_H
|
|
@ -70,7 +70,6 @@
|
||||||
|
|
||||||
const int MAX_TRACKER_ERRORS = 2;
|
const int MAX_TRACKER_ERRORS = 2;
|
||||||
const float MAX_RATIO = 100.;
|
const float MAX_RATIO = 100.;
|
||||||
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5};
|
|
||||||
enum VersionType { NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL };
|
enum VersionType { NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL };
|
||||||
|
|
||||||
// Main constructor
|
// Main constructor
|
||||||
|
@ -543,21 +542,21 @@ void QBtSession::configureSession() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch(Preferences::getPeerProxyType()) {
|
switch(Preferences::getPeerProxyType()) {
|
||||||
case HTTP:
|
case Proxy::HTTP:
|
||||||
qDebug("type: http");
|
qDebug("type: http");
|
||||||
proxySettings.type = proxy_settings::http;
|
proxySettings.type = proxy_settings::http;
|
||||||
break;
|
break;
|
||||||
case HTTP_PW:
|
case Proxy::HTTP_PW:
|
||||||
qDebug("type: http_pw");
|
qDebug("type: http_pw");
|
||||||
proxySettings.type = proxy_settings::http_pw;
|
proxySettings.type = proxy_settings::http_pw;
|
||||||
break;
|
break;
|
||||||
case SOCKS4:
|
case Proxy::SOCKS4:
|
||||||
proxySettings.type = proxy_settings::socks4;
|
proxySettings.type = proxy_settings::socks4;
|
||||||
case SOCKS5:
|
case Proxy::SOCKS5:
|
||||||
qDebug("type: socks5");
|
qDebug("type: socks5");
|
||||||
proxySettings.type = proxy_settings::socks5;
|
proxySettings.type = proxy_settings::socks5;
|
||||||
break;
|
break;
|
||||||
case SOCKS5_PW:
|
case Proxy::SOCKS5_PW:
|
||||||
qDebug("type: socks5_pw");
|
qDebug("type: socks5_pw");
|
||||||
proxySettings.type = proxy_settings::socks5_pw;
|
proxySettings.type = proxy_settings::socks5_pw;
|
||||||
break;
|
break;
|
||||||
|
@ -569,24 +568,24 @@ void QBtSession::configureSession() {
|
||||||
proxy_settings http_proxySettings;
|
proxy_settings http_proxySettings;
|
||||||
qDebug("HTTP Communications proxy type: %d", Preferences::getHTTPProxyType());
|
qDebug("HTTP Communications proxy type: %d", Preferences::getHTTPProxyType());
|
||||||
switch(Preferences::getHTTPProxyType()) {
|
switch(Preferences::getHTTPProxyType()) {
|
||||||
case HTTP_PW:
|
case Proxy::HTTP_PW:
|
||||||
http_proxySettings.type = proxy_settings::http_pw;
|
http_proxySettings.type = proxy_settings::http_pw;
|
||||||
http_proxySettings.username = Preferences::getHTTPProxyUsername().toStdString();
|
http_proxySettings.username = Preferences::getHTTPProxyUsername().toStdString();
|
||||||
http_proxySettings.password = Preferences::getHTTPProxyPassword().toStdString();
|
http_proxySettings.password = Preferences::getHTTPProxyPassword().toStdString();
|
||||||
http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString();
|
http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString();
|
||||||
http_proxySettings.port = Preferences::getHTTPProxyPort();
|
http_proxySettings.port = Preferences::getHTTPProxyPort();
|
||||||
break;
|
break;
|
||||||
case HTTP:
|
case Proxy::HTTP:
|
||||||
http_proxySettings.type = proxy_settings::http;
|
http_proxySettings.type = proxy_settings::http;
|
||||||
http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString();
|
http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString();
|
||||||
http_proxySettings.port = Preferences::getHTTPProxyPort();
|
http_proxySettings.port = Preferences::getHTTPProxyPort();
|
||||||
break;
|
break;
|
||||||
case SOCKS5:
|
case Proxy::SOCKS5:
|
||||||
http_proxySettings.type = proxy_settings::socks5;
|
http_proxySettings.type = proxy_settings::socks5;
|
||||||
http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString();
|
http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString();
|
||||||
http_proxySettings.port = Preferences::getHTTPProxyPort();
|
http_proxySettings.port = Preferences::getHTTPProxyPort();
|
||||||
break;
|
break;
|
||||||
case SOCKS5_PW:
|
case Proxy::SOCKS5_PW:
|
||||||
http_proxySettings.type = proxy_settings::socks5_pw;
|
http_proxySettings.type = proxy_settings::socks5_pw;
|
||||||
http_proxySettings.username = Preferences::getHTTPProxyUsername().toStdString();
|
http_proxySettings.username = Preferences::getHTTPProxyUsername().toStdString();
|
||||||
http_proxySettings.password = Preferences::getHTTPProxyPassword().toStdString();
|
http_proxySettings.password = Preferences::getHTTPProxyPassword().toStdString();
|
||||||
|
|
18
src/src.pro
18
src/src.pro
|
@ -12,9 +12,9 @@ CONFIG += qt \
|
||||||
|
|
||||||
# Update this VERSION for each release
|
# Update this VERSION for each release
|
||||||
os2 {
|
os2 {
|
||||||
DEFINES += VERSION=\'\"v2.5.0beta1\"\'
|
DEFINES += VERSION=\'\"v2.5.0beta2\"\'
|
||||||
} else {
|
} else {
|
||||||
DEFINES += VERSION=\\\"v2.5.0beta1\\\"
|
DEFINES += VERSION=\\\"v2.5.0beta2\\\"
|
||||||
}
|
}
|
||||||
DEFINES += VERSION_MAJOR=2
|
DEFINES += VERSION_MAJOR=2
|
||||||
DEFINES += VERSION_MINOR=5
|
DEFINES += VERSION_MINOR=5
|
||||||
|
@ -312,8 +312,13 @@ contains(DEFINES, DISABLE_GUI) {
|
||||||
torrentcreatordlg.h \
|
torrentcreatordlg.h \
|
||||||
torrentimportdlg.h
|
torrentimportdlg.h
|
||||||
|
|
||||||
|
win32 {
|
||||||
|
HEADERS += programupdater.h
|
||||||
|
}
|
||||||
|
|
||||||
macx {
|
macx {
|
||||||
HEADERS += qmacapplication.h
|
HEADERS += qmacapplication.h \
|
||||||
|
programupdater.h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,8 +387,13 @@ SOURCES += main.cpp \
|
||||||
torrentcreatordlg.cpp \
|
torrentcreatordlg.cpp \
|
||||||
torrentimportdlg.cpp
|
torrentimportdlg.cpp
|
||||||
|
|
||||||
|
win32 {
|
||||||
|
SOURCES += programupdater.cpp
|
||||||
|
}
|
||||||
|
|
||||||
macx {
|
macx {
|
||||||
SOURCES += qmacapplication.cpp
|
SOURCES += qmacapplication.cpp \
|
||||||
|
programupdater.cpp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue