2017-07-09 17:58:59 +02:00
|
|
|
#include "completionmanager.hpp"
|
2017-07-23 14:16:13 +02:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "emotemanager.hpp"
|
2017-07-09 17:58:59 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2017-08-01 00:10:02 +02:00
|
|
|
void CompletionModel::addString(const std::string &str)
|
|
|
|
{
|
|
|
|
// Always add a space at the end of completions
|
|
|
|
this->emotes.push_back(qS(str) + " ");
|
|
|
|
}
|
|
|
|
|
2017-07-23 14:16:13 +02:00
|
|
|
CompletionManager::CompletionManager(EmoteManager &_emoteManager)
|
|
|
|
: emoteManager(_emoteManager)
|
2017-07-09 17:58:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CompletionModel *CompletionManager::createModel(const std::string &channelName)
|
|
|
|
{
|
|
|
|
CompletionModel *ret = new CompletionModel();
|
|
|
|
|
2017-07-23 14:16:13 +02:00
|
|
|
this->updateModel(ret, channelName);
|
|
|
|
|
|
|
|
this->emoteManager.bttvGlobalEmoteCodes.updated.connect([=]() {
|
|
|
|
this->updateModel(ret, channelName); //
|
|
|
|
});
|
|
|
|
|
|
|
|
this->emoteManager.ffzGlobalEmoteCodes.updated.connect([=]() {
|
|
|
|
this->updateModel(ret, channelName); //
|
|
|
|
});
|
|
|
|
|
|
|
|
this->emoteManager.bttvChannelEmoteCodes[channelName].updated.connect([=]() {
|
|
|
|
this->updateModel(ret, channelName); //
|
|
|
|
});
|
|
|
|
|
|
|
|
this->emoteManager.ffzChannelEmoteCodes[channelName].updated.connect([=]() {
|
|
|
|
this->updateModel(ret, channelName); //
|
|
|
|
});
|
|
|
|
|
2017-07-09 17:58:59 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompletionManager::updateModel(CompletionModel *model, const std::string &channelName)
|
|
|
|
{
|
2017-07-23 14:16:13 +02:00
|
|
|
model->emotes.clear();
|
|
|
|
|
|
|
|
for (const auto &m : this->emoteManager.twitchAccountEmotes) {
|
|
|
|
for (const auto &emoteName : m.second.emoteCodes) {
|
2017-08-01 00:10:02 +02:00
|
|
|
model->addString(emoteName);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> &bttvGlobalEmoteCodes = this->emoteManager.bttvGlobalEmoteCodes;
|
|
|
|
for (const auto &m : bttvGlobalEmoteCodes) {
|
2017-08-01 00:10:02 +02:00
|
|
|
model->addString(m);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> &ffzGlobalEmoteCodes = this->emoteManager.ffzGlobalEmoteCodes;
|
|
|
|
for (const auto &m : ffzGlobalEmoteCodes) {
|
2017-08-01 00:10:02 +02:00
|
|
|
model->addString(m);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> &bttvChannelEmoteCodes =
|
|
|
|
this->emoteManager.bttvChannelEmoteCodes[channelName];
|
|
|
|
for (const auto &m : bttvChannelEmoteCodes) {
|
2017-08-01 00:10:02 +02:00
|
|
|
model->addString(m);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> &ffzChannelEmoteCodes =
|
|
|
|
this->emoteManager.ffzChannelEmoteCodes[channelName];
|
|
|
|
for (const auto &m : ffzChannelEmoteCodes) {
|
2017-08-01 00:10:02 +02:00
|
|
|
model->addString(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &emojiShortCodes = this->emoteManager.emojiShortCodes;
|
|
|
|
for (const auto &m : emojiShortCodes) {
|
|
|
|
model->addString(":" + m + ":");
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
2017-07-09 17:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|