diff options
-rw-r--r-- | src/icons/iconmanager.cpp | 87 | ||||
-rw-r--r-- | src/icons/iconmanager.h | 10 | ||||
-rw-r--r-- | src/icons/webicon.cpp | 55 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 24 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 30 | ||||
-rw-r--r-- | src/webtab/webpage.cpp | 3 |
6 files changed, 116 insertions, 93 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); } diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 4e6795f0..02605167 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2009-2013 by Andrea Diamantini <adjam7 at gmail dot com> * * * This program is free software; you can redistribute it and/or @@ -424,7 +424,6 @@ SearchListItem::SearchListItem(const UrlSuggestionItem &item, const QString &tex : ListItem(item, parent) , m_text(text) { - m_iconLabel = new IconLabel(item.url, this); m_titleLabel = new TextLabel(this); m_titleLabel->setEngineText(item.description, item.title); @@ -437,11 +436,10 @@ SearchListItem::SearchListItem(const UrlSuggestionItem &item, const QString &tex QHBoxLayout *hLayout = new QHBoxLayout; hLayout->setSpacing(4); - hLayout->addWidget(m_iconLabel); + hLayout->addWidget(new TypeIconLabel(item.type, this)); hLayout->addWidget(m_titleLabel); hLayout->addWidget(new QLabel(i18n("Engines:"), this)); hLayout->addWidget(m_engineBar); - hLayout->addWidget(new TypeIconLabel(item.type, this)); setLayout(hLayout); @@ -496,6 +494,19 @@ EngineBar::EngineBar(KService::Ptr selectedEngine, QWidget *parent) if (SearchEngine::defaultEngine().isNull()) return; + static bool isFirstExecution = true; + if (isFirstExecution) + { + Q_FOREACH(const KService::Ptr & engine, SearchEngine::favorites()) + { + QUrl u = engine->property("Query").toUrl(); + KUrl url = KUrl(u.toString(QUrl::RemovePath | QUrl::RemoveQuery)); + IconManager::self()->provideEngineFavicon(url); + } + + isFirstExecution = false; + } + m_engineGroup->addAction(newEngineAction(SearchEngine::defaultEngine(), selectedEngine)); Q_FOREACH(const KService::Ptr & engine, SearchEngine::favorites()) { @@ -514,7 +525,7 @@ KAction *EngineBar::newEngineAction(KService::Ptr engine, KService::Ptr selected QUrl u = engine->property("Query").toUrl(); KUrl url = KUrl(u.toString(QUrl::RemovePath | QUrl::RemoveQuery)); - KAction *a = new KAction(IconManager::self()->iconForUrl(url), engine->name(), this); + KAction *a = new KAction(IconManager::self()->engineFavicon(url), engine->name(), this); a->setCheckable(true); if (engine->desktopEntryName() == selectedEngine->desktopEntryName()) a->setChecked(true); a->setData(engine->entryPath()); @@ -631,9 +642,8 @@ BrowseListItem::BrowseListItem(const UrlSuggestionItem &item, const QString &tex QHBoxLayout *hLayout = new QHBoxLayout; hLayout->setSpacing(4); - hLayout->addWidget(new IconLabel(item.url, this)); - hLayout->addWidget(new TextLabel(item.url, text, this)); hLayout->addWidget(new TypeIconLabel(item.type, this)); + hLayout->addWidget(new TextLabel(item.url, text, this)); setLayout(hLayout); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 21867685..54bff109 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2009-2013 by Andrea Diamantini <adjam7 at gmail dot com> * * * This program is free software; you can redistribute it and/or @@ -53,7 +53,7 @@ class KJob; class QActionGroup; -class ListItem : public QWidget +class REKONQ_TESTS_EXPORT ListItem : public QWidget { Q_OBJECT @@ -91,7 +91,7 @@ protected: // ------------------------------------------------------------------------- -class TypeIconLabel : public QLabel +class REKONQ_TESTS_EXPORT TypeIconLabel : public QLabel { Q_OBJECT @@ -106,7 +106,7 @@ private: // ------------------------------------------------------------------------- -class IconLabel : public QLabel +class REKONQ_TESTS_EXPORT IconLabel : public QLabel { Q_OBJECT @@ -133,7 +133,7 @@ public: // ------------------------------------------------------------------------- -class DescriptionLabel : public QLabel +class REKONQ_TESTS_EXPORT DescriptionLabel : public QLabel { Q_OBJECT @@ -145,7 +145,7 @@ public: // ------------------------------------------------------------------------- -class EngineBar : public KToolBar +class REKONQ_TESTS_EXPORT EngineBar : public KToolBar { Q_OBJECT @@ -162,13 +162,14 @@ private Q_SLOTS: private: KAction *newEngineAction(KService::Ptr engine, KService::Ptr selectedEngine); QActionGroup *m_engineGroup; + }; // ------------------------------------------------------------------------- -class SearchListItem : public ListItem +class REKONQ_TESTS_EXPORT SearchListItem : public ListItem { Q_OBJECT @@ -194,7 +195,7 @@ private: // ------------------------------------------------------------------------- -class SuggestionListItem : public ListItem +class REKONQ_TESTS_EXPORT SuggestionListItem : public ListItem { Q_OBJECT @@ -210,7 +211,7 @@ private: // ------------------------------------------------------------------------- -class VisualSuggestionListItem : public ListItem +class REKONQ_TESTS_EXPORT VisualSuggestionListItem : public ListItem { Q_OBJECT @@ -226,7 +227,7 @@ private: // ------------------------------------------------------------------------- -class PreviewListItem : public ListItem +class REKONQ_TESTS_EXPORT PreviewListItem : public ListItem { Q_OBJECT @@ -238,7 +239,7 @@ public: // ------------------------------------------------------------------------- -class PreviewLabel : public QLabel +class REKONQ_TESTS_EXPORT PreviewLabel : public QLabel { Q_OBJECT @@ -249,7 +250,8 @@ public: // ------------------------------------------------------------------------- -class ImageLabel : public QLabel + +class REKONQ_TESTS_EXPORT ImageLabel : public QLabel { Q_OBJECT @@ -269,7 +271,7 @@ private Q_SLOTS: // ------------------------------------------------------------------------- -class BrowseListItem : public ListItem +class REKONQ_TESTS_EXPORT BrowseListItem : public ListItem { Q_OBJECT @@ -281,7 +283,7 @@ public: //------------------------------------------------------------------------------------------------- -class ListItemFactory +class REKONQ_TESTS_EXPORT ListItemFactory { public: static ListItem *create(const UrlSuggestionItem &item, const QString &text, QWidget *parent); diff --git a/src/webtab/webpage.cpp b/src/webtab/webpage.cpp index 9ed7b8c8..3e580dbe 100644 --- a/src/webtab/webpage.cpp +++ b/src/webtab/webpage.cpp @@ -586,9 +586,6 @@ void WebPage::loadFinished(bool ok) { Q_UNUSED(ok); - // Provide site icon. Can this be moved to loadStarted?? - IconManager::self()->provideIcon(mainFrame(), _loadingUrl); - // KWallet Integration QStringList list = ReKonfig::walletBlackList(); if (wallet() |