File indexing completed on 2024-04-14 04:53:13

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2000 Carsten Pfeiffer <pfeiffer@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KONQ_PIXMAPPROVIDER_H
0008 #define KONQ_PIXMAPPROVIDER_H
0009 
0010 #include "konqprivate_export.h"
0011 
0012 #include <QMap>
0013 #include <QPixmap>
0014 #include <QUrl>
0015 #include <QObject>
0016 
0017 class KConfigGroup;
0018 class KConfig;
0019 
0020 class KONQUERORPRIVATE_EXPORT KonqPixmapProvider : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     static KonqPixmapProvider *self();
0025 
0026     ~KonqPixmapProvider() override;
0027 
0028     /**
0029      * Trigger a download of a default favicon
0030      */
0031     void downloadHostIcon(const QUrl &hostUrl);
0032     /**
0033      * Trigger a download of a custom favicon (from the HTML page)
0034      */
0035     void setIconForUrl(const QUrl &hostUrl, const QUrl &iconUrl);
0036 
0037     /**
0038      * Looks up a pixmap for @p url. Uses a cache for the iconname of url.
0039      */
0040     QPixmap pixmapFor(const QString &url, int size);
0041 
0042     /**
0043      * Loads the cache to @p kc from key @p key.
0044      */
0045     void load(KConfigGroup &kc, const QString &key);
0046     /**
0047      * Saves the cache to @p kc as key @p key.
0048      * Only those @p items are saved, otherwise the cache would grow forever.
0049      */
0050     void save(KConfigGroup &kc, const QString &key, const QStringList &items);
0051 
0052     /**
0053      * Clears the pixmap cache
0054      */
0055     void clear();
0056 
0057     /**
0058      * Looks up an iconname for @p url. Uses a cache for the iconname of url.
0059      */
0060     QString iconNameFor(const QUrl &url);
0061     QIcon iconForUrl(const QUrl &url);
0062     QIcon iconForUrl(const QString &url_str);
0063 
0064 Q_SIGNALS:
0065     void changed();
0066 
0067 private:
0068     QPixmap loadIcon(const QString &icon, int size);
0069 
0070     KonqPixmapProvider();
0071     friend class KonqPixmapProviderSingleton;
0072 
0073     QMap<QUrl, QString> iconMap;
0074 };
0075 
0076 #endif // KONQ_PIXMAPPROVIDER_H