From 8e70f02e3bab8b4e10b4cb227c2adc8c1ac1ec33 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Tue, 5 Jun 2018 18:30:26 +0200 Subject: [PATCH] Move gif timer stuff to its own class Clean up unused includes --- chatterino.pro | 2 ++ src/messages/image.cpp | 2 +- src/providers/bttv/bttvemotes.cpp | 2 -- src/singletons/emotemanager.cpp | 47 +++--------------------------- src/singletons/emotemanager.hpp | 11 +++---- src/singletons/helper/giftimer.cpp | 31 ++++++++++++++++++++ src/singletons/helper/giftimer.hpp | 21 +++++++++++++ 7 files changed, 63 insertions(+), 53 deletions(-) create mode 100644 src/singletons/helper/giftimer.cpp create mode 100644 src/singletons/helper/giftimer.hpp diff --git a/chatterino.pro b/chatterino.pro index 3416094ff..d6fc9c888 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -124,6 +124,7 @@ SOURCES += \ src/singletons/helper/loggingchannel.cpp \ src/singletons/helper/moderationaction.cpp \ src/singletons/helper/chatterinosetting.cpp \ + src/singletons/helper/giftimer.cpp \ src/singletons/loggingmanager.cpp \ src/singletons/pathmanager.cpp \ src/singletons/resourcemanager.cpp \ @@ -251,6 +252,7 @@ HEADERS += \ src/singletons/emotemanager.hpp \ src/singletons/fontmanager.hpp \ src/singletons/helper/chatterinosetting.hpp \ + src/singletons/helper/giftimer.hpp \ src/util/completionmodel.hpp \ src/singletons/helper/loggingchannel.hpp \ src/singletons/helper/moderationaction.hpp \ diff --git a/src/messages/image.cpp b/src/messages/image.cpp index 62c137214..2aa887a98 100644 --- a/src/messages/image.cpp +++ b/src/messages/image.cpp @@ -125,7 +125,7 @@ void Image::loadImage() if (this->allFrames.size() > 1) { if (!this->animated) { util::postToThread([this] { - getApp()->emotes->getGifUpdateSignal().connect([=]() { + getApp()->emotes->gifTimer.signal.connect([=]() { this->gifUpdateTimout(); }); // For some reason when Boost signal is in // thread scope and thread deletes the signal diff --git a/src/providers/bttv/bttvemotes.cpp b/src/providers/bttv/bttvemotes.cpp index bff4581d0..4ccdda731 100644 --- a/src/providers/bttv/bttvemotes.cpp +++ b/src/providers/bttv/bttvemotes.cpp @@ -4,8 +4,6 @@ #include "messages/image.hpp" #include "util/urlfetch.hpp" -#define TWITCH_EMOTE_TEMPLATE "https://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}" - namespace chatterino { namespace providers { namespace bttv { diff --git a/src/singletons/emotemanager.cpp b/src/singletons/emotemanager.cpp index d34f44ddd..c94b68191 100644 --- a/src/singletons/emotemanager.cpp +++ b/src/singletons/emotemanager.cpp @@ -1,22 +1,10 @@ -#include "emotemanager.hpp" +#include "singletons/emotemanager.hpp" #include "application.hpp" #include "common.hpp" -#include "singletons/settingsmanager.hpp" -#include "singletons/windowmanager.hpp" -#include "util/urlfetch.hpp" +#include "controllers/accounts/accountcontroller.hpp" -#include #include -#include -#include -#include -#include -#include -#include -#include - -#include using namespace chatterino::providers::twitch; using namespace chatterino::messages; @@ -41,6 +29,8 @@ void EmoteManager::initialize() this->loadEmojis(); this->bttv.loadGlobalEmotes(); this->ffz.loadGlobalEmotes(); + + this->gifTimer.initialize(); } util::EmoteMap &EmoteManager::getChatterinoEmotes() @@ -234,35 +224,6 @@ util::EmoteData EmoteManager::getCheerImage(long long amount, bool animated) return util::EmoteData(); } -pajlada::Signals::NoArgSignal &EmoteManager::getGifUpdateSignal() -{ - if (!this->gifUpdateTimerInitiated) { - auto app = getApp(); - - this->gifUpdateTimerInitiated = true; - - this->gifUpdateTimer.setInterval(30); - this->gifUpdateTimer.start(); - - app->settings->enableGifAnimations.connect([this](bool enabled, auto) { - if (enabled) { - this->gifUpdateTimer.start(); - } else { - this->gifUpdateTimer.stop(); - } - }); - - QObject::connect(&this->gifUpdateTimer, &QTimer::timeout, [this] { - this->gifUpdateTimerSignal.invoke(); - // fourtf: - auto app = getApp(); - app->windows->repaintGifEmotes(); - }); - } - - return this->gifUpdateTimerSignal; -} - } // namespace singletons } // namespace chatterino diff --git a/src/singletons/emotemanager.hpp b/src/singletons/emotemanager.hpp index bb2354dfd..255a22172 100644 --- a/src/singletons/emotemanager.hpp +++ b/src/singletons/emotemanager.hpp @@ -8,6 +8,7 @@ #include "providers/ffz/ffzemotes.hpp" #include "providers/twitch/twitchemotes.hpp" #include "signalvector.hpp" +#include "singletons/helper/giftimer.hpp" #include "util/concurrentmap.hpp" #include "util/emotemap.hpp" @@ -16,7 +17,6 @@ #include #include #include -#include namespace chatterino { namespace singletons { @@ -32,6 +32,8 @@ public: providers::bttv::BTTVEmotes bttv; providers::ffz::FFZEmotes ffz; + GIFTimer gifTimer; + void initialize(); util::EmoteMap &getChatterinoEmotes(); @@ -39,9 +41,8 @@ public: util::EmoteData getCheerImage(long long int amount, bool animated); - pajlada::Signals::NoArgSignal &getGifUpdateSignal(); - // Bit badge/emotes? + // TODO: Move to twitch emote provider util::ConcurrentMap miscImageCache; private: @@ -68,10 +69,6 @@ public: /// Chatterino emotes util::EmoteMap _chatterinoEmotes; - - pajlada::Signals::NoArgSignal gifUpdateTimerSignal; - QTimer gifUpdateTimer; - bool gifUpdateTimerInitiated = false; }; } // namespace singletons diff --git a/src/singletons/helper/giftimer.cpp b/src/singletons/helper/giftimer.cpp new file mode 100644 index 000000000..097b90dc6 --- /dev/null +++ b/src/singletons/helper/giftimer.cpp @@ -0,0 +1,31 @@ +#include "singletons/helper/giftimer.hpp" + +#include "application.hpp" +#include "singletons/settingsmanager.hpp" +#include "singletons/windowmanager.hpp" + +namespace chatterino { +namespace singletons { + +void GIFTimer::initialize() +{ + this->timer.setInterval(30); + + getApp()->settings->enableGifAnimations.connect([this](bool enabled, auto) { + if (enabled) { + this->timer.start(); + } else { + this->timer.stop(); + } + }); + + QObject::connect(&this->timer, &QTimer::timeout, [this] { + this->signal.invoke(); + // fourtf: + auto app = getApp(); + app->windows->repaintGifEmotes(); + }); +} + +} // namespace singletons +} // namespace chatterino diff --git a/src/singletons/helper/giftimer.hpp b/src/singletons/helper/giftimer.hpp new file mode 100644 index 000000000..5078bb06a --- /dev/null +++ b/src/singletons/helper/giftimer.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace chatterino { +namespace singletons { + +class GIFTimer +{ +public: + void initialize(); + + pajlada::Signals::NoArgSignal signal; + +private: + QTimer timer; +}; + +} // namespace singletons +} // namespace chatterino