[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / guilib / GUIListItem.h
blob429a31af3bfe5f709ce650d901e90146df889dd5
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 /*!
12 \file GUIListItem.h
13 \brief
16 #include <map>
17 #include <memory>
18 #include <string>
20 // Forward
21 class CGUIListItemLayout;
22 class CArchive;
23 class CVariant;
25 /*!
26 \ingroup controls
27 \brief
29 class CGUIListItem
31 public:
32 typedef std::map<std::string, std::string> ArtMap;
34 ///
35 /// @ingroup controls python_xbmcgui_listitem
36 /// @defgroup kodi_guilib_listitem_iconoverlay Overlay icon types
37 /// @brief Overlay icon types used on list item.
38 /// @{
39 enum GUIIconOverlay { ICON_OVERLAY_NONE = 0, //!< Value **0** - No overlay icon
40 ICON_OVERLAY_RAR, //!< Value **1** - Compressed *.rar files
41 ICON_OVERLAY_ZIP, //!< Value **2** - Compressed *.zip files
42 ICON_OVERLAY_LOCKED, //!< Value **3** - Locked files
43 ICON_OVERLAY_UNWATCHED, //!< Value **4** - For not watched files
44 ICON_OVERLAY_WATCHED, //!< Value **5** - For seen files
45 ICON_OVERLAY_HD //!< Value **6** - Is on hard disk stored
47 /// @}
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); }
55 CGUIListItem& operator =(const CGUIListItem& item);
57 virtual void SetLabel(const std::string& strLabel);
58 const std::string& GetLabel() const;
60 void SetLabel2(const std::string& strLabel);
61 const std::string& GetLabel2() const;
63 void SetOverlayImage(GUIIconOverlay icon);
64 std::string GetOverlayImage() const;
66 /*! \brief Set a particular art type for an item
67 \param type type of art to set.
68 \param url the url of the art.
70 void SetArt(const std::string &type, const std::string &url);
72 /*! \brief set artwork for an item
73 \param art a type:url map for artwork
74 \sa GetArt
76 void SetArt(const ArtMap &art);
78 /*! \brief append artwork to an item
79 \param art a type:url map for artwork
80 \param prefix a prefix for the art, if applicable.
81 \sa GetArt
83 void AppendArt(const ArtMap &art, const std::string &prefix = "");
85 /*! \brief set a fallback image for art
86 \param from the type to fallback from
87 \param to the type to fallback to
88 \sa SetArt
90 void SetArtFallback(const std::string &from, const std::string &to);
92 /*! \brief clear art on an item
93 \sa SetArt
95 void ClearArt();
97 /*! \brief Get a particular art type for an item
98 \param type type of art to fetch.
99 \return the art URL, if available, else empty.
101 std::string GetArt(const std::string &type) const;
103 /*! \brief get artwork for an item
104 Retrieves artwork in a type:url map
105 \return a type:url map for artwork
106 \sa SetArt
108 const ArtMap &GetArt() const;
110 /*! \brief Check whether an item has a particular piece of art
111 Equivalent to !GetArt(type).empty()
112 \param type type of art to set.
113 \return true if the item has that art set, false otherwise.
115 bool HasArt(const std::string &type) const;
117 void SetSortLabel(const std::string &label);
118 void SetSortLabel(const std::wstring &label);
119 const std::wstring &GetSortLabel() const;
121 void Select(bool bOnOff);
122 bool IsSelected() const;
124 bool HasOverlay() const;
125 virtual bool IsFileItem() const { return false; }
127 void SetLayout(std::unique_ptr<CGUIListItemLayout> layout);
128 CGUIListItemLayout *GetLayout();
130 void SetFocusedLayout(std::unique_ptr<CGUIListItemLayout> layout);
131 CGUIListItemLayout *GetFocusedLayout();
133 void FreeIcons();
134 void FreeMemory(bool immediately = false);
135 void SetInvalid();
137 bool m_bIsFolder; ///< is item a folder or a file
139 void SetProperty(const std::string &strKey, const CVariant &value);
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);
145 void ClearProperties();
147 /*! \brief Append the properties of one CGUIListItem to another.
148 Any existing properties in the current item will be overridden if they
149 are set in the passed in item.
150 \param item the item containing the properties to append.
152 void AppendProperties(const CGUIListItem &item);
154 void Archive(CArchive& ar);
155 void Serialize(CVariant& value);
157 bool HasProperty(const std::string &strKey) const;
158 bool HasProperties() const { return !m_mapProperties.empty(); }
159 void ClearProperty(const std::string &strKey);
161 const CVariant &GetProperty(const std::string &strKey) const;
163 /*! \brief Set the current item number within it's container
164 Our container classes will set this member with the items position
165 in the container starting at 1.
166 \param position Position of the item in the container starting at 1.
168 void SetCurrentItem(unsigned int position);
170 /*! \brief Get the current item number within it's container
171 Retrieve the items position in a container, this is useful to show
172 for example numbering in front of entities in an arbitrary list of entities,
173 like songs of a playlist.
175 unsigned int GetCurrentItem() const;
177 protected:
178 std::string m_strLabel2; // text of column2
179 GUIIconOverlay m_overlayIcon; // type of overlay icon
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)
186 struct icompare
188 bool operator()(const std::string &s1, const std::string &s2) const;
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
197 ArtMap m_art;
198 ArtMap m_artFallbacks;