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 <utility>
26 #include <vector>
27 
28 
29 namespace XBMCAddon
30 {
31  namespace xbmcgui
32  {
33  XBMCCOMMONS_STANDARD_EXCEPTION(ListItemException);
34 
35  // This is a type that represents either a String or a String Tuple
36  typedef Alternative<StringOrInt,Tuple<String, StringOrInt> > InfoLabelStringOrTuple;
37 
38  // This type is either a String or a list of InfoLabelStringOrTuple types
39  typedef Alternative<StringOrInt, std::vector<InfoLabelStringOrTuple> > InfoLabelValue;
40 
41  // The type contains the dictionary values for the ListItem::setInfo call.
42  // The values in the dictionary can be either a String, or a list of items.
43  // If it's a list of items then the items can be either a String or a Tuple.
44  typedef Dictionary<InfoLabelValue> InfoLabelDict;
45 
46  //
52  class ListItem : public AddonClass
53  {
54  public:
55 #if !defined SWIG && !defined DOXYGEN_SHOULD_SKIP_THIS
56  CFileItemPtr item;
57  bool m_offscreen;
58 #endif
59 
60 #ifdef DOXYGEN_SHOULD_USE_THIS
61  ListItem([label, label2, path, offscreen]);
100 #else
101  ListItem(const String& label = emptyString,
102  const String& label2 = emptyString,
103  const String& path = emptyString,
104  bool offscreen = false);
105 #endif
106 
107 #if !defined SWIG && !defined DOXYGEN_SHOULD_SKIP_THIS
108  inline explicit ListItem(CFileItemPtr pitem) : item(std::move(pitem)), m_offscreen(false) {}
109 
110  static inline AddonClass::Ref<ListItem> fromString(const String& str)
111  {
113  ret->item.reset(new CFileItem(str));
114  return ret;
115  }
116 #endif
117 
118 #ifndef DOXYGEN_SHOULD_SKIP_THIS
119  ~ListItem() override;
120 #endif
121 
122 #ifdef DOXYGEN_SHOULD_USE_THIS
123  getLabel();
142 #else
143  String getLabel();
144 #endif
145 
146 #ifdef DOXYGEN_SHOULD_USE_THIS
147  getLabel2();
166 #else
167  String getLabel2();
168 #endif
169 
170 #ifdef DOXYGEN_SHOULD_USE_THIS
171  setLabel(...);
190 #else
191  void setLabel(const String& label);
192 #endif
193 
194 #ifdef DOXYGEN_SHOULD_USE_THIS
195  setLabel2(...);
214 #else
215  void setLabel2(const String& label);
216 #endif
217 
218 #ifdef DOXYGEN_SHOULD_USE_THIS
219  getDateTime();
239 #else
240  String getDateTime();
241 #endif
242 
243 #ifdef DOXYGEN_SHOULD_USE_THIS
244  setDateTime(...);
274 #else
275  void setDateTime(const String& dateTime);
276 #endif
277 
278 #ifdef DOXYGEN_SHOULD_USE_THIS
279  setArt(...);
312 #else
313  void setArt(const Properties& dictionary);
314 #endif
315 
316 #ifdef DOXYGEN_SHOULD_USE_THIS
317  setIsFolder(...);
338 #else
339  void setIsFolder(bool isFolder);
340 #endif
341 
342 #ifdef DOXYGEN_SHOULD_USE_THIS
343  setUniqueIDs(...);
373 #else
374  void setUniqueIDs(const Properties& dictionary, const String& defaultrating = "");
375 #endif
376 
377 #ifdef DOXYGEN_SHOULD_USE_THIS
378  setRating(...);
409 #else
410  void setRating(const std::string& type, float rating, int votes = 0, bool defaultt = false);
411 #endif
412 
413 #ifdef DOXYGEN_SHOULD_USE_THIS
414  addSeason(...);
437 #else
438  void addSeason(int number, std::string name = "");
439 #endif
440 
441 #ifdef DOXYGEN_SHOULD_USE_THIS
442  getArt(key);
472 #else
473  String getArt(const char* key);
474 #endif
475 
476 #ifdef DOXYGEN_SHOULD_USE_THIS
477  isFolder();
493 #else
494  bool isFolder() const;
495 #endif
496 
497 #ifdef DOXYGEN_SHOULD_USE_THIS
498  getUniqueID(key);
525 #else
526  String getUniqueID(const char* key);
527 #endif
528 
529 #ifdef DOXYGEN_SHOULD_USE_THIS
530  getRating(key);
557 #else
558  float getRating(const char* key);
559 #endif
560 
561 #ifdef DOXYGEN_SHOULD_USE_THIS
562  getVotes(key);
589 #else
590  int getVotes(const char* key);
591 #endif
592 
593 #ifdef DOXYGEN_SHOULD_USE_THIS
594  select(...);
614 #else
615  void select(bool selected);
616 #endif
617 
618 #ifdef DOXYGEN_SHOULD_USE_THIS
619  isSelected();
639 #else
640  bool isSelected();
641 #endif
642 
643 #ifdef DOXYGEN_SHOULD_USE_THIS
644  setInfo(...);
792 #else
793  void setInfo(const char* type, const InfoLabelDict& infoLabels);
794 #endif
795 
796 #ifdef DOXYGEN_SHOULD_USE_THIS
797  setCast(...);
826 #else
827  void setCast(const std::vector<Properties>& actors);
828 #endif
829 
830 #ifdef DOXYGEN_SHOULD_USE_THIS
831  setAvailableFanart(...);
858 #else
859  void setAvailableFanart(const std::vector<Properties>& images);
860 #endif
861 
862 #ifdef DOXYGEN_SHOULD_USE_THIS
863  addAvailableArtwork(...);
891 #else
892  void addAvailableArtwork(const std::string& url,
893  const std::string& art_type = "",
894  const std::string& preview = "",
895  const std::string& referrer = "",
896  const std::string& cache = "",
897  bool post = false,
898  bool isgz = false,
899  int season = -1);
900 #endif
901 
902 #ifdef DOXYGEN_SHOULD_USE_THIS
903  addStreamInfo(...);
945 #else
946  void addStreamInfo(const char* cType, const Properties& dictionary);
947 #endif
948 
949 #ifdef DOXYGEN_SHOULD_USE_THIS
950  addContextMenuItems(...);
974 #else
975  void addContextMenuItems(const std::vector<Tuple<String,String> >& items, bool replaceItems = false);
976 #endif
977 
978 #ifdef DOXYGEN_SHOULD_USE_THIS
979  setProperty(...);
1026 #else
1027  void setProperty(const char * key, const String& value);
1028 #endif
1029 
1030 #ifdef DOXYGEN_SHOULD_USE_THIS
1031  setProperties(...);
1050 #else
1051  void setProperties(const Properties& dictionary);
1052 #endif
1053 
1054 #ifdef DOXYGEN_SHOULD_USE_THIS
1055  getProperty(...);
1078 #else
1079  String getProperty(const char* key);
1080 #endif
1081 
1082 #ifdef DOXYGEN_SHOULD_USE_THIS
1083  setPath(...);
1103 #else
1104  void setPath(const String& path);
1105 #endif
1106 
1107 #ifdef DOXYGEN_SHOULD_USE_THIS
1108  setMimeType(...);
1119 #else
1120  void setMimeType(const String& mimetype);
1121 #endif
1122 
1123 #ifdef DOXYGEN_SHOULD_USE_THIS
1124  setContentLookup(...);
1138 #else
1139  void setContentLookup(bool enable);
1140 #endif
1141 
1142 #ifdef DOXYGEN_SHOULD_USE_THIS
1143  setSubtitles(...);
1164 #else
1165  void setSubtitles(const std::vector<String>& subtitleFiles);
1166 #endif
1167 
1168 #ifdef DOXYGEN_SHOULD_USE_THIS
1169  getPath();
1182 #else
1183  String getPath();
1184 #endif
1185 
1186 #ifdef DOXYGEN_SHOULD_USE_THIS
1187  getVideoInfoTag();
1199 #else
1200  xbmc::InfoTagVideo* getVideoInfoTag();
1201 #endif
1202 
1203 #ifdef DOXYGEN_SHOULD_USE_THIS
1204  getMusicInfoTag();
1216 #else
1217  xbmc::InfoTagMusic* getMusicInfoTag();
1218 #endif
1219 
1220 #ifdef DOXYGEN_SHOULD_USE_THIS
1221  getPictureInfoTag();
1233 #else
1234  xbmc::InfoTagPicture* getPictureInfoTag();
1235 #endif
1236 
1237 #ifdef DOXYGEN_SHOULD_USE_THIS
1238  getGameInfoTag();
1250 #else
1251  xbmc::InfoTagGame* getGameInfoTag();
1252 #endif
1253 
1254 private:
1255  std::vector<std::string> getStringArray(const InfoLabelValue& alt,
1256  const std::string& tag,
1257  std::string value,
1258  const std::string& separator);
1259  std::vector<std::string> getVideoStringArray(const InfoLabelValue& alt,
1260  const std::string& tag,
1261  std::string value = "");
1262  std::vector<std::string> getMusicStringArray(const InfoLabelValue& alt,
1263  const std::string& tag,
1264  std::string value = "");
1265 
1266  CVideoInfoTag* GetVideoInfoTag();
1267  const CVideoInfoTag* GetVideoInfoTag() const;
1268 
1269  MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag();
1270  const MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag() const;
1271 
1272  void setTitleRaw(std::string title);
1273  void setPathRaw(const std::string& path);
1274  void setCountRaw(int count);
1275  void setSizeRaw(int64_t size);
1276  void setDateTimeRaw(const std::string& dateTime);
1277  void setIsFolderRaw(bool isFolder);
1278  void setStartOffsetRaw(double startOffset);
1279  void setMimeTypeRaw(const std::string& mimetype);
1280  void setSpecialSortRaw(std::string specialSort);
1281  void setContentLookupRaw(bool enable);
1282  void addArtRaw(std::string type, const std::string& url);
1283  void addPropertyRaw(std::string type, const CVariant& value);
1284  void addSubtitlesRaw(const std::vector<std::string>& subtitles);
1285  };
1286 
1287 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1288  typedef std::vector<ListItem*> ListItemList;
1289 #endif
1290  }
1291 }
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:29
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:52
void setInfo(const char *type, const InfoLabelDict &infoLabels)
Definition: ListItem.cpp:373
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
Represents a file on a share.
Definition: FileItem.h:102
Definition: cache.py:1