Update to latest settings library version

This commit is contained in:
Rasmus Karlsson 2018-11-03 13:00:07 +01:00
parent 9ced50e94e
commit ac4a496a06
36 changed files with 373 additions and 374 deletions

3
.gitmodules vendored
View file

@ -24,3 +24,6 @@
path = lib/WinToast
url = https://github.com/mohabouje/WinToast.git
[submodule "lib/serialize"]
path = lib/serialize
url = https://github.com/pajlada/serialize.git

View file

@ -9,7 +9,7 @@ message(----)
QT += widgets core gui network multimedia svg concurrent
CONFIG += communi
COMMUNI += core model util
CONFIG += c++14
CONFIG += c++17
INCLUDEPATH += src/
TARGET = chatterino
TEMPLATE = app
@ -17,6 +17,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
PRECOMPILED_HEADER = src/PrecompiledHeader.hpp
CONFIG += precompile_header
QMAKE_CXXFLAGS += -std=c++17
debug {
DEFINES += QT_DEBUG
}
@ -43,6 +45,7 @@ macx {
# Submodules
include(dependencies/rapidjson.pri)
include(dependencies/serialize.pri)
include(dependencies/settings.pri)
include(dependencies/signals.pri)
include(dependencies/humanize.pri)

View file

@ -17,5 +17,5 @@ win32 {
LIBS += -L$$BOOST_DIRECTORY\\$$BOOST_LIB_SUFFIX
} else {
LIBS += -lboost_system
LIBS += -lboost_system -lboost_filesystem
}

2
dependencies/serialize.pri vendored Normal file
View file

@ -0,0 +1,2 @@
# serialize
INCLUDEPATH += $$PWD/../lib/serialize/include/

View file

@ -1,5 +1,5 @@
# settings
DEFINES += PAJLADA_SETTINGS_NO_BOOST
DEFINES += PAJLADA_SETTINGS_BOOST_FILESYSTEM
SOURCES += \
$$PWD/../lib/settings/src/settings/settingdata.cpp \

1
lib/serialize Submodule

@ -0,0 +1 @@
Subproject commit 8df89adc101e3208098e323f66caf3d04582281f

@ -1 +1 @@
Subproject commit bcbd29b793a2895ddf1772dca0105f51a0380798
Subproject commit f564560afc62de01c0b616d7d219cca5b7c06d97

@ -1 +1 @@
Subproject commit a1b61606c144c34a0f0f9173768cb85dd58e7f29
Subproject commit 0fde0171d61077e6e30e13fd67f91f72dae34122

View file

@ -138,7 +138,7 @@
# include <map>
# include <memory>
# include <mutex>
# include <pajlada/settings/serialize.hpp>
# include <pajlada/serialize.hpp>
# include <pajlada/settings/setting.hpp>
# include <pajlada/settings/settinglistener.hpp>
# include <pajlada/signals/connection.hpp>

View file

@ -4,7 +4,7 @@
namespace chatterino {
void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting)
void _registerSetting(std::weak_ptr<pajlada::Settings::SettingData> setting)
{
_actuallyRegisterSetting(setting);
}

View file

@ -5,7 +5,7 @@
namespace chatterino {
void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting);
void _registerSetting(std::weak_ptr<pajlada::Settings::SettingData> setting);
template <typename Type>
class ChatterinoSetting : public pajlada::Settings::Setting<Type>
@ -14,13 +14,13 @@ public:
ChatterinoSetting(const std::string &path)
: pajlada::Settings::Setting<Type>(path)
{
_registerSetting(this->data);
_registerSetting(this->getData());
}
ChatterinoSetting(const std::string &path, const Type &defaultValue)
: pajlada::Settings::Setting<Type>(path, defaultValue)
{
_registerSetting(this->data);
_registerSetting(this->getData());
}
template <typename T2>
@ -46,6 +46,7 @@ public:
using BoolSetting = ChatterinoSetting<bool>;
using FloatSetting = ChatterinoSetting<float>;
using DoubleSetting = ChatterinoSetting<double>;
using IntSetting = ChatterinoSetting<int>;
using StringSetting = ChatterinoSetting<std::string>;
using QStringSetting = ChatterinoSetting<QString>;

View file

@ -5,7 +5,7 @@
#include <QRegularExpression>
#include <QString>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
#include <memory>
@ -68,42 +68,38 @@ private:
} // namespace chatterino
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::HighlightBlacklistUser> {
static rapidjson::Value get(
const chatterino::HighlightBlacklistUser &value,
rapidjson::Document::AllocatorType &a)
template <>
struct Serialize<chatterino::HighlightBlacklistUser> {
static rapidjson::Value get(const chatterino::HighlightBlacklistUser &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
chatterino::rj::set(ret, "pattern", value.getPattern(), a);
chatterino::rj::set(ret, "regex", value.isRegex(), a);
return ret;
}
};
template <>
struct Deserialize<chatterino::HighlightBlacklistUser> {
static chatterino::HighlightBlacklistUser get(const rapidjson::Value &value)
{
QString pattern;
bool isRegex = false;
if (!value.IsObject())
{
rapidjson::Value ret(rapidjson::kObjectType);
AddMember(ret, "pattern", value.getPattern(), a);
AddMember(ret, "regex", value.isRegex(), a);
return ret;
}
};
template <>
struct Deserialize<chatterino::HighlightBlacklistUser> {
static chatterino::HighlightBlacklistUser get(
const rapidjson::Value &value)
{
QString pattern;
bool isRegex = false;
if (!value.IsObject())
{
return chatterino::HighlightBlacklistUser(pattern, isRegex);
}
chatterino::rj::getSafe(value, "pattern", pattern);
chatterino::rj::getSafe(value, "regex", isRegex);
return chatterino::HighlightBlacklistUser(pattern, isRegex);
}
};
} // namespace Settings
chatterino::rj::getSafe(value, "pattern", pattern);
chatterino::rj::getSafe(value, "regex", isRegex);
return chatterino::HighlightBlacklistUser(pattern, isRegex);
}
};
} // namespace pajlada

