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

List:       kde-devel
Subject:    titlebar pixmaps patch
From:       Rene Beutler <rbeutler () g26 ! ethz ! ch>
Date:       1998-10-30 20:15:12
[Download RAW message or body]

hi,

chosing the titlebar pixmap within kcontrol does not work. there are several 
problems:

- if the directory ($HOME/.kde/share/apps/) kwm/pics does not exist, the pixmaps 
are not saved
- kwm does not update the titlebar pixmaps because they are cached by 
kiconloader. I added the possibillity to reload pixmaps and flush pixmaps from 
the cache. I am not sure whether this is binary compatible...

the changes concern the following files:
- kdebase/kcontrol/kwm/titlebar.cp
- kdebase/kwm/main.C
- kdelibs/kdecore/kiconloader.h
- kdelibs/kdecore/kiconloader.cpp

I attached the diffs (981029), which should be fine. Can someone apply them to 
the CVS?

Regards,
Rene Beutler


----
rbeutler@g26.ethz.ch

["titlebar.cpp.diff" (TEXT/plain)]

--- kdebase/kcontrol/kwm/titlebar.cpp.orig	Fri Oct 30 18:18:13 1998
+++ kdebase/kcontrol/kwm/titlebar.cpp	Fri Oct 30 18:23:38 1998
@@ -22,16 +22,17 @@
  */
 
 #include <iostream.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>
 
+#include <qdir.h>
 #include <qlayout.h> //CT 21Oct1998
 #include <kmsgbox.h> 
 #include <kmsgbox.h>
 #include <kapp.h>
 #include <kiconloaderdialog.h>
 #include <kiconloader.h>
 
 #include "titlebar.h"
@@ -1199,54 +1200,63 @@
 
   /*CT 18Oct1998 - these are no more needed
   config->writeEntry("TitlebarPixmapActive", sPixmapActive);
   config->writeEntry("TitlebarPixmapInactive", sPixmapInactive);
   */
 
   //CT 18Oct1998 - save the pixmaps
   if (t == TITLEBAR_PIXMAP ) {
+    QString kwmdir = kapp->localkdedir() + "/share/apps/kwm";
+    QString kwmpicsdir = kwmdir + "/pics";
+
+    QDir dir("/");
+    if( !dir.exists( (const char *)kwmdir ) )
+        dir.mkdir( (const char *)kwmdir );
+    if( !dir.exists( (const char *)kwmpicsdir ) )
+        dir.mkdir( (const char *)kwmpicsdir );
+
     //first, a backup
-    sPixmapActive = kapp->localkdedir() +
-      "/share/apps/kwm/pics/oldactivetitlebar.xpm";
-    
-    if (!pixmapActiveOld.isNull())
+    sPixmapActive   = kwmpicsdir + "/oldactivetitlebar.xpm";
+    sPixmapInactive = kwmpicsdir + "/oldinactivetitlebar.xpm";   
+ 
+    if (!pixmapActiveOld.isNull()) {
+      QFile( (const char *)sPixmapActive ).remove();
       pixmapActiveOld.save(sPixmapActive,"XPM");
+      iconLoader->flush( "oldactivetitlebar.xpm" );
+    }
 
-    sPixmapInactive = kapp->localkdedir() +
-      "/share/apps/kwm/pics/oldinactivetitlebar.xpm";
-
-    if (!pixmapInactiveOld.isNull())
+    if (!pixmapInactiveOld.isNull()) {
+      QFile( (const char *)sPixmapInactive ).remove();
       pixmapInactiveOld.save(sPixmapInactive,"XPM");
+      iconLoader->flush( "oldinactivetitlebar" );
+    }
 
     //then, the save
-    sPixmapActive = kapp->localkdedir() +
-      "/share/apps/kwm/pics/activetitlebar.xpm";
-    sPixmapInactive = kapp->localkdedir() +
-      "/share/apps/kwm/pics/inactivetitlebar.xpm";
-
-    //CT FIXME lazy!!! Uuuugly
-    system((const char *) ("rm " + sPixmapActive + " " + sPixmapInactive));
+    sPixmapActive   = kwmpicsdir + "/activetitlebar.xpm";
+    sPixmapInactive = kwmpicsdir + "/inactivetitlebar.xpm";
 
-    bool a_saved, i_saved;
-    if (!pixmapActive.isNull())
+    bool a_saved = true, i_saved = true;
+    if (!pixmapActive.isNull()) {
+      QFile( (const char *)sPixmapActive ).remove();
       a_saved = pixmapActive.save(sPixmapActive,"XPM");
-    else 
-      a_saved = FALSE;
+      iconLoader->flush( "activetitlebar.xpm" );
+    }
 
-    if (!pixmapInactive.isNull())
+    if (!pixmapInactive.isNull()) {
+      QFile( (const char *)sPixmapInactive ).remove();
       i_saved = pixmapInactive.save(sPixmapInactive,"XPM");
-    else
-      i_saved = FALSE;
+      iconLoader->flush( "inactivetitlebar.xpm" );
+    }
 
     //and a little check
     if ( !( a_saved && i_saved ) ) {
-      QMessageBox::critical(this, "Window manager setup - ERROR",
-			    "There was an error while saving\n"
-			    "the titlebar pixmaps! Please check permissions.");
+      QMessageBox::critical(this, i18n("Window manager setup - ERROR"),
+			    i18n("There was an error while saving\n"
+			    "the titlebar pixmaps! Please check permissions.") );
     }
   }
   //CT
 
   int a = getTitleAnim();
   config->writeEntry(KWM_TITLEANIMATION, a);
 
   //CT 11feb98 action on double click on titlebar

