Kodi Development  20.0
for Binary and Script based Add-Ons
ListItem.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "../AddonBase.h"
12 #include "../c-api/gui/list_item.h"
13 
14 #ifdef __cplusplus
15 
16 #include <memory>
17 
18 namespace kodi
19 {
20 namespace gui
21 {
22 
23 class CWindow;
24 
25 class ATTRIBUTE_HIDDEN CAddonGUIControlBase
26 {
27 public:
28  KODI_GUI_LISTITEM_HANDLE GetControlHandle() const { return m_controlHandle; }
29 
30 protected:
32  : m_controlHandle(nullptr),
33  m_interface(::kodi::addon::CAddonBase::m_interface->toKodi),
34  m_Window(window)
35  {
36  }
37 
38  virtual ~CAddonGUIControlBase() = default;
39 
40  friend class CWindow;
41 
42  KODI_GUI_LISTITEM_HANDLE m_controlHandle;
43  AddonToKodiFuncTable_Addon* m_interface;
44  CAddonGUIControlBase* m_Window;
45 
46 private:
47  CAddonGUIControlBase() = delete;
49  CAddonGUIControlBase& operator=(const CAddonGUIControlBase&) = delete;
50 };
51 
52 class CListItem;
53 
54 //==============================================================================
64 class ATTRIBUTE_HIDDEN CListItem : public CAddonGUIControlBase
65 {
66 public:
67  //============================================================================
75  CListItem(const std::string& label = "",
76  const std::string& label2 = "",
77  const std::string& path = "")
78  : CAddonGUIControlBase(nullptr)
79  {
80  m_controlHandle = m_interface->kodi_gui->listItem->create(m_interface->kodiBase, label.c_str(),
81  label2.c_str(), path.c_str());
82  }
83 
84  /*
85  * Constructor used for parts given by list items from addon window
86  *
87  * Related to call of "std::shared_ptr<CListItem> kodi::gui::CWindow::GetListItem(int listPos)"
88  * Not needed for addon development itself
89  */
90  explicit CListItem(KODI_GUI_LISTITEM_HANDLE listItemHandle) : CAddonGUIControlBase(nullptr)
91  {
92  m_controlHandle = listItemHandle;
93  }
94 
95  //============================================================================
99  ~CListItem() override
100  {
101  m_interface->kodi_gui->listItem->destroy(m_interface->kodiBase, m_controlHandle);
102  }
103  //----------------------------------------------------------------------------
104 
105  //============================================================================
111  std::string GetLabel()
112  {
113  std::string label;
114  char* ret = m_interface->kodi_gui->listItem->get_label(m_interface->kodiBase, m_controlHandle);
115  if (ret != nullptr)
116  {
117  if (std::strlen(ret))
118  label = ret;
119  m_interface->free_string(m_interface->kodiBase, ret);
120  }
121  return label;
122  }
123  //----------------------------------------------------------------------------
124 
125  //============================================================================
131  void SetLabel(const std::string& label)
132  {
133  m_interface->kodi_gui->listItem->set_label(m_interface->kodiBase, m_controlHandle,
134  label.c_str());
135  }
136  //----------------------------------------------------------------------------
137 
138  //============================================================================
144  std::string GetLabel2()
145  {
146  std::string label;
147  char* ret = m_interface->kodi_gui->listItem->get_label2(m_interface->kodiBase, m_controlHandle);
148  if (ret != nullptr)
149  {
150  if (std::strlen(ret))
151  label = ret;
152  m_interface->free_string(m_interface->kodiBase, ret);
153  }
154  return label;
155  }
156  //----------------------------------------------------------------------------
157 
158  //============================================================================
164  void SetLabel2(const std::string& label)
165  {
166  m_interface->kodi_gui->listItem->set_label2(m_interface->kodiBase, m_controlHandle,
167  label.c_str());
168  }
169  //----------------------------------------------------------------------------
170 
171  //============================================================================
189  std::string GetArt(const std::string& type)
190  {
191  std::string strReturn;
192  char* ret = m_interface->kodi_gui->listItem->get_art(m_interface->kodiBase, m_controlHandle,
193  type.c_str());
194  if (ret != nullptr)
195  {
196  if (std::strlen(ret))
197  strReturn = ret;
198  m_interface->free_string(m_interface->kodiBase, ret);
199  }
200  return strReturn;
201  }
202  //----------------------------------------------------------------------------
203 
204  //============================================================================
222  void SetArt(const std::string& type, const std::string& url)
223  {
224  m_interface->kodi_gui->listItem->set_art(m_interface->kodiBase, m_controlHandle, type.c_str(),
225  url.c_str());
226  }
227  //----------------------------------------------------------------------------
228 
229  //============================================================================
235  std::string GetPath()
236  {
237  std::string strReturn;
238  char* ret = m_interface->kodi_gui->listItem->get_path(m_interface->kodiBase, m_controlHandle);
239  if (ret != nullptr)
240  {
241  if (std::strlen(ret))
242  strReturn = ret;
243  m_interface->free_string(m_interface->kodiBase, ret);
244  }
245  return strReturn;
246  }
247  //----------------------------------------------------------------------------
248 
249  //============================================================================
257  void SetPath(const std::string& path)
258  {
259  m_interface->kodi_gui->listItem->set_path(m_interface->kodiBase, m_controlHandle, path.c_str());
260  }
261  //----------------------------------------------------------------------------
262 
263  //============================================================================
281  void SetProperty(const std::string& key, const std::string& value)
282  {
283  m_interface->kodi_gui->listItem->set_property(m_interface->kodiBase, m_controlHandle,
284  key.c_str(), value.c_str());
285  }
286  //----------------------------------------------------------------------------
287 
288  //============================================================================
301  std::string GetProperty(const std::string& key)
302  {
303  std::string label;
304  char* ret = m_interface->kodi_gui->listItem->get_property(m_interface->kodiBase,
305  m_controlHandle, key.c_str());
306  if (ret != nullptr)
307  {
308  if (std::strlen(ret))
309  label = ret;
310  m_interface->free_string(m_interface->kodiBase, ret);
311  }
312  return label;
313  }
314  //----------------------------------------------------------------------------
315 
316  //============================================================================
323  void Select(bool selected)
324  {
325  m_interface->kodi_gui->listItem->select(m_interface->kodiBase, m_controlHandle, selected);
326  }
327  //----------------------------------------------------------------------------
328 
329  //============================================================================
335  bool IsSelected()
336  {
337  return m_interface->kodi_gui->listItem->is_selected(m_interface->kodiBase, m_controlHandle);
338  }
339  //----------------------------------------------------------------------------
340 };
341 
342 } /* namespace gui */
343 } /* namespace kodi */
344 
345 #endif /* __cplusplus */
Definition: ListItem.h:26
Definition: ListItem.h:65
Definition: Window.h:110
std::string GetArt(const std::string &type)
Sets the listitem's art.
Definition: ListItem.h:189
void SetArt(const std::string &type, const std::string &url)
Sets the listitem's art.
Definition: ListItem.h:222
void SetPath(const std::string &path)
Sets the listitem's path.
Definition: ListItem.h:257
CListItem(const std::string &label="", const std::string &label2="", const std::string &path="")
Class constructor with parameters.
Definition: ListItem.h:75
void Select(bool selected)
To control selection of item in list (also multiple selection, in list on serveral items possible).
Definition: ListItem.h:323
void SetProperty(const std::string &key, const std::string &value)
Sets a listitem property, similar to an infolabel.
Definition: ListItem.h:281
bool IsSelected()
Returns the listitem's selected status.
Definition: ListItem.h:335
std::string GetPath()
Returns the path / filename of this listitem.
Definition: ListItem.h:235
~CListItem() override
Class destructor.
Definition: ListItem.h:99
void SetLabel(const std::string &label)
Sets the listitem label.
Definition: ListItem.h:131
std::string GetLabel2()
Returns the second listitem label.
Definition: ListItem.h:144
void SetLabel2(const std::string &label)
Sets the listitem's label2.
Definition: ListItem.h:164
std::string GetLabel()
Returns the listitem label.
Definition: ListItem.h:111
std::string GetProperty(const std::string &key)
Returns a listitem property as a string, similar to an infolabel.
Definition: ListItem.h:301
Definition: addon_base.h:216