xbmc
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 using CGUIListItemLayoutPtr = std::unique_ptr<CGUIListItemLayout>;
23 class CArchive;
24 class CVariant;
25 
31 {
32 public:
33  typedef std::map<std::string, std::string> ArtMap;
34 
47  };
49 
50  CGUIListItem(void);
51  explicit CGUIListItem(const CGUIListItem& item);
52  explicit CGUIListItem(const std::string& strLabel);
53  virtual ~CGUIListItem(void);
54  virtual CGUIListItem* Clone() const { return new CGUIListItem(*this); }
55 
56  CGUIListItem& operator =(const CGUIListItem& item);
57 
58  virtual void SetLabel(const std::string& strLabel);
59  const std::string& GetLabel() const;
60 
61  void SetLabel2(const std::string& strLabel);
62  const std::string& GetLabel2() const;
63 
64  void SetOverlayImage(GUIIconOverlay icon, bool bOnOff=false);
65  std::string GetOverlayImage() const;
66 
71  void SetArt(const std::string &type, const std::string &url);
72 
77  void SetArt(const ArtMap &art);
78 
84  void AppendArt(const ArtMap &art, const std::string &prefix = "");
85 
91  void SetArtFallback(const std::string &from, const std::string &to);
92 
96  void ClearArt();
97 
102  std::string GetArt(const std::string &type) const;
103 
109  const ArtMap &GetArt() const;
110 
116  bool HasArt(const std::string &type) const;
117 
118  void SetSortLabel(const std::string &label);
119  void SetSortLabel(const std::wstring &label);
120  const std::wstring &GetSortLabel() const;
121 
122  void Select(bool bOnOff);
123  bool IsSelected() const;
124 
125  bool HasOverlay() const;
126  virtual bool IsFileItem() const { return false; }
127 
128  void SetLayout(CGUIListItemLayoutPtr layout);
129  CGUIListItemLayout *GetLayout();
130 
131  void SetFocusedLayout(CGUIListItemLayoutPtr layout);
132  CGUIListItemLayout *GetFocusedLayout();
133 
134  void FreeIcons();
135  void FreeMemory(bool immediately = false);
136  void SetInvalid();
137 
138  bool m_bIsFolder;
139 
140  void SetProperty(const std::string &strKey, const CVariant &value);
141 
142  void IncrementProperty(const std::string &strKey, int nVal);
143  void IncrementProperty(const std::string& strKey, int64_t nVal);
144  void IncrementProperty(const std::string &strKey, double dVal);
145 
146  void ClearProperties();
147 
153  void AppendProperties(const CGUIListItem &item);
154 
155  void Archive(CArchive& ar);
156  void Serialize(CVariant& value);
157 
158  bool HasProperty(const std::string &strKey) const;
159  bool HasProperties() const { return !m_mapProperties.empty(); }
160  void ClearProperty(const std::string &strKey);
161 
162  const CVariant &GetProperty(const std::string &strKey) const;
163 
169  void SetCurrentItem(unsigned int position);
170 
176  unsigned int GetCurrentItem() const;
177 
178 protected:
179  std::string m_strLabel2; // text of column2
180  GUIIconOverlay m_overlayIcon; // type of overlay icon
181 
182  CGUIListItemLayoutPtr m_layout;
183  CGUIListItemLayoutPtr m_focusedLayout;
184  bool m_bSelected; // item is selected or not
185  unsigned int m_currentItem; // current item number within container (starting at 1)
186 
187  struct icompare
188  {
189  bool operator()(const std::string &s1, const std::string &s2) const;
190  };
191 
192  typedef std::map<std::string, CVariant, icompare> PropertyMap;
193  PropertyMap m_mapProperties;
194 private:
195  std::wstring m_sortLabel; // text for sorting. Need to be UTF16 for proper sorting
196  std::string m_strLabel; // text of column1
197 
198  ArtMap m_art;
199  ArtMap m_artFallbacks;
200 };
201 
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:40
Value 4 - For not watched files.
Definition: GUIListItem.h:44
Definition: GUIListItem.h:30
unsigned int GetCurrentItem() const
Get the current item number within it&#39;s container Retrieve the items position in a container...
Definition: GUIListItem.cpp:438
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:433
Value 1 - Compressed *.rar files.
Definition: GUIListItem.h:41
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:45
Definition: Variant.h:29
Value 6 - Is on hard disk stored.
Definition: GUIListItem.h:46
Definition: GUIListItem.h:187
bool m_bIsFolder
is item a folder or a file
Definition: GUIListItem.h:138
Value 2 - Compressed *.zip files.
Definition: GUIListItem.h:42
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:427
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:43
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:40