From 303258b8e313432ca66984f9dfbf5624259462b3 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 16 Jun 2013 09:43:32 +0200 Subject: Restore use of webkit icon cache Fix rekonq icon retrieve mechanism to let it show well engine icons on bar BUG:272565 --- src/icons/webicon.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'src/icons/webicon.cpp') diff --git a/src/icons/webicon.cpp b/src/icons/webicon.cpp index 64bb884b..6e9ec0d5 100644 --- a/src/icons/webicon.cpp +++ b/src/icons/webicon.cpp @@ -30,16 +30,25 @@ // Local Includes #include "iconmanager.h" +#include "icondownloader.h" + +#include "knetworkaccessmanager.h" + +// KDE Includes +#include // Qt Includes #include #include +#include WebIcon::WebIcon(const KUrl& url, QObject *parent) : QObject(parent) , m_url(url) { + m_page.setNetworkAccessManager(new KNetworkAccessManager); + m_page.settings()->setAttribute(QWebSettings::PluginsEnabled, false); m_page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false); m_page.settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); @@ -57,10 +66,50 @@ void WebIcon::load() void WebIcon::saveIcon(bool b) { - if (b) + if (!b) + { + this->deleteLater(); + return; + } + + // the simplest way.. + const QString rootUrlString = m_url.scheme() + QL1S("://") + m_url.host(); + + // find favicon url + KUrl faviconUrl(rootUrlString + QL1S("/favicon.ico")); + + + QWebElement root = m_page.mainFrame()->documentElement(); + QWebElement e = root.findFirst(QL1S("link[rel~=\"icon\"]")); + QString relUrlString = e.attribute(QL1S("href")); + if (relUrlString.isEmpty()) + { + e = root.findFirst(QL1S("link[rel~=\"shortcut icon\"]")); + relUrlString = e.attribute(QL1S("href")); + } + + // remove eventual initial // + if (relUrlString.startsWith(QL1S("//"))) { - IconManager::self()->provideIcon(m_page.mainFrame(), m_url, false); + relUrlString.remove(0, 2); + relUrlString.prepend(QL1S("http://")); } + + if (!relUrlString.isEmpty()) + { + faviconUrl = KUrl(relUrlString); + + if (!faviconUrl.isValid()) + { + + faviconUrl = KUrl(rootUrlString + QL1C('/') + relUrlString); + } + } + QString faviconsDir = KStandardDirs::locateLocal("cache" , "favicons/" , true); + + // dest url + KUrl destUrl(faviconsDir + m_url.host()); - this->deleteLater(); + // will autodelete itself when done + new IconDownloader(faviconUrl, destUrl, this); } -- cgit v1.2.1