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/>.
20 #include "LanguageHook.h"
22 #include "dialogs/GUIDialogOK.h"
23 #include "dialogs/GUIDialogYesNo.h"
24 #include "dialogs/GUIDialogSelect.h"
25 #include "guilib/GUIWindowManager.h"
26 #include "dialogs/GUIDialogFileBrowser.h"
27 #include "dialogs/GUIDialogNumeric.h"
28 #include "settings/MediaSourceSettings.h"
29 #include "dialogs/GUIDialogKaiToast.h"
30 #include "ModuleXbmcgui.h"
31 #include "guilib/GUIKeyboardFactory.h"
32 #include "utils/StringUtils.h"
34 #define ACTIVE_WINDOW g_windowManager.GetActiveWindow()
40 static void XBMCWaitForThreadMessage(int message, int param1, int param2)
42 ThreadMessage tMsg = {(DWORD)message, (DWORD)param1, (DWORD)param2};
43 CApplicationMessenger::Get().SendMessage(tMsg, true);
48 bool Dialog::yesno(const String& heading, const String& line1,
51 const String& nolabel,
52 const String& yeslabel,
53 int autoclose) throw (WindowException)
55 DelayedCallGuard dcguard(languageHook);
56 const int window = WINDOW_DIALOG_YES_NO;
57 CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(window);
59 throw WindowException("Error: Window is NULL, this is not possible :-)");
61 // get lines, last 4 lines are optional.
63 pDialog->SetHeading(heading);
65 pDialog->SetLine(0, line1);
67 pDialog->SetLine(1, line2);
69 pDialog->SetLine(2, line3);
72 pDialog->SetChoice(0,nolabel);
73 if (!yeslabel.empty())
74 pDialog->SetChoice(1,yeslabel);
77 pDialog->SetAutoClose(autoclose);
79 //send message and wait for user input
80 XBMCWaitForThreadMessage(TMSG_DIALOG_DOMODAL, window, ACTIVE_WINDOW);
82 return pDialog->IsConfirmed();
85 int Dialog::select(const String& heading, const std::vector<String>& list, int autoclose) throw (WindowException)
87 DelayedCallGuard dcguard(languageHook);
88 const int window = WINDOW_DIALOG_SELECT;
89 CGUIDialogSelect* pDialog= (CGUIDialogSelect*)g_windowManager.GetWindow(window);
91 throw WindowException("Error: Window is NULL, this is not possible :-)");
95 pDialog->SetHeading(heading);
98 for(unsigned int i = 0; i < list.size(); i++)
101 pDialog->Add(listLine);
104 pDialog->SetAutoClose(autoclose);
106 //send message and wait for user input
107 XBMCWaitForThreadMessage(TMSG_DIALOG_DOMODAL, window, ACTIVE_WINDOW);
109 return pDialog->GetSelectedLabel();
112 bool Dialog::ok(const String& heading, const String& line1,
114 const String& line3) throw (WindowException)
116 DelayedCallGuard dcguard(languageHook);
117 const int window = WINDOW_DIALOG_OK;
119 CGUIDialogOK* pDialog = (CGUIDialogOK*)g_windowManager.GetWindow(window);
121 throw WindowException("Error: Window is NULL, this is not possible :-)");
123 if (!heading.empty())
124 pDialog->SetHeading(heading);
126 pDialog->SetLine(0, line1);
128 pDialog->SetLine(1, line2);
130 pDialog->SetLine(2, line3);
132 //send message and wait for user input
133 XBMCWaitForThreadMessage(TMSG_DIALOG_DOMODAL, window, ACTIVE_WINDOW);
135 return pDialog->IsConfirmed();
138 Alternative<String, std::vector<String> > Dialog::browse(int type, const String& heading,
139 const String& s_shares, const String& maskparam, bool useThumbs,
140 bool useFileDirectories, const String& defaultt,
141 bool enableMultiple) throw (WindowException)
143 Alternative<String, std::vector<String> > ret;
145 ret.later() = browseMultiple(type,heading,s_shares,maskparam,useThumbs,useFileDirectories,defaultt);
147 ret.former() = browseSingle(type,heading,s_shares,maskparam,useThumbs,useFileDirectories,defaultt);
151 String Dialog::browseSingle(int type, const String& heading, const String& s_shares,
152 const String& maskparam, bool useThumbs,
153 bool useFileDirectories,
154 const String& defaultt ) throw (WindowException)
156 DelayedCallGuard dcguard(languageHook);
158 std::string mask = maskparam;
159 VECSOURCES *shares = CMediaSourceSettings::Get().GetSources(s_shares);
161 throw WindowException("Error: GetSources given %s is NULL.",s_shares.c_str());
163 if (useFileDirectories && (!maskparam.empty() && !maskparam.size() == 0))
164 mask += "|.rar|.zip";
168 CGUIDialogFileBrowser::ShowAndGetFile(*shares, mask, heading, value, useThumbs, useFileDirectories);
170 CGUIDialogFileBrowser::ShowAndGetImage(*shares, heading, value);
172 CGUIDialogFileBrowser::ShowAndGetDirectory(*shares, heading, value, type != 0);
176 std::vector<String> Dialog::browseMultiple(int type, const String& heading, const String& s_shares,
177 const String& mask, bool useThumbs,
178 bool useFileDirectories, const String& defaultt ) throw (WindowException)
180 DelayedCallGuard dcguard(languageHook);
181 VECSOURCES *shares = CMediaSourceSettings::Get().GetSources(s_shares);
182 CStdStringArray tmpret;
185 throw WindowException("Error: GetSources given %s is NULL.",s_shares.c_str());
187 if (useFileDirectories && (!lmask.empty() && !(lmask.size() == 0)))
188 lmask += "|.rar|.zip";
191 CGUIDialogFileBrowser::ShowAndGetFileList(*shares, lmask, heading, tmpret, useThumbs, useFileDirectories);
193 CGUIDialogFileBrowser::ShowAndGetImageList(*shares, heading, tmpret);
195 throw WindowException("Error: Cannot retreive multuple directories using browse %s is NULL.",s_shares.c_str());
197 std::vector<String> valuelist;
199 for (CStdStringArray::iterator iter = tmpret.begin(); iter != tmpret.end(); ++iter)
200 valuelist[index++] = (*iter);
205 String Dialog::numeric(int inputtype, const String& heading, const String& defaultt)
207 DelayedCallGuard dcguard(languageHook);
210 GetLocalTime(&timedate);
212 if (!heading.empty())
216 if (!defaultt.empty() && defaultt.size() == 10)
218 CStdString sDefault = defaultt;
219 timedate.wDay = atoi(sDefault.Left(2));
220 timedate.wMonth = atoi(sDefault.Mid(3,4));
221 timedate.wYear = atoi(sDefault.Right(4));
223 if (CGUIDialogNumeric::ShowAndGetDate(timedate, heading))
224 value = StringUtils::Format("%2d/%2d/%4d", timedate.wDay, timedate.wMonth, timedate.wYear);
228 else if (inputtype == 2)
230 if (!defaultt.empty() && defaultt.size() == 5)
232 CStdString sDefault = defaultt;
233 timedate.wHour = atoi(sDefault.Left(2));
234 timedate.wMinute = atoi(sDefault.Right(2));
236 if (CGUIDialogNumeric::ShowAndGetTime(timedate, heading))
237 value = StringUtils::Format("%2d:%02d", timedate.wHour, timedate.wMinute);
241 else if (inputtype == 3)
244 if (!CGUIDialogNumeric::ShowAndGetIPAddress(value, heading))
250 if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading))
257 void Dialog::notification(const String& heading, const String& message, const String& icon, int time, bool sound)
259 DelayedCallGuard dcguard(languageHook);
261 CStdString strIcon = getNOTIFICATION_INFO();
262 int iTime = TOAST_DISPLAY_TIME;
269 if (strIcon.Equals(getNOTIFICATION_INFO()))
270 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, heading, message, iTime, sound);
271 else if (strIcon.Equals(getNOTIFICATION_WARNING()))
272 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, heading, message, iTime, sound);
273 else if (strIcon.Equals(getNOTIFICATION_ERROR()))
274 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, heading, message, iTime, sound);
276 CGUIDialogKaiToast::QueueNotification(strIcon, heading, message, iTime, sound);
279 String Dialog::input(const String& heading, const String& defaultt, int type, int option, int autoclose) throw (WindowException)
281 DelayedCallGuard dcguard(languageHook);
282 CStdString value(defaultt);
284 GetLocalTime(&timedate);
290 bool bHiddenInput = option & ALPHANUM_HIDE_INPUT;
291 if (!CGUIKeyboardFactory::ShowAndGetInput(value, heading, true, bHiddenInput, autoclose))
297 if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading, autoclose))
303 if (!defaultt.empty() && defaultt.size() == 10)
305 CStdString sDefault = defaultt;
306 timedate.wDay = atoi(sDefault.Left(2));
307 timedate.wMonth = atoi(sDefault.Mid(3,4));
308 timedate.wYear = atoi(sDefault.Right(4));
310 if (CGUIDialogNumeric::ShowAndGetDate(timedate, heading))
311 value = StringUtils::Format("%2d/%2d/%4d", timedate.wDay, timedate.wMonth, timedate.wYear);
318 if (!defaultt.empty() && defaultt.size() == 5)
320 CStdString sDefault = defaultt;
321 timedate.wHour = atoi(sDefault.Left(2));
322 timedate.wMinute = atoi(sDefault.Right(2));
324 if (CGUIDialogNumeric::ShowAndGetTime(timedate, heading))
325 value = StringUtils::Format("%2d:%02d", timedate.wHour, timedate.wMinute);
330 case INPUT_IPADDRESS:
332 if (!CGUIDialogNumeric::ShowAndGetIPAddress(value, heading))
338 bool bResult = false;
340 if (option & PASSWORD_VERIFY)
341 bResult = CGUIKeyboardFactory::ShowAndVerifyPassword(value, heading, 0, autoclose) == 0 ? true : false;
343 bResult = CGUIKeyboardFactory::ShowAndVerifyNewPassword(value, heading, true, autoclose);
356 DialogProgress::~DialogProgress() { XBMC_TRACE; deallocating(); }
358 void DialogProgress::deallocating()
369 void DialogProgress::create(const String& heading, const String& line1,
371 const String& line3) throw (WindowException)
373 DelayedCallGuard dcguard(languageHook);
374 CGUIDialogProgress* pDialog= (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
377 throw WindowException("Error: Window is NULL, this is not possible :-)");
381 pDialog->SetHeading(heading);
384 pDialog->SetLine(0, line1);
386 pDialog->SetLine(1, line2);
388 pDialog->SetLine(2, line3);
390 pDialog->StartModal();
393 void DialogProgress::update(int percent, const String& line1,
395 const String& line3) throw (WindowException)
397 DelayedCallGuard dcguard(languageHook);
398 CGUIDialogProgress* pDialog= dlg;
401 throw WindowException("Error: Window is NULL, this is not possible :-)");
403 if (percent >= 0 && percent <= 100)
405 pDialog->SetPercentage(percent);
406 pDialog->ShowProgressBar(true);
410 pDialog->ShowProgressBar(false);
414 pDialog->SetLine(0, line1);
416 pDialog->SetLine(1, line2);
418 pDialog->SetLine(2, line3);
421 void DialogProgress::close()
423 DelayedCallGuard dcguard(languageHook);
427 bool DialogProgress::iscanceled()
429 return dlg->IsCanceled();
432 DialogProgressBG::~DialogProgressBG() { XBMC_TRACE; deallocating(); }
434 void DialogProgressBG::deallocating()
445 void DialogProgressBG::create(const String& heading, const String& message) throw (WindowException)
447 DelayedCallGuard dcguard(languageHook);
448 CGUIDialogExtendedProgressBar* pDialog =
449 (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS);
452 throw WindowException("Error: Window is NULL, this is not possible :-)");
454 CGUIDialogProgressBarHandle* pHandle = pDialog->GetHandle(heading);
459 pHandle->SetTitle(heading);
460 if (!message.empty())
461 pHandle->SetText(message);
464 void DialogProgressBG::update(int percent, const String& heading, const String& message) throw (WindowException)
466 DelayedCallGuard dcguard(languageHook);
467 CGUIDialogExtendedProgressBar* pDialog = dlg;
468 CGUIDialogProgressBarHandle* pHandle = handle;
471 throw WindowException("Error: Window is NULL, this is not possible :-)");
473 if (percent >= 0 && percent <= 100)
474 pHandle->SetPercentage((float)percent);
475 if (!heading.empty())
476 pHandle->SetTitle(heading);
477 if (!message.empty())
478 pHandle->SetText(message);
481 void DialogProgressBG::close()
483 DelayedCallGuard dcguard(languageHook);
484 handle->MarkFinished();
487 bool DialogProgressBG::isFinished()
489 return handle->IsFinished();