diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2011-12-23 18:21:23 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-12-24 07:49:42 +0100 |
commit | bacf98c3e5cb2407a964286a43a629696a498abd (patch) | |
tree | ede126af1b3aad393586ba77a866cdf88bbeb88c | |
parent | SVN_SILENT made messages (.desktop file) (diff) | |
download | rekonq-bacf98c3e5cb2407a964286a43a629696a498abd.tar.xz |
icon management fix/improvements/cleanup
-rw-r--r-- | src/application.cpp | 8 | ||||
-rw-r--r-- | src/iconmanager.cpp | 91 | ||||
-rw-r--r-- | src/iconmanager.h | 2 | ||||
-rw-r--r-- | src/mainview.cpp | 2 | ||||
-rw-r--r-- | src/newtabpage.cpp | 10 | ||||
-rw-r--r-- | src/webpage.h | 2 |
6 files changed, 94 insertions, 21 deletions
diff --git a/src/application.cpp b/src/application.cpp index 5f66d80e..f5547fa2 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -678,10 +678,10 @@ void Application::updateConfiguration() if (!mainWindow()) return; - if (!ReKonfig::useFavicon()) - mainWindow()->setWindowIcon(KIcon("rekonq")); - else - mainWindow()->changeWindowIcon(mainWindow()->mainView()->currentIndex()); + ReKonfig::useFavicon() + ? mainWindow()->changeWindowIcon(mainWindow()->mainView()->currentIndex()) + : mainWindow()->setWindowIcon(KIcon("rekonq")) + ; // hovering unfocused tabs options switch (ReKonfig::hoveringTabOption()) diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp index ea36c45a..632a33af 100644 --- a/src/iconmanager.cpp +++ b/src/iconmanager.cpp @@ -36,7 +36,6 @@ #include <KIO/Job> #include <KIcon> -#include <KMimeType> #include <KStandardDirs> #include <KUrl> @@ -82,11 +81,10 @@ KIcon IconManager::iconForUrl(const KUrl &url) return KIcon("folder"); } - QString i = KMimeType::favIconForUrl(url); + QString i = favIconForUrl(url); if (!i.isEmpty()) { - QString faviconDir = KStandardDirs::locateLocal("cache" , "" , true); - return KIcon(faviconDir + i); + return KIcon(QIcon(_faviconsDir + i)); } // Not found icon. Return default one. @@ -113,7 +111,7 @@ void IconManager::provideIcon(QWebPage *page, const KUrl &url, bool notify) } // check if icon exists - if (!KMimeType::favIconForUrl(url).isEmpty()) + if (!favIconForUrl(url).isEmpty()) { if (notify) emit iconChanged(); @@ -142,12 +140,11 @@ void IconManager::provideIcon(QWebPage *page, const KUrl &url, bool notify) : KUrl(rootUrlString + QL1C('/') + relUrlString); } - kDebug() << "Favicon URL: " << faviconUrl; if (faviconUrl.isEmpty()) return; // dest url - KUrl destUrl(_faviconsDir + url.host() + QL1S(".png")); + KUrl destUrl(_faviconsDir + url.host()); // download icon KIO::FileCopyJob *job = KIO::file_copy(faviconUrl, destUrl, -1, KIO::HideProgressInfo); @@ -217,13 +214,15 @@ void IconManager::doLastStuffs(KJob *j) } px = px.scaled(16, 16); - if (!px.save(s)) + if (!px.save(s + QL1S(".png"), "PNG")) { kDebug() << "PIXMAP NOT SAVED"; return; } + QFile::remove(s); } + void IconManager::notifyLastStuffs(KJob *j) { doLastStuffs(j); @@ -242,3 +241,79 @@ void IconManager::saveDesktopIconForUrl(const KUrl &u) pix.save(destPath); } + + +// NOTE: this function is builded "around" the iconForurl one. It basically returns the same things +// with an important difference: this one returns paths while the other one returns KIcons +QString IconManager::iconPathForUrl(const KUrl &url) +{ + // first things first.. avoid infinite loop at startup + if (url.isEmpty() || rApp->mainWindowList().isEmpty()) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/mimetypes/text-html.png"); + return icon; + } + + QByteArray encodedUrl = url.toEncoded(); + // rekonq icons.. + if (encodedUrl == QByteArray("about:home")) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/actions/go-home.png"); + return icon; + } + if (encodedUrl == QByteArray("about:closedTabs")) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/actions/tab-close.png"); + return icon; + } + if (encodedUrl == QByteArray("about:history")) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/actions/view-history.png"); + return icon; + } + if (encodedUrl == QByteArray("about:bookmarks")) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/places/bookmarks.png"); + return icon; + } + if (encodedUrl == QByteArray("about:favorites")) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/emblems/emblem-favorite.png"); + return icon; + } + if (encodedUrl == QByteArray("about:downloads")) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/actions/download.png"); + return icon; + } + + // TODO: return other mimetype icons + if (url.isLocalFile()) + { + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/places/folder.png"); + return icon; + } + + QString i = favIconForUrl(url); + if (!i.isEmpty()) + { + return QL1S("file://") + _faviconsDir + i; + } + + // Not found icon. Return default one. + QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/mimetypes/text-html.png"); + return icon; +} + + +QString IconManager::favIconForUrl(const KUrl &url) +{ + if (url.isLocalFile() + || !url.protocol().startsWith(QL1S("http"))) + return QString(); + + if (QFile::exists(_faviconsDir + url.host() + QL1S(".png"))) + return url.host() + QL1S(".png"); + else + return QString(); +} diff --git a/src/iconmanager.h b/src/iconmanager.h index 85db5ddd..e7e317f0 100644 --- a/src/iconmanager.h +++ b/src/iconmanager.h @@ -47,6 +47,7 @@ public: IconManager(QObject *parent = 0); KIcon iconForUrl(const KUrl &url); + QString iconPathForUrl(const KUrl &url); void provideIcon(QWebPage *page, const KUrl &url, bool notify = true); @@ -65,6 +66,7 @@ Q_SIGNALS: private: bool existsIconForUrl(const KUrl &url); + QString favIconForUrl(const KUrl &url); QString _faviconsDir; }; diff --git a/src/mainview.cpp b/src/mainview.cpp index d7612143..c98e030a 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -548,7 +548,7 @@ void MainView::webViewIconChanged() { WebView *view = qobject_cast<WebView *>(sender()); WebTab *tab = qobject_cast<WebTab *>(view->parent()); - int index = indexOf(tab); + const int index = indexOf(tab); if (-1 != index) { diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index 529a9804..09d15af6 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -36,6 +36,7 @@ #include "application.h" #include "bookmarkmanager.h" #include "downloadmanager.h" +#include "iconmanager.h" #include "historymodels.h" #include "mainview.h" #include "mainwindow.h" @@ -416,8 +417,6 @@ void NewTabPage::historyPage() } int i = 0; - QString faviconsDir = KStandardDirs::locateLocal("cache" , "favicons/" , true); - QString icon = QL1S("file://") + KGlobal::dirs()->findResource("icon", "oxygen/16x16/mimetypes/text-html.png"); const int maxTextSize = 103; const int truncateSize = 100; do @@ -435,14 +434,10 @@ void NewTabPage::historyPage() QModelIndex son = model->index(j, 0, index); KUrl u = son.data(HistoryModel::UrlStringRole).toUrl(); - QString b = faviconsDir + u.host() + QL1S(".png"); - if (QFile::exists(b)) - icon = QL1S("file://") + b; - little.appendInside(son.data(HistoryModel::DateTimeRole).toDateTime().toString("hh:mm")); little.appendInside(QL1S(" ")); little.appendInside(markup(QL1S("img"))); - little.lastChild().setAttribute(QL1S("src"), icon); + little.lastChild().setAttribute(QL1S("src"), rApp->iconManager()->iconPathForUrl(u)); little.lastChild().setAttribute(QL1S("width"), QL1S("16")); little.lastChild().setAttribute(QL1S("height"), QL1S("16")); little.appendInside(QL1S(" ")); @@ -653,6 +648,7 @@ QWebElement NewTabPage::createLinkItem(const QString &title, const QString &urlS return nav; } + void NewTabPage::updateWindowIcon() { int currentIndex = rApp->mainWindow()->mainView()->currentIndex(); diff --git a/src/webpage.h b/src/webpage.h index 528ce331..6a717f78 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -56,7 +56,7 @@ public: { return _networkAnalyzer; }; - + inline void enableNetworkAnalyzer(bool b) { _networkAnalyzer = b; |