[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / GUIListItem.h
1 /*!
2 \file GUIListItem.h
3 \brief
4 */
5
6 #ifndef GUILIB_GUILISTITEM_H
7 #define GUILIB_GUILISTITEM_H
8
9 #pragma once
10
11 /*
12  *      Copyright (C) 2005-2013 Team XBMC
13  *      http://www.xbmc.org
14  *
15  *  This Program is free software; you can redistribute it and/or modify
16  *  it under the terms of the GNU General Public License as published by
17  *  the Free Software Foundation; either version 2, or (at your option)
18  *  any later version.
19  *
20  *  This Program is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with XBMC; see the file COPYING.  If not, see
27  *  <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 #include "utils/StdString.h"
32
33 #include <map>
34 #include <string>
35
36 //  Forward
37 class CGUIListItemLayout;
38 class CArchive;
39 class CVariant;
40
41 /*!
42  \ingroup controls
43  \brief
44  */
45 class CGUIListItem
46 {
47 public:
48   typedef std::map<std::string, std::string> ArtMap;
49
50   enum GUIIconOverlay { ICON_OVERLAY_NONE = 0,
51                         ICON_OVERLAY_RAR,
52                         ICON_OVERLAY_ZIP,
53                         ICON_OVERLAY_LOCKED,
54                         ICON_OVERLAY_HAS_TRAINER,
55                         ICON_OVERLAY_TRAINED,
56                         ICON_OVERLAY_UNWATCHED,
57                         ICON_OVERLAY_WATCHED,
58                         ICON_OVERLAY_HD};
59
60   CGUIListItem(void);
61   CGUIListItem(const CGUIListItem& item);
62   CGUIListItem(const CStdString& strLabel);
63   virtual ~CGUIListItem(void);
64   virtual CGUIListItem *Clone() const { return new CGUIListItem(*this); };
65
66   const CGUIListItem& operator =(const CGUIListItem& item);
67
68   virtual void SetLabel(const CStdString& strLabel);
69   const CStdString& GetLabel() const;
70
71   void SetLabel2(const CStdString& strLabel);
72   const CStdString& GetLabel2() const;
73
74   void SetIconImage(const CStdString& strIcon);
75   const CStdString& GetIconImage() const;
76
77   void SetOverlayImage(GUIIconOverlay icon, bool bOnOff=false);
78   CStdString GetOverlayImage() const;
79
80   /*! \brief Set a particular art type for an item
81    \param type type of art to set.
82    \param url the url of the art.
83    */
84   void SetArt(const std::string &type, const std::string &url);
85
86   /*! \brief set artwork for an item
87    \param art a type:url map for artwork
88    \sa GetArt
89    */
90   void SetArt(const ArtMap &art);
91
92   /*! \brief append artwork to an item
93    \param art a type:url map for artwork
94    \param prefix a prefix for the art, if applicable.
95    \sa GetArt
96    */
97   void AppendArt(const ArtMap &art, const std::string &prefix = "");
98
99   /*! \brief set a fallback image for art
100    \param from the type to fallback from
101    \param to the type to fallback to
102    \sa SetArt
103    */
104   void SetArtFallback(const std::string &from, const std::string &to);
105
106   /*! \brief clear art on an item
107    \sa SetArt
108    */
109   void ClearArt();
110
111   /*! \brief Get a particular art type for an item
112    \param type type of art to fetch.
113    \return the art URL, if available, else empty.
114    */
115   std::string GetArt(const std::string &type) const;
116
117   /*! \brief get artwork for an item
118    Retrieves artwork in a type:url map
119    \return a type:url map for artwork
120    \sa SetArt
121    */
122   const ArtMap &GetArt() const;
123
124   /*! \brief Check whether an item has a particular piece of art
125    Equivalent to !GetArt(type).empty()
126    \param type type of art to set.
127    \return true if the item has that art set, false otherwise.
128    */
129   bool HasArt(const std::string &type) const;
130
131   void SetSortLabel(const CStdString &label);
132   void SetSortLabel(const CStdStringW &label);
133   const CStdStringW &GetSortLabel() const;
134
135   void Select(bool bOnOff);
136   bool IsSelected() const;
137
138   bool HasIcon() const;
139   bool HasOverlay() const;
140   virtual bool IsFileItem() const { return false; };
141
142   void SetLayout(CGUIListItemLayout *layout);
143   CGUIListItemLayout *GetLayout();
144
145   void SetFocusedLayout(CGUIListItemLayout *layout);
146   CGUIListItemLayout *GetFocusedLayout();
147
148   void FreeIcons();
149   void FreeMemory(bool immediately = false);
150   void SetInvalid();
151
152   bool m_bIsFolder;     ///< is item a folder or a file
153
154   void SetProperty(const CStdString &strKey, const CVariant &value);
155
156   void IncrementProperty(const CStdString &strKey, int nVal);
157   void IncrementProperty(const CStdString &strKey, double dVal);
158
159   void ClearProperties();
160
161   /*! \brief Append the properties of one CGUIListItem to another.
162    Any existing properties in the current item will be overridden if they
163    are set in the passed in item.
164    \param item the item containing the properties to append.
165    */
166   void AppendProperties(const CGUIListItem &item);
167
168   void Archive(CArchive& ar);
169   void Serialize(CVariant& value);
170
171   bool       HasProperty(const CStdString &strKey) const;
172   bool       HasProperties() const { return m_mapProperties.size() > 0; };
173   void       ClearProperty(const CStdString &strKey);
174
175   CVariant   GetProperty(const CStdString &strKey) const;
176
177 protected:
178   CStdString m_strLabel2;     // text of column2
179   CStdString m_strIcon;      // filename of icon
180   GUIIconOverlay m_overlayIcon; // type of overlay icon
181
182   CGUIListItemLayout *m_layout;
183   CGUIListItemLayout *m_focusedLayout;
184   bool m_bSelected;     // item is selected or not
185
186   struct icompare
187   {
188     bool operator()(const CStdString &s1, const CStdString &s2) const
189     {
190       return s1.CompareNoCase(s2) < 0;
191     }
192   };
193
194   typedef std::map<CStdString, CVariant, icompare> PropertyMap;
195   PropertyMap m_mapProperties;
196 private:
197   CStdStringW m_sortLabel;    // text for sorting. Need to be UTF16 for proper sorting
198   CStdString m_strLabel;      // text of column1
199
200   ArtMap m_art;
201   ArtMap m_artFallbacks;
202 };
203 #endif
204