["kwm-main.C.diff" (TEXT/plain)]

--- kdebase/kwm/main.C.orig	Sat Oct 24 01:19:00 1998
+++ kdebase/kwm/main.C	Fri Oct 30 11:18:10 1998
@@ -751,19 +751,19 @@
     config->writeEntry("TitlebarLook", "shadedHorizontal");
     options.TitlebarLook = H_SHADED;
   }
 
   //CT 23Sep1998 - fixed the name of the titlebar pixmaps to become
   //   consistent with the buttons pixmaps definition technique
   if (options.TitlebarLook == PIXMAP) {
     *(options.titlebarPixmapActive) = getIconLoader()
-      ->loadIcon("activetitlebar.xpm");
+      ->reloadIcon("activetitlebar.xpm");
     *(options.titlebarPixmapInactive) = getIconLoader()
-      ->loadIcon("inactivetitlebar.xpm");
+      ->reloadIcon("inactivetitlebar.xpm");
 
     if (options.titlebarPixmapInactive->size() == QSize(0,0))
       *options.titlebarPixmapInactive = *options.titlebarPixmapActive;
 
     if (options.titlebarPixmapActive->size() == QSize(0,0))
       options.TitlebarLook = PLAIN;
   }
 

["iconloader.h.diff" (TEXT/plain)]

--- kdelibs/kdecore/kiconloader.h.orig	Sat Sep  5 00:21:22 1998
+++ kdelibs/kdecore/kiconloader.h	Fri Oct 30 18:32:57 1998
@@ -117,16 +117,25 @@
 
          If the icon is larger then the specified size, it is 
          scaled down automatically. If the specified size is 
          0, the icon is not scaled at all.
 
   */
   QPixmap loadIcon( const QString &name, int w = 0, int h = 0 );
 
+
+  /// Load an icon from disk without cache
+  /**
+      Same like loadIcon, except that cached icons will be reloaded.
+      This is useful if the icon has changed on the filesystem and you want to be
+      sure that you get the new version, not the old one from the cache.
+  */
+  QPixmap reloadIcon( const QString &name, int w = 0, int h = 0);
+  
   /// Load an mini icon from disk
   /**
 	 Same like loadIcon, but looks for "mini/name" first.
   */
   QPixmap loadMiniIcon( const QString &name , int w = 0, int h = 0 );
 
   /* 
    * The loadApplication-Icon functions are similar to the 
@@ -160,17 +169,21 @@
 	     6-x: list of directories in [KDE Setup]:IconPath=...
 
   */
 
   bool insertDirectory( int index, const QString &dir_name ) {
     return pixmap_dirs.insert( index, dir_name ); }
   QStrList* getDirList() { return &pixmap_dirs; }
 
-
+  /// Flush cache
+  /**
+      Remove an icon from the cache given it's name
+  */
+  void flush( const QString &name ); 
 
 protected:
   KConfig           *config;
   QStrList           name_list;
   QStrList           pixmap_dirs;
   QList<QPixmap>     pixmap_list;
   QPixmap loadInternal(const QString &name, int w = 0, int h = 0 );
 

["kiconloader.cpp.diff" (TEXT/plain)]

--- kdelibs/kdecore/kiconloader.cpp.orig	Mon Oct  5 01:03:15 1998
+++ kdelibs/kdecore/kiconloader.cpp	Fri Oct 30 18:27:32 1998
@@ -149,16 +149,22 @@
     warning(klocale->translate("ERROR: couldn't find icon: %s"), (const char *) name);
 
 */
 
   return result;
 }
 
 
+QPixmap KIconLoader::reloadIcon ( const QString &name, int w, int h ){
+  flush( name );
+
+  return loadInternal( name, w, h );
+}
+
 
 QPixmap KIconLoader::loadMiniIcon ( const QString &name, int w, int h ){
 
   QPixmap result;
 
   if (name.left(1)!='/'){
     result = loadInternal( "mini/" + name, w, h);
   }
@@ -287,9 +293,19 @@
 
   if (dir.exists()){
     pixmap_dirs.insert(0, path);
   }
   else{
     //    fprintf(stderr,"Path %s doesn't exist\n",path.data());
   }
 
+}
+
+void KIconLoader::flush( const QString& name  )
+{
+  int index;
+
+  if( (index = name_list.find(name)) >= 0 ) {
+     name_list.remove( index );
+     pixmap_list.remove( index );
+  }
 }


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

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