diff --git a/src/konqpixmapprovider.cpp b/src/konqpixmapprovider.cpp index 9f1df015d..fa29827ff 100644 --- a/src/konqpixmapprovider.cpp +++ b/src/konqpixmapprovider.cpp @@ -1,186 +1,186 @@ /* This file is part of the KDE project Copyright (C) 2000 Carsten Pfeiffer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "konqpixmapprovider.h" #include #include #include #include "konqdebug.h" #include #include #include #include #include class KonqPixmapProviderSingleton { public: KonqPixmapProvider self; }; Q_GLOBAL_STATIC(KonqPixmapProviderSingleton, globalPixmapProvider) KonqPixmapProvider *KonqPixmapProvider::self() { return &globalPixmapProvider->self; } KonqPixmapProvider::KonqPixmapProvider() - : KPixmapProvider() + : QObject() { } KonqPixmapProvider::~KonqPixmapProvider() { } void KonqPixmapProvider::downloadHostIcon(const QUrl &hostUrl) { KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(hostUrl); connect(job, &KIO::FavIconRequestJob::result, this, [job, this](KJob *) { bool modified = false; const QUrl _hostUrl = job->hostUrl(); QMap::iterator itEnd = iconMap.end(); for (QMap::iterator it = iconMap.begin(); it != itEnd; ++it) { const QUrl url(it.key()); if (url.host() == _hostUrl.host()) { // For host default-icons still query the favicon manager to get // the correct icon for pages that have an own one. const QString icon = KIO::favIconForUrl(url); if (!icon.isEmpty() && *it != icon) { *it = icon; modified = true; } } } if (modified) { emit changed(); } }); } void KonqPixmapProvider::setIconForUrl(const QUrl &hostUrl, const QUrl &iconUrl) { KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(hostUrl); job->setIconUrl(iconUrl); connect(job, &KIO::FavIconRequestJob::result, this, [job, this](KJob *) { bool modified = false; const QUrl _hostUrl = job->hostUrl(); QMap::iterator itEnd = iconMap.end(); for (QMap::iterator it = iconMap.begin(); it != itEnd; ++it) { const QUrl url(it.key()); if (url.host() == _hostUrl.host() && url.path() == _hostUrl.path()) { const QString icon = job->iconFile(); if (!icon.isEmpty() && *it != icon) { *it = icon; modified = true; } } } if (modified) { emit changed(); } }); } // at first, tries to find the iconname in the cache // if not available, tries to find the pixmap for the mimetype of url // if that fails, gets the icon for the protocol // finally, inserts the url/icon pair into the cache QString KonqPixmapProvider::iconNameFor(const QUrl &url) { QMap::iterator it = iconMap.find(url); QString icon; if (it != iconMap.end()) { icon = it.value(); if (!icon.isEmpty()) { return icon; } } if (url.url().isEmpty()) { // Use the folder icon for the empty URL QMimeDatabase db; const QMimeType directoryType = db.mimeTypeForName(QStringLiteral("inode/directory")); icon = directoryType.iconName(); Q_ASSERT(!icon.isEmpty()); } else { icon = KIO::iconNameForUrl(url); Q_ASSERT(!icon.isEmpty()); } // cache the icon found for url iconMap.insert(url, icon); return icon; } QPixmap KonqPixmapProvider::pixmapFor(const QString &url, int size) { return loadIcon(iconNameFor(QUrl::fromUserInput(url)), size); } void KonqPixmapProvider::load(KConfigGroup &kc, const QString &key) { iconMap.clear(); const QStringList list = kc.readPathEntry(key, QStringList()); QStringList::const_iterator it = list.begin(); QStringList::const_iterator itEnd = list.end(); while (it != itEnd) { const QString url(*it); if ((++it) == itEnd) { break; } const QString icon(*it); iconMap.insert(QUrl::fromUserInput(url), icon); ++it; } } // only saves the cache for the given list of items to prevent the cache // from growing forever. void KonqPixmapProvider::save(KConfigGroup &kc, const QString &key, const QStringList &items) { QStringList list; QStringList::const_iterator itEnd = items.end(); for (QStringList::const_iterator it = items.begin(); it != itEnd; ++it) { QMap::const_iterator mit = iconMap.constFind(QUrl::fromUserInput(*it)); if (mit != iconMap.constEnd()) { list.append(mit.key().url()); list.append(mit.value()); } } kc.writePathEntry(key, list); } void KonqPixmapProvider::clear() { iconMap.clear(); } QPixmap KonqPixmapProvider::loadIcon(const QString &icon, int size) { if (size == 0) { size = KIconLoader::SizeSmall; } return QIcon::fromTheme(icon).pixmap(size); } diff --git a/src/konqpixmapprovider.h b/src/konqpixmapprovider.h index 4e457af72..026a633b7 100644 --- a/src/konqpixmapprovider.h +++ b/src/konqpixmapprovider.h @@ -1,88 +1,86 @@ /* This file is part of the KDE project Copyright (C) 2000 Carsten Pfeiffer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KONQ_PIXMAPPROVIDER_H #define KONQ_PIXMAPPROVIDER_H #include "konqprivate_export.h" -#include - #include #include #include class KConfigGroup; class KConfig; -class KONQUERORPRIVATE_EXPORT KonqPixmapProvider : public QObject, public KPixmapProvider +class KONQUERORPRIVATE_EXPORT KonqPixmapProvider : public QObject { Q_OBJECT public: static KonqPixmapProvider *self(); - ~KonqPixmapProvider() override; + ~KonqPixmapProvider(); /** * Trigger a download of a default favicon */ void downloadHostIcon(const QUrl &hostUrl); /** * Trigger a download of a custom favicon (from the HTML page) */ void setIconForUrl(const QUrl &hostUrl, const QUrl &iconUrl); /** * Looks up a pixmap for @p url. Uses a cache for the iconname of url. */ - QPixmap pixmapFor(const QString &url, int size) override; + QPixmap pixmapFor(const QString &url, int size); /** * Loads the cache to @p kc from key @p key. */ void load(KConfigGroup &kc, const QString &key); /** * Saves the cache to @p kc as key @p key. * Only those @p items are saved, otherwise the cache would grow forever. */ void save(KConfigGroup &kc, const QString &key, const QStringList &items); /** * Clears the pixmap cache */ void clear(); /** * Looks up an iconname for @p url. Uses a cache for the iconname of url. */ QString iconNameFor(const QUrl &url); Q_SIGNALS: void changed(); private: QPixmap loadIcon(const QString &icon, int size); KonqPixmapProvider(); friend class KonqPixmapProviderSingleton; QMap iconMap; }; #endif // KONQ_PIXMAPPROVIDER_H