summaryrefslogtreecommitdiffstats
path: root/libktorrent/interfaces/guiinterface.h
blob: a263bb620ce28737b23a19c52e55228d7d8378dc (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
/***************************************************************************
 *   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 KTGUIINTERFACE_H
#define KTGUIINTERFACE_H

#include <qptrlist.h>

class QWidget;
class QIconSet;
class QString;
class KToolBar;
class KProgress;

namespace kt
{
	class PrefPageInterface;
	class Plugin;
	class TorrentInterface;
	class GUIInterface;

	enum Position
	{
		LEFT, ///< New widgets will be added to the left of the old
		RIGHT, ///< New widgets will be added to the right of the old
		ABOVE, ///< New widgets will be added above the old
		BELOW  ///< New widgets will be added below the old
	};
	
	/**
	 * Small interface for classes who want to know when
	 * current torrent in the gui changes.
	 */
	class ViewListener
	{
	public:
		ViewListener() {}
		virtual ~ViewListener() {}
		
		virtual void currentTorrentChanged(TorrentInterface* tc) = 0;
	};
	
	/**
	 * Plugins wanting to add closeable tabs, should implement this interface.
	 * That way they can be notified of close requests.
	 * Not providing this interface in addTabPage means the tab cannot be closed.
	*/
	class CloseTabListener
	{
	public:
		/// By default all tabs can be closed, but this can be overridden
		virtual bool closeAllowed(QWidget* ) {return true;}
		
		/// THe close button was pressed for this tab, please remove it from the GUI
		virtual void tabCloseRequest(kt::GUIInterface* gui,QWidget* tab) = 0;
	};
	
	/**
	 * @author Joris Guisson
	 * @brief Interface to modify the GUI
	 *
	 * This interface allows plugins and others to modify the GUI.
	*/
	class GUIInterface
	{
		QPtrList<ViewListener> listeners;
	public:
		GUIInterface();
		virtual ~GUIInterface();


		/// Add a view listener.
		void addViewListener(ViewListener* vl);

		/// Remove a view listener
		void removeViewListener(ViewListener* vl);
		
		/// Add a progress bar tot the status bar, if one is already present this will fail and return 0
		virtual KProgress* addProgressBarToStatusBar() = 0;
		
		/// Remove the progress bar from the status bar
		virtual void removeProgressBarFromStatusBar(KProgress* p) = 0;
		
		/**
		 * Add a new tab page to the GUI
		 * @param page The widget
		 * @param icon Icon for the tab
		 * @param caption Text on the tab
		 * @param ctl For closeable tabs this pointer should be set
		 */
		virtual void addTabPage(QWidget* page,const QIconSet & icon,
								const QString & caption,CloseTabListener* ctl = 0) = 0;

		/**
		 * Remove a tab page, does nothing if the page
		 * isn't added. Does not delete the widget.
		 * @param page The page
		 */
		virtual void removeTabPage(QWidget* page) = 0;

		/**
		 * Add a page to the preference dialog.
		 * @param page The page
		 */
		virtual void addPrefPage(PrefPageInterface* page) = 0;

		
		/**
		 * Remove a page from the preference dialog.
		 * @param page The page
		 */
		virtual void removePrefPage(PrefPageInterface* page) = 0;

		/**
		 * Change the statusbar message.
		 * @param msg The new message
		 */
		virtual void changeStatusbar(const QString& msg) = 0;

		/**
		 * Merge the GUI of a plugin.
		 * @param p The Plugin
		 */
		virtual void mergePluginGui(Plugin* p) = 0;

		/**
		 * Remove the GUI of a plugin.
		 * @param p The Plugin
		 */
		virtual void removePluginGui(Plugin* p) = 0;
		
		/**
		 * Embed a widget in the view in the mainview.
		 * The view and the new widget will be separated by a separator.
		 * @param w The widget
		 * @param pos How the widget will be positioned against the already present widgets
		 */
		virtual void addWidgetInView(QWidget* w,Position pos) = 0;

		/**
		 * Remove a widget added with addWidgetInView.
		 * The widget will be reparented to 0.
		 * @param w The widget 
		 */
		virtual void removeWidgetFromView(QWidget* w) = 0;
		
		/**
		 * Add a widget below the view.
		 * @param w The widget
		 * @param icon Name of icon to use
		 * @param caption The caption to use
		 */
		virtual void addWidgetBelowView(QWidget* w,const QString & icon,const QString & caption) = 0;
		
		/**
		 * Remove a widget, which was added below the view.
		 * @param w The widget
		 */
		virtual void removeWidgetBelowView(QWidget* w) = 0;
		
		enum ToolDock
		{
			DOCK_LEFT,
			DOCK_RIGHT,
			DOCK_BOTTOM
		};
		
		/**
		 * Add a tool widget.
		 * @param w The widget
		 * @param icon Name of icon to use
		 * @param caption The caption to use
		 * @param dock Where to dock the widget
		 */
		virtual void addToolWidget(QWidget* w,const QString & icon,const QString & caption,ToolDock dock) = 0;
		
		/**
		 * Remove a tool widget.
		 * @param w The widget
		 */
		virtual void removeToolWidget(QWidget* w) = 0;

		/// Get the current torrent.
		virtual const TorrentInterface* getCurrentTorrent() const = 0;
		
		/// Add a toolbar
		virtual KToolBar* addToolBar(const char* name) = 0;
		
		/// Remove a toolbar
		virtual void removeToolBar(KToolBar* tb) = 0;
		
	protected:
		/**
		 * Notifies all view listeners of the change in the current downloading TorrentInterface
		 * @param tc Pointer to current TorrentInterface
		 */
		void notifyViewListeners(TorrentInterface* tc);
	};

}

#endif