[PATCH] favicons with rel="icon"
Alexander Kellett
kelletta at eidetica.com
Tue Jun 25 00:03:28 BST 2002
On Sun, Jun 23, 2002 at 11:22:52PM +0200, Alexander Kellett wrote:
> AFAICS, the problem is as follows, seticonforurl is called correctly, but as
> its not a host icon, but is rather a "link" icon, the icon and its related
> iconurl are not "related" correctly (i.e the config file doesn't ever get a
> writeEntry for this url).
>
> If all such relations are called for a large host then the faviconrc would get
> quite enormous. Therefore another less persistant but "good enough" way to do fix
> this might be to add a cache of page urls and related iconurls to the kded
> module itself. I'll try writing a patch now.
Patch attached, together with my first patch it gets the
mozilla.org site to work well at the very least :)
mvg,
Alex
-------------- next part --------------
? favicons_kded.patch
Index: favicons.cpp
===================================================================
RCS file: /home/kde/kdebase/libkonq/favicons/favicons.cpp,v
retrieving revision 1.13
diff -u -p -r1.13 favicons.cpp
--- favicons.cpp 2002/03/13 21:35:06 1.13
+++ favicons.cpp 2002/06/24 22:58:15
@@ -22,6 +22,7 @@
#include <qbuffer.h>
#include <qfile.h>
+#include <qcache.h>
#include <qimage.h>
#include <qtimer.h>
@@ -32,6 +33,8 @@
#include <kstandarddirs.h>
#include <kio/job.h>
+#include <kdebug.h>
+
#include "favicons.moc"
struct FaviconsModulePrivate
@@ -50,6 +53,7 @@ struct FaviconsModulePrivate
QPtrList<KIO::Job> killJobs;
KIO::MetaData metaData;
QString faviconsDir;
+ QCache<QString> faviconsCache;
};
FaviconsModule::FaviconsModule(const QCString &obj)
@@ -63,6 +67,7 @@ FaviconsModule::FaviconsModule(const QCS
d->metaData.insert("ssl_militant", "TRUE");
d->config = new KSimpleConfig(locateLocal("data", "konqueror/faviconrc"));
d->killJobs.setAutoDelete(true);
+ d->faviconsCache.setAutoDelete(true);
}
FaviconsModule::~FaviconsModule()
@@ -74,8 +79,15 @@ QString FaviconsModule::iconForURL(const
{
if (url.host().isEmpty())
return QString::null;
+
+ QString icon;
+
+ QString *iconURL = d->faviconsCache.find( simplifyURL(url) );
+ if (iconURL)
+ icon = *iconURL;
+ else
+ icon = d->config->readEntry(simplifyURL(url));
- QString icon = d->config->readEntry(simplifyURL(url));
if (!icon.isEmpty())
icon = iconNameFromURL(icon);
else
@@ -129,11 +141,20 @@ bool FaviconsModule::isIconOld(const QSt
void FaviconsModule::setIconForURL(const KURL &url, const KURL &iconURL)
{
+ QString simplifiedURL = simplifyURL(url);
QString iconFile = d->faviconsDir + "favicons/" + iconNameFromURL(iconURL) + ".png";
- if (!isIconOld(iconFile))
+
+ if (!d->faviconsCache.insert(simplifiedURL, new QString(iconURL.url()) )) {
+ // AK - do failure stuff
+ }
+
+ if (!isIconOld(iconFile)) {
+ QString iconName = "favicons/" + iconNameFromURL(iconURL);
+ emit iconChanged(false, simplifiedURL, iconName);
return;
+ }
- startDownload(simplifyURL(url), false, iconURL);
+ startDownload(simplifiedURL, false, iconURL);
}
void FaviconsModule::downloadHostIcon(const KURL &url)
@@ -205,7 +226,7 @@ void FaviconsModule::slotResult(KIO::Job
iconName = iconNameFromURL(iconURL);
iconName = "favicons/" + iconName;
-
+
io.setIODevice(0);
io.setFileName(d->faviconsDir + iconName + ".png");
io.setFormat("PNG");
More information about the kfm-devel
mailing list