libktorrent  2.2.0
torrentinterface.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTTORRENTINTERFACE_H
21 #define BTTORRENTINTERFACE_H
22 
23 #include <QSharedPointer>
24 #include <QPointer>
25 #include <QUrl>
26 
27 #include <ktorrent_export.h>
28 #include <util/constants.h>
29 #include <interfaces/trackerslist.h>
30 #include <torrent/torrentstats.h>
31 #include <torrent/torrentfilestream.h>
32 
33 #ifdef ERROR
34 #undef ERROR
35 #endif
36 namespace bt
37 {
38  class Job;
39  class BitSet;
40  class SHA1Hash;
41  class WaitJob;
42  class PeerID;
43  class MonitorInterface;
44  class TorrentFileInterface;
45  class PeerSource;
46  class SHA1Hash;
47  class WebSeedInterface;
48  class JobQueue;
49  class ChunkSelectorInterface;
50 
51 
52  enum TorrentStartResponse
53  {
54  START_OK,
55  USER_CANCELED,
56  NOT_ENOUGH_DISKSPACE,
57  MAX_SHARE_RATIO_REACHED,
58  BUSY_WITH_JOB,
59  QM_LIMITS_REACHED // Max seeds or downloads reached
60  };
61 
62  enum AutoStopReason
63  {
64  MAX_RATIO_REACHED,
65  MAX_SEED_TIME_REACHED
66  };
67 
68 
69  struct DHTNode
70  {
71  QString ip;
72  bt::Uint16 port;
73  };
74 
75  enum TorrentFeature
76  {
77  DHT_FEATURE,
78  UT_PEX_FEATURE // µTorrent peer exchange
79  };
80 
81 
89  class KTORRENT_EXPORT TorrentInterface : public QObject
90  {
91  Q_OBJECT
92  public:
94  ~TorrentInterface() override;
95 
97  void setLoadUrl(const QUrl &u) {url = u;}
98 
100  QUrl loadUrl() const {return url;}
101 
105  virtual void update() = 0;
106 
110  virtual void pause() = 0;
111 
115  virtual void unpause() = 0;
116 
120  virtual void start() = 0;
121 
127  virtual void stop(bt::WaitJob* wjob = 0) = 0;
128 
133  virtual void updateTracker() = 0;
134 
138  virtual void scrapeTracker() = 0;
139 
141  const TorrentStats & getStats() const {return stats;}
142 
148  virtual bool readyForPreview() const = 0;
149 
151  virtual bool isMultimedia() const = 0;
152 
157  virtual QString getTorDir() const = 0;
158 
160  virtual QString getDataDir() const = 0;
161 
166  virtual Uint32 getRunningTimeDL() const = 0;
167 
172  virtual Uint32 getRunningTimeUL() const = 0;
173 
180  virtual bool changeTorDir(const QString & new_dir) = 0;
181 
182  enum ChangeOutputFlags
183  {
184  MOVE_FILES = 1,FULL_PATH = 2
185  };
186 
194  virtual bool changeOutputDir(const QString& new_dir,int flags) = 0;
195 
200  virtual void rollback() = 0;
201 
205  virtual const bt::BitSet & downloadedChunksBitSet() const = 0;
206 
210  virtual const bt::BitSet & availableChunksBitSet() const = 0;
211 
215  virtual const bt::BitSet & excludedChunksBitSet() const = 0;
216 
220  virtual const bt::BitSet & onlySeedChunksBitSet() const = 0;
221 
223  virtual void setMonitor(MonitorInterface* tmo) = 0;
224 
226  virtual Uint32 getNumFiles() const = 0;
227 
233  virtual TorrentFileInterface & getTorrentFile(Uint32 index) = 0;
234 
240  virtual const TorrentFileInterface & getTorrentFile(Uint32 index) const = 0;
241 
247  virtual bool moveTorrentFiles(const QMap<TorrentFileInterface*,QString> & files) = 0;
248 
258  virtual TorrentFileStream::Ptr createTorrentFileStream(bt::Uint32 index,bool streaming_mode,QObject* parent) = 0;
259 
262 
264  virtual const TrackersList* getTrackersList() const = 0;
265 
267  virtual int getPriority() const = 0;
268 
270  virtual void setPriority(int p) = 0;
271 
273  virtual void setMaxShareRatio(float ratio) = 0;
274 
276  virtual float getMaxShareRatio() const = 0;
277 
279  virtual void setMaxSeedTime(float hours) = 0;
280 
282  virtual float getMaxSeedTime() const = 0;
283 
285  virtual QString getComments() const = 0;
286 
288  virtual void updateStatus() = 0;
289 
291  virtual bool announceAllowed() = 0;
292 
293 
298  virtual int getETA() = 0;
299 
307  virtual Job* startDataCheck(bool auto_import, bt::Uint32 from, bt::Uint32 to) = 0;
308 
314  virtual bool isStorageMounted(QStringList & missing) = 0;
315 
320  virtual bool hasMissingFiles(QStringList & sl) = 0;
321 
325  virtual void recreateMissingFiles() = 0;
326 
330  virtual void dndMissingFiles() = 0;
331 
332 
334  virtual Uint32 getNumDHTNodes() const = 0;
335 
337  virtual const DHTNode & getDHTNode(Uint32 i) const = 0;
338 
342  virtual void deleteDataFiles() = 0;
343 
345  virtual bool overMaxRatio() = 0;
346 
348  virtual bool overMaxSeedTime() = 0;
349 
351  virtual void handleError(const QString & err) = 0;
352 
354  virtual const bt::SHA1Hash & getInfoHash() const = 0;
355 
360  virtual void addPeerSource(PeerSource* ps) = 0;
361 
366  virtual void removePeerSource(PeerSource* ps) = 0;
367 
369  virtual bool isFeatureEnabled(TorrentFeature tf) = 0;
370 
372  virtual void setFeatureEnabled(TorrentFeature tf,bool on) = 0;
373 
375  virtual const bt::PeerID & getOwnPeerID() const = 0;
376 
378  virtual void setTrafficLimits(Uint32 up,Uint32 down) = 0;
379 
381  virtual void getTrafficLimits(Uint32 & up,Uint32 & down) = 0;
382 
384  virtual void setAssuredSpeeds(Uint32 up,Uint32 down) = 0;
385 
387  virtual void getAssuredSpeeds(Uint32 & up,Uint32 & down) = 0;
388 
390  virtual bool checkDiskSpace(bool emit_sig = true) = 0;
391 
393  virtual const QTextCodec* getTextCodec() const = 0;
394 
396  virtual void changeTextCodec(QTextCodec* tc) = 0;
397 
399  virtual Uint32 getNumWebSeeds() const = 0;
400 
402  virtual const WebSeedInterface* getWebSeed(Uint32 i) const = 0;
403 
405  virtual WebSeedInterface* getWebSeed(Uint32 i) = 0;
406 
408  virtual bool addWebSeed(const QUrl &url) = 0;
409 
411  virtual bool removeWebSeed(const QUrl &url) = 0;
412 
414  virtual void markExistingFilesAsDownloaded() = 0;
415 
417  virtual void setUserModifiedFileName(const QString & n) {user_modified_name = n;}
418 
420  QString getUserModifiedFileName() const {return user_modified_name.isEmpty() ? stats.torrent_name : user_modified_name;}
421 
423  virtual void setDisplayName(const QString & n) = 0;
424 
426  QString getDisplayName() const {return display_name.isEmpty() ? stats.torrent_name : display_name;}
427 
429  virtual void setAllowedToStart(bool on) = 0;
430 
435  bool isAllowedToStart() const {return stats.qm_can_start;}
436 
440  virtual void setQueued(bool queued) = 0;
441 
443  virtual const JobQueue* getJobQueue() const = 0;
444 
446  virtual void setChunkSelector(ChunkSelectorInterface* csel) = 0;
447 
449  virtual void networkUp() = 0;
450 
455  virtual void setMoveWhenCompletedDir(const QString &dir) = 0;
456 
460  virtual QString getMoveWhenCompletedDir() const = 0;
461 
465  virtual void setSuperSeeding(bool on) = 0;
466 
467  typedef QSharedPointer<TorrentInterface> Ptr;
468  typedef QPointer<TorrentInterface> WPtr;
469 
470  Q_SIGNALS:
476 
482  void stoppedByError(bt::TorrentInterface* me, QString msg);
483 
489 
496  void seedingAutoStopped(bt::TorrentInterface* me,bt::AutoStopReason reason);
497 
505 
512 
518 
524  void diskSpaceLow(bt::TorrentInterface* me, bool toStop);
525 
531 
537 
543 
549  void chunkDownloaded(bt::TorrentInterface* me,bt::Uint32 chunk);
550 
554  void updateQueue();
555 
561 
562  protected:
563  TorrentStats stats;
564  QString user_modified_name;
565  QString display_name;
566  QUrl url;
567  };
568 
569 }
570 
571 #endif
bt::TorrentInterface::getUserModifiedFileName
QString getUserModifiedFileName() const
Gets the user modified file or toplevel directory name.
Definition: torrentinterface.h:420
bt::TorrentInterface::networkUp
virtual void networkUp()=0
After some network down time, the network is back up.
bt::TorrentInterface::stoppedByError
void stoppedByError(bt::TorrentInterface *me, QString msg)
bt::TorrentInterface::getMaxShareRatio
virtual float getMaxShareRatio() const =0
Get the max share ratio.
bt::TorrentInterface::getComments
virtual QString getComments() const =0
Get the comments.
bt::TorrentInterface::setMoveWhenCompletedDir
virtual void setMoveWhenCompletedDir(const QString &dir)=0
bt::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:37
bt::TorrentInterface::onlySeedChunksBitSet
virtual const bt::BitSet & onlySeedChunksBitSet() const =0
bt::TorrentInterface::createTorrentFileStream
virtual TorrentFileStream::Ptr createTorrentFileStream(bt::Uint32 index, bool streaming_mode, QObject *parent)=0
bt::TorrentInterface::startDataCheck
virtual Job * startDataCheck(bool auto_import, bt::Uint32 from, bt::Uint32 to)=0
bt::TorrentInterface::needDataCheck
void needDataCheck(bt::TorrentInterface *me)
bt::TorrentInterface::getMoveWhenCompletedDir
virtual QString getMoveWhenCompletedDir() const =0
bt::TorrentInterface::changeOutputDir
virtual bool changeOutputDir(const QString &new_dir, int flags)=0
bt::TorrentInterface::dndMissingFiles
virtual void dndMissingFiles()=0
bt::TorrentInterface::getNumDHTNodes
virtual Uint32 getNumDHTNodes() const =0
Get the number of initial DHT nodes.
bt::TorrentInterface::getStats
const TorrentStats & getStats() const
Get the torrent's statistics.
Definition: torrentinterface.h:141
bt::TorrentInterface::markExistingFilesAsDownloaded
virtual void markExistingFilesAsDownloaded()=0
Mark all existing files as downloaded (.
bt::TorrentInterface::removePeerSource
virtual void removePeerSource(PeerSource *ps)=0
bt::TorrentInterface::setLoadUrl
void setLoadUrl(const QUrl &u)
Set the URL which the torrent was loaded from.
Definition: torrentinterface.h:97
bt::TorrentInterface::chunkDownloaded
void chunkDownloaded(bt::TorrentInterface *me, bt::Uint32 chunk)
bt::TorrentFileInterface
Interface for a file in a multifile torrent.
Definition: torrentfileinterface.h:40
bt::TorrentInterface::seedingAutoStopped
void seedingAutoStopped(bt::TorrentInterface *me, bt::AutoStopReason reason)
bt::TorrentInterface::getDataDir
virtual QString getDataDir() const =0
Get the data directory of this torrent.
bt::TorrentInterface::removeWebSeed
virtual bool removeWebSeed(const QUrl &url)=0
Remove a webseed (only user created ones can be removed)
bt::TorrentInterface::addPeerSource
virtual void addPeerSource(PeerSource *ps)=0
bt::ChunkSelectorInterface
Definition: chunkselectorinterface.h:41
bt::TorrentInterface::getTorrentFile
virtual TorrentFileInterface & getTorrentFile(Uint32 index)=0
bt::TorrentInterface::excludedChunksBitSet
virtual const bt::BitSet & excludedChunksBitSet() const =0
bt::TorrentInterface::getInfoHash
virtual const bt::SHA1Hash & getInfoHash() const =0
Get the info_hash.
bt::TorrentInterface::setQueued
virtual void setQueued(bool queued)=0
bt::JobQueue
Definition: jobqueue.h:36
bt::TorrentInterface::getTrackersList
virtual TrackersList * getTrackersList()=0
Get a pointer to TrackersList object.
bt::Job
Definition: job.h:38
bt::TorrentInterface::setAssuredSpeeds
virtual void setAssuredSpeeds(Uint32 up, Uint32 down)=0
Set the assured speeds.
bt::TorrentInterface::setMaxSeedTime
virtual void setMaxSeedTime(float hours)=0
Set the max seed time in hours (0 is no limit)
bt::TorrentInterface::changeTextCodec
virtual void changeTextCodec(QTextCodec *tc)=0
Set the text codec.
bt::TorrentInterface::getETA
virtual int getETA()=0
bt::WaitJob
Definition: waitjob.h:39
bt::TorrentInterface::hasMissingFiles
virtual bool hasMissingFiles(QStringList &sl)=0
bt::TorrentInterface::downloadedChunksBitSet
virtual const bt::BitSet & downloadedChunksBitSet() const =0
bt::DHTNode
Definition: torrentinterface.h:70
bt::TorrentInterface::overMaxRatio
virtual bool overMaxRatio()=0
Checks if a seeding torrent has reached its maximum share ratio.
bt::PeerSource
Definition: peersource.h:42
bt::TorrentInterface::loadUrl
QUrl loadUrl() const
Get the URL which the torrent was loaded from.
Definition: torrentinterface.h:100
bt::TorrentInterface::isFeatureEnabled
virtual bool isFeatureEnabled(TorrentFeature tf)=0
Is a feature enabled.
bt::TorrentInterface::getTextCodec
virtual const QTextCodec * getTextCodec() const =0
Get the text codec used in the torrent.
bt::TorrentInterface::getOwnPeerID
virtual const bt::PeerID & getOwnPeerID() const =0
Get our PeerID.
bt::TrackersList
Definition: trackerslist.h:44
bt::TorrentInterface::finished
void finished(bt::TorrentInterface *me)
bt::TorrentInterface::checkDiskSpace
virtual bool checkDiskSpace(bool emit_sig=true)=0
Check if there is enough diskspace available for this torrent.
bt::TorrentStats
Definition: torrentstats.h:55
bt::TorrentInterface::deleteDataFiles
virtual void deleteDataFiles()=0
bt::TorrentInterface::setSuperSeeding
virtual void setSuperSeeding(bool on)=0
bt::TorrentInterface::getWebSeed
virtual WebSeedInterface * getWebSeed(Uint32 i)=0
Get a webseed (returns 0 if index is invalid)
bt::TorrentInterface::aboutToBeStarted
void aboutToBeStarted(bt::TorrentInterface *me, bool &ret)
bt::WebSeedInterface
Definition: webseedinterface.h:35
bt::TorrentInterface::setTrafficLimits
virtual void setTrafficLimits(Uint32 up, Uint32 down)=0
Set the traffic limits for this torrent.
bt::TorrentInterface::setFeatureEnabled
virtual void setFeatureEnabled(TorrentFeature tf, bool on)=0
Disable or enable a feature.
bt::TorrentInterface::getTorDir
virtual QString getTorDir() const =0
bt::MonitorInterface
Interface for classes who want to monitor a TorrentInterface.
Definition: monitorinterface.h:39
bt::TorrentInterface::getDisplayName
QString getDisplayName() const
Gets the displayed name.
Definition: torrentinterface.h:426
bt::TorrentInterface::getWebSeed
virtual const WebSeedInterface * getWebSeed(Uint32 i) const =0
Get a webseed (returns 0 if index is invalid)
bt::TorrentInterface::corruptedDataFound
void corruptedDataFound(bt::TorrentInterface *me)
bt::TorrentInterface::rollback
virtual void rollback()=0
bt::TorrentInterface::setPriority
virtual void setPriority(int p)=0
Set the torrent queue number.
bt::TorrentInterface::getTrackersList
virtual const TrackersList * getTrackersList() const =0
Get a pointer to TrackersList object.
bt::TorrentInterface::getNumWebSeeds
virtual Uint32 getNumWebSeeds() const =0
Get the number of webseeds.
bt::TorrentInterface::overMaxSeedTime
virtual bool overMaxSeedTime()=0
Checks if a seeding torrent has reached it's max seed timery / will be ret.
bt::TorrentInterface::statusChanged
void statusChanged(bt::TorrentInterface *me)
bt::TorrentInterface::maxRatioChanged
void maxRatioChanged(bt::TorrentInterface *me)
bt::TorrentInterface::getNumFiles
virtual Uint32 getNumFiles() const =0
Get the number of files in a multifile torrent (0 if we do not have a multifile torrent)
bt::TorrentInterface::getDHTNode
virtual const DHTNode & getDHTNode(Uint32 i) const =0
Get a DHT node.
bt::TorrentInterface::isStorageMounted
virtual bool isStorageMounted(QStringList &missing)=0
bt::TorrentInterface::addWebSeed
virtual bool addWebSeed(const QUrl &url)=0
Add a webseed (return false, if there is already a webseed with the same url)
bt::TorrentInterface::setMaxShareRatio
virtual void setMaxShareRatio(float ratio)=0
Set the max share ratio.
bt::TorrentInterface::update
virtual void update()=0
bt::TorrentInterface::getJobQueue
virtual const JobQueue * getJobQueue() const =0
Get the JobQueue of the torrent.
bt::TorrentInterface::updateStatus
virtual void updateStatus()=0
Update the status.
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
bt::TorrentInterface::diskSpaceLow
void diskSpaceLow(bt::TorrentInterface *me, bool toStop)
bt::TorrentInterface::getRunningTimeDL
virtual Uint32 getRunningTimeDL() const =0
bt::TorrentInterface::unpause
virtual void unpause()=0
bt::TorrentInterface::torrentStopped
void torrentStopped(bt::TorrentInterface *me)
bt::TorrentInterface::moveTorrentFiles
virtual bool moveTorrentFiles(const QMap< TorrentFileInterface *, QString > &files)=0
bt::TorrentInterface::getMaxSeedTime
virtual float getMaxSeedTime() const =0
Get the max seed time.
bt::TorrentInterface::setAllowedToStart
virtual void setAllowedToStart(bool on)=0
Set whether the QM can start a torrent.
bt::TorrentInterface::stop
virtual void stop(bt::WaitJob *wjob=0)=0
bt::TorrentInterface::isAllowedToStart
bool isAllowedToStart() const
Definition: torrentinterface.h:435
bt::TorrentInterface::setChunkSelector
virtual void setChunkSelector(ChunkSelectorInterface *csel)=0
Set the ChunkSelector to use (0 resets to the default ChunkSelector)
bt::TorrentInterface::pause
virtual void pause()=0
bt::TorrentInterface::readyForPreview
virtual bool readyForPreview() const =0
bt::TorrentInterface::getAssuredSpeeds
virtual void getAssuredSpeeds(Uint32 &up, Uint32 &down)=0
Get the assured speeds.
bt::TorrentInterface::missingFilesMarkedDND
void missingFilesMarkedDND(bt::TorrentInterface *me)
bt::TorrentInterface::updateTracker
virtual void updateTracker()=0
bt::TorrentInterface::getTorrentFile
virtual const TorrentFileInterface & getTorrentFile(Uint32 index) const =0
bt::TorrentInterface::getTrafficLimits
virtual void getTrafficLimits(Uint32 &up, Uint32 &down)=0
Get the traffic limits.
bt::TorrentInterface::isMultimedia
virtual bool isMultimedia() const =0
See if this is a single file torrent and a multimedia files.
bt::TorrentInterface::announceAllowed
virtual bool announceAllowed()=0
Is manual announce allowed?
bt::TorrentInterface::updateQueue
void updateQueue()
bt::TorrentInterface::getPriority
virtual int getPriority() const =0
Get the torrent queue number. Zero if not in queue.
bt::TorrentInterface::start
virtual void start()=0
bt::TorrentInterface::scrapeTracker
virtual void scrapeTracker()=0
bt::PeerID
Definition: peerid.h:33
bt::TorrentInterface::setUserModifiedFileName
virtual void setUserModifiedFileName(const QString &n)
Set the user modified file or toplevel directory name.
Definition: torrentinterface.h:417
bt::TorrentInterface::availableChunksBitSet
virtual const bt::BitSet & availableChunksBitSet() const =0
bt::TorrentInterface::setDisplayName
virtual void setDisplayName(const QString &n)=0
Set the displayed name.
bt::TorrentInterface::getRunningTimeUL
virtual Uint32 getRunningTimeUL() const =0
bt::TorrentInterface::handleError
virtual void handleError(const QString &err)=0
Handle an error.
bt::TorrentInterface::recreateMissingFiles
virtual void recreateMissingFiles()=0
bt::TorrentInterface::changeTorDir
virtual bool changeTorDir(const QString &new_dir)=0
bt::TorrentInterface
Interface for an object which controls one torrent.
Definition: torrentinterface.h:90
bt::TorrentInterface::runningJobsDone
void runningJobsDone(bt::TorrentInterface *me)
bt::TorrentInterface::setMonitor
virtual void setMonitor(MonitorInterface *tmo)=0
Set the monitor.