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"
|
2021-05-03 00:08:08 +02:00
|
|
|
#include "messages/Image.hpp"
|
|
|
|
#include "util/DisplayBadge.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "util/QStringHash.hpp"
|
|
|
|
|
2021-05-03 00:08:08 +02:00
|
|
|
#include "pajlada/signals/signal.hpp"
|
|
|
|
|
|
|
|
#include <shared_mutex>
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
struct Emote;
|
|
|
|
using EmotePtr = std::shared_ptr<const Emote>;
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
class Settings;
|
|
|
|
class Paths;
|
|
|
|
|
|
|
|
class TwitchBadges
|
|
|
|
{
|
2021-05-03 00:08:08 +02:00
|
|
|
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:
|
2021-05-03 00:08:08 +02:00
|
|
|
static TwitchBadges *instance();
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-05-03 00:08:08 +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;
|
2021-05-03 00:08:08 +02:00
|
|
|
// 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:
|
2021-05-03 00:08:08 +02:00
|
|
|
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
|