2007-03-05 13:55:23 +00:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 14:31:59 +00:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2007-03-05 13:55:23 +00:00
|
|
|
*
|
2007-07-14 14:31:59 +00: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 13:55:23 +00: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 14:31:59 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
2007-03-05 13:55:23 +00:00
|
|
|
*/
|
|
|
|
#ifndef __BITTORRENT_H__
|
|
|
|
#define __BITTORRENT_H__
|
|
|
|
|
2007-06-29 15:23:15 +00:00
|
|
|
#include <QHash>
|
2007-07-23 12:46:36 +00:00
|
|
|
#include <QStringList>
|
2008-09-07 11:31:29 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QPalette>
|
2008-09-13 07:33:41 +00:00
|
|
|
#include <QPointer>
|
2007-06-29 15:23:15 +00:00
|
|
|
|
2007-03-05 13:55:23 +00:00
|
|
|
#include <libtorrent/session.hpp>
|
2007-10-01 09:47:00 +00:00
|
|
|
#include <libtorrent/ip_filter.hpp>
|
2007-08-20 06:29:18 +00:00
|
|
|
#include "qtorrenthandle.h"
|
2007-03-05 13:55:23 +00:00
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
2007-03-07 22:36:01 +00:00
|
|
|
class downloadThread;
|
2007-07-30 13:56:31 +00:00
|
|
|
class QTimer;
|
2008-12-26 13:17:08 +00:00
|
|
|
class QFileSystemWatcher;
|
|
|
|
class QMutex;
|
2008-05-17 20:32:03 +00:00
|
|
|
class FilterParserThread;
|
2007-03-07 22:36:01 +00:00
|
|
|
|
2008-09-07 11:31:29 +00:00
|
|
|
class bittorrent : public QObject {
|
2007-03-05 17:35:38 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2007-03-05 13:55:23 +00:00
|
|
|
private:
|
|
|
|
session *s;
|
2008-12-26 13:17:08 +00:00
|
|
|
QPointer<QFileSystemWatcher> FSWatcher;
|
|
|
|
QMutex* FSMutex;
|
2008-11-04 19:01:51 +00:00
|
|
|
QPointer<QTimer> timerAlerts;
|
2008-09-13 07:33:41 +00:00
|
|
|
QPointer<QTimer> BigRatioTimer;
|
2007-08-28 16:17:32 +00:00
|
|
|
bool DHTEnabled;
|
2008-11-04 19:01:51 +00:00
|
|
|
QPointer<downloadThread> downloader;
|
2007-03-07 22:36:01 +00:00
|
|
|
QString defaultSavePath;
|
2008-05-15 19:48:15 +00:00
|
|
|
QHash<QString, QHash<QString, QString> > trackersErrors;
|
2008-09-07 11:31:29 +00:00
|
|
|
QStringList consoleMessages;
|
|
|
|
QStringList peerBanMessages;
|
2007-08-19 14:20:54 +00:00
|
|
|
QStringList finishedTorrents;
|
|
|
|
QStringList unfinishedTorrents;
|
2007-09-08 17:07:29 +00:00
|
|
|
bool preAllocateAll;
|
|
|
|
bool addInPause;
|
2007-09-09 07:44:22 +00:00
|
|
|
int maxConnecsPerTorrent;
|
|
|
|
int maxUploadsPerTorrent;
|
2007-09-09 09:09:24 +00:00
|
|
|
float max_ratio;
|
2007-11-23 15:20:26 +00:00
|
|
|
bool UPnPEnabled;
|
|
|
|
bool NATPMPEnabled;
|
|
|
|
bool LSDEnabled;
|
2008-09-13 07:33:41 +00:00
|
|
|
QPointer<FilterParserThread> filterParser;
|
2008-05-17 20:32:03 +00:00
|
|
|
QString filterPath;
|
2008-07-14 22:01:05 +00:00
|
|
|
bool queueingEnabled;
|
2008-09-14 10:14:54 +00:00
|
|
|
QStringList url_skippingDlg;
|
2007-03-05 13:55:23 +00:00
|
|
|
|
2007-03-05 17:35:38 +00:00
|
|
|
protected:
|
2007-07-22 09:47:27 +00:00
|
|
|
QString getSavePath(QString hash);
|
2007-03-05 17:35:38 +00:00
|
|
|
|
2007-03-05 13:55:23 +00:00
|
|
|
public:
|
2007-03-07 22:36:01 +00:00
|
|
|
// Constructor / Destructor
|
|
|
|
bittorrent();
|
|
|
|
~bittorrent();
|
2007-08-20 06:29:18 +00:00
|
|
|
QTorrentHandle getTorrentHandle(QString hash) const;
|
2007-07-22 09:47:27 +00:00
|
|
|
bool isPaused(QString hash) const;
|
|
|
|
bool isFilePreviewPossible(QString fileHash) const;
|
2007-03-05 13:55:23 +00:00
|
|
|
bool isDHTEnabled() const;
|
2007-03-07 22:36:01 +00:00
|
|
|
float getPayloadDownloadRate() const;
|
|
|
|
float getPayloadUploadRate() const;
|
|
|
|
session_status getSessionStatus() const;
|
|
|
|
int getListenPort() const;
|
2007-07-18 07:44:52 +00:00
|
|
|
float getRealRatio(QString hash) const;
|
2007-07-14 10:50:38 +00:00
|
|
|
session* getSession() const;
|
2008-05-15 19:48:15 +00:00
|
|
|
QHash<QString, QString> getTrackersErrors(QString hash) const;
|
2007-08-19 14:20:54 +00:00
|
|
|
QStringList getFinishedTorrents() const;
|
|
|
|
QStringList getUnfinishedTorrents() const;
|
|
|
|
bool isFinished(QString hash) const;
|
2007-08-20 06:29:18 +00:00
|
|
|
bool has_filtered_files(QString hash) const;
|
2008-05-18 09:26:02 +00:00
|
|
|
unsigned int getFinishedPausedTorrentsNb() const;
|
|
|
|
unsigned int getUnfinishedPausedTorrentsNb() const;
|
2008-07-14 22:01:05 +00:00
|
|
|
bool isQueueingEnabled() const;
|
2008-07-14 19:20:18 +00:00
|
|
|
int getDlTorrentPriority(QString hash) const;
|
2008-07-14 22:01:05 +00:00
|
|
|
int getUpTorrentPriority(QString hash) const;
|
2008-07-15 18:34:28 +00:00
|
|
|
int getMaximumActiveDownloads() const;
|
|
|
|
int getMaximumActiveTorrents() const;
|
2008-11-02 11:43:20 +00:00
|
|
|
bool isTorrentQueued(QString hash) const;
|
|
|
|
bool is_auto_managed() const;
|
2008-07-14 22:01:05 +00:00
|
|
|
int loadTorrentPriority(QString hash);
|
2008-09-07 11:31:29 +00:00
|
|
|
QStringList getConsoleMessages() const;
|
|
|
|
QStringList getPeerBanMessages() const;
|
2008-09-13 18:53:58 +00:00
|
|
|
float getUncheckedTorrentProgress(QString hash) const;
|
2008-11-02 13:07:38 +00:00
|
|
|
qlonglong getETA(QString hash) const;
|
2007-03-05 13:55:23 +00:00
|
|
|
|
|
|
|
public slots:
|
2007-10-10 17:34:52 +00:00
|
|
|
void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
2008-11-02 13:19:27 +00:00
|
|
|
void loadSessionState();
|
|
|
|
void saveSessionState();
|
2007-07-22 09:47:27 +00:00
|
|
|
void downloadFromUrl(QString url);
|
2007-03-07 22:36:01 +00:00
|
|
|
void downloadFromURLList(const QStringList& url_list);
|
2007-07-22 09:47:27 +00:00
|
|
|
void deleteTorrent(QString hash, bool permanent = false);
|
2007-07-29 14:14:57 +00:00
|
|
|
bool pauseTorrent(QString hash);
|
|
|
|
bool resumeTorrent(QString hash);
|
2008-05-16 07:10:50 +00:00
|
|
|
void pauseAllTorrents();
|
|
|
|
void resumeAllTorrents();
|
2007-03-07 22:36:01 +00:00
|
|
|
void saveDHTEntry();
|
2007-09-08 17:07:29 +00:00
|
|
|
void preAllocateAllFiles(bool b);
|
2008-11-01 22:07:14 +00:00
|
|
|
void saveFastResumeData();
|
|
|
|
void saveFastResumeData(QString hash);
|
2007-07-22 09:47:27 +00:00
|
|
|
void enableDirectoryScanning(QString scan_dir);
|
2007-03-05 13:55:23 +00:00
|
|
|
void disableDirectoryScanning();
|
2008-05-17 20:32:03 +00:00
|
|
|
void enableIPFilter(QString filter);
|
2007-03-05 17:35:38 +00:00
|
|
|
void disableIPFilter();
|
2008-07-14 22:01:05 +00:00
|
|
|
void setQueueingEnabled(bool enable);
|
2007-03-07 22:36:01 +00:00
|
|
|
void resumeUnfinishedTorrents();
|
2007-07-14 13:38:29 +00:00
|
|
|
void saveTorrentSpeedLimits(QString hash);
|
|
|
|
void loadTorrentSpeedLimits(QString hash);
|
2007-08-26 16:25:22 +00:00
|
|
|
void handleDownloadFailure(QString url, QString reason);
|
2007-07-27 09:53:55 +00:00
|
|
|
void loadWebSeeds(QString fileHash);
|
2008-07-14 19:20:18 +00:00
|
|
|
void increaseDlTorrentPriority(QString hash);
|
|
|
|
void decreaseDlTorrentPriority(QString hash);
|
2008-09-14 10:14:54 +00:00
|
|
|
void downloadUrlAndSkipDialog(QString);
|
2007-03-05 13:55:23 +00:00
|
|
|
// Session configuration - Setters
|
|
|
|
void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports);
|
2007-03-07 22:36:01 +00:00
|
|
|
void setMaxConnections(int maxConnec);
|
2007-09-09 07:44:22 +00:00
|
|
|
void setMaxConnectionsPerTorrent(int max);
|
|
|
|
void setMaxUploadsPerTorrent(int max);
|
2007-08-04 06:23:44 +00:00
|
|
|
void setDownloadRateLimit(long rate);
|
|
|
|
void setUploadRateLimit(long rate);
|
2007-03-05 13:55:23 +00:00
|
|
|
void setGlobalRatio(float ratio);
|
2007-09-09 09:09:24 +00:00
|
|
|
void setDeleteRatio(float ratio);
|
2007-03-05 17:35:38 +00:00
|
|
|
void setDHTPort(int dht_port);
|
2007-05-13 20:02:30 +00:00
|
|
|
void setProxySettings(proxy_settings proxySettings, bool trackers=true, bool peers=true, bool web_seeds=true, bool dht=true);
|
2007-03-05 17:35:38 +00:00
|
|
|
void setSessionSettings(session_settings sessionSettings);
|
2007-09-08 17:07:29 +00:00
|
|
|
void startTorrentsInPause(bool b);
|
2007-07-22 09:47:27 +00:00
|
|
|
void setDefaultSavePath(QString savepath);
|
2007-06-15 20:35:07 +00:00
|
|
|
void applyEncryptionSettings(pe_settings se);
|
2007-08-20 06:29:18 +00:00
|
|
|
void loadFilesPriorities(QTorrentHandle& h);
|
2007-08-04 06:23:44 +00:00
|
|
|
void setDownloadLimit(QString hash, long val);
|
|
|
|
void setUploadLimit(QString hash, long val);
|
2007-08-19 14:20:54 +00:00
|
|
|
void setUnfinishedTorrent(QString hash);
|
|
|
|
void setFinishedTorrent(QString hash);
|
2007-09-08 17:07:29 +00:00
|
|
|
void enableUPnP(bool b);
|
|
|
|
void enableNATPMP(bool b);
|
|
|
|
void enableLSD(bool b);
|
2007-10-27 20:53:09 +00:00
|
|
|
bool enableDHT(bool b);
|
2008-09-07 11:31:29 +00:00
|
|
|
void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText));
|
|
|
|
void addPeerBanMessage(QString msg, bool from_ipfilter);
|
2007-03-05 13:55:23 +00:00
|
|
|
|
|
|
|
protected slots:
|
2008-12-26 13:17:08 +00:00
|
|
|
void scanDirectory(QString);
|
2007-03-05 17:35:38 +00:00
|
|
|
void readAlerts();
|
2007-07-22 09:47:27 +00:00
|
|
|
void processDownloadedFile(QString, QString);
|
|
|
|
bool loadTrackerFile(QString hash);
|
|
|
|
void saveTrackerFile(QString hash);
|
2007-09-09 09:09:24 +00:00
|
|
|
void deleteBigRatios();
|
2007-03-05 13:55:23 +00:00
|
|
|
|
|
|
|
signals:
|
2008-09-07 11:31:29 +00:00
|
|
|
void addedTorrent(QTorrentHandle& h);
|
2008-05-16 07:10:50 +00:00
|
|
|
void deletedTorrent(QString hash);
|
|
|
|
void pausedTorrent(QString hash);
|
|
|
|
void resumedTorrent(QString hash);
|
2007-08-20 06:29:18 +00:00
|
|
|
void finishedTorrent(QTorrentHandle& h);
|
|
|
|
void fullDiskError(QTorrentHandle& h);
|
2007-07-22 09:47:27 +00:00
|
|
|
void trackerError(QString hash, QString time, QString msg);
|
2007-08-20 06:29:18 +00:00
|
|
|
void trackerAuthenticationRequired(QTorrentHandle& h);
|
2007-07-22 09:47:27 +00:00
|
|
|
void newDownloadedTorrent(QString path, QString url);
|
2007-04-12 21:28:15 +00:00
|
|
|
void updateFileSize(QString hash);
|
2007-07-22 09:47:27 +00:00
|
|
|
void downloadFromUrlFailure(QString url, QString reason);
|
2008-10-06 18:34:47 +00:00
|
|
|
void torrentFinishedChecking(QString hash);
|
2008-07-15 20:19:41 +00:00
|
|
|
void updateFinishedTorrentNumber();
|
|
|
|
void updateUnfinishedTorrentNumber();
|
2008-08-08 13:17:26 +00:00
|
|
|
void forceUnfinishedListUpdate();
|
|
|
|
void forceFinishedListUpdate();
|
2007-03-05 17:35:38 +00:00
|
|
|
};
|
2007-03-05 13:55:23 +00:00
|
|
|
|
|
|
|
#endif
|