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 "guilib/guiinfo/GUIInfoProviders.h" 12 #include "interfaces/info/InfoBool.h" 13 #include "interfaces/info/SkinVariable.h" 14 #include "messaging/IMessageTarget.h" 15 #include "threads/CriticalSection.h" 16 17 #include <map> 18 #include <memory> 19 #include <set> 20 #include <string> 21 #include <vector> 22 23 class CFileItem; 24 class CVideoInfoTag; 25 26 class CGUIListItem; 27 typedef std::shared_ptr<CGUIListItem> CGUIListItemPtr; 28 29 namespace KODI 30 { 31 namespace GUILIB 32 { 33 namespace GUIINFO 34 { 35 class CGUIInfo; 36 class IGUIInfoProvider; 37 } 38 } 39 } 40 namespace INFO 41 { 42 class InfoSingle; 43 } 44 namespace MUSIC_INFO 45 { 46 class CMusicInfoTag; 47 } 48 49 /*! 50 \ingroup strings 51 \brief 52 */ 53 class CGUIInfoManager : public KODI::MESSAGING::IMessageTarget 54 { 55 public: 56 CGUIInfoManager(void); 57 ~CGUIInfoManager(void) override; 58 59 void Initialize(); 60 61 void Clear(); 62 void ResetCache(); 63 64 // KODI::MESSAGING::IMessageTarget implementation 65 int GetMessageMask() override; 66 void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override; 67 68 /*! \brief Register a boolean condition/expression 69 This routine allows controls or other clients of the info manager to register 70 to receive updates of particular expressions, in a particular context (currently windows). 71 72 In the future, it will allow clients to receive pushed callbacks when the expression changes. 73 74 \param expression the boolean condition or expression 75 \param context the context window 76 \return an identifier used to reference this expression 77 */ 78 INFO::InfoPtr Register(const std::string &expression, int context = 0); 79 80 /// \brief iterates through boolean conditions and compares their stored values to current values. Returns true if any condition changed value. 81 bool ConditionsChangedValues(const std::map<INFO::InfoPtr, bool>& map); 82 83 /*! \brief Evaluate a boolean expression 84 \param expression the expression to evaluate 85 \param context the context in which to evaluate the expression (currently windows) 86 \return the value of the evaluated expression. 87 \sa Register 88 */ 89 bool EvaluateBool(const std::string &expression, int context = 0, const CGUIListItemPtr &item = nullptr); 90 91 int TranslateString(const std::string &strCondition); 92 int TranslateSingleString(const std::string &strCondition, bool &listItemDependent); 93 94 std::string GetLabel(int info, int contextWindow = 0, std::string *fallback = nullptr) const; 95 std::string GetImage(int info, int contextWindow, std::string *fallback = nullptr); 96 bool GetInt(int &value, int info, int contextWindow = 0, const CGUIListItem *item = nullptr) const; 97 bool GetBool(int condition, int contextWindow = 0, const CGUIListItem *item = nullptr); 98 99 std::string GetItemLabel(const CFileItem *item, int contextWindow, int info, std::string *fallback = nullptr) const; 100 std::string GetItemImage(const CGUIListItem *item, int contextWindow, int info, std::string *fallback = nullptr) const; 101 /*! \brief Get integer value of info. 102 \param value int reference to pass value of given info 103 \param info id of info 104 \param context the context in which to evaluate the expression (currently windows) 105 \param item optional listitem if want to get listitem related int 106 \return true if given info was handled 107 \sa GetItemInt, GetMultiInfoInt 108 */ 109 bool GetItemInt(int &value, const CGUIListItem *item, int contextWindow, int info) const; 110 bool GetItemBool(const CGUIListItem *item, int contextWindow, int condition) const; 111 112 /*! \brief Set currently playing file item 113 */ 114 void SetCurrentItem(const CFileItem &item); 115 void ResetCurrentItem(); 116 void UpdateCurrentItem(const CFileItem &item); 117 118 // Current song stuff 119 void SetCurrentAlbumThumb(const std::string &thumbFileName); 120 const MUSIC_INFO::CMusicInfoTag *GetCurrentSongTag() const; 121 122 // Current video stuff 123 const CVideoInfoTag* GetCurrentMovieTag() const; 124 125 void UpdateAVInfo(); 126 127 int RegisterSkinVariableString(const INFO::CSkinVariableString* info); 128 int TranslateSkinVariableString(const std::string& name, int context); 129 130 /*! \brief register a guiinfo provider 131 \param the guiinfo provider to register 132 */ 133 void RegisterInfoProvider(KODI::GUILIB::GUIINFO::IGUIInfoProvider *provider); 134 135 /*! \brief unregister a guiinfo provider 136 \param the guiinfo provider to unregister 137 */ 138 void UnregisterInfoProvider(KODI::GUILIB::GUIINFO::IGUIInfoProvider *provider); 139 140 /*! \brief get access to the registered guiinfo providers 141 \return the guiinfo providers 142 */ GetInfoProviders()143 KODI::GUILIB::GUIINFO::CGUIInfoProviders& GetInfoProviders() { return m_infoProviders; } 144 145 private: 146 /*! \brief class for holding information on properties 147 */ 148 class Property 149 { 150 public: 151 Property(const std::string &property, const std::string ¶meters); 152 153 const std::string ¶m(unsigned int n = 0) const; 154 unsigned int num_params() const; 155 156 std::string name; 157 private: 158 std::vector<std::string> params; 159 }; 160 161 /*! \brief Split an info string into it's constituent parts and parameters 162 Format is: 163 164 info1(params1).info2(params2).info3(params3) ... 165 166 where the parameters are an optional comma separated parameter list. 167 168 \param infoString the original string 169 \param info the resulting pairs of info and parameters. 170 */ 171 void SplitInfoString(const std::string &infoString, std::vector<Property> &info); 172 173 int TranslateSingleString(const std::string &strCondition); 174 int TranslateListItem(const Property& cat, const Property& prop, int id, bool container); 175 int TranslateMusicPlayerString(const std::string &info) const; 176 int TranslateVideoPlayerString(const std::string& info) const; 177 int TranslatePlayerString(const std::string& info) const; 178 static TIME_FORMAT TranslateTimeFormat(const std::string &format); 179 180 std::string GetMultiInfoLabel(const KODI::GUILIB::GUIINFO::CGUIInfo &info, int contextWindow, std::string *fallback = nullptr) const; 181 bool GetMultiInfoInt(int &value, const KODI::GUILIB::GUIINFO::CGUIInfo &info, int contextWindow, const CGUIListItem *item) const; 182 bool GetMultiInfoBool(const KODI::GUILIB::GUIINFO::CGUIInfo &info, int contextWindow, const CGUIListItem *item); 183 184 std::string GetMultiInfoItemLabel(const CFileItem *item, int contextWindow, const KODI::GUILIB::GUIINFO::CGUIInfo &info, std::string *fallback = nullptr) const; 185 std::string GetMultiInfoItemImage(const CFileItem *item, int contextWindow, const KODI::GUILIB::GUIINFO::CGUIInfo &info, std::string *fallback = nullptr) const; 186 187 std::string GetSkinVariableString(int info, bool preferImage = false, const CGUIListItem *item = nullptr) const; 188 189 int AddMultiInfo(const KODI::GUILIB::GUIINFO::CGUIInfo &info); 190 191 int ResolveMultiInfo(int info) const; 192 bool IsListItemInfo(int info) const; 193 194 void SetCurrentSongTag(const MUSIC_INFO::CMusicInfoTag &tag); 195 void SetCurrentVideoTag(const CVideoInfoTag &tag); 196 197 // Vector of multiple information mapped to a single integer lookup 198 std::vector<KODI::GUILIB::GUIINFO::CGUIInfo> m_multiInfo; 199 200 // Current playing stuff 201 CFileItem* m_currentFile; 202 203 typedef std::set<INFO::InfoPtr, bool(*)(const INFO::InfoPtr&, const INFO::InfoPtr&)> INFOBOOLTYPE; 204 INFOBOOLTYPE m_bools; 205 unsigned int m_refreshCounter = 0; 206 std::vector<INFO::CSkinVariableString> m_skinVariableStrings; 207 208 CCriticalSection m_critInfo; 209 210 KODI::GUILIB::GUIINFO::CGUIInfoProviders m_infoProviders; 211 }; 212