2018-06-26 14:09:39 +02:00
|
|
|
#include "EmotePopup.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2021-11-21 18:46:21 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2021-11-21 18:46:21 +01:00
|
|
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
2018-08-11 14:20:53 +02:00
|
|
|
#include "debug/Benchmark.hpp"
|
2022-12-18 15:36:39 +01:00
|
|
|
#include "messages/Emote.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "messages/Message.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/MessageBuilder.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "messages/MessageElement.hpp"
|
2022-12-18 15:36:39 +01:00
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
2021-07-13 13:23:50 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "singletons/Settings.hpp"
|
2020-04-13 13:15:51 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2023-09-24 14:17:17 +02:00
|
|
|
#include "util/Helpers.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/helper/ChannelView.hpp"
|
2022-05-16 11:42:17 +02:00
|
|
|
#include "widgets/helper/TrimRegExpValidator.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Notebook.hpp"
|
|
|
|
#include "widgets/Scrollbar.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
#include <QAbstractButton>
|
2018-04-27 22:11:19 +02:00
|
|
|
#include <QHBoxLayout>
|
2022-01-02 15:59:16 +01:00
|
|
|
#include <QRegularExpression>
|
2018-04-27 22:11:19 +02:00
|
|
|
#include <QTabWidget>
|
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
namespace {
|
2022-12-17 18:33:17 +01:00
|
|
|
|
|
|
|
using namespace chatterino;
|
|
|
|
|
|
|
|
auto makeTitleMessage(const QString &title)
|
|
|
|
{
|
|
|
|
MessageBuilder builder;
|
|
|
|
builder.emplace<TextElement>(title, MessageElementFlag::Text);
|
|
|
|
builder->flags.set(MessageFlag::Centered);
|
|
|
|
return builder.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto makeEmoteMessage(const EmoteMap &map, const MessageElementFlag &emoteFlag)
|
|
|
|
{
|
|
|
|
MessageBuilder builder;
|
|
|
|
builder->flags.set(MessageFlag::Centered);
|
|
|
|
builder->flags.set(MessageFlag::DisableCompactEmotes);
|
|
|
|
|
|
|
|
if (map.empty())
|
2018-08-15 22:46:20 +02:00
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
builder.emplace<TextElement>("no emotes available",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
2018-08-15 22:46:20 +02:00
|
|
|
return builder.release();
|
2018-08-11 14:20:53 +02:00
|
|
|
}
|
2022-12-17 18:33:17 +01:00
|
|
|
|
|
|
|
std::vector<std::pair<EmoteName, EmotePtr>> vec(map.begin(), map.end());
|
|
|
|
std::sort(vec.begin(), vec.end(),
|
|
|
|
[](const std::pair<EmoteName, EmotePtr> &l,
|
|
|
|
const std::pair<EmoteName, EmotePtr> &r) {
|
2023-09-24 14:17:17 +02:00
|
|
|
return compareEmoteStrings(l.first.string, r.first.string);
|
2022-12-17 18:33:17 +01:00
|
|
|
});
|
|
|
|
for (const auto &emote : vec)
|
|
|
|
{
|
|
|
|
builder
|
|
|
|
.emplace<EmoteElement>(
|
|
|
|
emote.second,
|
|
|
|
MessageElementFlags{MessageElementFlag::AlwaysShow, emoteFlag})
|
|
|
|
->setLink(Link(Link::InsertText, emote.first.string));
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.release();
|
|
|
|
}
|
|
|
|
|
2023-11-26 19:17:58 +01:00
|
|
|
auto makeEmojiMessage(const std::vector<EmojiPtr> &emojiMap)
|
2022-12-17 18:33:17 +01:00
|
|
|
{
|
|
|
|
MessageBuilder builder;
|
|
|
|
builder->flags.set(MessageFlag::Centered);
|
|
|
|
builder->flags.set(MessageFlag::DisableCompactEmotes);
|
|
|
|
|
2023-11-26 19:17:58 +01:00
|
|
|
for (const auto &value : emojiMap)
|
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
builder
|
|
|
|
.emplace<EmoteElement>(
|
|
|
|
value->emote,
|
|
|
|
MessageElementFlags{MessageElementFlag::AlwaysShow,
|
|
|
|
MessageElementFlag::EmojiAll})
|
|
|
|
->setLink(
|
|
|
|
Link(Link::Type::InsertText, ":" + value->shortCodes[0] + ":"));
|
2023-11-26 19:17:58 +01:00
|
|
|
}
|
2022-12-17 18:33:17 +01:00
|
|
|
|
|
|
|
return builder.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void addTwitchEmoteSets(
|
|
|
|
std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> sets,
|
|
|
|
Channel &globalChannel, Channel &subChannel, QString currentChannelName)
|
|
|
|
{
|
|
|
|
QMap<QString, QPair<bool, std::vector<MessagePtr>>> mapOfSets;
|
|
|
|
|
|
|
|
for (const auto &set : sets)
|
2018-08-15 22:46:20 +02:00
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
// Some emotes (e.g. follower ones) are only available in their origin channel
|
|
|
|
if (set->local && currentChannelName != set->channelName)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TITLE
|
|
|
|
auto channelName = set->channelName;
|
|
|
|
auto text = set->text.isEmpty() ? "Twitch" : set->text;
|
|
|
|
|
|
|
|
// EMOTES
|
2018-08-11 14:20:53 +02:00
|
|
|
MessageBuilder builder;
|
|
|
|
builder->flags.set(MessageFlag::Centered);
|
|
|
|
builder->flags.set(MessageFlag::DisableCompactEmotes);
|
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
// If value of map is empty, create init pair and add title.
|
|
|
|
if (mapOfSets.find(channelName) == mapOfSets.end())
|
2018-09-04 20:09:06 +02:00
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
std::vector<MessagePtr> b;
|
|
|
|
b.push_back(makeTitleMessage(text));
|
|
|
|
mapOfSets[channelName] = qMakePair(set->key == "0", b);
|
2021-04-24 17:43:15 +02:00
|
|
|
}
|
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
for (const auto &emote : set->emotes)
|
2021-04-24 17:43:15 +02:00
|
|
|
{
|
|
|
|
builder
|
|
|
|
.emplace<EmoteElement>(
|
2024-01-20 11:49:32 +01:00
|
|
|
getIApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote(
|
|
|
|
emote.id, emote.name),
|
2021-04-24 17:43:15 +02:00
|
|
|
MessageElementFlags{MessageElementFlag::AlwaysShow,
|
2022-12-17 18:33:17 +01:00
|
|
|
MessageElementFlag::TwitchEmote})
|
|
|
|
->setLink(Link(Link::InsertText, emote.name.string));
|
2018-08-11 14:20:53 +02:00
|
|
|
}
|
2017-12-28 00:48:21 +01:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
mapOfSets[channelName].second.push_back(builder.release());
|
2018-08-15 22:46:20 +02:00
|
|
|
}
|
2022-01-02 15:59:16 +01:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
// Output to channel all created messages,
|
|
|
|
// That contain title or emotes.
|
|
|
|
// Put current channel emotes at the top
|
|
|
|
auto currentChannelPair = mapOfSets[currentChannelName];
|
|
|
|
for (const auto &message : currentChannelPair.second)
|
2018-08-15 22:46:20 +02:00
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
subChannel.addMessage(message);
|
|
|
|
}
|
|
|
|
mapOfSets.remove(currentChannelName);
|
2018-08-15 22:46:20 +02:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
for (const auto &pair : mapOfSets)
|
|
|
|
{
|
|
|
|
auto &channel = pair.first ? globalChannel : subChannel;
|
|
|
|
for (const auto &message : pair.second)
|
2018-10-11 14:56:10 +02:00
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
channel.addMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-15 22:46:20 +02:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
void addEmotes(Channel &channel, const EmoteMap &map, const QString &title,
|
|
|
|
const MessageElementFlag &emoteFlag)
|
|
|
|
{
|
|
|
|
channel.addMessage(makeTitleMessage(title));
|
|
|
|
channel.addMessage(makeEmoteMessage(map, emoteFlag));
|
|
|
|
}
|
2018-08-15 22:46:20 +02:00
|
|
|
|
2023-11-26 19:17:58 +01:00
|
|
|
void loadEmojis(ChannelView &view, const std::vector<EmojiPtr> &emojiMap)
|
2022-12-17 18:33:17 +01:00
|
|
|
{
|
|
|
|
ChannelPtr emojiChannel(new Channel("", Channel::Type::None));
|
|
|
|
emojiChannel->addMessage(makeEmojiMessage(emojiMap));
|
2018-10-11 14:56:10 +02:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
view.setChannel(emojiChannel);
|
|
|
|
}
|
2018-08-15 22:46:20 +02:00
|
|
|
|
2023-11-26 19:17:58 +01:00
|
|
|
void loadEmojis(Channel &channel, const std::vector<EmojiPtr> &emojiMap,
|
|
|
|
const QString &title)
|
2022-12-17 18:33:17 +01:00
|
|
|
{
|
|
|
|
channel.addMessage(makeTitleMessage(title));
|
|
|
|
channel.addMessage(makeEmojiMessage(emojiMap));
|
|
|
|
}
|
2018-10-11 14:56:10 +02:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
// Create an emote
|
|
|
|
EmoteMap filterEmoteMap(const QString &text,
|
|
|
|
std::shared_ptr<const EmoteMap> emotes)
|
|
|
|
{
|
|
|
|
EmoteMap filteredMap;
|
2020-10-11 12:31:00 +02:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
for (const auto &emote : *emotes)
|
|
|
|
{
|
|
|
|
if (emote.first.string.contains(text, Qt::CaseInsensitive))
|
2018-10-11 14:56:10 +02:00
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
filteredMap.insert(emote);
|
2018-08-15 22:46:20 +02:00
|
|
|
}
|
2018-08-11 14:20:53 +02:00
|
|
|
}
|
2022-12-17 18:33:17 +01:00
|
|
|
|
|
|
|
return filteredMap;
|
|
|
|
}
|
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
} // namespace
|
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
namespace chatterino {
|
|
|
|
|
2019-08-13 16:39:22 +02:00
|
|
|
EmotePopup::EmotePopup(QWidget *parent)
|
2019-12-14 12:57:40 +01:00
|
|
|
: BasePopup(BaseWindow::EnableCustomFrame, parent)
|
2022-12-17 18:33:17 +01:00
|
|
|
, search_(new QLineEdit())
|
|
|
|
, notebook_(new Notebook(this))
|
2018-08-11 14:20:53 +02:00
|
|
|
{
|
2023-08-05 13:22:37 +02:00
|
|
|
// this->setStayInScreenRect(true);
|
2024-01-19 17:59:55 +01:00
|
|
|
this->moveTo(getIApp()->getWindows()->emotePopupPos(),
|
2023-09-24 15:32:43 +02:00
|
|
|
widgets::BoundsChecking::DesiredPosition);
|
2020-04-13 13:15:51 +02:00
|
|
|
|
2023-06-10 12:55:47 +02:00
|
|
|
auto *layout = new QVBoxLayout();
|
2018-04-18 17:51:53 +02:00
|
|
|
this->getLayoutContainer()->setLayout(layout);
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
QRegularExpression searchRegex("\\S*");
|
|
|
|
searchRegex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
|
|
|
|
2022-11-10 20:11:40 +01:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2022-03-26 14:46:22 +01:00
|
|
|
layout->setSpacing(0);
|
|
|
|
|
2023-06-10 12:55:47 +02:00
|
|
|
auto *layout2 = new QHBoxLayout();
|
2022-11-10 20:11:40 +01:00
|
|
|
layout2->setContentsMargins(8, 8, 8, 8);
|
2022-03-26 14:46:22 +01:00
|
|
|
layout2->setSpacing(8);
|
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
this->search_->setPlaceholderText("Search all emotes...");
|
2022-05-16 11:42:17 +02:00
|
|
|
this->search_->setValidator(new TrimRegExpValidator(searchRegex));
|
2022-01-02 15:59:16 +01:00
|
|
|
this->search_->setClearButtonEnabled(true);
|
|
|
|
this->search_->findChild<QAbstractButton *>()->setIcon(
|
|
|
|
QPixmap(":/buttons/clearSearch.png"));
|
2023-12-16 14:40:05 +01:00
|
|
|
this->search_->installEventFilter(this);
|
2022-03-26 14:46:22 +01:00
|
|
|
layout2->addWidget(this->search_);
|
|
|
|
|
|
|
|
layout->addLayout(layout2);
|
2022-01-02 15:59:16 +01:00
|
|
|
|
|
|
|
QObject::connect(this->search_, &QLineEdit::textChanged, this,
|
|
|
|
&EmotePopup::filterEmotes);
|
2018-04-18 17:51:53 +02:00
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
auto clicked = [this](const Link &link) {
|
|
|
|
this->linkClicked.invoke(link);
|
|
|
|
};
|
2018-08-11 17:15:17 +02:00
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
auto makeView = [&](QString tabTitle, bool addToNotebook = true) {
|
2023-12-17 21:49:37 +01:00
|
|
|
auto *view = new ChannelView(nullptr);
|
2018-08-11 14:20:53 +02:00
|
|
|
|
|
|
|
view->setOverrideFlags(MessageElementFlags{
|
|
|
|
MessageElementFlag::Default, MessageElementFlag::AlwaysShow,
|
|
|
|
MessageElementFlag::EmoteImages});
|
|
|
|
view->setEnableScrollingToBottom(false);
|
2023-09-16 13:52:51 +02:00
|
|
|
// We can safely ignore this signal connection since the ChannelView is deleted
|
|
|
|
// either when the notebook is deleted, or when our main layout is deleted.
|
|
|
|
std::ignore = view->linkClicked.connect(clicked);
|
2018-08-11 14:20:53 +02:00
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
if (addToNotebook)
|
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
this->notebook_->addPage(view, std::move(tabTitle));
|
2022-01-02 15:59:16 +01:00
|
|
|
}
|
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
return view;
|
|
|
|
};
|
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
this->searchView_ = makeView("", false);
|
|
|
|
this->searchView_->hide();
|
|
|
|
layout->addWidget(this->searchView_);
|
|
|
|
|
|
|
|
layout->addWidget(this->notebook_);
|
2022-11-10 20:11:40 +01:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2022-01-02 15:59:16 +01:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
this->subEmotesView_ = makeView("Subs");
|
|
|
|
this->channelEmotesView_ = makeView("Channel");
|
|
|
|
this->globalEmotesView_ = makeView("Global");
|
|
|
|
this->viewEmojis_ = makeView("Emojis");
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2023-11-26 19:17:58 +01:00
|
|
|
loadEmojis(*this->viewEmojis_,
|
|
|
|
getApp()->getEmotes()->getEmojis()->getEmojis());
|
2021-11-21 18:46:21 +01:00
|
|
|
this->addShortcuts();
|
2024-01-19 17:59:55 +01:00
|
|
|
this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated,
|
2021-11-21 18:46:21 +01:00
|
|
|
[this]() {
|
|
|
|
this->clearShortcuts();
|
|
|
|
this->addShortcuts();
|
|
|
|
});
|
2022-01-02 15:59:16 +01:00
|
|
|
|
|
|
|
this->search_->setFocus();
|
2021-11-21 18:46:21 +01:00
|
|
|
}
|
2022-01-02 15:59:16 +01:00
|
|
|
|
2021-11-21 18:46:21 +01:00
|
|
|
void EmotePopup::addShortcuts()
|
|
|
|
{
|
|
|
|
HotkeyController::HotkeyMap actions{
|
|
|
|
{"openTab", // CTRL + 1-8 to open corresponding tab.
|
|
|
|
[this](std::vector<QString> arguments) -> QString {
|
2022-12-17 18:33:17 +01:00
|
|
|
if (arguments.empty())
|
2021-11-21 18:46:21 +01:00
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys)
|
|
|
|
<< "openTab shortcut called without arguments. Takes "
|
|
|
|
"only one argument: tab specifier";
|
|
|
|
return "openTab shortcut called without arguments. "
|
|
|
|
"Takes only one argument: tab specifier";
|
|
|
|
}
|
|
|
|
auto target = arguments.at(0);
|
|
|
|
if (target == "last")
|
|
|
|
{
|
|
|
|
this->notebook_->selectLastTab();
|
|
|
|
}
|
|
|
|
else if (target == "next")
|
|
|
|
{
|
|
|
|
this->notebook_->selectNextTab();
|
|
|
|
}
|
|
|
|
else if (target == "previous")
|
|
|
|
{
|
|
|
|
this->notebook_->selectPreviousTab();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-17 18:33:17 +01:00
|
|
|
bool ok{false};
|
2021-11-21 18:46:21 +01:00
|
|
|
int result = target.toInt(&ok);
|
|
|
|
if (ok)
|
|
|
|
{
|
2023-06-11 11:34:28 +02:00
|
|
|
this->notebook_->selectVisibleIndex(result, false);
|
2021-11-21 18:46:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys)
|
|
|
|
<< "Invalid argument for openTab shortcut";
|
|
|
|
return QString("Invalid argument for openTab "
|
|
|
|
"shortcut: \"%1\". Use \"last\", "
|
|
|
|
"\"next\", \"previous\" or an integer.")
|
|
|
|
.arg(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"delete",
|
2022-12-17 18:33:17 +01:00
|
|
|
[this](const std::vector<QString> &) -> QString {
|
2021-11-21 18:46:21 +01:00
|
|
|
this->close();
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"scrollPage",
|
|
|
|
[this](std::vector<QString> arguments) -> QString {
|
2022-12-17 18:33:17 +01:00
|
|
|
if (arguments.empty())
|
2021-11-21 18:46:21 +01:00
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys)
|
|
|
|
<< "scrollPage hotkey called without arguments!";
|
|
|
|
return "scrollPage hotkey called without arguments!";
|
|
|
|
}
|
|
|
|
auto direction = arguments.at(0);
|
2022-12-17 18:33:17 +01:00
|
|
|
auto *channelView = dynamic_cast<ChannelView *>(
|
2021-11-21 18:46:21 +01:00
|
|
|
this->notebook_->getSelectedPage());
|
2020-01-05 09:45:10 +01:00
|
|
|
|
2021-11-21 18:46:21 +01:00
|
|
|
auto &scrollbar = channelView->getScrollBar();
|
|
|
|
if (direction == "up")
|
|
|
|
{
|
|
|
|
scrollbar.offset(-scrollbar.getLargeChange());
|
|
|
|
}
|
|
|
|
else if (direction == "down")
|
|
|
|
{
|
|
|
|
scrollbar.offset(scrollbar.getLargeChange());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys) << "Unknown scroll direction";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
|
|
|
|
{"reject", nullptr},
|
|
|
|
{"accept", nullptr},
|
2022-01-02 15:59:16 +01:00
|
|
|
{"search",
|
2022-12-17 18:33:17 +01:00
|
|
|
[this](const std::vector<QString> &) -> QString {
|
2022-01-02 15:59:16 +01:00
|
|
|
this->search_->setFocus();
|
|
|
|
this->search_->selectAll();
|
|
|
|
return "";
|
|
|
|
}},
|
2021-11-21 18:46:21 +01:00
|
|
|
};
|
2020-12-12 14:58:59 +01:00
|
|
|
|
2024-01-19 17:59:55 +01:00
|
|
|
this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory(
|
2021-11-21 18:46:21 +01:00
|
|
|
HotkeyCategory::PopupWindow, actions, this);
|
2017-09-15 17:23:49 +02:00
|
|
|
}
|
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
void EmotePopup::loadChannel(ChannelPtr channel)
|
2017-09-15 17:23:49 +02:00
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
BenchmarkGuard guard("loadChannel");
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
this->channel_ = std::move(channel);
|
2022-01-02 15:59:16 +01:00
|
|
|
this->twitchChannel_ = dynamic_cast<TwitchChannel *>(this->channel_.get());
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
this->setWindowTitle("Emotes in #" + this->channel_->getName());
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
if (this->twitchChannel_ == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
auto subChannel = std::make_shared<Channel>("", Channel::Type::None);
|
|
|
|
auto globalChannel = std::make_shared<Channel>("", Channel::Type::None);
|
|
|
|
auto channelChannel = std::make_shared<Channel>("", Channel::Type::None);
|
2017-12-17 02:18:13 +01:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
// twitch
|
2024-01-19 17:59:55 +01:00
|
|
|
addTwitchEmoteSets(getIApp()
|
|
|
|
->getAccounts()
|
|
|
|
->twitch.getCurrent()
|
|
|
|
->accessEmotes()
|
|
|
|
->emoteSets,
|
|
|
|
*globalChannel, *subChannel, this->channel_->getName());
|
2018-05-31 16:20:46 +02:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
// global
|
2022-08-28 12:20:47 +02:00
|
|
|
if (Settings::instance().enableBTTVGlobalEmotes)
|
|
|
|
{
|
|
|
|
addEmotes(*globalChannel, *getApp()->twitch->getBttvEmotes().emotes(),
|
|
|
|
"BetterTTV", MessageElementFlag::BttvEmote);
|
|
|
|
}
|
|
|
|
if (Settings::instance().enableFFZGlobalEmotes)
|
|
|
|
{
|
|
|
|
addEmotes(*globalChannel, *getApp()->twitch->getFfzEmotes().emotes(),
|
|
|
|
"FrankerFaceZ", MessageElementFlag::FfzEmote);
|
|
|
|
}
|
2022-10-16 13:22:17 +02:00
|
|
|
if (Settings::instance().enableSevenTVGlobalEmotes)
|
|
|
|
{
|
|
|
|
addEmotes(*globalChannel,
|
|
|
|
*getApp()->twitch->getSeventvEmotes().globalEmotes(), "7TV",
|
|
|
|
MessageElementFlag::SevenTVEmote);
|
|
|
|
}
|
2018-05-31 16:20:46 +02:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
// channel
|
2022-08-28 12:20:47 +02:00
|
|
|
if (Settings::instance().enableBTTVChannelEmotes)
|
|
|
|
{
|
|
|
|
addEmotes(*channelChannel, *this->twitchChannel_->bttvEmotes(),
|
|
|
|
"BetterTTV", MessageElementFlag::BttvEmote);
|
|
|
|
}
|
|
|
|
if (Settings::instance().enableFFZChannelEmotes)
|
|
|
|
{
|
|
|
|
addEmotes(*channelChannel, *this->twitchChannel_->ffzEmotes(),
|
|
|
|
"FrankerFaceZ", MessageElementFlag::FfzEmote);
|
|
|
|
}
|
2022-10-16 13:22:17 +02:00
|
|
|
if (Settings::instance().enableSevenTVChannelEmotes)
|
|
|
|
{
|
|
|
|
addEmotes(*channelChannel, *this->twitchChannel_->seventvEmotes(),
|
|
|
|
"7TV", MessageElementFlag::SevenTVEmote);
|
|
|
|
}
|
2018-05-31 16:20:46 +02:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
this->globalEmotesView_->setChannel(globalChannel);
|
|
|
|
this->subEmotesView_->setChannel(subChannel);
|
|
|
|
this->channelEmotesView_->setChannel(channelChannel);
|
2018-09-04 20:09:06 +02:00
|
|
|
|
2018-11-03 21:26:57 +01:00
|
|
|
if (subChannel->getMessageSnapshot().size() == 0)
|
2018-09-04 20:09:06 +02:00
|
|
|
{
|
|
|
|
MessageBuilder builder;
|
|
|
|
builder->flags.set(MessageFlag::Centered);
|
|
|
|
builder->flags.set(MessageFlag::DisableCompactEmotes);
|
|
|
|
builder.emplace<TextElement>("no subscription emotes available",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
subChannel->addMessage(builder.release());
|
|
|
|
}
|
2017-12-19 03:18:00 +01:00
|
|
|
}
|
|
|
|
|
2023-12-16 14:40:05 +01:00
|
|
|
bool EmotePopup::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
|
|
|
if (object == this->search_ && event->type() == QEvent::KeyPress)
|
|
|
|
{
|
|
|
|
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
|
|
|
|
if (keyEvent == QKeySequence::DeleteStartOfWord &&
|
|
|
|
this->search_->selectionLength() > 0)
|
|
|
|
{
|
|
|
|
this->search_->backspace();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-22 14:05:01 +01:00
|
|
|
void EmotePopup::filterTwitchEmotes(std::shared_ptr<Channel> searchChannel,
|
|
|
|
const QString &searchText)
|
2022-01-02 15:59:16 +01:00
|
|
|
{
|
2024-01-19 17:59:55 +01:00
|
|
|
auto twitchEmoteSets = getIApp()
|
|
|
|
->getAccounts()
|
|
|
|
->twitch.getCurrent()
|
|
|
|
->accessEmotes()
|
|
|
|
->emoteSets;
|
2022-01-02 15:59:16 +01:00
|
|
|
std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> twitchGlobalEmotes{};
|
|
|
|
|
|
|
|
for (const auto &set : twitchEmoteSets)
|
|
|
|
{
|
|
|
|
auto setCopy = std::make_shared<TwitchAccount::EmoteSet>(*set);
|
|
|
|
auto setIt =
|
|
|
|
std::remove_if(setCopy->emotes.begin(), setCopy->emotes.end(),
|
|
|
|
[searchText](auto &emote) {
|
|
|
|
return !emote.name.string.contains(
|
|
|
|
searchText, Qt::CaseInsensitive);
|
|
|
|
});
|
|
|
|
setCopy->emotes.resize(std::distance(setCopy->emotes.begin(), setIt));
|
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
if (!setCopy->emotes.empty())
|
|
|
|
{
|
2022-01-02 15:59:16 +01:00
|
|
|
twitchGlobalEmotes.push_back(setCopy);
|
2022-12-17 18:33:17 +01:00
|
|
|
}
|
2022-01-02 15:59:16 +01:00
|
|
|
}
|
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
auto bttvGlobalEmotes =
|
|
|
|
filterEmoteMap(searchText, getApp()->twitch->getBttvEmotes().emotes());
|
|
|
|
auto ffzGlobalEmotes =
|
|
|
|
filterEmoteMap(searchText, getApp()->twitch->getFfzEmotes().emotes());
|
|
|
|
auto seventvGlobalEmotes = filterEmoteMap(
|
2022-10-16 13:22:17 +02:00
|
|
|
searchText, getApp()->twitch->getSeventvEmotes().globalEmotes());
|
2022-01-02 15:59:16 +01:00
|
|
|
|
|
|
|
// twitch
|
2022-12-17 18:33:17 +01:00
|
|
|
addTwitchEmoteSets(twitchGlobalEmotes, *searchChannel, *searchChannel,
|
|
|
|
this->channel_->getName());
|
2022-01-02 15:59:16 +01:00
|
|
|
|
|
|
|
// global
|
2022-12-17 18:33:17 +01:00
|
|
|
if (!bttvGlobalEmotes.empty())
|
|
|
|
{
|
|
|
|
addEmotes(*searchChannel, bttvGlobalEmotes, "BetterTTV (Global)",
|
2022-01-02 15:59:16 +01:00
|
|
|
MessageElementFlag::BttvEmote);
|
2022-12-17 18:33:17 +01:00
|
|
|
}
|
|
|
|
if (!ffzGlobalEmotes.empty())
|
|
|
|
{
|
|
|
|
addEmotes(*searchChannel, ffzGlobalEmotes, "FrankerFaceZ (Global)",
|
2022-01-02 15:59:16 +01:00
|
|
|
MessageElementFlag::FfzEmote);
|
2022-12-17 18:33:17 +01:00
|
|
|
}
|
|
|
|
if (!seventvGlobalEmotes.empty())
|
2022-10-16 14:29:28 +02:00
|
|
|
{
|
2023-02-24 15:22:23 +01:00
|
|
|
addEmotes(*searchChannel, seventvGlobalEmotes, "7TV (Global)",
|
2022-10-16 14:29:28 +02:00
|
|
|
MessageElementFlag::SevenTVEmote);
|
|
|
|
}
|
2022-01-02 15:59:16 +01:00
|
|
|
|
2022-12-17 18:33:17 +01:00
|
|
|
if (this->twitchChannel_ == nullptr)
|
2022-01-22 14:05:01 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto bttvChannelEmotes =
|
2022-12-17 18:33:17 +01:00
|
|
|
filterEmoteMap(searchText, this->twitchChannel_->bttvEmotes());
|
2022-01-22 14:05:01 +01:00
|
|
|
auto ffzChannelEmotes =
|
2022-12-17 18:33:17 +01:00
|
|
|
filterEmoteMap(searchText, this->twitchChannel_->ffzEmotes());
|
|
|
|
auto seventvChannelEmotes =
|
|
|
|
filterEmoteMap(searchText, this->twitchChannel_->seventvEmotes());
|
2022-10-16 13:22:17 +02:00
|
|
|
|
2022-01-02 15:59:16 +01:00
|
|
|
// channel
|
2022-12-17 18:33:17 +01:00
|
|
|
if (!bttvChannelEmotes.empty())
|
|
|
|
{
|
|
|
|
addEmotes(*searchChannel, bttvChannelEmotes, "BetterTTV (Channel)",
|
2022-01-02 15:59:16 +01:00
|
|
|
MessageElementFlag::BttvEmote);
|
2022-12-17 18:33:17 +01:00
|
|
|
}
|
|
|
|
if (!ffzChannelEmotes.empty())
|
|
|
|
{
|
|
|
|
addEmotes(*searchChannel, ffzChannelEmotes, "FrankerFaceZ (Channel)",
|
2022-01-02 15:59:16 +01:00
|
|
|
MessageElementFlag::FfzEmote);
|
2022-12-17 18:33:17 +01:00
|
|
|
}
|
|
|
|
if (!seventvChannelEmotes.empty())
|
2022-10-16 13:22:17 +02:00
|
|
|
{
|
2023-02-24 15:22:23 +01:00
|
|
|
addEmotes(*searchChannel, seventvChannelEmotes, "7TV (Channel)",
|
2022-10-16 13:22:17 +02:00
|
|
|
MessageElementFlag::SevenTVEmote);
|
|
|
|
}
|
2022-01-22 14:05:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmotePopup::filterEmotes(const QString &searchText)
|
|
|
|
{
|
|
|
|
if (searchText.length() == 0)
|
|
|
|
{
|
|
|
|
this->notebook_->show();
|
|
|
|
this->searchView_->hide();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto searchChannel = std::make_shared<Channel>("", Channel::Type::None);
|
|
|
|
|
|
|
|
// true in special channels like /mentions
|
|
|
|
if (this->channel_->isTwitchChannel())
|
|
|
|
{
|
|
|
|
this->filterTwitchEmotes(searchChannel, searchText);
|
|
|
|
}
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2023-11-26 19:17:58 +01:00
|
|
|
std::vector<EmojiPtr> filteredEmojis{};
|
2022-01-22 14:05:01 +01:00
|
|
|
int emojiCount = 0;
|
|
|
|
|
2023-11-26 19:17:58 +01:00
|
|
|
const auto &emojis = getIApp()->getEmotes()->getEmojis()->getEmojis();
|
|
|
|
for (const auto &emoji : emojis)
|
|
|
|
{
|
|
|
|
if (emoji->shortCodes[0].contains(searchText, Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
filteredEmojis.push_back(emoji);
|
|
|
|
emojiCount++;
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 03:18:00 +01:00
|
|
|
// emojis
|
2022-01-02 15:59:16 +01:00
|
|
|
if (emojiCount > 0)
|
2022-12-17 18:33:17 +01:00
|
|
|
{
|
|
|
|
loadEmojis(*searchChannel, filteredEmojis, "Emojis");
|
|
|
|
}
|
2022-01-02 15:59:16 +01:00
|
|
|
|
|
|
|
this->searchView_->setChannel(searchChannel);
|
|
|
|
|
|
|
|
this->notebook_->hide();
|
|
|
|
this->searchView_->show();
|
|
|
|
}
|
|
|
|
|
2020-04-13 13:15:51 +02:00
|
|
|
void EmotePopup::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2024-01-19 17:59:55 +01:00
|
|
|
getIApp()->getWindows()->setEmotePopupPos(this->pos());
|
2022-12-17 18:33:17 +01:00
|
|
|
BaseWindow::closeEvent(event);
|
2020-04-13 13:15:51 +02:00
|
|
|
}
|
2022-12-17 18:33:17 +01:00
|
|
|
|
2017-09-23 18:37:51 +02:00
|
|
|
} // namespace chatterino
|