summaryrefslogtreecommitdiffstats
path: root/apps/ktorrent/ktorrent.h
blob: fff305f2e16f818231fe4904891b9e058820b59f (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/***************************************************************************
 *   Copyright (C) 2005 by Joris Guisson                                   *
 *   joris.guisson@gmail.com                                               *
 *                                                                         *
 *   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 option) 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.             *
 ***************************************************************************/


#ifndef _KTORRENT_H_
#define _KTORRENT_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kapplication.h>
#include <newui/dmainwindow.h>
#include <tqtimer.h>
#include <interfaces/guiinterface.h>

typedef TQValueList<TQCString> QCStringList;

class KAction;
class KToggleAction;
class KURL;
class KTorrentCore;
class KTorrentView;
class TrayIcon;
class SetMaxRate;
class KTorrentDCOP;
class TQLabel;
class TQListViewItem;
class KTorrentPreferences;
class ViewManager;


namespace kt
{
	class TorrentInterface;
	class Group;
	class GroupView;
}


/**
 * This class serves as the main window for KTorrent.  It handles the
 * menus, toolbars, and status bars.
 *
 * @short Main window class
 * @author Joris Guisson <joris.guisson@gmail.com>
 * @version 0.1
 */
class KTorrent : public DMainWindow, public kt::GUIInterface
{
	Q_OBJECT
  
public:
	/**
	 * Default Constructor
	 */
	KTorrent();

	/**
	 * Default Destructor
	 */
	virtual ~KTorrent();

	/// Open a view with the given group
	void openView(const TQString & group_name);

	/// Get the core
	KTorrentCore & getCore() {return *m_core;}
	
	/**
	 * Apply the settings.
	 * @param change_port Wether or not to change the server port
	 */
	void applySettings(bool change_port = true);

	virtual void addTabPage(TQWidget* page,const TQIconSet & icon,
							const TQString & caption,kt::CloseTabListener* ctl = 0);
	virtual void addTabPage(TQWidget* page,const TQPixmap & icon,
							const TQString & caption,kt::CloseTabListener* ctl = 0);
	virtual void removeTabPage(TQWidget* page);
	virtual void addPrefPage(kt::PrefPageInterface* page);
	virtual void removePrefPage(kt::PrefPageInterface* page);
	virtual void mergePluginGui(kt::Plugin* p);
	virtual void removePluginGui(kt::Plugin* p);
	virtual void addWidgetBelowView(TQWidget* w,const TQString & icon,const TQString & caption);
	virtual void removeWidgetBelowView(TQWidget* w);
	virtual void addToolWidget(TQWidget* w,const TQString & icon,const TQString & caption,ToolDock dock);
	virtual void removeToolWidget(TQWidget* w);
	virtual const kt::TorrentInterface* getCurrentTorrent() const;
	virtual KToolBar* addToolBar(const char* name);
	virtual void removeToolBar(KToolBar* tb);
	virtual KProgress* addProgressBarToStatusBar();
	virtual void removeProgressBarFromStatusBar(KProgress* p);
	
	TQString	getStatusInfo();
	TQString	getStatusTransfer();
	TQString	getStatusSpeed();
	TQString	getStatusDHT();
	TQString getStatusFirewall();
	QCStringList getTorrentInfo(kt::TorrentInterface* tc);

public slots:
	/**
	 * Use this method to load whatever file/URL you have
	 */
	void load(const KURL& url);
	
	/**
	 * Does the same as load, but doesn't ask any questions
	*/
	void loadSilently(const KURL& url);
	
	/**
	 * Does the same as loadSilently, except accepts a directory to
	 * save to
	 */
	void loadSilentlyDir(const KURL& url, const KURL& savedir);
	
	/// Open a view with the given group
	void openView(kt::Group* g);

protected:
	/**
	 * This function is called when it is time for the app to save its
	 * properties for session management purposes.
	 */
	void saveProperties(TDEConfig *);

	/**
	 * This function is called when this app is restored.  The TDEConfig
	 * object points to the session management config file that was saved
	 * with @ref saveProperties
	 */
	void readProperties(TDEConfig *);


private slots:
	void fileOpen();
	void fileNew();
	void torrentPaste();
	void startDownload();
	void startAllDownloadsCurrentView();
	void startAllDownloads();
	void stopDownload();
	void stopAllDownloadsCurrentView();
	void stopAllDownloads();
	void showIPFilter();
	void removeDownload();
	void queueManagerShow();
	void optionsShowStatusbar();
	void optionsShowMenubar();
	void optionsConfigureKeys();
	void optionsConfigureToolbars();
	void optionsPreferences();
	void newToolbarConfig();
	void changeStatusbar(const TQString& text);
	void changeCaption(const TQString& text);
	void currentTorrentChanged(kt::TorrentInterface* tc);
	void updatedStats();
	void urlDropped(TQDropEvent*,TQListViewItem*);
	void onUpdateActions(int flags);
	void groupChanged(kt::Group* g);
	void groupRenamed(kt::Group* g);
	void groupRemoved(kt::Group* g);
	void currentTabChanged(TQWidget* w);
	void openDefaultView();
	void statusBarMsgExpired();
	void find();
	
private:
	void setupAccel();
	void setupActions();
	bool queryClose();
	bool queryExit();
	
	
	virtual void addWidgetInView(TQWidget* w,kt::Position pos);
	virtual void removeWidgetFromView(TQWidget* w);	
	virtual void closeTab();
	
private:
	kt::GroupView* m_group_view;
	ViewManager* m_view_man;
	KToggleAction *m_statusbarAction;
	KToggleAction* m_menubarAction;
	
	KTorrentCore* m_core;
	TrayIcon* m_systray_icon;
	SetMaxRate* m_set_max_upload_rate;
	SetMaxRate* m_set_max_download_rate;
	
	KTorrentDCOP* m_dcop;
	TQTimer m_gui_update_timer;
	TQTimer m_status_msg_expire;
	KTorrentPreferences* m_pref;

	TQMap<TQWidget*,kt::CloseTabListener*> m_tab_map;

	TQLabel* m_statusInfo;
	TQLabel* m_statusTransfer;
	TQLabel* m_statusSpeed;
	TQLabel* m_statusDHT;
	TQLabel* m_statusFirewall;
	
	KAction* m_start;
	KAction* m_stop;
	KAction* m_remove;
	KAction* m_startall;
	KAction* m_startall_systray;
	KAction* m_stopall;
	KAction* m_stopall_systray;
	KAction* m_pasteurl;
	KAction* m_queuemgr; 
	KAction* m_queueaction;
	KAction* m_datacheck;
	KAction* m_ipfilter;
	KAction* m_find;
	
	KProgress* m_status_prog;
};

#endif // _KTORRENT_H_