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"
33 #define ACTIVE_WINDOW g_windowManager.GetActiveWindow()
39 static void XBMCWaitForThreadMessage(int message, int param1, int param2)
41 ThreadMessage tMsg = {(DWORD)message, (DWORD)param1, (DWORD)param2};
42 CApplicationMessenger::Get().SendMessage(tMsg, true);
47 bool Dialog::yesno(const String& heading, const String& line1,
50 const String& nolabel,
51 const String& yeslabel,
52 int autoclose) throw (WindowException)
54 DelayedCallGuard dcguard(languageHook);
55 const int window = WINDOW_DIALOG_YES_NO;
56 CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(window);
58 throw WindowException("Error: Window is NULL, this is not possible :-)");
60 // get lines, last 4 lines are optional.
62 pDialog->SetHeading(heading);
64 pDialog->SetLine(0, line1);
66 pDialog->SetLine(1, line2);
68 pDialog->SetLine(2, line3);
71 pDialog->SetChoice(0,nolabel);
72 if (!yeslabel.empty())
73 pDialog->SetChoice(1,yeslabel);
76 pDialog->SetAutoClose(autoclose);
78 //send message and wait for user input
79 XBMCWaitForThreadMessage(TMSG_DIALOG_DOMODAL, window, ACTIVE_WINDOW);
81 return pDialog->IsConfirmed();
84 int Dialog::select(const String& heading, const std::vector<String>& list, int autoclose) throw (WindowException)
86 DelayedCallGuard dcguard(languageHook);
87 const int window = WINDOW_DIALOG_SELECT;
88 CGUIDialogSelect* pDialog= (CGUIDialogSelect*)g_windowManager.GetWindow(window);
90 throw WindowException("Error: Window is NULL, this is not possible :-)");
94 pDialog->SetHeading(heading);
97 for(unsigned int i = 0; i < list.size(); i++)
100 pDialog->Add(listLine);
103 pDialog->SetAutoClose(autoclose);
105 //send message and wait for user input
106 XBMCWaitForThreadMessage(TMSG_DIALOG_DOMODAL, window, ACTIVE_WINDOW);
108 return pDialog->GetSelectedLabel();
111 bool Dialog::ok(const String& heading, const String& line1,
113 const String& line3) throw (WindowException)
115 DelayedCallGuard dcguard(languageHook);
116 const int window = WINDOW_DIALOG_OK;
118 CGUIDialogOK* pDialog = (CGUIDialogOK*)g_windowManager.GetWindow(window);
120 throw WindowException("Error: Window is NULL, this is not possible :-)");
122 if (!heading.empty())
123 pDialog->SetHeading(heading);
125 pDialog->SetLine(0, line1);
127 pDialog->SetLine(1, line2);
129 pDialog->SetLine(2, line3);
131 //send message and wait for user input
132 XBMCWaitForThreadMessage(TMSG_DIALOG_DOMODAL, window, ACTIVE_WINDOW);
134 return pDialog->IsConfirmed();
137 Alternative<String, std::vector<String> > Dialog::browse(int type, const String& heading,
138 const String& s_shares, const String& maskparam, bool useThumbs,
139 bool useFileDirectories, const String& defaultt,
140 bool enableMultiple) throw (WindowException)
142 Alternative<String, std::vector<String> > ret;
144 ret.later() = browseMultiple(type,heading,s_shares,maskparam,useThumbs,useFileDirectories,defaultt);
146 ret.former() = browseSingle(type,heading,s_shares,maskparam,useThumbs,useFileDirectories,defaultt);
150 String Dialog::browseSingle(int type, const String& heading, const String& s_shares,
151 const String& maskparam, bool useThumbs,
152 bool useFileDirectories,
153 const String& defaultt ) throw (WindowException)
155 DelayedCallGuard dcguard(languageHook);
157 std::string mask = maskparam;
158 VECSOURCES *shares = CMediaSourceSettings::Get().GetSources(s_shares);
160 throw WindowException("Error: GetSources given %s is NULL.",s_shares.c_str());
162 if (useFileDirectories && (!maskparam.empty() && !maskparam.size() == 0))
163 mask += "|.rar|.zip";
167 CGUIDialogFileBrowser::ShowAndGetFile(*shares, mask, heading, value, useThumbs, useFileDirectories);
169 CGUIDialogFileBrowser::ShowAndGetImage(*shares, heading, value);
171 CGUIDialogFileBrowser::ShowAndGetDirectory(*shares, heading, value, type != 0);
175 std::vector<String> Dialog::browseMultiple(int type, const String& heading, const String& s_shares,
176 const String& mask, bool useThumbs,
177 bool useFileDirectories, const String& defaultt ) throw (WindowException)
179 DelayedCallGuard dcguard(languageHook);
180 VECSOURCES *shares = CMediaSourceSettings::Get().GetSources(s_shares);
181 CStdStringArray tmpret;
184 throw WindowException("Error: GetSources given %s is NULL.",s_shares.c_str());
186 if (useFileDirectories && (!lmask.empty() && !(lmask.size() == 0)))
187 lmask += "|.rar|.zip";
190 CGUIDialogFileBrowser::ShowAndGetFileList(*shares, lmask, heading, tmpret, useThumbs, useFileDirectories);
192 CGUIDialogFileBrowser::ShowAndGetImageList(*shares, heading, tmpret);
194 throw WindowException("Error: Cannot retreive multuple directories using browse %s is NULL.",s_shares.c_str());
196 std::vector<String> valuelist;
198 for (CStdStringArray::iterator iter = tmpret.begin(); iter != tmpret.end(); ++iter)
199 valuelist[index++] = (*iter);
204 String Dialog::numeric(int inputtype, const String& heading, const String& defaultt)
206 DelayedCallGuard dcguard(languageHook);
209 GetLocalTime(&timedate);
211 if (!heading.empty())
215 if (!defaultt.empty() && defaultt.size() == 10)
217 CStdString sDefault = defaultt;
218 timedate.wDay = atoi(sDefault.Left(2));
219 timedate.wMonth = atoi(sDefault.Mid(3,4));
220 timedate.wYear = atoi(sDefault.Right(4));
222 if (CGUIDialogNumeric::ShowAndGetDate(timedate, heading))
223 value.Format("%2d/%2d/%4d", timedate.wDay, timedate.wMonth, timedate.wYear);
227 else if (inputtype == 2)
229 if (!defaultt.empty() && defaultt.size() == 5)
231 CStdString sDefault = defaultt;
232 timedate.wHour = atoi(sDefault.Left(2));
233 timedate.wMinute = atoi(sDefault.Right(2));
235 if (CGUIDialogNumeric::ShowAndGetTime(timedate, heading))
236 value.Format("%2d:%02d", timedate.wHour, timedate.wMinute);
240 else if (inputtype == 3)
243 if (!CGUIDialogNumeric::ShowAndGetIPAddress(value, heading))
249 if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading))
256 void Dialog::notification(const String& heading, const String& message, const String& icon, int time, bool sound)
258 DelayedCallGuard dcguard(languageHook);
260 CStdString strIcon = getNOTIFICATION_INFO();
261 int iTime = TOAST_DISPLAY_TIME;
268 if (strIcon.Equals(getNOTIFICATION_INFO()))
269 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, heading, message, iTime, sound);
270 else if (strIcon.Equals(getNOTIFICATION_WARNING()))
271 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, heading, message, iTime, sound);
272 else if (strIcon.Equals(getNOTIFICATION_ERROR()))
273 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, heading, message, iTime, sound);
275 CGUIDialogKaiToast::QueueNotification(strIcon, heading, message, iTime, sound);
278 String Dialog::input(const String& heading, const String& defaultt, int type, int option, int autoclose) throw (WindowException)
280 DelayedCallGuard dcguard(languageHook);
281 CStdString value(defaultt);
283 GetLocalTime(&timedate);
289 bool bHiddenInput = option & ALPHANUM_HIDE_INPUT;
290 if (!CGUIKeyboardFactory::ShowAndGetInput(value, heading, true, bHiddenInput, autoclose))
296 if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading, autoclose))
302 if (!defaultt.empty() && defaultt.size() == 10)
304 CStdString sDefault = defaultt;
305 timedate.wDay = atoi(sDefault.Left(2));
306 timedate.wMonth = atoi(sDefault.Mid(3,4));
307 timedate.wYear = atoi(sDefault.Right(4));
309 if (CGUIDialogNumeric::ShowAndGetDate(timedate, heading))
310 value.Format("%2d/%2d/%4d", timedate.wDay, timedate.wMonth, timedate.wYear);
317 if (!defaultt.empty() && defaultt.size() == 5)
319 CStdString sDefault = defaultt;
320 timedate.wHour = atoi(sDefault.Left(2));
321 timedate.wMinute = atoi(sDefault.Right(2));
323 if (CGUIDialogNumeric::ShowAndGetTime(timedate, heading))
324 value.Format("%2d:%02d", timedate.wHour, timedate.wMinute);
329 case INPUT_IPADDRESS:
331 if (!CGUIDialogNumeric::ShowAndGetIPAddress(value, heading))
337 bool bResult = false;
339 if (option & PASSWORD_VERIFY)
340 bResult = CGUIKeyboardFactory::ShowAndVerifyPassword(value, heading, 0, autoclose) == 0 ? true : false;
342 bResult = CGUIKeyboardFactory::ShowAndVerifyNewPassword(value, heading, true, autoclose);
355 DialogProgress::~DialogProgress() { XBMC_TRACE; deallocating(); }
357 void DialogProgress::deallocating()
368 void DialogProgress::create(const String& heading, const String& line1,
370 const String& line3) throw (WindowException)
372 DelayedCallGuard dcguard(languageHook);
373 CGUIDialogProgress* pDialog= (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
376 throw WindowException("Error: Window is NULL, this is not possible :-)");
380 pDialog->SetHeading(heading);
383 pDialog->SetLine(0, line1);
385 pDialog->SetLine(1, line2);
387 pDialog->SetLine(2, line3);
389 pDialog->StartModal();
392 void DialogProgress::update(int percent, const String& line1,
394 const String& line3) throw (WindowException)
396 DelayedCallGuard dcguard(languageHook);
397 CGUIDialogProgress* pDialog= dlg;
400 throw WindowException("Error: Window is NULL, this is not possible :-)");
402 if (percent >= 0 && percent <= 100)
404 pDialog->SetPercentage(percent);
405 pDialog->ShowProgressBar(true);
409 pDialog->ShowProgressBar(false);
413 pDialog->SetLine(0, line1);
415 pDialog->SetLine(1, line2);
417 pDialog->SetLine(2, line3);
420 void DialogProgress::close()
422 DelayedCallGuard dcguard(languageHook);
426 bool DialogProgress::iscanceled()
428 return dlg->IsCanceled();
431 DialogProgressBG::~DialogProgressBG() { XBMC_TRACE; deallocating(); }
433 void DialogProgressBG::deallocating()
444 void DialogProgressBG::create(const String& heading, const String& message) throw (WindowException)
446 DelayedCallGuard dcguard(languageHook);
447 CGUIDialogExtendedProgressBar* pDialog =
448 (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS);
451 throw WindowException("Error: Window is NULL, this is not possible :-)");
453 CGUIDialogProgressBarHandle* pHandle = pDialog->GetHandle(heading);
458 pHandle->SetTitle(heading);
459 if (!message.empty())
460 pHandle->SetText(message);
463 void DialogProgressBG::update(int percent, const String& heading, const String& message) throw (WindowException)
465 DelayedCallGuard dcguard(languageHook);
466 CGUIDialogExtendedProgressBar* pDialog = dlg;
467 CGUIDialogProgressBarHandle* pHandle = handle;
470 throw WindowException("Error: Window is NULL, this is not possible :-)");
472 if (percent >= 0 && percent <= 100)
473 pHandle->SetPercentage((float)percent);
474 if (!heading.empty())
475 pHandle->SetTitle(heading);
476 if (!message.empty())
477 pHandle->SetText(message);
480 void DialogProgressBG::close()
482 DelayedCallGuard dcguard(languageHook);
483 handle->MarkFinished();
486 bool DialogProgressBG::isFinished()
488 return handle->IsFinished();