renamed resources to ResourceManager

This commit is contained in:
2017-12-31 02:21:33 +01:00
parent bfa2f1637e
commit ad001431f2
9 changed files with 44 additions and 44 deletions

View file

@ -61,7 +61,6 @@ SOURCES += \
src/messages/message.cpp \ src/messages/message.cpp \
src/messages/word.cpp \ src/messages/word.cpp \
src/messages/wordpart.cpp \ src/messages/wordpart.cpp \
src/resources.cpp \
src/widgets/notebook.cpp \ src/widgets/notebook.cpp \
src/widgets/helper/notebookbutton.cpp \ src/widgets/helper/notebookbutton.cpp \
src/widgets/helper/notebooktab.cpp \ src/widgets/helper/notebooktab.cpp \
@ -112,7 +111,8 @@ SOURCES += \
src/widgets/tooltipwidget.cpp \ src/widgets/tooltipwidget.cpp \
src/singletons/thememanager.cpp \ src/singletons/thememanager.cpp \
src/twitch/twitchaccountmanager.cpp \ src/twitch/twitchaccountmanager.cpp \
src/singletons/helper/completionmodel.cpp src/singletons/helper/completionmodel.cpp \
src/singletons/resourcemanager.cpp
HEADERS += \ HEADERS += \
src/precompiled_headers.hpp \ src/precompiled_headers.hpp \
@ -126,7 +126,6 @@ HEADERS += \
src/messages/message.hpp \ src/messages/message.hpp \
src/messages/word.hpp \ src/messages/word.hpp \
src/messages/wordpart.hpp \ src/messages/wordpart.hpp \
src/resources.hpp \
src/setting.hpp \ src/setting.hpp \
src/twitch/emotevalue.hpp \ src/twitch/emotevalue.hpp \
src/widgets/notebook.hpp \ src/widgets/notebook.hpp \
@ -194,7 +193,8 @@ HEADERS += \
src/singletons/thememanager.hpp \ src/singletons/thememanager.hpp \
src/twitch/twitchaccountmanager.hpp \ src/twitch/twitchaccountmanager.hpp \
src/singletons/helper/completionmodel.hpp \ src/singletons/helper/completionmodel.hpp \
src/singletons/helper/chatterinosetting.hpp src/singletons/helper/chatterinosetting.hpp \
src/singletons/resourcemanager.hpp
PRECOMPILED_HEADER = PRECOMPILED_HEADER =

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "singletons/ircmanager.hpp" #include "singletons/ircmanager.hpp"
#include "resources.hpp" #include "singletons/resourcemanager.hpp"
#include <QApplication> #include <QApplication>

View file

@ -6,7 +6,7 @@
#include "singletons/fontmanager.hpp" #include "singletons/fontmanager.hpp"
#include "singletons/ircmanager.hpp" #include "singletons/ircmanager.hpp"
#include "messages/link.hpp" #include "messages/link.hpp"
#include "resources.hpp" #include "singletons/resourcemanager.hpp"
#include "util/irchelpers.hpp" #include "util/irchelpers.hpp"
#include <ctime> #include <ctime>

View file

@ -1,7 +1,7 @@
#include "messagebuilder.hpp" #include "messagebuilder.hpp"
#include "singletons/thememanager.hpp" #include "singletons/thememanager.hpp"
#include "singletons/emotemanager.hpp" #include "singletons/emotemanager.hpp"
#include "resources.hpp" #include "singletons/resourcemanager.hpp"
#include <QDateTime> #include <QDateTime>

View file

