2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
25 #include "WindowException.h"
26 #include "AddonClass.h"
27 #include "AddonString.h"
28 #include "ApplicationMessenger.h"
29 #include "dialogs/GUIDialogProgress.h"
30 #include "dialogs/GUIDialogExtendedProgressBar.h"
31 #include "Alternative.h"
33 #define INPUT_ALPHANUM 0
34 #define INPUT_NUMERIC 1
37 #define INPUT_IPADDRESS 4
38 #define INPUT_PASSWORD 5
40 #define PASSWORD_VERIFY 1
41 #define ALPHANUM_HIDE_INPUT 2
48 * Dialog class (Duh!)\n
50 class Dialog : public AddonClass
58 * yesno(heading, line1[, line2, line3]) -- Show a dialog 'YES/NO'.\n
60 * heading : string or unicode - dialog heading.\n
61 * line1 : string or unicode - line #1 text.\n
62 * line2 : [opt] string or unicode - line #2 text.\n
63 * line3 : [opt] string or unicode - line #3 text.\n
64 * nolabel : [opt] label to put on the no button.\n
65 * yeslabel : [opt] label to put on the yes button.\n
66 * autoclose : [opt] integer - milliseconds to autoclose dialog. (default=do not autoclose)\n
68 * *Note, Returns True if 'Yes' was pressed, else False.\n
69 * *Note, Optionally line1 can be sent as multi-line text. In this case line2 and line3 must be omitted.\n
72 * - dialog = xbmcgui.Dialog()\n
73 * - ret = dialog.yesno('XBMC', 'Do you want to exit this script?')n\n
75 bool yesno(const String& heading, const String& line1,
76 const String& line2 = emptyString,
77 const String& line3 = emptyString,
78 const String& nolabel = emptyString,
79 const String& yeslabel = emptyString,
80 int autoclose = 0) throw (WindowException);
83 * select(heading, list) -- Show a select dialog.\n
85 * heading : string or unicode - dialog heading.\n
86 * list : string list - list of items.\n
87 * autoclose : [opt] integer - milliseconds to autoclose dialog. (default=do not autoclose)\n
89 * *Note, Returns the position of the highlighted item as an integer.\n
92 * - dialog = xbmcgui.Dialog()\n
93 * - ret = dialog.select('Choose a playlist', ['Playlist #1', 'Playlist #2, 'Playlist #3'])n\n
95 int select(const String& heading, const std::vector<String>& list, int autoclose=0) throw (WindowException);
98 * ok(heading, line1[, line2, line3]) -- Show a dialog 'OK'.\n
100 * heading : string or unicode - dialog heading.\n
101 * line1 : string or unicode - line #1 text.\n
102 * line2 : [opt] string or unicode - line #2 text.\n
103 * line3 : [opt] string or unicode - line #3 text.\n
105 * *Note, Returns True if 'Ok' was pressed, else False.\n
106 * *Note: Optionally line1 can be sent as multi-line text. In this case line2 and line3 must be omitted.\n
109 * - dialog = xbmcgui.Dialog()\n
110 * - ok = dialog.ok('XBMC', 'There was an error.')n\n
112 bool ok(const String& heading, const String& line1,
113 const String& line2 = emptyString,
114 const String& line3 = emptyString) throw (WindowException);
117 * browse(type, heading, shares[, mask, useThumbs, treatAsFolder, default, enableMultiple]) -- Show a 'Browse' dialog.\n
119 * type : integer - the type of browse dialog.\n
120 * heading : string or unicode - dialog heading.\n
121 * shares : string or unicode - from sources.xml. (i.e. 'myprograms')\n
122 * mask : [opt] string or unicode - '|' separated file mask. (i.e. '.jpg|.png')\n
123 * useThumbs : [opt] boolean - if True autoswitch to Thumb view if files exist.\n
124 * treatAsFolder : [opt] boolean - if True playlists and archives act as folders.\n
125 * default : [opt] string - default path or file.\n
127 * enableMultiple : [opt] boolean - if True multiple file selection is enabled.
130 * - 0 : ShowAndGetDirectory
131 * - 1 : ShowAndGetFile
132 * - 2 : ShowAndGetImage
133 * - 3 : ShowAndGetWriteableDirectory
135 * *Note, If enableMultiple is False (default): returns filename and/or path as a string\n
136 * to the location of the highlighted item, if user pressed 'Ok' or a masked item\n
137 * was selected. Returns the default value if dialog was canceled.\n
138 * If enableMultiple is True: returns tuple of marked filenames as a strin\n
139 * if user pressed 'Ok' or a masked item was selected. Returns empty tuple if dialog was canceled.\n
141 * If type is 0 or 3 the enableMultiple parameter is ignore\n
144 * - dialog = xbmcgui.Dialog()\n
145 * - fn = dialog.browse(3, 'XBMC', 'files', '', False, False, False, 'special://masterprofile/script_data/XBMC Lyrics')\n
147 Alternative<String, std::vector<String> > browse(int type, const String& heading, const String& s_shares,
148 const String& mask = emptyString, bool useThumbs = false,
149 bool treatAsFolder = false, const String& defaultt = emptyString,
150 bool enableMultiple = false) throw (WindowException);
153 * browse(type, heading, shares[, mask, useThumbs, treatAsFolder, default]) -- Show a 'Browse' dialog.\n
155 * type : integer - the type of browse dialog.\n
156 * heading : string or unicode - dialog heading.\n
157 * shares : string or unicode - from sources.xml. (i.e. 'myprograms')\n
158 * mask : [opt] string or unicode - '|' separated file mask. (i.e. '.jpg|.png')\n
159 * useThumbs : [opt] boolean - if True autoswitch to Thumb view if files exist (default=false).\n
160 * treatAsFolder : [opt] boolean - if True playlists and archives act as folders (default=false).\n
161 * default : [opt] string - default path or file.\n
164 * - 0 : ShowAndGetDirectory
165 * - 1 : ShowAndGetFile
166 * - 2 : ShowAndGetImage
167 * - 3 : ShowAndGetWriteableDirectory
169 * *Note, Returns filename and/or path as a string to the location of the highlighted item,\n
170 * if user pressed 'Ok' or a masked item was selected.\n
171 * Returns the default value if dialog was canceled.\n
174 * - dialog = xbmcgui.Dialog()
175 * - fn = dialog.browse(3, 'XBMC', 'files', '', False, False, 'special://masterprofile/script_data/XBMC Lyrics')
177 String browseSingle(int type, const String& heading, const String& shares,
178 const String& mask = emptyString, bool useThumbs = false,
179 bool treatAsFolder = false,
180 const String& defaultt = emptyString ) throw (WindowException);
183 * browse(type, heading, shares[, mask, useThumbs, treatAsFolder, default]) -- Show a 'Browse' dialog.\n
185 * type : integer - the type of browse dialog.\n
186 * heading : string or unicode - dialog heading.\n
187 * shares : string or unicode - from sources.xml. (i.e. 'myprograms')\n
188 * mask : [opt] string or unicode - '|' separated file mask. (i.e. '.jpg|.png')\n
189 * useThumbs : [opt] boolean - if True autoswitch to Thumb view if files exist (default=false).\n
190 * treatAsFolder : [opt] boolean - if True playlists and archives act as folders (default=false).\n
191 * default : [opt] string - default path or file.\n
194 * - 1 : ShowAndGetFile
195 * - 2 : ShowAndGetImage
198 * returns tuple of marked filenames as a string,"\n
199 * if user pressed 'Ok' or a masked item was selected. Returns empty tuple if dialog was canceled.\n
202 * - dialog = xbmcgui.Dialog()
203 * - fn = dialog.browseMultiple(2, 'XBMC', 'files', '', False, False, 'special://masterprofile/script_data/XBMC Lyrics')
205 std::vector<String> browseMultiple(int type, const String& heading, const String& shares,
206 const String& mask = emptyString, bool useThumbs = false,
207 bool treatAsFolder = false,
208 const String& defaultt = emptyString ) throw (WindowException);
212 * numeric(type, heading[, default]) -- Show a 'Numeric' dialog.\n
214 * type : integer - the type of numeric dialog.\n
215 * heading : string or unicode - dialog heading.\n
216 * default : [opt] string - default value.\n
219 * - 0 : ShowAndGetNumber (default format: #)
220 * - 1 : ShowAndGetDate (default format: DD/MM/YYYY)
221 * - 2 : ShowAndGetTime (default format: HH:MM)
222 * - 3 : ShowAndGetIPAddress (default format: #.#.#.#)
224 * *Note, Returns the entered data as a string.\n
225 * Returns the default value if dialog was canceled.\n
228 * - dialog = xbmcgui.Dialog()
229 * - d = dialog.numeric(1, 'Enter date of birth')
231 String numeric(int type, const String& heading, const String& defaultt = emptyString);
234 * notification(heading, message[, icon, time, sound]) -- Show a Notification alert.\n
236 * heading : string - dialog heading.\n
237 * message : string - dialog message.\n
238 * icon : [opt] string - icon to use. (default xbmcgui.NOTIFICATION_INFO)\n
239 * time : [opt] integer - time in milliseconds (default 5000)\n
240 * sound : [opt] bool - play notification sound (default True)\n
243 * - xbmcgui.NOTIFICATION_INFO
244 * - xbmcgui.NOTIFICATION_WARNING
245 * - xbmcgui.NOTIFICATION_ERROR
248 * - dialog = xbmcgui.Dialog()
249 * - dialog.notification('Movie Trailers', 'Finding Nemo download finished.', xbmcgui.NOTIFICATION_INFO, 5000)
251 void notification(const String& heading, const String& message, const String& icon = emptyString, int time = 0, bool sound = true);
254 * input(heading[, default, type, option, autoclose]) -- Show an Input dialog.\n
256 * heading : string - dialog heading.\n
257 * default : [opt] string - default value. (default=empty string)\n
258 * type : [opt] integer - the type of keyboard dialog. (default=xbmcgui.INPUT_ALPHANUM)\n
259 * option : [opt] integer - option for the dialog. (see Options below)\n
260 * autoclose : [opt] integer - milliseconds to autoclose dialog. (default=do not autoclose)\n
263 * - xbmcgui.INPUT_ALPHANUM (standard keyboard)
264 * - xbmcgui.INPUT_NUMERIC (format: #)
265 * - xbmcgui.INPUT_DATE (format: DD/MM/YYYY)
266 * - xbmcgui.INPUT_TIME (format: HH:MM)
267 * - xbmcgui.INPUT_IPADDRESS (format: #.#.#.#)
268 * - xbmcgui.INPUT_PASSWORD (return md5 hash of input, input is masked)
270 * Options Password Dialog:\n
271 * - xbmcgui.PASSWORD_VERIFY (verifies an existing (default) md5 hashed password)
273 * Options Alphanum Dialog:\n
274 * - xbmcgui.ALPHANUM_HIDE_INPUT (masks input)
276 * *Note, Returns the entered data as a string.\n
277 * Returns an empty string if dialog was canceled.\n
280 * - dialog = xbmcgui.Dialog()
281 * - d = dialog.input('Enter secret code', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)n
283 String input(const String& heading,
284 const String& defaultt = emptyString,
285 int type = INPUT_ALPHANUM,
287 int autoclose = 0) throw (WindowException);
291 * DialogProgress class (Duh!)
293 class DialogProgress : public AddonClass
295 CGUIDialogProgress* dlg;
299 virtual void deallocating();
303 DialogProgress() : dlg(NULL), open(false) {}
304 virtual ~DialogProgress();
308 * create(heading[, line1, line2, line3]) -- Create and show a progress dialog.\n
310 * heading : string or unicode - dialog heading.\n
311 * line1 : [opt] string or unicode - line #1 text.\n
312 * line2 : [opt] string or unicode - line #2 text.\n
313 * line3 : [opt] string or unicode - line #3 text.\n
315 * *Note, Optionally line1 can be sent as multi-line text. In this case line2 and line3 must be omitted.\n
316 * *Note, Use update() to update lines and progressbar.\n
319 * - pDialog = xbmcgui.DialogProgress()
320 * - pDialog.create('XBMC', 'Initializing script...')
322 void create(const String& heading, const String& line1 = emptyString,
323 const String& line2 = emptyString,
324 const String& line3 = emptyString) throw (WindowException);
327 * update(percent[, line1, line2, line3]) -- Updates the progress dialog.\n
329 * percent : integer - percent complete. (0:100)\n
330 * line1 : [opt] string or unicode - line #1 text.\n
331 * line2 : [opt] string or unicode - line #2 text.\n
332 * line3 : [opt] string or unicode - line #3 text.\n
334 * *Note, Optionally line1 can be sent as multi-line text. In this case line2 and line3 must be omitted.\n
335 * *Note, If percent == 0, the progressbar will be hidden.\n
338 * - pDialog.update(25, 'Importing modules...')
340 void update(int percent, const String& line1 = emptyString,
341 const String& line2 = emptyString,
342 const String& line3 = emptyString) throw (WindowException);
345 * close() -- Close the progress dialog.\n
353 * iscanceled() -- Returns True if the user pressed cancel.\n
356 * - if (pDialog.iscanceled()): return
362 * DialogProgressBG class
364 class DialogProgressBG : public AddonClass
366 CGUIDialogExtendedProgressBar* dlg;
367 CGUIDialogProgressBarHandle* handle;
371 virtual void deallocating();
375 DialogProgressBG() : dlg(NULL), handle(NULL), open(false) {}
376 virtual ~DialogProgressBG();
380 * create(heading[, message]) -- Create and show a background progress dialog.\n
382 * heading : string or unicode - dialog heading.\n
383 * message : [opt] string or unicode - message text.\n
385 * *Note, 'heading' is used for the dialog's id. Use a unique heading.\n
386 * Use update() to update heading, message and progressbar.\n
389 * - pDialog = xbmcgui.DialogProgressBG()
390 * - pDialog.create('Movie Trailers', 'Downloading Monsters Inc. ...')
392 void create(const String& heading, const String& message = emptyString) throw (WindowException);
395 * update([percent, heading, message]) -- Updates the background progress dialog.
397 * percent : [opt] integer - percent complete. (0:100)\n
398 * heading : [opt] string or unicode - dialog heading.\n
399 * message : [opt] string or unicode - message text.\n
401 * *Note, To clear heading or message, you must pass a blank character.\n
404 * - pDialog.update(25, message='Downloading Finding Nemo ...')
406 void update(int percent = 0, const String& heading = emptyString, const String& message = emptyString) throw (WindowException);
409 * close() -- Close the background progress dialog
417 * isFinished() -- Returns True if the background dialog is active.
420 * - if (pDialog.isFinished()): return