[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Debug warnings for broken icons
From:       Urs Wolfer <uwolfer () kde ! org>
Date:       2007-12-19 18:57:34
Message-ID: 200712191957.40300.uwolfer () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi all

I have had the idea to throw debug warnings about missing or wrong spelled 
icons in apps. It's something like the runtime debug warnings about broken 
connections in Qt.

Example:
khelpcenter(28217)/kdeui (KIconLoader) KIconLoader::loadIcon: No such 
icon "thumbnail"

It would help us to detect and fix such cases:
* You can see it quite fast in the debug output when there is an icon missing. 
A good testcase is for example the "Configure Toolbar" dialog.

* You can see the name of the broken icon in the debug. This makes it very 
easy to find the ussage(s) of this icon in the source code. Just do a simple 
grep in the application source folder (grep "\"brokenicon\"" * -R).

There is one problem: we will see this warning only once because of the icon 
cache. Currently, the icon cache caches the "unknown" icon if the icon is 
broken. There is not a really nice solution for this issue: either we don't 
cache broken images, so we can see it every time an app calls such an icon, 
or we output the warning only once. I have discussed that with Rivo (the 
author of the icon cache). We found a solution, but only for 4.1 because it 
adds some new features. For the moment, I prefer the way to not cache broken 
icons. This makes it way easier to find and fix such icons. Of course it 
would be nice if we have a #define when we compile kdelibs in debug mode (is 
that possible?). Then we could just not insert it into the cache when we are 
in debug mode.

Okay to commit this patch?

Bye
urs

["broken_icon_warnings.patch" (text/x-diff)]

Index: icons/kiconloader.cpp
===================================================================
--- icons/kiconloader.cpp	(revision 750617)
+++ icons/kiconloader.cpp	(working copy)
@@ -847,6 +847,7 @@
     QString name = _name;
     QString path;
     QPixmap pix;
+    bool unknownIcon = false;
     bool absolutePath = false;
     bool favIconOverlay = false;
 
@@ -889,6 +890,10 @@
                         iconPath(name, KIconLoader::User, canReturnNull);
         if (path.isEmpty())
         {
+            if (!canReturnNull) {
+                kWarning(264) << "No such icon" << _name;
+                unknownIcon = true;
+            }
             if (canReturnNull)
                 return pix;
             // We don't know the desired size: use small
@@ -910,7 +915,8 @@
 
         pix = QPixmap::fromImage(img);
         d->drawOverlays(this, KIconLoader::Desktop, state, pix, overlays);
-        d->mIconCache->insert(key, pix, path);
+        if (!unknownIcon)
+            d->mIconCache->insert(key, pix, path);
         return pix;
     }
 
@@ -1008,6 +1014,8 @@
                     return pix;
                 }
 
+                kWarning(264) << "No such icon" << _name;
+                unknownIcon = true;
                 icon = d->findMatchingIcon(str_unknown, size);
                 if (!icon.isValid())
                 {
@@ -1132,7 +1140,8 @@
 
     delete img;
 
-    d->mIconCache->insert(key, pix, path);
+    if (!unknownIcon)
+        d->mIconCache->insert(key, pix, path);
     return pix;
 }
 

["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic