libktorrent  2.1.1
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:
93  TorrentInterface();
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 
261  virtual TrackersList* getTrackersList() = 0;
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:
475  void finished(bt::TorrentInterface* me);
476 
482  void stoppedByError(bt::TorrentInterface* me, QString msg);
483 
488  void maxRatioChanged(bt::TorrentInterface* me);
489 
496  void seedingAutoStopped(bt::TorrentInterface* me,bt::AutoStopReason reason);
497 
504  void aboutToBeStarted(bt::TorrentInterface* me,bool & ret);
505 
511  void missingFilesMarkedDND(bt::TorrentInterface* me);
512 
517  void corruptedDataFound(bt::TorrentInterface* me);
518 
524  void diskSpaceLow(bt::TorrentInterface* me, bool toStop);
525 
530  void torrentStopped(bt::TorrentInterface* me);
531 
536  void needDataCheck(bt::TorrentInterface* me);
537 
542  void statusChanged(bt::TorrentInterface* me);
543 
549  void chunkDownloaded(bt::TorrentInterface* me,bt::Uint32 chunk);
550 
554  void updateQueue();
555 
560  void runningJobsDone(bt::TorrentInterface* me);
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::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:55
bt::TorrentFileInterface
Interface for a file in a multifile torrent.
Definition: torrentfileinterface.h:40
bt::ChunkSelectorInterface
Definition: chunkselectorinterface.h:60
bt::JobQueue
Definition: jobqueue.h:54
bt::Job
Definition: job.h:38
bt::WaitJob
Definition: waitjob.h:57
bt::DHTNode
Definition: torrentinterface.h:88
bt::PeerSource
Definition: peersource.h:60
bt::TrackersList
Definition: trackerslist.h:55
bt::TorrentStats
Definition: torrentstats.h:73
bt::WebSeedInterface
Definition: webseedinterface.h:54
bt::MonitorInterface
Interface for classes who want to monitor a TorrentInterface.
Definition: monitorinterface.h:57
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
bt::PeerID
Definition: peerid.h:51
bt::TorrentInterface
Interface for an object which controls one torrent.
Definition: torrentinterface.h:108