kodi
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 "AddonClass.h"
12 #include "AddonString.h"
13 #include "Alternative.h"
14 #include "Dictionary.h"
15 #include "FileItem.h"
16 #include "InfoTagGame.h"
17 #include "InfoTagMusic.h"
18 #include "InfoTagPicture.h"
19 #include "InfoTagVideo.h"
20 #include "ListItem.h"
21 #include "Tuple.h"
22 #include "commons/Exception.h"
23 
24 #include <map>
25 #include <memory>
26 #include <utility>
27 #include <vector>
28 
29 
30 namespace XBMCAddon
31 {
32  namespace xbmcgui
33  {
34  XBMCCOMMONS_STANDARD_EXCEPTION(ListItemException);
35 
36  // This is a type that represents either a String or a String Tuple
37  typedef Alternative<StringOrInt,Tuple<String, StringOrInt> > InfoLabelStringOrTuple;
38 
39  // This type is either a String or a list of InfoLabelStringOrTuple types
40  typedef Alternative<StringOrInt, std::vector<InfoLabelStringOrTuple> > InfoLabelValue;
41 
42  // The type contains the dictionary values for the ListItem::setInfo call.
43  // The values in the dictionary can be either a String, or a list of items.
44  // If it's a list of items then the items can be either a String or a Tuple.
45  typedef Dictionary<InfoLabelValue> InfoLabelDict;
46 
47  //
53  class ListItem : public AddonClass
54  {
55  public:
56 #if !defined SWIG && !defined DOXYGEN_SHOULD_SKIP_THIS
57  CFileItemPtr item;
58  bool m_offscreen;
59 #endif
60 
61 #ifdef DOXYGEN_SHOULD_USE_THIS
62  ListItem([label, label2, path, offscreen]);
101 #else
102  ListItem(const String& label = emptyString,
103  const String& label2 = emptyString,
104  const String& path = emptyString,
105  bool offscreen = false);
106 #endif
107 
108 #if !defined SWIG && !defined DOXYGEN_SHOULD_SKIP_THIS
109  inline explicit ListItem(CFileItemPtr pitem) : item(std::move(pitem)), m_offscreen(false) {}
110 
111  static inline AddonClass::Ref<ListItem> fromString(const String& str)
112  {
114  ret->item = std::make_shared<CFileItem>(str);
115  return ret;
116  }
117 #endif
118 
119 #ifndef DOXYGEN_SHOULD_SKIP_THIS
120  ~ListItem() override;
121 #endif
122 
123 #ifdef DOXYGEN_SHOULD_USE_THIS
124  getLabel();
143 #else
144  String getLabel();
145 #endif
146 
147 #ifdef DOXYGEN_SHOULD_USE_THIS
148  getLabel2();
167 #else
168  String getLabel2();
169 #endif
170 
171 #ifdef DOXYGEN_SHOULD_USE_THIS
172  setLabel(...);
191 #else
192  void setLabel(const String& label);
193 #endif
194 
195 #ifdef DOXYGEN_SHOULD_USE_THIS
196  setLabel2(...);
215 #else
216  void setLabel2(const String& label);
217 #endif
218 
219 #ifdef DOXYGEN_SHOULD_USE_THIS
220  getDateTime();
240 #else
241  String getDateTime();
242 #endif
243 
244 #ifdef DOXYGEN_SHOULD_USE_THIS
245  setDateTime(...);
275 #else
276  void setDateTime(const String& dateTime);
277 #endif
278 
279 #ifdef DOXYGEN_SHOULD_USE_THIS
280  setArt(...);
313 #else
314  void setArt(const Properties& dictionary);
315 #endif
316 
317 #ifdef DOXYGEN_SHOULD_USE_THIS
318  setIsFolder(...);
339 #else
340  void setIsFolder(bool isFolder);
341 #endif
342 
343 #ifdef DOXYGEN_SHOULD_USE_THIS
344  setUniqueIDs(...);
374 #else
375  void setUniqueIDs(const Properties& dictionary, const String& defaultrating = "");
376 #endif
377 
378 #ifdef DOXYGEN_SHOULD_USE_THIS
379  setRating(...);
410 #else
411  void setRating(const std::string& type, float rating, int votes = 0, bool defaultt = false);
412 #endif
413 
414 #ifdef DOXYGEN_SHOULD_USE_THIS
415  addSeason(...);
438 #else
439  void addSeason(int number, std::string name = "");
440 #endif
441 
442 #ifdef DOXYGEN_SHOULD_USE_THIS
443  getArt(key);
473 #else
474  String getArt(const char* key);
475 #endif
476 
477 #ifdef DOXYGEN_SHOULD_USE_THIS
478  isFolder();
494 #else
495  bool isFolder() const;
496 #endif
497 
498 #ifdef DOXYGEN_SHOULD_USE_THIS
499  getUniqueID(key);
526 #else
527  String getUniqueID(const char* key);
528 #endif
529 
530 #ifdef DOXYGEN_SHOULD_USE_THIS
531  getRating(key);
558 #else
559  float getRating(const char* key);
560 #endif
561 
562 #ifdef DOXYGEN_SHOULD_USE_THIS
563  getVotes(key);
590 #else
591  int getVotes(const char* key);
592 #endif
593 
594 #ifdef DOXYGEN_SHOULD_USE_THIS
595  select(...);
615 #else
616  void select(bool selected);
617 #endif
618 
619 #ifdef DOXYGEN_SHOULD_USE_THIS
620  isSelected();
640 #else
641  bool isSelected();
642 #endif
643 
644 #ifdef DOXYGEN_SHOULD_USE_THIS
645  setInfo(...);
795 #else
796  void setInfo(const char* type, const InfoLabelDict& infoLabels);
797 #endif
798 
799 #ifdef DOXYGEN_SHOULD_USE_THIS
800  setCast(...);
829 #else
830  void setCast(const std::vector<Properties>& actors);
831 #endif
832 
833 #ifdef DOXYGEN_SHOULD_USE_THIS
834  setAvailableFanart(...);
861 #else
862  void setAvailableFanart(const std::vector<Properties>& images);
863 #endif
864 
865 #ifdef DOXYGEN_SHOULD_USE_THIS
866  addAvailableArtwork(...);
894 #else
895  void addAvailableArtwork(const std::string& url,
896  const std::string& art_type = "",
897  const std::string& preview = "",
898  const std::string& referrer = "",
899  const std::string& cache = "",
900  bool post = false,
901  bool isgz = false,
902  int season = -1);
903 #endif
904 
905 #ifdef DOXYGEN_SHOULD_USE_THIS
906  addStreamInfo(...);
948 #else
949  void addStreamInfo(const char* cType, const Properties& dictionary);
950 #endif
951 
952 #ifdef DOXYGEN_SHOULD_USE_THIS
953  addContextMenuItems(...);
977 #else
978  void addContextMenuItems(const std::vector<Tuple<String,String> >& items, bool replaceItems = false);
979 #endif
980 
981 #ifdef DOXYGEN_SHOULD_USE_THIS
982  setProperty(...);
1029 #else
1030  void setProperty(const char * key, const String& value);
1031 #endif
1032 
1033 #ifdef DOXYGEN_SHOULD_USE_THIS
1034  setProperties(...);
1053 #else
1054  void setProperties(const Properties& dictionary);
1055 #endif
1056 
1057 #ifdef DOXYGEN_SHOULD_USE_THIS
1058  getProperty(...);
1081 #else
1082  String getProperty(const char* key);
1083 #endif
1084 
1085 #ifdef DOXYGEN_SHOULD_USE_THIS
1086  setPath(...);
1106 #else
1107  void setPath(const String& path);
1108 #endif
1109 
1110 #ifdef DOXYGEN_SHOULD_USE_THIS
1111  setMimeType(...);
1122 #else
1123  void setMimeType(const String& mimetype);
1124 #endif
1125 
1126 #ifdef DOXYGEN_SHOULD_USE_THIS
1127  setContentLookup(...);
1141 #else
1142  void setContentLookup(bool enable);
1143 #endif
1144 
1145 #ifdef DOXYGEN_SHOULD_USE_THIS
1146  setSubtitles(...);
1167 #else
1168  void setSubtitles(const std::vector<String>& subtitleFiles);
1169 #endif
1170 
1171 #ifdef DOXYGEN_SHOULD_USE_THIS
1172  getPath();
1185 #else
1186  String getPath();
1187 #endif
1188 
1189 #ifdef DOXYGEN_SHOULD_USE_THIS
1190  getVideoInfoTag();
1202 #else
1203  xbmc::InfoTagVideo* getVideoInfoTag();
1204 #endif
1205 
1206 #ifdef DOXYGEN_SHOULD_USE_THIS
1207  getMusicInfoTag();
1219 #else
1220  xbmc::InfoTagMusic* getMusicInfoTag();
1221 #endif
1222 
1223 #ifdef DOXYGEN_SHOULD_USE_THIS
1224  getPictureInfoTag();
1236 #else
1237  xbmc::InfoTagPicture* getPictureInfoTag();
1238 #endif
1239 
1240 #ifdef DOXYGEN_SHOULD_USE_THIS
1241  getGameInfoTag();
1253 #else
1254  xbmc::InfoTagGame* getGameInfoTag();
1255 #endif
1256 
1257 private:
1258  std::vector<std::string> getStringArray(const InfoLabelValue& alt,
1259  const std::string& tag,
1260  std::string value,
1261  const std::string& separator);
1262  std::vector<std::string> getVideoStringArray(const InfoLabelValue& alt,
1263  const std::string& tag,
1264  std::string value = "");
1265  std::vector<std::string> getMusicStringArray(const InfoLabelValue& alt,
1266  const std::string& tag,
1267  std::string value = "");
1268 
1269  CVideoInfoTag* GetVideoInfoTag();
1270  const CVideoInfoTag* GetVideoInfoTag() const;
1271 
1272  MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag();
1273  const MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag() const;
1274 
1275  void setTitleRaw(std::string title);
1276  void setPathRaw(const std::string& path);
1277  void setCountRaw(int count);
1278  void setSizeRaw(int64_t size);
1279  void setDateTimeRaw(const std::string& dateTime);
1280  void setIsFolderRaw(bool isFolder);
1281  void setStartOffsetRaw(double startOffset);
1282  void setMimeTypeRaw(const std::string& mimetype);
1283  void setSpecialSortRaw(std::string specialSort);
1284  void setContentLookupRaw(bool enable);
1285  void addArtRaw(std::string type, const std::string& url);
1286  void addPropertyRaw(std::string type, const CVariant& value);
1287  void addSubtitlesRaw(const std::vector<std::string>& subtitles);
1288  };
1289 
1290 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1291  typedef std::vector<ListItem*> ListItemList;
1292 #endif
1293  }
1294 }
This class is a smart pointer for a Referenced class.
Definition: AddonClass.h:154
Definition: InfoTagGame.h:48
Definition: InfoTagPicture.h:43
Definition: Variant.h:31
Definition: InfoTagVideo.h:858
Defining LOG_LIFECYCLE_EVENTS will log all instantiations, deletions and also reference countings (in...
Definition: Addon.cpp:25
Definition: ListItem.h:53
void setInfo(const char *type, const InfoLabelDict &infoLabels)
Definition: ListItem.cpp:374
This class is the superclass for all reference counted classes in the api.
Definition: AddonClass.h:57
Definition: InfoTagMusic.h:47
Definition: VideoInfoTag.h:53
Definition: MusicInfoTag.h:27
Definition: Tuple.h:32
This is a bit of a hack for dynamically typed languages.
Definition: Dictionary.h:31
Definition: cache.py:1