Chatterino
HighlightBadge.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <QString>
8 #include <QUrl>
9 #include <pajlada/serialize.hpp>
10 
11 namespace chatterino {
13 {
14 public:
15  bool operator==(const HighlightBadge &other) const;
16 
17  HighlightBadge(const QString &badgeName, const QString &displayName,
18  bool showInMentions, bool hasAlert, bool hasSound,
19  const QString &soundUrl, QColor color);
20 
21  HighlightBadge(const QString &badgeName, const QString &displayName,
22  bool showInMentions, bool hasAlert, bool hasSound,
23  const QString &soundUrl, std::shared_ptr<QColor> color);
24 
25  const QString &badgeName() const;
26  const QString &displayName() const;
27  bool showInMentions() const;
28  bool hasAlert() const;
29  bool hasSound() const;
30  bool isMatch(const Badge &badge) const;
31 
41  bool hasCustomSound() const;
42 
43  const QUrl &getSoundUrl() const;
44  const std::shared_ptr<QColor> getColor() const;
45 
46  /*
47  * XXX: Use the constexpr constructor here once we are building with
48  * Qt>=5.13.
49  */
50  static QColor FALLBACK_HIGHLIGHT_COLOR;
51 
52 private:
53  bool compare(const QString &id, const Badge &badge) const;
54 
55  QString badgeName_;
56  QString displayName_;
57  bool showInMentions_;
58  bool hasAlert_;
59  bool hasSound_;
60  QUrl soundUrl_;
61  std::shared_ptr<QColor> color_;
62 
63  bool isMulti_;
64  bool hasVersions_;
65  QStringList badges_;
66 };
67 }; // namespace chatterino
68 
69 namespace pajlada {
70 
71 template <>
72 struct Serialize<chatterino::HighlightBadge> {
73  static rapidjson::Value get(const chatterino::HighlightBadge &value,
74  rapidjson::Document::AllocatorType &a)
75  {
76  rapidjson::Value ret(rapidjson::kObjectType);
77 
78  chatterino::rj::set(ret, "name", value.badgeName(), a);
79  chatterino::rj::set(ret, "displayName", value.displayName(), a);
80  chatterino::rj::set(ret, "showInMentions", value.showInMentions(), a);
81  chatterino::rj::set(ret, "alert", value.hasAlert(), a);
82  chatterino::rj::set(ret, "sound", value.hasSound(), a);
83  chatterino::rj::set(ret, "soundUrl", value.getSoundUrl().toString(), a);
84  chatterino::rj::set(ret, "color",
85  value.getColor()->name(QColor::HexArgb), a);
86 
87  return ret;
88  }
89 };
90 
91 template <>
92 struct Deserialize<chatterino::HighlightBadge> {
93  static chatterino::HighlightBadge get(const rapidjson::Value &value,
94  bool *error)
95  {
96  if (!value.IsObject())
97  {
98  PAJLADA_REPORT_ERROR(error);
99  return chatterino::HighlightBadge(QString(), QString(), false,
100  false, false, "", QColor());
101  }
102 
103  QString _name;
104  QString _displayName;
105  bool _showInMentions = false;
106  bool _hasAlert = true;
107  bool _hasSound = false;
108  QString _soundUrl;
109  QString encodedColor;
110 
111  chatterino::rj::getSafe(value, "name", _name);
112  chatterino::rj::getSafe(value, "displayName", _displayName);
113  chatterino::rj::getSafe(value, "showInMentions", _showInMentions);
114  chatterino::rj::getSafe(value, "alert", _hasAlert);
115  chatterino::rj::getSafe(value, "sound", _hasSound);
116  chatterino::rj::getSafe(value, "soundUrl", _soundUrl);
117  chatterino::rj::getSafe(value, "color", encodedColor);
118 
119  auto _color = QColor(encodedColor);
120  if (!_color.isValid())
122 
123  return chatterino::HighlightBadge(_name, _displayName, _showInMentions,
124  _hasAlert, _hasSound, _soundUrl,
125  _color);
126  }
127 };
128 
129 } // namespace pajlada
static QColor FALLBACK_HIGHLIGHT_COLOR
Definition: HighlightBadge.hpp:50
HighlightBadge(const QString &badgeName, const QString &displayName, bool showInMentions, bool hasAlert, bool hasSound, const QString &soundUrl, QColor color)
Definition: HighlightBadge.cpp:20
const QString & badgeName() const
Definition: HighlightBadge.cpp:51
Definition: HighlightBadge.hpp:12
bool showInMentions() const
Definition: HighlightBadge.cpp:61
Definition: Application.cpp:48
bool operator==(const HighlightBadge &other) const
Definition: HighlightBadge.cpp:10
const QString & displayName() const
Definition: HighlightBadge.cpp:56
void set(rapidjson::Value &obj, const char *key, const Type &value, rapidjson::Document::AllocatorType &a)
Definition: RapidjsonHelpers.hpp:22
Definition: Command.hpp:25
bool hasAlert() const
Definition: HighlightBadge.cpp:66
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
Definition: RapidjsonHelpers.hpp:73
const std::shared_ptr< QColor > getColor() const
Definition: HighlightBadge.cpp:117
Definition: TwitchBadge.hpp:9
bool hasSound() const
Definition: HighlightBadge.cpp:71
bool hasCustomSound() const
Check if this highlight phrase has a custom sound set.
Definition: HighlightBadge.cpp:107
const QUrl & getSoundUrl() const
Definition: HighlightBadge.cpp:112
bool isMatch(const Badge &badge) const
Definition: HighlightBadge.cpp:76