@ -3,10 +3,10 @@
#include "channel.hpp" #include "channel.hpp"
#include "debug/log.hpp" #include "debug/log.hpp"
#include "messages/messageparseargs.hpp" #include "messages/messageparseargs.hpp"
#include "resources.hpp"
#include "singletons/accountmanager.hpp" #include "singletons/accountmanager.hpp"
#include "singletons/channelmanager.hpp" #include "singletons/channelmanager.hpp"
#include "singletons/emotemanager.hpp" #include "singletons/emotemanager.hpp"
#include "singletons/resourcemanager.hpp"
#include "singletons/settingsmanager.hpp" #include "singletons/settingsmanager.hpp"
#include "singletons/windowmanager.hpp" #include "singletons/windowmanager.hpp"
#include "twitch/twitchmessagebuilder.hpp" #include "twitch/twitchmessagebuilder.hpp"
@ -27,7 +27,7 @@ using namespace chatterino::messages;
namespace chatterino { namespace chatterino {
IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources, IrcManager::IrcManager(ChannelManager &_channelManager, ResourceManager &_resources,
AccountManager &_accountManager) AccountManager &_accountManager)
: channelManager(_channelManager) : channelManager(_channelManager)
, resources(_resources) , resources(_resources)
@ -70,7 +70,7 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
IrcManager &IrcManager::getInstance() IrcManager &IrcManager::getInstance()
{ {
static IrcManager instance(ChannelManager::getInstance(), Resources::getInstance(), static IrcManager instance(ChannelManager::getInstance(), ResourceManager::getInstance(),
AccountManager::getInstance()); AccountManager::getInstance());
return instance; return instance;
} }

View file

@ -19,14 +19,14 @@
namespace chatterino { namespace chatterino {
class ChannelManager; class ChannelManager;
class Resources; class ResourceManager;
class AccountManager; class AccountManager;
class IrcManager : public QObject class IrcManager : public QObject
{ {
// Q_OBJECT // Q_OBJECT
IrcManager(ChannelManager &channelManager, Resources &resources, IrcManager(ChannelManager &channelManager, ResourceManager &resources,
AccountManager &accountManager); AccountManager &accountManager);
public: public:
@ -55,7 +55,7 @@ public:
private: private:
ChannelManager &channelManager; ChannelManager &channelManager;
Resources &resources; ResourceManager &resources;
AccountManager &accountManager; AccountManager &accountManager;
// variables // variables

View file

@ -1,4 +1,4 @@
#include "resources.hpp" #include "resourcemanager.hpp"
//#include "singletons/emotemanager.hpp" //#include "singletons/emotemanager.hpp"
//#include "singletons/windowmanager.hpp" //#include "singletons/windowmanager.hpp"
#include "util/urlfetch.hpp" #include "util/urlfetch.hpp"
@ -16,7 +16,7 @@ inline messages::LazyLoadedImage *lli(const char *pixmapPath, qreal scale = 1)
} // namespace } // namespace
Resources::Resources() ResourceManager::ResourceManager()
: badgeStaff(lli(":/images/staff_bg.png")) : badgeStaff(lli(":/images/staff_bg.png"))
, badgeAdmin(lli(":/images/admin_bg.png")) , badgeAdmin(lli(":/images/admin_bg.png"))
, badgeGlobalModerator(lli(":/images/globalmod_bg.png")) , badgeGlobalModerator(lli(":/images/globalmod_bg.png"))
@ -41,13 +41,13 @@ Resources::Resources()
this->loadChatterinoBadges(); this->loadChatterinoBadges();
} }
Resources &Resources::getInstance() ResourceManager &ResourceManager::getInstance()
{ {
static Resources instance; static ResourceManager instance;
return instance; return instance;
} }
Resources::BadgeVersion::BadgeVersion(QJsonObject &&root) ResourceManager::BadgeVersion::BadgeVersion(QJsonObject &&root)
: badgeImage1x(new messages::LazyLoadedImage(root.value("image_url_1x").toString())) : badgeImage1x(new messages::LazyLoadedImage(root.value("image_url_1x").toString()))
, badgeImage2x(new messages::LazyLoadedImage(root.value("image_url_2x").toString())) , badgeImage2x(new messages::LazyLoadedImage(root.value("image_url_2x").toString()))
, badgeImage4x(new messages::LazyLoadedImage(root.value("image_url_4x").toString())) , badgeImage4x(new messages::LazyLoadedImage(root.value("image_url_4x").toString()))
@ -58,7 +58,7 @@ Resources::BadgeVersion::BadgeVersion(QJsonObject &&root)
{ {
} }
void Resources::loadChannelData(const QString &roomID, bool bypassCache) void ResourceManager::loadChannelData(const QString &roomID, bool bypassCache)
{ {
qDebug() << "Load channel data for" << roomID; qDebug() << "Load channel data for" << roomID;
@ -70,7 +70,7 @@ void Resources::loadChannelData(const QString &roomID, bool bypassCache)
req.getJSON([this, roomID](QJsonObject &root) { req.getJSON([this, roomID](QJsonObject &root) {
QJsonObject sets = root.value("badge_sets").toObject(); QJsonObject sets = root.value("badge_sets").toObject();
Resources::Channel &ch = this->channels[roomID]; ResourceManager::Channel &ch = this->channels[roomID];
for (QJsonObject::iterator it = sets.begin(); it != sets.end(); ++it) { for (QJsonObject::iterator it = sets.begin(); it != sets.end(); ++it) {
QJsonObject versions = it.value().toObject().value("versions").toObject(); QJsonObject versions = it.value().toObject().value("versions").toObject();
@ -91,7 +91,7 @@ void Resources::loadChannelData(const QString &roomID, bool bypassCache)
}); });
} }
void Resources::loadDynamicTwitchBadges() void ResourceManager::loadDynamicTwitchBadges()
{ {
static QString url("https://badges.twitch.tv/v1/badges/global/display?language=en"); static QString url("https://badges.twitch.tv/v1/badges/global/display?language=en");
@ -119,7 +119,7 @@ void Resources::loadDynamicTwitchBadges()
}); });
} }
void Resources::loadChatterinoBadges() void ResourceManager::loadChatterinoBadges()
{ {
this->chatterinoBadges.clear(); this->chatterinoBadges.clear();

View file

@ -8,12 +8,12 @@
namespace chatterino { namespace chatterino {
class Resources class ResourceManager
{ {
explicit Resources(); ResourceManager();
public: public:
static Resources &getInstance(); static ResourceManager &getInstance();
messages::LazyLoadedImage *badgeStaff; messages::LazyLoadedImage *badgeStaff;
messages::LazyLoadedImage *badgeAdmin; messages::LazyLoadedImage *badgeAdmin;

View file

@ -1,6 +1,6 @@
#include "twitchmessagebuilder.hpp" #include "twitchmessagebuilder.hpp"
#include "debug/log.hpp" #include "debug/log.hpp"
#include "resources.hpp" #include "singletons/resourcemanager.hpp"
#include "singletons/emotemanager.hpp" #include "singletons/emotemanager.hpp"
#include "singletons/ircmanager.hpp" #include "singletons/ircmanager.hpp"
#include "singletons/settingsmanager.hpp" #include "singletons/settingsmanager.hpp"
@ -482,9 +482,9 @@ void TwitchMessageBuilder::appendModerationButtons()
static QString buttonBanTooltip("Ban user"); static QString buttonBanTooltip("Ban user");
static QString buttonTimeoutTooltip("Timeout user"); static QString buttonTimeoutTooltip("Timeout user");
this->appendWord(Word(Resources::getInstance().buttonBan, Word::ButtonBan, QString(), this->appendWord(Word(ResourceManager::getInstance().buttonBan, Word::ButtonBan, QString(),
buttonBanTooltip, Link(Link::UserBan, ircMessage->account()))); buttonBanTooltip, Link(Link::UserBan, ircMessage->account())));
this->appendWord(Word(Resources::getInstance().buttonTimeout, Word::ButtonTimeout, QString(), this->appendWord(Word(ResourceManager::getInstance().buttonTimeout, Word::ButtonTimeout, QString(),
buttonTimeoutTooltip, Link(Link::UserTimeout, ircMessage->account()))); buttonTimeoutTooltip, Link(Link::UserTimeout, ircMessage->account())));
} }
@ -567,7 +567,7 @@ bool TwitchMessageBuilder::appendEmote(EmoteData &emoteData)
void TwitchMessageBuilder::parseTwitchBadges() void TwitchMessageBuilder::parseTwitchBadges()
{ {
const auto &channelResources = Resources::getInstance().channels[this->roomID]; const auto &channelResources = ResourceManager::getInstance().channels[this->roomID];
auto iterator = this->tags.find("badges"); auto iterator = this->tags.find("badges");
@ -584,7 +584,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
} }
if (badge.startsWith("bits/")) { if (badge.startsWith("bits/")) {
if (!Resources::getInstance().dynamicBadgesLoaded) { if (!ResourceManager::getInstance().dynamicBadgesLoaded) {
// Do nothing // Do nothing
continue; continue;
} }
@ -593,7 +593,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
std::string versionKey = cheerAmountQS.toStdString(); std::string versionKey = cheerAmountQS.toStdString();
try { try {
auto &badgeSet = Resources::getInstance().badgeSets.at("bits"); auto &badgeSet = ResourceManager::getInstance().badgeSets.at("bits");
try { try {
auto &badgeVersion = badgeSet.versions.at(versionKey); auto &badgeVersion = badgeSet.versions.at(versionKey);
@ -609,34 +609,34 @@ void TwitchMessageBuilder::parseTwitchBadges()
debug::Log("No badge set with key bits. Exception: {}", e.what()); debug::Log("No badge set with key bits. Exception: {}", e.what());
} }
} else if (badge == "staff/1") { } else if (badge == "staff/1") {
appendWord(Word(Resources::getInstance().badgeStaff, Word::BadgeGlobalAuthority, appendWord(Word(ResourceManager::getInstance().badgeStaff, Word::BadgeGlobalAuthority,
QString(), QString("Twitch Staff"))); QString(), QString("Twitch Staff")));
} else if (badge == "admin/1") { } else if (badge == "admin/1") {
appendWord(Word(Resources::getInstance().badgeAdmin, Word::BadgeGlobalAuthority, appendWord(Word(ResourceManager::getInstance().badgeAdmin, Word::BadgeGlobalAuthority,
QString(), QString("Twitch Admin"))); QString(), QString("Twitch Admin")));
} else if (badge == "global_mod/1") { } else if (badge == "global_mod/1") {
appendWord(Word(Resources::getInstance().badgeGlobalModerator, appendWord(Word(ResourceManager::getInstance().badgeGlobalModerator,
Word::BadgeGlobalAuthority, QString(), QString("Global Moderator"))); Word::BadgeGlobalAuthority, QString(), QString("Global Moderator")));
} else if (badge == "moderator/1") { } else if (badge == "moderator/1") {
// TODO: Implement custom FFZ moderator badge // TODO: Implement custom FFZ moderator badge
appendWord(Word(Resources::getInstance().badgeModerator, Word::BadgeChannelAuthority, appendWord(Word(ResourceManager::getInstance().badgeModerator, Word::BadgeChannelAuthority,
QString(), QString(),
QString("Channel Moderator"))); // custom badge QString("Channel Moderator"))); // custom badge
} else if (badge == "turbo/1") { } else if (badge == "turbo/1") {
appendWord(Word(Resources::getInstance().badgeTurbo, Word::BadgeVanity, QString(), appendWord(Word(ResourceManager::getInstance().badgeTurbo, Word::BadgeVanity, QString(),
QString("Turbo Subscriber"))); QString("Turbo Subscriber")));
} else if (badge == "broadcaster/1") { } else if (badge == "broadcaster/1") {
appendWord(Word(Resources::getInstance().badgeBroadcaster, Word::BadgeChannelAuthority, appendWord(Word(ResourceManager::getInstance().badgeBroadcaster, Word::BadgeChannelAuthority,
QString(), QString("Channel Broadcaster"))); QString(), QString("Channel Broadcaster")));
} else if (badge == "premium/1") { } else if (badge == "premium/1") {
appendWord(Word(Resources::getInstance().badgePremium, Word::BadgeVanity, QString(), appendWord(Word(ResourceManager::getInstance().badgePremium, Word::BadgeVanity, QString(),
QString("Twitch Prime"))); QString("Twitch Prime")));
} else if (badge.startsWith("partner/")) { } else if (badge.startsWith("partner/")) {
int index = badge.midRef(8).toInt(); int index = badge.midRef(8).toInt();
switch (index) { switch (index) {
case 1: { case 1: {
appendWord(Word(Resources::getInstance().badgeVerified, Word::BadgeVanity, appendWord(Word(ResourceManager::getInstance().badgeVerified, Word::BadgeVanity,
QString(), "Twitch Verified")); QString(), "Twitch Verified"));
} break; } break;
default: { default: {
@ -652,7 +652,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
auto badgeSetIt = channelResources.badgeSets.find("subscriber"); auto badgeSetIt = channelResources.badgeSets.find("subscriber");
if (badgeSetIt == channelResources.badgeSets.end()) { if (badgeSetIt == channelResources.badgeSets.end()) {
// Fall back to default badge // Fall back to default badge
appendWord(Word(Resources::getInstance().badgeSubscriber, appendWord(Word(ResourceManager::getInstance().badgeSubscriber,
Word::Flags::BadgeSubscription, QString(), Word::Flags::BadgeSubscription, QString(),
QString("Twitch Subscriber"))); QString("Twitch Subscriber")));
continue; continue;
@ -666,7 +666,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
if (badgeVersionIt == badgeSet.versions.end()) { if (badgeVersionIt == badgeSet.versions.end()) {
// Fall back to default badge // Fall back to default badge
appendWord(Word(Resources::getInstance().badgeSubscriber, appendWord(Word(ResourceManager::getInstance().badgeSubscriber,
Word::Flags::BadgeSubscription, QString(), Word::Flags::BadgeSubscription, QString(),
QString("Twitch Subscriber"))); QString("Twitch Subscriber")));
continue; continue;
@ -677,7 +677,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
appendWord(Word(badgeVersion.badgeImage1x, Word::Flags::BadgeSubscription, QString(), appendWord(Word(badgeVersion.badgeImage1x, Word::Flags::BadgeSubscription, QString(),
QString("Twitch " + QString::fromStdString(badgeVersion.title)))); QString("Twitch " + QString::fromStdString(badgeVersion.title))));
} else { } else {
if (!Resources::getInstance().dynamicBadgesLoaded) { if (!ResourceManager::getInstance().dynamicBadgesLoaded) {
// Do nothing // Do nothing
continue; continue;
} }
@ -695,7 +695,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
std::string versionKey = parts[1].toStdString(); std::string versionKey = parts[1].toStdString();
try { try {
auto &badgeSet = Resources::getInstance().badgeSets.at(badgeSetKey); auto &badgeSet = ResourceManager::getInstance().badgeSets.at(badgeSetKey);
try { try {
auto &badgeVersion = badgeSet.versions.at(versionKey); auto &badgeVersion = badgeSet.versions.at(versionKey);
@ -717,7 +717,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
void TwitchMessageBuilder::parseChatterinoBadges() void TwitchMessageBuilder::parseChatterinoBadges()
{ {
auto &badges = Resources::getInstance().chatterinoBadges; auto &badges = ResourceManager::getInstance().chatterinoBadges;
auto it = badges.find(this->userName.toStdString()); auto it = badges.find(this->userName.toStdString());
if (it == badges.end()) { if (it == badges.end()) {