mirror-chatterino2/src/providers/twitch/TwitchBadges.hpp

68 lines
1.8 KiB
C++
Raw Normal View History

2018-08-02 14:23:27 +02:00
#pragma once
#include <QString>
2018-08-14 17:45:17 +02:00
#include <boost/optional.hpp>
2018-08-02 14:23:27 +02:00
#include <unordered_map>
2018-08-14 17:45:17 +02:00
#include "common/UniqueAccess.hpp"
#include "messages/Image.hpp"
#include "util/DisplayBadge.hpp"
2018-08-02 14:23:27 +02:00
#include "util/QStringHash.hpp"
#include "pajlada/signals/signal.hpp"
#include <shared_mutex>
2018-08-02 14:23:27 +02:00
namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
2018-08-02 14:23:27 +02:00
class Settings;
class Paths;
class TwitchBadges
{
using QIconPtr = std::shared_ptr<QIcon>;
using ImagePtr = std::shared_ptr<Image>;
using BadgeIconCallback = std::function<void(QString, const QIconPtr)>;
2018-08-02 14:23:27 +02:00
public:
static TwitchBadges *instance();
2018-08-02 14:23:27 +02:00
// Get badge from name and version
2018-08-14 17:45:17 +02:00
boost::optional<EmotePtr> badge(const QString &set,
const QString &version) const;
// Get first matching badge with name, regardless of version
boost::optional<EmotePtr> badge(const QString &set) const;
void getBadgeIcon(const QString &name, BadgeIconCallback callback);
void getBadgeIcon(const DisplayBadge &badge, BadgeIconCallback callback);
void getBadgeIcons(const QList<DisplayBadge> &badges,
BadgeIconCallback callback);
2018-08-02 14:23:27 +02:00
private:
static TwitchBadges *instance_;
TwitchBadges();
void loadTwitchBadges();
void loaded();
void loadEmoteImage(const QString &name, ImagePtr image,
BadgeIconCallback &&callback);
std::shared_mutex badgesMutex_;
QMap<QString, QIconPtr> badgesMap_;
std::mutex queueMutex_;
std::queue<QPair<QString, BadgeIconCallback>> callbackQueue_;
std::shared_mutex loadedMutex_;
bool loaded_ = false;
2018-08-14 17:45:17 +02:00
UniqueAccess<
std::unordered_map<QString, std::unordered_map<QString, EmotePtr>>>
badgeSets_; // "bits": { "100": ... "500": ...
2018-08-02 14:23:27 +02:00
};
} // namespace chatterino