2007-03-05 16:55:23 +03:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 18:31:59 +04:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2007-03-05 16:55:23 +03:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* 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.
|
2007-03-05 16:55:23 +03:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 21:00:55 +04:00
|
|
|
* 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.
|
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* Contact : chris@qbittorrent.org
|
2007-03-05 16:55:23 +03:00
|
|
|
*/
|
|
|
|
#ifndef __BITTORRENT_H__
|
|
|
|
#define __BITTORRENT_H__
|
|
|
|
|
2007-06-29 19:23:15 +04:00
|
|
|
#include <QHash>
|
2009-12-06 17:41:05 +03:00
|
|
|
#include <QMap>
|
|
|
|
#include <QUrl>
|
2007-07-23 16:46:36 +04:00
|
|
|
#include <QStringList>
|
2010-01-03 01:20:37 +03:00
|
|
|
#ifdef DISABLE_GUI
|
2010-01-03 02:03:46 +03:00
|
|
|
#include <QCoreApplication>
|
2010-01-03 01:20:37 +03:00
|
|
|
#else
|
2010-01-03 02:03:46 +03:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QPalette>
|
2010-01-03 01:20:37 +03:00
|
|
|
#endif
|
2008-09-13 11:33:41 +04:00
|
|
|
#include <QPointer>
|
2010-03-21 00:21:42 +03:00
|
|
|
#include <QTimer>
|
2007-06-29 19:23:15 +04:00
|
|
|
|
2010-06-07 12:32:41 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
2007-03-05 16:55:23 +03:00
|
|
|
#include <libtorrent/session.hpp>
|
2007-10-01 13:47:00 +04:00
|
|
|
#include <libtorrent/ip_filter.hpp>
|
2010-10-09 18:32:00 +04:00
|
|
|
|
2010-10-16 01:55:56 +04:00
|
|
|
#include "qtracker.h"
|
2007-08-20 10:29:18 +04:00
|
|
|
#include "qtorrenthandle.h"
|
2010-10-09 18:32:00 +04:00
|
|
|
#include "trackerinfos.h"
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
2009-11-16 23:28:58 +03:00
|
|
|
#define MAX_SAMPLES 20
|
|
|
|
|
2007-03-08 01:36:01 +03:00
|
|
|
class downloadThread;
|
2007-07-30 17:56:31 +04:00
|
|
|
class QTimer;
|
2008-05-18 00:32:03 +04:00
|
|
|
class FilterParserThread;
|
2009-11-18 20:46:59 +03:00
|
|
|
class HttpServer;
|
2010-01-24 14:57:15 +03:00
|
|
|
class BandwidthScheduler;
|
2010-02-28 18:15:00 +03:00
|
|
|
class ScanFoldersModel;
|
2007-03-08 01:36:01 +03:00
|
|
|
|
2010-10-17 18:46:01 +04:00
|
|
|
class QBtSession : public QObject {
|
2007-03-05 20:35:38 +03:00
|
|
|
Q_OBJECT
|
2010-10-31 15:35:07 +03:00
|
|
|
Q_DISABLE_COPY(QBtSession)
|
2010-10-31 02:40:28 +04:00
|
|
|
|
2010-11-13 22:36:46 +03:00
|
|
|
private:
|
|
|
|
explicit QBtSession();
|
|
|
|
static QBtSession* m_instance;
|
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
public:
|
2010-11-13 22:36:46 +03:00
|
|
|
static QBtSession* instance();
|
|
|
|
static void drop();
|
2010-10-17 18:46:01 +04:00
|
|
|
~QBtSession();
|
2009-11-19 11:14:04 +03:00
|
|
|
QTorrentHandle getTorrentHandle(QString hash) const;
|
|
|
|
std::vector<torrent_handle> getTorrents() const;
|
|
|
|
bool isFilePreviewPossible(QString fileHash) const;
|
|
|
|
float getPayloadDownloadRate() const;
|
|
|
|
float getPayloadUploadRate() const;
|
|
|
|
session_status getSessionStatus() const;
|
|
|
|
int getListenPort() const;
|
|
|
|
float getRealRatio(QString hash) const;
|
2009-11-19 18:04:43 +03:00
|
|
|
QHash<QString, TrackerInfos> getTrackersInfo(QString hash) const;
|
2009-11-19 11:14:04 +03:00
|
|
|
bool hasActiveTorrents() const;
|
2010-08-16 21:35:32 +04:00
|
|
|
bool hasDownloadingTorrents() const;
|
2010-10-31 02:40:28 +04:00
|
|
|
//int getMaximumActiveDownloads() const;
|
|
|
|
//int getMaximumActiveTorrents() const;
|
2009-11-19 11:14:04 +03:00
|
|
|
int loadTorrentPriority(QString hash);
|
|
|
|
qlonglong getETA(QString hash);
|
2010-10-31 02:40:28 +04:00
|
|
|
inline QStringList getConsoleMessages() const { return consoleMessages; }
|
|
|
|
inline QStringList getPeerBanMessages() const { return peerBanMessages; }
|
|
|
|
inline session* getSession() const { return s; }
|
|
|
|
inline bool useTemporaryFolder() const { return !defaultTempPath.isEmpty(); }
|
|
|
|
inline QString getDefaultSavePath() const { return defaultSavePath; }
|
|
|
|
inline ScanFoldersModel* getScanFoldersModel() const { return m_scanFolders; }
|
|
|
|
inline bool isDHTEnabled() const { return DHTEnabled; }
|
|
|
|
inline bool isLSDEnabled() const { return LSDEnabled; }
|
|
|
|
inline bool isPexEnabled() const { return DHTEnabled; }
|
|
|
|
inline bool isQueueingEnabled() const { return queueingEnabled; }
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
public slots:
|
|
|
|
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
|
|
|
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
|
|
|
void loadSessionState();
|
|
|
|
void saveSessionState();
|
|
|
|
void downloadFromUrl(QString url);
|
|
|
|
void deleteTorrent(QString hash, bool delete_local_files = false);
|
|
|
|
void startUpTorrents();
|
2009-12-01 00:30:14 +03:00
|
|
|
session_proxy asyncDeletion();
|
2010-01-20 21:02:26 +03:00
|
|
|
void recheckTorrent(QString hash);
|
2010-01-24 14:57:15 +03:00
|
|
|
void useAlternativeSpeedsLimit(bool alternative);
|
2009-11-19 11:14:04 +03:00
|
|
|
/* Needed by Web UI */
|
|
|
|
void pauseAllTorrents();
|
|
|
|
void pauseTorrent(QString hash);
|
|
|
|
void resumeTorrent(QString hash);
|
|
|
|
void resumeAllTorrents();
|
|
|
|
/* End Web UI */
|
|
|
|
void preAllocateAllFiles(bool b);
|
|
|
|
void saveFastResumeData();
|
|
|
|
void enableIPFilter(QString filter);
|
|
|
|
void disableIPFilter();
|
|
|
|
void setQueueingEnabled(bool enable);
|
|
|
|
void handleDownloadFailure(QString url, QString reason);
|
2010-11-13 13:49:22 +03:00
|
|
|
void downloadUrlAndSkipDialog(QString url, QString save_path, QString label);
|
2009-11-19 11:14:04 +03:00
|
|
|
// Session configuration - Setters
|
|
|
|
void setListeningPort(int port);
|
|
|
|
void setMaxConnections(int maxConnec);
|
|
|
|
void setMaxConnectionsPerTorrent(int max);
|
|
|
|
void setMaxUploadsPerTorrent(int max);
|
|
|
|
void setDownloadRateLimit(long rate);
|
|
|
|
void setUploadRateLimit(long rate);
|
2010-06-22 21:06:11 +04:00
|
|
|
void setMaxRatio(float ratio);
|
2009-11-19 11:14:04 +03:00
|
|
|
void setDHTPort(int dht_port);
|
2010-03-03 20:27:25 +03:00
|
|
|
void setPeerProxySettings(const proxy_settings &proxySettings);
|
|
|
|
void setHTTPProxySettings(const proxy_settings &proxySettings);
|
|
|
|
void setSessionSettings(const session_settings &sessionSettings);
|
2009-11-19 11:14:04 +03:00
|
|
|
void startTorrentsInPause(bool b);
|
|
|
|
void setDefaultTempPath(QString temppath);
|
2009-12-17 23:28:30 +03:00
|
|
|
void setAppendLabelToSavePath(bool append);
|
2010-07-18 16:53:16 +04:00
|
|
|
void appendLabelToTorrentSavePath(QTorrentHandle &h);
|
|
|
|
void changeLabelInTorrentSavePath(QTorrentHandle &h, QString old_label, QString new_label);
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2010-07-18 16:53:16 +04:00
|
|
|
void appendqBextensionToTorrent(QTorrentHandle &h, bool append);
|
2009-12-18 16:36:47 +03:00
|
|
|
void setAppendqBExtension(bool append);
|
|
|
|
#endif
|
2009-11-19 11:14:04 +03:00
|
|
|
void applyEncryptionSettings(pe_settings se);
|
|
|
|
void setDownloadLimit(QString hash, long val);
|
|
|
|
void setUploadLimit(QString hash, long val);
|
|
|
|
void enableUPnP(bool b);
|
|
|
|
void enableNATPMP(bool b);
|
|
|
|
void enableLSD(bool b);
|
|
|
|
bool enableDHT(bool b);
|
2010-01-03 01:20:37 +03:00
|
|
|
#ifdef DISABLE_GUI
|
|
|
|
void addConsoleMessage(QString msg, QString color=QString::null);
|
|
|
|
#else
|
2009-11-19 11:14:04 +03:00
|
|
|
void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText));
|
2010-01-03 01:20:37 +03:00
|
|
|
#endif
|
2009-11-19 11:14:04 +03:00
|
|
|
void addPeerBanMessage(QString msg, bool from_ipfilter);
|
|
|
|
void processDownloadedFile(QString, QString);
|
|
|
|
void addMagnetSkipAddDlg(QString uri);
|
|
|
|
void downloadFromURLList(const QStringList& urls);
|
|
|
|
void configureSession();
|
|
|
|
void banIP(QString ip);
|
2010-03-20 14:30:11 +03:00
|
|
|
void recursiveTorrentDownload(const QTorrentHandle &h);
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2010-03-03 22:04:34 +03:00
|
|
|
protected:
|
2010-04-06 13:17:33 +04:00
|
|
|
QString getSavePath(QString hash, bool fromScanDir = false, QString filePath = QString::null, QString root_folder=QString::null);
|
2010-03-03 22:04:34 +03:00
|
|
|
bool initWebUi(QString username, QString password, int port);
|
2010-10-17 18:46:01 +04:00
|
|
|
bool loadFastResumeData(QString hash, std::vector<char> &buf);
|
|
|
|
void loadTorrentSettings(QTorrentHandle h);
|
|
|
|
void loadTorrentTempData(QTorrentHandle h, QString savePath, bool magnet);
|
|
|
|
add_torrent_params initializeAddTorrentParams(QString hash);
|
2010-03-03 22:04:34 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
protected slots:
|
|
|
|
void addTorrentsFromScanFolder(QStringList&);
|
|
|
|
void readAlerts();
|
2010-06-22 21:06:11 +04:00
|
|
|
void processBigRatios();
|
2009-11-19 11:14:04 +03:00
|
|
|
void takeETASamples();
|
2010-01-31 16:09:46 +03:00
|
|
|
void exportTorrentFiles(QString path);
|
2010-03-21 00:21:42 +03:00
|
|
|
void saveTempFastResumeData();
|
2010-08-19 22:47:57 +04:00
|
|
|
void sendNotificationEmail(QTorrentHandle h);
|
2010-08-20 17:20:23 +04:00
|
|
|
void autoRunExternalProgram(QTorrentHandle h, bool async=true);
|
|
|
|
void cleanUpAutoRunProcess(int);
|
2010-10-17 16:18:34 +04:00
|
|
|
void mergeTorrents(QTorrentHandle h_ex, boost::intrusive_ptr<torrent_info> t);
|
2010-10-17 18:46:01 +04:00
|
|
|
void exportTorrentFile(QTorrentHandle h);
|
2010-10-31 02:40:28 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15
|
|
|
|
void saveDHTEntry();
|
|
|
|
#endif
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
signals:
|
2010-11-14 18:28:22 +03:00
|
|
|
void addedTorrent(const QTorrentHandle& h);
|
2009-11-19 11:14:04 +03:00
|
|
|
void deletedTorrent(QString hash);
|
2010-11-14 21:46:16 +03:00
|
|
|
void torrentAboutToBeRemoved(const QTorrentHandle &h);
|
2009-11-19 11:14:04 +03:00
|
|
|
void pausedTorrent(QTorrentHandle& h);
|
|
|
|
void resumedTorrent(QTorrentHandle& h);
|
|
|
|
void finishedTorrent(QTorrentHandle& h);
|
|
|
|
void fullDiskError(QTorrentHandle& h, QString msg);
|
|
|
|
void trackerError(QString hash, QString time, QString msg);
|
2010-03-04 22:29:48 +03:00
|
|
|
void trackerAuthenticationRequired(QTorrentHandle& h);
|
2009-11-19 11:14:04 +03:00
|
|
|
void newDownloadedTorrent(QString path, QString url);
|
|
|
|
void updateFileSize(QString hash);
|
|
|
|
void downloadFromUrlFailure(QString url, QString reason);
|
|
|
|
void torrentFinishedChecking(QTorrentHandle& h);
|
|
|
|
void metadataReceived(QTorrentHandle &h);
|
2009-12-18 19:56:57 +03:00
|
|
|
void savePathChanged(QTorrentHandle &h);
|
2009-12-15 15:55:46 +03:00
|
|
|
void newConsoleMessage(QString msg);
|
2010-01-24 14:57:15 +03:00
|
|
|
void alternativeSpeedsModeChanged(bool alternative);
|
2010-03-20 14:30:11 +03:00
|
|
|
void recursiveTorrentDownloadPossible(QTorrentHandle &h);
|
2010-03-03 22:04:34 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Bittorrent
|
|
|
|
session *s;
|
|
|
|
QPointer<QTimer> timerAlerts;
|
|
|
|
QPointer<BandwidthScheduler> bd_scheduler;
|
2010-11-13 13:49:22 +03:00
|
|
|
QMap<QUrl, QPair<QString, QString> > savepathLabel_fromurl;
|
2010-03-03 22:04:34 +03:00
|
|
|
QHash<QString, QHash<QString, TrackerInfos> > trackersInfos;
|
2010-07-18 00:55:40 +04:00
|
|
|
QHash<QString, QString> savePathsToRemove;
|
2010-03-03 22:04:34 +03:00
|
|
|
QStringList torrentsToPausedAfterChecking;
|
2010-03-21 00:21:42 +03:00
|
|
|
QTimer resumeDataTimer;
|
2010-03-03 22:04:34 +03:00
|
|
|
// Ratio
|
|
|
|
QPointer<QTimer> BigRatioTimer;
|
|
|
|
// HTTP
|
|
|
|
QPointer<downloadThread> downloader;
|
|
|
|
// File System
|
|
|
|
ScanFoldersModel *m_scanFolders;
|
|
|
|
// Console / Log
|
|
|
|
QStringList consoleMessages;
|
|
|
|
QStringList peerBanMessages;
|
|
|
|
// Settings
|
|
|
|
bool preAllocateAll;
|
|
|
|
bool addInPause;
|
|
|
|
float ratio_limit;
|
2010-06-22 21:06:11 +04:00
|
|
|
int high_ratio_action;
|
2010-03-03 22:04:34 +03:00
|
|
|
bool UPnPEnabled;
|
|
|
|
bool NATPMPEnabled;
|
|
|
|
bool LSDEnabled;
|
|
|
|
bool DHTEnabled;
|
|
|
|
int current_dht_port;
|
|
|
|
bool PeXEnabled;
|
|
|
|
bool queueingEnabled;
|
|
|
|
bool appendLabelToSavePath;
|
|
|
|
bool torrentExport;
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2010-03-03 22:04:34 +03:00
|
|
|
bool appendqBExtension;
|
|
|
|
#endif
|
|
|
|
QString defaultSavePath;
|
|
|
|
QString defaultTempPath;
|
|
|
|
// ETA Computation
|
|
|
|
QPointer<QTimer> timerETA;
|
|
|
|
QHash<QString, QList<int> > ETA_samples;
|
|
|
|
// IP filtering
|
|
|
|
QPointer<FilterParserThread> filterParser;
|
|
|
|
QString filterPath;
|
|
|
|
// Web UI
|
|
|
|
QPointer<HttpServer> httpServer;
|
|
|
|
QList<QUrl> url_skippingDlg;
|
|
|
|
// Fast exit (async)
|
|
|
|
bool exiting;
|
|
|
|
// GeoIP
|
|
|
|
#ifndef DISABLE_GUI
|
|
|
|
bool geoipDBLoaded;
|
|
|
|
bool resolve_countries;
|
|
|
|
#endif
|
2010-10-16 01:55:56 +04:00
|
|
|
// Tracker
|
|
|
|
QPointer<QTracker> m_tracker;
|
2010-03-03 22:04:34 +03:00
|
|
|
|
2007-03-05 20:35:38 +03:00
|
|
|
};
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
#endif
|