2017-09-16 16:20:10 +02:00
|
|
|
#include "emotepopup.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
#include "application.hpp"
|
2018-05-26 20:25:00 +02:00
|
|
|
#include "controllers/accounts/accountcontroller.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
#include "messages/messagebuilder.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
#include "providers/twitch/twitchchannel.hpp"
|
2018-04-18 17:51:53 +02:00
|
|
|
#include "widgets/notebook.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
#include <QHBoxLayout>
|
2018-05-23 13:54:42 +02:00
|
|
|
#include <QShortcut>
|
2018-04-27 22:11:19 +02:00
|
|
|
#include <QTabWidget>
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
using namespace chatterino::providers::twitch;
|
2017-09-16 00:05:06 +02:00
|
|
|
using namespace chatterino::messages;
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
EmotePopup::EmotePopup()
|
2018-05-23 22:27:29 +02:00
|
|
|
: BaseWindow(nullptr, BaseWindow::EnableCustomFrame)
|
2017-09-15 17:23:49 +02:00
|
|
|
{
|
2017-12-19 03:18:00 +01:00
|
|
|
this->viewEmotes = new ChannelView();
|
|
|
|
this->viewEmojis = new ChannelView();
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-05-31 16:20:46 +02:00
|
|
|
this->viewEmotes->setOverrideFlags(MessageElement::Flags(
|
2018-01-27 21:13:22 +01:00
|
|
|
MessageElement::Default | MessageElement::AlwaysShow | MessageElement::EmoteImages));
|
2018-05-31 16:20:46 +02:00
|
|
|
this->viewEmojis->setOverrideFlags(MessageElement::Flags(
|
2018-01-27 21:13:22 +01:00
|
|
|
MessageElement::Default | MessageElement::AlwaysShow | MessageElement::EmoteImages));
|
|
|
|
|
2017-12-28 00:48:21 +01:00
|
|
|
this->viewEmotes->setEnableScrollingToBottom(false);
|
|
|
|
this->viewEmojis->setEnableScrollingToBottom(false);
|
|
|
|
|
2018-04-18 17:51:53 +02:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
|
|
|
this->getLayoutContainer()->setLayout(layout);
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
Notebook *notebook = new Notebook(this);
|
2018-04-18 17:51:53 +02:00
|
|
|
layout->addWidget(notebook);
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
|
|
|
notebook->addPage(this->viewEmotes, "Emotes");
|
|
|
|
notebook->addPage(this->viewEmojis, "Emojis");
|
2017-12-19 03:18:00 +01:00
|
|
|
|
|
|
|
this->loadEmojis();
|
2018-01-24 20:58:53 +01:00
|
|
|
|
|
|
|
this->viewEmotes->linkClicked.connect(
|
|
|
|
[this](const Link &link) { this->linkClicked.invoke(link); });
|
|
|
|
this->viewEmojis->linkClicked.connect(
|
|
|
|
[this](const Link &link) { this->linkClicked.invoke(link); });
|
2017-09-15 17:23:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 13:15:41 +01:00
|
|
|
void EmotePopup::loadChannel(ChannelPtr _channel)
|
2017-09-15 17:23:49 +02:00
|
|
|
{
|
2018-04-18 18:55:49 +02:00
|
|
|
this->setWindowTitle("Emotes from " + _channel->name);
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(_channel.get());
|
|
|
|
|
|
|
|
if (channel == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
ChannelPtr emoteChannel(new Channel("", Channel::None));
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
auto addEmotes = [&](util::EmoteMap &map, const QString &title, const QString &emoteDesc) {
|
2017-09-16 00:05:06 +02:00
|
|
|
// TITLE
|
|
|
|
messages::MessageBuilder builder1;
|
|
|
|
|
2018-01-28 03:48:15 +01:00
|
|
|
builder1.append(new TextElement(title, MessageElement::Text));
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
builder1.getMessage()->flags |= Message::Centered;
|
2017-09-16 00:05:06 +02:00
|
|
|
emoteChannel->addMessage(builder1.getMessage());
|
|
|
|
|
|
|
|
// EMOTES
|
|
|
|
messages::MessageBuilder builder2;
|
2018-04-18 09:12:29 +02:00
|
|
|
builder2.getMessage()->flags |= Message::Centered;
|
|
|
|
builder2.getMessage()->flags |= Message::DisableCompactEmotes;
|
2018-01-07 02:56:45 +01:00
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
map.each([&](const QString &key, const util::EmoteData &value) {
|
2018-01-28 03:48:15 +01:00
|
|
|
builder2.append((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
|
2018-02-05 15:11:50 +01:00
|
|
|
->setLink(Link(Link::InsertText, key)));
|
2017-09-16 00:05:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
emoteChannel->addMessage(builder2.getMessage());
|
|
|
|
};
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2017-12-17 02:18:13 +01:00
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
QString userID = app->accounts->twitch.getCurrent()->getUserId();
|
2018-04-15 15:05:12 +02:00
|
|
|
|
2018-05-31 16:20:46 +02:00
|
|
|
// fourtf: the entire emote manager needs to be refactored so there's no point in trying to
|
|
|
|
// fix this pile of garbage
|
2018-06-07 12:36:06 +02:00
|
|
|
for (const auto &set : app->emotes->twitch.emotes[userID].emoteSets) {
|
2018-05-31 16:20:46 +02:00
|
|
|
// TITLE
|
|
|
|
messages::MessageBuilder builder1;
|
|
|
|
|
|
|
|
builder1.append(new TextElement("Twitch Account Emotes", MessageElement::Text));
|
|
|
|
|
|
|
|
builder1.getMessage()->flags |= Message::Centered;
|
|
|
|
emoteChannel->addMessage(builder1.getMessage());
|
|
|
|
|
|
|
|
// EMOTES
|
|
|
|
messages::MessageBuilder builder2;
|
|
|
|
builder2.getMessage()->flags |= Message::Centered;
|
|
|
|
builder2.getMessage()->flags |= Message::DisableCompactEmotes;
|
|
|
|
|
2018-06-07 13:01:06 +02:00
|
|
|
for (const auto &emote : set.emotes) {
|
2018-05-31 16:20:46 +02:00
|
|
|
[&](const QString &key, const util::EmoteData &value) {
|
|
|
|
builder2.append((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
|
|
|
|
->setLink(Link(Link::InsertText, key)));
|
2018-06-07 13:01:06 +02:00
|
|
|
}(emote.code, app->emotes->twitch.getEmoteById(emote.id, emote.code));
|
2018-05-31 16:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
emoteChannel->addMessage(builder2.getMessage());
|
|
|
|
}
|
|
|
|
|
2018-06-05 17:39:49 +02:00
|
|
|
addEmotes(app->emotes->bttv.globalEmotes, "BetterTTV Global Emotes", "BetterTTV Global Emote");
|
2017-09-16 00:05:06 +02:00
|
|
|
addEmotes(*channel->bttvChannelEmotes.get(), "BetterTTV Channel Emotes",
|
|
|
|
"BetterTTV Channel Emote");
|
2018-06-05 18:07:17 +02:00
|
|
|
addEmotes(app->emotes->ffz.globalEmotes, "FrankerFaceZ Global Emotes",
|
2017-09-16 00:05:06 +02:00
|
|
|
"FrankerFaceZ Global Emote");
|
|
|
|
addEmotes(*channel->ffzChannelEmotes.get(), "FrankerFaceZ Channel Emotes",
|
|
|
|
"FrankerFaceZ Channel Emote");
|
2017-09-15 17:23:49 +02:00
|
|
|
|
2017-12-19 03:18:00 +01:00
|
|
|
this->viewEmotes->setChannel(emoteChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmotePopup::loadEmojis()
|
|
|
|
{
|
2018-06-05 18:53:49 +02:00
|
|
|
auto &emojis = getApp()->emotes->emojis.emojis;
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
ChannelPtr emojiChannel(new Channel("", Channel::None));
|
2017-12-19 03:18:00 +01:00
|
|
|
|
|
|
|
// title
|
|
|
|
messages::MessageBuilder builder1;
|
|
|
|
|
2018-01-28 03:48:15 +01:00
|
|
|
builder1.append(new TextElement("emojis", MessageElement::Text));
|
2018-04-18 09:12:29 +02:00
|
|
|
builder1.getMessage()->flags |= Message::Centered;
|
2017-12-19 03:18:00 +01:00
|
|
|
emojiChannel->addMessage(builder1.getMessage());
|
|
|
|
|
|
|
|
// emojis
|
|
|
|
messages::MessageBuilder builder;
|
2018-04-18 09:12:29 +02:00
|
|
|
builder.getMessage()->flags |= Message::Centered;
|
|
|
|
builder.getMessage()->flags |= Message::DisableCompactEmotes;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-04-14 21:59:51 +02:00
|
|
|
emojis.each([&builder](const QString &key, const auto &value) {
|
2018-06-22 22:42:53 +02:00
|
|
|
builder.append(
|
|
|
|
(new EmoteElement(value->emoteData, MessageElement::Flags::AlwaysShow))
|
|
|
|
->setLink(Link(Link::Type::InsertText, ":" + value->shortCodes[0] + ":")));
|
2018-01-11 20:16:25 +01:00
|
|
|
});
|
2017-12-19 03:18:00 +01:00
|
|
|
emojiChannel->addMessage(builder.getMessage());
|
2017-09-16 16:20:10 +02:00
|
|
|
|
2017-12-19 03:18:00 +01:00
|
|
|
this->viewEmojis->setChannel(emojiChannel);
|
2017-09-15 17:23:49 +02:00
|
|
|
}
|
2017-12-17 02:10:35 +01:00
|
|
|
|
2017-09-23 18:37:51 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|