Huge refactor

- Remove some underscore-prefixes
 - Start using this-> more
 - Remove a few of the singletons (We pass references to managers to
         things that need it now. Might not be much better, but for now
         it works. It also shows what places might be slightly wrong
         designed)
This commit is contained in:
Rasmus Karlsson
2017-06-13 21:13:58 +02:00
parent 55b04ee7eb
commit 59d383c161
37 changed files with 630 additions and 523 deletions
+29 -36
View File
@@ -5,7 +5,6 @@
#include "concurrentmap.hpp"
#include "messages/lazyloadedimage.hpp"
#include "twitch/emotevalue.hpp"
#include "windowmanager.hpp"
#include <QMap>
#include <QMutex>
@@ -13,25 +12,33 @@
#include <boost/signals2.hpp>
namespace chatterino {
class WindowManager;
class Resources;
class EmoteManager
{
public:
static EmoteManager &getInstance()
{
return instance;
}
using FFZEmoteMap = ConcurrentMap<QString, messages::LazyLoadedImage *>;
using BTTVEmoteMap = ConcurrentMap<QString, messages::LazyLoadedImage *>;
using ChatterinoEmoteMap = ConcurrentMap<QString, messages::LazyLoadedImage *>;
ConcurrentMap<QString, twitch::EmoteValue *> &getTwitchEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getBttvEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getFfzEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getChatterinoEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getBttvChannelEmoteFromCaches();
ConcurrentMap<int, messages::LazyLoadedImage *> &getFfzChannelEmoteFromCaches();
ConcurrentMap<long, messages::LazyLoadedImage *> &getTwitchEmoteFromCache();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getMiscImageFromCache();
EmoteManager(WindowManager &_windowManager, Resources &_resources);
void loadGlobalEmotes();
void reloadBTTVChannelEmotes(const QString &channelName, BTTVEmoteMap &channelEmoteMap);
void reloadFFZChannelEmotes(const QString &channelName, FFZEmoteMap &channelEmoteMap);
ConcurrentMap<QString, twitch::EmoteValue *> &getTwitchEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getBTTVEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getFFZEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getChatterinoEmotes();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getBTTVChannelEmoteFromCaches();
ConcurrentMap<int, messages::LazyLoadedImage *> &getFFZChannelEmoteFromCaches();
ConcurrentMap<long, messages::LazyLoadedImage *> &getTwitchEmoteFromCache();
ConcurrentMap<QString, messages::LazyLoadedImage *> &getMiscImageFromCache();
messages::LazyLoadedImage *getCheerImage(long long int amount, bool animated);
messages::LazyLoadedImage *getCheerBadge(long long int amount);
@@ -47,29 +54,15 @@ public:
_generation++;
}
boost::signals2::signal<void()> &getGifUpdateSignal()
{
if (!_gifUpdateTimerInitiated) {
_gifUpdateTimerInitiated = true;
_gifUpdateTimer.setInterval(30);
_gifUpdateTimer.start();
QObject::connect(&_gifUpdateTimer, &QTimer::timeout, [this] {
_gifUpdateTimerSignal();
WindowManager::getInstance().repaintGifEmotes();
});
}
return _gifUpdateTimerSignal;
}
boost::signals2::signal<void()> &getGifUpdateSignal();
private:
static EmoteManager instance;
WindowManager &windowManager;
Resources &resources;
EmoteManager();
ConcurrentMap<QString, messages::LazyLoadedImage *> bttvChannelEmotes;
ConcurrentMap<QString, messages::LazyLoadedImage *> ffzChannelEmotes;
// variables
ConcurrentMap<QString, twitch::EmoteValue *> _twitchEmotes;
ConcurrentMap<QString, messages::LazyLoadedImage *> _bttvEmotes;
ConcurrentMap<QString, messages::LazyLoadedImage *> _ffzEmotes;
@@ -81,15 +74,15 @@ private:
boost::signals2::signal<void()> _gifUpdateTimerSignal;
QTimer _gifUpdateTimer;
bool _gifUpdateTimerInitiated;
bool _gifUpdateTimerInitiated = false;
int _generation;
int _generation = 0;
// methods
static QString getTwitchEmoteLink(long id, qreal &scale);
void loadFfzEmotes();
void loadBttvEmotes();
void loadFFZEmotes();
void loadBTTVEmotes();
};
} // namespace chatterino