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-06-29 20:49:45 +04:00
|
|
|
#include <QTimer>
|
2007-07-23 16:46:36 +04:00
|
|
|
#include <QStringList>
|
2007-06-29 19:23:15 +04:00
|
|
|
|
2007-07-23 16:46:36 +04:00
|
|
|
#include <libtorrent/torrent_handle.hpp>
|
2007-03-05 16:55:23 +03:00
|
|
|
#include <libtorrent/session.hpp>
|
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
2007-03-08 01:36:01 +03:00
|
|
|
class downloadThread;
|
2007-07-23 16:46:36 +04:00
|
|
|
class deleteThread;
|
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;
|
|
|
|
bool DHTEnabled;
|
2007-03-05 20:35:38 +03:00
|
|
|
QString scan_dir;
|
2007-03-05 16:55:23 +03:00
|
|
|
QTimer *timerScan;
|
2007-06-29 20:49:45 +04:00
|
|
|
QTimer timerAlerts;
|
2007-03-08 01:36:01 +03:00
|
|
|
downloadThread *downloader;
|
2007-03-05 20:35:38 +03:00
|
|
|
QStringList supported_preview_extensions;
|
2007-03-08 01:36:01 +03:00
|
|
|
QString defaultSavePath;
|
2007-06-29 01:54:07 +04:00
|
|
|
QStringList torrentsToPauseAfterChecking;
|
2007-06-29 02:58:43 +04:00
|
|
|
QStringList torrentsUnchecked;
|
2007-06-29 19:23:15 +04:00
|
|
|
QHash<QString, QList<long> > ETAstats;
|
|
|
|
QHash<QString, long> ETAs;
|
2007-07-18 11:44:52 +04:00
|
|
|
QHash<QString, QPair<size_type,size_type> > ratioData;
|
2007-06-29 20:49:45 +04:00
|
|
|
QTimer ETARefresher;
|
2007-07-04 14:06:22 +04:00
|
|
|
QList<QString> fullAllocationModeList;
|
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-07-22 13:47:27 +04:00
|
|
|
torrent_handle getTorrentHandle(QString hash) const;
|
2007-03-08 01:36:01 +03:00
|
|
|
std::vector<torrent_handle> getTorrentHandles() const;
|
2007-07-22 13:47:27 +04:00
|
|
|
bool isPaused(QString hash) const;
|
|
|
|
bool hasFilteredFiles(QString fileHash) 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;
|
|
|
|
QList<torrent_handle> getFinishedTorrentHandles() const;
|
|
|
|
session_status getSessionStatus() const;
|
|
|
|
int getListenPort() const;
|
2007-06-29 01:54:07 +04:00
|
|
|
QStringList getTorrentsToPauseAfterChecking() const;
|
2007-06-29 02:58:43 +04:00
|
|
|
QStringList getUncheckedTorrentsList() const;
|
2007-06-29 19:23:15 +04:00
|
|
|
long getETA(QString hash) const;
|
2007-07-04 12:10:44 +04:00
|
|
|
size_type torrentEffectiveSize(QString hash) const;
|
2007-07-22 13:47:27 +04:00
|
|
|
bool inFullAllocationMode(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;
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
public slots:
|
2007-07-22 13:47:27 +04:00
|
|
|
void addTorrent(QString path, bool fromScanDir = false, bool onStartup = false, QString from_url = QString());
|
|
|
|
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);
|
|
|
|
void pauseTorrent(QString hash);
|
2007-06-30 22:56:49 +04:00
|
|
|
bool pauseAllTorrents();
|
|
|
|
bool resumeAllTorrents();
|
2007-07-22 13:47:27 +04:00
|
|
|
void resumeTorrent(QString hash);
|
2007-03-05 16:55:23 +03:00
|
|
|
void enableDHT();
|
|
|
|
void disableDHT();
|
2007-03-08 01:36:01 +03:00
|
|
|
void saveDHTEntry();
|
2007-03-05 16:55:23 +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();
|
2007-03-05 20:35:38 +03:00
|
|
|
void enablePeerExchange();
|
|
|
|
void enableIPFilter(ip_filter filter);
|
|
|
|
void disableIPFilter();
|
2007-07-04 14:06:22 +04:00
|
|
|
void reloadTorrent(const torrent_handle &h);
|
2007-06-29 02:58:43 +04:00
|
|
|
void setTorrentFinishedChecking(QString hash);
|
2007-03-08 01:36:01 +03:00
|
|
|
void resumeUnfinishedTorrents();
|
2007-06-29 19:23:15 +04:00
|
|
|
void updateETAs();
|
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-07-22 13:47:27 +04:00
|
|
|
void HandleDownloadFailure(QString url, QString reason);
|
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-03-05 16:55:23 +03:00
|
|
|
void setDownloadRateLimit(int rate);
|
|
|
|
void setUploadRateLimit(int rate);
|
|
|
|
void setGlobalRatio(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-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-07-04 14:06:22 +04:00
|
|
|
void loadFilesPriorities(torrent_handle& h);
|
2007-07-14 17:38:29 +04:00
|
|
|
void setDownloadLimit(QString hash, int val);
|
|
|
|
void setUploadLimit(QString hash, int val);
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
protected slots:
|
|
|
|
void cleanDeleter(deleteThread* deleter);
|
|
|
|
void scanDirectory();
|
2007-03-05 20:35:38 +03:00
|
|
|
void readAlerts();
|
2007-07-22 13:47:27 +04:00
|
|
|
void processDownloadedFile(QString, QString);
|
2007-03-08 01:36:01 +03:00
|
|
|
void resumeUnfinished();
|
2007-07-22 13:47:27 +04:00
|
|
|
bool loadTrackerFile(QString hash);
|
|
|
|
void saveTrackerFile(QString hash);
|
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);
|
|
|
|
void addedTorrent(QString path, torrent_handle& h, bool fastResume);
|
2007-03-05 20:35:38 +03:00
|
|
|
void finishedTorrent(torrent_handle& h);
|
2007-03-08 01:36:01 +03:00
|
|
|
void fullDiskError(torrent_handle& 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();
|
|
|
|
void trackerAuthenticationRequired(torrent_handle& 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-06-29 02:58:43 +04:00
|
|
|
void allTorrentsFinishedChecking();
|
2007-07-22 13:47:27 +04:00
|
|
|
void peerBlocked(QString);
|
|
|
|
void downloadFromUrlFailure(QString url, QString reason);
|
2007-06-16 00:35:07 +04:00
|
|
|
|
2007-03-05 20:35:38 +03:00
|
|
|
};
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
#endif
|