mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Move gif timer stuff to its own class
Clean up unused includes
This commit is contained in:
parent
78664f79ee
commit
8e70f02e3b
7 changed files with 63 additions and 53 deletions
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 <QDebug>
|
||||
#include <QFile>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include <memory>
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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 <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
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<QString, messages::Image *> miscImageCache;
|
||||
|
||||
private:
|
||||
|
@ -68,10 +69,6 @@ public:
|
|||
|
||||
/// Chatterino emotes
|
||||
util::EmoteMap _chatterinoEmotes;
|
||||
|
||||
pajlada::Signals::NoArgSignal gifUpdateTimerSignal;
|
||||
QTimer gifUpdateTimer;
|
||||
bool gifUpdateTimerInitiated = false;
|
||||
};
|
||||
|
||||
} // namespace singletons
|
||||
|
|
31
src/singletons/helper/giftimer.cpp
Normal file
31
src/singletons/helper/giftimer.cpp
Normal file
|
@ -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
|
21
src/singletons/helper/giftimer.hpp
Normal file
21
src/singletons/helper/giftimer.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <QTimer>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
||||
class GIFTimer
|
||||
{
|
||||
public:
|
||||
void initialize();
|
||||
|
||||
pajlada::Signals::NoArgSignal signal;
|
||||
|
||||
private:
|
||||
QTimer timer;
|
||||
};
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
Loading…
Reference in a new issue