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

List:       kde-devel
Subject:    Small krdb.cpp patch
From:       Ilya Konstantinov <kde-devel () future ! galanet ! net>
Date:       2001-08-01 18:54:01
[Download RAW message or body]

Hi,

I wrote a small patch to remove the 'create temporary file' stage from
'Apply styles to non-KDE applications', by feeding the X resources to
xrdb via stdin instead. It works and seems trivial (unless KProcess is
buggy).

Not sure it's appropriate at this moment though :)
["krdb-no-temp-file.patch" (text/plain)]

--- kdebase/kcontrol/display/krdb.cpp	2001/07/30 19:36:51	1.8
+++ kdebase/kcontrol/display/krdb.cpp	2001/08/01 18:44:31
@@ -98,6 +98,20 @@ static void copyFile(QFile& tmp, QString
   }
 }
 
+// -----------------------------------------------------------------------------
+
+static void copyFile(QString& str, QString const& filename)
+{
+  QFile f( filename );
+  if ( f.open(IO_ReadOnly|IO_Raw) ) {
+      QCString buf( 8192 );
+      while ( !f.atEnd() ) {
+          int read = f.readBlock( buf.data(), buf.size() );
+          if ( read > 0 )
+              str.append( QString::fromLatin1(buf.data()) );
+      }
+  }
+}
 
 // -----------------------------------------------------------------------------
 
@@ -217,34 +231,17 @@ void runRdb() {
     }
   }
 
-  QString propString;
-
-  KTempFile tmpFile;
-
-  if (tmpFile.status() != 0)
-  {
-    kdDebug() << "Couldn't open temp file" << endl;
-    exit(0);
-  }
-
-  QFile &tmp = *(tmpFile.file());
-  tmp.writeBlock( preproc.latin1(), preproc.length() );
-
   for (QStringList::ConstIterator it = list.begin(); it != list.end(); it++)
-    copyFile(tmp, locate("appdefaults", *it ));
+    copyFile(preproc, locate("appdefaults", *it ));
 
   // very primitive support for  ~/.Xdefaults by appending it
-  copyFile(tmp, QDir::homeDirPath() + "/.Xdefaults");
-
-  tmpFile.close();
+  copyFile(preproc, QDir::homeDirPath() + "/.Xdefaults");
 
   KProcess proc;
 
-  proc.setExecutable("xrdb");
-  proc << "-merge" << tmpFile.name();
-
-  proc.start( KProcess::Block, KProcess::Stdin );
+  proc << "xrdb";
+  proc << "-merge";
 
-  tmpFile.unlink();
+  proc.start( KProcess::DontCare, KProcess::Stdin );
+  proc.writeStdin( preproc.latin1(), preproc.length() );
 }
-

>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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