Perform initial refactoring work

Things that were once singletons are no longer singletons, but are
instead stored in the "Application" singleton

Some singletons still remain, and some renaming/renamespacing is left
This commit is contained in:
Rasmus Karlsson
2018-04-27 22:11:19 +02:00
parent 32b6417a55
commit ae26b835b6
78 changed files with 850 additions and 773 deletions
+5 -4
View File
@@ -1,13 +1,14 @@
#include "accountspage.hpp"
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include "application.hpp"
#include "const.hpp"
#include "singletons/accountmanager.hpp"
#include "util/layoutcreator.hpp"
#include "widgets/logindialog.hpp"
#include <QDialogButtonBox>
#include <QVBoxLayout>
namespace chatterino {
namespace widgets {
namespace settingspages {
@@ -39,7 +40,7 @@ AccountsPage::AccountsPage()
return;
}
singletons::AccountManager::getInstance().Twitch.removeUser(selectedUser);
getApp()->accounts->Twitch.removeUser(selectedUser);
});
}
+29 -25
View File
@@ -1,5 +1,9 @@
#include "appearancepage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include "util/removescrollareabackground.hpp"
#include <QFontDialog>
#include <QFormLayout>
#include <QGroupBox>
@@ -9,9 +13,6 @@
#include <QSlider>
#include <QVBoxLayout>
#include "util/layoutcreator.hpp"
#include "util/removescrollareabackground.hpp"
#define THEME_ITEMS "White", "Light", "Dark", "Black"
#define TAB_X "Show close button"
@@ -34,7 +35,7 @@ namespace settingspages {
AppearancePage::AppearancePage()
: SettingsPage("Look", ":/images/theme.svg")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<AppearancePage> layoutCreator(this);
auto scroll = layoutCreator.emplace<QScrollArea>();
@@ -49,50 +50,52 @@ AppearancePage::AppearancePage()
auto form = application.emplace<QFormLayout>();
// clang-format off
form->addRow("Theme:", this->createComboBox({THEME_ITEMS}, singletons::ThemeManager::getInstance().themeName));
form->addRow("Theme:", this->createComboBox({THEME_ITEMS}, app->themes->themeName));
form->addRow("Theme color:", this->createThemeColorChanger());
form->addRow("Font:", this->createFontChanger());
form->addRow("Tabs:", this->createCheckBox(TAB_X, settings.hideTabX));
form->addRow("Tabs:", this->createCheckBox(TAB_X, app->settings->hideTabX));
#ifndef USEWINSDK
form->addRow("", this->createCheckBox(TAB_PREF, settings.hidePreferencesButton));
form->addRow("", this->createCheckBox(TAB_USER, settings.hideUserButton));
form->addRow("", this->createCheckBox(TAB_PREF, app->settings->hidePreferencesButton));
form->addRow("", this->createCheckBox(TAB_USER, app->settings->hideUserButton));
#endif
form->addRow("Scrolling:", this->createCheckBox(SCROLL_SMOOTH, settings.enableSmoothScrolling));
form->addRow("", this->createCheckBox(SCROLL_NEWMSG, settings.enableSmoothScrollingNewMessages));
form->addRow("Scrolling:", this->createCheckBox(SCROLL_SMOOTH, app->settings->enableSmoothScrolling));
form->addRow("", this->createCheckBox(SCROLL_NEWMSG, app->settings->enableSmoothScrollingNewMessages));
// clang-format on
}
auto messages = layout.emplace<QGroupBox>("Messages").emplace<QVBoxLayout>();
{
messages.append(this->createCheckBox("Show timestamp", settings.showTimestamps));
messages.append(this->createCheckBox("Show timestamp", app->settings->showTimestamps));
auto tbox = messages.emplace<QHBoxLayout>().withoutMargin();
{
tbox.emplace<QLabel>("timestamp format (a = am/pm):");
tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, settings.timestampFormat));
tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, app->settings->timestampFormat));
tbox->addStretch(1);
}
messages.append(this->createCheckBox("Show badges", settings.showBadges));
auto checkbox = this->createCheckBox("Seperate messages", settings.seperateMessages);
messages.append(this->createCheckBox("Show badges", app->settings->showBadges));
auto checkbox = this->createCheckBox("Seperate messages", app->settings->seperateMessages);
checkbox->setEnabled(false);
messages.append(checkbox);
messages.append(
this->createCheckBox("Show message length while typing", settings.showMessageLength));
messages.append(this->createCheckBox("Show message length while typing",
app->settings->showMessageLength));
messages.append(this->createCheckBox(LAST_MSG, settings.showLastMessageIndicator));
messages.append(this->createCheckBox(LAST_MSG, app->settings->showLastMessageIndicator));
}
auto emotes = layout.emplace<QGroupBox>("Emotes").setLayoutType<QVBoxLayout>();
{
emotes.append(this->createCheckBox("Enable Twitch emotes", settings.enableTwitchEmotes));
emotes.append(
this->createCheckBox("Enable BetterTTV emotes for Twitch", settings.enableBttvEmotes));
this->createCheckBox("Enable Twitch emotes", app->settings->enableTwitchEmotes));
emotes.append(this->createCheckBox("Enable BetterTTV emotes for Twitch",
app->settings->enableBttvEmotes));
emotes.append(this->createCheckBox("Enable FrankerFaceZ emotes for Twitch",
settings.enableFfzEmotes));
emotes.append(this->createCheckBox("Enable emojis", settings.enableEmojis));
emotes.append(this->createCheckBox("Enable animations", settings.enableGifAnimations));
app->settings->enableFfzEmotes));
emotes.append(this->createCheckBox("Enable emojis", app->settings->enableEmojis));
emotes.append(
this->createCheckBox("Enable animations", app->settings->enableGifAnimations));
}
layout->addStretch(1);
@@ -100,9 +103,10 @@ AppearancePage::AppearancePage()
QLayout *AppearancePage::createThemeColorChanger()
{
auto app = getApp();
QHBoxLayout *layout = new QHBoxLayout;
auto &themeHue = singletons::ThemeManager::getInstance().themeHue;
auto &themeHue = app->themes->themeHue;
// SLIDER
QSlider *slider = new QSlider(Qt::Horizontal);
@@ -115,9 +119,9 @@ QLayout *AppearancePage::createThemeColorChanger()
button->setFlat(true);
button->setFixedWidth(64);
auto setButtonColor = [button](int value) mutable {
auto setButtonColor = [button, app](int value) mutable {
double newValue = value / 100.0;
singletons::ThemeManager::getInstance().themeHue.setValue(newValue);
app->themes->themeHue.setValue(newValue);
QPalette pal = button->palette();
QColor color;
+17 -13
View File
@@ -1,12 +1,13 @@
#include "behaviourpage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QVBoxLayout>
#include <util/layoutcreator.hpp>
#define WINDOW_TOPMOST "Window always on top (requires restart)"
#define INPUT_EMPTY "Hide input box when empty"
#define PAUSE_HOVERING "When hovering"
@@ -20,20 +21,21 @@ namespace settingspages {
BehaviourPage::BehaviourPage()
: SettingsPage("Feel", ":/images/behave.svg")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<BehaviourPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
auto form = layout.emplace<QFormLayout>().withoutMargin();
{
form->addRow("Window:", this->createCheckBox(WINDOW_TOPMOST, settings.windowTopMost));
form->addRow("Messages:", this->createCheckBox(INPUT_EMPTY, settings.hideEmptyInput));
form->addRow("Pause chat:", this->createCheckBox(PAUSE_HOVERING, settings.pauseChatHover));
form->addRow("Window:", this->createCheckBox(WINDOW_TOPMOST, app->settings->windowTopMost));
form->addRow("Messages:", this->createCheckBox(INPUT_EMPTY, app->settings->hideEmptyInput));
form->addRow("Pause chat:",
this->createCheckBox(PAUSE_HOVERING, app->settings->pauseChatHover));
form->addRow("Mouse scroll speed:", this->createMouseScrollSlider());
form->addRow("Links:", this->createCheckBox("Open links only on double click",
settings.linksDoubleClickOnly));
app->settings->linksDoubleClickOnly));
}
layout->addSpacing(16);
@@ -43,17 +45,18 @@ BehaviourPage::BehaviourPage()
auto groupLayout = group.setLayoutType<QFormLayout>();
groupLayout->addRow(
LIMIT_CHATTERS_FOR_SMALLER_STREAMERS,
this->createCheckBox("", settings.onlyFetchChattersForSmallerStreamers));
this->createCheckBox("", app->settings->onlyFetchChattersForSmallerStreamers));
groupLayout->addRow("What viewer count counts as a \"smaller streamer\"",
this->createSpinBox(settings.smallStreamerLimit, 10, 50000));
this->createSpinBox(app->settings->smallStreamerLimit, 10, 50000));
}
{
auto group = layout.emplace<QGroupBox>("Misc");
auto groupLayout = group.setLayoutType<QVBoxLayout>();
groupLayout.append(this->createCheckBox("Show whispers inline", settings.inlineWhispers));
groupLayout.append(
this->createCheckBox("Show whispers inline", app->settings->inlineWhispers));
}
layout->addStretch(1);
@@ -61,16 +64,17 @@ BehaviourPage::BehaviourPage()
QSlider *BehaviourPage::createMouseScrollSlider()
{
auto app = getApp();
auto slider = new QSlider(Qt::Horizontal);
float currentValue = singletons::SettingManager::getInstance().mouseScrollMultiplier;
float currentValue = app->settings->mouseScrollMultiplier;
int sliderValue = ((currentValue - 0.1f) / 2.f) * 99.f;
slider->setValue(sliderValue);
QObject::connect(slider, &QSlider::valueChanged, [](int newValue) {
QObject::connect(slider, &QSlider::valueChanged, [=](int newValue) {
float mul = static_cast<float>(newValue) / 99.f;
float newSliderValue = (mul * 2.1f) + 0.1f;
singletons::SettingManager::getInstance().mouseScrollMultiplier = newSliderValue;
app->settings->mouseScrollMultiplier = newSliderValue;
});
return slider;
+10 -9
View File
@@ -1,11 +1,12 @@
#include "commandpage.hpp"
#include "application.hpp"
#include "singletons/commandmanager.hpp"
#include "util/layoutcreator.hpp"
#include <QLabel>
#include <QTextEdit>
#include "singletons/commandmanager.hpp"
#include "util/layoutcreator.hpp"
// clang-format off
#define TEXT "One command per line.\n"\
"\"/cmd example command\" will print \"example command\" when you type /cmd in chat.\n"\
@@ -34,27 +35,27 @@ CommandPage::CommandPage()
QTextEdit *CommandPage::getCommandsTextEdit()
{
singletons::CommandManager &commandManager = singletons::CommandManager::getInstance();
auto app = getApp();
// cancel
QStringList currentCommands = commandManager.getCommands();
QStringList currentCommands = app->commands->getCommands();
this->onCancel.connect(
[currentCommands, &commandManager] { commandManager.setCommands(currentCommands); });
[currentCommands, app] { app->commands->setCommands(currentCommands); });
// create text edit
QTextEdit *textEdit = new QTextEdit;
textEdit->setPlainText(QString(commandManager.getCommands().join('\n')));
textEdit->setPlainText(QString(app->commands->getCommands().join('\n')));
QObject::connect(textEdit, &QTextEdit::textChanged,
[this] { this->commandsEditTimer.start(200); });
QObject::connect(&this->commandsEditTimer, &QTimer::timeout, [textEdit, &commandManager] {
QObject::connect(&this->commandsEditTimer, &QTimer::timeout, [textEdit, app] {
QString text = textEdit->toPlainText();
QStringList lines = text.split(QRegularExpression("(\r?\n|\r\n?)"));
commandManager.setCommands(lines);
app->commands->setCommands(lines);
});
return textEdit;
@@ -1,5 +1,6 @@
#include "externaltoolspage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include <QGroupBox>
@@ -13,17 +14,21 @@ namespace settingspages {
ExternalToolsPage::ExternalToolsPage()
: SettingsPage("External tools", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<ExternalToolsPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
{
auto group = layout.emplace<QGroupBox>("Streamlink");
auto groupLayout = group.setLayoutType<QFormLayout>();
groupLayout->addRow("Streamlink path:", this->createLineEdit(settings.streamlinkPath));
groupLayout->addRow("Prefered quality:",
this->createComboBox({STREAMLINK_QUALITY}, settings.preferredQuality));
groupLayout->addRow("Additional options:", this->createLineEdit(settings.streamlinkOpts));
groupLayout->addRow("Streamlink path:",
this->createLineEdit(app->settings->streamlinkPath));
groupLayout->addRow(
"Prefered quality:",
this->createComboBox({STREAMLINK_QUALITY}, app->settings->preferredQuality));
groupLayout->addRow("Additional options:",
this->createLineEdit(app->settings->streamlinkOpts));
}
layout->addStretch(1);
+43 -42
View File
@@ -1,5 +1,11 @@
#include "highlightingpage.hpp"
#include "application.hpp"
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
#include "util/standarditemhelper.hpp"
#include <QFileDialog>
#include <QListWidget>
#include <QPushButton>
@@ -8,11 +14,6 @@
#include <QTableView>
#include <QTextEdit>
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
#include "util/standarditemhelper.hpp"
#define ENABLE_HIGHLIGHTS "Enable Highlighting"
#define HIGHLIGHT_MSG "Highlight messages containing your name"
#define PLAY_SOUND "Play sound when your name is mentioned"
@@ -26,13 +27,13 @@ namespace settingspages {
HighlightingPage::HighlightingPage()
: SettingsPage("Highlights", ":/images/notifications.svg")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<HighlightingPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
{
// GENERAL
layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, settings.enableHighlights));
layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, app->settings->enableHighlights));
// TABS
auto tabs = layout.emplace<QTabWidget>();
@@ -56,17 +57,17 @@ HighlightingPage::HighlightingPage()
yourName->setData(QBrush("#666"), Qt::ForegroundRole);
yourName->setFlags(yourName->flags() | Qt::ItemIsUserCheckable |
Qt::ItemIsUserCheckable);
yourName->setData(settings.enableHighlightsSelf ? 2 : 0, Qt::CheckStateRole);
yourName->setData(app->settings->enableHighlightsSelf ? 2 : 0, Qt::CheckStateRole);
model->appendRow(
{yourName,
util::boolItem(settings.enableHighlightTaskbar.getValue(), true, false),
util::boolItem(settings.enableHighlightSound.getValue(), true, false),
util::boolItem(app->settings->enableHighlightTaskbar.getValue(), true, false),
util::boolItem(app->settings->enableHighlightSound.getValue(), true, false),
util::emptyItem()});
// highlight phrases
// fourtf: could crash
for (const messages::HighlightPhrase &phrase :
settings.highlightProperties.getValue()) {
app->settings->highlightProperties.getValue()) {
model->appendRow({util::stringItem(phrase.key), util::boolItem(phrase.alert),
util::boolItem(phrase.sound), util::boolItem(phrase.regex)});
}
@@ -79,26 +80,26 @@ HighlightingPage::HighlightingPage()
auto buttons = highlights.emplace<QHBoxLayout>();
QObject::connect(model, &QStandardItemModel::dataChanged,
[model](const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles) {
std::vector<messages::HighlightPhrase> phrases;
for (int i = 1; i < model->rowCount(); i++) {
phrases.push_back(messages::HighlightPhrase{
model->item(i, 0)->data(Qt::DisplayRole).toString(),
model->item(i, 1)->data(Qt::CheckStateRole).toBool(),
model->item(i, 2)->data(Qt::CheckStateRole).toBool(),
model->item(i, 3)->data(Qt::CheckStateRole).toBool()});
}
auto &settings = singletons::SettingManager::getInstance();
settings.highlightProperties.setValue(phrases);
settings.enableHighlightsSelf.setValue(
model->item(0, 0)->data(Qt::CheckStateRole).toBool());
settings.enableHighlightTaskbar.setValue(
model->item(0, 1)->data(Qt::CheckStateRole).toBool());
settings.enableHighlightSound.setValue(
model->item(0, 2)->data(Qt::CheckStateRole).toBool());
});
QObject::connect(
model, &QStandardItemModel::dataChanged,
[model, app](const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles) {
std::vector<messages::HighlightPhrase> phrases;
for (int i = 1; i < model->rowCount(); i++) {
phrases.push_back(messages::HighlightPhrase{
model->item(i, 0)->data(Qt::DisplayRole).toString(),
model->item(i, 1)->data(Qt::CheckStateRole).toBool(),
model->item(i, 2)->data(Qt::CheckStateRole).toBool(),
model->item(i, 3)->data(Qt::CheckStateRole).toBool()});
}
app->settings->highlightProperties.setValue(phrases);
app->settings->enableHighlightsSelf.setValue(
model->item(0, 0)->data(Qt::CheckStateRole).toBool());
app->settings->enableHighlightTaskbar.setValue(
model->item(0, 1)->data(Qt::CheckStateRole).toBool());
app->settings->enableHighlightSound.setValue(
model->item(0, 2)->data(Qt::CheckStateRole).toBool());
});
auto add = buttons.emplace<QPushButton>("Add");
QObject::connect(*add, &QPushButton::clicked, [model, view] {
@@ -138,13 +139,13 @@ HighlightingPage::HighlightingPage()
[this] { this->disabledUsersChangedTimer.start(200); });
QObject::connect(
&this->disabledUsersChangedTimer, &QTimer::timeout, this, [text, &settings]() {
&this->disabledUsersChangedTimer, &QTimer::timeout, this, [text, app]() {
QStringList list = text->toPlainText().split("\n", QString::SkipEmptyParts);
list.removeDuplicates();
settings.highlightUserBlacklist = list.join("\n") + "\n";
app->settings->highlightUserBlacklist = list.join("\n") + "\n";
});
settings.highlightUserBlacklist.connect([=](const QString &str, auto) {
app->settings->highlightUserBlacklist.connect([=](const QString &str, auto) {
text->setPlainText(str); //
});
}
@@ -153,17 +154,17 @@ HighlightingPage::HighlightingPage()
// MISC
auto customSound = layout.emplace<QHBoxLayout>().withoutMargin();
{
customSound.append(this->createCheckBox("Custom sound", settings.customHighlightSound));
customSound.append(
this->createCheckBox("Custom sound", app->settings->customHighlightSound));
auto selectFile = customSound.emplace<QPushButton>("Select custom sound file");
QObject::connect(selectFile.getElement(), &QPushButton::clicked, this,
[&settings, this] {
auto fileName = QFileDialog::getOpenFileName(
this, tr("Open Sound"), "", tr("Audio Files (*.mp3 *.wav)"));
settings.pathHighlightSound = fileName;
});
QObject::connect(selectFile.getElement(), &QPushButton::clicked, this, [this, app] {
auto fileName = QFileDialog::getOpenFileName(this, tr("Open Sound"), "",
tr("Audio Files (*.mp3 *.wav)"));
app->settings->pathHighlightSound = fileName;
});
}
layout.append(createCheckBox(ALWAYS_PLAY, settings.highlightAlwaysPlaySound));
layout.append(createCheckBox(ALWAYS_PLAY, app->settings->highlightAlwaysPlaySound));
}
// ---- misc
@@ -1,5 +1,6 @@
#include "ignoremessagespage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include <QLabel>
@@ -12,22 +13,22 @@ namespace settingspages {
IgnoreMessagesPage::IgnoreMessagesPage()
: SettingsPage("Ignore Messages", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<IgnoreMessagesPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
layout.emplace<QLabel>("Ignored keywords:");
QTextEdit *textEdit = layout.emplace<QTextEdit>().getElement();
textEdit->setPlainText(settings.ignoredKeywords);
textEdit->setPlainText(app->settings->ignoredKeywords);
QObject::connect(textEdit, &QTextEdit::textChanged,
[this] { this->keywordsUpdated.start(200); });
QObject::connect(&this->keywordsUpdated, &QTimer::timeout, [textEdit, &settings] {
QObject::connect(&this->keywordsUpdated, &QTimer::timeout, [textEdit, app] {
QString text = textEdit->toPlainText();
settings.ignoredKeywords = text;
app->settings->ignoredKeywords = text;
});
// ---- misc
@@ -1,5 +1,6 @@
#include "ignoreuserspage.hpp"
#include "application.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
@@ -21,14 +22,15 @@ namespace settingspages {
IgnoreUsersPage::IgnoreUsersPage()
: SettingsPage("Ignores", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<IgnoreUsersPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
auto group = layout.emplace<QGroupBox>("Ignored users").setLayoutType<QVBoxLayout>();
{
group.append(
this->createCheckBox("Enable twitch ignored users", settings.enableTwitchIgnoredUsers));
group.append(this->createCheckBox("Enable twitch ignored users",
app->settings->enableTwitchIgnoredUsers));
auto anyways = group.emplace<QHBoxLayout>().withoutMargin();
{
+6 -4
View File
@@ -1,4 +1,6 @@
#include "logspage.hpp"
#include "application.hpp"
#include "singletons/pathmanager.hpp"
#include <QFormLayout>
@@ -23,12 +25,12 @@ inline QString CreateLink(const QString &url, bool file = false)
LogsPage::LogsPage()
: SettingsPage("Logs", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<LogsPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
singletons::PathManager &pathManager = singletons::PathManager::getInstance();
auto logPath = pathManager.logsFolderPath;
auto logPath = app->paths->logsFolderPath;
auto created = layout.emplace<QLabel>();
created->setText("Logs are saved to " + CreateLink(logPath, true));
@@ -36,7 +38,7 @@ LogsPage::LogsPage()
created->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByKeyboard);
created->setOpenExternalLinks(true);
layout.append(this->createCheckBox("Enable logging", settings.enableLogging));
layout.append(this->createCheckBox("Enable logging", app->settings->enableLogging));
layout->addStretch(1);
}
+11 -11
View File
@@ -1,5 +1,9 @@
#include "moderationpage.hpp"
#include "application.hpp"
#include "singletons/pathmanager.hpp"
#include "util/layoutcreator.hpp"
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
@@ -8,9 +12,6 @@
#include <QTextEdit>
#include <QVBoxLayout>
#include "singletons/pathmanager.hpp"
#include "util/layoutcreator.hpp"
namespace chatterino {
namespace widgets {
namespace settingspages {
@@ -28,14 +29,13 @@ inline QString CreateLink(const QString &url, bool file = false)
ModerationPage::ModerationPage()
: SettingsPage("Moderation", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
singletons::PathManager &pathManager = singletons::PathManager::getInstance();
auto app = getApp();
util::LayoutCreator<ModerationPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
{
// Logs (copied from LoggingMananger)
auto logPath = pathManager.logsFolderPath;
auto logPath = app->paths->logsFolderPath;
auto created = layout.emplace<QLabel>();
created->setText("Logs are saved to " + CreateLink(logPath, true));
@@ -44,7 +44,7 @@ ModerationPage::ModerationPage()
Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByKeyboard);
created->setOpenExternalLinks(true);
layout.append(this->createCheckBox("Enable logging", settings.enableLogging));
layout.append(this->createCheckBox("Enable logging", app->settings->enableLogging));
layout->addStretch(1);
// Logs end
@@ -58,7 +58,7 @@ ModerationPage::ModerationPage()
auto form = layout.emplace<QFormLayout>();
{
form->addRow("Action on timed out messages (unimplemented):",
this->createComboBox({"Disable", "Hide"}, settings.timeoutAction));
this->createComboBox({"Disable", "Hide"}, app->settings->timeoutAction));
}
auto modButtons =
@@ -71,13 +71,13 @@ ModerationPage::ModerationPage()
auto text = modButtons.emplace<QTextEdit>().getElement();
text->setPlainText(settings.moderationActions);
text->setPlainText(app->settings->moderationActions);
QObject::connect(text, &QTextEdit::textChanged, this,
[this] { this->itemsChangedTimer.start(200); });
QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, this, [text, &settings]() {
settings.moderationActions = text->toPlainText();
QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, this, [text, app]() {
app->settings->moderationActions = text->toPlainText();
});
}
}
@@ -1,5 +1,6 @@
#include "specialchannelspage.hpp"
#include "application.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
@@ -14,7 +15,8 @@ namespace settingspages {
SpecialChannelsPage::SpecialChannelsPage()
: SettingsPage("Special channels", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<SpecialChannelsPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();