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 
95  typedef std::function<std::string(const std::string&)> StringReplacerFunc;
96 
105  static bool ReplaceSpecialKeywordReferences(const std::string &strInput, const std::string &strKeyword, const StringReplacerFunc &func, std::string &strOutput);
106 
114  static bool ReplaceSpecialKeywordReferences(std::string &work, const std::string &strKeyword, const StringReplacerFunc &func);
115 
116 private:
117  class CInfoPortion
118  {
119  public:
120  CInfoPortion(int info, const std::string &prefix, const std::string &postfix, bool escaped = false);
121  bool NeedsUpdate(const std::string &label) const;
122  std::string Get() const;
123  int m_info;
124  private:
125  bool m_escaped;
126  mutable std::string m_label;
127  std::string m_prefix;
128  std::string m_postfix;
129  };
130 
138  void Parse(const std::string& label, std::vector<CInfoPortion>& infoPortion, int context);
139 
144  const std::string& CacheLabel(bool rebuild) const;
145 
150  void RebuildLabel(std::string& label, const std::vector<CInfoPortion>& infoPortion) const;
151 
160  bool LabelNeedsUpdate(int context,
161  bool preferImages,
162  std::string* fallback,
163  const std::vector<CInfoPortion>& infoPortion) const;
172  bool ItemLabelNeedsUpdate(const CGUIListItem* item,
173  bool preferImages,
174  std::string* fallback,
175  const std::vector<CInfoPortion>& infoPortion) const;
176 
177  mutable bool m_dirty = false;
178  mutable std::string m_label;
179  mutable std::string m_fallback;
180  std::vector<CInfoPortion> m_infoLabel;
181  std::vector<CInfoPortion> m_infoFallback;
182 };
183 
184 } // namespace GUIINFO
185 } // namespace GUILIB
186 } // namespace KODI
187 
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:168
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:238
Controller configuration window.
Definition: AudioDecoder.h:18
int GetIntValue(int contextWindow) const
Gets the label and returns it as an int value.
Definition: GUIInfoLabel.cpp:27
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:111
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:65
static std::string ReplaceAddonStrings(std::string &&label)
Replaces instances of $ADDON[id number] with the appropriate localized addon string.
Definition: GUIInfoLabel.cpp:246