2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2020-02-23 22:15:13 +01:00
|
|
|
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
|
|
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
|
|
|
#include "controllers/ignores/IgnorePhrase.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Paths.hpp"
|
|
|
|
#include "singletons/Resources.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2020-02-23 22:15:13 +01:00
|
|
|
#include "util/PersistSignalVector.hpp"
|
2019-07-23 23:56:14 +02:00
|
|
|
#include "util/WindowsHelper.hpp"
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2020-02-23 22:15:13 +01:00
|
|
|
ConcurrentSettings *concurrentInstance_{};
|
|
|
|
|
|
|
|
ConcurrentSettings::ConcurrentSettings()
|
|
|
|
: highlightedMessages(*new SignalVector<HighlightPhrase>())
|
|
|
|
, highlightedUsers(*new SignalVector<HighlightPhrase>())
|
|
|
|
, blacklistedUsers(*new SignalVector<HighlightBlacklistUser>())
|
|
|
|
, ignoredMessages(*new SignalVector<IgnorePhrase>())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConcurrentSettings::isHighlightedUser(const QString &username)
|
|
|
|
{
|
|
|
|
for (const auto &highlightedUser : this->highlightedUsers)
|
|
|
|
{
|
|
|
|
if (highlightedUser.isMatch(username))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConcurrentSettings::isBlacklistedUser(const QString &username)
|
|
|
|
{
|
|
|
|
auto items = this->blacklistedUsers.readOnly();
|
|
|
|
|
|
|
|
for (const auto &blacklistedUser : *items)
|
|
|
|
{
|
|
|
|
if (blacklistedUser.isMatch(username))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConcurrentSettings &getCSettings()
|
|
|
|
{
|
|
|
|
// `concurrentInstance_` gets assigned in Settings ctor.
|
|
|
|
assert(concurrentInstance_);
|
|
|
|
|
|
|
|
return *concurrentInstance_;
|
|
|
|
}
|
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
Settings *Settings::instance_ = nullptr;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-11-25 15:02:48 +01:00
|
|
|
Settings::Settings(const QString &settingsDirectory)
|
|
|
|
: ABSettings(settingsDirectory)
|
2018-06-28 19:38:57 +02:00
|
|
|
{
|
2019-10-07 22:42:34 +02:00
|
|
|
instance_ = this;
|
2020-02-23 22:15:13 +01:00
|
|
|
concurrentInstance_ = this;
|
|
|
|
|
|
|
|
persist(this->highlightedMessages, "/highlighting/highlights");
|
|
|
|
persist(this->blacklistedUsers, "/highlighting/blacklist");
|
|
|
|
persist(this->highlightedUsers, "/highlighting/users");
|
|
|
|
persist(this->ignoredMessages, "/ignore/phrases");
|
2019-07-23 23:56:14 +02:00
|
|
|
|
|
|
|
#ifdef USEWINSDK
|
|
|
|
this->autorun = isRegisteredForStartup();
|
|
|
|
this->autorun.connect(
|
|
|
|
[](bool autorun) { setRegisteredForStartup(autorun); }, false);
|
|
|
|
#endif
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
Settings &Settings::instance()
|
2018-01-04 01:52:37 +01:00
|
|
|
{
|
2019-10-07 22:42:34 +02:00
|
|
|
return *instance_;
|
2018-01-04 01:52:37 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 19:51:07 +02:00
|
|
|
Settings *getSettings()
|
2018-01-17 14:14:31 +01:00
|
|
|
{
|
2019-10-07 22:42:34 +02:00
|
|
|
return &Settings::instance();
|
2018-01-17 14:14:31 +01:00
|
|
|
}
|
2018-01-23 21:33:49 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|