Merge pull request #4594 from FernetMenta/paplayer
[xbmc.git] / xbmc / dialogs / GUIDialogYesNo.cpp
blob5143ecde25ae6df11ca796d771e1d7dcce422c4e
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
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)
8 * any later version.
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/>.
21 #include "GUIDialogYesNo.h"
22 #include "guilib/GUIWindowManager.h"
23 #include "guilib/Key.h"
25 #define CONTROL_NO_BUTTON 10
26 #define CONTROL_YES_BUTTON 11
28 CGUIDialogYesNo::CGUIDialogYesNo(int overrideId /* = -1 */)
29 : CGUIDialogBoxBase(overrideId == -1 ? WINDOW_DIALOG_YES_NO : overrideId, "DialogYesNo.xml")
31 m_bConfirmed = false;
34 CGUIDialogYesNo::~CGUIDialogYesNo()
38 bool CGUIDialogYesNo::OnMessage(CGUIMessage& message)
40 switch ( message.GetMessage() )
42 case GUI_MSG_CLICKED:
44 int iControl = message.GetSenderId();
45 int iAction = message.GetParam1();
46 if (1 || ACTION_SELECT_ITEM == iAction)
48 if (iControl == CONTROL_NO_BUTTON)
50 m_bConfirmed = false;
51 Close();
52 return true;
54 if (iControl == CONTROL_YES_BUTTON)
56 m_bConfirmed = true;
57 Close();
58 return true;
62 break;
64 return CGUIDialogBoxBase::OnMessage(message);
67 bool CGUIDialogYesNo::OnBack(int actionID)
69 m_bCanceled = true;
70 m_bConfirmed = false;
71 return CGUIDialogBoxBase::OnBack(actionID);
74 // \brief Show CGUIDialogYesNo dialog, then wait for user to dismiss it.
75 // \return true if user selects Yes, false if user selects No.
76 bool CGUIDialogYesNo::ShowAndGetInput(int heading, int line0, int line1, int line2, bool& bCanceled)
78 return ShowAndGetInput(heading,line0,line1,line2,-1,-1,bCanceled);
81 bool CGUIDialogYesNo::ShowAndGetInput(int heading, int line0, int line1, int line2, int iNoLabel, int iYesLabel)
83 bool bDummy;
84 return ShowAndGetInput(heading,line0,line1,line2,iNoLabel,iYesLabel,bDummy);
87 bool CGUIDialogYesNo::ShowAndGetInput(int heading, int line0, int line1, int line2, int iNoLabel, int iYesLabel, bool& bCanceled, unsigned int autoCloseTime)
89 CGUIDialogYesNo *dialog = (CGUIDialogYesNo *)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
90 if (!dialog) return false;
91 dialog->SetHeading(heading);
92 dialog->SetLine(0, line0);
93 dialog->SetLine(1, line1);
94 dialog->SetLine(2, line2);
95 if (autoCloseTime)
96 dialog->SetAutoClose(autoCloseTime);
97 if (iNoLabel != -1)
98 dialog->SetChoice(0,iNoLabel);
99 else
100 dialog->SetChoice(0,106);
101 if (iYesLabel != -1)
102 dialog->SetChoice(1,iYesLabel);
103 else
104 dialog->SetChoice(1,107);
105 dialog->m_bCanceled = false;
106 dialog->DoModal();
107 bCanceled = dialog->m_bCanceled;
108 return (dialog->IsConfirmed()) ? true : false;
111 bool CGUIDialogYesNo::ShowAndGetInput(const CStdString& heading, const CStdString& line0, const CStdString& line1, const CStdString& line2, const CStdString& noLabel, const CStdString& yesLabel)
113 bool bDummy;
114 return ShowAndGetInput(heading,line0,line1,line2,bDummy,noLabel,yesLabel);
117 bool CGUIDialogYesNo::ShowAndGetInput(const std::string& heading, const std::string& text, bool& bCanceled, const std::string& noLabel, const std::string& yesLabel)
119 CGUIDialogYesNo *dialog = (CGUIDialogYesNo *)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
120 if (!dialog) return false;
121 dialog->SetHeading(heading);
122 dialog->SetText(text);
123 dialog->m_bCanceled = false;
124 if (!noLabel.empty())
125 dialog->SetChoice(0,noLabel);
126 else
127 dialog->SetChoice(0,106);
128 if (!yesLabel.empty())
129 dialog->SetChoice(1,yesLabel);
130 else
131 dialog->SetChoice(1,107);
132 dialog->DoModal();
133 bCanceled = dialog->m_bCanceled;
134 return (dialog->IsConfirmed()) ? true : false;
137 bool CGUIDialogYesNo::ShowAndGetInput(const CStdString& heading, const CStdString& line0, const CStdString& line1, const CStdString& line2, bool& bCanceled, const CStdString& noLabel, const CStdString& yesLabel)
139 std::string text = line0 + "\n" + line1 + "\n" + line2;
140 return ShowAndGetInput(heading, text, bCanceled, noLabel, yesLabel);
143 int CGUIDialogYesNo::GetDefaultLabelID(int controlId) const
145 if (controlId == CONTROL_NO_BUTTON)
146 return 106;
147 else if (controlId == CONTROL_YES_BUTTON)
148 return 107;
149 return CGUIDialogBoxBase::GetDefaultLabelID(controlId);