#include "moderationpage.hpp" #include #include #include #include #include #include #include #include "singletons/pathmanager.hpp" #include "util/layoutcreator.hpp" namespace chatterino { namespace widgets { namespace settingspages { inline QString CreateLink(const QString &url, bool file = false) { if (file) { return QString("" + url + ""); } return QString("" + url + ""); } ModerationPage::ModerationPage() : SettingsPage("Moderation", "") { singletons::SettingManager &settings = singletons::SettingManager::getInstance(); singletons::PathManager &pathManager = singletons::PathManager::getInstance(); util::LayoutCreator layoutCreator(this); auto layout = layoutCreator.setLayoutType(); { // Logs (copied from LoggingMananger) auto logPath = pathManager.logsFolderPath; auto created = layout.emplace(); created->setText("Logs are saved to " + CreateLink(logPath, true)); created->setTextFormat(Qt::RichText); created->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByKeyboard); created->setOpenExternalLinks(true); layout.append(this->createCheckBox("Enable logging", settings.enableLogging)); layout->addStretch(1); // Logs end // clang-format off auto label = layout.emplace("Click the moderation mod button () in a channel that you moderate to enable moderator mode.
"); label->setWordWrap(true); label->setStyleSheet("color: #bbb"); // clang-format on auto form = layout.emplace(); { form->addRow("Action on timed out messages (unimplemented):", this->createComboBox({"Disable", "Hide"}, settings.timeoutAction)); } auto modButtons = layout.emplace("Custom moderator buttons").setLayoutType(); { auto label2 = modButtons.emplace("One action per line. {user} will be replaced with the " "username.
Example `/timeout {user} 120`
"); label2->setWordWrap(true); auto text = modButtons.emplace().getElement(); text->setPlainText(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(); }); } } // ---- misc this->itemsChangedTimer.setSingleShot(true); } } // namespace settingspages } // namespace widgets } // namespace chatterino