2007-03-05 16:55:23 +03:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#ifndef __BITTORRENT_H__
|
|
|
|
#define __BITTORRENT_H__
|
|
|
|
|
|
|
|
#include <libtorrent/entry.hpp>
|
|
|
|
#include <libtorrent/bencode.hpp>
|
|
|
|
#include <libtorrent/session.hpp>
|
|
|
|
#include <libtorrent/fingerprint.hpp>
|
|
|
|
#include <libtorrent/session_settings.hpp>
|
|
|
|
#include <libtorrent/identify_client.hpp>
|
|
|
|
#include <libtorrent/alert_types.hpp>
|
|
|
|
#include <libtorrent/extensions/metadata_transfer.hpp>
|
|
|
|
#include <libtorrent/extensions/ut_pex.hpp>
|
2007-03-05 20:35:38 +03:00
|
|
|
#include <libtorrent/ip_filter.hpp>
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
|
|
#include <boost/filesystem/exception.hpp>
|
|
|
|
|
|
|
|
#include "deleteThread.h"
|
|
|
|
|
2007-03-27 22:49:29 +04:00
|
|
|
class QTimer;
|
|
|
|
class QString;
|
|
|
|
|
2007-03-05 16:55:23 +03:00
|
|
|
using namespace libtorrent;
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2007-03-08 01:36:01 +03:00
|
|
|
class downloadThread;
|
2007-03-20 00:15:29 +03:00
|
|
|
#ifndef NO_UPNP
|
|
|
|
class CUPnPControlPoint;
|
|
|
|
class CUPnPPortMapping;
|
|
|
|
#endif
|
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-20 00:15:29 +03:00
|
|
|
#ifndef NO_UPNP
|
|
|
|
bool UPnPEnabled;
|
|
|
|
#endif
|
2007-03-05 20:35:38 +03:00
|
|
|
QString scan_dir;
|
2007-03-05 16:55:23 +03:00
|
|
|
QTimer *timerScan;
|
2007-03-05 20:35:38 +03: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-03-20 00:15:29 +03:00
|
|
|
#ifndef NO_UPNP
|
|
|
|
CUPnPControlPoint* m_upnp;
|
|
|
|
std::vector<CUPnPPortMapping> m_upnpMappings;
|
|
|
|
#endif
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2007-03-05 20:35:38 +03:00
|
|
|
protected:
|
|
|
|
QString getSavePath(const QString& hash);
|
|
|
|
|
2007-03-05 16:55:23 +03:00
|
|
|
public:
|
2007-03-08 01:36:01 +03:00
|
|
|
// Constructor / Destructor
|
|
|
|
bittorrent();
|
|
|
|
~bittorrent();
|
2007-03-05 20:35:38 +03:00
|
|
|
torrent_handle getTorrentHandle(const QString& hash) const;
|
2007-03-08 01:36:01 +03:00
|
|
|
std::vector<torrent_handle> getTorrentHandles() const;
|
|
|
|
bool isPaused(const QString& hash) const;
|
2007-03-05 16:55:23 +03:00
|
|
|
bool hasFilteredFiles(const QString& fileHash) const;
|
2007-03-05 20:35:38 +03:00
|
|
|
bool isFilePreviewPossible(const 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-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void addTorrent(const QString& path, bool fromScanDir = false, const QString& from_url = QString());
|
2007-03-08 01:36:01 +03:00
|
|
|
void downloadFromUrl(const QString& url);
|
|
|
|
void downloadFromURLList(const QStringList& url_list);
|
2007-03-05 20:35:38 +03:00
|
|
|
void deleteTorrent(const QString& hash, bool permanent = false);
|
2007-03-05 16:55:23 +03:00
|
|
|
void pauseTorrent(const QString& hash);
|
2007-03-08 19:40:02 +03:00
|
|
|
void pauseAllTorrents();
|
|
|
|
void resumeAllTorrents();
|
2007-03-05 16:55:23 +03:00
|
|
|
void resumeTorrent(const QString& hash);
|
|
|
|
void enableDHT();
|
|
|
|
void disableDHT();
|
2007-03-08 01:36:01 +03:00
|
|
|
void saveDHTEntry();
|
2007-03-05 16:55:23 +03:00
|
|
|
void saveFastResumeData();
|
|
|
|
void enableDirectoryScanning(const QString& scan_dir);
|
|
|
|
void disableDirectoryScanning();
|
2007-03-05 20:35:38 +03:00
|
|
|
void enablePeerExchange();
|
|
|
|
void enableIPFilter(ip_filter filter);
|
|
|
|
void disableIPFilter();
|
2007-03-08 01:36:01 +03:00
|
|
|
void reloadTorrent(const torrent_handle &h, bool compact_mode = true);
|
|
|
|
void resumeUnfinishedTorrents();
|
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);
|
|
|
|
void setSessionSettings(session_settings sessionSettings);
|
2007-03-08 01:36:01 +03:00
|
|
|
void setDefaultSavePath(const QString& savepath);
|
2007-03-20 00:15:29 +03:00
|
|
|
#ifndef NO_UPNP
|
|
|
|
void enableUPnP();
|
|
|
|
void disableUPnP();
|
|
|
|
#endif
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
protected slots:
|
|
|
|
void cleanDeleter(deleteThread* deleter);
|
|
|
|
void loadFilteredFiles(torrent_handle& h);
|
|
|
|
void scanDirectory();
|
2007-03-05 20:35:38 +03:00
|
|
|
void readAlerts();
|
2007-03-08 01:36:01 +03:00
|
|
|
void processDownloadedFile(const QString&, const QString&, int, const QString&);
|
|
|
|
void resumeUnfinished();
|
2007-03-25 22:39:27 +04:00
|
|
|
bool loadTrackerFile(const QString& hash);
|
2007-03-25 20:18:57 +04:00
|
|
|
void saveTrackerFile(const QString& hash);
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void invalidTorrent(const QString& path);
|
|
|
|
void duplicateTorrent(const QString& path);
|
|
|
|
void addedTorrent(const 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-03-05 20:35:38 +03:00
|
|
|
void trackerError(const QString& hash, const QString& time, const QString& msg);
|
|
|
|
void portListeningFailure();
|
|
|
|
void trackerAuthenticationRequired(torrent_handle& h);
|
2007-03-08 01:36:01 +03:00
|
|
|
void downloadFromUrlFailure(const QString& url, const QString& error);
|
|
|
|
void scanDirFoundTorrents(const QStringList& pathList);
|
|
|
|
void newDownloadedTorrent(const QString& path, const QString& url);
|
2007-03-08 20:00:12 +03:00
|
|
|
void aboutToDownloadFromUrl(const QString& url);
|
2007-03-05 20:35:38 +03:00
|
|
|
};
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
#endif
|