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.
|
|
|
|
*
|
|
|
|
* 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>
|
2007-07-27 17:58:12 +04:00
|
|
|
#include <QList>
|
|
|
|
#include <QPair>
|
2007-07-23 16:46:36 +04:00
|
|
|
#include <QStringList>
|
2007-11-25 00:55:19 +03:00
|
|
|
#include <QDateTime>
|
2007-06-29 19:23:15 +04:00
|
|
|
|
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>
|
2007-08-20 10:29:18 +04:00
|
|
|
#include "qtorrenthandle.h"
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
2007-03-08 01:36:01 +03:00
|
|
|
class downloadThread;
|
2007-10-19 20:00:42 +04:00
|
|
|
class deleteThread;
|
2007-07-30 17:56:31 +04:00
|
|
|
class QTimer;
|
2008-05-18 00:32:03 +04:00
|
|
|
class FilterParserThread;
|
2007-03-08 01:36:01 +03:00
|
|
|
|
2007-03-05 20:35:38 +03:00
|
|
|
class bittorrent : public QObject{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2007-03-05 16:55:23 +03:00
|
|
|
private:
|
|
|
|
session *s;
|
2007-03-05 20:35:38 +03:00
|
|
|
QString scan_dir;
|
2007-03-05 16:55:23 +03:00
|
|
|
QTimer *timerScan;
|
2007-07-30 17:56:31 +04:00
|
|
|
QTimer *timerAlerts;
|
2007-11-19 23:33:31 +03:00
|
|
|
QTimer *fastResumeSaver;
|
2007-11-25 00:55:19 +03:00
|
|
|
QTimer *BigRatioTimer;
|
2007-08-28 20:17:32 +04:00
|
|
|
bool DHTEnabled;
|
2007-03-08 01:36:01 +03:00
|
|
|
downloadThread *downloader;
|
|
|
|
QString defaultSavePath;
|
2007-06-29 01:54:07 +04:00
|
|
|
QStringList torrentsToPauseAfterChecking;
|
2007-11-25 00:55:19 +03:00
|
|
|
QHash<QString, QDateTime> TorrentsStartTime;
|
|
|
|
QHash<QString, size_type> TorrentsStartData;
|
2007-07-18 11:44:52 +04:00
|
|
|
QHash<QString, QPair<size_type,size_type> > ratioData;
|
2008-05-15 23:48:15 +04:00
|
|
|
QHash<QString, QHash<QString, QString> > trackersErrors;
|
2007-10-19 20:00:42 +04:00
|
|
|
deleteThread *deleter;
|
2007-08-19 18:20:54 +04:00
|
|
|
QStringList finishedTorrents;
|
|
|
|
QStringList unfinishedTorrents;
|
2007-09-08 21:07:29 +04:00
|
|
|
bool preAllocateAll;
|
|
|
|
bool addInPause;
|
2007-09-09 11:44:22 +04:00
|
|
|
int maxConnecsPerTorrent;
|
|
|
|
int maxUploadsPerTorrent;
|
2007-09-09 13:09:24 +04:00
|
|
|
float max_ratio;
|
2007-11-23 18:20:26 +03:00
|
|
|
bool UPnPEnabled;
|
|
|
|
bool NATPMPEnabled;
|
|
|
|
bool LSDEnabled;
|
2008-05-18 00:32:03 +04:00
|
|
|
FilterParserThread *filterParser;
|
|
|
|
QString filterPath;
|
2008-05-18 12:40:39 +04:00
|
|
|
int folderScanInterval; // in seconds
|
2008-07-15 02:01:05 +04:00
|
|
|
bool queueingEnabled;
|
|
|
|
int maxActiveDownloads;
|
|
|
|
int maxActiveTorrents;
|
|
|
|
int currentActiveDownloads;
|
2008-07-14 23:20:18 +04:00
|
|
|
QStringList *downloadQueue;
|
|
|
|
QStringList *queuedDownloads;
|
2008-07-15 02:01:05 +04:00
|
|
|
QStringList *uploadQueue;
|
|
|
|
QStringList *queuedUploads;
|
2008-07-27 19:41:46 +04:00
|
|
|
bool calculateETA;
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2007-03-05 20:35:38 +03:00
|
|
|
protected:
|
2007-07-22 13:47:27 +04:00
|
|
|
QString getSavePath(QString hash);
|
2007-03-05 20:35:38 +03:00
|
|
|
|
2007-03-05 16:55:23 +03:00
|
|
|
public:
|
2007-03-08 01:36:01 +03:00
|
|
|
// Constructor / Destructor
|
|
|
|
bittorrent();
|
|
|
|
~bittorrent();
|
2007-08-20 10:29:18 +04:00
|
|
|
QTorrentHandle getTorrentHandle(QString hash) const;
|
2007-07-22 13:47:27 +04:00
|
|
|
bool isPaused(QString hash) const;
|
|
|
|
bool isFilePreviewPossible(QString fileHash) const;
|
2007-03-05 16:55:23 +03:00
|
|
|
bool isDHTEnabled() const;
|
2007-03-08 01:36:01 +03:00
|
|
|
float getPayloadDownloadRate() const;
|
|
|
|
float getPayloadUploadRate() const;
|
|
|
|
session_status getSessionStatus() const;
|
|
|
|
int getListenPort() const;
|
2007-06-29 01:54:07 +04:00
|
|
|
QStringList getTorrentsToPauseAfterChecking() const;
|
2007-11-25 00:55:19 +03:00
|
|
|
qlonglong getETA(QString hash) const;
|
2007-07-18 11:44:52 +04:00
|
|
|
float getRealRatio(QString hash) const;
|
2007-07-14 14:50:38 +04:00
|
|
|
session* getSession() const;
|
2008-05-15 23:48:15 +04:00
|
|
|
QHash<QString, QString> getTrackersErrors(QString hash) const;
|
2007-08-19 18:20:54 +04:00
|
|
|
QStringList getFinishedTorrents() const;
|
|
|
|
QStringList getUnfinishedTorrents() const;
|
|
|
|
bool isFinished(QString hash) const;
|
2007-08-20 10:29:18 +04:00
|
|
|
bool has_filtered_files(QString hash) const;
|
2008-05-18 13:26:02 +04:00
|
|
|
unsigned int getFinishedPausedTorrentsNb() const;
|
|
|
|
unsigned int getUnfinishedPausedTorrentsNb() const;
|
2008-07-15 02:01:05 +04:00
|
|
|
bool isQueueingEnabled() const;
|
2008-07-14 23:20:18 +04:00
|
|
|
int getDlTorrentPriority(QString hash) const;
|
2008-07-15 02:01:05 +04:00
|
|
|
int getUpTorrentPriority(QString hash) const;
|
2008-07-15 22:34:28 +04:00
|
|
|
int getMaximumActiveDownloads() const;
|
|
|
|
int getMaximumActiveTorrents() const;
|
2008-07-14 23:20:18 +04:00
|
|
|
bool isDownloadQueued(QString hash) const;
|
2008-07-15 02:01:05 +04:00
|
|
|
bool isUploadQueued(QString hash) const;
|
|
|
|
int loadTorrentPriority(QString hash);
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
public slots:
|
2007-10-10 21:34:52 +04:00
|
|
|
void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
2007-07-22 13:47:27 +04:00
|
|
|
void downloadFromUrl(QString url);
|
2007-03-08 01:36:01 +03:00
|
|
|
void downloadFromURLList(const QStringList& url_list);
|
2007-07-22 13:47:27 +04:00
|
|
|
void deleteTorrent(QString hash, bool permanent = false);
|
2007-07-29 18:14:57 +04:00
|
|
|
bool pauseTorrent(QString hash);
|
|
|
|
bool resumeTorrent(QString hash);
|
2008-05-16 11:10:50 +04:00
|
|
|
void pauseAllTorrents();
|
|
|
|
void resumeAllTorrents();
|
2007-03-08 01:36:01 +03:00
|
|
|
void saveDHTEntry();
|
2007-09-08 21:07:29 +04:00
|
|
|
void preAllocateAllFiles(bool b);
|
2007-07-29 18:54:39 +04:00
|
|
|
void saveFastResumeAndRatioData();
|
2007-11-21 23:33:30 +03:00
|
|
|
void saveFastResumeAndRatioData(QString hash);
|
2007-07-22 13:47:27 +04:00
|
|
|
void enableDirectoryScanning(QString scan_dir);
|
2007-03-05 16:55:23 +03:00
|
|
|
void disableDirectoryScanning();
|
2007-03-05 20:35:38 +03:00
|
|
|
void enablePeerExchange();
|
2008-05-18 00:32:03 +04:00
|
|
|
void enableIPFilter(QString filter);
|
2007-03-05 20:35:38 +03:00
|
|
|
void disableIPFilter();
|
2008-07-15 02:01:05 +04:00
|
|
|
void setQueueingEnabled(bool enable);
|
2007-03-08 01:36:01 +03:00
|
|
|
void resumeUnfinishedTorrents();
|
2007-07-14 17:38:29 +04:00
|
|
|
void saveTorrentSpeedLimits(QString hash);
|
|
|
|
void loadTorrentSpeedLimits(QString hash);
|
2007-07-18 11:44:52 +04:00
|
|
|
void saveDownloadUploadForTorrent(QString hash);
|
|
|
|
void loadDownloadUploadForTorrent(QString hash);
|
2007-08-26 20:25:22 +04:00
|
|
|
void handleDownloadFailure(QString url, QString reason);
|
2007-07-27 13:53:55 +04:00
|
|
|
void loadWebSeeds(QString fileHash);
|
2008-07-14 23:20:18 +04:00
|
|
|
void updateDownloadQueue();
|
2008-07-15 02:01:05 +04:00
|
|
|
void updateUploadQueue();
|
2008-07-14 23:20:18 +04:00
|
|
|
void increaseDlTorrentPriority(QString hash);
|
|
|
|
void decreaseDlTorrentPriority(QString hash);
|
2008-07-15 02:01:05 +04:00
|
|
|
void increaseUpTorrentPriority(QString hash);
|
|
|
|
void decreaseUpTorrentPriority(QString hash);
|
|
|
|
void saveTorrentPriority(QString hash, int prio);
|
2007-03-05 16:55:23 +03:00
|
|
|
// Session configuration - Setters
|
|
|
|
void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports);
|
2007-03-08 01:36:01 +03:00
|
|
|
void setMaxConnections(int maxConnec);
|
2007-09-09 11:44:22 +04:00
|
|
|
void setMaxConnectionsPerTorrent(int max);
|
|
|
|
void setMaxUploadsPerTorrent(int max);
|
2007-08-04 10:23:44 +04:00
|
|
|
void setDownloadRateLimit(long rate);
|
|
|
|
void setUploadRateLimit(long rate);
|
2007-03-05 16:55:23 +03:00
|
|
|
void setGlobalRatio(float ratio);
|
2007-09-09 13:09:24 +04:00
|
|
|
void setDeleteRatio(float ratio);
|
2007-03-05 20:35:38 +03:00
|
|
|
void setDHTPort(int dht_port);
|
2007-05-14 00:02:30 +04:00
|
|
|
void setProxySettings(proxy_settings proxySettings, bool trackers=true, bool peers=true, bool web_seeds=true, bool dht=true);
|
2007-03-05 20:35:38 +03:00
|
|
|
void setSessionSettings(session_settings sessionSettings);
|
2007-09-08 21:07:29 +04:00
|
|
|
void startTorrentsInPause(bool b);
|
2007-07-22 13:47:27 +04:00
|
|
|
void setDefaultSavePath(QString savepath);
|
2007-06-16 00:35:07 +04:00
|
|
|
void applyEncryptionSettings(pe_settings se);
|
2007-08-20 10:29:18 +04:00
|
|
|
void loadFilesPriorities(QTorrentHandle& h);
|
2007-08-04 10:23:44 +04:00
|
|
|
void setDownloadLimit(QString hash, long val);
|
|
|
|
void setUploadLimit(QString hash, long val);
|
2007-08-19 18:20:54 +04:00
|
|
|
void setUnfinishedTorrent(QString hash);
|
|
|
|
void setFinishedTorrent(QString hash);
|
2007-09-08 21:07:29 +04:00
|
|
|
void enableUPnP(bool b);
|
|
|
|
void enableNATPMP(bool b);
|
|
|
|
void enableLSD(bool b);
|
2007-10-28 00:53:09 +04:00
|
|
|
bool enableDHT(bool b);
|
2007-11-19 23:33:31 +03:00
|
|
|
void reloadTorrent(const QTorrentHandle &h, bool full_alloc);
|
2008-05-18 12:40:39 +04:00
|
|
|
void setTimerScanInterval(int secs);
|
2008-07-15 02:01:05 +04:00
|
|
|
void setMaxActiveDownloads(int val);
|
|
|
|
void setMaxActiveTorrents(int val);
|
2008-07-27 19:41:46 +04:00
|
|
|
void setETACalculation(bool enable);
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
protected slots:
|
|
|
|
void scanDirectory();
|
2007-03-05 20:35:38 +03:00
|
|
|
void readAlerts();
|
2007-07-22 13:47:27 +04:00
|
|
|
void processDownloadedFile(QString, QString);
|
|
|
|
bool loadTrackerFile(QString hash);
|
|
|
|
void saveTrackerFile(QString hash);
|
2007-09-09 13:09:24 +04:00
|
|
|
void deleteBigRatios();
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
signals:
|
2007-07-22 13:47:27 +04:00
|
|
|
void invalidTorrent(QString path);
|
|
|
|
void duplicateTorrent(QString path);
|
2007-08-20 10:29:18 +04:00
|
|
|
void addedTorrent(QString path, QTorrentHandle& h, bool fastResume);
|
2008-05-16 11:10:50 +04:00
|
|
|
void deletedTorrent(QString hash);
|
|
|
|
void pausedTorrent(QString hash);
|
|
|
|
void resumedTorrent(QString hash);
|
2007-08-20 10:29:18 +04:00
|
|
|
void finishedTorrent(QTorrentHandle& h);
|
|
|
|
void fullDiskError(QTorrentHandle& h);
|
2007-07-22 13:47:27 +04:00
|
|
|
void trackerError(QString hash, QString time, QString msg);
|
2007-03-05 20:35:38 +03:00
|
|
|
void portListeningFailure();
|
2007-08-20 10:29:18 +04:00
|
|
|
void trackerAuthenticationRequired(QTorrentHandle& h);
|
2007-03-08 01:36:01 +03:00
|
|
|
void scanDirFoundTorrents(const QStringList& pathList);
|
2007-07-22 13:47:27 +04:00
|
|
|
void newDownloadedTorrent(QString path, QString url);
|
|
|
|
void aboutToDownloadFromUrl(QString url);
|
2007-04-13 01:28:15 +04:00
|
|
|
void updateFileSize(QString hash);
|
2007-07-22 13:47:27 +04:00
|
|
|
void peerBlocked(QString);
|
|
|
|
void downloadFromUrlFailure(QString url, QString reason);
|
2007-07-24 11:13:40 +04:00
|
|
|
void fastResumeDataRejected(QString name);
|
2007-07-27 13:53:55 +04:00
|
|
|
void urlSeedProblem(QString url, QString msg);
|
2007-08-17 06:03:13 +04:00
|
|
|
void torrentFinishedChecking(QString hash);
|
2008-05-16 11:10:50 +04:00
|
|
|
void torrent_ratio_deleted(QString fileName);
|
2007-12-31 19:57:35 +03:00
|
|
|
void UPnPError(QString msg);
|
2008-01-03 19:17:01 +03:00
|
|
|
void UPnPSuccess(QString msg);
|
2008-07-16 00:19:41 +04:00
|
|
|
void updateFinishedTorrentNumber();
|
|
|
|
void updateUnfinishedTorrentNumber();
|
2007-03-05 20:35:38 +03:00
|
|
|
};
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
#endif
|