2018-07-05 16:45:34 +02:00
|
|
|
#include "IgnoresPage.hpp"
|
2018-01-23 21:33:49 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
|
|
#include "controllers/ignores/IgnoreController.hpp"
|
|
|
|
#include "controllers/ignores/IgnoreModel.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/LayoutCreator.hpp"
|
|
|
|
#include "widgets/helper/EditableModelView.hpp"
|
2018-01-23 21:33:49 +01:00
|
|
|
|
|
|
|
#include <QCheckBox>
|
2018-01-23 23:10:27 +01:00
|
|
|
#include <QGroupBox>
|
2018-06-22 12:34:33 +02:00
|
|
|
#include <QHeaderView>
|
2018-01-23 21:33:49 +01:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QListView>
|
|
|
|
#include <QPushButton>
|
2018-05-13 19:24:32 +02:00
|
|
|
#include <QTableView>
|
2018-01-23 21:33:49 +01:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
// clang-format off
|
2019-08-26 14:36:06 +02:00
|
|
|
#define INFO "/ignore <user> in chat ignores a user.\n/unignore <user> in chat unignores a user.\nYou can also click on a user to open the usercard."
|
2018-01-23 21:33:49 +01:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
namespace chatterino {
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-07-05 16:45:34 +02:00
|
|
|
static void addPhrasesTab(LayoutCreator<QVBoxLayout> box);
|
2018-09-30 13:37:39 +02:00
|
|
|
static void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> box,
|
|
|
|
QStringListModel &model);
|
2018-07-05 16:45:34 +02:00
|
|
|
|
2018-07-05 16:22:25 +02:00
|
|
|
IgnoresPage::IgnoresPage()
|
2018-10-20 00:53:19 +02:00
|
|
|
: SettingsPage("Ignores", ":/settings/ignore.svg")
|
2018-01-23 21:33:49 +01:00
|
|
|
{
|
2018-07-05 16:22:25 +02:00
|
|
|
LayoutCreator<IgnoresPage> layoutCreator(this);
|
2018-01-23 21:56:25 +01:00
|
|
|
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
|
2018-04-27 01:11:09 +02:00
|
|
|
auto tabs = layout.emplace<QTabWidget>();
|
|
|
|
|
2019-08-26 14:36:06 +02:00
|
|
|
addPhrasesTab(tabs.appendTab(new QVBoxLayout, "Messages"));
|
2018-09-30 13:37:39 +02:00
|
|
|
addUsersTab(*this, tabs.appendTab(new QVBoxLayout, "Users"),
|
|
|
|
this->userListModel_);
|
2018-07-05 16:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void addPhrasesTab(LayoutCreator<QVBoxLayout> layout)
|
|
|
|
{
|
2019-08-26 14:36:06 +02:00
|
|
|
layout.emplace<QLabel>("Messages can be ignored if "
|
|
|
|
"they match a certain pattern.");
|
2018-07-05 16:45:34 +02:00
|
|
|
EditableModelView *view =
|
2018-09-30 13:37:39 +02:00
|
|
|
layout
|
|
|
|
.emplace<EditableModelView>(getApp()->ignores->createModel(nullptr))
|
|
|
|
.getElement();
|
|
|
|
view->setTitles(
|
|
|
|
{"Pattern", "Regex", "Case Sensitive", "Block", "Replacement"});
|
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
QHeaderView::Fixed);
|
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
0, QHeaderView::Stretch);
|
2019-08-26 14:07:21 +02:00
|
|
|
view->addRegexHelpLink();
|
2018-07-05 16:45:34 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(1, [view] {
|
|
|
|
view->getTableView()->resizeColumnsToContents();
|
|
|
|
view->getTableView()->setColumnWidth(0, 200);
|
|
|
|
});
|
|
|
|
|
|
|
|
view->addButtonPressed.connect([] {
|
2018-09-30 13:37:39 +02:00
|
|
|
getApp()->ignores->phrases.appendItem(
|
2019-08-26 14:36:06 +02:00
|
|
|
IgnorePhrase{"my pattern", false, false,
|
2018-09-30 13:37:39 +02:00
|
|
|
getSettings()->ignoredPhraseReplace.getValue(), true});
|
2018-07-05 16:45:34 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users,
|
|
|
|
QStringListModel &userModel)
|
2018-07-05 16:45:34 +02:00
|
|
|
{
|
2019-08-26 14:36:06 +02:00
|
|
|
auto label = users.emplace<QLabel>(INFO);
|
|
|
|
label->setWordWrap(true);
|
2018-08-15 22:46:20 +02:00
|
|
|
users.append(page.createCheckBox("Enable twitch ignored users",
|
|
|
|
getSettings()->enableTwitchIgnoredUsers));
|
2018-07-05 16:45:34 +02:00
|
|
|
|
|
|
|
auto anyways = users.emplace<QHBoxLayout>().withoutMargin();
|
2018-01-23 21:33:49 +01:00
|
|
|
{
|
2019-04-12 22:12:39 +02:00
|
|
|
anyways.emplace<QLabel>("Show messages from ignored users anyways:");
|
|
|
|
|
|
|
|
auto combo = anyways.emplace<QComboBox>().getElement();
|
|
|
|
combo->addItems(
|
|
|
|
{"Never", "If you are Moderator", "If you are Broadcaster"});
|
|
|
|
|
|
|
|
auto &setting = getSettings()->showIgnoredUsersMessages;
|
|
|
|
|
|
|
|
setting.connect(
|
|
|
|
[combo](const int value) { combo->setCurrentIndex(value); });
|
|
|
|
|
|
|
|
QObject::connect(combo,
|
|
|
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
[&setting](int index) {
|
|
|
|
if (index != -1)
|
|
|
|
setting = index;
|
|
|
|
});
|
|
|
|
|
2018-07-05 16:45:34 +02:00
|
|
|
anyways->addStretch(1);
|
2018-01-23 21:33:49 +01:00
|
|
|
}
|
2018-04-26 23:07:02 +02:00
|
|
|
|
2018-07-05 16:45:34 +02:00
|
|
|
/*auto addremove = users.emplace<QHBoxLayout>().withoutMargin();
|
2018-04-27 01:11:09 +02:00
|
|
|
{
|
2018-07-05 16:45:34 +02:00
|
|
|
auto add = addremove.emplace<QPushButton>("Ignore user");
|
|
|
|
auto remove = addremove.emplace<QPushButton>("Unignore User");
|
|
|
|
addremove->addStretch(1);
|
|
|
|
}*/
|
2018-04-27 01:11:09 +02:00
|
|
|
|
2019-08-26 14:36:06 +02:00
|
|
|
users.emplace<QLabel>("List of ignored users:");
|
2018-07-05 16:45:34 +02:00
|
|
|
users.emplace<QListView>()->setModel(&userModel);
|
2018-01-23 21:33:49 +01:00
|
|
|
}
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-07-05 16:22:25 +02:00
|
|
|
void IgnoresPage::onShow()
|
2018-05-12 20:34:13 +02:00
|
|
|
{
|
|
|
|
auto app = getApp();
|
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
auto user = app->accounts->twitch.getCurrent();
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (user->isAnon())
|
|
|
|
{
|
2018-05-12 20:34:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList users;
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &ignoredUser : user->getIgnores())
|
|
|
|
{
|
2018-05-12 20:34:13 +02:00
|
|
|
users << ignoredUser.name;
|
|
|
|
}
|
2018-11-17 16:41:22 +01:00
|
|
|
users.sort(Qt::CaseInsensitive);
|
2018-07-06 19:23:47 +02:00
|
|
|
this->userListModel_.setStringList(users);
|
2018-05-12 20:34:13 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 21:33:49 +01:00
|
|
|
} // namespace chatterino
|