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
71 * - dialog = xbmcgui.Dialog()\n
72 * - ret = dialog.yesno('XBMC', 'Do you want to exit this script?')n\n
74 bool yesno(const String& heading, const String& line1,
75 const String& line2 = emptyString,
76 const String& line3 = emptyString,
77 const String& nolabel = emptyString,
78 const String& yeslabel = emptyString,
79 int autoclose = 0) throw (WindowException);
82 * select(heading, list) -- Show a select dialog.\n
84 * heading : string or unicode - dialog heading.\n
85 * list : string list - list of items.\n
86 * autoclose : [opt] integer - milliseconds to autoclose dialog. (default=do not autoclose)\n
88 * *Note, Returns the position of the highlighted item as an integer.\n
91 * - dialog = xbmcgui.Dialog()\n
92 * - ret = dialog.select('Choose a playlist', ['Playlist #1', 'Playlist #2, 'Playlist #3'])n\n
94 int select(const String& heading, const std::vector<String>& list, int autoclose=0) throw (WindowException);
97 * ok(heading, line1[, line2, line3]) -- Show a dialog 'OK'.\n
99 * heading : string or unicode - dialog heading.\n
100 * line1 : string or unicode - line #1 text.\n
101 * line2 : [opt] string or unicode - line #2 text.\n
102 * line3 : [opt] string or unicode - line #3 text.\n
104 * *Note, Returns True if 'Ok' was pressed, else False.\n
107 * - dialog = xbmcgui.Dialog()\n
108 * - ok = dialog.ok('XBMC', 'There was an error.')n\n
110 bool ok(const String& heading, const String& line1,
111 const String& line2 = emptyString,
112 const String& line3 = emptyString) throw (WindowException);
115 * browse(type, heading, shares[, mask, useThumbs, treatAsFolder, default, enableMultiple]) -- Show a 'Browse' dialog.\n
117 * type : integer - the type of browse dialog.\n
118 * heading : string or unicode - dialog heading.\n
119 * shares : string or unicode - from sources.xml. (i.e. 'myprograms')\n
120 * mask : [opt] string or unicode - '|' separated file mask. (i.e. '.jpg|.png')\n
121 * useThumbs : [opt] boolean - if True autoswitch to Thumb view if files exist.\n
122 * treatAsFolder : [opt] boolean - if True playlists and archives act as folders.\n
123 * default : [opt] string - default path or file.\n
125 * enableMultiple : [opt] boolean - if True multiple file selection is enabled.
128 * - 0 : ShowAndGetDirectory
129 * - 1 : ShowAndGetFile
130 * - 2 : ShowAndGetImage
131 * - 3 : ShowAndGetWriteableDirectory
133 * *Note, If enableMultiple is False (default): returns filename and/or path as a string\n
134 * to the location of the highlighted item, if user pressed 'Ok' or a masked item\n
135 * was selected. Returns the default value if dialog was canceled.\n
136 * If enableMultiple is True: returns tuple of marked filenames as a strin\n
137 * if user pressed 'Ok' or a masked item was selected. Returns empty tuple if dialog was canceled.\n
139 * If type is 0 or 3 the enableMultiple parameter is ignore\n
142 * - dialog = xbmcgui.Dialog()\n
143 * - fn = dialog.browse(3, 'XBMC', 'files', '', False, False, False, 'special://masterprofile/script_data/XBMC Lyrics')\n
145 Alternative<String, std::vector<String> > browse(int type, const String& heading, const String& s_shares,
146 const String& mask = emptyString, bool useThumbs = false,
147 bool treatAsFolder = false, const String& defaultt = emptyString,
148 bool enableMultiple = false) throw (WindowException);
151 * browse(type, heading, shares[, mask, useThumbs, treatAsFolder, default]) -- Show a 'Browse' dialog.\n
153 * type : integer - the type of browse dialog.\n
154 * heading : string or unicode - dialog heading.\n
155 * shares : string or unicode - from sources.xml. (i.e. 'myprograms')\n
156 * mask : [opt] string or unicode - '|' separated file mask. (i.e. '.jpg|.png')\n
157 * useThumbs : [opt] boolean - if True autoswitch to Thumb view if files exist (default=false).\n
158 * treatAsFolder : [opt] boolean - if True playlists and archives act as folders (default=false).\n
159 * default : [opt] string - default path or file.\n
162 * - 0 : ShowAndGetDirectory
163 * - 1 : ShowAndGetFile
164 * - 2 : ShowAndGetImage
165 * - 3 : ShowAndGetWriteableDirectory
167 * *Note, Returns filename and/or path as a string to the location of the highlighted item,\n
168 * if user pressed 'Ok' or a masked item was selected.\n
169 * Returns the default value if dialog was canceled.\n
172 * - dialog = xbmcgui.Dialog()
173 * - fn = dialog.browse(3, 'XBMC', 'files', '', False, False, 'special://masterprofile/script_data/XBMC Lyrics')
175 String browseSingle(int type, const String& heading, const String& shares,
176 const String& mask = emptyString, bool useThumbs = false,
177 bool treatAsFolder = false,
178 const String& defaultt = emptyString ) throw (WindowException);
181 * browse(type, heading, shares[, mask, useThumbs, treatAsFolder, default]) -- Show a 'Browse' dialog.\n
183 * type : integer - the type of browse dialog.\n
184 * heading : string or unicode - dialog heading.\n
185 * shares : string or unicode - from sources.xml. (i.e. 'myprograms')\n
186 * mask : [opt] string or unicode - '|' separated file mask. (i.e. '.jpg|.png')\n
187 * useThumbs : [opt] boolean - if True autoswitch to Thumb view if files exist (default=false).\n
188 * treatAsFolder : [opt] boolean - if True playlists and archives act as folders (default=false).\n
189 * default : [opt] string - default path or file.\n
192 * - 1 : ShowAndGetFile
193 * - 2 : ShowAndGetImage
196 * returns tuple of marked filenames as a string,"\n
197 * if user pressed 'Ok' or a masked item was selected. Returns empty tuple if dialog was canceled.\n
200 * - dialog = xbmcgui.Dialog()
201 * - fn = dialog.browseMultiple(2, 'XBMC', 'files', '', False, False, 'special://masterprofile/script_data/XBMC Lyrics')
203 std::vector<String> browseMultiple(int type, const String& heading, const String& shares,
204 const String& mask = emptyString, bool useThumbs = false,
205 bool treatAsFolder = false,
206 const String& defaultt = emptyString ) throw (WindowException);
210 * numeric(type, heading[, default]) -- Show a 'Numeric' dialog.\n
212 * type : integer - the type of numeric dialog.\n
213 * heading : string or unicode - dialog heading.\n
214 * default : [opt] string - default value.\n
217 * - 0 : ShowAndGetNumber (default format: #)
218 * - 1 : ShowAndGetDate (default format: DD/MM/YYYY)
219 * - 2 : ShowAndGetTime (default format: HH:MM)
220 * - 3 : ShowAndGetIPAddress (default format: #.#.#.#)
222 * *Note, Returns the entered data as a string.\n
223 * Returns the default value if dialog was canceled.\n
226 * - dialog = xbmcgui.Dialog()
227 * - d = dialog.numeric(1, 'Enter date of birth')
229 String numeric(int type, const String& heading, const String& defaultt = emptyString);
232 * notification(heading, message[, icon, time, sound]) -- Show a Notification alert.\n
234 * heading : string - dialog heading.\n
235 * message : string - dialog message.\n
236 * icon : [opt] string - icon to use. (default xbmcgui.NOTIFICATION_INFO)\n
237 * time : [opt] integer - time in milliseconds (default 5000)\n
238 * sound : [opt] bool - play notification sound (default True)\n
241 * - xbmcgui.NOTIFICATION_INFO
242 * - xbmcgui.NOTIFICATION_WARNING
243 * - xbmcgui.NOTIFICATION_ERROR
246 * - dialog = xbmcgui.Dialog()
247 * - dialog.notification('Movie Trailers', 'Finding Nemo download finished.', xbmcgui.NOTIFICATION_INFO, 5000)
249 void notification(const String& heading, const String& message, const String& icon = emptyString, int time = 0, bool sound = true);
252 * input(heading[, default, type, option, autoclose]) -- Show an Input dialog.\n
254 * heading : string - dialog heading.\n
255 * default : [opt] string - default value. (default=empty string)\n
256 * type : [opt] integer - the type of keyboard dialog. (default=xbmcgui.INPUT_ALPHANUM)\n
257 * option : [opt] integer - option for the dialog. (see Options below)\n
258 * autoclose : [opt] integer - milliseconds to autoclose dialog. (default=do not autoclose)\n
261 * - xbmcgui.INPUT_ALPHANUM (standard keyboard)
262 * - xbmcgui.INPUT_NUMERIC (format: #)
263 * - xbmcgui.INPUT_DATE (format: DD/MM/YYYY)
264 * - xbmcgui.INPUT_TIME (format: HH:MM)
265 * - xbmcgui.INPUT_IPADDRESS (format: #.#.#.#)
266 * - xbmcgui.INPUT_PASSWORD (return md5 hash of input, input is masked)
268 * Options Password Dialog:\n
269 * - xbmcgui.PASSWORD_VERIFY (verifies an existing (default) md5 hashed password)
271 * Options Alphanum Dialog:\n
272 * - xbmcgui.ALPHANUM_HIDE_INPUT (masks input)
274 * *Note, Returns the entered data as a string.\n
275 * Returns an empty string if dialog was canceled.\n
278 * - dialog = xbmcgui.Dialog()
279 * - d = dialog.input('Enter secret code', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)n
281 String input(const String& heading,
282 const String& defaultt = emptyString,
283 int type = INPUT_ALPHANUM,
285 int autoclose = 0) throw (WindowException);
289 * DialogProgress class (Duh!)
291 class DialogProgress : public AddonClass
293 CGUIDialogProgress* dlg;
297 virtual void deallocating();
301 DialogProgress() : dlg(NULL), open(false) {}
302 virtual ~DialogProgress();
306 * create(heading[, line1, line2, line3]) -- Create and show a progress dialog.\n
308 * heading : string or unicode - dialog heading.\n
309 * line1 : [opt] string or unicode - line #1 text.\n
310 * line2 : [opt] string or unicode - line #2 text.\n
311 * line3 : [opt] string or unicode - line #3 text.\n
313 * *Note, Use update() to update lines and progressbar.\n
316 * - pDialog = xbmcgui.DialogProgress()
317 * - pDialog.create('XBMC', 'Initializing script...')
319 void create(const String& heading, const String& line1 = emptyString,
320 const String& line2 = emptyString,
321 const String& line3 = emptyString) throw (WindowException);
324 * update(percent[, line1, line2, line3]) -- Update's the progress dialog.\n
326 * percent : integer - percent complete. (0:100)\n
327 * line1 : [opt] string or unicode - line #1 text.\n
328 * line2 : [opt] string or unicode - line #2 text.\n
329 * line3 : [opt] string or unicode - line #3 text.\n
331 * *Note, If percent == 0, the progressbar will be hidden.\n
334 * - pDialog.update(25, 'Importing modules...')
336 void update(int percent, const String& line1 = emptyString,
337 const String& line2 = emptyString,
338 const String& line3 = emptyString) throw (WindowException);
341 * close() -- Close the progress dialog.\n
349 * iscanceled() -- Returns True if the user pressed cancel.\n
352 * - if (pDialog.iscanceled()): return
358 * DialogProgressBG class
360 class DialogProgressBG : public AddonClass
362 CGUIDialogExtendedProgressBar* dlg;
363 CGUIDialogProgressBarHandle* handle;
367 virtual void deallocating();
371 DialogProgressBG() : dlg(NULL), handle(NULL), open(false) {}
372 virtual ~DialogProgressBG();
376 * create(heading[, message]) -- Create and show a background progress dialog.n\n
378 * heading : string or unicode - dialog headingn\n
379 * message : [opt] string or unicode - message textn\n
381 * *Note, 'heading' is used for the dialog's id. Use a unique heading.n\n
382 * Use update() to update heading, message and progressbar.n\n
385 * - pDialog = xbmcgui.DialogProgressBG()
386 * - pDialog.create('Movie Trailers', 'Downloading Monsters Inc. ...')
388 void create(const String& heading, const String& message = emptyString) throw (WindowException);
391 * update([percent, heading, message]) -- Updates the background progress dialog.
393 * percent : [opt] integer - percent complete. (0:100)\n
394 * heading : [opt] string or unicode - dialog heading\n
395 * message : [opt] string or unicode - message text\n
397 * *Note, To clear heading or message, you must pass a blank character.\n
400 * - pDialog.update(25, message='Downloading Finding Nemo ...')
402 void update(int percent = 0, const String& heading = emptyString, const String& message = emptyString) throw (WindowException);
405 * close() -- Close the background progress dialog
413 * isFinished() -- Returns True if the background dialog is active.
416 * - if (pDialog.isFinished()): return