Browse Source

Merge pull request #2042 from sorokin/optimize-includes

Optimize includes
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
89ae72d5c4
  1. 1
      src/fs_utils.h
  2. 1
      src/geoip/geoipmanager.cpp
  3. 5
      src/geoip/geoipmanager.h
  4. 45
      src/misc.cpp
  5. 51
      src/misc.h
  6. 1
      src/preferences/options_imp.h
  7. 3
      src/properties/peeraddition.h
  8. 2
      src/properties/propertieswidget.cpp
  9. 1
      src/qtlibtorrent/alertdispatcher.cpp
  10. 9
      src/qtlibtorrent/alertdispatcher.h
  11. 99
      src/qtlibtorrent/qbtsession.cpp
  12. 54
      src/qtlibtorrent/qbtsession.h
  13. 2
      src/qtlibtorrent/qtorrenthandle.h
  14. 2
      src/qtlibtorrent/torrentmodel.cpp
  15. 2
      src/statsdialog.cpp
  16. 3
      src/statusbar.h
  17. 2
      src/webui/btjson.cpp
  18. 2
      src/webui/httpconnection.cpp

1
src/fs_utils.h

@ -32,7 +32,6 @@
#define FS_UTILS_H #define FS_UTILS_H
#include <QString> #include <QString>
#include <QCoreApplication>
/** /**
* Utility functions related to file system. * Utility functions related to file system.

1
src/geoip/geoipmanager.cpp

@ -65,6 +65,7 @@
#include <QChar> #include <QChar>
#include "fs_utils.h" #include "fs_utils.h"
#include <libtorrent/session.hpp>
using namespace libtorrent; using namespace libtorrent;

5
src/geoip/geoipmanager.h

@ -31,10 +31,13 @@
#ifndef GEOIPMANAGER_H #ifndef GEOIPMANAGER_H
#define GEOIPMANAGER_H #define GEOIPMANAGER_H
#include <libtorrent/session.hpp>
#include <QString> #include <QString>
#include <QIcon> #include <QIcon>
namespace libtorrent {
class session;
}
class GeoIPManager : public QObject { class GeoIPManager : public QObject {
Q_OBJECT Q_OBJECT

45
src/misc.cpp

@ -41,6 +41,7 @@
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include <QLocale> #include <QLocale>
#include <QThread>
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
#include <QCoreApplication> #include <QCoreApplication>
@ -70,6 +71,13 @@ const int UNLEN = 256;
#endif #endif
#endif // DISABLE_GUI #endif // DISABLE_GUI
#if LIBTORRENT_VERSION_NUM < 10000
#include <libtorrent/peer_id.hpp>
#else
#include <libtorrent/sha1_hash.hpp>
#endif
#include <libtorrent/escape_string.hpp>
using namespace libtorrent; using namespace libtorrent;
static struct { const char *source; const char *comment; } units[] = { static struct { const char *source; const char *comment; } units[] = {
@ -80,6 +88,28 @@ static struct { const char *source; const char *comment; } units[] = {
QT_TRANSLATE_NOOP3("misc", "TiB", "tebibytes (1024 gibibytes)") QT_TRANSLATE_NOOP3("misc", "TiB", "tebibytes (1024 gibibytes)")
}; };
QString misc::toQString(const std::string &str) {
return QString::fromLocal8Bit(str.c_str());
}
QString misc::toQString(const char* str) {
return QString::fromLocal8Bit(str);
}
QString misc::toQStringU(const std::string &str) {
return QString::fromUtf8(str.c_str());
}
QString misc::toQStringU(const char* str) {
return QString::fromUtf8(str);
}
QString misc::toQString(const libtorrent::sha1_hash &hash) {
char out[41];
libtorrent::to_hex((char const*)&hash[0], libtorrent::sha1_hash::size, out);
return QString(out);
}
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
void misc::shutdownComputer(shutDownAction action) { void misc::shutdownComputer(shutDownAction action) {
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
@ -602,3 +632,18 @@ QString misc::accurateDoubleToString(const double &n, const int &precision, bool
else else
return QString::number(std::floor(n*prec)/prec, 'f', precision); return QString::number(std::floor(n*prec)/prec, 'f', precision);
} }
namespace {
// Trick to get a portable sleep() function
class SleeperThread : public QThread {
public:
static void msleep(unsigned long msecs)
{
QThread::msleep(msecs);
}
};
}
void misc::msleep(unsigned long msecs) {
SleeperThread::msleep(msecs);
}

51
src/misc.h

@ -31,12 +31,9 @@
#ifndef MISC_H #ifndef MISC_H
#define MISC_H #define MISC_H
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <sstream> #include <sstream>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QThread>
#include <ctime> #include <ctime>
#include <QPoint> #include <QPoint>
#include <QFile> #include <QFile>
@ -46,33 +43,28 @@
#include <QIcon> #include <QIcon>
#endif #endif
#include <libtorrent/version.hpp>
namespace libtorrent {
#if LIBTORRENT_VERSION_NUM < 10000
class big_number;
typedef big_number sha1_hash;
#else
class sha1_hash;
#endif
}
const qlonglong MAX_ETA = 8640000; const qlonglong MAX_ETA = 8640000;
enum shutDownAction { NO_SHUTDOWN, SHUTDOWN_COMPUTER, SUSPEND_COMPUTER, HIBERNATE_COMPUTER }; enum shutDownAction { NO_SHUTDOWN, SHUTDOWN_COMPUTER, SUSPEND_COMPUTER, HIBERNATE_COMPUTER };
/* Miscellaneaous functions that can be useful */ /* Miscellaneaous functions that can be useful */
namespace misc namespace misc
{ {
inline QString toQString(const std::string &str) { QString toQString(const std::string &str);
return QString::fromLocal8Bit(str.c_str()); QString toQString(const char* str);
} QString toQStringU(const std::string &str);
QString toQStringU(const char* str);
inline QString toQString(const char* str) { QString toQString(const libtorrent::sha1_hash &hash);
return QString::fromLocal8Bit(str);
}
inline QString toQStringU(const std::string &str) {
return QString::fromUtf8(str.c_str());
}
inline QString toQStringU(const char* str) {
return QString::fromUtf8(str);
}
inline QString toQString(const libtorrent::sha1_hash &hash) {
char out[41];
libtorrent::to_hex((char const*)&hash[0], libtorrent::sha1_hash::size, out);
return QString(out);
}
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
void shutdownComputer(shutDownAction action=SHUTDOWN_COMPUTER); void shutdownComputer(shutDownAction action=SHUTDOWN_COMPUTER);
@ -113,15 +105,8 @@ namespace misc
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
bool naturalSort(QString left, QString right, bool& result); bool naturalSort(QString left, QString right, bool& result);
#endif #endif
}
// Trick to get a portable sleep() function void msleep(unsigned long msecs);
class SleeperThread : public QThread { }
public:
static void msleep(unsigned long msecs)
{
QThread::msleep(msecs);
}
};
#endif #endif

