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/>.
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")
34 CGUIDialogYesNo::~CGUIDialogYesNo()
38 bool CGUIDialogYesNo::OnMessage(CGUIMessage
& message
)
40 switch ( message
.GetMessage() )
44 int iControl
= message
.GetSenderId();
45 int iAction
= message
.GetParam1();
46 if (1 || ACTION_SELECT_ITEM
== iAction
)
48 if (iControl
== CONTROL_NO_BUTTON
)
54 if (iControl
== CONTROL_YES_BUTTON
)
64 return CGUIDialogBoxBase::OnMessage(message
);
67 bool CGUIDialogYesNo::OnBack(int actionID
)
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
)
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
);
96 dialog
->SetAutoClose(autoCloseTime
);
98 dialog
->SetChoice(0,iNoLabel
);
100 dialog
->SetChoice(0,106);
102 dialog
->SetChoice(1,iYesLabel
);
104 dialog
->SetChoice(1,107);
105 dialog
->m_bCanceled
= false;
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
)
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
);
127 dialog
->SetChoice(0,106);
128 if (!yesLabel
.empty())
129 dialog
->SetChoice(1,yesLabel
);
131 dialog
->SetChoice(1,107);
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
)
147 else if (controlId
== CONTROL_YES_BUTTON
)
149 return CGUIDialogBoxBase::GetDefaultLabelID(controlId
);