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

List:       kde-core-devel
Subject:    [PATCH] Fix KApplication for non-gui apps
From:       George Staikos <staikos () kde ! org>
Date:       2005-02-17 2:40:44
Message-ID: 200502162140.45011.staikos () kde ! org
[Download RAW message or body]

This evening, on the second most lousy flight I've ever been on (Air Canada 
can really suck sometimes), I got a chance to implement this patch for 
KApplication that Lars and I (well, mostly Lars) came up with.  It should fix 
the problems with creating a pixmap in non-gui mode.  It seems to be binary 
compatible, but it needs testing on different platforms.  Any comments?

-- 
George Staikos
KDE Developer				http://www.kde.org/
Staikos Computing Services Inc.		http://www.staikos.net/

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

? stamp-h3
Index: kapplication.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kapplication.cpp,v
retrieving revision 1.693
diff -u -3 -p -r1.693 kapplication.cpp
--- kapplication.cpp	15 Dec 2004 11:01:13 -0000	1.693
+++ kapplication.cpp	17 Feb 2005 02:29:31 -0000
@@ -593,6 +593,8 @@ KApplication::KApplication( int& argc, c
 #endif
   d (new KApplicationPrivate())
 {
+    aIconPixmap = 0L;
+    aMiniIconPixmap = 0L;
     read_app_startup_id();
     if (!GUIenabled)
        allowStyles = false;
@@ -616,6 +618,8 @@ KApplication::KApplication( bool allowSt
 #endif
   d (new KApplicationPrivate)
 {
+    aIconPixmap = 0L;
+    aMiniIconPixmap = 0L;
     read_app_startup_id();
     if (!GUIenabled)
        allowStyles = false;
@@ -635,6 +639,8 @@ KApplication::KApplication( Display *dpy
                 visual, colormap ),
   KInstance( KCmdLineArgs::about), display(0L), d (new KApplicationPrivate)
 {
+    aIconPixmap = 0L;
+    aMiniIconPixmap = 0L;
     read_app_startup_id();
     useStyles = allowStyles;
     setName( instanceName() );
@@ -650,6 +656,8 @@ KApplication::KApplication( Display *dpy
                 visual, colormap ),
   KInstance( _instance ), display(0L), d (new KApplicationPrivate)
 {
+    aIconPixmap = 0L;
+    aMiniIconPixmap = 0L;
     read_app_startup_id();
     useStyles = allowStyles;
     setName( instanceName() );
@@ -669,6 +677,8 @@ KApplication::KApplication( bool allowSt
 #endif
   d (new KApplicationPrivate)
 {
+    aIconPixmap = 0L;
+    aMiniIconPixmap = 0L;
     read_app_startup_id();
     if (!GUIenabled)
        allowStyles = false;
@@ -688,6 +698,8 @@ KApplication::KApplication(Display *disp
   display(0L),
   d (new KApplicationPrivate())
 {
+    aIconPixmap = 0L;
+    aMiniIconPixmap = 0L;
     read_app_startup_id();
     if (!GUIenabled)
        allowStyles = false;
@@ -1457,18 +1469,27 @@ void KApplication::parseCommandLine( )
     if (args->isSet("miniicon"))
     {
        const char *tmp = args->getOption("miniicon");
-       aMiniIconPixmap = SmallIcon(tmp);
+       if (!aMiniIconPixmap) {
+         aMiniIconPixmap = new QPixmap;
+       }
+       *aMiniIconPixmap = SmallIcon(tmp);
        aMiniIconName = tmp;
     }
 
     if (args->isSet("icon"))
     {
        const char *tmp = args->getOption("icon");
-       aIconPixmap = DesktopIcon( tmp );
+       if (!aIconPixmap) {
+          aIconPixmap = new QPixmap;
+       }
+       *aIconPixmap = DesktopIcon( tmp );
        aIconName = tmp;
-       if (aMiniIconPixmap.isNull())
+       if (!aMiniIconPixmap) {
+         aMiniIconPixmap = new QPixmap;
+       }
+       if (aMiniIconPixmap->isNull())
        {
-          aMiniIconPixmap = SmallIcon( tmp );
+          *aMiniIconPixmap = SmallIcon( tmp );
           aMiniIconName = tmp;
        }
     }
@@ -1524,11 +1545,13 @@ QString KApplication::geometryArgument()
 
 QPixmap KApplication::icon() const
 {
-  if( aIconPixmap.isNull()) {
-      KApplication *that = const_cast<KApplication *>(this);
-      that->aIconPixmap = DesktopIcon( instanceName() );
+  if( !aIconPixmap) {
+      aIconPixmap = new QPixmap;
   }
-  return aIconPixmap;
+  if( aIconPixmap->isNull()) {
+      *aIconPixmap = DesktopIcon( instanceName() );
+  }
+  return *aIconPixmap;
 }
 
 QString KApplication::iconName() const
@@ -1538,11 +1561,13 @@ QString KApplication::iconName() const
 
 QPixmap KApplication::miniIcon() const
 {
-  if (aMiniIconPixmap.isNull()) {
-      KApplication *that = const_cast<KApplication *>(this);
-      that->aMiniIconPixmap = SmallIcon( instanceName() );
+  if (!aMiniIconPixmap) {
+      aMiniIconPixmap = new QPixmap;
+  }
+  if (aMiniIconPixmap->isNull()) {
+      *aMiniIconPixmap = SmallIcon( instanceName() );
   }
-  return aMiniIconPixmap;
+  return *aMiniIconPixmap;
 }
 
 QString KApplication::miniIconName() const
@@ -1554,6 +1579,10 @@ extern void kDebugCleanup();
 
 KApplication::~KApplication()
 {
+  delete aMiniIconPixmap;
+  aMiniIconPixmap = 0L;
+  delete aIconPixmap;
+  aIconPixmap = 0L;
   delete d->m_KAppDCOPInterface;
 
   // First call the static deleters and then call KLibLoader::cleanup()
Index: kapplication.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kapplication.h,v
retrieving revision 1.321
diff -u -3 -p -r1.321 kapplication.h
--- kapplication.h	14 Nov 2004 12:05:49 -0000	1.321
+++ kapplication.h	17 Feb 2005 02:29:31 -0000
@@ -1161,8 +1161,9 @@ private:
   static bool s_dcopClientNeedsPostInit;
   QString aCaption; // the name for the window title
   bool bSessionManagement;
-  QPixmap aIconPixmap; // BIC (KDE 4) make a pointer, to avoid creating if noGUI
-  QPixmap aMiniIconPixmap; // BIC (KDE 4) make a pointer, to avoid creating if noGUI
+  mutable QPixmap *aIconPixmap;
+  mutable QPixmap *aMiniIconPixmap;
+  char unused[sizeof(QPixmap)*2 - sizeof(QPixmap*)*2]; // KDE4: remove me
   QString aIconName;
   QString aMiniIconName;
   bool useStyles;


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

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