1
src/preferences/options_imp.h

@ -32,7 +32,6 @@
#define OPTIONS_IMP_H #define OPTIONS_IMP_H
#include "ui_options.h" #include "ui_options.h"
#include <libtorrent/ip_filter.hpp>
// 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};

3
src/properties/peeraddition.h

@ -37,7 +37,8 @@
#include <QHostAddress> #include <QHostAddress>
#include "ui_peer.h" #include "ui_peer.h"
#include <libtorrent/session.hpp> #include <libtorrent/socket.hpp>
#include <libtorrent/address.hpp>
#include <boost/version.hpp> #include <boost/version.hpp>
#if BOOST_VERSION < 103500 #if BOOST_VERSION < 103500

2
src/properties/propertieswidget.cpp

@ -666,7 +666,7 @@ void PropertiesWidget::renameSelectedFile() {
int timeout = 10; int timeout = 10;
while(!QDir().rmpath(old_folder.absolutePath()) && timeout > 0) { while(!QDir().rmpath(old_folder.absolutePath()) && timeout > 0) {
// XXX: We should not sleep here (freezes the UI for 1 second) // XXX: We should not sleep here (freezes the UI for 1 second)
SleeperThread::msleep(100); misc::msleep(100);
--timeout; --timeout;
} }
} }

