1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "GUIDialogYesNo.h"
#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "input/Key.h"
#include "messaging/helpers/DialogHelper.h"
CGUIDialogYesNo::CGUIDialogYesNo(int overrideId /* = -1 */)
: CGUIDialogBoxBase(overrideId == -1 ? WINDOW_DIALOG_YES_NO : overrideId, "DialogConfirm.xml")
{
Reset();
}
CGUIDialogYesNo::~CGUIDialogYesNo() = default;
bool CGUIDialogYesNo::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
int iAction = message.GetParam1();
if (true || ACTION_SELECT_ITEM == iAction)
{
if (iControl == CONTROL_NO_BUTTON)
{
m_bConfirmed = false;
Close();
return true;
}
if (iControl == CONTROL_YES_BUTTON)
{
m_bConfirmed = true;
Close();
return true;
}
if (iControl == CONTROL_CUSTOM_BUTTON)
{
m_bConfirmed = false;
m_bCustom = true;
Close();
return true;
}
}
}
break;
}
return CGUIDialogBoxBase::OnMessage(message);
}
bool CGUIDialogYesNo::OnBack(int actionID)
{
m_bCanceled = true;
m_bConfirmed = false;
m_bCustom = false;
return CGUIDialogBoxBase::OnBack(actionID);
}
void CGUIDialogYesNo::OnInitWindow()
{
if (!m_strChoices[2].empty())
SET_CONTROL_VISIBLE(CONTROL_CUSTOM_BUTTON);
else
SET_CONTROL_HIDDEN(CONTROL_CUSTOM_BUTTON);
SET_CONTROL_HIDDEN(CONTROL_PROGRESS_BAR);
SET_CONTROL_FOCUS(m_defaultButtonId, 0);
CGUIDialogBoxBase::OnInitWindow();
}
bool CGUIDialogYesNo::ShowAndGetInput(const CVariant& heading,
const CVariant& line0,
const CVariant& line1,
const CVariant& line2,
bool& bCanceled)
{
return ShowAndGetInput(heading, line0, line1, line2, bCanceled, "", "", NO_TIMEOUT);
}
bool CGUIDialogYesNo::ShowAndGetInput(const CVariant& heading,
const CVariant& line0,
const CVariant& line1,
const CVariant& line2,
const CVariant& noLabel /* = "" */,
const CVariant& yesLabel /* = "" */)
{
bool bDummy(false);
return ShowAndGetInput(heading, line0, line1, line2, bDummy, noLabel, yesLabel, NO_TIMEOUT);
}
bool CGUIDialogYesNo::ShowAndGetInput(const CVariant& heading,
const CVariant& line0,
const CVariant& line1,
const CVariant& line2,
bool& bCanceled,
const CVariant& noLabel,
const CVariant& yesLabel,
unsigned int autoCloseTime)
{
CGUIDialogYesNo *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogYesNo>(WINDOW_DIALOG_YES_NO);
if (!dialog)
return false;
dialog->SetHeading(heading);
dialog->SetLine(0, line0);
dialog->SetLine(1, line1);
dialog->SetLine(2, line2);
if (autoCloseTime)
dialog->SetAutoClose(autoCloseTime);
dialog->SetChoice(0, !noLabel.empty() ? noLabel : 106);
dialog->SetChoice(1, !yesLabel.empty() ? yesLabel : 107);
dialog->SetChoice(2, "");
dialog->m_bCanceled = false;
dialog->m_defaultButtonId = CONTROL_NO_BUTTON;
dialog->Open();
bCanceled = dialog->m_bCanceled;
return (dialog->IsConfirmed()) ? true : false;
}
bool CGUIDialogYesNo::ShowAndGetInput(const CVariant& heading, const CVariant& text)
{
bool bDummy(false);
return ShowAndGetInput(heading, text, "", "", bDummy);
}
bool CGUIDialogYesNo::ShowAndGetInput(const CVariant& heading,
const CVariant& text,
bool& bCanceled,
const CVariant& noLabel /* = "" */,
const CVariant& yesLabel /* = "" */,
unsigned int autoCloseTime,
int defaultButtonId /* = CONTROL_NO_BUTTON */)
{
int result =
ShowAndGetInput(heading, text, noLabel, yesLabel, "", autoCloseTime, defaultButtonId);
bCanceled = result == -1;
return result == 1;
}
void CGUIDialogYesNo::Reset()
{
m_bConfirmed = false;
m_bCanceled = false;
m_bCustom = false;
m_bAutoClosed = false;
m_defaultButtonId = CONTROL_NO_BUTTON;
}
int CGUIDialogYesNo::GetResult() const
{
if (m_bCanceled)
return -1;
else if (m_bCustom)
return 2;
else if (IsConfirmed())
return 1;
else
return 0;
}
int CGUIDialogYesNo::ShowAndGetInput(const CVariant& heading,
const CVariant& text,
const CVariant& noLabel,
const CVariant& yesLabel,
const CVariant& customLabel,
unsigned int autoCloseTime,
int defaultButtonId /* = CONTROL_NO_BUTTON */)
{
CGUIDialogYesNo *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogYesNo>(WINDOW_DIALOG_YES_NO);
if (!dialog)
return false;
dialog->SetHeading(heading);
dialog->SetText(text);
if (autoCloseTime > 0)
dialog->SetAutoClose(autoCloseTime);
dialog->m_bCanceled = false;
dialog->m_bCustom = false;
dialog->m_defaultButtonId = defaultButtonId;
dialog->SetChoice(0, !noLabel.empty() ? noLabel : 106);
dialog->SetChoice(1, !yesLabel.empty() ? yesLabel : 107);
dialog->SetChoice(2, customLabel); // Button only visible when label is not empty
dialog->Open();
return dialog->GetResult();
}
int CGUIDialogYesNo::ShowAndGetInput(const KODI::MESSAGING::HELPERS::DialogYesNoMessage& options)
{
//Set default yes/no labels, these might be overwritten further down if specified
//by the caller
SetChoice(0, 106);
SetChoice(1, 107);
SetChoice(2, "");
if (!options.heading.isNull())
SetHeading(options.heading);
if (!options.text.isNull())
SetText(options.text);
if (!options.noLabel.isNull())
SetChoice(0, options.noLabel);
if (!options.yesLabel.isNull())
SetChoice(1, options.yesLabel);
if (!options.customLabel.isNull())
SetChoice(2, options.customLabel);
if (options.autoclose > 0)
SetAutoClose(options.autoclose);
m_bCanceled = false;
m_bCustom = false;
m_defaultButtonId = CONTROL_NO_BUTTON;
for (size_t i = 0; i < 3; ++i)
{
if (!options.lines[i].isNull())
SetLine(i, options.lines[i]);
}
Open();
return GetResult();
}
int CGUIDialogYesNo::GetDefaultLabelID(int controlId) const
{
if (controlId == CONTROL_NO_BUTTON)
return 106;
else if (controlId == CONTROL_YES_BUTTON)
return 107;
else if (controlId == CONTROL_CUSTOM_BUTTON)
return -1;
return CGUIDialogBoxBase::GetDefaultLabelID(controlId);
}
|