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>
|
2007-07-23 16:46:36 +04:00
|
|
|
#include <QStringList>
|
2008-09-07 15:31:29 +04:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QPalette>
|
2008-09-13 11:33:41 +04:00
|
|
|
#include <QPointer>
|
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-07-30 17:56:31 +04:00
|
|
|
class QTimer;
|
2008-12-26 16:17:08 +03:00
|
|
|
class QFileSystemWatcher;
|
|
|
|
class QMutex;
|
2008-05-18 00:32:03 +04:00
|
|
|
class FilterParserThread;
|
2007-03-08 01:36:01 +03:00
|
|
|
|
2008-09-07 15:31:29 +04:00
|
|
|
class bittorrent : public QObject {
|
2007-03-05 20:35:38 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
2007-03-05 16:55:23 +03:00
|
|
|
private:
|
|
|
|
session *s;
|
2008-12-26 16:17:08 +03:00
|
|
|
QPointer<QFileSystemWatcher> FSWatcher;
|
|
|
|
QMutex* FSMutex;
|
2008-11-04 22:01:51 +03:00
|
|
|
QPointer<QTimer> timerAlerts;
|
2008-09-13 11:33:41 +04:00
|
|
|
QPointer<QTimer> BigRatioTimer;
|
2007-08-28 20:17:32 +04:00
|
|
|
bool DHTEnabled;
|
2008-11-04 22:01:51 +03:00
|
|
|
QPointer<downloadThread> downloader;
|
2007-03-08 01:36:01 +03:00
|
|
|
QString defaultSavePath;
|
2009-03-08 19:26:02 +03:00
|
|
|
QString defaultTempPath;
|
2008-05-15 23:48:15 +04:00
|
|
|
QHash<QString, QHash<QString, QString> > trackersErrors;
|
2008-09-07 15:31:29 +04:00
|
|
|
QStringList consoleMessages;
|
|
|
|
QStringList peerBanMessages;
|
2007-09-08 21:07:29 +04:00
|
|
|
bool preAllocateAll;
|
|
|
|
bool addInPause;
|
2007-09-09 11:44:22 +04:00
|
|
|
int maxConnecsPerTorrent;
|
|
|
|
int maxUploadsPerTorrent;
|
2009-07-12 11:23:11 +04:00
|
|
|
float ratio_limit;
|
2007-11-23 18:20:26 +03:00
|
|
|
bool UPnPEnabled;
|
|
|
|
bool NATPMPEnabled;
|
|
|
|
bool LSDEnabled;
|
2008-09-13 11:33:41 +04:00
|
|
|
QPointer<FilterParserThread> filterParser;
|
2008-05-18 00:32:03 +04:00
|
|
|
QString filterPath;
|
2008-07-15 02:01:05 +04:00
|
|
|
bool queueingEnabled;
|
2008-09-14 14:14:54 +04:00
|
|
|
QStringList url_skippingDlg;
|
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;
|
2008-12-27 00:18:33 +03:00
|
|
|
std::vector<torrent_handle> getTorrents() const;
|
2007-07-22 13:47:27 +04:00
|
|
|
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-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-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-15 02:01:05 +04:00
|
|
|
int loadTorrentPriority(QString hash);
|
2008-09-07 15:31:29 +04:00
|
|
|
QStringList getConsoleMessages() const;
|
|
|
|
QStringList getPeerBanMessages() const;
|
2008-11-02 16:07:38 +03:00
|
|
|
qlonglong getETA(QString hash) const;
|
2009-08-16 07:09:20 +04:00
|
|
|
bool useTemporaryFolder() const;
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
public slots:
|
2008-12-30 03:34:41 +03:00
|
|
|
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
2009-08-17 09:14:03 +04:00
|
|
|
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
2008-11-02 16:19:27 +03:00
|
|
|
void loadSessionState();
|
|
|
|
void saveSessionState();
|
2007-07-22 13:47:27 +04:00
|
|
|
void downloadFromUrl(QString url);
|
|
|
|
void deleteTorrent(QString hash, bool permanent = false);
|
2009-08-16 07:09:20 +04:00
|
|
|
void startUpTorrents();
|
2008-12-27 13:14:16 +03:00
|
|
|
/* Needed by Web UI */
|
2008-05-16 11:10:50 +04:00
|
|
|
void pauseAllTorrents();
|
2008-12-27 13:14:16 +03:00
|
|
|
void pauseTorrent(QString hash);
|
|
|
|
void resumeTorrent(QString hash);
|
2009-08-16 07:09:20 +04:00
|
|
|
void resumeAllTorrents();
|
2008-12-27 13:14:16 +03:00
|
|
|
/* End Web UI */
|
2007-03-08 01:36:01 +03:00
|
|
|
void saveDHTEntry();
|
2007-09-08 21:07:29 +04:00
|
|
|
void preAllocateAllFiles(bool b);
|
2008-11-02 01:07:14 +03:00
|
|
|
void saveFastResumeData();
|
2007-07-22 13:47:27 +04:00
|
|
|
void enableDirectoryScanning(QString scan_dir);
|
2007-03-05 16:55:23 +03:00
|
|
|
void disableDirectoryScanning();
|
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-07-14 17:38:29 +04:00
|
|
|
void saveTorrentSpeedLimits(QString hash);
|
|
|
|
void loadTorrentSpeedLimits(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 increaseDlTorrentPriority(QString hash);
|
|
|
|
void decreaseDlTorrentPriority(QString hash);
|
2008-09-14 14:14:54 +04:00
|
|
|
void downloadUrlAndSkipDialog(QString);
|
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);
|
2009-03-08 19:26:02 +03:00
|
|
|
void setDefaultTempPath(QString temppath);
|
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-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);
|
2008-09-07 15:31:29 +04:00
|
|
|
void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText));
|
|
|
|
void addPeerBanMessage(QString msg, bool from_ipfilter);
|
2009-03-28 01:11:41 +03:00
|
|
|
void processDownloadedFile(QString, QString);
|
2009-08-16 07:09:20 +04:00
|
|
|
void saveTrackerFile(QString hash);
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
protected slots:
|
2008-12-26 16:17:08 +03:00
|
|
|
void scanDirectory(QString);
|
2007-03-05 20:35:38 +03:00
|
|
|
void readAlerts();
|
2009-08-16 07:09:20 +04:00
|
|
|
void loadTrackerFile(QString hash);
|
2007-09-09 13:09:24 +04:00
|
|
|
void deleteBigRatios();
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
signals:
|
2008-09-07 15:31:29 +04:00
|
|
|
void addedTorrent(QTorrentHandle& h);
|
2008-05-16 11:10:50 +04:00
|
|
|
void deletedTorrent(QString hash);
|
2008-12-29 21:36:54 +03:00
|
|
|
void pausedTorrent(QTorrentHandle& h);
|
|
|
|
void resumedTorrent(QTorrentHandle& h);
|
2007-08-20 10:29:18 +04:00
|
|
|
void finishedTorrent(QTorrentHandle& h);
|
2009-04-18 00:04:09 +04:00
|
|
|
void fullDiskError(QTorrentHandle& h, QString msg);
|
2007-07-22 13:47:27 +04:00
|
|
|
void trackerError(QString hash, QString time, QString msg);
|
2007-08-20 10:29:18 +04:00
|
|
|
void trackerAuthenticationRequired(QTorrentHandle& h);
|
2007-07-22 13:47:27 +04:00
|
|
|
void newDownloadedTorrent(QString path, QString url);
|
2007-04-13 01:28:15 +04:00
|
|
|
void updateFileSize(QString hash);
|
2007-07-22 13:47:27 +04:00
|
|
|
void downloadFromUrlFailure(QString url, QString reason);
|
2008-12-27 01:11:40 +03:00
|
|
|
void torrentFinishedChecking(QTorrentHandle& h);
|
2009-08-17 09:14:03 +04:00
|
|
|
void metadataReceived(QTorrentHandle &h);
|
2007-03-05 20:35:38 +03:00
|
|
|
};
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
#endif
|