1
src/qtlibtorrent/alertdispatcher.cpp

@ -30,6 +30,7 @@
#include "alertdispatcher.h" #include "alertdispatcher.h"
#include <libtorrent/session.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <QMutexLocker> #include <QMutexLocker>

9
src/qtlibtorrent/alertdispatcher.h

@ -36,7 +36,14 @@
#include <QWaitCondition> #include <QWaitCondition>
#include <QAtomicPointer> #include <QAtomicPointer>
#include <QSharedPointer> #include <QSharedPointer>
#include <libtorrent/session.hpp>
#include <vector>
#include <memory>
namespace libtorrent {
class session;
class alert;
}
class QAlertDispatcher : public QObject { class QAlertDispatcher : public QObject {
Q_OBJECT Q_OBJECT

99
src/qtlibtorrent/qbtsession.cpp

@ -41,12 +41,14 @@
#include "torrentspeedmonitor.h" #include "torrentspeedmonitor.h"
#include "torrentstatistics.h" #include "torrentstatistics.h"
#include "qbtsession.h" #include "qbtsession.h"
#include "alertdispatcher.h"
#include "misc.h" #include "misc.h"
#include "fs_utils.h" #include "fs_utils.h"
#include "downloadthread.h" #include "downloadthread.h"
#include "filterparserthread.h" #include "filterparserthread.h"
#include "preferences.h" #include "preferences.h"
#include "scannedfoldersmodel.h" #include "scannedfoldersmodel.h"
#include "qtracker.h"
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include "shutdownconfirm.h" #include "shutdownconfirm.h"
#include "geoipmanager.h" #include "geoipmanager.h"
@ -68,6 +70,9 @@
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/error_code.hpp> #include <libtorrent/error_code.hpp>
#include <libtorrent/alert_types.hpp>
#include <libtorrent/session.hpp>
#include <libtorrent/ip_filter.hpp>
#include <queue> #include <queue>
#include <string.h> #include <string.h>
#include "dnsupdater.h" #include "dnsupdater.h"
@ -2054,48 +2059,6 @@ void QBtSession::disableIPFilter() {
filterPath = ""; filterPath = "";
} }
// Set BT session settings (user_agent)
void QBtSession::setSessionSettings(const session_settings &sessionSettings) {
qDebug("Set session settings");
s->set_settings(sessionSettings);
}
// Set Proxy
void QBtSession::setProxySettings(proxy_settings proxySettings) {
qDebug() << Q_FUNC_INFO;
proxySettings.proxy_peer_connections = Preferences::instance()->proxyPeerConnections();
s->set_proxy(proxySettings);
// Define environment variable
QString proxy_str;
switch(proxySettings.type) {
case proxy_settings::http_pw:
proxy_str = "http://"+misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
case proxy_settings::http:
proxy_str = "http://"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
case proxy_settings::socks5:
proxy_str = misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
case proxy_settings::socks5_pw:
proxy_str = misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
default:
qDebug("Disabling HTTP communications proxy");
qputenv("http_proxy", QByteArray());
qputenv("sock_proxy", QByteArray());
return;
}
// We need this for urllib in search engine plugins
qDebug("HTTP communications proxy string: %s", qPrintable(proxy_str));
if (proxySettings.type == proxy_settings::socks5 || proxySettings.type == proxy_settings::socks5_pw)
qputenv("sock_proxy", proxy_str.toLocal8Bit());
else
qputenv("http_proxy", proxy_str.toLocal8Bit());
}
void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) {
try { try {
for (int i=0; i<h.num_files(); ++i) { for (int i=0; i<h.num_files(); ++i) {
@ -2792,6 +2755,53 @@ session_status QBtSession::getSessionStatus() const {
return s->status(); return s->status();
} }
void QBtSession::applyEncryptionSettings(pe_settings se) {
qDebug("Applying encryption settings");
s->set_pe_settings(se);
}
// Set Proxy
void QBtSession::setProxySettings(proxy_settings proxySettings) {
qDebug() << Q_FUNC_INFO;
proxySettings.proxy_peer_connections = Preferences::instance()->proxyPeerConnections();
s->set_proxy(proxySettings);
// Define environment variable
QString proxy_str;
switch(proxySettings.type) {
case proxy_settings::http_pw:
proxy_str = "http://"+misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
case proxy_settings::http:
proxy_str = "http://"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
case proxy_settings::socks5:
proxy_str = misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
case proxy_settings::socks5_pw:
proxy_str = misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port);
break;
default:
qDebug("Disabling HTTP communications proxy");
qputenv("http_proxy", QByteArray());
qputenv("sock_proxy", QByteArray());
return;
}
// We need this for urllib in search engine plugins
qDebug("HTTP communications proxy string: %s", qPrintable(proxy_str));
if (proxySettings.type == proxy_settings::socks5 || proxySettings.type == proxy_settings::socks5_pw)
qputenv("sock_proxy", proxy_str.toLocal8Bit());
else
qputenv("http_proxy", proxy_str.toLocal8Bit());
}
// Set BT session settings (user_agent)
void QBtSession::setSessionSettings(const session_settings &sessionSettings) {
qDebug("Set session settings");
s->set_settings(sessionSettings);
}
QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString filePath, bool imported) { QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString filePath, bool imported) {
QString savePath; QString savePath;
if (TorrentTempData::hasTempData(hash)) { if (TorrentTempData::hasTempData(hash)) {
@ -2921,11 +2931,6 @@ qreal QBtSession::getPayloadUploadRate() const {
return s->status().payload_upload_rate; return s->status().payload_upload_rate;
} }
void QBtSession::applyEncryptionSettings(pe_settings se) {
qDebug("Applying encryption settings");
s->set_pe_settings(se);
}
// Will fast resume torrents in // Will fast resume torrents in
// backup directory // backup directory
void QBtSession::startUpTorrents() { void QBtSession::startUpTorrents() {

54
src/qtlibtorrent/qbtsession.h

@ -45,17 +45,50 @@
#include <QNetworkCookie> #include <QNetworkCookie>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include <libtorrent/session.hpp>
#include <libtorrent/ip_filter.hpp>
#include <libtorrent/alert_types.hpp>
#include "qtracker.h"
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
#include "trackerinfos.h" #include "trackerinfos.h"
#include "alertdispatcher.h"
#include "misc.h" #include "misc.h"
#define MAX_SAMPLES 20 namespace libtorrent {
class add_torrent_params;
class pe_settings;
class proxy_settings;
class session;
class session_status;
class alert;
class torrent_finished_alert;
class save_resume_data_alert;
class file_renamed_alert;
class torrent_deleted_alert;
class storage_moved_alert;
class storage_moved_failed_alert;
class metadata_received_alert;
class file_error_alert;
class file_completed_alert;
class torrent_paused_alert;
class tracker_error_alert;
class tracker_reply_alert;
class tracker_warning_alert;
class portmap_error_alert;
class portmap_alert;
class peer_blocked_alert;
class peer_ban_alert;
class fastresume_rejected_alert;
class url_seed_alert;
class listen_succeeded_alert;
class listen_failed_alert;
class torrent_checked_alert;
class external_ip_alert;
class state_update_alert;
class stats_alert;
#if LIBTORRENT_VERSION_NUM < 10000
class upnp;
class natpmp;
#endif
}
class DownloadThread; class DownloadThread;
class FilterParserThread; class FilterParserThread;
@ -65,6 +98,7 @@ class ScanFoldersModel;
class TorrentSpeedMonitor; class TorrentSpeedMonitor;
class TorrentStatistics; class TorrentStatistics;
class DNSUpdater; class DNSUpdater;
class QAlertDispatcher;
const int MAX_LOG_MESSAGES = 1000; const int MAX_LOG_MESSAGES = 1000;
@ -73,6 +107,8 @@ enum TorrentExportFolder {
FinishedTorrentExportFolder FinishedTorrentExportFolder
}; };
class QTracker;
class QBtSession : public QObject { class QBtSession : public QObject {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(QBtSession) Q_DISABLE_COPY(QBtSession)
@ -151,8 +187,6 @@ public slots:
void setMaxRatioPerTorrent(const QString &hash, qreal ratio); void setMaxRatioPerTorrent(const QString &hash, qreal ratio);
qreal getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const; qreal getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const;
void removeRatioPerTorrent(const QString &hash); void removeRatioPerTorrent(const QString &hash);
void setProxySettings(libtorrent::proxy_settings proxySettings);
void setSessionSettings(const libtorrent::session_settings &sessionSettings);
void setDefaultSavePath(const QString &savepath); void setDefaultSavePath(const QString &savepath);
void setDefaultTempPath(const QString &temppath); void setDefaultTempPath(const QString &temppath);
void setAppendLabelToSavePath(bool append); void setAppendLabelToSavePath(bool append);
@ -160,7 +194,6 @@ public slots:
void changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label); void changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label);
void appendqBextensionToTorrent(const QTorrentHandle &h, bool append); void appendqBextensionToTorrent(const QTorrentHandle &h, bool append);
void setAppendqBExtension(bool append); void setAppendqBExtension(bool append);
void applyEncryptionSettings(libtorrent::pe_settings se);
void setDownloadLimit(QString hash, long val); void setDownloadLimit(QString hash, long val);
void setUploadLimit(QString hash, long val); void setUploadLimit(QString hash, long val);
void enableUPnP(bool b); void enableUPnP(bool b);
@ -184,6 +217,9 @@ public slots:
void unhideMagnet(const QString &hash); void unhideMagnet(const QString &hash);
private: private:
void applyEncryptionSettings(libtorrent::pe_settings se);
void setProxySettings(libtorrent::proxy_settings proxySettings);
void setSessionSettings(const libtorrent::session_settings &sessionSettings);
QString getSavePath(const QString &hash, bool fromScanDir = false, QString filePath = QString::null, bool imported = false); QString getSavePath(const QString &hash, bool fromScanDir = false, QString filePath = QString::null, bool imported = false);
bool loadFastResumeData(const QString &hash, std::vector<char> &buf); bool loadFastResumeData(const QString &hash, std::vector<char> &buf);
void loadTorrentSettings(QTorrentHandle &h); void loadTorrentSettings(QTorrentHandle &h);

2
src/qtlibtorrent/qtorrenthandle.h

@ -31,9 +31,7 @@
#ifndef QTORRENTHANDLE_H #ifndef QTORRENTHANDLE_H
#define QTORRENTHANDLE_H #define QTORRENTHANDLE_H
#include <libtorrent/version.hpp>
#include <libtorrent/torrent_handle.hpp> #include <libtorrent/torrent_handle.hpp>
#include <libtorrent/torrent_info.hpp>
#include <QString> #include <QString>

2
src/qtlibtorrent/torrentmodel.cpp

@ -35,6 +35,8 @@
#include "qbtsession.h" #include "qbtsession.h"
#include "fs_utils.h" #include "fs_utils.h"
#include <libtorrent/session.hpp>
using namespace libtorrent; using namespace libtorrent;
namespace { namespace {

2
src/statsdialog.cpp

@ -32,6 +32,8 @@
#include "ui_statsdialog.h" #include "ui_statsdialog.h"
#include "misc.h" #include "misc.h"
#include <libtorrent/session.hpp>
#include <libtorrent/disk_io_thread.hpp>
StatsDialog::StatsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::StatsDialog) { StatsDialog::StatsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::StatsDialog) {
ui->setupUi(this); ui->setupUi(this);

3
src/statusbar.h

@ -46,6 +46,9 @@
#include "preferences.h" #include "preferences.h"
#include "misc.h" #include "misc.h"
#include <libtorrent/session.hpp>
#include <libtorrent/session_status.hpp>
class StatusBar: public QObject { class StatusBar: public QObject {
Q_OBJECT Q_OBJECT

2
src/webui/btjson.cpp

@ -39,6 +39,8 @@
#include <QElapsedTimer> #include <QElapsedTimer>
#endif #endif
#include <libtorrent/session_status.hpp>
using namespace libtorrent; using namespace libtorrent;
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)

2
src/webui/httpconnection.cpp

@ -52,6 +52,8 @@
#include <queue> #include <queue>
#include <vector> #include <vector>
#include <libtorrent/session.hpp>
using namespace libtorrent; using namespace libtorrent;
HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent) HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent)

Loading…
Cancel
Save