2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIDialogYesNo.h"
11 #include "ServiceBroker.h"
12 #include "guilib/GUIComponent.h"
13 #include "guilib/GUIWindowManager.h"
14 #include "input/Key.h"
15 #include "messaging/helpers/DialogHelper.h"
17 CGUIDialogYesNo::CGUIDialogYesNo(int overrideId
/* = -1 */)
18 : CGUIDialogBoxBase(overrideId
== -1 ? WINDOW_DIALOG_YES_NO
: overrideId
, "DialogConfirm.xml")
23 CGUIDialogYesNo::~CGUIDialogYesNo() = default;
25 bool CGUIDialogYesNo::OnMessage(CGUIMessage
& message
)
27 switch ( message
.GetMessage() )
31 int iControl
= message
.GetSenderId();
32 int iAction
= message
.GetParam1();
33 if (true || ACTION_SELECT_ITEM
== iAction
)
35 if (iControl
== CONTROL_NO_BUTTON
)
41 if (iControl
== CONTROL_YES_BUTTON
)
47 if (iControl
== CONTROL_CUSTOM_BUTTON
)
58 return CGUIDialogBoxBase::OnMessage(message
);
61 bool CGUIDialogYesNo::OnBack(int actionID
)
66 return CGUIDialogBoxBase::OnBack(actionID
);
69 void CGUIDialogYesNo::OnInitWindow()
71 if (!m_strChoices
[2].empty())
72 SET_CONTROL_VISIBLE(CONTROL_CUSTOM_BUTTON
);
74 SET_CONTROL_HIDDEN(CONTROL_CUSTOM_BUTTON
);
75 SET_CONTROL_HIDDEN(CONTROL_PROGRESS_BAR
);
76 SET_CONTROL_FOCUS(m_defaultButtonId
, 0);
78 CGUIDialogBoxBase::OnInitWindow();
81 bool CGUIDialogYesNo::ShowAndGetInput(const CVariant
& heading
,
82 const CVariant
& line0
,
83 const CVariant
& line1
,
84 const CVariant
& line2
,
87 return ShowAndGetInput(heading
, line0
, line1
, line2
, bCanceled
, "", "", NO_TIMEOUT
);
90 bool CGUIDialogYesNo::ShowAndGetInput(const CVariant
& heading
,
91 const CVariant
& line0
,
92 const CVariant
& line1
,
93 const CVariant
& line2
,
94 const CVariant
& noLabel
/* = "" */,
95 const CVariant
& yesLabel
/* = "" */)
98 return ShowAndGetInput(heading
, line0
, line1
, line2
, bDummy
, noLabel
, yesLabel
, NO_TIMEOUT
);
101 bool CGUIDialogYesNo::ShowAndGetInput(const CVariant
& heading
,
102 const CVariant
& line0
,
103 const CVariant
& line1
,
104 const CVariant
& line2
,
106 const CVariant
& noLabel
,
107 const CVariant
& yesLabel
,
108 unsigned int autoCloseTime
)
110 CGUIDialogYesNo
*dialog
= CServiceBroker::GetGUI()->GetWindowManager().GetWindow
<CGUIDialogYesNo
>(WINDOW_DIALOG_YES_NO
);
114 dialog
->SetHeading(heading
);
115 dialog
->SetLine(0, line0
);
116 dialog
->SetLine(1, line1
);
117 dialog
->SetLine(2, line2
);
119 dialog
->SetAutoClose(autoCloseTime
);
120 dialog
->SetChoice(0, !noLabel
.empty() ? noLabel
: 106);
121 dialog
->SetChoice(1, !yesLabel
.empty() ? yesLabel
: 107);
122 dialog
->SetChoice(2, "");
123 dialog
->m_bCanceled
= false;
124 dialog
->m_defaultButtonId
= CONTROL_NO_BUTTON
;
127 bCanceled
= dialog
->m_bCanceled
;
128 return (dialog
->IsConfirmed()) ? true : false;
131 bool CGUIDialogYesNo::ShowAndGetInput(const CVariant
& heading
, const CVariant
& text
)
134 return ShowAndGetInput(heading
, text
, "", "", bDummy
);
137 bool CGUIDialogYesNo::ShowAndGetInput(const CVariant
& heading
,
138 const CVariant
& text
,
140 const CVariant
& noLabel
/* = "" */,
141 const CVariant
& yesLabel
/* = "" */,
142 unsigned int autoCloseTime
,
143 int defaultButtonId
/* = CONTROL_NO_BUTTON */)
146 ShowAndGetInput(heading
, text
, noLabel
, yesLabel
, "", autoCloseTime
, defaultButtonId
);
148 bCanceled
= result
== -1;
152 void CGUIDialogYesNo::Reset()
154 m_bConfirmed
= false;
157 m_bAutoClosed
= false;
158 m_defaultButtonId
= CONTROL_NO_BUTTON
;
161 int CGUIDialogYesNo::GetResult() const
167 else if (IsConfirmed())
173 int CGUIDialogYesNo::ShowAndGetInput(const CVariant
& heading
,
174 const CVariant
& text
,
175 const CVariant
& noLabel
,
176 const CVariant
& yesLabel
,
177 const CVariant
& customLabel
,
178 unsigned int autoCloseTime
,
179 int defaultButtonId
/* = CONTROL_NO_BUTTON */)
181 CGUIDialogYesNo
*dialog
= CServiceBroker::GetGUI()->GetWindowManager().GetWindow
<CGUIDialogYesNo
>(WINDOW_DIALOG_YES_NO
);
185 dialog
->SetHeading(heading
);
186 dialog
->SetText(text
);
187 if (autoCloseTime
> 0)
188 dialog
->SetAutoClose(autoCloseTime
);
189 dialog
->m_bCanceled
= false;
190 dialog
->m_bCustom
= false;
191 dialog
->m_defaultButtonId
= defaultButtonId
;
192 dialog
->SetChoice(0, !noLabel
.empty() ? noLabel
: 106);
193 dialog
->SetChoice(1, !yesLabel
.empty() ? yesLabel
: 107);
194 dialog
->SetChoice(2, customLabel
); // Button only visible when label is not empty
197 return dialog
->GetResult();
200 int CGUIDialogYesNo::ShowAndGetInput(const KODI::MESSAGING::HELPERS::DialogYesNoMessage
& options
)
202 //Set default yes/no labels, these might be overwritten further down if specified
207 if (!options
.heading
.isNull())
208 SetHeading(options
.heading
);
209 if (!options
.text
.isNull())
210 SetText(options
.text
);
211 if (!options
.noLabel
.isNull())
212 SetChoice(0, options
.noLabel
);
213 if (!options
.yesLabel
.isNull())
214 SetChoice(1, options
.yesLabel
);
215 if (!options
.customLabel
.isNull())
216 SetChoice(2, options
.customLabel
);
217 if (options
.autoclose
> 0)
218 SetAutoClose(options
.autoclose
);
221 m_defaultButtonId
= CONTROL_NO_BUTTON
;
223 for (size_t i
= 0; i
< 3; ++i
)
225 if (!options
.lines
[i
].isNull())
226 SetLine(i
, options
.lines
[i
]);
234 int CGUIDialogYesNo::GetDefaultLabelID(int controlId
) const
236 if (controlId
== CONTROL_NO_BUTTON
)
238 else if (controlId
== CONTROL_YES_BUTTON
)
240 else if (controlId
== CONTROL_CUSTOM_BUTTON
)
242 return CGUIDialogBoxBase::GetDefaultLabelID(controlId
);