View file

@ -5,7 +5,7 @@
#include <QRegularExpression>
#include <QString>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
namespace chatterino {
@ -70,48 +70,44 @@ private:
} // namespace chatterino
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::HighlightPhrase> {
static rapidjson::Value get(const chatterino::HighlightPhrase &value,
rapidjson::Document::AllocatorType &a)
template <>
struct Serialize<chatterino::HighlightPhrase> {
static rapidjson::Value get(const chatterino::HighlightPhrase &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
chatterino::rj::set(ret, "pattern", value.getPattern(), a);
chatterino::rj::set(ret, "alert", value.getAlert(), a);
chatterino::rj::set(ret, "sound", value.getSound(), a);
chatterino::rj::set(ret, "regex", value.isRegex(), a);
return ret;
}
};
template <>
struct Deserialize<chatterino::HighlightPhrase> {
static chatterino::HighlightPhrase get(const rapidjson::Value &value)
{
if (!value.IsObject())
{
rapidjson::Value ret(rapidjson::kObjectType);
AddMember(ret, "pattern", value.getPattern(), a);
AddMember(ret, "alert", value.getAlert(), a);
AddMember(ret, "sound", value.getSound(), a);
AddMember(ret, "regex", value.isRegex(), a);
return ret;
return chatterino::HighlightPhrase(QString(), true, false, false);
}
};
template <>
struct Deserialize<chatterino::HighlightPhrase> {
static chatterino::HighlightPhrase get(const rapidjson::Value &value)
{
if (!value.IsObject())
{
return chatterino::HighlightPhrase(QString(), true, false,
false);
}
QString _pattern;
bool _alert = true;
bool _sound = false;
bool _isRegex = false;
QString _pattern;
bool _alert = true;
bool _sound = false;
bool _isRegex = false;
chatterino::rj::getSafe(value, "pattern", _pattern);
chatterino::rj::getSafe(value, "alert", _alert);
chatterino::rj::getSafe(value, "sound", _sound);
chatterino::rj::getSafe(value, "regex", _isRegex);
chatterino::rj::getSafe(value, "pattern", _pattern);
chatterino::rj::getSafe(value, "alert", _alert);
chatterino::rj::getSafe(value, "sound", _sound);
chatterino::rj::getSafe(value, "regex", _isRegex);
return chatterino::HighlightPhrase(_pattern, _alert, _sound, _isRegex);
}
};
return chatterino::HighlightPhrase(_pattern, _alert, _sound,
_isRegex);
}
};
} // namespace Settings
} // namespace pajlada

View file

