refactored the managers
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
static void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting);
|
||||
|
||||
template <typename Type>
|
||||
class ChatterinoSetting : public pajlada::Settings::Setting<Type>
|
||||
{
|
||||
public:
|
||||
ChatterinoSetting(const std::string &_path, const Type &_defaultValue)
|
||||
: pajlada::Settings::Setting<Type>(_path, _defaultValue)
|
||||
{
|
||||
_registerSetting(this->data);
|
||||
}
|
||||
|
||||
void saveRecall();
|
||||
|
||||
ChatterinoSetting &operator=(const Type &newValue)
|
||||
{
|
||||
assert(this->data != nullptr);
|
||||
|
||||
this->setValue(newValue);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
ChatterinoSetting &operator=(const T2 &newValue)
|
||||
{
|
||||
assert(this->data != nullptr);
|
||||
|
||||
this->setValue(newValue);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChatterinoSetting &operator=(Type &&newValue) noexcept
|
||||
{
|
||||
assert(this->data != nullptr);
|
||||
|
||||
this->setValue(std::move(newValue));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Type &rhs) const
|
||||
{
|
||||
assert(this->data != nullptr);
|
||||
|
||||
return this->getValue() == rhs;
|
||||
}
|
||||
|
||||
bool operator!=(const Type &rhs) const
|
||||
{
|
||||
assert(this->data != nullptr);
|
||||
|
||||
return this->getValue() != rhs;
|
||||
}
|
||||
|
||||
operator const Type() const
|
||||
{
|
||||
assert(this->data != nullptr);
|
||||
|
||||
return this->getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "completionmodel.hpp"
|
||||
|
||||
#include "common.hpp"
|
||||
#include "debug/log.hpp"
|
||||
#include "singletons/channelmanager.hpp"
|
||||
#include "singletons/completionmanager.hpp"
|
||||
#include "singletons/emotemanager.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
CompletionModel::CompletionModel(const QString &_channelName)
|
||||
: channelName(_channelName)
|
||||
{
|
||||
}
|
||||
|
||||
void CompletionModel::refresh()
|
||||
{
|
||||
// debug::Log("[CompletionModel:{}] Refreshing...]", this->channelName);
|
||||
|
||||
auto &emoteManager = EmoteManager::getInstance();
|
||||
this->emotes.clear();
|
||||
|
||||
// User-specific: Twitch Emotes
|
||||
// TODO: Fix this so it properly updates with the proper api. oauth token needs proper scope
|
||||
for (const auto &m : emoteManager.twitchAccountEmotes) {
|
||||
for (const auto &emoteName : m.second.emoteCodes) {
|
||||
this->addString(emoteName);
|
||||
}
|
||||
}
|
||||
|
||||
// Global: BTTV Global Emotes
|
||||
std::vector<std::string> &bttvGlobalEmoteCodes = emoteManager.bttvGlobalEmoteCodes;
|
||||
for (const auto &m : bttvGlobalEmoteCodes) {
|
||||
this->addString(m);
|
||||
}
|
||||
|
||||
// Global: FFZ Global Emotes
|
||||
std::vector<std::string> &ffzGlobalEmoteCodes = emoteManager.ffzGlobalEmoteCodes;
|
||||
for (const auto &m : ffzGlobalEmoteCodes) {
|
||||
this->addString(m);
|
||||
}
|
||||
|
||||
// Channel-specific: BTTV Channel Emotes
|
||||
std::vector<std::string> &bttvChannelEmoteCodes =
|
||||
emoteManager.bttvChannelEmoteCodes[this->channelName.toStdString()];
|
||||
for (const auto &m : bttvChannelEmoteCodes) {
|
||||
this->addString(m);
|
||||
}
|
||||
|
||||
// Channel-specific: FFZ Channel Emotes
|
||||
std::vector<std::string> &ffzChannelEmoteCodes =
|
||||
emoteManager.ffzChannelEmoteCodes[this->channelName.toStdString()];
|
||||
for (const auto &m : ffzChannelEmoteCodes) {
|
||||
this->addString(m);
|
||||
}
|
||||
|
||||
// Global: Emojis
|
||||
const auto &emojiShortCodes = emoteManager.emojiShortCodes;
|
||||
for (const auto &m : emojiShortCodes) {
|
||||
this->addString(":" + m + ":");
|
||||
}
|
||||
|
||||
// Channel-specific: Usernames
|
||||
auto c = ChannelManager::getInstance().getTwitchChannel(this->channelName);
|
||||
auto usernames = c->getUsernamesForCompletions();
|
||||
for (const auto &name : usernames) {
|
||||
assert(!name.displayName.isEmpty());
|
||||
this->addString(name.displayName);
|
||||
this->addString('@' + name.displayName);
|
||||
|
||||
if (!name.localizedName.isEmpty()) {
|
||||
this->addString(name.localizedName);
|
||||
this->addString('@' + name.localizedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CompletionModel::addString(const std::string &str)
|
||||
{
|
||||
// Always add a space at the end of completions
|
||||
this->emotes.push_back(qS(str) + " ");
|
||||
}
|
||||
|
||||
void CompletionModel::addString(const QString &str)
|
||||
{
|
||||
// Always add a space at the end of completions
|
||||
this->emotes.push_back(str + " ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QVector>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace chatterino {
|
||||
class CompletionModel : public QAbstractListModel
|
||||
{
|
||||
public:
|
||||
CompletionModel(const QString &_channelName);
|
||||
|
||||
virtual int columnCount(const QModelIndex &) const override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int) const override
|
||||
{
|
||||
// TODO: Implement more safely
|
||||
return QVariant(this->emotes.at(index.row()));
|
||||
}
|
||||
|
||||
virtual int rowCount(const QModelIndex &) const override
|
||||
{
|
||||
return this->emotes.size();
|
||||
}
|
||||
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
void addString(const std::string &str);
|
||||
void addString(const QString &str);
|
||||
|
||||
QVector<QString> emotes;
|
||||
|
||||
QString channelName;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user