Chatterino
HighlightController.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common/Singleton.hpp"
7 #include "singletons/Paths.hpp"
9 
10 #include <QColor>
11 #include <QUrl>
12 #include <boost/optional.hpp>
13 
14 #include <functional>
15 #include <memory>
16 #include <utility>
17 
18 namespace chatterino {
19 
21  HighlightResult(bool _alert, bool _playSound,
22  boost::optional<QUrl> _customSoundUrl,
23  std::shared_ptr<QColor> _color, bool _showInMentions)
24  : alert(_alert)
25  , playSound(_playSound)
26  , customSoundUrl(std::move(_customSoundUrl))
27  , color(std::move(_color))
28  , showInMentions(_showInMentions)
29  {
30  }
31 
36  {
37  return {
38  false, false, boost::none, nullptr, false,
39  };
40  }
41 
45  bool alert{false};
46 
50  bool playSound{false};
51 
57  boost::optional<QUrl> customSoundUrl{};
58 
62  std::shared_ptr<QColor> color{};
63 
67  bool showInMentions{false};
68 
69  bool operator==(const HighlightResult &other) const
70  {
71  if (this->alert != other.alert)
72  {
73  return false;
74  }
75  if (this->playSound != other.playSound)
76  {
77  return false;
78  }
79  if (this->customSoundUrl != other.customSoundUrl)
80  {
81  return false;
82  }
83 
84  if (this->color && other.color)
85  {
86  if (*this->color != *other.color)
87  {
88  return false;
89  }
90  }
91 
92  if (this->showInMentions != other.showInMentions)
93  {
94  return false;
95  }
96 
97  return true;
98  }
99 
100  bool operator!=(const HighlightResult &other) const
101  {
102  return !(*this == other);
103  }
104 
108  [[nodiscard]] bool empty() const
109  {
110  return !this->alert && !this->playSound &&
111  !this->customSoundUrl.has_value() && !this->color &&
112  !this->showInMentions;
113  }
114 
118  [[nodiscard]] bool full() const
119  {
120  return this->alert && this->playSound &&
121  this->customSoundUrl.has_value() && this->color &&
122  this->showInMentions;
123  }
124 
125  friend std::ostream &operator<<(std::ostream &os,
126  const HighlightResult &result)
127  {
128  os << "Alert: " << (result.alert ? "Yes" : "No") << ", "
129  << "Play sound: " << (result.playSound ? "Yes" : "No") << " ("
130  << (result.customSoundUrl
131  ? result.customSoundUrl.get().toString().toStdString()
132  : "")
133  << ")"
134  << ", "
135  << "Color: "
136  << (result.color ? result.color->name().toStdString() : "") << ", "
137  << "Show in mentions: " << (result.showInMentions ? "Yes" : "No");
138  return os;
139  }
140 };
141 
143  using Checker = std::function<boost::optional<HighlightResult>(
144  const MessageParseArgs &args, const std::vector<Badge> &badges,
145  const QString &senderName, const QString &originalMessage,
146  const MessageFlags &messageFlags, bool self)>;
148 };
149 
150 class HighlightController final : public Singleton
151 {
152 public:
153  void initialize(Settings &settings, Paths &paths) override;
154 
158  [[nodiscard]] std::pair<bool, HighlightResult> check(
159  const MessageParseArgs &args, const std::vector<Badge> &badges,
160  const QString &senderName, const QString &originalMessage,
161  const MessageFlags &messageFlags) const;
162 
163 private:
169  void rebuildChecks(Settings &settings);
170 
172 
173  pajlada::SettingListener rebuildListener_;
174  pajlada::Signals::SignalHolder signalHolder_;
175 };
176 
177 } // namespace chatterino
bool full() const
Returns true if all side-effects have been enabled.
Definition: HighlightController.hpp:118
static HighlightResult emptyResult()
Construct an empty HighlightResult with all side-effects disabled.
Definition: HighlightController.hpp:35
bool playSound
true if highlight should play a notification sound
Definition: HighlightController.hpp:50
bool empty() const
Returns true if no side-effect has been enabled.
Definition: HighlightController.hpp:108
Definition: Singleton.hpp:10
bool showInMentions
true if highlight should show message in the /mentions split
Definition: HighlightController.hpp:67
Definition: SeventvEventAPISubscription.hpp:67
HighlightResult(bool _alert, bool _playSound, boost::optional< QUrl > _customSoundUrl, std::shared_ptr< QColor > _color, bool _showInMentions)
Definition: HighlightController.hpp:21
Definition: Application.cpp:48
Definition: HighlightController.hpp:142
Definition: HighlightController.hpp:150
std::function< boost::optional< HighlightResult >(const MessageParseArgs &args, const std::vector< Badge > &badges, const QString &senderName, const QString &originalMessage, const MessageFlags &messageFlags, bool self)> Checker
Definition: HighlightController.hpp:146
friend std::ostream & operator<<(std::ostream &os, const HighlightResult &result)
Definition: HighlightController.hpp:125
Definition: UniqueAccess.hpp:53
bool operator!=(const HighlightResult &other) const
Definition: HighlightController.hpp:100
bool operator==(const HighlightResult &other) const
Definition: HighlightController.hpp:69
bool alert
true if highlight should trigger the taskbar to flash
Definition: HighlightController.hpp:45
Settings which are availlable for reading and writing on the gui thread.
Definition: Settings.hpp:78
int64_t FlagsEnum< MessageFlag > MessageFlags
Definition: Channel.hpp:20
std::shared_ptr< QColor > color
set if highlight should set a background color
Definition: HighlightController.hpp:62
Definition: Paths.hpp:8
Checker cb
Definition: HighlightController.hpp:147
Definition: HighlightController.hpp:20
Definition: MessageBuilder.hpp:43
boost::optional< QUrl > customSoundUrl
Can be set to a different sound that should play when this highlight is activated.
Definition: HighlightController.hpp:57