summaryrefslogtreecommitdiff
path: root/src/icons
diff options
context:
space:
mode:
Diffstat (limited to 'src/icons')
-rw-r--r--src/icons/iconmanager.cpp87
-rw-r--r--src/icons/iconmanager.h10
-rw-r--r--src/icons/webicon.cpp55
3 files changed, 83 insertions, 69 deletions
diff --git a/src/icons/iconmanager.cpp b/src/icons/iconmanager.cpp
index d0222bed..d7c0b170 100644
--- a/src/icons/iconmanager.cpp
+++ b/src/icons/iconmanager.cpp
@@ -30,7 +30,6 @@
// Local Includes
#include "application.h"
-#include "icondownloader.h"
#include "webicon.h"
// KDE Includes
@@ -42,9 +41,6 @@
// Qt Includes
#include <QDir>
-
-#include <QWebElement>
-#include <QWebFrame>
#include <QWebSettings>
@@ -68,6 +64,9 @@ IconManager::IconManager(QObject *parent)
: QObject(parent)
{
_faviconsDir = KStandardDirs::locateLocal("cache" , "favicons/" , true);
+
+ // Use webkit icon database path
+ QWebSettings::setIconDatabasePath(_faviconsDir);
}
@@ -100,69 +99,15 @@ KIcon IconManager::iconForUrl(const KUrl &url)
return KIcon("folder");
}
- QString i = favIconForUrl(url);
- if (!i.isEmpty())
- {
- return KIcon(QIcon(_faviconsDir + i));
- }
+ QIcon icon = QWebSettings::iconForUrl(url);
+ if (!icon.isNull())
+ return KIcon(icon);
// Not found icon. Return default one.
return KIcon("text-html");
}
-void IconManager::provideIcon(QWebFrame *mFrame, const KUrl &url, bool notify)
-{
- // provide icons just for http/https sites
- if (!url.scheme().startsWith(QL1S("http")))
- return;
-
- // do not load new icons in private browsing..
- if (mFrame->page()->settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
- return;
-
- // check if icon exists
- if (!favIconForUrl(url).isEmpty())
- return;
-
- // the simplest way..
- const QString rootUrlString = url.scheme() + QL1S("://") + url.host();
-
- // find favicon url
- KUrl faviconUrl(rootUrlString + QL1S("/favicon.ico"));
-
-
- QWebElement root = mFrame->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"));
- }
-
- if (!relUrlString.isEmpty())
- {
- faviconUrl = relUrlString.startsWith(QL1S("http"))
- ? KUrl(relUrlString)
- : KUrl(rootUrlString + QL1C('/') + relUrlString);
- }
-
- // dest url
- KUrl destUrl(_faviconsDir + url.host());
-
- IconDownloader *id = new IconDownloader(faviconUrl, destUrl, this);
- if (notify)
- connect(id, SIGNAL(iconReady()), mFrame, SIGNAL(iconChanged()));
-}
-
-
-void IconManager::downloadIconFromUrl(const KUrl &url)
-{
- new WebIcon(url, this);
-}
-
-
void IconManager::clearIconCache()
{
QDir d(_faviconsDir);
@@ -171,6 +116,9 @@ void IconManager::clearIconCache()
{
d.remove(fav);
}
+
+ // delete webkit icon cache
+ QWebSettings::clearIconDatabase();
}
@@ -261,3 +209,20 @@ QString IconManager::favIconForUrl(const KUrl &url)
else
return QString();
}
+
+
+void IconManager::provideEngineFavicon(const KUrl &url)
+{
+ // will autodelete itself when done
+ new WebIcon(url, this);
+}
+
+
+KIcon IconManager::engineFavicon(const KUrl &url)
+{
+ if (QFile::exists(_faviconsDir + url.host() + QL1S(".png")))
+ return KIcon(QIcon(_faviconsDir + url.host() + QL1S(".png")));
+
+ kDebug() << "NO ENGINE FAVICON";
+ return KIcon("text-html");
+}
diff --git a/src/icons/iconmanager.h b/src/icons/iconmanager.h
index bbb58bdb..4903d7c4 100644
--- a/src/icons/iconmanager.h
+++ b/src/icons/iconmanager.h
@@ -53,20 +53,20 @@ public:
static IconManager *self();
KIcon iconForUrl(const KUrl &url);
+
QString iconPathForUrl(const KUrl &url);
- void provideIcon(QWebFrame *mFrame, const KUrl &url, bool notify = true);
-
- void downloadIconFromUrl(const KUrl &url);
-
void clearIconCache();
void saveDesktopIconForUrl(const KUrl &u);
+ // Engine ToolBar needed methods
+ void provideEngineFavicon(const KUrl &);
+ KIcon engineFavicon(const KUrl &);
+
private:
IconManager(QObject *parent = 0);
- bool existsIconForUrl(const KUrl &url);
QString favIconForUrl(const KUrl &url);
QString _faviconsDir;
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 <KStandardDirs>
// Qt Includes
#include <QTimer>
#include <QWebFrame>
+#include <QWebElement>
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);
}