Browse Source

- Move Web UI code to Bittorrent class

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
d3c59f0814
  1. 32
      src/GUI.cpp
  2. 5
      src/GUI.h
  3. 27
      src/bittorrent.cpp
  4. 4
      src/bittorrent.h

32
src/GUI.cpp

@ -62,7 +62,6 @@
#include "preferences.h" #include "preferences.h"
#include <stdlib.h> #include <stdlib.h>
#include "console_imp.h" #include "console_imp.h"
#include "httpserver.h"
#include "torrentPersistentData.h" #include "torrentPersistentData.h"
#include "TransferListFiltersWidget.h" #include "TransferListFiltersWidget.h"
#include "propertieswidget.h" #include "propertieswidget.h"
@ -171,10 +170,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession->startUpTorrents(); BTSession->startUpTorrents();
// Add torrent given on command line // Add torrent given on command line
processParams(torrentCmdLine); processParams(torrentCmdLine);
// Initialize Web UI
if(Preferences::isWebUiEnabled()) {
initWebUi(Preferences::getWebUiUsername(), Preferences::getWebUiPassword(), Preferences::getWebUiPort());
}
// Use a tcp server to allow only one instance of qBittorrent // Use a tcp server to allow only one instance of qBittorrent
localServer = new QLocalServer(); localServer = new QLocalServer();
QString uid = QString::number(getuid()); QString uid = QString::number(getuid());
@ -238,9 +233,6 @@ GUI::~GUI() {
localServer->close(); localServer->close();
delete localServer; delete localServer;
delete tabs; delete tabs;
// HTTP Server
if(httpServer)
delete httpServer;
qDebug("3"); qDebug("3");
// Keyboard shortcuts // Keyboard shortcuts
delete switchSearchShortcut; delete switchSearchShortcut;
@ -702,16 +694,6 @@ void GUI::loadPreferences(bool configure_session) {
} }
systrayIntegration = newSystrayIntegration; systrayIntegration = newSystrayIntegration;
} }
// XXX: Should probably be done in bittorrent, not here
// Update Web UI
if (Preferences::isWebUiEnabled()) {
quint16 port = Preferences::getWebUiPort();
QString username = Preferences::getWebUiUsername();
QString password = Preferences::getWebUiPassword();
initWebUi(username, password, port);
} else if(httpServer) {
delete httpServer;
}
// General // General
bool new_displaySpeedInTitle = Preferences::speedInTitleBar(); bool new_displaySpeedInTitle = Preferences::speedInTitleBar();
if(!new_displaySpeedInTitle && new_displaySpeedInTitle != displaySpeedInTitle) { if(!new_displaySpeedInTitle && new_displaySpeedInTitle != displaySpeedInTitle) {
@ -893,20 +875,6 @@ void GUI::on_actionOptions_triggered() {
connect(options, SIGNAL(status_changed()), this, SLOT(optionsSaved())); connect(options, SIGNAL(status_changed()), this, SLOT(optionsSaved()));
} }
bool GUI::initWebUi(QString username, QString password, int port) {
if(httpServer)
httpServer->close();
else
httpServer = new HttpServer(BTSession, 3000, this);
httpServer->setAuthorization(username, password);
bool success = httpServer->listen(QHostAddress::Any, port);
if (success)
qDebug("Web UI listening on port %d", port);
else
QMessageBox::critical(this, "Web User Interface Error", "Unable to initialize HTTP Server on port " + misc::toQString(port));
return success;
}
/***************************************************** /*****************************************************
* * * *
* HTTP Downloader * * HTTP Downloader *

5
src/GUI.h

@ -53,7 +53,6 @@ class options_imp;
class QTabWidget; class QTabWidget;
class QLabel; class QLabel;
class QModelIndex; class QModelIndex;
class HttpServer;
class QFrame; class QFrame;
class TransferListWidget; class TransferListWidget;
class TransferListFiltersWidget; class TransferListFiltersWidget;
@ -97,8 +96,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
SearchEngine *searchEngine; SearchEngine *searchEngine;
// RSS // RSS
QPointer<RSSImp> rssWidget; QPointer<RSSImp> rssWidget;
// Web UI
QPointer<HttpServer> httpServer;
// Misc // Misc
QLocalServer *localServer; QLocalServer *localServer;
QLocalSocket *clientConnection; QLocalSocket *clientConnection;
@ -142,8 +139,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void processDownloadedFiles(QString path, QString url); void processDownloadedFiles(QString path, QString url);
void downloadFromURLList(const QStringList& urls); void downloadFromURLList(const QStringList& urls);
void finishedTorrent(QTorrentHandle& h) const; void finishedTorrent(QTorrentHandle& h) const;
//void updateLists(bool force=false);
bool initWebUi(QString username, QString password, int port);
// Options slots // Options slots
void on_actionOptions_triggered(); void on_actionOptions_triggered();
void optionsSaved(); void optionsSaved();

27
src/bittorrent.cpp

@ -42,6 +42,7 @@
#include "preferences.h" #include "preferences.h"
#include "geoip.h" #include "geoip.h"
#include "torrentPersistentData.h" #include "torrentPersistentData.h"
#include "httpserver.h"
#include <libtorrent/extensions/ut_metadata.hpp> #include <libtorrent/extensions/ut_metadata.hpp>
#ifdef LIBTORRENT_0_15 #ifdef LIBTORRENT_0_15
#include <libtorrent/extensions/lt_trackers.hpp> #include <libtorrent/extensions/lt_trackers.hpp>
@ -119,6 +120,9 @@ bittorrent::~bittorrent() {
if(FSWatcher) { if(FSWatcher) {
delete FSWatcher; delete FSWatcher;
} }
// HTTP Server
if(httpServer)
delete httpServer;
if(timerETA) if(timerETA)
delete timerETA; delete timerETA;
// Delete BT session // Delete BT session
@ -370,6 +374,15 @@ void bittorrent::configureSession() {
}else{ }else{
disableIPFilter(); disableIPFilter();
} }
// Update Web UI
if (Preferences::isWebUiEnabled()) {
quint16 port = Preferences::getWebUiPort();
QString username = Preferences::getWebUiUsername();
QString password = Preferences::getWebUiPassword();
initWebUi(username, password, port);
} else if(httpServer) {
delete httpServer;
}
// * Proxy settings // * Proxy settings
proxy_settings proxySettings; proxy_settings proxySettings;
if(Preferences::isProxyEnabled()) { if(Preferences::isProxyEnabled()) {
@ -438,6 +451,20 @@ void bittorrent::configureSession() {
qDebug("Session configured"); qDebug("Session configured");
} }
bool bittorrent::initWebUi(QString username, QString password, int port) {
if(httpServer)
httpServer->close();
else
httpServer = new HttpServer(this, 3000, this);
httpServer->setAuthorization(username, password);
bool success = httpServer->listen(QHostAddress::Any, port);
if (success)
qDebug("Web UI listening on port %d", port);
else
addConsoleMessage(tr("Web User Interface Error - Unable to bind Web UI to port %1").arg(port), QColor("red"));
return success;
}
void bittorrent::takeETASamples() { void bittorrent::takeETASamples() {
bool change = false;; bool change = false;;
foreach(const QString &hash, ETA_samples.keys()) { foreach(const QString &hash, ETA_samples.keys()) {

4
src/bittorrent.h

@ -48,6 +48,7 @@ class downloadThread;
class QTimer; class QTimer;
class FileSystemWatcher; class FileSystemWatcher;
class FilterParserThread; class FilterParserThread;
class HttpServer;
class bittorrent : public QObject { class bittorrent : public QObject {
Q_OBJECT Q_OBJECT
@ -79,9 +80,12 @@ class bittorrent : public QObject {
bool geoipDBLoaded; bool geoipDBLoaded;
QPointer<QTimer> timerETA; QPointer<QTimer> timerETA;
QHash<QString, QList<int> > ETA_samples; QHash<QString, QList<int> > ETA_samples;
// Web UI
QPointer<HttpServer> httpServer;
protected: protected:
QString getSavePath(QString hash); QString getSavePath(QString hash);
bool initWebUi(QString username, QString password, int port);
public: public:
// Constructor / Destructor // Constructor / Destructor

Loading…
Cancel
Save