summaryrefslogtreecommitdiffstats
path: root/src/modules/torrent/tc_ktorrentdcopinterface.h
blob: 8f39810f0a640f31610cbad3f503e6be331f9085 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef _TC_KTORRENTDCOPINTERFACE_H_
#define _TC_KTORRENTDCOPINTERFACE_H_

//=============================================================================
//
//	DCOP interface for KTorrent client.
//
//   File : torr_ktorrentdcopinterface.h
//   Creation date : Fri Jan 1 15:42:25 2007 GMT by Alexander Stillich
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2001-2005 Szymon Stefanek (pragma at kvirc dot net)
//   Copyright (C) 2007 Alexander Stillich (torque at pltn dot org)
//
//   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 opinion) 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.
//
//=============================================================================


#include "tc_interface.h"

#ifdef COMPILE_KDE_SUPPORT

#include <kvi_dcophelper.h>

// DCOP interface to KTorrent. this has 'DCOP' in its name
// because in kde4 there will be a D-BUS interface.
class KviKTorrentDCOPInterface : public KviTorrentInterface,
                                 private KviDCOPHelper
{
	Q_OBJECT

public:

	KviKTorrentDCOPInterface();
	virtual ~KviKTorrentDCOPInterface();

	virtual int detect();

	virtual int count();

	virtual bool start(int i);
	virtual bool stop(int i);
	virtual bool announce(int i);
	virtual QString state(int i);
	virtual QString name(int i);

	virtual int fileCount(int i);
	virtual QString fileName(int i, int file);
	virtual QString filePriority(int i, int file);
	virtual bool setFilePriority(int i, int file, const QString &prio);

	virtual bool startAll();
	virtual bool stopAll();

	virtual int maxUploadSpeed();
	virtual int maxDownloadSpeed();

	virtual bool setMaxUploadSpeed(int kbytes_per_sec);
	virtual bool setMaxDownloadSpeed(int kbytes_per_sec);

	virtual float speedUp();
	virtual float speedDown();

	virtual float trafficUp();
	virtual float trafficDown();

private slots:

	// polls client and extracts information.
	// this is done because the order of torrents returned changes
	// each time a torrent's state changes.
	// we want to present a consistent list (in terms of indices) to
	// the user, so we extract the info and sort it by name.
	// otherwise the user would have a hard time figuring out what's
	// going on. we could sort each time a function working with
	// torrents is called, but this would be horribly slow ...
	void	slotTimer();

private:

	struct TorrentInfo
	{
		// internal number
		int num;
		// name displayed in ktorrent
		QString name;
		// state of torrent
		QString state;
		// bytes
		float size;
		// bytes
		float trafficUp;
		// bytes
		float trafficDown;
		// KB/s
		float speedUp;
		// KB/s
		float speedDown;
		// percent complete
		float percent;
		// number of peers
		int peers;

		bool operator<(const TorrentInfo &ti) { return name < ti.name; }
	};

	QValueList<TorrentInfo>	m_ti;

private:

	bool makeTorrentInfo(TorrentInfo &ti, const KviQCStringList &ret);
};

TORR_DECLARE_DESCRIPTOR(KviKTorrentDCOPInterface)

#endif // COMPILE_KDE_SUPPORT

#endif // _TC_KTORRENTDCOPINTERFACE_H_