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

List:       koffice
Subject:    Re: icons
From:       David Faure <David.Faure () insa-lyon ! fr>
Date:       1999-02-19 9:44:19
[Download RAW message or body]

On Fri, Feb 19, 1999 at 01:03:13AM +0100, David Faure wrote:
> I came up with the following patch, and tested it.
... but not enough.
It breaks at least kpanel, which relies on loadIcon returning 0L.

So I think I'd rather add a default parameter to loadIcon, set by ICON() and
Icon(), as all koffice apps use ICON()... It won't break other existing
apps, this way. loadIcon can still return 0L, but ICON will never, which is 
what we want.

I'll wait a little to commit it, in order to test it more, and to merge it
with other binary incompatible changes - changing kapp.h means recompiling
everything !

Index: kapp.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kapp.h,v
retrieving revision 1.61
diff -u -p -r1.61 kapp.h
--- kapp.h	1999/02/06 16:27:11	1.61
+++ kapp.h	1999/02/19 09:36:30
@@ -39,8 +39,8 @@
 #define i18n(X) KApplication::getKApplication()->getLocale()->translate(X)
 #endif
 
-#define Icon(x) kapp->getIconLoader()->loadIcon(x)         
-#define ICON(x) kapp->getIconLoader()->loadIcon(x)
+#define Icon(x) kapp->getIconLoader()->loadIcon(x,0,0,false)
+#define ICON(x) kapp->getIconLoader()->loadIcon(x,0,0,false)
 
 class KIconLoader;
 class KCharsets;
Index: kiconloader.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kiconloader.cpp,v
retrieving revision 1.26
diff -u -p -r1.26 kiconloader.cpp
--- kiconloader.cpp	1999/01/18 10:56:20	1.26
+++ kiconloader.cpp	1999/02/19 09:36:30
@@ -149,17 +149,19 @@ KIconLoader::~KIconLoader()
   pixmap_list.clear();
 }
 
-QPixmap KIconLoader::loadIcon ( const QString &name, int w, int h ){
+QPixmap KIconLoader::loadIcon ( const QString &name, int w, int h, bool canReturnNull ){
   QPixmap result = loadInternal(name, w, h);
 
 /* Stephan: It's OK to know, how many icons are still missing, but
        we don't need to tell everybody ;) Perhaps this can be con-
        verted to a KDEBUG solution, that is more silent? Don't know.
-
-  if (result.isNull())
-    warning(klocale->translate("ERROR: couldn't find icon: %s"), (const char *) name);
-
+   David: Re-enabled the warning. Most applications (esp. koffice) crash
+        if the icon doesn't exist, anyway. And base apps should be ok now.
 */
+  if (result.isNull() && !canReturnNull) {
+    warning("%s : ERROR: couldn't find icon: %s", kapp->appName().data(), name.data());
+    result = loadInternal("unknown.xpm", w, h);
+  }
 
   return result;
 }
Index: kiconloader.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kiconloader.h,v
retrieving revision 1.15
diff -u -p -r1.15 kiconloader.h
--- kiconloader.h	1998/11/02 10:08:35	1.15
+++ kiconloader.h	1999/02/19 09:36:30
@@ -109,7 +109,8 @@ public:
   /**
 	 This function searches for the icon called name 
 	 and returns a QPixmap object
-	 of this icon if it was found and 0 otherwise.
+	 of this icon if it was found and 0 otherwise (if canReturnNull is true).
+         Returns pixmap from unknown.xpm if canReturnNull is false.
 	 If name starts with "/..." loadIcon treats it as an absolut pathname.
 	 LoadIcon() creates a list of all loaded icons, 
 	 so calling loadIcon() a second time
@@ -123,7 +124,7 @@ public:
          0, the icon is not scaled at all.
 
   */
-  QPixmap loadIcon( const QString &name, int w = 0, int h = 0 );
+  QPixmap loadIcon( const QString &name, int w = 0, int h = 0, bool canReturnNull = true);
 
 
   /// Load an icon from disk without cache


-- 
 ____________________________________________________________________
|                                                                    |
|  David FAURE                                                       |
|  E-mail : David.Faure@insa-lyon.fr, faure@kde.org                  |
|  http://www.insa-lyon.fr/People/AEDI/dfaure/index.html             |
|____________________________________________________________________|

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

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