mirror-chatterino2/src/singletons/Settings.cpp

88 lines
2.2 KiB
C++
Raw Normal View History

2018-06-28 19:46:45 +02:00
#include "singletons/Settings.hpp"
2018-06-26 14:09:39 +02:00
#include "Application.hpp"
#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"
#include "util/PersistSignalVector.hpp"
#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
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_;
}
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)
{
instance_ = this;
concurrentInstance_ = this;
persist(this->highlightedMessages, "/highlighting/highlights");
persist(this->blacklistedUsers, "/highlighting/blacklist");
persist(this->highlightedUsers, "/highlighting/users");
persist(this->ignoredMessages, "/ignore/phrases");
#ifdef USEWINSDK
this->autorun = isRegisteredForStartup();
this->autorun.connect(
[](bool autorun) { setRegisteredForStartup(autorun); }, false);
#endif
2017-04-12 17:46:44 +02:00
}
Settings &Settings::instance()
{
return *instance_;
}
2018-06-28 19:51:07 +02:00
Settings *getSettings()
2018-01-17 14:14:31 +01: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