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