From 07ee2a4aff13ab901de89ab8ad513b79bc0a3211 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 10:23:41 +0000 Subject: [PATCH 01/11] Branched for work on headless running --- src/search_engine/helpers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/search_engine/helpers.py b/src/search_engine/helpers.py index 111b5f71f..e45fc41df 100644 --- a/src/search_engine/helpers.py +++ b/src/search_engine/helpers.py @@ -22,16 +22,15 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -#VERSION: 1.1 +#VERSION: 1.2 # Author: # Christophe DUMEZ (chris@qbittorrent.org) import re, htmlentitydefs -import urllib2 import tempfile import os -import StringIO, gzip, httplib +import StringIO, gzip, urllib2 def htmlentitydecode(s): # First convert alpha entities (such as é) @@ -64,12 +63,14 @@ def retrieve_url(url): dat = htmlentitydecode(dat) return dat.encode('utf-8', 'replace') -def download_file(url): +def download_file(url, referer=None): """ Download file at url and write it to a file, return the path to the file and the url """ file, path = tempfile.mkstemp() file = os.fdopen(file, "w") # Download url req = urllib2.Request(url) + if referer is not None: + req.add_header('referer', referer) response = urllib2.urlopen(req) dat = response.read() # Check if data is gzip encoded From 0b7ca15c4fe5f483951bf62a7f601e01240d91e1 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 10:36:18 +0000 Subject: [PATCH 02/11] - Added --disable-gui flag to configure file (adds DISABLE_GUI define) --- configure | 21 +++++++++++++++++++++ qcm/geoip-database.qcm | 4 ++++ qcm/libnotify.qcm | 4 ++++ qcm/qt4.qcm | 4 ++++ 4 files changed, 33 insertions(+) diff --git a/configure b/configure index 698423dff..8b0a95f1c 100755 --- a/configure +++ b/configure @@ -18,6 +18,8 @@ Main options: --help This help text. Dependency options: + --disable-gui Disable qBittorrent Graphical user + interface for headless running --with-libboost-inc=[path] Path to libboost include files --disable-libnotify Disable use of libnotify --disable-geoip-database Disable use of geoip-database @@ -140,6 +142,11 @@ while [ $# -gt 0 ]; do shift ;; + --disable-gui) + QC_DISABLE_GUI="Y" + shift + ;; + --with-libboost-inc=*) QC_WITH_LIBBOOST_INC=$optarg shift @@ -181,6 +188,7 @@ echo PREFIX=$PREFIX echo BINDIR=$BINDIR echo DATADIR=$DATADIR echo EX_QTDIR=$EX_QTDIR +echo QC_DISABLE_GUI=$QC_DISABLE_GUI echo QC_WITH_LIBBOOST_INC=$QC_WITH_LIBBOOST_INC echo QC_DISABLE_libnotify=$QC_DISABLE_libnotify echo QC_DISABLE_geoip_database=$QC_DISABLE_geoip_database @@ -290,6 +298,7 @@ cat >$1/modules.cpp <= 4.4 +arg: disable-gui, Disable qBittorrent Graphical user interface for headless running -----END QCMOD----- */ class qc_qt4 : public ConfObj @@ -300,6 +309,9 @@ public: QString shortname() const { return "Qt 4.4"; } bool exec() { + if(!conf->getenv("QC_DISABLE_GUI").isEmpty()) { + conf->addDefine("DISABLE_GUI"); + } if(QT_VERSION >= 0x040500) { conf->addDefine("QT_4_5"); } @@ -410,6 +422,10 @@ public: QString name() const { return "libnotify >= 0.4.2 (optional)"; } QString shortname() const { return "libnotify"; } bool exec(){ + if(!conf->getenv("QC_DISABLE_GUI").isEmpty()) { + printf("\nNot Required"); + return true; + } QStringList incs; QString req_ver = "0.4.2"; QString version, libs, other; @@ -453,6 +469,10 @@ public: QString name() const { return "GeoIP Database (optional)"; } QString shortname() const { return "GeoIP Database"; } bool exec() { + if(!conf->getenv("QC_DISABLE_GUI").isEmpty()) { + printf("\nNot Required"); + return true; + } #ifdef Q_WS_X11 if(!conf->getenv("QC_WITH_GEOIP_DATABASE_EMBEDDED").isEmpty()) { #endif @@ -1431,6 +1451,7 @@ export PREFIX export BINDIR export DATADIR export EX_QTDIR +export QC_DISABLE_GUI export QC_WITH_LIBBOOST_INC export QC_DISABLE_libnotify export QC_DISABLE_geoip_database diff --git a/qcm/geoip-database.qcm b/qcm/geoip-database.qcm index f5fb0854d..9c21afdba 100644 --- a/qcm/geoip-database.qcm +++ b/qcm/geoip-database.qcm @@ -12,6 +12,10 @@ public: QString name() const { return "GeoIP Database (optional)"; } QString shortname() const { return "GeoIP Database"; } bool exec() { + if(!conf->getenv("QC_DISABLE_GUI").isEmpty()) { + printf("\nNot Required"); + return true; + } #ifdef Q_WS_X11 if(!conf->getenv("QC_WITH_GEOIP_DATABASE_EMBEDDED").isEmpty()) { #endif diff --git a/qcm/libnotify.qcm b/qcm/libnotify.qcm index cc55aa4b2..415c80133 100644 --- a/qcm/libnotify.qcm +++ b/qcm/libnotify.qcm @@ -11,6 +11,10 @@ public: QString name() const { return "libnotify >= 0.4.2 (optional)"; } QString shortname() const { return "libnotify"; } bool exec(){ + if(!conf->getenv("QC_DISABLE_GUI").isEmpty()) { + printf("\nNot Required"); + return true; + } QStringList incs; QString req_ver = "0.4.2"; QString version, libs, other; diff --git a/qcm/qt4.qcm b/qcm/qt4.qcm index 5866ebe5a..59b564275 100644 --- a/qcm/qt4.qcm +++ b/qcm/qt4.qcm @@ -1,6 +1,7 @@ /* -----BEGIN QCMOD----- name: Qt >= 4.4 +arg: disable-gui, Disable qBittorrent Graphical user interface for headless running -----END QCMOD----- */ class qc_qt4 : public ConfObj @@ -11,6 +12,9 @@ public: QString shortname() const { return "Qt 4.4"; } bool exec() { + if(!conf->getenv("QC_DISABLE_GUI").isEmpty()) { + conf->addDefine("DISABLE_GUI"); + } if(QT_VERSION >= 0x040500) { conf->addDefine("QT_4_5"); } From e2aaf5d1de35e05a452b4c398bd54e298a77a5eb Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 10:56:41 +0000 Subject: [PATCH 03/11] - Edited project file in order not to compile UI classes when DISABLE_GUI is defined - Added #ifndef directives to main.cpp in order to fix compilation when DISABLE_GUI is defined --- src/main.cpp | 51 +++++++++++----- src/src.pro | 160 +++++++++++++++++++++++++++------------------------ 2 files changed, 123 insertions(+), 88 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 248cd1bfc..94172577c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,21 +32,27 @@ #include #include #include -#include + +#ifndef DIABLE_GUI + #include + #include + #include "qgnomelook.h" + #include + #include + #ifdef Q_WS_WIN + #include + #endif + #ifdef Q_WS_MAC + #include + #endif + #include "GUI.h" + #include "ico.h" +#endif + #include #include #include #include -#include -#include "qgnomelook.h" -#include -#include -#ifdef Q_WS_WIN -#include -#endif -#ifdef Q_WS_MAC -#include -#endif #ifndef Q_WS_WIN #include #include @@ -54,9 +60,7 @@ #endif #include -#include "GUI.h" #include "misc.h" -#include "ico.h" QApplication *app; @@ -81,6 +85,7 @@ void sigabrtHandler(int) { } #endif +#ifndef DISABLE_GUI void useStyle(QApplication *app, int style){ switch(style) { case 1: @@ -113,13 +118,16 @@ void useStyle(QApplication *app, int style){ } } } +#endif // Main int main(int argc, char *argv[]){ QFile file; QString locale; QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); +#ifndef DISABLE_GUI bool no_splash = false; +#endif if(argc > 1){ if(QString::fromUtf8(argv[1]) == QString::fromUtf8("--version")){ std::cout << "qBittorrent " << VERSION << '\n'; @@ -128,18 +136,24 @@ int main(int argc, char *argv[]){ if(QString::fromUtf8(argv[1]) == QString::fromUtf8("--help")){ std::cout << "Usage: \n"; std::cout << '\t' << argv[0] << " --version : displays program version\n"; +#ifndef DISABLE_GUI std::cout << '\t' << argv[0] << " --no-splash : disable splash screen\n"; +#endif std::cout << '\t' << argv[0] << " --help : displays this help message\n"; std::cout << '\t' << argv[0] << " [files or urls] : starts program and download given parameters (optional)\n"; return 0; } +#ifndef DISABLE_GUI if(QString::fromUtf8(argv[1]) == QString::fromUtf8("--no-splash")){ no_splash = true; } +#endif } +#ifndef DISABLE_GUI if(settings.value(QString::fromUtf8("Preferences/General/NoSplashScreen"), false).toBool()) { no_splash = true; } +#endif // Set environment variable if(putenv((char*)"QBITTORRENT="VERSION)) { std::cerr << "Couldn't set environment variable...\n"; @@ -173,6 +187,7 @@ int main(int argc, char *argv[]){ return 0; } app = new QApplication(argc, argv); +#ifndef DISABLE_GUI useStyle(app, settings.value("Preferences/General/Style", 0).toInt()); app->setStyleSheet("QStatusBar::item { border-width: 0; }"); QSplashScreen *splash = 0; @@ -180,6 +195,7 @@ int main(int argc, char *argv[]){ splash = new QSplashScreen(QPixmap(QString::fromUtf8(":/Icons/skin/splash.png"))); splash->show(); } +#endif // Open options file to read locale locale = settings.value(QString::fromUtf8("Preferences/General/Locale"), QString()).toString(); QTranslator translator; @@ -194,7 +210,9 @@ int main(int argc, char *argv[]){ } app->installTranslator(&translator); app->setApplicationName(QString::fromUtf8("qBittorrent")); +#ifndef DISABLE_GUI app->setQuitOnLastWindowClosed(false); +#endif #ifndef Q_WS_WIN signal(SIGABRT, sigabrtHandler); signal(SIGTERM, sigtermHandler); @@ -204,14 +222,21 @@ int main(int argc, char *argv[]){ QStringList torrentCmdLine = app->arguments(); // Remove first argument (program name) torrentCmdLine.removeFirst(); +#ifndef DISABLE_GUI GUI *window = new GUI(0, torrentCmdLine); if(!no_splash) { splash->finish(window); delete splash; } +#else + // Load Headless class + // TODO: by Frederic Lassabe +#endif int ret = app->exec(); +#ifndef DISABLE_GUI delete window; qDebug("GUI was deleted!"); +#endif qDebug("Deleting app..."); delete app; qDebug("App was deleted! All good."); diff --git a/src/src.pro b/src/src.pro index 27d5c4d27..585ca5a66 100644 --- a/src/src.pro +++ b/src/src.pro @@ -170,28 +170,10 @@ TRANSLATIONS = $$LANG_PATH/qbittorrent_fr.ts \ $$LANG_PATH/qbittorrent_sr.ts # Source code -HEADERS += GUI.h \ - misc.h \ - options_imp.h \ - about_imp.h \ - createtorrent_imp.h \ - searchlistdelegate.h \ - proplistdelegate.h \ - previewselect.h \ - previewlistdelegate.h \ - trackerlogin.h \ +HEADERS += misc.h \ downloadthread.h \ - downloadfromurldlg.h \ - torrentadditiondlg.h \ bittorrent.h \ - searchEngine.h \ - rss.h \ - rss_imp.h \ - speedlimitdlg.h \ qtorrenthandle.h \ - engineselectdlg.h \ - pluginsource.h \ - qgnomelook.h \ httpserver.h \ httpconnection.h \ httprequestparser.h \ @@ -199,70 +181,98 @@ HEADERS += GUI.h \ json.h \ eventmanager.h \ filterparserthread.h \ - trackersadditiondlg.h \ - searchtab.h \ - console_imp.h \ - ico.h \ stacktrace.h \ torrentpersistentdata.h \ - feeddownloader.h \ - feedList.h \ - supportedengines.h \ - transferlistwidget.h \ - transferlistdelegate.h \ - transferlistfilterswidget.h \ - propertieswidget.h \ - torrentfilesmodel.h \ filesystemwatcher.h \ - peerlistwidget.h \ - peerlistdelegate.h \ - reverseresolution.h \ - preferences.h \ - geoip.h \ - peeraddition.h \ - deletionconfirmationdlg.h \ - statusbar.h \ - trackerlist.h \ - downloadedpiecesbar.h \ - pieceavailabilitybar.h -FORMS += ui/mainwindow.ui \ - ui/options.ui \ - ui/about.ui \ - ui/createtorrent.ui \ - ui/preview.ui \ - ui/login.ui \ - ui/downloadfromurldlg.ui \ - ui/torrentadditiondlg.ui \ - ui/search.ui \ - ui/rss.ui \ - ui/bandwidth_limit.ui \ - ui/engineselect.ui \ - ui/pluginsource.ui \ - ui/trackersadditiondlg.ui \ - ui/console.ui \ - ui/feeddownloader.ui \ - ui/propertieswidget.ui \ - ui/peer.ui \ - ui/confirmdeletiondlg.ui -SOURCES += GUI.cpp \ - main.cpp \ - options_imp.cpp \ - createtorrent_imp.cpp \ + preferences.h + +!contains(DEFINES, DISABLE_GUI) { + FORMS += GUI.h \ + feedList.h \ + supportedengines.h \ + transferlistwidget.h \ + transferlistdelegate.h \ + transferlistfilterswidget.h \ + propertieswidget.h \ + torrentfilesmodel.h \ + geoip.h \ + peeraddition.h \ + deletionconfirmationdlg.h \ + statusbar.h \ + trackerlist.h \ + downloadedpiecesbar.h \ + peerlistwidget.h \ + peerlistdelegate.h \ + reverseresolution.h \ + feeddownloader.h \ + trackersadditiondlg.h \ + searchtab.h \ + console_imp.h \ + ico.h \ + engineselectdlg.h \ + pluginsource.h \ + qgnomelook.h \ + searchEngine.h \ + rss.h \ + rss_imp.h \ + speedlimitdlg.h \ + options_imp.h \ + about_imp.h \ + createtorrent_imp.h \ + searchlistdelegate.h \ + proplistdelegate.h \ + previewselect.h \ + previewlistdelegate.h \ + downloadfromurldlg.h \ + torrentadditiondlg.h \ + trackerlogin.h \ + pieceavailabilitybar.h +} + +!contains(DEFINES, DISABLE_GUI) { + FORMS += ui/mainwindow.ui \ + ui/options.ui \ + ui/about.ui \ + ui/createtorrent.ui \ + ui/preview.ui \ + ui/login.ui \ + ui/downloadfromurldlg.ui \ + ui/torrentadditiondlg.ui \ + ui/search.ui \ + ui/rss.ui \ + ui/bandwidth_limit.ui \ + ui/engineselect.ui \ + ui/pluginsource.ui \ + ui/trackersadditiondlg.ui \ + ui/console.ui \ + ui/feeddownloader.ui \ + ui/propertieswidget.ui \ + ui/peer.ui \ + ui/confirmdeletiondlg.ui +} +SOURCES += main.cpp \ bittorrent.cpp \ - searchengine.cpp \ - rss_imp.cpp \ qtorrenthandle.cpp \ - engineselectdlg.cpp \ downloadthread.cpp \ httpserver.cpp \ httpconnection.cpp \ httprequestparser.cpp \ httpresponsegenerator.cpp \ - eventmanager.cpp \ - searchtab.cpp \ - ico.cpp \ - rss.cpp \ - transferlistwidget.cpp \ - propertieswidget.cpp \ - peerlistwidget.cpp + eventmanager.cpp + +!contains(DEFINES, DISABLE_GUI) { + SOURCES += GUI.cpp \ + options_imp.cpp \ + createtorrent_imp.cpp \ + searchengine.cpp \ + rss_imp.cpp \ + engineselectdlg.cpp \ + searchtab.cpp \ + ico.cpp \ + rss.cpp \ + transferlistwidget.cpp \ + propertieswidget.cpp \ + peerlistwidget.cpp +} + DESTDIR = . From af166f53d391212c58766ec25537d67b3d09f44b Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 11:08:22 +0000 Subject: [PATCH 04/11] - Added headlessloader class to prepare Fred's work --- src/headlessloader.h | 43 +++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 7 ++++++- src/src.pro | 4 +++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/headlessloader.h diff --git a/src/headlessloader.h b/src/headlessloader.h new file mode 100644 index 000000000..46c241f98 --- /dev/null +++ b/src/headlessloader.h @@ -0,0 +1,43 @@ +/* + * Bittorrent Client using Qt4 and libtorrent. + * Copyright (C) 2006 Christophe Dumez, Frédéric Lassabe + * + * 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 HEADLESSLOADER_H +#define HEADLESSLOADER_H + +#include + +class HeadlessLoader: QObject { + public: + HeadlessLoader() { + + } +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp index 94172577c..a47398d10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ #include #include -#ifndef DIABLE_GUI +#ifndef DISABLE_GUI #include #include #include "qgnomelook.h" @@ -47,6 +47,8 @@ #endif #include "GUI.h" #include "ico.h" +#else + #include "headlessloader.h" #endif #include @@ -231,11 +233,14 @@ int main(int argc, char *argv[]){ #else // Load Headless class // TODO: by Frederic Lassabe + HeadlessLoader *loader = new HeadlessLoader(); #endif int ret = app->exec(); #ifndef DISABLE_GUI delete window; qDebug("GUI was deleted!"); +#else + delete loader; #endif qDebug("Deleting app..."); delete app; diff --git a/src/src.pro b/src/src.pro index 585ca5a66..4f9698b6e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -186,7 +186,9 @@ HEADERS += misc.h \ filesystemwatcher.h \ preferences.h -!contains(DEFINES, DISABLE_GUI) { +contains(DEFINES, DISABLE_GUI) { + HEADERS += headlessloader.h +} else { FORMS += GUI.h \ feedList.h \ supportedengines.h \ From c7ccf39abfc397bdd55570a29ebec4bbaea75731 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 11:10:47 +0000 Subject: [PATCH 05/11] - Use QCoreApplication instead of QApplication when GUI is disabled --- src/main.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a47398d10..4a3a2116b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,12 +28,12 @@ * Contact : chris@qbittorrent.org */ -#include #include #include #include #ifndef DISABLE_GUI + #include #include #include #include "qgnomelook.h" @@ -48,6 +48,7 @@ #include "GUI.h" #include "ico.h" #else + #include #include "headlessloader.h" #endif @@ -64,7 +65,11 @@ #include #include "misc.h" -QApplication *app; +#ifdef DISABLE_GUI + QCoreApplication *app; +#else + QApplication *app; +#endif #ifndef Q_WS_WIN void sigtermHandler(int) { @@ -188,7 +193,11 @@ int main(int argc, char *argv[]){ localSocket.close(); return 0; } +#ifdef DISABLE_GUI + app = new QCoreApplication(argc, argv); +#else app = new QApplication(argc, argv); +#endif #ifndef DISABLE_GUI useStyle(app, settings.value("Preferences/General/Style", 0).toInt()); app->setStyleSheet("QStatusBar::item { border-width: 0; }"); From dd22e9009c1eab9aa8b7fced87e781392e20e7dd Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 11:14:03 +0000 Subject: [PATCH 06/11] - Added exit() function to headless loader class so that we have a way to return to prompt --- src/headlessloader.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/headlessloader.h b/src/headlessloader.h index 46c241f98..cd4326c37 100644 --- a/src/headlessloader.h +++ b/src/headlessloader.h @@ -32,12 +32,22 @@ #define HEADLESSLOADER_H #include +#include class HeadlessLoader: QObject { + Q_OBJECT + public: HeadlessLoader() { } + + public slots: + // Call this function to exit qBittorrent headless loader + // and return to prompt (object will be deleted by main) + void exit() { + qApp->quit(); + } }; #endif From 3dc1107b40e0917dc7c63538bfece94307f8207f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 11:48:57 +0000 Subject: [PATCH 07/11] - Fix typo in src.pro that broke compilation with GUI enabled --- src/src.pro | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/src.pro b/src/src.pro index 4f9698b6e..09fb1397a 100644 --- a/src/src.pro +++ b/src/src.pro @@ -189,7 +189,7 @@ HEADERS += misc.h \ contains(DEFINES, DISABLE_GUI) { HEADERS += headlessloader.h } else { - FORMS += GUI.h \ + HEADERS += GUI.h \ feedList.h \ supportedengines.h \ transferlistwidget.h \ @@ -232,6 +232,7 @@ contains(DEFINES, DISABLE_GUI) { } !contains(DEFINES, DISABLE_GUI) { + message(adding forms) FORMS += ui/mainwindow.ui \ ui/options.ui \ ui/about.ui \ @@ -252,6 +253,7 @@ contains(DEFINES, DISABLE_GUI) { ui/peer.ui \ ui/confirmdeletiondlg.ui } + SOURCES += main.cpp \ bittorrent.cpp \ qtorrenthandle.cpp \ From 1923a51c59a3cec0d1095889511cf704e689d125 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 11:59:48 +0000 Subject: [PATCH 08/11] - Prepare a little headlessloader class --- src/headlessloader.h | 20 ++++++++++++++++++-- src/main.cpp | 2 +- src/preferences.h | 5 +++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/headlessloader.h b/src/headlessloader.h index cd4326c37..3d3988faa 100644 --- a/src/headlessloader.h +++ b/src/headlessloader.h @@ -33,13 +33,29 @@ #include #include +#include "preferences.h" +#include "bittorrent.h" class HeadlessLoader: QObject { Q_OBJECT - public: - HeadlessLoader() { + private: + Bittorrent *BTSession; + public: + HeadlessLoader(QStringList torrentCmdLine) { + // Enable Web UI + Preferences::setWebUiEnabled(true); + // TODO: Listen on socket for parameters + // Instanciate Bittorrent Object + BTSession = new Bittorrent(); + // Resume unfinished torrents + BTSession->startUpTorrents(); + // TODO: Process command line parameter + } + + ~HeadlessLoader() { + delete BTSession; } public slots: diff --git a/src/main.cpp b/src/main.cpp index 4a3a2116b..065d9a351 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -242,7 +242,7 @@ int main(int argc, char *argv[]){ #else // Load Headless class // TODO: by Frederic Lassabe - HeadlessLoader *loader = new HeadlessLoader(); + HeadlessLoader *loader = new HeadlessLoader(torrentCmdLine); #endif int ret = app->exec(); #ifndef DISABLE_GUI diff --git a/src/preferences.h b/src/preferences.h index 3e7f09130..3873bf22d 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -450,6 +450,11 @@ public: return settings.value("Preferences/WebUI/Enabled", false).toBool(); } + static void setWebUiEnabled(bool enabled) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue("Preferences/WebUI/Enabled", enabled); + } + static quint16 getWebUiPort() { QSettings settings("qBittorrent", "qBittorrent"); return settings.value("Preferences/WebUI/Port", 8080).toInt(); From 8e39eef7aa276d639ae9a795ceb08df50f4c9e46 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 12:55:46 +0000 Subject: [PATCH 09/11] - Display console messages on Terminal - Program seems to be working --- src/bittorrent.cpp | 1 + src/bittorrent.h | 1 + src/headlessloader.h | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index b50f2ba84..795bdd0c8 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1184,6 +1184,7 @@ void Bittorrent::addConsoleMessage(QString msg, QColor color) { consoleMessages.removeFirst(); } consoleMessages.append(QString::fromUtf8("")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8(" - ") + msg + QString::fromUtf8("")); + emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg); } void Bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) { diff --git a/src/bittorrent.h b/src/bittorrent.h index 8ea40788f..f89d0dc5e 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -233,6 +233,7 @@ signals: void downloadFromUrlFailure(QString url, QString reason); void torrentFinishedChecking(QTorrentHandle& h); void metadataReceived(QTorrentHandle &h); + void newConsoleMessage(QString msg); }; #endif diff --git a/src/headlessloader.h b/src/headlessloader.h index 3d3988faa..c3dfc51ef 100644 --- a/src/headlessloader.h +++ b/src/headlessloader.h @@ -49,6 +49,7 @@ class HeadlessLoader: QObject { // TODO: Listen on socket for parameters // Instanciate Bittorrent Object BTSession = new Bittorrent(); + connect(BTSession, SIGNAL(newConsoleMessage(QString)), this, SLOT(displayConsoleMessage(QString))); // Resume unfinished torrents BTSession->startUpTorrents(); // TODO: Process command line parameter @@ -64,6 +65,10 @@ class HeadlessLoader: QObject { void exit() { qApp->quit(); } + + void displayConsoleMessage(QString msg) { + std::cout << msg.toLocal8Bit().data() << std::endl; + } }; #endif From 690bb92154b1afd6dbfa0e8f40dbe2f255624c47 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 13:01:57 +0000 Subject: [PATCH 10/11] - Catch CTRL+C and exit cleanly --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 065d9a351..127c229ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -227,6 +227,7 @@ int main(int argc, char *argv[]){ #ifndef Q_WS_WIN signal(SIGABRT, sigabrtHandler); signal(SIGTERM, sigtermHandler); + signal(SIGINT, sigtermHandler); signal(SIGSEGV, sigsegvHandler); #endif // Read torrents given on command line From 83d83a364d062705cc85ac5722b83e6a349d9d8c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Dec 2009 13:08:34 +0000 Subject: [PATCH 11/11] - Added Frederic Lassabe to AUTHORS file --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 545a96a18..4949c1d2d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,6 +6,7 @@ Contributors: * Ishan Arora * Arnaud Demaizière * Grigis Gaëtan +* Frédéric Lassabe Code from other projects: * files src/ico.cpp src/ico.h