#include "moderationpage.hpp" #include "application.hpp" #include "singletons/loggingmanager.hpp" #include "singletons/pathmanager.hpp" #include "util/layoutcreator.hpp" #include #include #include #include #include #include #include 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", "") { auto app = getApp(); util::LayoutCreator layoutCreator(this); auto layout = layoutCreator.setLayoutType(); { // Logs (copied from LoggingMananger) auto created = layout.emplace(); if (app->settings->logPath == "") { created->setText("Logs are saved to " + CreateLink(QCoreApplication::applicationDirPath(), true)); } else { created->setText("Logs are saved to " + CreateLink(app->settings->logPath, true)); } created->setTextFormat(Qt::RichText); created->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByKeyboard); created->setOpenExternalLinks(true); layout.append(this->createCheckBox("Enable logging", app->settings->enableLogging)); layout->addStretch(1); auto selectDir = layout.emplace("Set custom logpath"); // Setting custom logpath QObject::connect(selectDir.getElement(), &QPushButton::clicked, this, [ this, created, app, dirMemory = QString{app->settings->logPath} ]() mutable { auto dirName = QFileDialog::getExistingDirectory(this); created->setText("Logs are saved to " + CreateLink(dirName, true)); if (dirName == "" && dirMemory == "") { created->setText( "Logs are saved to " + CreateLink(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), true)); } else if (dirName == "") { dirName = dirMemory; created->setText("Logs are saved to " + CreateLink(dirName, true)); } app->settings->logPath = dirName; dirMemory = dirName; app->logging->refreshLoggingPath(); }); // Reset custom logpath auto resetDir = layout.emplace("Reset logpath"); QObject::connect( resetDir.getElement(), &QPushButton::clicked, this, [this, created, app]() mutable { app->settings->logPath = ""; created->setText( "Logs are saved to " + CreateLink(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), true)); app->logging->refreshLoggingPath(); }); // 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"}, app->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(app->settings->moderationActions); QObject::connect(text, &QTextEdit::textChanged, this, [this] { this->itemsChangedTimer.start(200); }); QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, this, [text, app]() { app->settings->moderationActions = text->toPlainText(); }); } } // ---- misc this->itemsChangedTimer.setSingleShot(true); } } // namespace settingspages } // namespace widgets } // namespace chatterino