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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
#pragma once
/*
* Copyright (C) 2005-2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KODI; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "../AddonBase.h"
#include "definitions.h"
#include <memory>
namespace kodi
{
namespace gui
{
class CWindow;
class CAddonGUIControlBase
{
public:
GUIHANDLE GetControlHandle() const { return m_controlHandle; }
protected:
explicit CAddonGUIControlBase(CAddonGUIControlBase* window)
: m_controlHandle(nullptr),
m_interface(::kodi::addon::CAddonBase::m_interface->toKodi),
m_Window(window) {}
virtual ~CAddonGUIControlBase() = default;
friend class CWindow;
GUIHANDLE m_controlHandle;
AddonToKodiFuncTable_Addon* m_interface;
CAddonGUIControlBase* m_Window;
private:
CAddonGUIControlBase() = delete;
CAddonGUIControlBase(const CAddonGUIControlBase&) = delete;
CAddonGUIControlBase &operator=(const CAddonGUIControlBase&) = delete;
};
class CListItem;
typedef std::shared_ptr<CListItem> ListItemPtr;
//============================================================================
///
/// \defgroup cpp_kodi_gui_CListItem List Item
/// \ingroup cpp_kodi_gui
/// @brief \cpp_class{ kodi::gui::CListItem }
/// **Selectable window list item**
///
/// The list item control is used for creating item lists in Kodi
///
/// The with \ref ListItem.h "#include <kodi/gui/ListItem.h>" given
/// class is used to create a item entry for a list on window and to support it's
/// control.
///
//============================================================================
///
/// \defgroup cpp_kodi_gui_CListItem_Defs Definitions, structures and enumerators
/// \ingroup cpp_kodi_gui_CListItem
/// @brief **Library definition values**
///
class CListItem : public CAddonGUIControlBase
{
public:
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Class constructor with parameters
///
/// @param[in] label Item label
/// @param[in] label2 Second Item label (if needed)
/// @param[in] iconImage Item icon image (if needed)
/// @param[in] path Path to where item is defined
///
CListItem(
const std::string& label = "",
const std::string& label2 = "",
const std::string& iconImage = "",
const std::string& path = "")
: CAddonGUIControlBase(nullptr)
{
m_controlHandle = m_interface->kodi_gui->listItem->create(m_interface->kodiBase, label.c_str(),
label2.c_str(), iconImage.c_str(),
path.c_str());
}
/*
* Constructor used for parts given by list items from addon window
*
* Related to call of "ListItemPtr kodi::gui::CWindow::GetListItem(int listPos)"
* Not needed for addon development itself
*/
explicit CListItem(GUIHANDLE listItemHandle)
: CAddonGUIControlBase(nullptr)
{
m_controlHandle = listItemHandle;
}
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Class destructor
///
~CListItem() override
{
m_interface->kodi_gui->listItem->destroy(m_interface->kodiBase, m_controlHandle);
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Returns the listitem label.
///
/// @return Label of item
///
std::string GetLabel()
{
std::string label;
char* ret = m_interface->kodi_gui->listItem->get_label(m_interface->kodiBase, m_controlHandle);
if (ret != nullptr)
{
if (std::strlen(ret))
label = ret;
m_interface->free_string(m_interface->kodiBase, ret);
}
return label;
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Sets the listitem label.
///
/// @param[in] label string or unicode - text string.
///
void SetLabel(const std::string& label)
{
m_interface->kodi_gui->listItem->set_label(m_interface->kodiBase, m_controlHandle, label.c_str());
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Returns the second listitem label.
///
/// @return Second label of item
///
std::string GetLabel2()
{
std::string label;
char* ret = m_interface->kodi_gui->listItem->get_label2(m_interface->kodiBase, m_controlHandle);
if (ret != nullptr)
{
if (std::strlen(ret))
label = ret;
m_interface->free_string(m_interface->kodiBase, ret);
}
return label;
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Sets the listitem's label2.
///
/// @param[in] label string or unicode - text string.
///
void SetLabel2(const std::string& label)
{
m_interface->kodi_gui->listItem->set_label2(m_interface->kodiBase, m_controlHandle, label.c_str());
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief To get current icon image of entry
///
/// @return The current icon image path (if present)
///
std::string GetIconImage()
{
std::string image;
char* ret = m_interface->kodi_gui->listItem->get_icon_image(m_interface->kodiBase, m_controlHandle);
if (ret != nullptr)
{
if (std::strlen(ret))
image = ret;
m_interface->free_string(m_interface->kodiBase, ret);
}
return image;
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief To set icon image of entry
///
/// @param image The image to use for.
///
/// @note Alternative can be \ref SetArt used
///
///
void SetIconImage(const std::string& image)
{
m_interface->kodi_gui->listItem->set_icon_image(m_interface->kodiBase, m_controlHandle, image.c_str());
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Sets the listitem's art
///
/// @param[in] type Type of Art to set
/// - Some default art values (any string possible):
/// | value (type) | Type |
/// |:-------------:|:--------------------------------------------------|
/// | thumb | string - image filename
/// | poster | string - image filename
/// | banner | string - image filename
/// | fanart | string - image filename
/// | clearart | string - image filename
/// | clearlogo | string - image filename
/// | landscape | string - image filename
/// | icon | string - image filename
/// @return The url to use for Art
///
std::string GetArt(const std::string& type)
{
std::string strReturn;
char* ret = m_interface->kodi_gui->listItem->get_art(m_interface->kodiBase, m_controlHandle, type.c_str());
if (ret != nullptr)
{
if (std::strlen(ret))
strReturn = ret;
m_interface->free_string(m_interface->kodiBase, ret);
}
return strReturn;
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Sets the listitem's art
///
/// @param[in] type Type of Art to set
/// @param[in] url The url to use for Art
/// - Some default art values (any string possible):
/// | value (type) | Type |
/// |:-------------:|:--------------------------------------------------|
/// | thumb | string - image filename
/// | poster | string - image filename
/// | banner | string - image filename
/// | fanart | string - image filename
/// | clearart | string - image filename
/// | clearlogo | string - image filename
/// | landscape | string - image filename
/// | icon | string - image filename
///
void SetArt(const std::string& type, const std::string& url)
{
m_interface->kodi_gui->listItem->set_art(m_interface->kodiBase, m_controlHandle, type.c_str(), url.c_str());
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Returns the path / filename of this listitem.
///
/// @return Path string
///
std::string GetPath()
{
std::string strReturn;
char* ret = m_interface->kodi_gui->listItem->get_path(m_interface->kodiBase, m_controlHandle);
if (ret != nullptr)
{
if (std::strlen(ret))
strReturn = ret;
m_interface->free_string(m_interface->kodiBase, ret);
}
return strReturn;
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Sets the listitem's path.
///
/// @param[in] path string or unicode - path, activated when
/// item is clicked.
///
/// @note You can use the above as keywords for arguments.
///
void SetPath(const std::string& path)
{
m_interface->kodi_gui->listItem->set_path(m_interface->kodiBase, m_controlHandle, path.c_str());
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Sets a listitem property, similar to an infolabel.
///
/// @param[in] key string - property name.
/// @param[in] value string or unicode - value of property.
///
/// @note Key is NOT case sensitive.
/// You can use the above as keywords for arguments and skip certain\n
/// optional arguments.\n
/// Once you use a keyword, all following arguments require the
/// keyword.
///
/// Some of these are treated internally by Kodi, such as the
/// <b>'StartOffset'</b> property, which is the offset in seconds at which to
/// start playback of an item. Others may be used in the skin to add
/// extra information, such as <b>'WatchedCount'</b> for tvshow items
///
void SetProperty(const std::string& key, const std::string& value)
{
m_interface->kodi_gui->listItem->set_property(m_interface->kodiBase, m_controlHandle, key.c_str(), value.c_str());
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Returns a listitem property as a string, similar to an infolabel.
///
/// @param[in] key string - property name.
/// @return string - List item property
///
/// @note Key is NOT case sensitive.\n
/// You can use the above as keywords for arguments and skip certain
/// optional arguments.\n
/// Once you use a keyword, all following arguments require the
/// keyword.
///
std::string GetProperty(const std::string& key)
{
std::string label;
char* ret = m_interface->kodi_gui->listItem->get_property(m_interface->kodiBase, m_controlHandle, key.c_str());
if (ret != nullptr)
{
if (std::strlen(ret))
label = ret;
m_interface->free_string(m_interface->kodiBase, ret);
}
return label;
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief To control selection of item in list (also multiple selection,
/// in list on serveral items possible).
///
/// @param[in] selected if true becomes set as selected
///
void Select(bool selected)
{
m_interface->kodi_gui->listItem->select(m_interface->kodiBase, m_controlHandle, selected);
}
//--------------------------------------------------------------------------
//==========================================================================
///
/// \ingroup cpp_kodi_gui_CListItem
/// @brief Returns the listitem's selected status.
///
/// @return true if selected, otherwise false
///
bool IsSelected()
{
return m_interface->kodi_gui->listItem->is_selected(m_interface->kodiBase, m_controlHandle);
}
//--------------------------------------------------------------------------
};
} /* namespace gui */
} /* namespace kodi */
|