@ -9,7 +9,7 @@
#include <QRegularExpression>
#include <QString>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
#include <memory>
@ -138,53 +138,51 @@ private:
} // namespace chatterino
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::IgnorePhrase> {
static rapidjson::Value get(const chatterino::IgnorePhrase &value,
rapidjson::Document::AllocatorType &a)
template <>
struct Serialize<chatterino::IgnorePhrase> {
static rapidjson::Value get(const chatterino::IgnorePhrase &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
chatterino::rj::set(ret, "pattern", value.getPattern(), a);
chatterino::rj::set(ret, "regex", value.isRegex(), a);
chatterino::rj::set(ret, "isBlock", value.isBlock(), a);
chatterino::rj::set(ret, "replaceWith", value.getReplace(), a);
chatterino::rj::set(ret, "caseSensitive", value.isCaseSensitive(), a);
return ret;
}
};
template <>
struct Deserialize<chatterino::IgnorePhrase> {
static chatterino::IgnorePhrase get(const rapidjson::Value &value)
{
if (!value.IsObject())
{
rapidjson::Value ret(rapidjson::kObjectType);
AddMember(ret, "pattern", value.getPattern(), a);
AddMember(ret, "regex", value.isRegex(), a);
AddMember(ret, "isBlock", value.isBlock(), a);
AddMember(ret, "replaceWith", value.getReplace(), a);
AddMember(ret, "caseSensitive", value.isCaseSensitive(), a);
return ret;
return chatterino::IgnorePhrase(
QString(), false, false,
::chatterino::getSettings()->ignoredPhraseReplace.getValue(),
true);
}
};
template <>
struct Deserialize<chatterino::IgnorePhrase> {
static chatterino::IgnorePhrase get(const rapidjson::Value &value)
{
if (!value.IsObject())
{
return chatterino::IgnorePhrase(
QString(), false, false,
::chatterino::getSettings()
->ignoredPhraseReplace.getValue(),
true);
}
QString _pattern;
bool _isRegex = false;
bool _isBlock = false;
QString _replace;
bool _caseSens = true;
QString _pattern;
bool _isRegex = false;
bool _isBlock = false;
QString _replace;
bool _caseSens = true;
chatterino::rj::getSafe(value, "pattern", _pattern);
chatterino::rj::getSafe(value, "regex", _isRegex);
chatterino::rj::getSafe(value, "isBlock", _isBlock);
chatterino::rj::getSafe(value, "replaceWith", _replace);
chatterino::rj::getSafe(value, "caseSensitive", _caseSens);
chatterino::rj::getSafe(value, "pattern", _pattern);
chatterino::rj::getSafe(value, "regex", _isRegex);
chatterino::rj::getSafe(value, "isBlock", _isBlock);
chatterino::rj::getSafe(value, "replaceWith", _replace);
chatterino::rj::getSafe(value, "caseSensitive", _caseSens);
return chatterino::IgnorePhrase(_pattern, _isRegex, _isBlock, _replace,
_caseSens);
}
};
return chatterino::IgnorePhrase(_pattern, _isRegex, _isBlock,
_replace, _caseSens);
}
};
} // namespace Settings
} // namespace pajlada

View file

@ -2,7 +2,7 @@
#include <QString>
#include <boost/optional.hpp>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
#include "util/RapidjsonHelpers.hpp"
@ -34,37 +34,35 @@ private:
} // namespace chatterino
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::ModerationAction> {
static rapidjson::Value get(const chatterino::ModerationAction &value,
rapidjson::Document::AllocatorType &a)
template <>
struct Serialize<chatterino::ModerationAction> {
static rapidjson::Value get(const chatterino::ModerationAction &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
chatterino::rj::set(ret, "pattern", value.getAction(), a);
return ret;
}
};
template <>
struct Deserialize<chatterino::ModerationAction> {
static chatterino::ModerationAction get(const rapidjson::Value &value)
{
if (!value.IsObject())
{
rapidjson::Value ret(rapidjson::kObjectType);
AddMember(ret, "pattern", value.getAction(), a);
return ret;
return chatterino::ModerationAction(QString());
}
};
template <>
struct Deserialize<chatterino::ModerationAction> {
static chatterino::ModerationAction get(const rapidjson::Value &value)
{
if (!value.IsObject())
{
return chatterino::ModerationAction(QString());
}
QString pattern;
QString pattern;
chatterino::rj::getSafe(value, "pattern", pattern);
chatterino::rj::getSafe(value, "pattern", pattern);
return chatterino::ModerationAction(pattern);
}
};
return chatterino::ModerationAction(pattern);
}
};
} // namespace Settings
} // namespace pajlada

View file

