KVIrc  4.9.2
DeveloperAPIs
TorrentInterface.h
Go to the documentation of this file.
1 #ifndef _TC_INTERFACE_H_
2 #define _TC_INTERFACE_H_
3 
4 //=============================================================================
5 //
6 // Common interface for BitTorrent clients.
7 //
8 // File : TorrentInterface.h
9 // Creation date : Fri Jan 1 15:42:25 2007 GMT by Alexander Stillich
10 //
11 // This file is part of the KVIrc IRC client distribution
12 // Copyright (C) 2007-2008 Alexander Stillich (torque at pltn dot org)
13 //
14 // This program is FREE software. You can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the HOPE that it will be USEFUL,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 // See the GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program. If not, write to the Free Software Foundation,
26 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 //
28 //=============================================================================
29 
30 #include "kvi_settings.h"
31 #include "KviQString.h"
32 
33 #include <QObject>
34 
35 class TorrentInterface : public QObject
36 {
37 public:
39  virtual ~TorrentInterface() {}
40 
41  virtual int detect() = 0;
42 
43  // returns number of torrents in client
44  virtual int count() = 0;
45 
46  /*
47  // path of torrent file
48  virtual QCString getTorrentFile(int i)=0;
49 
50  // directory where data is downloaded to
51  virtual QCString getTorrentDataDir(int i)=0;
52 */
53  // number of files in torrent
54  virtual int fileCount(int i) = 0;
55  // name of file in torrent
56  virtual QString fileName(int i, int file) = 0;
57  // returns file priority (low, normal, high)
58  virtual QString filePriority(int i, int file) = 0;
59  // sets file priority
60  virtual bool setFilePriority(int i, int file, const QString & prio) = 0;
61 
62  virtual bool start(int i) = 0;
63  virtual bool stop(int i) = 0;
64 
65  virtual bool announce(int i) = 0;
66 
67  virtual bool startAll() = 0;
68  virtual bool stopAll() = 0;
69  /*
70  // remove torrent from client
71  virtual bool removeTorrent(int i)=0;
72 
73  virtual bool addTorrent(const QCString &mrl);
74 */
75  // returns state of torrent number i (Stopped, Stalled, Seeding, Downloading)
76  // this uses getTorrentInfo() to obtain the state and then
77  // returns it as string
78  virtual QString state(int i) = 0;
79 
80  // name of torrent as displayed in client
81  // uses getTorrentInfo()
82  virtual QString name(int i) = 0;
83 
84  virtual float speedUp() = 0;
85  virtual float speedDown() = 0;
86 
87  virtual float trafficUp() = 0;
88  virtual float trafficDown() = 0;
89 
90  virtual int maxUploadSpeed() = 0;
91  virtual int maxDownloadSpeed() = 0;
92 
93  virtual bool setMaxUploadSpeed(int kbytes_per_sec) = 0;
94  virtual bool setMaxDownloadSpeed(int kbytes_per_sec) = 0;
95 
96  QString lastError() { return m_lastError; }
97 
98  static void select(TorrentInterface * i) { m_selected = i; }
99  static TorrentInterface * selected() { return m_selected; }
100 
101 protected:
102  QString m_lastError;
104 };
105 
107 {
108 public:
111 
112 public:
113  virtual const QString & name() = 0;
114  virtual const QString & description() = 0;
115  virtual TorrentInterface * instance() = 0;
116 };
117 
118 #define TORR_DECLARE_DESCRIPTOR(_interfaceclass) \
119  class _interfaceclass##Descriptor : public TorrentInterfaceDescriptor \
120  { \
121  public: \
122  _interfaceclass##Descriptor(); \
123  virtual ~_interfaceclass##Descriptor(); \
124  \
125  protected: \
126  _interfaceclass * m_pInstance; \
127  QString m_szName; \
128  QString m_szDescription; \
129  \
130  public: \
131  virtual const QString & name(); \
132  virtual const QString & description(); \
133  virtual TorrentInterface * instance(); \
134  };
135 
136 #define TORR_IMPLEMENT_DESCRIPTOR(_interfaceclass, _name, _description) \
137  _interfaceclass##Descriptor::_interfaceclass##Descriptor() \
138  : TorrentInterfaceDescriptor() \
139  { \
140  m_pInstance = 0; \
141  m_szName = _name; \
142  m_szDescription = _description; \
143  } \
144  _interfaceclass##Descriptor::~_interfaceclass##Descriptor() \
145  { \
146  delete m_pInstance; \
147  } \
148  const QString & _interfaceclass##Descriptor::name() \
149  { \
150  return m_szName; \
151  } \
152  const QString & _interfaceclass##Descriptor::description() \
153  { \
154  return m_szDescription; \
155  } \
156  TorrentInterface * _interfaceclass##Descriptor::instance() \
157  { \
158  if(!m_pInstance) \
159  m_pInstance = new _interfaceclass(); \
160  return m_pInstance; \
161  }
162 
163 #endif // _TC_INTERFACE_H_
virtual int maxDownloadSpeed()=0
TorrentInterface()
Definition: TorrentInterface.h:38
Definition: TorrentInterface.h:106
virtual bool stop(int i)=0
virtual bool start(int i)=0
virtual ~TorrentInterface()
Definition: TorrentInterface.h:39
static TorrentInterface * selected()
Definition: TorrentInterface.h:99
virtual float trafficDown()=0
#define i
Definition: detector.cpp:73
virtual QString filePriority(int i, int file)=0
virtual int maxUploadSpeed()=0
virtual QString state(int i)=0
virtual bool startAll()=0
virtual bool announce(int i)=0
virtual float speedUp()=0
virtual const QString & name()=0
virtual bool setMaxDownloadSpeed(int kbytes_per_sec)=0
static void select(TorrentInterface *i)
Definition: TorrentInterface.h:98
static TorrentInterface * m_selected
Definition: TorrentInterface.h:103
virtual int count()=0
QString m_lastError
Definition: TorrentInterface.h:102
virtual bool stopAll()=0
TorrentInterfaceDescriptor()
Definition: TorrentInterface.h:109
virtual QString name(int i)=0
virtual bool setFilePriority(int i, int file, const QString &prio)=0
virtual ~TorrentInterfaceDescriptor()
Definition: TorrentInterface.h:110
virtual int fileCount(int i)=0
virtual TorrentInterface * instance()=0
Definition: TorrentInterface.h:35
QString lastError()
Definition: TorrentInterface.h:96
This file contains compile time settings.
virtual const QString & description()=0
virtual float trafficUp()=0
virtual int detect()=0
virtual QString fileName(int i, int file)=0
Helper functions for the QString class.
virtual float speedDown()=0
virtual bool setMaxUploadSpeed(int kbytes_per_sec)=0