xbmc
GUIInfoLabel.h
Go to the documentation of this file.
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 
16 #include "interfaces/info/Info.h"
17 
18 #include <functional>
19 #include <string>
20 #include <vector>
21 
22 class CGUIListItem;
23 
24 namespace KODI
25 {
26 namespace GUILIB
27 {
28 namespace GUIINFO
29 {
30 
32 {
33 public:
34  CGUIInfoLabel() = default;
35  CGUIInfoLabel(const std::string& label,
36  const std::string& fallback = "",
37  int context = INFO::DEFAULT_CONTEXT);
38 
39  void SetLabel(const std::string& label,
40  const std::string& fallback,
41  int context = INFO::DEFAULT_CONTEXT);
42 
50  const std::string &GetLabel(int contextWindow, bool preferImage = false, std::string *fallback = NULL) const;
51 
58  int GetIntValue(int contextWindow) const;
59 
67  const std::string& GetItemLabel(const CGUIListItem* item,
68  bool preferImage = false,
69  std::string* fallback = nullptr) const;
70 
71  bool IsConstant() const;
72  bool IsEmpty() const;
73 
74  const std::string& GetFallback() const { return m_fallback; }
75 
76  static std::string GetLabel(const std::string& label,
77  int contextWindow,
78  bool preferImage = false);
79  static std::string GetItemLabel(const std::string &label, const CGUIListItem *item, bool preferImage = false);
80 
86  static std::string ReplaceLocalize(const std::string &label);
87 
93  static std::string ReplaceAddonStrings(std::string &&label);
94 
103  static std::string ReplaceControllerStrings(std::string&& label);
104 
105  typedef std::function<std::string(const std::string&)> StringReplacerFunc;
106 
115  static bool ReplaceSpecialKeywordReferences(const std::string &strInput, const std::string &strKeyword, const StringReplacerFunc &func, std::string &strOutput);
116 
124  static bool ReplaceSpecialKeywordReferences(std::string &work, const std::string &strKeyword, const StringReplacerFunc &func);
125 
126 private:
127  class CInfoPortion
128  {
129  public:
130  CInfoPortion(int info, const std::string &prefix, const std::string &postfix, bool escaped = false);
131  bool NeedsUpdate(const std::string &label) const;
132  std::string Get() const;
133  int m_info;
134  private:
135  bool m_escaped;
136  mutable std::string m_label;
137  std::string m_prefix;
138  std::string m_postfix;
139  };
140 
148  void Parse(const std::string& label, std::vector<CInfoPortion>& infoPortion, int context);
149 
154  const std::string& CacheLabel(bool rebuild) const;
155 
160  void RebuildLabel(std::string& label, const std::vector<CInfoPortion>& infoPortion) const;
161 
170  bool LabelNeedsUpdate(int context,
171  bool preferImages,
172  std::string* fallback,
173  const std::vector<CInfoPortion>& infoPortion) const;
182  bool ItemLabelNeedsUpdate(const CGUIListItem* item,
183  bool preferImages,
184  std::string* fallback,
185  const std::vector<CInfoPortion>& infoPortion) const;
186 
187  mutable bool m_dirty = false;
188  mutable std::string m_label;
189  mutable std::string m_fallback;
190  std::vector<CInfoPortion> m_infoLabel;
191  std::vector<CInfoPortion> m_infoFallback;
192 };
193 
194 } // namespace GUIINFO
195 } // namespace GUILIB
196 } // namespace KODI
197 
Definition: GUIListItem.h:30
static bool ReplaceSpecialKeywordReferences(const std::string &strInput, const std::string &strKeyword, const StringReplacerFunc &func, std::string &strOutput)
Replaces instances of $strKeyword[value] with the appropriate resolved string.
Definition: GUIInfoLabel.cpp:170
Definition: GUIInfoLabel.h:31
static std::string ReplaceLocalize(const std::string &label)
Replaces instances of $LOCALIZE[number] with the appropriate localized string.
Definition: GUIInfoLabel.cpp:250
Definition: AudioDecoder.h:18
int GetIntValue(int contextWindow) const
Gets the label and returns it as an int value.
Definition: GUIInfoLabel.cpp:29
const std::string & GetItemLabel(const CGUIListItem *item, bool preferImage=false, std::string *fallback=nullptr) const
Gets a label (or image) for a given listitem from the info manager.
Definition: GUIInfoLabel.cpp:113
const std::string & GetLabel(int contextWindow, bool preferImage=false, std::string *fallback=NULL) const
Gets a label (or image) for a given window context from the info manager.
Definition: GUIInfoLabel.cpp:67
static std::string ReplaceControllerStrings(std::string &&label)
Replaces instances of $FEATURE[feature name, controller ID] with the appropriate localized controller...
Definition: GUIInfoLabel.cpp:264
static std::string ReplaceAddonStrings(std::string &&label)
Replaces instances of $ADDON[id number] with the appropriate localized addon string.
Definition: GUIInfoLabel.cpp:258