@ -242,7 +242,7 @@ void Emojis::loadEmojiSet()
{
auto app = getApp();
getSettings()->emojiSet.connect([=](const auto &emojiSet, auto) {
getSettings()->emojiSet.connect([=](const auto &emojiSet) {
this->emojis.each([=](const auto &name,
std::shared_ptr<EmojiData> &emoji) {
QString emojiSetToUse = emojiSet;

View file

@ -79,25 +79,25 @@ void TwitchAccountManager::reloadUsers()
continue;
}
std::string username = pajlada::Settings::Setting<std::string>::get(
auto username = pajlada::Settings::Setting<QString>::get(
"/accounts/" + uid + "/username");
std::string userID = pajlada::Settings::Setting<std::string>::get(
"/accounts/" + uid + "/userID");
std::string clientID = pajlada::Settings::Setting<std::string>::get(
auto userID = pajlada::Settings::Setting<QString>::get("/accounts/" +
uid + "/userID");
auto clientID = pajlada::Settings::Setting<QString>::get(
"/accounts/" + uid + "/clientID");
std::string oauthToken = pajlada::Settings::Setting<std::string>::get(
auto oauthToken = pajlada::Settings::Setting<QString>::get(
"/accounts/" + uid + "/oauthToken");
if (username.empty() || userID.empty() || clientID.empty() ||
oauthToken.empty())
if (username.isEmpty() || userID.isEmpty() || clientID.isEmpty() ||
oauthToken.isEmpty())
{
continue;
}
userData.username = qS(username).trimmed();
userData.userID = qS(userID).trimmed();
userData.clientID = qS(clientID).trimmed();
userData.oauthToken = qS(oauthToken).trimmed();
userData.username = username.trimmed();
userData.userID = userID.trimmed();
userData.clientID = clientID.trimmed();
userData.oauthToken = oauthToken.trimmed();
switch (this->addUser(userData))
{
@ -138,8 +138,7 @@ void TwitchAccountManager::load()
{
this->reloadUsers();
this->currentUsername.connect([this](const auto &newValue, auto) {
QString newUsername(QString::fromStdString(newValue));
this->currentUsername.connect([this](const QString &newUsername) {
auto user = this->findUserByUsername(newUsername);
if (user)
{
@ -175,14 +174,14 @@ bool TwitchAccountManager::removeUser(TwitchAccount *account)
{
const auto &accs = this->accounts.getVector();
std::string userID(account->getUserId().toStdString());
if (!userID.empty())
auto userID(account->getUserId());
if (!userID.isEmpty())
{
pajlada::Settings::SettingManager::removeSetting("/accounts/uid" +
userID);
pajlada::Settings::SettingManager::removeSetting(
fS("/accounts/uid{}", userID));
}
if (account->getUserName() == qS(this->currentUsername.getValue()))
if (account->getUserName() == this->currentUsername)
{
// The user that was removed is the current user, log into the anonymous
// user

View file

@ -1,11 +1,10 @@
#pragma once
#include "common/ChatterinoSetting.hpp"
#include "common/SignalVector.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "util/SharedPtrElementLess.hpp"
#include <pajlada/settings/setting.hpp>
#include <mutex>
#include <vector>
@ -47,8 +46,7 @@ public:
bool isLoggedIn() const;
pajlada::Settings::Setting<std::string> currentUsername = {
"/accounts/current", ""};
QStringSetting currentUsername{"/accounts/current", ""};
pajlada::Signals::NoArgSignal currentUserChanged;
pajlada::Signals::NoArgSignal userListUpdated;

View file

@ -470,8 +470,6 @@ void TwitchChannel::refreshLiveStatus()
return;
}
log("[TwitchChannel:{}] Refreshing live status", this->getName());
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
// auto request = makeGetStreamRequest(roomID, QThread::currentThread());

View file

@ -4,7 +4,7 @@
#include <rapidjson/document.h>
#include <QString>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
#include <cassert>
@ -32,49 +32,42 @@ struct TwitchUser {
} // namespace chatterino
namespace pajlada {
namespace Settings {
template <>
struct Deserialize<chatterino::TwitchUser> {
static chatterino::TwitchUser get(const rapidjson::Value &value,
bool *error = nullptr)
template <>
struct Deserialize<chatterino::TwitchUser> {
static chatterino::TwitchUser get(const rapidjson::Value &value,
bool *error = nullptr)
{
using namespace chatterino;
TwitchUser user;
if (!value.IsObject())
{
using namespace chatterino;
TwitchUser user;
if (!value.IsObject())
{
PAJLADA_REPORT_ERROR(error)
PAJLADA_THROW_EXCEPTION(
"Deserialized rapidjson::Value is wrong type");
return user;
}
if (!rj::getSafe(value, "_id", user.id))
{
PAJLADA_REPORT_ERROR(error)
PAJLADA_THROW_EXCEPTION("Missing ID key");
return user;
}
if (!rj::getSafe(value, "name", user.name))
{
PAJLADA_REPORT_ERROR(error)
PAJLADA_THROW_EXCEPTION("Missing name key");
return user;
}
if (!rj::getSafe(value, "display_name", user.displayName))
{
PAJLADA_REPORT_ERROR(error)
PAJLADA_THROW_EXCEPTION("Missing display name key");
return user;
}
PAJLADA_REPORT_ERROR(error)
return user;
}
};
} // namespace Settings
if (!rj::getSafe(value, "_id", user.id))
{
PAJLADA_REPORT_ERROR(error)
return user;
}
if (!rj::getSafe(value, "name", user.name))
{
PAJLADA_REPORT_ERROR(error)
return user;
}
if (!rj::getSafe(value, "display_name", user.displayName))
{
PAJLADA_REPORT_ERROR(error)
return user;
}
return user;
}
};
} // namespace pajlada

View file

@ -32,37 +32,43 @@ Fonts::Fonts()
void Fonts::initialize(Settings &, Paths &)
{
this->chatFontFamily.connect([this](const std::string &, auto) {
assertInGuiThread();
this->chatFontFamily.connect(
[this]() {
assertInGuiThread();
for (auto &map : this->fontsByType_)
{
map.clear();
}
this->fontChanged.invoke();
});
for (auto &map : this->fontsByType_)
{
map.clear();
}
this->fontChanged.invoke();
},
false);
this->chatFontSize.connect([this](const int &, auto) {
assertInGuiThread();
this->chatFontSize.connect(
[this]() {
assertInGuiThread();
for (auto &map : this->fontsByType_)
{
map.clear();
}
this->fontChanged.invoke();
});
for (auto &map : this->fontsByType_)
{
map.clear();
}
this->fontChanged.invoke();
},
false);
getSettings()->boldScale.connect([this](const int &, auto) {
assertInGuiThread();
getSettings()->boldScale.connect(
[this]() {
assertInGuiThread();
getApp()->windows->incGeneration();
getApp()->windows->incGeneration();
for (auto &map : this->fontsByType_)
{
map.clear();
}
this->fontChanged.invoke();
});
for (auto &map : this->fontsByType_)
{
map.clear();
}
this->fontChanged.invoke();
},
false);
}
QFont Fonts::getFont(FontStyle type, float scale)
@ -118,7 +124,7 @@ Fonts::FontData Fonts::createFontData(FontStyle type, float scale)
1, false, QFont::Weight(getSettings()->boldScale.getValue())};
auto data = sizeScale[type];
return FontData(
QFont(QString::fromStdString(this->chatFontFamily.getValue()),
QFont(this->chatFontFamily.getValue(),
int(this->chatFontSize.getValue() * data.scale * scale),
data.weight, data.italic));
}

View file

@ -1,14 +1,15 @@
#pragma once
#include "common/ChatterinoSetting.hpp"
#include "common/Singleton.hpp"
#include <QFont>
#include <QFontDatabase>
#include <QFontMetrics>
#include <array>
#include <boost/noncopyable.hpp>
#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/signal.hpp>
#include <array>
#include <unordered_map>
namespace chatterino {
@ -49,8 +50,8 @@ public:
QFont getFont(FontStyle type, float scale);
QFontMetrics getFontMetrics(FontStyle type, float scale);
pajlada::Settings::Setting<std::string> chatFontFamily;
pajlada::Settings::Setting<int> chatFontSize;
QStringSetting chatFontFamily;
IntSetting chatFontSize;
pajlada::Signals::NoArgSignal fontChanged;

View file

@ -8,12 +8,12 @@
namespace chatterino {
std::vector<std::weak_ptr<pajlada::Settings::ISettingData>> _settings;
std::vector<std::weak_ptr<pajlada::Settings::SettingData>> _settings;
Settings *Settings::instance = nullptr;
void _actuallyRegisterSetting(
std::weak_ptr<pajlada::Settings::ISettingData> setting)
std::weak_ptr<pajlada::Settings::SettingData> setting)
{
_settings.push_back(setting);
}
@ -24,7 +24,15 @@ Settings::Settings(Paths &paths)
QString settingsPath = paths.settingsDirectory + "/settings.json";
pajlada::Settings::SettingManager::gLoad(qPrintable(settingsPath));
// get global instance of the settings library
auto settingsInstance = pajlada::Settings::SettingManager::getInstance();
settingsInstance->load(qPrintable(settingsPath));
settingsInstance->setBackupEnabled(true);
settingsInstance->setBackupSlots(9);
settingsInstance->saveMethod =
pajlada::Settings::SettingManager::SaveMethod::SaveOnExit;
}
Settings &Settings::getInstance()
@ -46,13 +54,20 @@ void Settings::saveSnapshot()
}
rapidjson::Value key(setting->getPath().c_str(), a);
rapidjson::Value val = setting->marshalInto(*d);
auto curVal = setting->unmarshalJSON();
if (curVal == nullptr)
{
continue;
}
rapidjson::Value val;
val.CopyFrom(*curVal, a);
d->AddMember(key.Move(), val.Move(), a);
}
this->snapshot_.reset(d);
// log("Snapshot state: {}", rj::stringify(*d));
log("hehe: {}", pajlada::Settings::SettingManager::stringify(*d));
this->snapshot_.reset(d);
}
void Settings::restoreSnapshot()
@ -62,26 +77,29 @@ void Settings::restoreSnapshot()
return;
}
const auto &snapshotObject = this->snapshot_->GetObject();
const auto &snapshot = *(this->snapshot_.get());
if (!snapshot.IsObject())
{
return;
}
for (const auto &weakSetting : _settings)
{
auto setting = weakSetting.lock();
if (!setting)
{
log("Error stage 1 of loading");
continue;
}
const char *path = setting->getPath().c_str();
if (!snapshotObject.HasMember(path))
if (!snapshot.HasMember(path))
{
log("Error stage 2 of loading");
continue;
}
setting->unmarshalValue(snapshotObject[path]);
setting->marshalJSON(snapshot[path]);
}
}

View file

@ -12,7 +12,7 @@
namespace chatterino {
void _actuallyRegisterSetting(
std::weak_ptr<pajlada::Settings::ISettingData> setting);
std::weak_ptr<pajlada::Settings::SettingData> setting);
class Settings
{

View file

@ -39,8 +39,6 @@ namespace detail {
} // namespace detail
Theme::Theme()
: themeName("/appearance/theme/name", "Dark")
, themeHue("/appearance/theme/hue", 0.0)
{
this->update();

View file

@ -130,8 +130,8 @@ public:
pajlada::Signals::NoArgSignal updated;
pajlada::Settings::Setting<QString> themeName;
pajlada::Settings::Setting<double> themeHue;
QStringSetting themeName{"/appearance/theme/name", "Dark"};
DoubleSetting themeHue{"/appearance/theme/hue", 0.0};
private:
void actuallyUpdate(double hue, double multiplier);

View file

@ -1,49 +1,45 @@
#pragma once
#include <QString>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
namespace pajlada {
namespace Settings {
template <>
struct Serialize<QString> {
static rapidjson::Value get(const QString &value,
rapidjson::Document::AllocatorType &a)
template <>
struct Serialize<QString> {
static rapidjson::Value get(const QString &value,
rapidjson::Document::AllocatorType &a)
{
return rapidjson::Value(value.toUtf8(), a);
}
};
template <>
struct Deserialize<QString> {
static QString get(const rapidjson::Value &value, bool *error = nullptr)
{
if (!value.IsString())
{
return rapidjson::Value(value.toUtf8(), a);
}
};
template <>
struct Deserialize<QString> {
static QString get(const rapidjson::Value &value, bool *error = nullptr)
{
if (!value.IsString())
{
PAJLADA_REPORT_ERROR(error)
PAJLADA_THROW_EXCEPTION(
"Deserialized rapidjson::Value is not a string");
return QString{};
}
try
{
return QString::fromUtf8(value.GetString(),
value.GetStringLength());
}
catch (const std::exception &)
{
// int x = 5;
}
catch (...)
{
// int y = 5;
}
PAJLADA_REPORT_ERROR(error)
return QString{};
}
};
} // namespace Settings
try
{
return QString::fromUtf8(value.GetString(),
value.GetStringLength());
}
catch (const std::exception &)
{
// int x = 5;
}
catch (...)
{
// int y = 5;
}
return QString{};
}
};
} // namespace pajlada

View file

@ -3,7 +3,7 @@
#include "util/RapidJsonSerializeQString.hpp"
#include <rapidjson/document.h>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
#include <cassert>
#include <string>
@ -24,8 +24,7 @@ namespace rj {
{
assert(obj.IsObject());
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a),
a);
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
}
template <>
@ -45,8 +44,7 @@ namespace rj {
auto &a = obj.GetAllocator();
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a),
a);
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
}
template <>
@ -66,7 +64,7 @@ namespace rj {
{
assert(arr.IsArray());
arr.PushBack(pajlada::Settings::Serialize<Type>::get(value, a), a);
arr.PushBack(pajlada::Serialize<Type>::get(value, a), a);
}
template <typename Type>
@ -88,7 +86,7 @@ namespace rj {
}
bool error = false;
out = pajlada::Settings::Deserialize<Type>::get(obj[key], &error);
out = pajlada::Deserialize<Type>::get(obj[key], &error);
return !error;
}
@ -97,7 +95,7 @@ namespace rj {
bool getSafe(const rapidjson::Value &value, Type &out)
{
bool error = false;
out = pajlada::Settings::Deserialize<Type>::get(value, &error);
out = pajlada::Deserialize<Type>::get(value, &error);
return !error;
}

View file

@ -50,8 +50,7 @@ AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
}
else
{
app->accounts->twitch.currentUsername =
newUsername.toStdString();
app->accounts->twitch.currentUsername = newUsername;
}
}
});

View file

@ -56,9 +56,9 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
this->init();
this->connections_.managedConnect(
getSettings()->uiScale.getValueChangedSignal(),
[this](auto, auto) { postToThread([this] { this->updateScale(); }); });
getSettings()->uiScale.connect(
[this]() { postToThread([this] { this->updateScale(); }); },
this->connections_);
this->updateScale();
@ -133,8 +133,8 @@ void BaseWindow::init()
? Qt::WindowActive
: Qt::WindowMaximized);
});
QObject::connect(_exitButton, &TitleBarButton::leftClicked, this,
[this] { this->close(); });
QObject::connect(_exitButton, &TitleBarButton::leftClicked,
this, [this] { this->close(); });
this->ui_.minButton = _minButton;
this->ui_.maxButton = _maxButton;

View file

@ -5,6 +5,7 @@
#include "common/NetworkRequest.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "providers/twitch/PartialTwitchUser.hpp"
#include "util/Helpers.hpp"
#ifdef USEWINSDK
# include <Windows.h>
@ -21,26 +22,25 @@ namespace chatterino {
namespace {
void LogInWithCredentials(const std::string &userID,
const std::string &username,
const std::string &clientID,
const std::string &oauthToken)
void LogInWithCredentials(const QString &userID, const QString &username,
const QString &clientID,
const QString &oauthToken)
{
QStringList errors;
if (userID.empty())
if (userID.isEmpty())
{
errors.append("Missing user ID");
}
if (username.empty())
if (username.isEmpty())
{
errors.append("Missing username");
}
if (clientID.empty())
if (clientID.isEmpty())
{
errors.append("Missing Client ID");
}
if (oauthToken.empty())
if (oauthToken.isEmpty())
{
errors.append("Missing OAuth Token");
}
@ -65,14 +65,14 @@ namespace {
// messageBox.setIcon(QMessageBox::Information);
// messageBox.setText("Successfully logged in with user <b>" +
// qS(username) + "</b>!");
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/username", username);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/userID", userID);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/clientID", clientID);
pajlada::Settings::Setting<std::string>::set(
"/accounts/uid" + userID + "/oauthToken", oauthToken);
auto basePath = fS("/accounts/uid{}", userID);
pajlada::Settings::Setting<QString>::set(basePath + "/username",
username);
pajlada::Settings::Setting<QString>::set(basePath + "/userID", userID);
pajlada::Settings::Setting<QString>::set(basePath + "/clientID",
clientID);
pajlada::Settings::Setting<QString>::set(basePath + "/oauthToken",
oauthToken);
getApp()->accounts->twitch.reloadUsers();
@ -105,7 +105,7 @@ BasicLoginWidget::BasicLoginWidget()
QString clipboardString = clipboard->text();
QStringList parameters = clipboardString.split(';');
std::string oauthToken, clientID, username, userID;
QString oauthToken, clientID, username, userID;
for (const auto &param : parameters)
{
@ -119,19 +119,19 @@ BasicLoginWidget::BasicLoginWidget()
if (key == "oauth_token")
{
oauthToken = value.toStdString();
oauthToken = value;
}
else if (key == "client_id")
{
clientID = value.toStdString();
clientID = value;
}
else if (key == "username")
{
username = value.toStdString();
username = value;
}
else if (key == "user_id")
{
userID = value.toStdString();
userID = value;
}
else
{
@ -198,16 +198,15 @@ AdvancedLoginWidget::AdvancedLoginWidget()
this->ui_.oauthTokenInput.clear();
});
connect(
&this->ui_.buttonUpperRow.addUserButton, &QPushButton::clicked, [=]() {
std::string userID = this->ui_.userIDInput.text().toStdString();
std::string username = this->ui_.usernameInput.text().toStdString();
std::string clientID = this->ui_.clientIDInput.text().toStdString();
std::string oauthToken =
this->ui_.oauthTokenInput.text().toStdString();
connect(&this->ui_.buttonUpperRow.addUserButton, &QPushButton::clicked,
[=]() {
QString userID = this->ui_.userIDInput.text();
QString username = this->ui_.usernameInput.text();
QString clientID = this->ui_.clientIDInput.text();
QString oauthToken = this->ui_.oauthTokenInput.text();
LogInWithCredentials(userID, username, clientID, oauthToken);
});
LogInWithCredentials(userID, username, clientID, oauthToken);
});
/// Lower button row
this->ui_.buttonLowerRow.fillInUserIDButton.setText(

View file

@ -36,8 +36,8 @@ NotebookTab::NotebookTab(Notebook *notebook)
this->positionChangedAnimation_.setEasingCurve(
QEasingCurve(QEasingCurve::InCubic));
getSettings()->showTabCloseButton.connect(
boost::bind(&NotebookTab::hideTabXChanged, this, _1),
getSettings()->showTabCloseButton.connectSimple(
boost::bind(&NotebookTab::hideTabXChanged, this),
this->managedConnections_);
getSettings()->showTabLive.connect([this](auto, auto) { this->update(); },
this->managedConnections_);
@ -230,7 +230,7 @@ QRect NotebookTab::getDesiredRect() const
return QRect(this->positionAnimationDesiredPoint_, size());
}
void NotebookTab::hideTabXChanged(bool)
void NotebookTab::hideTabXChanged()
{
this->updateSize();
this->update();

View file

@ -49,7 +49,7 @@ public:
void moveAnimated(QPoint pos, bool animated = true);
QRect getDesiredRect() const;
void hideTabXChanged(bool);
void hideTabXChanged();
protected:
virtual void themeChangedEvent() override;

View file

@ -148,10 +148,9 @@ void GeneralPage::initLayout(SettingsLayout &layout)
layout.addTitle("Appearance");
layout.addDropdown("Theme", {"White", "Light", "Dark", "Black"},
getApp()->themes->themeName);
layout.addDropdown<std::string>(
layout.addDropdown<QString>(
"Font", {"Segoe UI", "Arial", "Choose..."},
getApp()->fonts->chatFontFamily,
[](auto val) { return QString::fromStdString(val); },
getApp()->fonts->chatFontFamily, [](auto val) { return val; },
[this](auto args) { return this->getFont(args); });
layout.addDropdown<int>(
"Font size", {"9pt", "10pt", "12pt", "14pt", "16pt", "20pt"},
@ -220,7 +219,8 @@ void GeneralPage::initLayout(SettingsLayout &layout)
layout.addCheckbox("Animate only when focused", s.animationsWhenFocused);
layout.addDropdown("Emoji set",
{"EmojiOne 2", "EmojiOne 3", "Twitter", "Facebook",
"Apple", "Google", "Messenger"});
"Apple", "Google", "Messenger"},
s.emojiSet);
layout.addTitle("Badges");
layout.addCheckbox("Show authority badges (staff, admin, turbo, etc)",
@ -311,7 +311,7 @@ void GeneralPage::initExtra()
}
}
std::string GeneralPage::getFont(const DropdownArgs &args) const
QString GeneralPage::getFont(const DropdownArgs &args) const
{
if (args.combobox->currentIndex() == args.combobox->count() - 1)
{
@ -325,11 +325,11 @@ std::string GeneralPage::getFont(const DropdownArgs &args) const
auto font = dialog.getFont(&ok);
if (ok)
return font.family().toStdString();
return font.family();
else
return args.combobox->itemText(0).toStdString();
return args.combobox->itemText(0);
}
return args.value.toStdString();
return args.value;
}
} // namespace chatterino

View file

@ -156,7 +156,7 @@ private:
void initLayout(SettingsLayout &layout);
void initExtra();
std::string getFont(const DropdownArgs &args) const;
QString getFont(const DropdownArgs &args) const;
DescriptionLabel *cachePath{};
};

View file

@ -532,17 +532,15 @@ QLayout *LookPage::createFontChanger()
QLabel *label = new QLabel();
layout->addWidget(label);
auto updateFontFamilyLabel = [=](auto) {
label->setText(
"Font (" +
QString::fromStdString(app->fonts->chatFontFamily.getValue()) +
", " + QString::number(app->fonts->chatFontSize) + "pt)");
auto updateFontFamilyLabel = [=]() {
label->setText("Font (" + app->fonts->chatFontFamily.getValue() + ", " +
QString::number(app->fonts->chatFontSize) + "pt)");
};
app->fonts->chatFontFamily.connectSimple(updateFontFamilyLabel,
this->managedConnections_);
app->fonts->chatFontSize.connectSimple(updateFontFamilyLabel,
this->managedConnections_);
app->fonts->chatFontFamily.connect(updateFontFamilyLabel,
this->managedConnections_);
app->fonts->chatFontSize.connect(updateFontFamilyLabel,
this->managedConnections_);
// BUTTON
QPushButton *button = new QPushButton("Select");
@ -554,11 +552,11 @@ QLayout *LookPage::createFontChanger()
dialog.setWindowFlag(Qt::WindowStaysOnTopHint);
dialog.connect(
&dialog, &QFontDialog::fontSelected, [=](const QFont &font) {
app->fonts->chatFontFamily = font.family().toStdString();
app->fonts->chatFontSize = font.pointSize();
});
dialog.connect(&dialog, &QFontDialog::fontSelected,
[=](const QFont &font) {
app->fonts->chatFontFamily = font.family();
app->fonts->chatFontSize = font.pointSize();
});
dialog.show();
dialog.exec();