mirror-chatterino2/src/widgets/settingspages/IgnoresPage.cpp

104 lines
3.3 KiB
C++
Raw Normal View History

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"
#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>
#include <QGroupBox>
#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
2018-04-26 23:07:02 +02:00
#define INFO "/ignore <user> in chat ignores a user\n/unignore <user> in chat unignores a user"
2018-01-23 21:33:49 +01:00
// clang-format on
namespace chatterino {
2018-07-05 16:45:34 +02:00
static void addPhrasesTab(LayoutCreator<QVBoxLayout> box);
Squashed commit of the following: commit ea07bbef0be589cc5412bff0a25735ac713128e3 Merge: 0b36f436 5cfcf114 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:05:14 2018 +0200 Merge branch 'blacklist' into blacklistnew commit 5cfcf114b65ea7c0fca9654393ac2faa78610098 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:00:16 2018 +0200 rename second pattern to replacement commit f08cc4cf88c49140a282d3d29af5ad8e7179bb7c Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:30 2018 +0200 delete out commented code commit 1acb1278aa0109359e0e349ae240d10b34de9d34 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:03 2018 +0200 fix replacement with emotes issues commit 646268ab1883a955291f152029fa37f4416e681e Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 01:06:36 2018 +0200 fix build commit ad711b4c15ef0660c554af5ceea82397769a2313 Merge: e8e059f8 8bcc9c48 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:52:38 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e8e059f8473271128086c5230cf1c40b235af380 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:25:58 2018 +0200 add replaced emotes into twitchEmotes commit a63454f00de479cee1ab1eca18a8b4ab93e37d52 Merge: e7f2f397 63eaf3b9 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 22:38:16 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e7f2f397378d0582d989ff8fcbe83bcec41449a1 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 21:54:01 2018 +0200 emotedata commit f00d3da537ec14aebd9cbb84d63f7b16c196f199 Author: hemirt <hemirt@email.cz> Date: Sat Jul 28 19:53:55 2018 +0200 rename variables to fit better, emotes in capture groups from regex work commit 00c9fa080aeb8a4a187743d708ba139cbed5a849 Author: hemirt <hemirt@email.cz> Date: Mon Jul 9 19:53:53 2018 +0200 add case sensitivity checkbox and fix validity issues due to isValid that checked regex commit 4385fcd13fe6e011b91a3f4a29fd440d019fc499 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:09:14 2018 +0200 remove commented code commit 1834342f74c4fbff38b81fa2c2fcfd6c55adc0d5 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:03:13 2018 +0200 IgnorePhrase replacement also removes twitch emotes info about the matched and changed parts and shifts positions of other emotes from emote infos to the corresponding new position commit d3b6e294ed38fa8587c367c5da6f257641c28b86 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 16:21:33 2018 +0200 ignore phrases
2018-09-23 20:21:50 +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-04-26 23:07:02 +02:00
: SettingsPage("Ignores", "")
2018-01-23 21:33:49 +01:00
{
2018-07-05 16:22:25 +02:00
LayoutCreator<IgnoresPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
2018-04-27 01:11:09 +02:00
auto tabs = layout.emplace<QTabWidget>();
2018-07-05 16:45:34 +02:00
addPhrasesTab(tabs.appendTab(new QVBoxLayout, "Phrases"));
Squashed commit of the following: commit ea07bbef0be589cc5412bff0a25735ac713128e3 Merge: 0b36f436 5cfcf114 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:05:14 2018 +0200 Merge branch 'blacklist' into blacklistnew commit 5cfcf114b65ea7c0fca9654393ac2faa78610098 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:00:16 2018 +0200 rename second pattern to replacement commit f08cc4cf88c49140a282d3d29af5ad8e7179bb7c Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:30 2018 +0200 delete out commented code commit 1acb1278aa0109359e0e349ae240d10b34de9d34 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:03 2018 +0200 fix replacement with emotes issues commit 646268ab1883a955291f152029fa37f4416e681e Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 01:06:36 2018 +0200 fix build commit ad711b4c15ef0660c554af5ceea82397769a2313 Merge: e8e059f8 8bcc9c48 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:52:38 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e8e059f8473271128086c5230cf1c40b235af380 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:25:58 2018 +0200 add replaced emotes into twitchEmotes commit a63454f00de479cee1ab1eca18a8b4ab93e37d52 Merge: e7f2f397 63eaf3b9 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 22:38:16 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e7f2f397378d0582d989ff8fcbe83bcec41449a1 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 21:54:01 2018 +0200 emotedata commit f00d3da537ec14aebd9cbb84d63f7b16c196f199 Author: hemirt <hemirt@email.cz> Date: Sat Jul 28 19:53:55 2018 +0200 rename variables to fit better, emotes in capture groups from regex work commit 00c9fa080aeb8a4a187743d708ba139cbed5a849 Author: hemirt <hemirt@email.cz> Date: Mon Jul 9 19:53:53 2018 +0200 add case sensitivity checkbox and fix validity issues due to isValid that checked regex commit 4385fcd13fe6e011b91a3f4a29fd440d019fc499 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:09:14 2018 +0200 remove commented code commit 1834342f74c4fbff38b81fa2c2fcfd6c55adc0d5 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:03:13 2018 +0200 IgnorePhrase replacement also removes twitch emotes info about the matched and changed parts and shifts positions of other emotes from emote infos to the corresponding new position commit d3b6e294ed38fa8587c367c5da6f257641c28b86 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 16:21:33 2018 +0200 ignore phrases
2018-09-23 20:21:50 +02:00
addUsersTab(*this, tabs.appendTab(new QVBoxLayout, "Users"), this->userListModel_);
2018-07-05 16:45:34 +02:00
auto label = layout.emplace<QLabel>(INFO);
label->setWordWrap(true);
label->setStyleSheet("color: #BBB");
}
void addPhrasesTab(LayoutCreator<QVBoxLayout> layout)
{
EditableModelView *view =
Squashed commit of the following: commit ea07bbef0be589cc5412bff0a25735ac713128e3 Merge: 0b36f436 5cfcf114 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:05:14 2018 +0200 Merge branch 'blacklist' into blacklistnew commit 5cfcf114b65ea7c0fca9654393ac2faa78610098 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:00:16 2018 +0200 rename second pattern to replacement commit f08cc4cf88c49140a282d3d29af5ad8e7179bb7c Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:30 2018 +0200 delete out commented code commit 1acb1278aa0109359e0e349ae240d10b34de9d34 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:03 2018 +0200 fix replacement with emotes issues commit 646268ab1883a955291f152029fa37f4416e681e Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 01:06:36 2018 +0200 fix build commit ad711b4c15ef0660c554af5ceea82397769a2313 Merge: e8e059f8 8bcc9c48 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:52:38 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e8e059f8473271128086c5230cf1c40b235af380 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:25:58 2018 +0200 add replaced emotes into twitchEmotes commit a63454f00de479cee1ab1eca18a8b4ab93e37d52 Merge: e7f2f397 63eaf3b9 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 22:38:16 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e7f2f397378d0582d989ff8fcbe83bcec41449a1 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 21:54:01 2018 +0200 emotedata commit f00d3da537ec14aebd9cbb84d63f7b16c196f199 Author: hemirt <hemirt@email.cz> Date: Sat Jul 28 19:53:55 2018 +0200 rename variables to fit better, emotes in capture groups from regex work commit 00c9fa080aeb8a4a187743d708ba139cbed5a849 Author: hemirt <hemirt@email.cz> Date: Mon Jul 9 19:53:53 2018 +0200 add case sensitivity checkbox and fix validity issues due to isValid that checked regex commit 4385fcd13fe6e011b91a3f4a29fd440d019fc499 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:09:14 2018 +0200 remove commented code commit 1834342f74c4fbff38b81fa2c2fcfd6c55adc0d5 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:03:13 2018 +0200 IgnorePhrase replacement also removes twitch emotes info about the matched and changed parts and shifts positions of other emotes from emote infos to the corresponding new position commit d3b6e294ed38fa8587c367c5da6f257641c28b86 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 16:21:33 2018 +0200 ignore phrases
2018-09-23 20:21:50 +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);
2018-07-05 16:45:34 +02:00
QTimer::singleShot(1, [view] {
view->getTableView()->resizeColumnsToContents();
view->getTableView()->setColumnWidth(0, 200);
});
view->addButtonPressed.connect([] {
Squashed commit of the following: commit ea07bbef0be589cc5412bff0a25735ac713128e3 Merge: 0b36f436 5cfcf114 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:05:14 2018 +0200 Merge branch 'blacklist' into blacklistnew commit 5cfcf114b65ea7c0fca9654393ac2faa78610098 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:00:16 2018 +0200 rename second pattern to replacement commit f08cc4cf88c49140a282d3d29af5ad8e7179bb7c Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:30 2018 +0200 delete out commented code commit 1acb1278aa0109359e0e349ae240d10b34de9d34 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:03 2018 +0200 fix replacement with emotes issues commit 646268ab1883a955291f152029fa37f4416e681e Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 01:06:36 2018 +0200 fix build commit ad711b4c15ef0660c554af5ceea82397769a2313 Merge: e8e059f8 8bcc9c48 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:52:38 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e8e059f8473271128086c5230cf1c40b235af380 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:25:58 2018 +0200 add replaced emotes into twitchEmotes commit a63454f00de479cee1ab1eca18a8b4ab93e37d52 Merge: e7f2f397 63eaf3b9 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 22:38:16 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e7f2f397378d0582d989ff8fcbe83bcec41449a1 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 21:54:01 2018 +0200 emotedata commit f00d3da537ec14aebd9cbb84d63f7b16c196f199 Author: hemirt <hemirt@email.cz> Date: Sat Jul 28 19:53:55 2018 +0200 rename variables to fit better, emotes in capture groups from regex work commit 00c9fa080aeb8a4a187743d708ba139cbed5a849 Author: hemirt <hemirt@email.cz> Date: Mon Jul 9 19:53:53 2018 +0200 add case sensitivity checkbox and fix validity issues due to isValid that checked regex commit 4385fcd13fe6e011b91a3f4a29fd440d019fc499 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:09:14 2018 +0200 remove commented code commit 1834342f74c4fbff38b81fa2c2fcfd6c55adc0d5 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:03:13 2018 +0200 IgnorePhrase replacement also removes twitch emotes info about the matched and changed parts and shifts positions of other emotes from emote infos to the corresponding new position commit d3b6e294ed38fa8587c367c5da6f257641c28b86 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 16:21:33 2018 +0200 ignore phrases
2018-09-23 20:21:50 +02:00
getApp()->ignores->phrases.appendItem(IgnorePhrase{
"my phrase", false, false, getSettings()->ignoredPhraseReplace.getValue(), true});
2018-07-05 16:45:34 +02:00
});
}
Squashed commit of the following: commit ea07bbef0be589cc5412bff0a25735ac713128e3 Merge: 0b36f436 5cfcf114 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:05:14 2018 +0200 Merge branch 'blacklist' into blacklistnew commit 5cfcf114b65ea7c0fca9654393ac2faa78610098 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 20:00:16 2018 +0200 rename second pattern to replacement commit f08cc4cf88c49140a282d3d29af5ad8e7179bb7c Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:30 2018 +0200 delete out commented code commit 1acb1278aa0109359e0e349ae240d10b34de9d34 Author: hemirt <hemirt@email.cz> Date: Sun Sep 23 19:52:03 2018 +0200 fix replacement with emotes issues commit 646268ab1883a955291f152029fa37f4416e681e Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 01:06:36 2018 +0200 fix build commit ad711b4c15ef0660c554af5ceea82397769a2313 Merge: e8e059f8 8bcc9c48 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:52:38 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e8e059f8473271128086c5230cf1c40b235af380 Author: hemirt <hemirt@email.cz> Date: Sun Aug 19 00:25:58 2018 +0200 add replaced emotes into twitchEmotes commit a63454f00de479cee1ab1eca18a8b4ab93e37d52 Merge: e7f2f397 63eaf3b9 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 22:38:16 2018 +0200 Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist commit e7f2f397378d0582d989ff8fcbe83bcec41449a1 Author: hemirt <hemirt@email.cz> Date: Sat Aug 11 21:54:01 2018 +0200 emotedata commit f00d3da537ec14aebd9cbb84d63f7b16c196f199 Author: hemirt <hemirt@email.cz> Date: Sat Jul 28 19:53:55 2018 +0200 rename variables to fit better, emotes in capture groups from regex work commit 00c9fa080aeb8a4a187743d708ba139cbed5a849 Author: hemirt <hemirt@email.cz> Date: Mon Jul 9 19:53:53 2018 +0200 add case sensitivity checkbox and fix validity issues due to isValid that checked regex commit 4385fcd13fe6e011b91a3f4a29fd440d019fc499 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:09:14 2018 +0200 remove commented code commit 1834342f74c4fbff38b81fa2c2fcfd6c55adc0d5 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 21:03:13 2018 +0200 IgnorePhrase replacement also removes twitch emotes info about the matched and changed parts and shifts positions of other emotes from emote infos to the corresponding new position commit d3b6e294ed38fa8587c367c5da6f257641c28b86 Author: hemirt <hemirt@email.cz> Date: Sun Jul 8 16:21:33 2018 +0200 ignore phrases
2018-09-23 20:21:50 +02:00
void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users, QStringListModel &userModel)
2018-07-05 16:45:34 +02:00
{
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
{
2018-07-05 16:45:34 +02:00
anyways.emplace<QLabel>("Show anyways if:");
anyways.emplace<QComboBox>();
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
2018-07-05 16:45:34 +02:00
users.emplace<QListView>()->setModel(&userModel);
2018-01-23 21:33:49 +01:00
}
2018-07-05 16:22:25 +02:00
void IgnoresPage::onShow()
{
auto app = getApp();
2018-05-26 20:26:25 +02:00
auto user = app->accounts->twitch.getCurrent();
if (user->isAnon()) {
return;
}
QStringList users;
for (const auto &ignoredUser : user->getIgnores()) {
users << ignoredUser.name;
}
2018-07-06 19:23:47 +02:00
this->userListModel_.setStringList(users);
}
2018-01-23 21:33:49 +01:00
} // namespace chatterino