xbmc
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(...);
793 #else
794  void setInfo(const char* type, const InfoLabelDict& infoLabels);
795 #endif
796 
797 #ifdef DOXYGEN_SHOULD_USE_THIS
798  setCast(...);
827 #else
828  void setCast(const std::vector<Properties>& actors);
829 #endif
830 
831 #ifdef DOXYGEN_SHOULD_USE_THIS
832  setAvailableFanart(...);
859 #else
860  void setAvailableFanart(const std::vector<Properties>& images);
861 #endif
862 
863 #ifdef DOXYGEN_SHOULD_USE_THIS
864  addAvailableArtwork(...);
892 #else
893  void addAvailableArtwork(const std::string& url,
894  const std::string& art_type = "",
895  const std::string& preview = "",
896  const std::string& referrer = "",
897  const std::string& cache = "",
898  bool post = false,
899  bool isgz = false,
900  int season = -1);
901 #endif
902 
903 #ifdef DOXYGEN_SHOULD_USE_THIS
904  addStreamInfo(...);
946 #else
947  void addStreamInfo(const char* cType, const Properties& dictionary);
948 #endif
949 
950 #ifdef DOXYGEN_SHOULD_USE_THIS
951  addContextMenuItems(...);
975 #else
976  void addContextMenuItems(const std::vector<Tuple<String,String> >& items, bool replaceItems = false);
977 #endif
978 
979 #ifdef DOXYGEN_SHOULD_USE_THIS
980  setProperty(...);
1027 #else
1028  void setProperty(const char * key, const String& value);
1029 #endif
1030 
1031 #ifdef DOXYGEN_SHOULD_USE_THIS
1032  setProperties(...);
1051 #else
1052  void setProperties(const Properties& dictionary);
1053 #endif
1054 
1055 #ifdef DOXYGEN_SHOULD_USE_THIS
1056  getProperty(...);
1079 #else
1080  String getProperty(const char* key);
1081 #endif
1082 
1083 #ifdef DOXYGEN_SHOULD_USE_THIS
1084  setPath(...);
1104 #else
1105  void setPath(const String& path);
1106 #endif
1107 
1108 #ifdef DOXYGEN_SHOULD_USE_THIS
1109  setMimeType(...);
1120 #else
1121  void setMimeType(const String& mimetype);
1122 #endif
1123 
1124 #ifdef DOXYGEN_SHOULD_USE_THIS
1125  setContentLookup(...);
1139 #else
1140  void setContentLookup(bool enable);
1141 #endif
1142 
1143 #ifdef DOXYGEN_SHOULD_USE_THIS
1144  setSubtitles(...);
1165 #else
1166  void setSubtitles(const std::vector<String>& subtitleFiles);
1167 #endif
1168 
1169 #ifdef DOXYGEN_SHOULD_USE_THIS
1170  getPath();
1183 #else
1184  String getPath();
1185 #endif
1186 
1187 #ifdef DOXYGEN_SHOULD_USE_THIS
1188  getVideoInfoTag();
1200 #else
1201  xbmc::InfoTagVideo* getVideoInfoTag();
1202 #endif
1203 
1204 #ifdef DOXYGEN_SHOULD_USE_THIS
1205  getMusicInfoTag();
1217 #else
1218  xbmc::InfoTagMusic* getMusicInfoTag();
1219 #endif
1220 
1221 #ifdef DOXYGEN_SHOULD_USE_THIS
1222  getPictureInfoTag();
1234 #else
1235  xbmc::InfoTagPicture* getPictureInfoTag();
1236 #endif
1237 
1238 #ifdef DOXYGEN_SHOULD_USE_THIS
1239  getGameInfoTag();
1251 #else
1252  xbmc::InfoTagGame* getGameInfoTag();
1253 #endif
1254 
1255 private:
1256  std::vector<std::string> getStringArray(const InfoLabelValue& alt,
1257  const std::string& tag,
1258  std::string value,
1259  const std::string& separator);
1260  std::vector<std::string> getVideoStringArray(const InfoLabelValue& alt,
1261  const std::string& tag,
1262  std::string value = "");
1263  std::vector<std::string> getMusicStringArray(const InfoLabelValue& alt,
1264  const std::string& tag,
1265  std::string value = "");
1266 
1267  CVideoInfoTag* GetVideoInfoTag();
1268  const CVideoInfoTag* GetVideoInfoTag() const;
1269 
1270  MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag();
1271  const MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag() const;
1272 
1273  void setTitleRaw(std::string title);
1274  void setPathRaw(const std::string& path);
1275  void setCountRaw(int count);
1276  void setSizeRaw(int64_t size);
1277  void setDateTimeRaw(const std::string& dateTime);
1278  void setIsFolderRaw(bool isFolder);
1279  void setStartOffsetRaw(double startOffset);
1280  void setMimeTypeRaw(const std::string& mimetype);
1281  void setSpecialSortRaw(std::string specialSort);
1282  void setContentLookupRaw(bool enable);
1283  void addArtRaw(std::string type, const std::string& url);
1284  void addPropertyRaw(std::string type, const CVariant& value);
1285  void addSubtitlesRaw(const std::vector<std::string>& subtitles);
1286  };
1287 
1288 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1289  typedef std::vector<ListItem*> ListItemList;
1290 #endif
1291  }
1292 }
This class is a smart pointer for a Referenced class.
Definition: AddonClass.h:154
Definition: InfoTagGame.h:49
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:51
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