kodi
GUIListItem.h
Go to the documentation of this file.
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 
16 #include <map>
17 #include <memory>
18 #include <string>
19 
20 // Forward
21 class CGUIListItemLayout;
22 class CArchive;
23 class CVariant;
24 
30 {
31 public:
32  typedef std::map<std::string, std::string> ArtMap;
33 
46  };
48 
49  CGUIListItem(void);
50  explicit CGUIListItem(const CGUIListItem& item);
51  explicit CGUIListItem(const std::string& strLabel);
52  virtual ~CGUIListItem(void);
53  virtual CGUIListItem* Clone() const { return new CGUIListItem(*this); }
54 
55  CGUIListItem& operator =(const CGUIListItem& item);
56 
57  virtual void SetLabel(const std::string& strLabel);
58  const std::string& GetLabel() const;
59 
60  void SetLabel2(const std::string& strLabel);
61  const std::string& GetLabel2() const;
62 
63  void SetOverlayImage(GUIIconOverlay icon);
64  std::string GetOverlayImage() const;
65 
70  void SetArt(const std::string &type, const std::string &url);
71 
76  void SetArt(const ArtMap &art);
77 
83  void AppendArt(const ArtMap &art, const std::string &prefix = "");
84 
90  void SetArtFallback(const std::string &from, const std::string &to);
91 
95  void ClearArt();
96 
101  std::string GetArt(const std::string &type) const;
102 
108  const ArtMap &GetArt() const;
109 
115  bool HasArt(const std::string &type) const;
116 
117  void SetSortLabel(const std::string &label);
118  void SetSortLabel(const std::wstring &label);
119  const std::wstring &GetSortLabel() const;
120 
121  void Select(bool bOnOff);
122  bool IsSelected() const;
123 
124  bool HasOverlay() const;
125  virtual bool IsFileItem() const { return false; }
126 
127  void SetLayout(std::unique_ptr<CGUIListItemLayout> layout);
128  CGUIListItemLayout *GetLayout();
129 
130  void SetFocusedLayout(std::unique_ptr<CGUIListItemLayout> layout);
131  CGUIListItemLayout *GetFocusedLayout();
132 
133  void FreeIcons();
134  void FreeMemory(bool immediately = false);
135  void SetInvalid();
136 
137  bool m_bIsFolder;
138 
139  void SetProperty(const std::string &strKey, const CVariant &value);
140 
141  void IncrementProperty(const std::string &strKey, int nVal);
142  void IncrementProperty(const std::string& strKey, int64_t nVal);
143  void IncrementProperty(const std::string &strKey, double dVal);
144 
145  void ClearProperties();
146 
152  void AppendProperties(const CGUIListItem &item);
153 
154  void Archive(CArchive& ar);
155  void Serialize(CVariant& value);
156 
157  bool HasProperty(const std::string &strKey) const;
158  bool HasProperties() const { return !m_mapProperties.empty(); }
159  void ClearProperty(const std::string &strKey);
160 
161  const CVariant &GetProperty(const std::string &strKey) const;
162 
168  void SetCurrentItem(unsigned int position);
169 
175  unsigned int GetCurrentItem() const;
176 
177 protected:
178  std::string m_strLabel2; // text of column2
179  GUIIconOverlay m_overlayIcon; // type of overlay icon
180 
181  std::unique_ptr<CGUIListItemLayout> m_layout;
182  std::unique_ptr<CGUIListItemLayout> m_focusedLayout;
183  bool m_bSelected; // item is selected or not
184  unsigned int m_currentItem; // current item number within container (starting at 1)
185 
186  struct icompare
187  {
188  bool operator()(const std::string &s1, const std::string &s2) const;
189  };
190 
191  typedef std::map<std::string, CVariant, icompare> PropertyMap;
192  PropertyMap m_mapProperties;
193 private:
194  std::wstring m_sortLabel; // text for sorting. Need to be UTF16 for proper sorting
195  std::string m_strLabel; // text of column1
196 
197  ArtMap m_art;
198  ArtMap m_artFallbacks;
199 };
200 
void AppendArt(const ArtMap &art, const std::string &prefix="")
append artwork to an item
Definition: GUIListItem.cpp:126
Value 0 - No overlay icon.
Definition: GUIListItem.h:39
Value 4 - For not watched files.
Definition: GUIListItem.h:43
Definition: GUIListItem.h:29
unsigned int GetCurrentItem() const
Get the current item number within it&#39;s container Retrieve the items position in a container...
Definition: GUIListItem.cpp:437
void ClearArt()
clear art on an item
Definition: GUIListItem.cpp:119
void SetCurrentItem(unsigned int position)
Set the current item number within it&#39;s container Our container classes will set this member with the...
Definition: GUIListItem.cpp:432
Value 1 - Compressed *.rar files.
Definition: GUIListItem.h:40
void SetArt(const std::string &type, const std::string &url)
Set a particular art type for an item.
Definition: GUIListItem.cpp:98
const ArtMap & GetArt() const
get artwork for an item Retrieves artwork in a type:url map
Definition: GUIListItem.cpp:147
Definition: GUIListItemLayout.h:20
Value 5 - For seen files.
Definition: GUIListItem.h:44
Definition: Variant.h:31
Value 6 - Is on hard disk stored.
Definition: GUIListItem.h:45
Definition: GUIListItem.h:186
bool m_bIsFolder
is item a folder or a file
Definition: GUIListItem.h:137
Value 2 - Compressed *.zip files.
Definition: GUIListItem.h:41
Definition: Archive.h:29
void AppendProperties(const CGUIListItem &item)
Append the properties of one CGUIListItem to another. Any existing properties in the current item wil...
Definition: GUIListItem.cpp:426
void SetArtFallback(const std::string &from, const std::string &to)
set a fallback image for art
Definition: GUIListItem.cpp:114
Value 3 - Locked files.
Definition: GUIListItem.h:42
bool HasArt(const std::string &type) const
Check whether an item has a particular piece of art Equivalent to !GetArt(type).empty() ...
Definition: GUIListItem.cpp:152
GUIIconOverlay
Definition: GUIListItem.h:39