1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-28 02:27:41 +00:00
transmission/qt/FaviconCache.h
Charles Kerr e14c7f38e5
feat: use libpsl (#2575)
Use libpsl to calculate public and private parts of URL hosts.
2022-02-12 11:30:27 -06:00

47 lines
1.1 KiB
C++

// This file Copyright © 2012-2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
#include <unordered_map>
#include <QObject>
#include <QPixmap>
#include <QString>
#include "Utils.h" // std::hash<QString>
class QNetworkAccessManager;
class QNetworkReply;
class QUrl;
class FaviconCache : public QObject
{
Q_OBJECT
public:
FaviconCache();
// This will emit a signal when (if) the icon becomes ready.
void add(QString const& sitename, QString const& url);
// returns a cached pixmap, or a nullptr pixmap if there's no match in the cache
QPixmap find(QString const& sitename);
static QString getDisplayName(QString const& sitename);
static QSize getIconSize();
signals:
void pixmapReady(QString const& sitename);
private slots:
void onRequestFinished(QNetworkReply* reply);
private:
void ensureCacheDirHasBeenScanned();
QNetworkAccessManager* nam_ = {};
std::unordered_map<QString /*sitename*/, QPixmap> pixmaps_;
};