dslinux/user/pixil/packages/viewml/viewml/kdecore AUTHORS ChangeLog Makefile.am Makefile.in NEWS README TODO charsets.config ckey.h convert_key.c dither.cpp dither.h drag.cpp fakes.cpp kaccel.cpp kaccel.h kapp.cpp kcharsets.cpp kcharsetsdata.cpp kcharsetsdata.h kchartables.cpp kckey.cpp kckey.h kclipboard.cpp kclipboard.h kcolorgroup.cpp kcolorgroup.h kconfig.cpp kconfig.h kconfigbase.cpp kconfigbase.h kconfigdata.h kdebug.areas kdebug.cpp kdebug.h kdebugareas.txt kdebugdialog.h kglobalaccel.cpp kglobalaccel.h kiconloader.cpp kiconloader.h klocale.cpp kmisc.h kpixmap.cpp kpixmap.h kpoint.cpp kpoint.h kprocctrl.cpp kprocctrl.h kprocess.cpp kprocess.h krect.cpp krect.h krootprop.cpp krootprop.h ksimpleconfig.cpp ksimpleconfig.h ksize.cpp ksize.h ksock.cpp ksock.h kstdaccel.cpp kstdaccel.h kstddirs.cpp kstddirs.h kstring.cpp kstring.h kurl.cpp kurl.h kwm.cpp kwm.h libintl.cpp

amadeus dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:26:30 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/pixil/packages/viewml/viewml/kdecore
In directory antilope:/tmp/cvs-serv11916/packages/viewml/viewml/kdecore

Added Files:
	AUTHORS ChangeLog Makefile.am Makefile.in NEWS README TODO 
	charsets.config ckey.h convert_key.c dither.cpp dither.h 
	drag.cpp fakes.cpp kaccel.cpp kaccel.h kapp.cpp kcharsets.cpp 
	kcharsetsdata.cpp kcharsetsdata.h kchartables.cpp kckey.cpp 
	kckey.h kclipboard.cpp kclipboard.h kcolorgroup.cpp 
	kcolorgroup.h kconfig.cpp kconfig.h kconfigbase.cpp 
	kconfigbase.h kconfigdata.h kdebug.areas kdebug.cpp kdebug.h 
	kdebugareas.txt kdebugdialog.h kglobalaccel.cpp kglobalaccel.h 
	kiconloader.cpp kiconloader.h klocale.cpp kmisc.h kpixmap.cpp 
	kpixmap.h kpoint.cpp kpoint.h kprocctrl.cpp kprocctrl.h 
	kprocess.cpp kprocess.h krect.cpp krect.h krootprop.cpp 
	krootprop.h ksimpleconfig.cpp ksimpleconfig.h ksize.cpp 
	ksize.h ksock.cpp ksock.h kstdaccel.cpp kstdaccel.h 
	kstddirs.cpp kstddirs.h kstring.cpp kstring.h kurl.cpp kurl.h 
	kwm.cpp kwm.h libintl.cpp 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: kprocess.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Christian Czezakte (e9025461 at student.tuwien.ac.at)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
//
//  KPROCESS -- A class for handling child processes in KDE without
//  having to take care of Un*x specific implementation details
//
//  version 0.3.1, Jan 8th 1998
//
//  (C) Christian Czezatke
//  e9025461 at student.tuwien.ac.at
//

#ifndef __kprocess_h__
#define __kprocess_h__

#include <sys/types.h> // for pid_t
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <qstrlist.h>
#include <qobject.h>
#include <qsocketnotifier.h>


/**
  @short KProcess -- A class for invoking Child processes from within KDE applications
  @author Christian Czezakte e9025461 at student.tuwien.ac.at

1) General usage and features

  This class allows a KDE application to start child processes without having
  to worry about UN*X signal handling issues and zombie process reaping

  Basically, this class distinguishes three different ways of running
  child processes: 

  +) "KProcess::DontCare" -- The child process is invoked and both the child
  process and the parent process continue concurrently. 

  Starting a "DontCare" child process means that the application is
  not interested in any notification to determine whether the
  child process has already exited or not.
  
  +) "KProcess::NotifyOnExit" -- The child process is invoked both the
  child and the parent process run concurrently.
  
  When the child process exits, the KProcess instance
  corresponding to it emits the Qt Signal "processExited".
  
  Since this signal is _not_ emitted from within a UN*X
  signal handler, arbitrary function calls can be made.
  
  +) "KProcess::Block" -- The child process starts and the parent
  process is suspended 
  until the child process exits. (_Really_ not recommended for programs
  with a GUI)

  KProcess also provides several functions for determining the exit status
  and the pid of the child process it represents. 

  Furthermore it is possible to supply command-line arguments to the process
  in a clean fashion (no null -- terminated stringlists and such...)

  A small usage example:
  <pre>
  KProcess proc;

  proc &lt;&lt; "my_executable";
  proc &lt;&lt; "These" &lt;&lt; "are" &lt;&lt; "the" &lt;&lt; "command" &lt;&lt; "line" &lt;&lt; "args";
  QApplication::connect(&proc, SIGNAL(processExited(KProcess *)), 
                        pointer_to_my_object, SLOT(my_objects_slot));
  proc.start();
  </pre>  

  This will start "my_executable" with the commandline arguments "These"...
  
  When the child process exits, the respective Qt signal will be emitted.
  
  2) Communication with the child process
  
  KProcess supports communication with the child process through
  stdin/stdout/stderr.
  
  The following functions are provided for getting data from the child process
  or sending data to the child's stdin (For more information, have a look at the 
  documentation of each function):
  
  
  bool writeStdin(char *buffer, int buflen);
  -- Transmit data to the child process's stdin.
  
  bool closeStdin();
  -- Closes the child process's stdin (which causes it to see a "feof(stdin)")
  Returns FALSE if you try to close stdin for a process that has been started
  without a communication channel to stdin.
  
  QT signals:
  
  void receivedStdout(KProcess *proc, char *buffer, int buflen);
  void receivedStderr(KProcess *proc, char *buffer, int buflen);
  -- Indicates that new data has arrived from either the
  child process's stdout or stderr.
  
  void wroteStdin(KProcess *proc);
  -- Indicates that all data that has been sent to the child process
  by a prior call to "writeStdin" has actually been transmitted to the
  client 
*/
class KProcess : public QObject
{
  Q_OBJECT

public:

  /** enums for communication channels to open. If communication for more 
      than one channel is required, the values have to be or'ed together, 
      for example to get communication with stdout as well as with
      stdin, you would specify "Stdin | Stdout" 
  */
  enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4,
					   AllOutput = 6, All = 7 };

  /** various run--modes for a child process. For more information about the
      semantics of the run modes have a look at the general description of
      the @ref KProcess class.
  */
  enum RunMode { DontCare, NotifyOnExit, Block };

  /** Constructor */
  KProcess();

  /**
         Destructor:

	  If the process is running when the destructor for this class
	  is called, the child process is killed with a SIGKILL, but
	  only if the run mode is not of type "DontCare". --
	  Processes started as "DontCare" keep running anyway...
  */
  virtual ~KProcess();
 
  /**
         The use of this function is now depreciated. -- Please use the
	 "operator&lt;&lt;" instead of "setExecutable".

	 Sets the executable to be started with this KProcess object.
	 Returns FALSE if the process is currently running (in that
	 case the executable remains unchanged.) 

  */
  bool setExecutable(const char *proc);


  /** Sets the executable and the command line argument list for this process 
      
      For example, doning a "ls -l /usr/local/bin" can be achieved by:
      <pre>
      KProcess p;
      ...
      p &lt;&lt; "ls" &lt;&lt; "-l" &lt;&lt; "/usr/local/bin"
      </pre>

   */
  KProcess &operator<<(const char *arg);

  /** Clears a command line argument list that has been set by using the "operator&lt;&lt;".
  */
  void clearArguments();

  /** Starts up the process. -- For a detailed description of the 
      various run modes and communication semantics, have a look at the 
      general description of the KProcess class.

      This function returns TRUE if the process was started successfully.
      The following problems could cause KProcess:start" to return FALSE:

	  +) the process is already running

	  +) the command line argument list is empty 

	  +) the starting of the process failed (could not fork)

      The second argument specifies which communication links should be
      established to the child process. (stdin/stdout/stderr). By default,
      no communication takes place and the respective communication signals 
      will never get emitted.
  */
  virtual bool start(RunMode  runmode = NotifyOnExit, Communication comm = NoCommunication);

  /**
     Stops the process (by sending a SIGTERM to it). -- You may send other
     signals too of course... ;-) ) 

     Returns TRUE if the signal could be delivered successfully
  */
  virtual bool kill(int signo = SIGTERM);

  /**
     Returns TRUE if the process is (still) considered to be running
  */
  bool isRunning();

  /** Returns the process id of the process. If it is called after
      the process has exited, it returns the process id of the last
      child process that was created by this instance of KProcess.

      Calling it before any child process has been started by this
      KProcess instance causes getPid to return 0
  */    
  pid_t getPid();


  /** Returns TRUE if the process has already finished and has exited
      "voluntarily", ie: it has not been killed by a signal.
  */
  bool normalExit();

  /** Returns the exit status of the process. Please use "KProcess::normalExit" to 
      check whether the process has exited cleanly (KProcess::normalExit returning
      TRUE) before calling this function because if the process did not exit
      normally, it does not have a valid exit status.
  */
  int  exitStatus(); 

   
  /**
	 Transmit data to the child process's stdin. KProcess::writeStdin
         may return FALSE in the following cases:

         +) The process is not currently running

	 +) Communication to stdin has not been requested in the "start" call

         +) transmission of data to the child process by a previous call to "writeStdin"
            is still in progress. 

	 Please note that the data is sent to the client asynchronousely,
	 so when this function returns, the data might not have been
	 processed by the child process. 

	 If all the data has been sent to the client, the signal
	 "wroteStdin" will be emitted. 

	 Please note that you must not free "buffer" or call "writeStdin"
	 again until either a "wroteStdin" signal indicates that the data has been sent or a
	 "processHasExited" signal shows that the child process is no
	 longer alive... 
  */
  bool writeStdin(char *buffer, int buflen);

  /**
     This causes the stdin file descriptor of the child process to be
	 closed indicating an "EOF" to the child. This function will
	 return FALSE if:

	 +) No communication to the process's stdin has been specified in the "start" call.
  */
  bool closeStdin();

  signals: 

  /**
     This signal gets emitted after the process has terminated when
	 the process was run in the "NotfiyOnExit"  (=default option to
	 "start") or the "Block" mode. 
  */     
  void processExited(KProcess *proc);

 
  /**
     These signals get emitted, when output from the child process has
	 been received on stdout. -- To actually get
	 these signals, the respective communication link (stdout/stderr)
	 has to be turned on in "start". 

     "buffer" contains the data, and "buflen" bytes are available from
	 the client. 

     You should copy the information contained in "buffer" to your private
     data structures before returning from this slot.
  */
  void receivedStdout(KProcess *proc, char *buffer, int buflen);


  /**
     These signals get emitted, when output from the child process has
	 been received on stderr. -- To actually get
	 these signals, the respective communication link (stdout/stderr)
	 has to be turned on in "start". 

     "buffer" contains the data, and "buflen" bytes are available from
	 the client. 

     You should copy the information contained in "buffer" to your private
     data structures before returning from this slot.
  */
  void receivedStderr(KProcess *proc, char *buffer, int buflen);

  /**
     This signal gets emitted after all the data that has been
	 specified by a prior call to "writeStdin" has actually been
	 written to the child process. 
  */
  void wroteStdin(KProcess *proc);


protected slots:

 /**
   This slot gets activated when data from the child's stdout arrives.
   It usually calls "childOutput"
  */
  void slotChildOutput(int fdno);

 /**
   This slot gets activated when data from the child's stderr arrives.
   It usually calls "childError"
  */
  void slotChildError(int fdno);
  /*
	Slot functions for capturing stdout and stderr of the child 
  */


  /**
	Called when another bulk of data can be sent to the child's
	stdin. If there is no more data to be sent to stdin currently
	available, this function must disable the QSocketNotifier "innot".
  */
  void slotSendData(int dummy);

protected:

  /**
     The list of the process' command line arguments. The first entry
     in this list is the executable itself.
  */
  QStrList arguments;
  /**
     How to run the process (Block, NotifyOnExit, DontCare). You should
     not modify this data member directly from derived classes.
  */
  RunMode run_mode;
  /** 
     TRUE if the process is currently running. You should not 
     modify this data member directly from derived classes. For
     reading the value of this data member, please use "isRunning()"
     since "runs" will probably be made private in later versions
     of KProcess.
  */
  bool runs;

  /** 
      The PID of the currently running process (see "getPid()").
      You should not modify this data member in derived classes.
      Please use "getPid()" instead of directly accessing this
      member function since it will probably be made private in
      later versions of KProcess.
  */

  pid_t pid;

  /** The process' exit status as returned by "waitpid". You should not 
      modify the value of this data member from derived classes. You should
      rather use "getStatus()" than accessing this data member directly
      since it will probably be made private in further versions of
      KProcess.
  */
  int status;


  /*
	Functions for setting up the sockets for communication.
	setupCommunication 
	-- is called from "start" before "fork"ing.
	commSetupDoneP
	-- completes communcation socket setup in the parent
	commSetupDoneC
	-- completes communication setup in the child process
	commClose
	-- frees all allocated communication ressources in the parent
	after the process has exited
  */

  /**
    This function is called from "KProcess::start" right before a "fork" takes 
    place. According to
    the "comm" parameter this function has to initialize the "in", "out" and
    "err" data member of KProcess.

    This function should return 0 if setting the needed communication channels
    was successful. 

    The default implementation is to create UNIX STREAM sockets for the communication,
    but you could overload this function and establish a TCP/IP communication for
    network communication, for example. 
  */      
  virtual int setupCommunication(Communication comm);

  /**
     Called right after a (successful) fork on the parent side. This function
     will usually do some communications cleanup, like closing the reading end
     of the "stdin" communication channel.

     Furthermore, it must also create the QSocketNotifiers "innot", "outnot" and
     "errnot" and connect their Qt slots to the respective KProcess member functions.

     For a more detailed explanation, it is best to have a look at the default
     implementation of "setupCommunication" in @ref kprocess.cpp.
  */
  virtual int commSetupDoneP();
 
  /**
     Called right after a (successful) fork, but before an "exec" on the child
     process' side. It usually just closes the unused communication ends of
     "in", "out" and "err" (like the writing end of the "in" communication
     channel.
  */
  virtual int commSetupDoneC();


  /**
     Immediately called after a process has exited. This function normally calls commClose
     to close all open communication channels to this process and emits the "processExited"
     signal (if the process was not running in the "DontCare" mode).
  */
  virtual void processHasExited(int state);
  /**
     Should clean up the communication links to the child after it has exited. Should
     be called from "processHasExited".
  */
  virtual void commClose();
  

  int out[2], in[2], err[2];
  /* the socket descriptors for stdin/stdout/stderr */

  QSocketNotifier *innot, *outnot, *errnot;
  /* The socket notifiers for the above socket descriptors */

  /**
     Lists the communication links that are activated for the child process.
     Should not be modified from derived classes.
  */
  Communication communication;		



  /**
     Called by "slotChildOutput" this function copies data arriving from the
     child process's stdout to the respective buffer and emits the signal
     "receivedStderr"
  */
  int childOutput(int fdno);

  /**
     Called by "slotChildOutput" this function copies data arriving from the
     child process's stdout to the respective buffer and emits the signal
     "receivedStderr"
  */
  int childError(int fdno);
   
  // information about the data that has to be sent to the child:

  char *input_data;  // the buffer holding the data
  int input_sent;    // # of bytes already transmitted
  int input_total;   // total length of input_data

  /**
    @ref KProcessController is a friend fo KProcess because it has to have
    access to various data members.
  */
  friend class KProcessController;


private:
  // Disallow assignment and copy-construction
  KProcess( const KProcess& );
  KProcess& operator= ( const KProcess& );
};

/**
  @short A class derived from @ref KProcess to start child processes through a shell
  @author Christian Czezakte e9025461 at student.tuwien.ac.at

This class is similar to @ref KProcess. The only difference is that KShellProcess runs 
the specified executable through a UN*X shell so that standard shell mechanisms like
wildcard matching, use of pipes and environment variable expansion will work.

For example, you could run commands like the following through KShellProcess:
<pre>
  ls ~/HOME/ *.lyx | sort | uniq |wc -l 
</pre>

KShellProcess tries really hard to find a valid executable shell. Here is the 
algorithm used for finding an executable shell:

	   +) Try to use executable pointed to by the "SHELL" environment variable

	   +) Try the executable pointed to by the "SHELL" environment variable with
whitespaces stripped off

	   +) "/bin/sh" as a last ressort.
*/
class KShellProcess: public KProcess
{
  Q_OBJECT

public:

  /**
      Constructor

      By specifying the name of a shell (like "/bin/bash") you can override
      the mechanism for finding a valid shell as described in the detailed
      description of this class.
  */
  KShellProcess(const char *shellname=NULL);
  ~KShellProcess();

  /** 
    Starts up the process. -- For a detailed description
    have a look at the "start" member function and the detailed
    description of @ref KProcess .

  */
  virtual bool start(RunMode  runmode = NotifyOnExit, Communication comm = NoCommunication);

private:

  /** searches for a valid shell. See the general description of this class for
      information on how the search is actually performed.
  */
  char *searchShell();

  /** used by "searchShell" in order to find out whether the shell found is actually
      executable at all.
  */
  bool isExecutable(const char *fname);


  char *shell;

  // Disallow assignment and copy-construction
  KShellProcess( const KShellProcess& );
  KShellProcess& operator= ( const KShellProcess& );
};



#endif

--- NEW FILE: kckey.cpp ---
#include <qkeycode.h>
#include "ckey.h"

--- NEW FILE: kconfigbase.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: kconfigbase.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
//
// $Log: kconfigbase.h,v $
// Revision 1.1  2006-10-03 11:26:26  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:04  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
// Initial import of ViewML
//
// Revision 1.14  1998/11/22 21:52:33  garbanzo
// Fixed some comments that referred to sync() as Sync(), and a few other case issues.
//
// Revision 1.13  1998/10/20 18:58:12  ettrich
// ugly hack to get rid of X11 includes, small fix
//
// Revision 1.12  1998/10/07 06:49:23  kalle
// Correctly read double dollar signs (patch by Harri Porten)
// Dollar expansion can be turned off with setDollarExpansion( false ).
// \sa isDollarExpansion
//
// Revision 1.11  1998/08/22 20:02:37  kulow
// make kdecore have nicer output, when compiled with -Weffc++ :)
//
// Revision 1.10  1998/03/29 19:07:30  kalle
// Methods for reading and writing bool, unsigned int, long, unsigned long,
// double, QRect, QSize, QPoint
//
// Revision 1.9  1998/01/18 14:38:51  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.7  1998/01/09 08:06:47  kalle
// KConfigGroupSaver
//
// Revision 1.6  1997/12/12 14:46:03  denis
// Reverting to lower case true/false
//
// Revision 1.5  1997/12/12 14:33:46  denis
// replaced true by TRUE and false by FALSE
//
// Revision 1.4  1997/10/21 20:44:45  kulow
// removed all NULLs and replaced it with 0L or "".
// There are some left in mediatool, but this is not C++
//
// Revision 1.3  1997/10/16 11:14:31  torben
// Kalle: Copyright headers
// kdoctoolbar removed
//
// Revision 1.2  1997/10/05 02:31:11  jones
// MRJ: Changed const char *readEntry( ... ) to QString readEntry( ... )
// I had to do this - almost everything was broken.
//
// Revision 1.1  1997/10/04 19:51:04  kalle
// new KConfig
//

#ifndef _KCONFIGBASE_H
#define _KCONFIGBASE_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


// Qt includes
#include <qcolor.h>
#include <qfont.h>
#include <qstrlist.h>

// KDE includes
#include <kconfigdata.h>

/**
* Abstract base class for KDE configuration entries
*
*	This class forms the base for all KDE configuration. It is an
* 	abstract base class, meaning that you cannot directly instantiate
* 	objects of this class. Either use KConfig (for usual KDE
* 	configuration) or KSimpleConfig (for special needs like ksamba).
*	one application, independent of the configuration files they came
*	from.
*
*	All configuration entries are of the form "key=value" and
*	belong to a certain group. A group can be specified in a
*	configuration file with "[GroupName]". All configuration entries
*	from the beginning of a configuration file to the first group
*	declaration belong to a special group called the default group.
*
*	If there is a $ character in a entry, KConfig tries to expand
*	environment variable and uses its value instead of its name. You
*	can avoid this feature by having two consecutive $ characters in
*	your config file which get expanded to one.
*
*   Lines starting with a hash mark(#) are comment lines.
*
* @author Kalle Dalheimer (kalle at kde.org)
* @version $Id: kconfigbase.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
* @see KApplication::getConfig KConfig KSimpleConfig
* @short KDE Configuration Management abstract base class
*/

#include <qfile.h>
#include <qobject.h>
#include "kdebug.h"

class KConfigBaseData;

class KConfigBase : public QObject
{
  Q_OBJECT

private:
  KConfigBaseData* pData;

  // copy-construction and assignment are not allowed
  KConfigBase( const KConfigBase& );
  KConfigBase& operator= ( const KConfigBase& rConfig );

protected:
  /**
	* Access to the configuration data.
	*
	* @return a pointer to the configuration base data
	*/
  KConfigBaseData* data() const { return pData; }

  /**
	* Read the locale and put in the configuration data struct.
	* Note: This should be done in the constructor, but this is not
	* possible due to some mutual dependencies in KApplication::init()
	*/
  void setLocale();

  /** Parse all configuration files for a configuration object.
	*
	* This method must be reimplemented by the derived classes. It
	*  should go through the list of appropriate files for a
	* configuration object, open the files and call
	* parseOneConfigFile() for each one of them.
	*/
  virtual void parseConfigFiles() = 0;

  /** Parse one configuration file.
	*
	* This method contains the actual configuration file parser. It
	* can overridden by derived classes for specific parsing
	* needs. For normal use, this should not be necessary.
	*	
	* @param rFile The configuration file to parse
	* @param pGroup
	* @param bGlobal
	*/
  virtual void parseOneConfigFile( QFile& rFile,
								   KGroupDict* pGroup = 0L,
								   bool bGlobal = false );

  /** Write configuration file back.
	*
	* This method must be reimplemented by derived classes. It should
	* dump the data of the configuration object to the appropriate
	* files.
	*
	* @param rFile The file to write
	* @param bGlobal Should the data be saved to a global file
	* @return Whether some entries are left to be written to other
	*  files.
	*/
  virtual bool writeConfigFile( QFile& rFile, bool bGlobal = false ) = 0;

public:
  /**
	* Construct a KConfigBase object.
	*/
  KConfigBase();

  /**
	* Destructor.
	*
	* Writes back any dirty configuration entries.
	*/
  virtual ~KConfigBase();

  /**
	* Specify the group in which keys will be searched.
	*
	* Switch back to the default group by passing an empty string.
	*  @param pGroup The name of the new group.
	*/
  void setGroup( const char* pGroup );

  /**
	* Retrieve the group where keys are currently searched in.
	*
	* @return The current group
	*/
  const char* group() const;

  /**
	* Retrieve the group where keys are currently searched in. Note:
	* this method is deprecated; use KConfigBase::group() instead.
	*
	* @return The current group
	*/
  const char* getGroup() const { debug( "KConfigBase::getGroup() is deprecated, use KConfigBase::group() instead" );
  return group(); }

  /**
	* Read the value of an entry specified by rKey in the current group
	*
	* @param pKey	The key to search for.
	* @param pDefault A default value returned if the key was not found.
	* @return The value for this key or an empty string if no value
	*	  was found.
	*/
  const QString readEntry( const char* pKey,
						 const char* pDefault = 0L ) const;

  /**
	* Read a list of strings.
	*
	* @param pKey The key to search for
	* @param list In this object, the read list will be returned.
	* @param sep  The list separator (default ",")
	* @return The number of entries in the list.
	*/
  int readListEntry( const char* pKey, QStrList &list,
					 char sep = ',' ) const;

  /**
	* Read a numerical value.
	*
	* Read the value of an entry specified by rKey in the current group
	* and interpret it numerically.
	*
	* @param pKey The key to search for.
	* @param nDefault A default value returned if the key was not found.
	* @return The value for this key or 0 if no value was found.
	*/
  int readNumEntry( const char* pKey, int nDefault = 0 ) const;

  /**
	* Read a numerical value.
	*
	* Read the value of an entry specified by rKey in the current group
	* and interpret it numerically.
	*
	* @param pKey The key to search for.
	* @param nDefault A default value returned if the key was not found.
	* @return The value for this key or 0 if no value was found.
	*/
  unsigned int readUnsignedNumEntry( const char* pKey,
									 unsigned int nDefault = 0 ) const;
  /**
	* Read a numerical value.
	*
	* Read the value of an entry specified by rKey in the current group
	* and interpret it numerically.
	*
	* @param pKey The key to search for.
	* @param nDefault A default value returned if the key was not found.
	* @return The value for this key or 0 if no value was found.
	*/
  long readLongNumEntry( const char* pKey, long nDefault = 0 ) const;

  /**
	* Read a numerical value.
	*
	* Read the value of an entry specified by rKey in the current group
	* and interpret it numerically.
	*
	* @param pKey The key to search for.
	* @param nDefault A default value returned if the key was not found.
	* @return The value for this key or 0 if no value was found.
	*/
  unsigned long readUnsignedLongNumEntry( const char* pKey,
										  unsigned long nDefault = 0 ) const;


  /**
	* Read a numerical value.
	*
	* Read the value of an entry specified by rKey in the current group
	* and interpret it numerically.
	*
	* @param pKey The key to search for.
	* @param nDefault A default value returned if the key was not found.
	* @return The value for this key or 0 if no value was found.
	*/
  double readDoubleNumEntry( const char* pKey, double nDefault = 0.0 ) const;

  /**
	* Read a QFont.
	*
	* Read the value of an entry specified by rKey in the current group
	* and interpret it as a font object.
	*
	* @param pKey		The key to search for.
	* @param pDefault	A default value returned if the key was not found.
	* @return The value for this key or a default font if no value was found.
	*/
  QFont readFontEntry( const char* pKey,
					   const QFont* pDefault = 0L ) const;

  /**
   * Read a boolean entry.
   *
   * Read the value of an entry specified by pKey in the current group
   * and interpret it as a boolean value. Currently "on" and "true" are
   * accepted as true, everything else if false.
   *
   * @param pKey		The key to search for
   * @param bDefault    A default value returned if the key was not
   * 					found.
   * @return The value for this key or a default value if no value was
   * found.
   */
  bool readBoolEntry( const char* pKey, const bool bDefault = false ) const;


  /**
   * Read a rect entry.
   *
   * Read the value of an entry specified by pKey in the current group
   * and interpret it as a QRect object.
   *
   * @param pKey		The key to search for
   * @param pDefault	A default value returned if the key was not
   *	 				found.
   * @return The value for this key or a default rectangle if no value
   * was found.
   */
  QRect readRectEntry( const char* pKey, const QRect* pDefault = 0L ) const;


  /**
   * Read a point entry.
   *
   * Read the value of an entry specified by pKey in the current group
   * and interpret it as a QPoint object.
   *
   * @param pKey		The key to search for
   * @param pDefault	A default value returned if the key was not
   *	 				found.
   * @return The value for this key or a default point if no value
   * was found.
   */
  QPoint readPointEntry( const char* pKey, const QPoint* pDefault = 0L ) const;


  /**
   * Read a size entry.
   *
   * Read the value of an entry specified by pKey in the current group
   * and interpret it as a QSize object.
   *
   * @param pKey		The key to search for
   * @param pDefault	A default value returned if the key was not
   *	 				found.
   * @return The value for this key or a default point if no value
   * was found.
   */
  QSize readSizeEntry( const char* pKey, const QSize* pDefault = 0L ) const;


  /**
	* Read a QColor.
	*
	* Read the value of an entry specified by rKey in the current group
	* and interpret it as a color.
	*
	* @param pKey		The key to search for.
	* @param pDefault	A default value returned if the key was not found.
	* @return The value for this key or a default color if no value
	* was found.
	*/
  QColor readColorEntry( const char* pKey,
						 const QColor* pDefault = 0L ) const;

  /** Write the key/value pair.
	*
	* This is stored to the most specific config file when destroying the
	* config object or when calling sync().
	*
	*  @param pKey		The key to write.
	*  @param pValue	The value to write.
	*  @param bPersistent	If bPersistent is false, the entry's dirty
	*			flag will not be set and thus the entry will
	*			not be written to disk at deletion time.
	*  @param bGlobal	If bGlobal is true, the pair is not saved to the
	*   application specific config file, but to the global ~/.kderc
	*  @param bNLS	If bNLS is true, the locale tag is added to the key
	*   when writing it back.
	*  @return The old value for this key. If this key did not
	*   exist, a null string is returned.	
*/
  const char* writeEntry( const char* pKey, const char* pValue,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /**
	* writeEntry() overriden to accept a list of strings.
	*
	* Note: Unlike the other writeEntry() functions, the old value is
	* _not_ returned here!
	*
	* @param pKey		The key to write
	* @param list		The list to write
	* @param sep		The list separator
	* @param bPersistent	If bPersistent is false, the entry's dirty flag
	*			will not be set and thus the entry will not be
	*			written to disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	*
	* @see #writeEntry
	*/
  void writeEntry ( const char* pKey, QStrList &list, char sep = ',',
					bool bPersistent = true, bool bGlobal = false,
					bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a numerical value.
	* @param pKey The key to write.
	* @param nValue The value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	* exist, a null string is returned.	
	*/
  const char* writeEntry( const char* pKey, int nValue,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write an unsigned numerical value.
	* @param pKey The key to write.
	* @param nValue The value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	* exist, a null string is returned.	
	*/
  const char* writeEntry( const char* pKey, unsigned int nValue,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a long numerical value.
	* @param pKey The key to write.
	* @param nValue The value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	* exist, a null string is returned.	
	*/
  const char* writeEntry( const char* pKey, long nValue,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write an unsigned long numerical value.
	* @param pKey The key to write.
	* @param nValue The value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	* exist, a null string is returned.	
	*/
  const char* writeEntry( const char* pKey, unsigned long nValue,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a floating-point value.
	* @param pKey The key to write.
	* @param nValue The value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	* exist, a null string is returned.	
	*/
  const char* writeEntry( const char* pKey, double nValue,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a boolean value.
	* @param pKey The key to write.
	* @param bValue The value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	* exist, a null string is returned.	
	*/
  const char* writeEntry( const char* pKey, bool bValue,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a font
	* @param pKey The key to write.
	* @param rFont The font value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	* exist, a null string is returned.	
	*/
  const char* writeEntry( const char* pKey, const QFont& rFont,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a color
	* @param pKey The key to write.
	* @param rValue The color value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	*  exist, a null string is returned.	
	*/
  void writeEntry( const char* pKey, const QColor& rColor,
				   bool bPersistent = true, bool bGlobal = false,
				   bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a rectangle
	* @param pKey The key to write.
	* @param rValue The rectangle value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	*  exist, a null string is returned.	
	*/
  void writeEntry( const char* pKey, const QRect& rColor,
				   bool bPersistent = true, bool bGlobal = false,
				   bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a point
	* @param pKey The key to write.
	* @param rValue The point value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	*  exist, a null string is returned.	
	*/
  void writeEntry( const char* pKey, const QPoint& rColor,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );

  /** Write the key value pair.
	* Same as above, but write a size
	* @param pKey The key to write.
	* @param rValue The size value to write.
	* @param bPersistent If bPersistent is false, the entry's dirty
	* flag will not be set and thus the entry will not be written to
	* disk at deletion time.
	* @param bGlobal	If bGlobal is true, the pair is not saved to the
	*  application specific config file, but to the global ~/.kderc
	* @param bNLS	If bNLS is true, the locale tag is added to the key
	*  when writing it back.
	* @return The old value for this key. If this key did not
	*  exist, a null string is returned.	
	*/
  void writeEntry( const char* pKey, const QSize& rColor,
						  bool bPersistent = true, bool bGlobal = false,
						  bool bNLS = false );
  //}


	/** Turns on or off "dollar expansion" when reading config entries.
	 *	@param bExpand if true, dollar expansion is turned on.
	 */
	void setDollarExpansion( bool bExpand = true );

	/** Returns whether dollar expansion is on or off.
	 *	@return true if dollar expansion is on.
	 */
	bool isDollarExpansion() const;

  /** Don't write dirty entries at destruction time. If bDeep is
	* false, only the global dirty flag of the KConfig object gets
	* cleared. If you then call writeEntry again, the global dirty flag
	* is set again and all dirty entries will be written.
	* @param bDeep if
	* true, the dirty flags of all entries are cleared, as well as the
	* global dirty flag.
	*/
  virtual void rollback( bool bDeep = true );

  /** Flush the entry cache. Write back dirty configuration entries to
	* the most specific file. This is called automatically from the
	* destructor.
	* This method must be implemented by the derived classes.
   */
  virtual void sync() = 0;

  /** Check if the key has an entry in the specified group
	  Use this to determine if a key is not specified for the current
	  group (HasKey returns false) or is specified but has no value
	  ("key =EOL"; Has Key returns true, ReadEntry returns an empty
	  string)
	  @param pKey The key to search for.
	  @return if true, the key is available
   */
  bool hasKey( const char* pKey ) const;

  /** Returns an iterator on the list of groups
	  @return The group iterator. The caller is reponsable for
	  deleting the iterator after using it.
  */
  KGroupIterator* groupIterator(void) { return pData->groupIterator(); }

  /** Returns an iterator on the entries in the current group
	  @param pGroup the group to provide an iterator for
	  @return The iterator for the group or 0, if the group does not
	  exist. The caller is responsible for deleting the iterator after
	  using it.
	  */
  KEntryIterator* entryIterator( const char* pGroup );

  /** Reparses all configuration files. This is useful for programms
	  which use standalone graphical configuration tools.
   */
  virtual void reparseConfiguration();
};


/**
  * Helper class to facilitate working with KConfig/KSimpleConfig groups
  *
  * Careful programmers always set the group of a
  * KConfig/KSimpleConfig object to the group they want to read from
  * and set it back to the old one of afterwards. This is usually
  * written as
  *
  * QString oldgroup config->group();
  * config->setGroup( "TheGroupThatIWant" );
  * ...
  * config->writeEntry( "Blah", "Blubb" );
  *
  * config->setGroup( oldgroup );
  *
  * In order to facilitate this task, you can use
  * KConfigGroupSaver. Simply construct such an object ON THE STACK
  * when you want to switch to a new group. Then, when the object goes
  * out of scope, the group will automatically be restored. If you
  * want to use several different groups within a function or method,
  * you can still use KConfigGroupSaver: Simply enclose all work with
  * one group (including the creation of the KConfigGroupSaver object)
  * in one block.
  *
  * @author Kalle Dalheimer <kalle at kde.org>
  * @version $Id: kconfigbase.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
  * @see KConfigBase, KConfig, KSimpleConfig
  * @short helper class for easier use of KConfig/KSimpleConfig groups
  */

class KConfigGroupSaver
{
public:
  /** Constructor. You pass a pointer to the KConfig/KSimpleConfig
	* object you want to work with and a string indicating the _new_
	* group.
	* @param config the KConfig/KSimpleConfig object this
	* KConfigGroupSaver works on
	* @param group the new group that the KConfig/KSimpleConfig object
	* should switch to
	*/
  KConfigGroupSaver( KConfigBase* config, QString group )
      : _config(config), _oldgroup(config->group())
	{
	  //	  _config = config;
	  //	  _oldgroup = _config->group();
	  _config->setGroup( group );
	};

  ~KConfigGroupSaver()
	{
	  _config->setGroup( _oldgroup );
	}

private:
  KConfigBase* _config;
  QString _oldgroup;

  KConfigGroupSaver(const KConfigGroupSaver&);
  KConfigGroupSaver& operator=(const KConfigGroupSaver&);
};

#endif

--- NEW FILE: kstring.cpp ---
#include "kstring.h"
#include <stdio.h>  
#include <stdarg.h>

QString& operator<<( QString& _str, short _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, ushort _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, int _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, uint _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, long _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, ulong _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, float _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, double _v )
{
    QString tmp;
    tmp.setNum( _v );
    _str += tmp.data();
    return _str;
}

QString& operator<<( QString& _str, const char* _v )
{
    _str += _v;
    return _str;
}

void ksprintf(QString *str, const char *fmt, ...)
{
    va_list ap;
    va_start( ap, fmt );

    int i = 0;
    int len = 255 + strlen(fmt); // default is the same as in QString::sprintf
    int dummy; // this ugly hack is just to avoid warnings

    while (fmt[i+1]) {

	if (fmt[i] == '%' && fmt[i+1] != '%' ) { // argument
	    if (fmt[i+1] == 's') {
		const char *str = va_arg( ap, const char*);
		len += strlen(str);
	    } else
		dummy = va_arg (ap, int); // take it out of the arg list
	} else // jump over "%%"
	    if (fmt[i] == '%' && fmt[i+1] == '%') i++;

	i++; 
    }

    va_end( ap); // oh god, what I hope, that restarting is portable

    char *tmp_data = new char[len]; // make enough space

    va_start( ap, fmt ); // the rest does the libc for us
    vsprintf( tmp_data, fmt, ap );
    va_end( ap );

    *str = tmp_data; // makes deep copy, that is also resized
    
    delete [] tmp_data; // clear the heap
}

--- NEW FILE: kurl.cpp ---
// -*-C++-*-
/* This file is part of the KDE libraries
    Copyright (C) 1997 Steffen Hansen (stefh at dit.ou.dk)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
[...1122 lines suppressed...]

}



/*
**
**
**
*/
bool KURL::isLocalFile() 
{
  if (protocol_part != "file")
    return false;
  
  if (hasSubProtocol())
    return false;
  
  return host_part.isEmpty();
}

--- NEW FILE: ksize.cpp ---
// KSize - (c) by Reginald Stadlbauer 1998 <reggie at kde.org>
// Version: 0.0.1

#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif

#include <qsize.h>

#include "ksize.h"

//==========================================================
KSize::KSize()
{
  wid = -1;
  hei = -1;
}

//==========================================================
KSize::KSize(int _wid,int _hei)
{
  wid = _wid;
  hei = _hei;
}

//==========================================================
KSize::KSize(const QSize &_size)
{
  wid = _size.width();
  hei = _size.height();
}
  
//==========================================================
bool KSize::isNull() const
{
  return (wid == 0 && hei == 0);
}

//==========================================================
bool KSize::isEmpty() const
{
  return (wid <= 0 || hei <= 0);
}

//==========================================================
bool KSize::isValid() const
{
  return (wid >= 0 && hei >= 0);
}
  
//==========================================================
int KSize::width() const
{
  return wid;
}

//==========================================================
int KSize::height() const
{
  return hei;
}

//==========================================================
void KSize::setWidth(int _wid)
{
  wid = _wid;
}

//==========================================================
void KSize::setHeight(int _hei)
{
  hei = _hei;
}

//==========================================================
void KSize::transpose()
{
  wid = wid^hei;
  hei = wid^hei;
  wid = wid^hei;
}

//==========================================================
KSize KSize::expandedTo(const KSize &_size) const
{
  return KSize(max(wid,_size.width()),max(hei,_size.height()));
}

//==========================================================
KSize KSize::boundedTo(const KSize &_size) const
{
  return KSize(min(wid,_size.width()),min(hei,_size.height()));
}
  
//==========================================================
int &KSize::rwidth()
{
  return wid;
}

//==========================================================
int &KSize::rheight()
{
  return hei;
}
  
//==========================================================
KSize &KSize::operator+=(const KSize &_size)
{
  wid += _size.width();
  hei += _size.height();

  return *this;
}

//==========================================================
KSize &KSize::operator-=(const KSize &_size)
{
  wid -= _size.width();
  hei -= _size.height();

  return *this;
}

//==========================================================
KSize &KSize::operator*=(int _c)
{
  wid *= _c;
  hei *= _c;

  return *this;
}

//==========================================================
KSize &KSize::operator*=(float _c)
{
  wid = static_cast<int>(wid * _c);
  hei = static_cast<int>(hei * _c);

  return *this;
}

//==========================================================
KSize &KSize::operator/=(int _c)
{
  wid /= _c;
  hei /= _c;

  return *this;
}

//==========================================================
KSize &KSize::operator/=(float _c)
{
  wid = static_cast<int>(wid / _c);
  hei = static_cast<int>(hei / _c);

  return *this;
}

//==========================================================
KSize::operator QSize() const
{
  return QSize(wid,hei);
}

//==========================================================
bool operator==(const KSize &_size1,const KSize &_size2)
{
  return (_size1.width() == _size2.width() && _size1.height() == _size2.height());
}

//==========================================================
bool operator!=(const KSize &_size1,const KSize &_size2)
{
  return (_size1.width() != _size2.width() || _size1.height() != _size2.height());
}

//==========================================================
bool operator==(const QSize &_size1,const KSize &_size2)
{
  return (_size1.width() == _size2.width() && _size1.height() == _size2.height());
}

//==========================================================
bool operator!=(const QSize &_size1,const KSize &_size2)
{
  return (_size1.width() != _size2.width() || _size1.height() != _size2.height());
}

//==========================================================
bool operator==(const KSize &_size1,const QSize &_size2)
{
  return (_size1.width() == _size2.width() && _size1.height() == _size2.height());
}

//==========================================================
bool operator!=(const KSize &_size1,const QSize &_size2)
{
  return (_size1.width() != _size2.width() || _size1.height() != _size2.height());
}

//==========================================================
KSize operator+(const KSize &_size1,const KSize &_size2)
{
  return KSize(_size1.width() + _size2.width(),_size1.height() + _size2.height());
}

//==========================================================
KSize operator-(const KSize &_size1,const KSize &_size2)
{
  return KSize(_size1.width() - _size2.width(),_size1.height() - _size2.height());
}

//==========================================================
KSize operator*(const KSize &_size,int _c)
{
  return KSize(_size.width() * _c,_size.height() * _c);
}

//==========================================================
KSize operator*(int _c,const KSize &_size)
{
  return KSize(_size.width() * _c,_size.height() * _c);
}

//==========================================================
KSize operator*(const KSize &_size,float _c)
{
  return KSize(_size.width() * _c,_size.height() * _c);
}

//==========================================================
KSize operator*(float _c,const KSize &_size)
{
  return KSize(_size.width() * _c,_size.height() * _c);
}

//==========================================================
KSize operator/(const KSize &_size,int _c)
{
  return KSize(_size.width() / _c,_size.height() / _c);
}

//==========================================================
KSize operator/(const KSize &_size,float _c)
{
  return KSize(_size.width() / _c,_size.height() / _c);
}

--- NEW FILE: kcharsetsdata.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Jacek Konieczny (jajcus at zeus.polsl.gliwice.pl)
    $Id: kcharsetsdata.cpp,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
	*/
[...971 lines suppressed...]
        }
	++(*it);
      }  
  }
  delete it;
  return ""; 
}

QString KCharsetsData::toX(QString name){

  if ( strncmp(name,"iso-",4)==0 ){
      name="iso"+name.mid(4,100);
      return name;
  }
  if ( strncmp(name,"koi8", 4) == 0 )
      return name;

  config->setGroup("XNames");
  return config->readEntry(name,"");
}

--- NEW FILE: ksock.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Torben Weis (weis at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

/*
 * $Id: ksock.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
 *
 * $Log: ksock.h,v $
 * Revision 1.1  2006-10-03 11:26:27  dslinux_amadeus
 * adding pristine copy of pixil to HEAD so I can branch from it
 *
 * Revision 1.1  2003/09/08 19:42:05  jasonk
 * Addition of packages directory and associated files.
 *
 * Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
 * Initial import of PIXIL into new cvs repository.
 *
 * Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
 *
 *
 * Revision 1.1.1.1  2000/07/07 16:10:59  jasonk
 * Initial import of ViewML
 *
 * Revision 1.20  1998/11/11 00:02:55  thufir
 * addes ability to set a connect Time Out, breaks binary compatability
 *
 * Revision 1.19  1998/09/01 20:21:33  kulow
 * I renamed all old qt header files to the new versions. I think, this looks
 * nicer (and gives the change in configure a sense :)
 *
 * Revision 1.18  1998/08/22 20:02:47  kulow
 * make kdecore have nicer output, when compiled with -Weffc++ :)
 *
 * Revision 1.17  1998/03/28 11:02:08  kulow
 * undef NULL for egcs's sake
 *
 * Revision 1.16  1998/03/26 22:06:41  torben
 * Torben: Little bug fix in copy constructor
 *
 * Revision 1.15  1998/01/24 11:13:58  kulow
 * changed the order of the header files
 *
 * Revision 1.14  1998/01/24 00:12:02  kulow
 * added sys/socket.h
 *
 * Revision 1.13  1998/01/23 02:23:40  torben
 * Torben: Supports UNIX domain sockets now.
 *
 * Revision 1.12  1998/01/18 14:39:05  kulow
 * reverted the changes, Jacek commited.
 * Only the RCS comments were affected, but to keep them consistent, I
 * thought, it's better to revert them.
 * I checked twice, that only comments are affected ;)
 *
 * Revision 1.10  1997/12/18 01:56:25  torben
 * Torben: Secure string operations. Use instead of QString::sprintf
 *
 * Revision 1.9  1997/10/21 20:44:53  kulow
 * removed all NULLs and replaced it with 0L or "".
 * There are some left in mediatool, but this is not C++
 *
 * Revision 1.8  1997/10/16 11:15:03  torben
 * Kalle: Copyright headers
 * kdoctoolbar removed
 *
 * Revision 1.7  1997/09/18 12:16:05  kulow
 * corrected some header dependencies. Removed most of them in drag.h and put
 * them in drag.cpp. Now it should compile even under SunOS 4.4.1 ;)
 *
 * Revision 1.6  1997/08/30 08:32:56  kdecvs
 * Coolo: changed the location of the include files to get rid of the
 * hardcoded HAVE_STDC_HEADERS
 *
 * Revision 1.5  1997/07/27 13:43:59  kalle
 * Even more SGI and SCC patches, security patch for kapp, various fixes for ksock
 *
 * Revision 1.4  1997/07/25 19:46:43  kalle
 * SGI changes
 *
 * Revision 1.3  1997/07/18 05:49:18  ssk
 * Taj: All kdecore doc now in javadoc format (hopefully).
 *
 * Revision 1.2  1997/06/25 14:22:13  ssk
 * Taj: updated some documentation.
 *
 * Revision 1.1.1.1  1997/04/13 14:42:42  cvsuser
 * Source imported
 *
 * Revision 1.1.1.1  1997/04/09 00:28:07  cvsuser
 * Sources imported
 *
 * Revision 1.4  1997/01/15 20:34:14  kalle
 * merged changes from 0.52
 *
 * Revision 1.3  1996/12/07 22:23:07  kalle
 * autoconf, documentation
 *
 * Revision 1.2  1996/12/07 18:32:00  kalle
 * RCS header
 *
 *
 * The KDE Socket Classes.
 *
 * Torben Weis
 * weis at stud.uni-frankfurt.de
 *
 * Part of the KDE Project.
 */

#ifndef KSOCK_H
#define KSOCK_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef NULL
#undef NULL
#endif
#define NULL 0

#include <sys/types.h>
#include <sys/socket.h> 
#include <sys/un.h>
#include <netinet/in.h>

#include <qsocketnotifier.h>

/** 
 * A TCP/IP client socket. You can connect this socket to any internet address. 
 *
 * The socket gives you three signals: When ready for reading/writing or 
 * if the connection is broken.  Using socket() you get a file descriptor
 * which you can use with usual unix commands like write(..) or read(...). 
 * If you have already such a socket identifier you can construct a KSocket
 * on this identifier. 
 *  
 * If socket() delivers a value of -1 or less, the connection 
 * had no success.
 *
 * @author Torben Weis <weis at uni-frankfurt.de>
 * @version $Id: ksock.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
 * @short a TCP/IP client socket.
 */
class KSocket : public QObject
{
    Q_OBJECT
public:
    /** 
     * Create a KSocket with the provided file descriptor.
     * @param _sock	the file descriptor to use.
     */
    KSocket( int _sock )
	: sock(_sock), domain(0), 
	readNotifier(0), writeNotifier(0) {}
    
    /** 
     * Create a socket and connect to a host.
     * @param _host	the remote host to which to connect.
     * @param _port	the port on the remote host.
     */
    KSocket( const char *_host, unsigned short int _port );
    KSocket( const char *_host, unsigned short int _port, int timeOut);
    
    /** 
     * Connects to a UNIX domain socket.
     * @param _path    the filename of the socket
     */
    KSocket( const char *_path );

    /** 
     * Destructor. Closes the socket if it is still open.
     */
    ~KSocket();
    
    /** 
     * Returns a file descriptor for this socket.
     */
    int socket() const { return sock; }
    
    /** 
     * Enable the socket for reading.
     *
     * If you enable read mode, the socket will emit the signal
     * readEvent whenever there is something to read out of this
     * socket.
     */
    void enableRead( bool );
    
    /** 
     * Enable the socket for writing.
     *
     * If you enable write mode, the socket will emit the signal
     * writeEvent whenever the socket is ready for writing.
     */
    void enableWrite( bool );
    
    /**
     * Return address.
     */
    unsigned long getAddr();
    
signals:
    /** 
     * Data has arrived for reading.
     *
     * This signal will only be raised if enableRead( TRUE ) was called
     * first.
     */
    void readEvent( KSocket * );
    
    /** 
     * Socket is ready for writing.
     *
     * This signal will only be raised if enableWrite( TRUE ) was called
     * first.
     */
    void writeEvent( KSocket * );
    
    /** 
     * Raised when the connection is broken.
     */
    void closeEvent( KSocket * );
    
public slots:
    /** 
     * Connected to the writeNotifier.
     */
    void slotWrite( int );
    
    /** 
     * Connected to the readNotifier.
     */
    void slotRead( int );
    
protected:
    bool connect( const char *_host, unsigned short int _port );
    bool connect( const char *_path );
  
    bool init_sockaddr( const char *hostname, unsigned short int port );
    
    struct sockaddr_in server_name;
    struct sockaddr_un unix_addr;

    /******************************************************
     * The file descriptor for this socket. sock may be -1.
     * This indicates that it is not connected.
     */
    int sock;

    int domain;
  
    QSocketNotifier *readNotifier;
    QSocketNotifier *writeNotifier;

private:
    int timeOut;
    
    KSocket(const KSocket&);
    KSocket& operator=(const KSocket&);
};


/**
 * Monitor a port for incoming TCP/IP connections.
 *
 * You can use a KServerSocket to listen on a port for incoming
 * connections. When a connection arrived in the port, a KSocket
 * is created and the signal accepted is raised. Make sure you
 * always connect to this signal. If you dont the ServerSocket will
 * create new KSocket's and no one will delete them!
 *
 * If socket() is -1 or less the socket was not created properly.
 *
 * @author Torben Weis <weis at stud.uni-frankfurt.de>
 * @version $Id: ksock.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
 * @short Monitor a port for incoming TCP/IP connections.
*/
class KServerSocket : public QObject
{
    Q_OBJECT
public:
    /**
     * Constructor.
     * @param _port	the port number to monitor for incoming connections.
     */
    KServerSocket( int _port );

    /**
     * Creates a UNIX domain server socket.
     */
    KServerSocket( const char *_path );
  
    /** 
     * Destructor. Closes the socket if it was not already closed.
     */
    ~KServerSocket();
    
    /** 
     * Get the file descriptor assoziated with the socket.
     */
    int socket() const { return sock; }

    /** 
     * Returns the port number which is being monitored.
     */
    unsigned short getPort();

    /** 
     * The address.
     */
    unsigned long getAddr();

public slots: 
    /** 
     * Called when someone connected to our port.
     */
    virtual void slotAccept( int );

signals:
    /**
     * A connection has been accepted.
     * It is your task to delete the KSocket if it is no longer needed.
     */
    void accepted( KSocket* );

protected:
    bool init( short unsigned int );
    bool init( const char* _path );
  
    /** 
     * Notifies us when there is something to read on the port.
     */
    QSocketNotifier *notifier;
    
    /** 
     * The file descriptor for this socket. sock may be -1.
     * This indicates that it is not connected.
     */    
    int sock;  

    int domain;

private:
    KServerSocket(const KServerSocket&);
    KServerSocket& operator=(const KServerSocket&);
};

#endif



--- NEW FILE: kstring.h ---
#ifndef __kstring_h__
#define __kstring_h__

#include <qstring.h>

QString& operator<<( QString&, short );
QString& operator<<( QString&, ushort );
QString& operator<<( QString&, int );
QString& operator<<( QString&, uint );
QString& operator<<( QString&, long );
QString& operator<<( QString&, ulong );
QString& operator<<( QString&, float );
QString& operator<<( QString&, double );
QString& operator<<( QString&, const char* );

/* replaces QString::sprintf, where it's not sure, that 256
   bytes are enough for the resulting string.
   
   ksprintf adds to the 256 default bytes the len of every
   used string. 
   */
void ksprintf(QString *str, const char *fmt, ...);

#endif

--- NEW FILE: fakes.cpp ---

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef HAVE_FUNC_SETENV

#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif

#include <string.h>
#include <stdlib.h>

int setenv(const char *name, const char *value, int overwrite) {
    int i;
    char * a;

    if (!overwrite && getenv(name)) return 0;

    i = strlen(name) + strlen(value) + 2;
    a = (char*)malloc(i);
    if (!a) return 1;
    
    strcpy(a, name);
    strcat(a, "=");
    strcat(a, value);
    
    return putenv(a);
}

int unsetenv(const char *name) {
    int i;
    char * a;

    i = strlen(name) + 2;
    a = (char*)malloc(i);
    if (!a) return 1;
    
    strcpy(a, name);
    strcat(a, "=");
    
    return putenv(a);
}

#endif

#ifndef HAVE_USLEEP

#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif

#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif

extern "C" {

void usleep(unsigned int usec) {
        struct timeval _usleep_tv;
        _usleep_tv.tv_sec = usec/1000000;
        _usleep_tv.tv_usec = usec%1000000;
        select(0,0,0,0,&_usleep_tv);
}

}

#endif

#if !defined(HAVE_GETDOMAINNAME)

#include <sys/utsname.h> 
#include <netdb.h>
#include <strings.h>
#include <errno.h>
#include <stdio.h>

int getdomainname(char *name, size_t len)
{
        struct utsname uts;
        struct hostent *hent;
        int rv = -1;

        if (name == 0L)
          errno = EINVAL;
        else
        {               
                name[0] = '\0';
                if (uname(&uts) >= 0)
                {
                        if ((hent = gethostbyname(uts.nodename)) != 0L)
                        {
                                char *p = strchr(hent->h_name, '.');
                                if (p != 0L)
                                {
                                        ++p;
                                        if (strlen(p) > len-1)
                                          errno = EINVAL;
                                        else
                                        {
                                                strcpy(name, p);
                                                rv = 0;
                                        }
                                }
                        }
                }
        }
        return rv;
}


#endif

#ifndef HAVE_RANDOM
long int random(void)
{
    return lrand48();
}

void srandom(unsigned int seed)
{
    srand48(seed);
}
#endif

--- NEW FILE: kstddirs.h ---
/*
* kstddirs.h -- Declaration of class KStandardDirs.
* Generated by newclass on Thu Mar  5 16:05:28 EST 1998.
*/
#ifndef SSK_KSTDDIRS_H
#define SSK_KSTDDIRS_H

#include<qstring.h>
#include<qdict.h>

class QStrList;

/**
* Site-independent access to standard KDE directories.
*
* The various directory accessors allow you to access the various
* KDE FSSTND directories in a portable way.
*
* Since the KDE FSSTND is heirarchical, the accessors provide the
* ability to get the directory in the most to the least specific
* location (in order, Application/User/System);
*
* Additionally, each accessor has the ability to find the most
* specific directory that actually exists. The default is no check
* whether the directory exists.
* 
* Ordinarily, you will not want to manually instantiate this class.
* The global @ref KApplication object instantiates and provides const 
* access to a <code>KStandardDirs</code> object via the 
* @ref KApplication::dirs method.
*
* @author Sirtaj Singh Kang <taj at kde.org>
* @version $Id: kstddirs.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
*/
class KStandardDirs
{
public:
	/**
	* KStandardDirs Constructor.
	* @param appName The name of the application, which will be
	*		used for searching the "apps" directory.
	*/
	KStandardDirs( const char *appName );

	/**
	* KStandardDirs Destructor.
	*/
	~KStandardDirs();

	/** 
	 * The scope of a directory. App is the application-specific
	 * directory in the user's local KDE directory, User is the
	 * user's local KDE directory, SysApp is the application-specific
	 * directory in the system directory and System is the system
	 * directory in which KDE is installed.
	 *
	 * Closest is used for searching the first directory in the
	 * list that exists, in the order App, User, SysApp, System.
	 */
	enum DirScope { Closest, App, User, SysApp, System };

	/** 
	 * The full path to the application-specific directory.
	 */
	const char *app		(DirScope s = Closest) const;

	/** 
	 * The full path to the kde binary directory.
	 */
	const char *bin		(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which KDE-specific
	 * CGI programs are stored.
	 */
	const char *cgi		(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which configuration
	 * files are stored.
	 */
	const char *config	(DirScope s = Closest) const;

	/** 
	 * The full path to the data directory.
	 */
	const char *apps	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which HTML documentation
	 * is saved. This does not take into account the current
	 * locale setting.
	 */
	const char *html	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which icon images are stored.
	 */
	const char *icon	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which locale information
	 * and translation catalogues are stored.
	 */
	const char *locale	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which MIME information
	 * is stored.
	 */
	const char *mime	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which mini icons are stored.
	 */
	const char *parts	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which toolbar icons are
	 * stored.
	 */
	const char *toolbar	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which wallpapers are stored.
	 */
	const char *wallpaper	(DirScope s = Closest) const;

	/** 
	 * The full path to the directory in which sound files are stored.
	 */
	const char *sound	(DirScope s = Closest) const;

	/** 
	* Finds the executable in the system path. A valid executable must
	* be a file and have its executable bit set.
	*
	* @see #findAllExe
	* @param appname the name of the executable file for which to search.
	* @param pathstr The path which will be searched. If this is 
	* 		0 (default), the $PATH environment variable will 
	*		be searched.
	* @param ignoreExecBit	If true, an existing file will be returned
	*			even if its executable bit is not set.
	*
	* @return The path of the executable. If it was not found, this string 
	*	will be null.
	*/
	static QString findExe( const char *appname, const char *pathstr=0,
			     bool ignoreExecBit=false );

	/** 
	 * Finds all occurences of an executable in the system path.
	 *
	 * @see	#findExe
	 *
	 * @param list	will be filled with the pathnames of all the
	 *		executables found. Will be empty if the executable
	 *		was not found.
	 * @param appname	The name of the executable for which to
	 *	 		search.
	 * @param pathstr	The path list which will be searched. If this
	 *		is 0 (default), the $PATH environment variable will
	 *		be searched.
	 * @param ignoreExecBit If true, an existing file will be returned
	 *			even if its executable bit is not set.
	 *
	 * @return The number of executables found, 0 if none were found.
	 */
	static int findAllExe( QStrList& list, const char *appname,
			const char *pathstr=0, bool ignoreExecBit=false );

private:

	/** 
	 * Finds a directory, subject to the suffix and scope.
	 */
	const char *closest( DirScope scope, const char *suffix ) const;



	/** Application name. */
	QString *_appName;
	const char *_appPath;

	// Directory dictionaries

	QDict<QString> *_app;
	QDict<QString> *_sysapp;
	QDict<QString> *_sys;
	QDict<QString> *_user;

	QString UserDir;
	const char * const KDEDir;

  // Disallow assignment and copy-construction
  KStandardDirs( const KStandardDirs& ) {};
  KStandardDirs& operator= ( const KStandardDirs& ) {};
};

#endif // SSK_KSTDDIRS_H

--- NEW FILE: ksimpleconfig.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: ksimpleconfig.cpp,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
//
// $Log: ksimpleconfig.cpp,v $
// Revision 1.1  2006-10-03 11:26:27  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:05  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
// Initial import of ViewML
//
// Revision 1.13  1999/01/18 10:56:24  kulow
// .moc files are back in kdelibs. Built fine here using automake 1.3
//
// Revision 1.12  1999/01/15 09:30:41  kulow
// it's official - kdelibs builds with srcdir != builddir. For this I
// automocifized it, the generated rules are easier to maintain than
// selfwritten rules. I have to fight with some bugs of this tool, but
// generally it's better than keeping them updated by hand.
//
// Revision 1.11  1998/09/01 20:21:32  kulow
// I renamed all old qt header files to the new versions. I think, this looks
// nicer (and gives the change in configure a sense :)
//
// Revision 1.10  1998/01/18 14:39:01  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.8  1998/01/15 13:22:30  kalle
// Read-only mode for KSimpleConfig
//
// Revision 1.7  1998/01/11 13:41:42  kalle
// Write tag line for MIME detection even in KSimpleConfig
//
// Revision 1.6  1997/12/18 20:51:34  kalle
// Some patches by Alex and me
//
// Revision 1.5  1997/10/21 20:44:52  kulow
// removed all NULLs and replaced it with 0L or "".
// There are some left in mediatool, but this is not C++
//
// Revision 1.4  1997/10/16 11:15:02  torben
// Kalle: Copyright headers
// kdoctoolbar removed
//
// Revision 1.3  1997/10/10 16:14:24  kulow
// removed one more default value from the implementation
//
// Revision 1.2  1997/10/08 19:28:53  kalle
// KSimpleConfig implemented
//
// Revision 1.1  1997/10/04 19:51:07  kalle
// new KConfig
//

#include <ksimpleconfig.h>

#include <qfileinfo.h>

KSimpleConfig::KSimpleConfig( const char* pFile )
{
  if( pFile )
	{
	  // the file should exist in any case
	  QFileInfo info( pFile );
	  if( !info.exists() )
		{
		  QFile file( pFile );
		  file.open( IO_WriteOnly );
		  file.close();
		}

	  // we use the global app config file to save the filename 
	  data()->aGlobalAppFile = pFile;
	}
  
  parseConfigFiles();
}


KSimpleConfig::KSimpleConfig( const char* pFile, bool bReadOnly )
{
  if( pFile )
	{
	  if( !bReadOnly )
		{
		  // the file should exist in any case if the object is not read-only
		  QFileInfo info( pFile );
		  if( !info.exists() )
			{
			  QFile file( pFile );
			  file.open( IO_WriteOnly );
			  file.close();
			}
		}

	  // we use the global app config file to save the filename 
	  data()->aGlobalAppFile = pFile;
	}

  data()->bReadOnly = bReadOnly;

  parseConfigFiles();
}


KSimpleConfig::~KSimpleConfig()
{
  if( !data()->bReadOnly )
	sync();
}


void KSimpleConfig::parseConfigFiles()
{
  QFile aFile( data()->aGlobalAppFile );
  if( data()->bReadOnly )
	aFile.open( IO_ReadOnly );
  else
	aFile.open( IO_ReadWrite );
  parseOneConfigFile( aFile, 0L );
  aFile.close();
}


const QString KSimpleConfig::deleteEntry( const char* pKey, bool bLocalized )
{
  // retrieve the current group dictionary
  KEntryDict* pCurrentGroupDict = data()->aGroupDict[ data()->aGroup.data() ];
  
  if( pCurrentGroupDict )
    {
	  if( bLocalized )
		{	  
		  QString aLocalizedKey = QString( pKey );
		  aLocalizedKey += "[";
		  aLocalizedKey += data()->aLocaleString;
		  aLocalizedKey += "]";
		  // find the value for the key in the current group
		  KEntryDictEntry* pEntryData = (*pCurrentGroupDict)[ aLocalizedKey.data() ];
		  if( pEntryData )
			{
			  QString aValue = pEntryData->aValue;
			  pCurrentGroupDict->remove( pKey );
			  return aValue.copy();
			}
		  else
			return QString();
		}
	  else
		{
		  KEntryDictEntry* pEntryData = (*pCurrentGroupDict)[ pKey ];
		  if( pEntryData )
			{
			  QString aValue = pEntryData->aValue;
			  pCurrentGroupDict->remove( pKey );
			  return aValue.copy();
			}
		  else
			return QString();
		}
	}
  else 
	return QString();
}


bool KSimpleConfig::deleteGroup( const char* pGroup, bool bDeep )
{
  // retrieve the group dictionary
  KEntryDict* pGroupDict = data()->aGroupDict[ pGroup ];
  
  if( pGroupDict )
	{
	  if( pGroupDict->count() && !bDeep )
		// there are items which should not be deleted
		return false;
	  else
		{
		  // simply remove the group dictionary, since the main group
		  // dictionary is set to autoDelete, the items will be deleted,
		  // too
		  data()->aGroupDict.remove( pGroup );
		  return true;
		}
	}
  else
	// no such group
	return false;
}

/** Write back the configuration data.
  */
bool KSimpleConfig::writeConfigFile( QFile& rFile, bool )
{
  if( data()->bReadOnly )
	return true; // fake that the data was written

  rFile.open( IO_Truncate | IO_WriteOnly );
  QTextStream* pStream = new QTextStream( &rFile );

  // write a magic cookie for Fritz' mime magic
  *pStream << "# KDE Config File\n";
  
  // write back -- start with the default group
  KEntryDict* pDefWriteGroup = data()->aGroupDict[ "<default>" ];
  if( pDefWriteGroup )
	{
	  QDictIterator<KEntryDictEntry> aWriteInnerIt( *pDefWriteGroup );
	  while( aWriteInnerIt.current() )
		{
		  if( aWriteInnerIt.current()->bNLS && 
			  QString( aWriteInnerIt.currentKey() ).right( 1 ) != "]" )
			// not yet localized, but should be
			*pStream << aWriteInnerIt.currentKey() << '[' 
					 << data()->aLocaleString << ']' << "=" 
					 << aWriteInnerIt.current()->aValue << '\n';
		  else
			// need not be localized or already is
			*pStream << aWriteInnerIt.currentKey() << "=" 
					 << aWriteInnerIt.current()->aValue << '\n';
		  ++aWriteInnerIt;
		}
	}
  
  QDictIterator<KEntryDict> aWriteIt( data()->aGroupDict );
  while( aWriteIt.current() )
	{
	  // check if it's not the default group (which has already been written)
	  if( strcmp (aWriteIt.currentKey(), "<default>" ) )
		{
		  *pStream << '[' << aWriteIt.currentKey() << ']' << '\n';
		  QDictIterator<KEntryDictEntry> aWriteInnerIt( *aWriteIt.current() );
		  while( aWriteInnerIt.current() )
			{
			  if( aWriteInnerIt.current()->bNLS && 
				  QString( aWriteInnerIt.currentKey() ).right( 1 ) != "]" )
				// not yet localized, but should be
				*pStream << aWriteInnerIt.currentKey() << '[' 
						 << data()->aLocaleString << ']' << "=" 
						 << aWriteInnerIt.current()->aValue << '\n';
			  else
				// need not be localized or already is
				*pStream << aWriteInnerIt.currentKey() << "="
						 << aWriteInnerIt.current()->aValue << '\n';
			  ++aWriteInnerIt;
			}
		}
	  ++aWriteIt;
	}
  
  // clean up
  delete pStream;
  rFile.close();

  return true;
}

void KSimpleConfig::sync()
{
  if( data()->bReadOnly )
	return;

  QFile aFile( data()->aGlobalAppFile );
  writeConfigFile( aFile, false );
}

#include "ksimpleconfig.moc"


--- NEW FILE: kcharsets.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Jacek Konieczny (jajcus at zeus.polsl.gliwice.pl)
    $Id: kcharsets.cpp,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
	*/

#define KCHARSETS_CPP 
#include "kcharsetsdata.h"
#include "qstrlist.h"
#include "qfontinfo.h"
#include "qregexp.h"
#include <kapp.h>


KCharsetsData *KCharsets::data=0;
KCharsetsData *KCharset::data=0;
KCharsets *KCharset::charsets=0;
KCharsetsData *KCharsetConverterData::kcharsetsData=0;
uint KCharsets::count=0;

/////////////////////////////////////////////////////////////////

KCharset::KCharset(){
  
   if (!data || !charsets){
      fatal("KCharset constructor called when no KCharsets object created");
      return;
   }   
   entry=0;
}

KCharset::KCharset(const KCharsetEntry *e){
  
   if (!data || !charsets){
      fatal("KCharset constructor called when no KCharsets object created");
      return;
   }   
   entry=e;
}

KCharset::KCharset(const char *str){

   if (!data || !charsets){
      fatal("KCharset constructor called when no KCharsets object created");
      return;
   }   
   entry=data->charsetEntry(str);
}

KCharset::KCharset(const QString s){

   if (!data || !charsets){
      fatal("KCharset constructor called when no KCharsets object created");
      return;
   }   
   entry=data->charsetEntry((const char*)s);
}

KCharset::KCharset(QFont::CharSet qtCharset){

  if (!data || !charsets){
      fatal("KCharset constructor called when no KCharsets object created");
      return;
   }  
  entry=data->charsetEntry(qtCharset);
}

KCharset::KCharset( const KCharset& kc){

  if (!data || !charsets){
     fatal("KCharset copy constructor called when no KCharsets object created (???)");
     return;
  }   
  entry=kc.entry;
}

KCharset& KCharset::operator= ( const KCharset& kc){

  entry=kc.entry;
  return *this;
}
 
const char * KCharset::name()const{
  
  if (entry) return entry->name;
  else return "unknown";
}

bool KCharset::isDisplayable(){

  if (!entry) return FALSE;  
  
  return data->isDisplayable((KCharsetEntry *)entry); /* discard const */
}

bool KCharset::isDisplayable(const char *face){

  if (!entry) return FALSE;
  if (!face) return FALSE;
  
  kchdebug("Testing if %s is displayable in %s\n",name(),face);
  if ( stricmp(name(),"any")==0 ){
    kchdebug("Yes - it is any charset\n");
    return TRUE;
  }  

  QFont::CharSet qcharset=entry->qtCharset;
  kchdebug("qtcharset=%i\n",qcharset);
  
  if ( qcharset==QFont::AnyCharSet )
     if (data->charsetOfFace(entry,face)){
       kchdebug("Yes: face %s is of charset: %s\n",face,entry->name);
       return TRUE;
     }  
     else{
       kchdebug("No: face %s is not of charset: %s\n",face,entry->name);
       return FALSE;
     }  
  else{
    QFont f;
    f.setCharSet(qcharset);
    f.setFamily(face);
    QFontInfo fi(f);
    kchdebug("fi.charset()=%i\n",fi.charSet());
    if (fi.charSet()!=qcharset || strcmp(fi.family(),face)!=0 ){
      kchdebug("No: qtCharset is specified, but doesn't work\n");
      return FALSE;
    }  
    else{
      kchdebug("Yes: qtCharset is specified and it works\nn");
      return TRUE;
    }   
  }  
}

bool KCharset::isRegistered()const{

  if (!entry) return FALSE;
  if (entry->registered) return TRUE;
  else return FALSE;
}

QFont::CharSet KCharset::qtCharset()const{

  if (!entry) {
    warning("KCharset: Wrong charset!\n");
    return QFont::AnyCharSet;
  }  
  if (!stricmp(name(),"any")) return QFont::AnyCharSet;
  if (entry) return entry->qtCharset;
  return QFont::AnyCharSet;
}

int KCharset::bits()const{

  if (!entry) {
    warning("KCharset: Wrong charset!\n");
    return 8;
  }  
  if ( stricmp(name(),"unicode") == 0 ) return 16;
  else if ( stricmp(name(),"iso-10640") == 0 ) return 16;
  else if ( stricmp(name(),"us-ascii") ==0 ) return 7;
  else if ( stricmp(name(),"unicode-1-1-utf-8") == 0 ) return 8;
  else if ( stricmp(name(),"unicode-1-1-utf-7") == 0 ) return 7;
  else return 8;
}

QFont &KCharset::setQFont(QFont &fnt){
  if (!entry) {
    warning("KCharset: Wrong charset!\n");
    return fnt;
  }  
  if ( (stricmp(charsets->name(fnt),name()) == 0)
     || data->charsetOfFace(entry,fnt.family())) return fnt;
     
  kchdebug("setQFont: Setting font to: \"%s\"\n",name());
  QString faceStr=data->faceForCharset(entry);

  /* If Qt doesn't support this charset we must use the hack */
  if (qtCharset()==QFont::AnyCharSet && faceStr){
     kchdebug("setQFont: Face for font: \"%s\"\n",(const char *)faceStr);
     faceStr.replace("\\*",fnt.family());
     kchdebug("setQFont: New face for font: \"%s\"\n",(const char *)faceStr);
     fnt.setCharSet(QFont::AnyCharSet);
     fnt.setFamily(faceStr);
     QFontInfo fi(fnt);
     if (fi.family()!=faceStr) // hack doesn't work.
        // Maybe we know a face wich will work
        if (entry->good_family && !(entry->good_family->isEmpty())){
	    kchdebug("trying to find replacement font\n");
	    QFontInfo fi(fnt);
	    QString search;
	    if(!fi.fixedPitch()) search += "-p";
	    search += "-s"; // prefer scalable fonts
	    if(fi.bold()) search += "-s";
	    if(fi.italic()) search += "-i"; 
    
	    while(!search.isEmpty())
	    {
		int pos;
		if((pos = entry->good_family->find(search)) != -1)
		{
		    int start = entry->good_family->findRev("/", pos);
		    QString face = entry->good_family->mid(start+1, pos-start-1);
		    kchdebug("replacement: %s\n", (const char *)face);
		    fnt.setFamily(face);
		    break;
		}	  
		search.truncate(search.length()-2);
	    }
	    if(search.isEmpty())
	    {
		QString face = entry->good_family->left(entry->good_family->find("/")-1);
		kchdebug("replacement: %s\n", (const char *)face);
		fnt.setFamily(face);
	    }
	}
  }
  else{
    kchdebug("setQFont: trying to set charset to %i (family = %s\n", 
	     (int)qtCharset(), fnt.family());
    fnt.setCharSet(qtCharset());
    QFontInfo fi(fnt);
    int ch = fi.charSet();
    kchdebug("setQFont: got charset %i\n",ch);
    if( ch == QFont::AnyCharSet ) ch = QFont::Latin1; // small hack... 
    if (ch != qtCharset() && qtCharset() != QFont::AnyCharSet)
    {
//#define kchdebug printf
      kchdebug("setQFont: didn't get charset: %d <--> %d\n", ch, qtCharset());
      if (entry->good_family && !(entry->good_family->isEmpty())){
	  kchdebug("trying to find replacement font\n");
	  QFontInfo fi(fnt);
	  QString search;
	  if(!fi.fixedPitch()) search += "-p";
	  search += "-s"; // prefer scalable fonts
	  if(fi.bold()) search += "-s";
	  if(fi.italic()) search += "-i"; 
	  search+= "/";

	  while(search.length() > 1)
	  {
	      int pos;
	      if((pos = entry->good_family->find(search)) != -1)
	      {
		  int start = entry->good_family->findRev("/", pos);
		  QString face = entry->good_family->mid(start+1, pos-start-1);
		  kchdebug("replacement: %s\n", (const char *)face);
		  fnt.setFamily(face);
		  break;
	      }	  
	      search.truncate(search.length()-3);
	      search += "/";
	  }
	  if(search.length() == 1)
	  {
	      QString face = entry->good_family->left(entry->good_family->find("/")-1);
	      kchdebug("last replacement: %s\n", (const char *)face);
	      fnt.setFamily(face);
	  }
#undef kchdebug
      }	  
      else if (faceStr){ /* nothing else works - we must use the hack */
         kchdebug("setQFont: Face for font: \"%s\"\n",(const char *)faceStr);
         faceStr.replace("\\*",fnt.family());
         kchdebug("setQFont: New face for font: \"%s\"\n",
		  (const char *)faceStr);
         fnt.setCharSet(QFont::AnyCharSet);
         fnt.setFamily(faceStr);
      }
    }
  }  
  kchdebug("setQFont: New charset: \"%s\"\n",charsets->name(fnt));
  return fnt;
}

KCharset::operator const KCharsetEntry *()const{
 
  return entry;
}

bool KCharset::printable(int chr){

  if (!entry) return FALSE;
  if (entry->toUnicode)
    if (entry->toUnicode[chr]!=0) return TRUE;
    else;
  else if (entry->toUnicodeDict)
    if ((*entry->toUnicodeDict)[chr]!=0) return TRUE;
  return FALSE;
}

QString KCharset::xCharset(){

  if (!entry) return 0;
  QString xch=data->toX(entry->name);
  if ( !xch.isEmpty() ) return xch; 
  if (strnicmp(entry->name,"iso-",4)==0){
     return QString("iso")+QString(entry->name).mid(4,100);
  }
  return entry->name;
}

KCharsetConverter::KCharsetConverter(KCharset inputCharset
				    ,int flags){
				    
  if (!inputCharset.ok()) {
    warning("KCharsetConverter: NULL charset on input!\n");
    inputCharset="us-ascii";    
  }  
  data=new KCharsetConverterData(inputCharset,flags);
}

KCharsetConverter::KCharsetConverter(KCharset inputCharset
				    ,KCharset outputCharset
				    ,int flags){
  if (!inputCharset.ok()) {
    warning("KCharsetConverter: NULL charset on input!\n");
    inputCharset="us-ascii";    
  }  
  if (!outputCharset.ok()) {
    warning("KCharsetConverter: NULL charset on output!\n");
    outputCharset="us-ascii";    
  }  
  data=new KCharsetConverterData(inputCharset,outputCharset,flags);
}

KCharsetConverter::~KCharsetConverter(){
  delete data;
}

bool  KCharsetConverter::ok(){

  return data->ok();
}

const char * KCharsetConverter::outputCharset(){

  return data->outputCharset();
}
   
KCharsetConversionResult::KCharsetConversionResult(
                                        const KCharsetConversionResult& kccr){
  cCharset=kccr.cCharset;
  cText=kccr.cText;
  cText.detach();
}

KCharsetConversionResult& KCharsetConversionResult::operator =(
                           const KCharsetConversionResult& kccr){
  cCharset=kccr.cCharset;
  cText=kccr.cText;
  cText.detach();
  return *this;
}

const KCharsetConversionResult & KCharsetConverter::convert(const char *str){

  data->convert(str,result);
  return result;
}


const QList<KCharsetConversionResult> & KCharsetConverter::multipleConvert(
                                                             const char *str){
static QList<KCharsetConversionResult> resultList;

  resultList.setAutoDelete(TRUE);
  resultList.clear();
  data->convert(str,resultList);
  return resultList;
}

const KCharsetConversionResult & KCharsetConverter::convert(unsigned ch){
  
  return data->convert(ch);
}

const KCharsetConversionResult & KCharsetConverter::convertTag(const char *tag){

  int tmp;
  return data->convertTag(tag,tmp);
}
   
const KCharsetConversionResult & KCharsetConverter::convertTag(const char *tag
							       ,int &l){

  return data->convertTag(tag,l);
}

char * KCharsetConversionResult::copy()const{

  char *ptr=new char [cText.length()+1];
  strcpy(ptr,cText);
  return ptr;
}
   
/////////////////////////////////////////////////////////////////////
KCharsets::KCharsets(){

  if (!data){
     data=new KCharsetsData();
     KCharsetConverterData::kcharsetsData=data;
     KCharset::data=data;
     KCharset::charsets=this;
     count++;
  }   
}

KCharsets::~KCharsets(){
  if(!--count)
    delete data;
}

KCharset KCharsets::defaultCharset()const{

   return defaultCh();
}

KCharset KCharsets::defaultCh()const{

  return data->defaultCharset();
}

bool KCharsets::setDefault(KCharset ch){

  if ( ch.ok() ){
     data->setDefaultCharset(ch.entry);
     return TRUE; 
  }   
  warning("Wrong charset (%s)! Setting to default (us-ascii)", ch.name());
  const KCharsetEntry *ce=data->charsetEntry("us-ascii");
  data->setDefaultCharset(ce);
  return FALSE;  
}

QStrList KCharsets::available()const{

  QStrList w;
  int i;
  for(i=0;data->charsetEntry(i);i++)
    w.append(data->charsetEntry(i)->name);
  return w;  
}

QStrList KCharsets::displayable(const char *face){

  QStrList w;
  int i;
  for(i=0;data->charsetEntry(i);i++)
    if (KCharset(data->charsetEntry(i)).isDisplayable(face))
          w.append(data->charsetEntry(i)->name);
  return w;  
}

QStrList KCharsets::displayable(){

  QStrList w;
  int i;
  for(i=0;data->charsetEntry(i);i++){
    const char *charset=data->charsetEntry(i)->name;
    if (isDisplayable(charset))
          w.append(charset);
  }
	
  return w;  
}

QStrList KCharsets::registered()const{

  QStrList w;
  int i;
  for(i=0;data->charsetEntry(i);i++)
    if (data->charsetEntry(i)->registered)
       w.append(data->charsetEntry(i)->name);
  return w;  
}

bool KCharsets::isAvailable(KCharset charset){

  return charset.isAvailable();
}

bool KCharsets::isDisplayable(KCharset charset){

  return charset.isDisplayable();
}

bool KCharsets::isRegistered(KCharset charset){

  return charset.isRegistered();
}

int KCharsets::bits(KCharset charset){

  return charset.bits();
}

const char * KCharsets::name(QFont::CharSet qtcharset){

  if (qtcharset==QFont::AnyCharSet) return "unknown";
  return KCharset(qtcharset);
}

KCharset KCharsets::charset(QFont::CharSet qtcharset){

  return KCharset(qtcharset);
}

QFont::CharSet KCharsets::qtCharset(){

  return qtCharset(data->defaultCharset());
}

QFont::CharSet KCharsets::qtCharset(KCharset set){

  return set.qtCharset();
}

QFont &KCharsets::setQFont(QFont &fnt,KCharset charset){

  return charset.setQFont(fnt);
}


QFont &KCharsets::setQFont(QFont &fnt){

  return KCharset(data->defaultCharset()).setQFont(fnt);
}

KCharset KCharsets::charset(const QFont& font){

  kchdebug("Testing charset of font: %s, qtcharset=%i\n",font.family(),(int)font.charSet());
  if (font.charSet()!=QFont::AnyCharSet) return charset(font.charSet());
  const KCharsetEntry * ce=data->charsetOfFace(font.family());
  kchdebug("ce=%p ce->name=%s\n",ce,ce?ce->name:0);
  return KCharset(ce);
}

const char * KCharsets::name(const QFont& font){
  
  return charset(font); 
}

KCharset KCharsetConversionResult::charset()const{

  if (cCharset == 0) return "";
  return cCharset;
}

QFont & KCharsetConversionResult::setQFont(QFont &font)const{

  if (!cCharset) return font;
  return KApplication::getKApplication()
         ->getCharsets()->setQFont(font,cCharset->name);
}


const KCharsetConversionResult & KCharsets::convert(unsigned ch){
  
  return data->convert(ch);
}

const KCharsetConversionResult & KCharsets::convertTag(const char *tag){

  int tmp;
  return data->convertTag(tag,tmp);
}
 
const KCharsetConversionResult & KCharsets::convertTag(const char *tag
							,int &l){
  return data->convertTag(tag,l);
}
 
KCharset KCharsets::charsetFromX(const QString &xName){
  
  QString name=data->fromX(xName);
  KCharset kch;
  if (!name.isEmpty()) kch=KCharset(name);
  return kch;
}


--- NEW FILE: kconfigbase.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: kconfigbase.cpp,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
[...1110 lines suppressed...]
  //  if (!data()->pAppStream->device()->open( IO_ReadWrite ))
  //    data()->pAppStream->device()->open( IO_ReadOnly );

  parseConfigFiles();
}


void KConfigBase::setDollarExpansion( bool bExpand )
{
	data()->bExpand = bExpand;
}


bool KConfigBase::isDollarExpansion() const
{
	return data()->bExpand;
}

#include "kconfigbase.moc"


--- NEW FILE: kmisc.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Stephan Kulow (coolo at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#warning this header is deprecated! Use the prototypes you need in your config.h.bot

--- NEW FILE: kprocess.cpp ---
/*

   $Id: kprocess.cpp,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $

   This file is part of the KDE libraries
   Copyright (C) 1997 Christian Czezatke (e9025461 at student.tuwien.ac.at)

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   $Log: kprocess.cpp,v $
   Revision 1.1  2006-10-03 11:26:27  dslinux_amadeus
   adding pristine copy of pixil to HEAD so I can branch from it

   Revision 1.1  2003/09/08 19:42:05  jasonk
   Addition of packages directory and associated files.

   Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
   Initial import of PIXIL into new cvs repository.

   Revision 1.1.1.1  2003/06/23 22:04:23  jasonk


   Revision 1.1.1.1  2000/07/07 16:10:59  jasonk
   Initial import of ViewML

   Revision 1.29.4.6  1999/08/18 15:23:49  waba
   WABA: Fix for communication with child processes

   Revision 1.29.4.5  1999/07/22 21:14:17  porten
   applied Waba's fix for the fix from HEAD

   Revision 1.29.4.4  1999/07/12 10:26:42  porten
   kprocess deadlock fix from Alex Hayward (bug #1002 and #1513)

   Revision 1.29.4.3  1999/07/04 17:48:09  porten
   check for Stdin flag in writeStdin

   Revision 1.29.4.2  1999/05/10 19:33:18  gehrmab
   Fixed memory leak in KProcess

   Revision 1.29.4.1  1999/04/07 15:39:11  porten
   restore SIGPIPE handler

   Revision 1.29  1999/01/18 10:56:22  kulow
   .moc files are back in kdelibs. Built fine here using automake 1.3

   Revision 1.28  1999/01/15 09:30:40  kulow
   it's official - kdelibs builds with srcdir != builddir. For this I
   automocifized it, the generated rules are easier to maintain than
   selfwritten rules. I have to fight with some bugs of this tool, but
   generally it's better than keeping them updated by hand.

   Revision 1.27  1998/10/28 19:00:15  ettrich
   small fix (thanks to Christian Stoeckl)

   Revision 1.26  1998/10/19 08:09:05  ettrich
   small pseudo fix to kshellprocess reverted

   Revision 1.25  1998/09/22 18:03:13  ettrich
   Matthias: small updates to kaccel

   Revision 1.24  1998/09/17 19:22:09  radej
   sven: made it work with egcs-1.1

   Revision 1.23  1998/09/01 20:21:29  kulow
   I renamed all old qt header files to the new versions. I think, this looks
   nicer (and gives the change in configure a sense :)

   Revision 1.22  1998/07/29 10:14:28  kulow
   porting to a virtual plattform called "tajsandmineansiplatform" :)

   Revision 1.21  1998/07/29 09:07:50  ssk
   Fixed a whole lot of -Wall -ansi -pedantic warnings.

   Revision 1.20  1998/03/10 18:59:22  mario
   Mario: fixed a memory leak in KShellProcess (shell not freed)

   Revision 1.19  1998/03/08 17:21:40  wuebben
   Bernd: Fixed the segfault problem in 'KShellProcess::start()'.


*/


//
//  KPROCESS -- A class for handling child processes in KDE without
//  having to take care of Un*x specific implementation details
//
//  version 0.3.1, Jan 8th 1998
//
//  (C) Christian Czezatke
//  e9025461 at student.tuwien.ac.at
//
// Changes:
//
// March 2nd, 1998: Changed parameter list for KShellProcess:
//   Arguments are now placed in a single string so that
//   <shell> -c <commandstring> is passed to the shell
//   to make the use of "operator<<" consistent with KProcess

#include "kprocess.h"
#define _MAY_INCLUDE_KPROCESSCONTROLLER_
#include "kprocctrl.h"

#include <qapplication.h>

// to define kstrdup
#include <config.h>

#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>

/////////////////////////////
// public member functions //
/////////////////////////////


KProcess::KProcess()
{
  if (0 == theKProcessController) {
	theKProcessController= new KProcessController();
	CHECK_PTR(theKProcessController);
  }

  run_mode = NotifyOnExit;
  runs = FALSE;
  pid = 0;
  status = 0;
  innot = outnot = errnot = 0;
  communication = NoCommunication;
  input_data = 0;
  input_sent = 0;
  input_total = 0;

  theKProcessController->processList->append(this);
}



KProcess::~KProcess()
{
  // destroying the KProcess instance sends a SIGKILL to the
  // child process (if it is running) after removing it from the
  // list of valid processes (if the process is not started as
  // "DontCare")

  theKProcessController->processList->remove(this);
  // this must happen before we kill the child
  // TODO: block the signal while removing the current process from the process list

  if (runs && (run_mode != DontCare))
    kill(SIGKILL);

  // TODO: restore SIGCHLD and SIGPIPE handler if this is the last KProcess
}



bool KProcess::setExecutable(const char *proc)
{
  if (runs) return FALSE;

  arguments.removeFirst();
  if (0 != proc) {
    arguments.insert(0,proc);
  }

  return TRUE;
}






KProcess &KProcess::operator<<(const char *arg)
{
  CHECK_PTR(arg);
  arguments.append(arg);
  return *this;
}



void KProcess::clearArguments()
{
  if (0 != arguments.first()) {
    while (arguments.remove())
      ;
  }
}



bool KProcess::start(RunMode runmode, Communication comm)
{
  uint i;
  uint n = arguments.count();
  char **arglist;

  if (runs || (0 == n)) {
	return FALSE;  // cannot start a process that is already running
	// or if no executable has been assigned
  }
  run_mode = runmode;
  status = 0;

  arglist = (char **)malloc( (n+1)*sizeof(char *));
  CHECK_PTR(arglist);
  for (i=0; i < n; i++)
    arglist[i] = arguments.at(i);
  arglist[n]= 0;

  if (!setupCommunication(comm))
    debug("Could not setup Communication!");

  runs = TRUE;
  pid = fork();

  if (0 == pid) {
	// The child process
	if(!commSetupDoneC())
	  debug("Could not finish comm setup in child!");

	// Matthias
	if (run_mode == DontCare)
          setpgid(0,0);

        // restore default SIGPIPE handler (Harri)
        struct sigaction act;
        sigemptyset(&(act.sa_mask));
        sigaddset(&(act.sa_mask), SIGPIPE);
        act.sa_handler = SIG_DFL;
        act.sa_flags = 0;
        sigaction(SIGPIPE, &act, 0L);

	execvp(arglist[0], arglist);
	exit(-1);

  } else if (-1 == pid) {
	// forking failed

	runs = FALSE;
	free(arglist);
	return FALSE;

  } else {
	// the parent continues here
	if (!commSetupDoneP())  // finish communication socket setup for the parent
	  debug("Could not finish comm setup in parent!");

	// Discard any data for stdin that might still be there
	input_data = 0;

	if (run_mode == Block) {
	  commClose();

	  // Its possible that the child's exit was caught by the SIGCHLD handler
	  // which will have set status for us.
	  if (waitpid(pid, &status, 0) != -1) this->status = status;

	  runs = FALSE;
	  emit processExited(this);
	}
  }
  free(arglist);
  return TRUE;
}



bool KProcess::kill(int signo)
{
  bool rv=FALSE;

  if (0 != pid)
    rv= (-1 != ::kill(pid, signo));
  // probably store errno somewhere...
  return rv;
}



bool KProcess::isRunning()
{
  return runs;
}



pid_t KProcess::getPid()
{
  return pid;
}



bool KProcess::normalExit()
{
  int _status = status;
  return (pid != 0) && (!runs) && (WIFEXITED((_status)));
}



int KProcess::exitStatus()
{
  int _status = status;
  return WEXITSTATUS((_status));
}



bool KProcess::writeStdin(char *buffer, int buflen)
{
  bool rv;

  // if there is still data pending, writing new data
  // to stdout is not allowed (since it could also confuse
  // kprocess...
  if (0 != input_data)
    return FALSE;

  if (runs && (communication & Stdin)) {
    input_data = buffer;
    input_sent = 0;
    input_total = buflen;
    slotSendData(0);
    innot->setEnabled(TRUE);
    rv = TRUE;
  } else
    rv = FALSE;
  return rv;
}



bool KProcess::closeStdin()
{
  bool rv;

  if (communication & Stdin) {
    communication = (Communication) (communication & ~Stdin);
    innot->setEnabled(FALSE);
    close(in[1]);
    rv = TRUE;
  } else
    rv = FALSE;
  return rv;
}


/////////////////////////////
// protected slots         //
/////////////////////////////



void KProcess::slotChildOutput(int fdno)
{
  if (!childOutput(fdno)) {
	outnot->setEnabled(FALSE);	
  }
}



void KProcess::slotChildError(int fdno)
{
  if (!childError(fdno)) {
    errnot->setEnabled(FALSE);
  }
}



void KProcess::slotSendData(int)
{
  if (input_sent == input_total) {
    innot->setEnabled(FALSE);
    input_data = 0;
    emit wroteStdin(this);
  } else
    input_sent += ::write(in[1], input_data+input_sent, input_total-input_sent);
}



//////////////////////////////
// private member functions //
//////////////////////////////



void KProcess::processHasExited(int state)
{
  runs = FALSE;
  status = state;

  commClose(); // cleanup communication sockets

  // also emit a signal if the process was run Blocking
  if (DontCare != run_mode)
    emit processExited(this);
}



int KProcess::childOutput(int fdno)
{
  char buffer[1024];
  int len;

  len = ::read(fdno, buffer, 1024);

  if ( 0 < len) {
	emit receivedStdout(this, buffer, len);
  }
  return len;
}



int KProcess::childError(int fdno)
{
  char buffer[1024];
  int len;

  len = ::read(fdno, buffer, 1024);

  if ( 0 < len)
	emit receivedStderr(this, buffer, len);
  return len;
}



int KProcess::setupCommunication(Communication comm)
{
  int ok;

  communication = comm;

  ok = 1;
  if (comm & Stdin)
	ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, in) >= 0;

  if (comm & Stdout)
	ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, out) >= 0;

  if (comm & Stderr)
	ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, err) >= 0;

  return ok;
}



int KProcess::commSetupDoneP()
{
  int ok = 1;

  if (communication != NoCommunication) {
	if (communication & Stdin)
	  close(in[0]);
	if (communication & Stdout)
	  close(out[1]);
	if (communication & Stderr)
	  close(err[1]);

	// Don't create socket notifiers and set the sockets non-blocking if
	// blocking is requested.
	if (run_mode == Block) return ok;

	if (communication & Stdin) {
	  ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK));
	  innot =  new QSocketNotifier(in[1], QSocketNotifier::Write, this);
	  CHECK_PTR(innot);
	  innot->setEnabled(FALSE); // will be enabled when data has to be sent
	  QObject::connect(innot, SIGNAL(activated(int)),
					   this, SLOT(slotSendData(int)));
	}

	if (communication & Stdout) {
	  ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK));
	  outnot = new QSocketNotifier(out[0], QSocketNotifier::Read, this);
	  CHECK_PTR(outnot);
	  QObject::connect(outnot, SIGNAL(activated(int)),
					   this, SLOT(slotChildOutput(int)));
	}

	if (communication & Stderr) {
	  ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK));
	  errnot = new QSocketNotifier(err[0], QSocketNotifier::Read, this );
	  CHECK_PTR(errnot);
	  QObject::connect(errnot, SIGNAL(activated(int)),
					   this, SLOT(slotChildError(int)));
	}
  }
  return ok;
}



int KProcess::commSetupDoneC()
{
  int ok = 1;
  struct linger so;

  if (communication != NoCommunication) {
	if (communication & Stdin)
	  close(in[1]);
	if (communication & Stdout)
	  close(out[0]);
	if (communication & Stderr)
	  close(err[0]);

	if (communication & Stdin)
	  ok &= dup2(in[0],  STDIN_FILENO) != -1;
	if (communication & Stdout) {
	  ok &= dup2(out[1], STDOUT_FILENO) != -1;
	  ok &= !setsockopt(out[1], SOL_SOCKET, SO_LINGER, (char*)&so, sizeof(so));
	}
	if (communication & Stderr) {
	  ok &= dup2(err[1], STDERR_FILENO) != -1;
	  ok &= !setsockopt(err[1], SOL_SOCKET, SO_LINGER, (char*)&so, sizeof(so));
	}
  }
  return ok;
}



void KProcess::commClose()
{
  if (NoCommunication != communication) {
        bool b_in = (communication & Stdin);
        bool b_out = (communication & Stdout);
        bool b_err = (communication & Stderr);
	if (b_in)
		delete innot;

	if (b_out || b_err) {
	  // If both channels are being read we need to make sure that one socket buffer
	  // doesn't fill up whilst we are waiting for data on the other (causing a deadlock).
	  // Hence we need to use select.

	  // Once one or other of the channels has reached EOF (or given an error) go back
	  // to the usual mechanism.

	  int fds_ready = 1;
	  fd_set rfds;

          int max_fd = 0;
          if (b_out) {
            if (out[0] > max_fd)
              max_fd = out[0];
            delete outnot;
          }
          if (b_err) {
            if (err[0] > max_fd)
              max_fd = err[0];
            delete errnot;
          }
           

	  while (b_out || b_err) {
	    FD_ZERO(&rfds);
            if (b_out) 
	      FD_SET(out[0], &rfds);

            if (b_err) 
	      FD_SET(err[0], &rfds);

	    fds_ready = select(max_fd+1, &rfds, 0, 0, 0);
	    if (fds_ready <= 0) break;

	    if (b_out && FD_ISSET(out[0], &rfds)) {
	      int ret = childOutput(out[0]);
	      if ((ret == -1 && errno != EAGAIN) || ret == 0) 
		b_out = false;
	    }
                               
	    if (b_err && FD_ISSET(err[0], &rfds)) {
	      int ret = childError(err[0]);
	      if ((ret == -1 && errno != EAGAIN) || ret == 0) 
		b_err = false;
	    }
	  }
	}

	if (communication & Stdin)
	    close(in[1]);
	if (communication & Stdout)
	    close(out[0]);
	if (communication & Stderr)
	    close(err[0]);
	
	communication = NoCommunication;
  }
}




///////////////////////////
// CC: Class KShellProcess
///////////////////////////

KShellProcess::KShellProcess(const char *shellname):
  KProcess()
{
  if (0 != shellname)
    shell = kstrdup(shellname);
  else
    shell = 0;
}


KShellProcess::~KShellProcess() {
  if(shell)
    free(shell);
}

bool KShellProcess::start(RunMode runmode, Communication comm)
{
  uint i;
  uint n = arguments.count();
  char *arglist[4];
  QString cmd;

  if (runs || (0 == n)) {
	return FALSE;  // cannot start a process that is already running
	// or if no executable has been assigned
  }

  run_mode = runmode;
  status = 0;

  if (0 == shell)
    shell = searchShell();
  if (0 == shell) {
    debug("Could not find a valid shell\n");
    return FALSE;
  }

  // CC: Changed the way the parameter was built up
  // CC: Arglist for KShellProcess is now always:
  // CC: <shell> -c <command>

  arglist[0] = shell;
  arglist[1] = "-c";

  for (i=0; i < n; i++) {
    cmd += arguments.at(i);
    cmd += " "; // CC: to separate the arguments
  }

//   // execution in background
//   cmd.stripWhiteSpace();
//   if (cmd[cmd.length()-1] != '&')
//       cmd += '&';
  arglist[2] = cmd.data();
  arglist[3] = 0;

  if (!setupCommunication(comm))
    debug("Could not setup Communication!");

  runs = TRUE;
  pid = fork();

  if (0 == pid) {
	// The child process

	if(!commSetupDoneC())
	  debug("Could not finish comm setup in child!");

	// Matthias
	if (run_mode == DontCare)
          setpgid(0,0);

        // restore default SIGPIPE handler (Harri)
        struct sigaction act;
        sigemptyset(&(act.sa_mask));
        sigaddset(&(act.sa_mask), SIGPIPE);
        act.sa_handler = SIG_DFL;
        act.sa_flags = 0;
        sigaction(SIGPIPE, &act, 0L);

	execvp(arglist[0], arglist);
	exit(-1);

  } else if (-1 == pid) {
	// forking failed

	runs = FALSE;
	return FALSE;

  } else {
	// the parent continues here

	if (!commSetupDoneP())  // finish communication socket setup for the parent
	  debug("Could not finish comm setup in parent!");

	// Discard any data for stdin that might still be there
	input_data = 0;

	if (run_mode == Block) {
	  commClose();

	  // Its possible that the child's exit was caught by the SIGCHLD handler
	  // which will have set status for us.
	  if (waitpid(pid, &status, 0) != -1) this->status = status;

	  runs = FALSE;
	  emit processExited(this);
	}
  }
  return TRUE;
}



char *KShellProcess::searchShell()
{
  char *hlp = 0;
  char *copy = 0;


  // CC: now get the name of the shell we have to use
  hlp = getenv("SHELL");
  if (isExecutable(hlp)) {
    copy = kstrdup(hlp);
    CHECK_PTR(copy);
  }

  if (0 == copy) {
    // CC: hmm, invalid $SHELL in environment -- maybe there are whitespaces to be stripped?
    QString stmp = QString(shell);
    QString shell_stripped = stmp.stripWhiteSpace();
    if (isExecutable(shell_stripped.data())) {
      copy = kstrdup(shell_stripped.data());
      CHECK_PTR(copy);
    }
  }
  return copy;
}




bool KShellProcess::isExecutable(const char *fname)
{
  struct stat fileinfo;

  if ((0 == fname) || (strlen(fname) == 0)) return FALSE;
  // CC: filename is invalid

  // CC: we've got a valid filename, now let's see whether we can execute that file

  if (-1 == stat(fname, &fileinfo)) return FALSE;
  // CC: return false if the file does not exist

  // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets
  if ( (S_ISDIR(fileinfo.st_mode))  ||
       (S_ISCHR(fileinfo.st_mode))  ||
       (S_ISBLK(fileinfo.st_mode))  ||
#ifdef S_ISSOCK
       // CC: SYSVR4 systems don't have that macro
       (S_ISSOCK(fileinfo.st_mode)) ||
#endif
       (S_ISFIFO(fileinfo.st_mode)) ||
       (S_ISDIR(fileinfo.st_mode)) ) {
    return FALSE;
  }

  // CC: now check for permission to execute the file
  if (access(fname, X_OK) != 0) return FALSE;

  // CC: we've passed all the tests...
  return TRUE;
}
#include "kprocess.moc"


--- NEW FILE: krect.h ---
// KRect - (c) by Reginald Stadlbauer 1998 <reggie at kde.org>
// Version: $Id: krect.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $

#ifndef krect_h
#define krect_h

#include "kpoint.h"
#include "ksize.h"

class QRect;

/**
 * Class for reperesenting a rect by its X,Y, WIDTH and HEIGHT. It's source compatible
 * to the Qt class QRect, but KRect uses 32 bit integers for the x/y/width/height.
 * @short Class for representing a rect by (x,y,width,height)
 * @author Reginald Stadlbauer <reggie at kde.org>
 * @version $Id: krect.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
 */

class KRect
{
public:
  KRect();
  KRect(const KPoint &_topleft,const KPoint &_bottomright);
  KRect(const KPoint &_topleft,const KSize &_size);
  KRect(int _left,int _top,int _width,int _height);
  KRect(const QRect &_rect);
  
  bool isNull() const;
  bool isEmpty() const;
  bool isValid() const;
  KRect normalize() const;
  
  int left() const;
  int top() const;
  int right() const;
  int bottom() const;
  int x() const;
  int y() const;
  void setLeft(int _pos);
  void setTop(int _pos);
  void setRight(int _pos);
  void setBottom(int _pos);
  void setX(int _x);
  void setY(int _y);
  
  KPoint topLeft() const;
  KPoint bottomRight() const;
  KPoint topRight() const;
  KPoint bottomLeft() const;
  KPoint center() const;
  
  void rect(int *_x,int *_y,int *_w,int *_h) const;
  void coords(int *_x1,int *_y1,int *_x2,int *_y2) const;
  
  void moveTopLeft(const KPoint &_pnt);
  void moveBottomRight(const KPoint &_pnt);
  void moveTopRight(const KPoint &_pnt);
  void moveBottomLeft(const KPoint &_pnt);
  void moveCenter(const KPoint &_pnt);
  void moveBy(int _dx,int _dy);
  
  void setRect(int _x,int _y,int _w,int _h);
  void setCoords(int _x1,int _y1,int _x2,int _y2);
  
  KSize size() const;
  int width() const;
  int height() const;
  void setWidth(int _w);
  void setHeight(int _h);
  void setSize(const KSize &_size);
  
  bool contains(const KPoint &_pnt,bool _strict = false) const;
  bool contains(const KRect &_rect,bool _strict = false) const;
  KRect unite( const KRect &_rect) const;
  KRect intersect(const KRect &_rect) const;
  bool intersects(const KRect &_rect) const;

  operator QRect() const;
  
  friend bool operator==(const KRect &_rect1,const KRect &_rect2);
  friend bool operator!=(const KRect &_rect1,const KRect &_rect2);
  friend bool operator==(const QRect &_rect1,const KRect &_rect2);
  friend bool operator!=(const QRect &_rect1,const KRect &_rect2);
  friend bool operator==(const KRect &_rect1,const QRect &_rect2);
  friend bool operator!=(const KRect &_rect1,const QRect &_rect2);

protected:
  int x1,x2,y1,y2;

};

#endif

--- NEW FILE: kapp.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
	*/

[...1760 lines suppressed...]
    KWM::setMiniIcon(topWidget->winId(), getMiniIcon());
    // set a short icon text
    XSetIconName( qt_xdisplay(), topWidget->winId(), getCaption() );
    if (bSessionManagement)
      enableSessionManagement(bSessionManagementUserDefined);

    if (!bSessionManagement)
	KWM::setWmCommand( topWidget->winId(), aWmCommand);
  }
}

void KApplication::registerTopWidget()
{
}

void KApplication::unregisterTopWidget()
{
}

#include "kapp.moc"

--- NEW FILE: kdebugareas.txt ---
Area codes for KDebug system
============================

1-100 kdesupport

101-1000 kdelibs

	101-199 kdecore
		101-110 KApplication
		111-120	KConfig
		125	KAccel
		151-200 widgets
		151-160 KTopLevelWidget
	201-300 khtmlw
	301-400 jscript
	401-500 libmediatool
	501-600 libkfm
	601-700 libkwm
	701-800	kspell

1000-30000 applications
	1001-1100 kwm
	1101-1200 kpanel
	1201-1300 kfm
	1301-1400 kcalc
	1401-1500 kedit
	1501-1600 khexdit
	1601-1700 kdisplay
	1701-1800 kscreensavers
	1801-1900 kdehelp
	1901-2000 kfind
	2001-2100 kdm
	2101-2200 kfontmanager
	2201-2300 klogout
	2301-2400 kvt
	2401-2500 kacli
	2501-2600 karm
	2601-2700 kfax
	2701-2800 kghostview
	2801-2900 kjots
	2901-3000 knotes
	3001-3100 kpaint
	3101-3200 kpat
	3201-3300 kreversi
	3301-3400 krn
	3401-3500 kmail
	3501-3600 kscd
	3601-3700 ktetris
	3701-3800 kview
	3801-3900 ksamba
	3901-4000 ktalk
	4001-4100 kirc
	4101-4200 kciv
	4201-4250 krot
	4251-4260 khidaq

30001-65534 koffice
	30001-31000 kxcl
	31001-32000 kword
	32001-33000 kpresenter
	33001-34000 klyx
	34001-35000 kchart

--- NEW FILE: krect.cpp ---
// KRect - (c) by Reginald Stadlbauer 1998 <reggie at kde.org>
// Version: 0.0.1

#include <qrect.h>

#include "krect.h"

//==========================================================
KRect::KRect()
{
  x1 = 0; y1 = 0;
  x2 = -1; y2 = -1;
}

//==========================================================
KRect::KRect(const KPoint &_topleft,const KPoint &_bottomright)
{
  x1 = _topleft.x();
  y1 = _topleft.y();
  x2 = _bottomright.x();
  y2 = _bottomright.y();
}

//==========================================================
KRect::KRect(const KPoint &_topleft,const KSize &_size)
{
  x1 = _topleft.x();
  y1 = _topleft.y();
  x2 = x1 + _size.width() - 1;
  y2 = y1 + _size.height() - 1;
}

//==========================================================
KRect::KRect(int _left,int _top,int _width,int _height)
{
  x1 = _left;
  y1 = _top;
  x2 = x1 + _width - 1;
  y2 = y1 + _height - 1;
}

//==========================================================
KRect::KRect(const QRect &_rect)
{
  x1 = _rect.left();
  y1 = _rect.top();
  x2 = _rect.right();
  y2 = _rect.bottom();
}

//==========================================================
bool KRect::isNull() const
{
  return (x1 == x2 - 1 && y1 == y2 - 1);
}

//==========================================================
bool KRect::isEmpty() const
{
  return (x1 > x2 || y1 > y2);
}

//==========================================================
bool KRect::isValid() const
{
  return !isEmpty();
}

//==========================================================
KRect KRect::normalize() const
{
  int xx1,xx2,yy1,yy2;
  if (x1 <= x2) 
    {
      xx1 = x1;
      xx2 = x2;
    } 
  else 
    {
      xx1 = x2;
      xx2 = x1;
    }
  if (y1 <= y2) 
    {
      yy1 = y1;
      yy2 = y2;
    } 
  else 
    {
      yy1 = y2;
      yy2 = y1;
    }

  return KRect(KPoint(xx1,yy1),KPoint(xx2,yy2));
}

//==========================================================
int KRect::left() const
{
  return x1;
}

//==========================================================
int KRect::top() const
{
  return y1;
}

//==========================================================
int KRect::right() const
{
  return x2;
}

//==========================================================
int KRect::bottom() const
{
  return y2;
}

//==========================================================
int KRect::x() const
{
  return x1;
}

//==========================================================
int KRect::y() const
{
  return y1;
}

//==========================================================
void KRect::setLeft(int _pos)
{
  x1 = _pos;
}

//==========================================================
void KRect::setTop(int _pos)
{
  y1 = _pos;
}

//==========================================================
void KRect::setRight(int _pos)
{
  x2 = _pos;
}

//==========================================================
void KRect::setBottom(int _pos)
{
  y2 = _pos;
}

//==========================================================
void KRect::setX(int _x)
{
  x1 = _x;
}

//==========================================================
void KRect::setY(int _y)
{
  y1 = _y;
}

//==========================================================
KPoint KRect::topLeft() const
{
  return KPoint(x1,y1);
}

//==========================================================
KPoint KRect::bottomRight() const
{
  return KPoint(x2,y2);
}

//==========================================================
KPoint KRect::topRight() const
{
  return KPoint(x2,y1);
}

//==========================================================
KPoint KRect::bottomLeft() const
{
  return KPoint(x1,y2);
}

//==========================================================
KPoint KRect::center() const
{
  return KPoint((x1 + x2) / 2,(y1 + y2) / 2);
}

//==========================================================
void KRect::rect(int *_x,int *_y,int *_w,int *_h) const
{
  *_x = x1;
  *_y = y1;
  *_w = x2 - x1 + 1;
  *_h = y2 - y1 + 1;
}

//==========================================================
void KRect::coords(int *_x1,int *_y1,int *_x2,int *_y2) const
{
  *_x1 = x1;
  *_y1 = y1;
  *_x2 = x2;
  *_y2 = y2;
}

//==========================================================
void KRect::moveTopLeft(const KPoint &_pnt)
{
  x2 += _pnt.x() - x1;
  y2 += _pnt.y() - y1;
  x1 = _pnt.x();
  y1 = _pnt.y();
}

//==========================================================
void KRect::moveBottomRight(const KPoint &_pnt)
{
  x1 += _pnt.x() - x2;
  y1 += _pnt.y() - y2;
  x2 = _pnt.x();
  y2 = _pnt.y();
}

//==========================================================
void KRect::moveTopRight(const KPoint &_pnt)
{
  x1 += _pnt.x() - x2;
  y2 += _pnt.y() - y1;
  x2 = _pnt.x();
  y1 = _pnt.y();
}

//==========================================================
void KRect::moveBottomLeft(const KPoint &_pnt)
{
  x2 += _pnt.x() - x1;
  y1 += _pnt.y() - y2;
  x1 = _pnt.x();
  y2 = _pnt.y();
}

//==========================================================
void KRect::moveCenter(const KPoint &_pnt)
{
  int _dx = _pnt.x() - (x2 + x1) / 2;
  int _dy = _pnt.y() - (y2 + y1) / 2;
  x1 += _dx;
  y1 += _dy;
  x2 += _dx;
  y2 += _dy;
}

//==========================================================
void KRect::moveBy(int _dx,int _dy)
{
  x1 += _dx;
  y1 += _dy;
  x2 += _dx;
  y2 += _dy;
}

//==========================================================
void KRect::setRect(int _x,int _y,int _w,int _h)
{
  x1 = _x;
  y1 = _y;
  x2 = _x + _w - 1;
  y2 = _y + _h - 1;
}

//==========================================================
void KRect::setCoords(int _x1,int _y1,int _x2,int _y2)
{
  x1 = _x1;
  y1 = _y1;
  x2 = _x2;
  y2 = _y2;
}

//==========================================================
KSize KRect::size() const
{
  return KSize(x2 - x1 + 1, y2 - y1 + 1);
}

//==========================================================
int KRect::width() const
{
  return x2 - x1 + 1;
}

//==========================================================
int KRect::height() const
{
  return y2 - y1 + 1;
}

//==========================================================
void KRect::setWidth(int _w)
{
  x2 = x1 + _w - 1;
}

//==========================================================
void KRect::setHeight(int _h)
{
  y2 = y1 + _h - 1;
}

//==========================================================
void KRect::setSize(const KSize &_size)
{
  x2 = x1 + _size.width() - 1;
  y2 = y1 + _size.height() - 1;
}

//==========================================================
bool KRect::contains(const KPoint &_pnt,bool _strict ) const
{
  if (_strict)
    return (x1 < _pnt.x()) && (y1 < _pnt.y()) && (x2 > _pnt.x()) && (y2 > _pnt.y());
  else
    return (x1 <= _pnt.x()) && (y1 <= _pnt.y()) && (x2 >= _pnt.x()) && (y2 >= _pnt.y());
}

//==========================================================
bool KRect::contains(const KRect &_rect,bool _strict ) const
{
  return (contains(KPoint(_rect.left(),_rect.top()),_strict) && contains(KPoint(_rect.right(),_rect.bottom()),_strict));
}

//==========================================================
KRect KRect::unite( const KRect &_rect) const
{
  if (_rect.isEmpty())
    return *this;
  else
    return KRect(KPoint(x1 < _rect.x1 ? x1 : _rect.x1, y1 < _rect.y1 ? y1 : _rect.y1),
		 KPoint(x2 > _rect.x2 ? x2 : _rect.x2, y2 > _rect.y2 ? y2 : _rect.y2));
}

//==========================================================
KRect KRect::intersect(const KRect &_rect) const
{
  if(isEmpty())
    return *this;
  else
    return KRect(KPoint(x1 > _rect.x1 ? x1 : _rect.x1, y1 > _rect.y1 ? y1 : _rect.y1),
		 QPoint(x2 < _rect.x2 ? x2 : _rect.x2, y2 < _rect.y2 ? y2 : _rect.y2));
}

//==========================================================
bool KRect::intersects(const KRect &_rect) const
{
  if(isEmpty())
    return false;
  else
    return (x2 >= _rect.x1 && x1 <= _rect.x2 && y2 >= _rect.y1 && y1 <= _rect.y2);
}

//==========================================================
KRect::operator QRect() const
{
  return QRect(x(),y(),width(),height());
}

//==========================================================
bool operator==(const KRect &_rect1,const KRect &_rect2)
{
  return (_rect1.left() == _rect2.left() && _rect1.top() == _rect2.top() && 
	  _rect1.right() == _rect2.right() && _rect1.bottom() == _rect2.bottom());
}

//==========================================================
bool operator!=(const KRect &_rect1,const KRect &_rect2)
{
  return (_rect1.left() != _rect2.left() || _rect1.top() != _rect2.top() || 
	  _rect1.right() != _rect2.right() || _rect1.bottom() != _rect2.bottom());
}

//==========================================================
bool operator==(const QRect &_rect1,const KRect &_rect2)
{
  return (_rect1.left() == _rect2.left() && _rect1.top() == _rect2.top() && 
	  _rect1.right() == _rect2.right() && _rect1.bottom() == _rect2.bottom());
}

//==========================================================
bool operator!=(const QRect &_rect1,const KRect &_rect2)
{
  return (_rect1.left() != _rect2.left() || _rect1.top() != _rect2.top() || 
	  _rect1.right() != _rect2.right() || _rect1.bottom() != _rect2.bottom());
}

//==========================================================
bool operator==(const KRect &_rect1,const QRect &_rect2)
{
  return (_rect1.left() == _rect2.left() && _rect1.top() == _rect2.top() && 
	  _rect1.right() == _rect2.right() && _rect1.bottom() == _rect2.bottom());
}

//==========================================================
bool operator!=(const KRect &_rect1,const QRect &_rect2)
{
  return (_rect1.left() != _rect2.left() || _rect1.top() != _rect2.top() || 
	  _rect1.right() != _rect2.right() || _rect1.bottom() != _rect2.bottom());
}


--- NEW FILE: drag.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Torben Weis (weis at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
/*
 * $Id: drag.cpp,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
 * 
 * $Log: drag.cpp,v $
 * Revision 1.1  2006-10-03 11:26:26  dslinux_amadeus
 * adding pristine copy of pixil to HEAD so I can branch from it
 *
 * Revision 1.1  2003/09/08 19:42:03  jasonk
 * Addition of packages directory and associated files.
 *
 * Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
 * Initial import of PIXIL into new cvs repository.
 *
 * Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
 *
 *
 * Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
 * Initial import of ViewML
 *
 * Revision 1.24  1999/01/18 10:56:11  kulow
 * .moc files are back in kdelibs. Built fine here using automake 1.3
 *
 * Revision 1.23  1999/01/15 09:30:29  kulow
 * it's official - kdelibs builds with srcdir != builddir. For this I
 * automocifized it, the generated rules are easier to maintain than
 * selfwritten rules. I have to fight with some bugs of this tool, but
 * generally it's better than keeping them updated by hand.
 *
 * Revision 1.22  1998/08/22 20:02:32  kulow
 * make kdecore have nicer output, when compiled with -Weffc++ :)
 *
 * Revision 1.21  1998/06/19 18:18:04  kalle
 * Cleaned up debugging messages
 *
 * This was my last change before KDE 1.0.
 *
 * Revision 1.20  1998/06/16 06:03:12  kalle
 * Implemented copy constructors and assignment operators or disabled them
 *
 * Revision 1.19  1998/03/09 20:21:52  kulow
 * just remove the dragZone from the dragZoneList, if kapp is still exist.
 * If this happens in the end of the application, big problems accour (the
 * reason, for many segfaults of applications at exit)
 *
 * Revision 1.18  1998/01/18 14:38:28  kulow
 * reverted the changes, Jacek commited.
 * Only the RCS comments were affected, but to keep them consistent, I
 * thought, it's better to revert them.
 * I checked twice, that only comments are affected ;)
 *
 * Revision 1.16  1997/11/04 11:00:30  kulow
 * fixed some free mismatch errors
 *
 * Revision 1.15  1997/10/21 20:44:40  kulow
 * removed all NULLs and replaced it with 0L or "".
 * There are some left in mediatool, but this is not C++
 *
 * Revision 1.14  1997/10/16 11:14:26  torben
 * Kalle: Copyright headers
 * kdoctoolbar removed
 *
 * Revision 1.13  1997/10/12 11:05:32  kulow
 * don't export debugWin. kmenuedit used the same name
 *
 * Revision 1.12  1997/10/04 14:51:31  kulow
 * added some prototypes in case the shape.h is not found. I'm not sure,
 * if this works, but it helps for compiling
 *
 * Revision 1.11  1997/09/18 12:47:15  kulow
 * uups. The error message is not valid for the cpp file
 *
 * Revision 1.10  1997/09/18 12:16:03  kulow
 * corrected some header dependencies. Removed most of them in drag.h and put
 * them in drag.cpp. Now it should compile even under SunOS 4.4.1 ;)
 *
 * Revision 1.9  1997/08/31 08:03:47  kdecvs
 * Heureka: Fritz fixed the dragging of icons on the root window (Kalle)
 *
 * Revision 1.8  1997/07/31 19:52:31  kalle
 * Root-drop bug hopefully fixed (courtesy of Fritz Elfert of ISDN4Linux fame)
 *
 * Revision 1.7  1997/05/09 15:10:10  kulow
 * Coolo: patched ltconfig for FreeBSD
 * removed some stupid warnings
 *
 * Revision 1.6  1997/05/09 08:23:40  kulow
 * Coolo: included X11 headers again in drag.cpp (my fault)
 *
 * Revision 1.5  1997/05/08 22:53:15  kalle
 * Kalle:
 * KPixmap gone for good
 * Eliminated static objects from KApplication and HTML-Widget
 *
 * Revision 1.4  1997/05/08 21:09:44  kulow
 * Coolo: I forgot to include Torben's changes
 *
 * Revision 1.4  1997/03/10 19:59:12  kalle
 * Merged changes from 0.6.3
 *
 * Revision 1.3  1997/01/15 20:01:58  kalle
 * merged changes from 0.52
 *
 * Revision 1.2  1996/12/07 22:21:18  kalle
 * RCS header, include kapp.h
 *
 *
 * Drag 'n Drop implementation, taken from kfm
 *
 * Author: Torben Weis
 */

#include "drag.h"

#include <stdio.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif

#include <qlist.h>
#include <qcursor.h>
#include <qbitmap.h>

#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif    

#include "kapp.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>

#ifdef HAVE_X11_EXTENSTIONS_SHAPE_H
#include <X11/extensions/shape.h>
#else
extern "C" {
void XShapeCombineMask(Display*, Window, int, int, int, Pixmap, int);
#define ShapeBounding                   0 
#define ShapeSet                        0 
}
#endif

static Window debugWin = 0;

KDNDDropZone::KDNDDropZone( QWidget* _parent, int _accept ) : QObject()
{
  widget = _parent;
  acceptType = _accept;
  
  kapp->addDropZone( this );
}

QWidget* KDNDDropZone::getWidget()
{
  return widget;
}

QStrList & KDNDDropZone::getURLList()
{
    return urlList;
}

void KDNDDropZone::parseURLList()
{
    urlList.clear();

    if ( dndType != DndURL )
	return;

    QString s = dndData;
    s.detach();
    int i;
    
    while ( ( i = s.find( "\n" ) ) != -1 )
    {
	QString t = s.left( i );
	urlList.append( t.data() );
	s = s.mid( i + 1, s.length() );
    }
    
    urlList.append( s.data() );
}

void KDNDDropZone::drop( char *_data, int _size, int _type, int _x, int _y )
{
  dndSize = _size;
  dndType = _type;
  dndData = _data;
  
  dndX = _x;
  dndY = _y;
  
  parseURLList();

  emit dropAction( this );
}

void KDNDDropZone::enter( char *_data, int _size, int _type, int _x, int _y )
{
  dndSize = _size;
  dndType = _type;
  dndData = _data;
  
  dndX = _x;
  dndY = _y;
  
  parseURLList();

  emit dropEnter( this );
}

void KDNDDropZone::leave()
{
  emit dropLeave( this );
}

KDNDDropZone::~KDNDDropZone()
{
  if (kapp)
     kapp->removeDropZone( this );
}


void KDNDWidget::startDrag( KDNDIcon *_icon, char *_data, int _size, int _type, int _dx, int _dy )
{
  if ( dndData != 0 )
     delete [] dndData ;
  
  drag = true;
    
  dndData = new char[ _size + 1 ];
  memcpy( dndData, _data, _size );
  dndData[ _size ] = 0;
  
  dndSize = _size + 1;
  dndType = _type;
  dndIcon = _icon;
  dndOffsetX = _dx;
  dndOffsetY = _dy;
  
  dndIcon->raise();
  
  dndLastWindow = (Window)0;
  
  Window root = DefaultRootWindow( kapp->getDisplay() );
  XChangeProperty( kapp->getDisplay(), root, kapp->getDndSelectionAtom(), 
				   XA_STRING, 8,
				   PropModeReplace, (const unsigned char*)dndData, dndSize);
    
/* I commented this out, like mentioned by Paul Kendal (coolo)
  // Commenting this out will only work with click on focus window managers
  // grabMouse();
  XGrabPointer(kapp->getDisplay(),root,False,
			   ButtonMotionMask|ButtonPressMask|ButtonReleaseMask,
			   GrabModeSync,GrabModeAsync,root,
			   None,
			   CurrentTime);
*/

  // KDNDApplication::setOverrideCursor( waitCursor );
}

Window KDNDWidget::findRootWindow( QPoint & p )
{
    int x,y;
    Window root = DefaultRootWindow( kapp->getDisplay() );
    Window win;
    XTranslateCoordinates( kapp->getDisplay(), root, root, p.x(), p.y(), &x, &y, &win );
    /*
  Window root;
  Window parent;
  Window *children;
  unsigned int cchildren;
  
  int win = -1;
  int win_x,win_y,win_h,win_w;
  
  root = DefaultRootWindow( kapp->getDisplay() );
  
  XQueryTree( kapp->getDisplay(), root, &root, &parent, 
			  &children, &cchildren );
  
  XWindowAttributes *attribs = new XWindowAttributes;
  
  for ( int i = 0; i < cchildren; i++ )
    {
	  int x,y;
	  unsigned int w,h,b,d;
	  
	  XGetGeometry( kapp->getDisplay(), children[i], &root, 
					&x, &y, &w, &h, &b, &d );

	  QRect r( x,y,w,h );
	  
	  if ( r.contains( p ) && children[i] != dndIcon->winId() )
		{   
		  XGetWindowAttributes( kapp->getDisplay(), children[i], attribs );
		  
		  if ( attribs->map_state != 0 )
			{
			  win = children[i];
			  win_x = x;
			  win_y = y;
			  win_h = h;
			  win_w = w;
			}
		}
    }     
  
  delete attribs;
  */
  return win;
}


/**
 * @oldErrorHandler stores the original error handler.
 */
static
int (* oldErrorHandler)(Display *, XErrorEvent *) = 0L;

/**
 * Errorhandler to be used during DND
 */
static
int myErrorHandler(Display *d, XErrorEvent *e)
{
	char msg[80];
	XGetErrorText(d, e->error_code, msg, 80);
	//	fprintf(stderr, "Ignored Error: %s\n", msg);
	//	fprintf(stderr, "Request: Maj=%d Min=%di, Serial=%08lx\n",
	//		e->request_code, e->minor_code, e->serial);
	return 0;
}

void KDNDWidget::mouseReleaseEvent( QMouseEvent * _mouse )
{
  if ( !drag )
    {
	  dndMouseReleaseEvent( _mouse );
	  return;
    }
    
  // KDNDApplication::restoreOverrideCursor();

  dndIcon->move( -200, -200 );
  
//   printf("************************************************************\n");
//   printf("*** id = %i ****\n", dndIcon->winId());
//   printf("************************************************************\n");
  debugWin = dndIcon->winId();
  
  QPoint p = mapToGlobal( _mouse->pos() );
  
  Window root;
  root = DefaultRootWindow( kapp->getDisplay() );
  
  Window win = findRootWindow( p );
//   printf("************************************************************\n");
//   printf("*** win = %ld **** dndLastWindow = %ld ****\n", win, dndLastWindow );
//   printf("************************************************************\n");
  
  drag = false;
/* I commented this out, since it works without (coolo)
  // Commenting this out will only work with click on focus window managers
  // releaseMouse();
  XUngrabPointer(kapp->getDisplay(),CurrentTime);
*/

//   printf("Ungarbbed\n");
  
  // If we found a destination for the drop
   if ( win != 0 )
  // if ( dndLastWindow != 0 )
    {	
          XWindowAttributes Wattr;

          XGetWindowAttributes(kapp->getDisplay(), win, &Wattr);
          if (Wattr.map_state != IsUnmapped)
          { 
// 	printf("Sending event\n");
	
	      XEvent Event;
	  
	      Event.xclient.type              = ClientMessage;
	      Event.xclient.display           = kapp->getDisplay();
	      Event.xclient.message_type      = kapp->getDndProtocolAtom();
	      Event.xclient.format            = 32;
	      Event.xclient.window            = dndLastWindow;
	      Event.xclient.data.l[0]         = dndType;
	      Event.xclient.data.l[1]         = 0;
	      Event.xclient.data.l[2]         = 0;
	      Event.xclient.data.l[3]         = p.x();
	      Event.xclient.data.l[4]         = p.y();

              // Switch to "friendly" error handler.
              if (oldErrorHandler == 0L)
	          oldErrorHandler = XSetErrorHandler(myErrorHandler);
// 	      printf("1\n");
	      XSendEvent( kapp->getDisplay(), dndLastWindow, True, NoEventMask, &Event );	
// 	      printf("2\n");
	      XSync( kapp->getDisplay(), FALSE );	
// 	      printf("3\n");
	      (void) XSetErrorHandler(oldErrorHandler);
              oldErrorHandler = 0L;
          }

	  delete [] dndData;
	  dndData = 0L;
    }
   else
   {
//        printf("Root Drop Event\n");
       rootDropEvent( p.x(), p.y() );
   }

  delete dndIcon;
  dndIcon = 0L;
   
  dragEndEvent();
}

void KDNDWidget::mouseMoveEvent( QMouseEvent * _mouse )
{
  if ( !drag )
    {
	  dndMouseMoveEvent( _mouse );
	  return;
    }

    
  // dndIcon->hide();
  
  // QPoint p = mapToGlobal( _mouse->pos() );
  QPoint p = QCursor::pos();

  /* Window root;
  root = DefaultRootWindow( kapp->getDisplay() );  
  Window win = findRootWindow( p );
  printf("Window = '%x'  %i %i\n",win,dndOffsetX,dndOffsetY);
  printf("x=%i y=%i\n",p.x(),p.y()); */

  QPoint p2( p.x(), p.y() );
  p2.setX( p2.x() + dndOffsetX );
  p2.setY( p2.y() + dndOffsetY );
  dndIcon->move( p2 );
  // dndIcon->show();
}

void KDNDWidget::rootDropEvent( int _x, int _y )
{
  Window root;
  Window parent;
  Window *children;
  unsigned int cchildren;
    
//   printf("Root Window\n");
  root = DefaultRootWindow( kapp->getDisplay() );
//   printf("Query root tree\n");

  // Switch to "friendly" error handler.
  if (oldErrorHandler == 0L)
      oldErrorHandler = XSetErrorHandler(myErrorHandler);
  XQueryTree( kapp->getDisplay(), root, &root, &parent, &children, &cchildren );
    
  for ( uint i = 0; i < cchildren; i++ )
  {
	if ( children[i] == debugWin ) {}
// 	  printf("******************** root id = %ld *********************\n",children[i] );
      else
      {
	  XEvent Event;
      
	  XWindowAttributes Wattr;
	  XGetWindowAttributes(kapp->getDisplay(), children[i], &Wattr);
	  if (Wattr.map_state == IsUnmapped)
		continue;
 
	  Event.xclient.type              = ClientMessage;
	  Event.xclient.display           = kapp->getDisplay();
	  Event.xclient.message_type      = kapp->getDndRootProtocolAtom();
	  Event.xclient.format            = 32;
	  Event.xclient.window            = children[ i ];
	  Event.xclient.data.l[0]         = dndType;
	  Event.xclient.data.l[1]         = (long) time( 0L );
	  Event.xclient.data.l[2]         = 0;
	  Event.xclient.data.l[3]         = _x;
	  Event.xclient.data.l[4]         = _y;
	  XSendEvent( kapp->getDisplay(), children[ i ], True, NoEventMask, &Event);
	  XSync( kapp->getDisplay(), FALSE );	
      }
  }
    
  (void)XSetErrorHandler(oldErrorHandler);
  oldErrorHandler = 0L;
//   printf("Done\n");
  
  // Clean up.
  rootDropEvent();
}

void KDNDWidget::rootDropEvent()
{
  if ( dndIcon != 0L )
	delete dndIcon;
  dndIcon = 0L;
  
  if ( dndData != 0L )
	delete [] dndData;
  dndData = 0L;
}

KDNDWidget::~KDNDWidget()
{
  if ( dndData != 0L )
     delete [] dndData;
}

KDNDIcon::KDNDIcon( QPixmap &_pixmap, int _x, int _y ) :
  QWidget( 0L, 0L, WStyle_Customize | WStyle_Tool | WStyle_NoBorder )
{
  pixmap = _pixmap;
  
  setGeometry( _x, _y, _pixmap.width(), _pixmap.height() );
  show();
}


KDNDIcon::KDNDIcon( const KDNDIcon& icon ) : QWidget()
{
  pixmap = icon.pixmap; // implicitly ref-counted
}


KDNDIcon& KDNDIcon::operator= ( const KDNDIcon& icon )
{
  if( this != &icon )
	pixmap = icon.pixmap;

  return *this;
}


void KDNDIcon::paintEvent( QPaintEvent * ) 
{
  bitBlt( this, 0,0, &pixmap );
}

void KDNDIcon::resizeEvent( QResizeEvent * )
{
  if ( pixmap.mask() != 0L )
	XShapeCombineMask( x11Display(), winId(), ShapeBounding, 0, 0, 
					   pixmap.mask()->handle(), ShapeSet );
}

KDNDIcon::~KDNDIcon()
{
}

#include "drag.moc"


--- NEW FILE: kpoint.cpp ---
// KPoint - (c) by Reginald Stadlbauer 1998 <reggie at kde.org>
// Version: 0.0.1

#include <qpoint.h>

#include "kpoint.h"

//==========================================================
KPoint::KPoint()
{
  xpos = 0;
  ypos = 0;
}

//==========================================================
KPoint::KPoint(int _xpos,int _ypos)
{
  xpos = _xpos;
  ypos = _ypos;
}

//==========================================================
KPoint::KPoint(const QPoint &_pnt)
{
  xpos = _pnt.x();
  ypos = _pnt.y();
}
  
//==========================================================
bool KPoint::isNull() const
{
  return (xpos == 0 && ypos == 0);
}

//==========================================================
int KPoint::x() const
{
  return xpos;
}

//==========================================================
int KPoint::y() const
{
  return ypos;
}

//==========================================================
void KPoint::setX(int _xpos)
{
  xpos = _xpos;
}

//==========================================================
void KPoint::setY(int _ypos)
{
  ypos = _ypos;
}

//==========================================================
int &KPoint::rx()
{
  return xpos;
}

//==========================================================
int &KPoint::ry()
{
  return ypos;
}

//==========================================================
KPoint &KPoint::operator+=(const KPoint &_pnt)
{
  xpos += _pnt.x();
  ypos += _pnt.y();

  return *this;
}

//==========================================================
KPoint &KPoint::operator-=(const KPoint &_pnt)
{
  xpos -= _pnt.x();
  ypos -= _pnt.y();

  return *this;
}

//==========================================================
KPoint &KPoint::operator*=(int _c)
{
  xpos *= _c;
  ypos *= _c;

  return *this;
}

//==========================================================
KPoint &KPoint::operator*=(double _c)
{
  xpos = static_cast<int>(xpos * _c);
  ypos = static_cast<int>(ypos * _c);

  return *this;
}

//==========================================================
KPoint &KPoint::operator/=(int _c)
{
  xpos /= _c;
  ypos /= _c;

  return *this;
}

//==========================================================
KPoint &KPoint::operator/=(double _c)
{
  xpos = static_cast<int>(xpos / _c);
  ypos = static_cast<int>(ypos / _c);

  return *this;
}

//==========================================================
KPoint::operator QPoint() const
{
  return QPoint(xpos,ypos); 
}

//==========================================================
bool operator==(const KPoint &_pnt1,const KPoint &_pnt2)
{
  return (_pnt1.x() == _pnt2.x() && _pnt1.y() == _pnt2.y());
}

//==========================================================
bool operator!=(const KPoint &_pnt1,const KPoint &_pnt2)
{
  return (_pnt1.x() != _pnt2.x() || _pnt1.y() != _pnt2.y());
}

//==========================================================
bool operator==(const QPoint &_pnt1,const KPoint &_pnt2)
{
  return (_pnt1.x() == _pnt2.x() && _pnt1.y() == _pnt2.y());
}

//==========================================================
bool operator!=(const QPoint &_pnt1,const KPoint &_pnt2)
{
  return (_pnt1.x() != _pnt2.x() || _pnt1.y() != _pnt2.y());
}

//==========================================================
bool operator==(const KPoint &_pnt1,const QPoint &_pnt2)
{
  return (_pnt1.x() == _pnt2.x() && _pnt1.y() == _pnt2.y());
}

//==========================================================
bool operator!=(const KPoint &_pnt1,const QPoint &_pnt2)
{
  return (_pnt1.x() != _pnt2.x() || _pnt1.y() != _pnt2.y());
}

//==========================================================
KPoint operator+(const KPoint &_pnt1,const KPoint &_pnt2)
{
  return KPoint(_pnt1.x() + _pnt2.x(),_pnt1.y() + _pnt2.y());
}

//==========================================================
KPoint operator-(const KPoint &_pnt1,const KPoint &_pnt2)
{
  return KPoint(_pnt1.x() - _pnt2.x(),_pnt1.y() - _pnt2.y());
}

//==========================================================
KPoint operator*(const KPoint &_pnt,int _c)
{
  return KPoint(_pnt.x() * _c,_pnt.y() *_c);
}

//==========================================================
KPoint operator*(int _c,const KPoint &_pnt)
{
  return KPoint(_pnt.x() * _c,_pnt.y() *_c);
}

//==========================================================
KPoint operator*(const KPoint &_pnt,double _c)
{
  return KPoint(_pnt.x() * _c,_pnt.y() *_c);
}

//==========================================================
KPoint operator*(double _c,const KPoint &_pnt)
{
  return KPoint(_pnt.x() * _c,_pnt.y() *_c);
}

//==========================================================
KPoint operator-(const KPoint &_pnt)
{
  return KPoint(-_pnt.x(),-_pnt.y());
}

//==========================================================
KPoint operator/(const KPoint &_pnt,int _c)
{
  return KPoint(_pnt.x() / _c,_pnt.y() /_c);
}

//==========================================================
KPoint operator/(const KPoint &_pnt,double _c)
{
  return KPoint(_pnt.x() / _c,_pnt.y() /_c);
}

--- NEW FILE: Makefile.in ---
# Makefile.in generated automatically by automake 1.4 from Makefile.am

# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

#	This file is part of the KDE libraries
#    Copyright (C) 1996-1997 Matthias Kalle Dalheimer (kalle at kde.org)
#			  (C) 1997 Stephan Kulow (coolo at kde.org)

#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Library General Public
#    License as published by the Free Software Foundation; either
#    version 2 of the License, or (at your option) any later version.

#    This library is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    Library General Public License for more details.

#    You should have received a copy of the GNU Library General Public License 
#    along with this library; see the file COPYING.LIB.  If not, write to
#    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#    Boston, MA 02111-1307, USA.


SHELL = @SHELL@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

DESTDIR =

pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@

top_builddir = ..

ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@

NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_alias = @build_alias@
build_triplet = @build@
host_alias = @host_alias@
host_triplet = @host@
target_alias = @target_alias@
target_triplet = @target@
AS = @AS@
CC = @CC@
CPP = @CPP@
CXX = @CXX@
CXXCPP = @CXXCPP@
DLLTOOL = @DLLTOOL@
GLINC = @GLINC@
GLLIB = @GLLIB@
GMSGFMT = @GMSGFMT@
IDL = @IDL@
KDE_EXTRA_RPATH = @KDE_EXTRA_RPATH@
KDE_INCLUDES = @KDE_INCLUDES@
KDE_LDFLAGS = @KDE_LDFLAGS@
KDE_RPATH = @KDE_RPATH@
LD = @LD@
LIBCOMPAT = @LIBCOMPAT@
LIBCRYPT = @LIBCRYPT@
LIBDL = @LIBDL@
LIBJPEG = @LIBJPEG@
LIBMICO = @LIBMICO@
LIBOBJS = @LIBOBJS@
LIBPNG = @LIBPNG@
LIBPTHREAD = @LIBPTHREAD@
LIBPYTHON = @LIBPYTHON@
LIBQIMGIO = @LIBQIMGIO@
LIBSOCKET = @LIBSOCKET@
LIBTIFF = @LIBTIFF@
LIBTOOL = @LIBTOOL@
LIBUCB = @LIBUCB@
LIBZ = @LIBZ@
LIB_KAB = @LIB_KAB@
LIB_KDECORE = @LIB_KDECORE@
LIB_KDEUI = @LIB_KDEUI@
LIB_KDEUTIL = @LIB_KDEUTIL@
LIB_KFILE = @LIB_KFILE@
LIB_KFM = @LIB_KFM@
LIB_KHTML = @LIB_KHTML@
LIB_KHTMLW = @LIB_KHTMLW@
LIB_KIMGIO = @LIB_KIMGIO@
LIB_KIO = @LIB_KIO@
LIB_MEDIATOOL = @LIB_MEDIATOOL@
LIB_QT = @LIB_QT@
LIB_X11 = @LIB_X11@
LN_S = @LN_S@
MAKEINFO = @MAKEINFO@
MICO_INCLUDES = @MICO_INCLUDES@
MICO_LDFLAGS = @MICO_LDFLAGS@
MOC = @MOC@
MSGFMT = @MSGFMT@
NM = @NM@
PACKAGE = @PACKAGE@
PAMINC = @PAMINC@
PAMLIBPATHS = @PAMLIBPATHS@
PAMLIBS = @PAMLIBS@
PYTHONINC = @PYTHONINC@
PYTHONLIB = @PYTHONLIB@
QKEYCODE_H = @QKEYCODE_H@
QT_INCLUDES = @QT_INCLUDES@
QT_LDFLAGS = @QT_LDFLAGS@
RANLIB = @RANLIB@
TOPSUBDIRS = @TOPSUBDIRS@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
XGETTEXT = @XGETTEXT@
XPMINC = @XPMINC@
XPMLIB = @XPMLIB@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_INCLUDES = @X_INCLUDES@
X_LDFLAGS = @X_LDFLAGS@
all_includes = @all_includes@
all_libraries = @all_libraries@
install_root = @install_root@
kde_appsdir = @kde_appsdir@
kde_bindir = @kde_bindir@
kde_cgidir = @kde_cgidir@
kde_confdir = @kde_confdir@
kde_datadir = @kde_datadir@
kde_htmldir = @kde_htmldir@
kde_icondir = @kde_icondir@
kde_includes = @kde_includes@
kde_libraries = @kde_libraries@
kde_locale = @kde_locale@
kde_mimedir = @kde_mimedir@
kde_minidir = @kde_minidir@
kde_partsdir = @kde_partsdir@
kde_sounddir = @kde_sounddir@
kde_toolbardir = @kde_toolbardir@
kde_wallpaperdir = @kde_wallpaperdir@
qt_includes = @qt_includes@
qt_libraries = @qt_libraries@
topdir = @topdir@
x_includes = @x_includes@
x_libraries = @x_libraries@

INCLUDES = $(QT_INCLUDES) $(X_INCLUDES)
EXTRA_DIST = convert_key.c charsets.config $(kdebug_DATA) kdebugareas.txt 	kstddirs.h kstddirs.cpp

lib_LTLIBRARIES = libkdecore.la

include_HEADERS = kconfig.h kconfigdata.h ksimpleconfig.h kconfigbase.h 	kcolorgroup.h kapp.h kcharsets.h 	kurl.h ksock.h drag.h  ckey.h kmisc.h 	kprocess.h kprocctrl.h klocale.h kiconloader.h kdebug.h		kstdaccel.h kwm.h krootprop.h kstring.h kpixmap.h dither.h 	kaccel.h kglobalaccel.h kckey.h kclipboard.h krect.h ksize.h 	kpoint.h 


noinst_HEADERS = kdebugdialog.h kcharsetsdata.h 

libkdecore_la_SOURCES = kconfig.cpp kconfigbase.cpp ksimpleconfig.cpp 	kcolorgroup.cpp kapp.cpp kurl.cpp ksock.cpp drag.cpp 	 kprocess.cpp kprocctrl.cpp klocale.cpp 	libintl.cpp fakes.cpp kiconloader.cpp kdebug.cpp 	kstdaccel.cpp kwm.cpp krootprop.cpp kcharsets.cpp kcharsetsdata.cpp 	kchartables.cpp kstring.cpp kpixmap.cpp dither.cpp 	kckey.cpp kaccel.cpp kglobalaccel.cpp kclipboard.cpp 	krect.cpp ksize.cpp kpoint.cpp


libkdecore_la_LDFLAGS = -version-info 2:0
# libkdecore_la_LIBADD = 

libkdecore_la_METASOURCES = drag.moc kapp.moc kclipboard.moc 	kconfig.moc kconfigbase.moc kdebugdialog.moc kglobalaccel.moc 	kiconloader.moc kprocctrl.moc kprocess.moc ksimpleconfig.moc 	ksock.moc 


SRCDOC_DEST = $(kde_htmldir)/en/kdelibs/kdecore

kdebugdir = $(kde_confdir)
kdebug_DATA = kdebug.areas
mkinstalldirs = $(SHELL) $(top_srcdir)/admin/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES = 
LTLIBRARIES =  $(lib_LTLIBRARIES)


DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libkdecore_la_LIBADD = 
libkdecore_la_OBJECTS =  kconfig.lo kconfigbase.lo ksimpleconfig.lo \
kcolorgroup.lo kapp.lo kurl.lo ksock.lo drag.lo kprocess.lo \
kprocctrl.lo klocale.lo libintl.lo fakes.lo kiconloader.lo kdebug.lo \
kstdaccel.lo kwm.lo krootprop.lo kcharsets.lo kcharsetsdata.lo \
kchartables.lo kstring.lo kpixmap.lo dither.lo kckey.lo kaccel.lo \
kglobalaccel.lo kclipboard.lo krect.lo ksize.lo kpoint.lo
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DATA =  $(kdebug_DATA)

HEADERS =  $(include_HEADERS) $(noinst_HEADERS)

DIST_COMMON =  README AUTHORS ChangeLog Makefile.am Makefile.in NEWS \
TODO


DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)

TAR = tar
GZIP_ENV = --best
SOURCES = $(libkdecore_la_SOURCES)
OBJECTS = $(libkdecore_la_OBJECTS)

all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cpp .lo .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
	cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps kdecore/Makefile
	cd $(top_srcdir) && perl admin/automoc kdecore/Makefile.in

Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
	cd $(top_builddir) \
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status


mostlyclean-libLTLIBRARIES:

clean-libLTLIBRARIES:
	-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)

distclean-libLTLIBRARIES:

maintainer-clean-libLTLIBRARIES:

install-libLTLIBRARIES: $(lib_LTLIBRARIES)
	@$(NORMAL_INSTALL)
	$(mkinstalldirs) $(DESTDIR)$(libdir)
	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    echo "$(LIBTOOL)  --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \
	    $(LIBTOOL)  --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \
	  else :; fi; \
	done

uninstall-libLTLIBRARIES:
	@$(NORMAL_UNINSTALL)
	list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  $(LIBTOOL)  --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
	done

.c.o:
	$(COMPILE) -c $<

.s.o:
	$(COMPILE) -c $<

.S.o:
	$(COMPILE) -c $<

mostlyclean-compile:
	-rm -f *.o core *.core

clean-compile:

distclean-compile:
	-rm -f *.tab.c

maintainer-clean-compile:

.c.lo:
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<

.s.lo:
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<

.S.lo:
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<

mostlyclean-libtool:
	-rm -f *.lo

clean-libtool:
	-rm -rf .libs _libs

distclean-libtool:

maintainer-clean-libtool:

libkdecore.la: $(libkdecore_la_OBJECTS) $(libkdecore_la_DEPENDENCIES)
	$(CXXLINK) -rpath $(libdir) $(libkdecore_la_LDFLAGS) $(libkdecore_la_OBJECTS) $(libkdecore_la_LIBADD) $(LIBS)
.cpp.o:
	$(CXXCOMPILE) -c $<
.cpp.lo:
	$(LTCXXCOMPILE) -c $<

install-kdebugDATA: $(kdebug_DATA)
	@$(NORMAL_INSTALL)
	$(mkinstalldirs) $(DESTDIR)$(kdebugdir)
	@list='$(kdebug_DATA)'; for p in $$list; do \
	  if test -f $(srcdir)/$$p; then \
	    echo " $(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(kdebugdir)/$$p"; \
	    $(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(kdebugdir)/$$p; \
	  else if test -f $$p; then \
	    echo " $(INSTALL_DATA) $$p $(DESTDIR)$(kdebugdir)/$$p"; \
	    $(INSTALL_DATA) $$p $(DESTDIR)$(kdebugdir)/$$p; \
	  fi; fi; \
	done

uninstall-kdebugDATA:
	@$(NORMAL_UNINSTALL)
	list='$(kdebug_DATA)'; for p in $$list; do \
	  rm -f $(DESTDIR)$(kdebugdir)/$$p; \
	done

install-includeHEADERS: $(include_HEADERS)
	@$(NORMAL_INSTALL)
	$(mkinstalldirs) $(DESTDIR)$(includedir)
	@list='$(include_HEADERS)'; for p in $$list; do \
	  if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
	  echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p"; \
	  $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p; \
	done

uninstall-includeHEADERS:
	@$(NORMAL_UNINSTALL)
	list='$(include_HEADERS)'; for p in $$list; do \
	  rm -f $(DESTDIR)$(includedir)/$$p; \
	done

tags: TAGS

ID: $(HEADERS) $(SOURCES) $(LISP)
	list='$(SOURCES) $(HEADERS)'; \
	unique=`for i in $$list; do echo $$i; done | \
	  awk '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	here=`pwd` && cd $(srcdir) \
	  && mkid -f$$here/ID $$unique $(LISP)

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)'; \
	unique=`for i in $$list; do echo $$i; done | \
	  awk '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
	  || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags  $$unique $(LISP) -o $$here/TAGS)

mostlyclean-tags:

clean-tags:

distclean-tags:
	-rm -f TAGS ID

maintainer-clean-tags:

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)

subdir = kdecore

distdir: $(DISTFILES)
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  if test -d $$d/$$file; then \
	    cp -pr $$/$$file $(distdir)/$$file; \
	  else \
	    test -f $(distdir)/$$file \
	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
	    || cp -p $$d/$$file $(distdir)/$$file || :; \
	  fi; \
	done
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am: install-libLTLIBRARIES
install-exec: install-exec-am

install-data-am: install-kdebugDATA install-includeHEADERS \
		install-data-local
install-data: install-data-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-libLTLIBRARIES uninstall-kdebugDATA \
		uninstall-includeHEADERS uninstall-local
uninstall: uninstall-am
all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS)
all-redirect: all-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
	$(mkinstalldirs)  $(DESTDIR)$(libdir) $(DESTDIR)$(kdebugdir) \
		$(DESTDIR)$(includedir)


mostlyclean-generic:

clean-generic:

distclean-generic:
	-rm -f Makefile $(CONFIG_CLEAN_FILES)
	-rm -f config.cache config.log stamp-h stamp-h[0-9]*

maintainer-clean-generic:
mostlyclean-am:  mostlyclean-libLTLIBRARIES mostlyclean-compile \
		mostlyclean-libtool mostlyclean-tags \
		mostlyclean-generic

mostlyclean: mostlyclean-am

clean-am:  clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \
		clean-generic mostlyclean-am

clean: clean-am

distclean-am:  distclean-libLTLIBRARIES distclean-compile \
		distclean-libtool distclean-tags distclean-generic \
		clean-am
	-rm -f libtool

distclean: distclean-metasources distclean-am

maintainer-clean-am:  maintainer-clean-libLTLIBRARIES \
		maintainer-clean-compile maintainer-clean-libtool \
		maintainer-clean-tags maintainer-clean-generic \
		distclean-am
	@echo "This command is intended for maintainers to use;"
	@echo "it deletes files that may require special tools to rebuild."

maintainer-clean: maintainer-clean-am

.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \
clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \
uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \
distclean-compile clean-compile maintainer-clean-compile \
mostlyclean-libtool distclean-libtool clean-libtool \
maintainer-clean-libtool uninstall-kdebugDATA install-kdebugDATA \
uninstall-includeHEADERS install-includeHEADERS tags mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-local install-data-am install-data install-am \
install uninstall-local uninstall-am uninstall all-redirect all-am all \
installdirs mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean


srcdoc:
	$(mkinstalldirs) $(SRCDOC_DEST)
	kdoc -H -d $(SRCDOC_DEST) kdecore \
		 $(include_HEADERS) -lqt

ckey.h : convert_key.c
	$(CC) $(CFLAGS) convert_key.c -o convert_key
	./convert_key $(QKEYCODE_H)
	cat ackey ckey > ckey.h
	rm -f ackey ckey

install-data-local: charsets.config 
	$(mkinstalldirs) $(kde_confdir)
	$(INSTALL_DATA) $(srcdir)/charsets.config $(kde_confdir)/charsets   

uninstall-local:
	-rm -f $(kde_confdir)/charsets

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:


$(srcdir)/drag.cpp: drag.moc
drag.moc: $(srcdir)/drag.h
	$(MOC) $(srcdir)/drag.h -o drag.moc

$(srcdir)/kapp.cpp: kapp.moc
kapp.moc: $(srcdir)/kapp.h
	$(MOC) $(srcdir)/kapp.h -o kapp.moc

$(srcdir)/kclipboard.cpp: kclipboard.moc
kclipboard.moc: $(srcdir)/kclipboard.h
	$(MOC) $(srcdir)/kclipboard.h -o kclipboard.moc

$(srcdir)/kconfig.cpp: kconfig.moc
kconfig.moc: $(srcdir)/kconfig.h
	$(MOC) $(srcdir)/kconfig.h -o kconfig.moc

$(srcdir)/kconfigbase.cpp: kconfigbase.moc
kconfigbase.moc: $(srcdir)/kconfigbase.h
	$(MOC) $(srcdir)/kconfigbase.h -o kconfigbase.moc

$(srcdir)/kdebug.cpp: kdebugdialog.moc
kdebugdialog.moc: $(srcdir)/kdebugdialog.h
	$(MOC) $(srcdir)/kdebugdialog.h -o kdebugdialog.moc

$(srcdir)/kglobalaccel.cpp: kglobalaccel.moc
kglobalaccel.moc: $(srcdir)/kglobalaccel.h
	$(MOC) $(srcdir)/kglobalaccel.h -o kglobalaccel.moc

$(srcdir)/kiconloader.cpp: kiconloader.moc
kiconloader.moc: $(srcdir)/kiconloader.h
	$(MOC) $(srcdir)/kiconloader.h -o kiconloader.moc

$(srcdir)/kprocctrl.cpp: kprocctrl.moc
kprocctrl.moc: $(srcdir)/kprocctrl.h
	$(MOC) $(srcdir)/kprocctrl.h -o kprocctrl.moc

$(srcdir)/kprocess.cpp: kprocess.moc
kprocess.moc: $(srcdir)/kprocess.h
	$(MOC) $(srcdir)/kprocess.h -o kprocess.moc

$(srcdir)/ksimpleconfig.cpp: ksimpleconfig.moc
ksimpleconfig.moc: $(srcdir)/ksimpleconfig.h
	$(MOC) $(srcdir)/ksimpleconfig.h -o ksimpleconfig.moc

$(srcdir)/ksock.cpp: ksock.moc
ksock.moc: $(srcdir)/ksock.h
	$(MOC) $(srcdir)/ksock.h -o ksock.moc

distclean-metasources:
	-rm -f drag.moc kapp.moc kclipboard.moc kconfig.moc kconfigbase.moc kdebugdialog.moc kglobalaccel.moc kiconloader.moc kprocctrl.moc kprocess.moc ksimpleconfig.moc ksock.moc 

# DO_NOT_USE_AUTOMOC

--- NEW FILE: kclipboard.cpp ---
#include "kclipboard.h"

#include <qdatetm.h>
#define  GC GC_QQQ
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>  

#include <assert.h>
#include <iostream.h>
#include <ctype.h>
#include <string.h>

// Here we depend on Qt not to change their implementation!!!
extern Time qt_x_clipboardtime;                 // def. in qapp_x11.cpp   
extern QObject *qt_clipboard;                   // defined in qapp_xyz.cpp

KClipboard* KClipboard::s_pSelf = 0L;

KClipboard* KClipboard::self()
{
  if ( s_pSelf == 0L )
    s_pSelf = new KClipboard;
  
  return s_pSelf;
}

KClipboard::KClipboard()
{
  if ( s_pSelf )
  {
    cerr << "You may only open one KClipboard at once" << endl;
    assert( 0 );
  }
  
  if ( qt_clipboard != 0L )
  {    
    cerr << "KClipboard::KClipboard There is already a clipboard registered\n" << endl;
    assert( 0 );
  }
    
  qt_clipboard = this;
    
  m_bOwner = false;
  m_pOwner = 0L;
  m_bEmpty = true;    
  m_mimeTypeLen = 0;
}

KClipboard::~KClipboard()
{
}
   
bool KClipboard::open( int _mode )
{
  return open( _mode, "application/octet-stream" );
}

bool KClipboard::open( int _mode, const char *_format )
{
  if ( _mode != IO_ReadOnly && _mode != ( IO_WriteOnly | IO_Truncate ) && _mode != IO_WriteOnly )
  {    
    cerr << "KClipboard: Wrong flags in call for Ken" << endl;
    assert( 0 );
  }
    
  if ( _mode == IO_WriteOnly )
    _mode |= IO_Truncate;

  if ( _mode == ( IO_WriteOnly | IO_Truncate ) )
  {
    m_bEmpty = false;
    m_strFormat = _format;

    cerr << "Fuck ya too" << endl;

    QBuffer::open( _mode );
    if ( strcmp( _format, "application/octet-stream" ) != 0L && 
	 strcmp( _format, "text/plain" ) != 0L ) 
    {
      m_mimeTypeLen = strlen( _format ) + 1;
      writeBlock( _format, m_mimeTypeLen );
    }
    else
      m_mimeTypeLen = 0;
    
    cerr << "2 Fuck ya too" << endl;

    return true;
  }
  else if ( ( _mode & IO_ReadOnly ) == IO_ReadOnly )
  {
    // printf("isOwner %i\n", ( isOwner() ? 1:0 ) );
    // printf("isEmpty %i\n", ( isEmpty() ? 1:0 ) );
    if ( !isOwner() )
      fetchData();
      
    if ( m_strFormat != _format && strcmp( _format, "application/octet-stream" ) != 0L )
      return false;

    if ( !QBuffer::open( _mode ) )
      return false;
    at( m_mimeTypeLen );

    return true;
  }
  else
    assert( 0 );
}

const char* KClipboard::format()
{
  if ( !isOwner() )
    fetchData();

  return m_strFormat;  
}
  
void KClipboard::close()
{
  if ( ( mode() & IO_WriteOnly ) == IO_WriteOnly )
    setOwner();    
 
  QBuffer::close();
 
  if ( ( mode() & IO_ReadOnly ) == IO_ReadOnly && !isOwner() )
    clear();
}
    
void KClipboard::clear()
{
  m_bEmpty = true;
  m_strFormat = "";
  
  buffer().resize( 0 );
  
  if ( isOwner() )
    setOwner();
}

bool KClipboard::isEmpty()
{
  return m_bEmpty;
}

bool KClipboard::isOwner()
{
  return m_bOwner;
}

void KClipboard::setOwner()
{
  if ( isOwner() )
    return;

  // printf("Setting owner\n");
    
  QWidget *owner = makeOwner();
  Window win = owner->winId();
  Display *dpy = owner->x11Display();
    
  XSetSelectionOwner( dpy, XA_PRIMARY, win, qt_x_clipboardtime );
  if ( XGetSelectionOwner( dpy, XA_PRIMARY ) != win )
  {
    cerr <<  "KClipboard::setOwner: Cannot set X11 selection owner" << endl;
    return;
  }                            

  m_bOwner = true;
}

void KClipboard::fetchData()
{
  // printf("Getting data\n");
    
  if ( isOwner() )
    return;

  // printf("Doing it really!\n");
    
  clear();
    
  QWidget *owner = makeOwner();
  Window   win   = owner->winId();
  Display *display   = owner->x11Display();

  if ( XGetSelectionOwner(display,XA_PRIMARY) == None )
    return;

  Atom prop = XInternAtom( display, "QT_SELECTION", FALSE );
  XConvertSelection( display, XA_PRIMARY, XA_STRING, prop, win, CurrentTime );

  /** DEBUG code */
  XFlush( display );
  /** End DEBUG code */

  XEvent xevent;

  /** DEBUG code */
  QTime started = QTime::currentTime();
  while ( TRUE )
  {
    if ( XCheckTypedWindowEvent(display,win,SelectionNotify,&xevent) )
      break;
    QTime now = QTime::currentTime();
    if ( started > now )
      started = now;
    if ( started.msecsTo(now) > 5000 )
    {
      return;
    }
  }
  /** End Debug code */

  win  = xevent.xselection.requestor;
  prop = xevent.xselection.property;

  int nread = 0;
  Atom type;
  ulong nitems, bytes_after;
  int format;
  uchar *result;

  QBuffer::open( IO_WriteOnly | IO_Truncate );

  bool first = true;
  
  do 
  {
    int n = XGetWindowProperty( display, win, prop, nread/4, 1024, TRUE,
				AnyPropertyType, &type, &format, &nitems,
				&bytes_after, &result );
    if ( n != Success || type != XA_STRING )
      break;

    if ( first )
    {
      first = false;

      unsigned int i;
      for( i = 0; i < nitems; i++ )
	if ( result[i] == 0 )
	  break;
      
      if ( i < nitems )
      {
	m_mimeTypeLen = i + 1;
	m_strFormat = (const char*)result;
      }
      else
      {  
	m_strFormat = "";
      }
    }
    
    writeBlock( (const char*)result, nitems );
    nread += nitems;

    XFree( (char *)result );
    
  } while ( bytes_after > 0 );

  // printf("#################### READ %i bytes\n", nread );
    
  QBuffer::close();

  if ( m_strFormat.isEmpty() )
  {
    // Find non printable characters
    QByteArray ba = buffer();
    const char *d = ba.data();
    int len = ba.size();
    for( int j = 0; j < len; j++ )
    {
      if ( !isprint( d[j] ) && d[j] != '\n' && d[j] != '\r' && d[j] != '\t' )
      {
	m_strFormat = "application/octet-stream";
	return;
      }
    }
    
    m_strFormat = "text/plain";  
  }
  
  return;
}

bool KClipboard::event( QEvent *e )
{
  if ( e->type() != Event_Clipboard )
    return false;

  Display *display = qt_xdisplay();
  XEvent *xevent = (XEvent *)Q_CUSTOM_EVENT(e)->data();

  switch ( xevent->type )
  {
  case SelectionNotify:
    // printf("NOTIFY\n");
    m_bOwner = false;
    clear();
    break;

  case SelectionRequest:
    // printf("REQUEST\n");
    {
      // printf("Sending %i bytes\n",size());
	    
      XEvent xev;
      XSelectionRequestEvent *xreqev = &xevent->xselectionrequest;
      xev.xselection.type = SelectionNotify;
      xev.xselection.display = xreqev->display;
      xev.xselection.requestor = xreqev->requestor;
      xev.xselection.selection = xreqev->selection;
      xev.xselection.target = xreqev->target;
      xev.xselection.property = None;
      xev.xselection.time = xreqev->time;
      
      if ( xreqev->target == XA_STRING )
      {
	XChangeProperty ( display, xreqev->requestor, xreqev->property, XA_STRING, 8,
                                  PropModeReplace, (uchar *)buffer().data(), buffer().size() );
	xev.xselection.property = xreqev->property;
      }
      XSendEvent( display, xreqev->requestor, False, 0, &xev );
    }
  break;

  case SelectionClear:                    // new selection owner
    // printf("CLEAR\n");
    m_bOwner = false;
    clear();
    emit ownerChanged();
    break;

  }

  return true;
}                                              

QWidget* KClipboard::makeOwner()
{
  // Fake some clipboard owner
  if ( m_pOwner )  
    return m_pOwner;
  if ( qApp->mainWidget() )
    m_pOwner = qApp->mainWidget();
  else                     
    m_pOwner = new QWidget( 0L );
  return m_pOwner;
}            

void KClipboard::setURLList( QStrList& _urls )
{
  open( IO_WriteOnly | IO_Truncate, "url/url" );
  
  const char *s;
  for( s = _urls.first(); s != 0L; s = _urls.next() )
  {
    if ( s == _urls.getLast() )
      writeBlock( s, strlen( s ) );
    else
      writeBlock( s, strlen( s ) + 1 );
  }
  
  close();
}

bool KClipboard::urlList( QStrList& _urls)
{
  if ( !isOwner() )
    fetchData();

  if ( m_strFormat != "url/url" )
    return false;

  QByteArray ba = octetStream();
  char* d = ba.data();
  unsigned int c = 0;

  while ( c < ba.size() )
  {
    unsigned int start = c;
    // Find zero or end
    while ( d[c] != 0 && c < ba.size() )
      c++;

    if ( c < ba.size() )
    {
      _urls.append( d + start );
      // Skip zero
      c++;
    }
    else
    {
      char* s = new char[ c - start + 1 ];
      memcpy( s, d + start, c - start );
      s[ c - start ] = '\0';
      _urls.append( s );
      delete []s;
    }
  }

  return true;
}

void KClipboard::setText( const char *_text )
{
  open( IO_WriteOnly | IO_Truncate, "text/plain" );  

  writeBlock( _text, strlen( _text ) );
  
  close();
}

const char* KClipboard::text()
{
  if ( !isOwner() )
    fetchData();

 if ( m_strFormat != "text/plain" )
    return 0L;

  QByteArray ba = buffer();
  return ba.data() + m_mimeTypeLen;
}

void KClipboard::setOctetStream( QByteArray& _arr )
{
  open( IO_WriteOnly | IO_Truncate );  

  writeBlock( _arr.data(), _arr.size() );
  
  close();
}

QByteArray KClipboard::octetStream()
{
  if ( !isOwner() )
    fetchData();

  QByteArray ba;
  ba.duplicate( buffer().data() + m_mimeTypeLen, buffer().size() - m_mimeTypeLen );
  
  return ba;
}

#include "kclipboard.moc"


--- NEW FILE: kconfig.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: kconfig.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
//
// $Log: kconfig.h,v $
// Revision 1.1  2006-10-03 11:26:26  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:04  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
// Initial import of ViewML
//
// Revision 1.7  1998/01/18 14:38:48  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.5  1997/12/12 14:46:01  denis
// Reverting to lower case true/false
//
// Revision 1.4  1997/12/12 14:33:45  denis
// replaced true by TRUE and false by FALSE
//
// Revision 1.3  1997/10/21 20:44:44  kulow
// removed all NULLs and replaced it with 0L or "".
// There are some left in mediatool, but this is not C++
//
// Revision 1.2  1997/10/16 11:14:30  torben
// Kalle: Copyright headers
// kdoctoolbar removed
//
// Revision 1.1  1997/10/04 19:50:58  kalle
// new KConfig
//

#ifndef _KCONFIG_H
#define _KCONFIG_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kconfigbase.h>

/** 
* KDE Configuration entries
*
* This class implements KDE's default-based configuration system.
*
* @author Kalle Dalheimer (kalle at kde.org)
* @version $Id: kconfig.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
* @see KApplication::getConfig KConfigBase KSimpleConfig
* @short KDE Configuration Management  class
*/
class KConfig : public KConfigBase
{
  Q_OBJECT

  // copy-construction and assignment are not allowed
  KConfig( const KConfig& );
  KConfig& operator= ( const KConfig& rConfig );

protected:
  /** Open all appropriate configuration files and pass them on to
	* parseOneConfigFile()
	*/
  virtual void parseConfigFiles();

  /** Write back the configuration data.
	*/
  bool writeConfigFile( QFile& rFile, bool bGlobal = false );

public:
  /** 
	* Construct a KConfig object. 
	*
	* @param pGlobalAppFile A file to parse in addition to the
	*  normally parsed files.  
	* @param pLocalAppFile Another file to parse in addition to the
	* normally parsed files (has priority over pGlobalAppFile 
	*/
  KConfig( const char* pGlobalAppFile = 0L, 
		   const char* pLocalAppFile = 0L );

  /** 
	* Destructor. 
	*
	* Writes back any dirty configuration entries.
	*/
  virtual ~KConfig();

  /**
	* Write back the config cache.
	*/
  virtual void sync();
};
  


#endif

--- NEW FILE: kdebug.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef _KDEBUG_H
#define _KDEBUG_H

#ifdef kdebug
#undef kdebug
#endif
#ifdef NDEBUG
#define kdebug kdebug_null
#endif

void kdebug( unsigned short level, unsigned short area, const char *fmt, ... );
void kdebug_null (unsigned short level, unsigned short area, const char *fmt, ...);

#ifndef NDEBUG
#define KDEBUG( Level, Area, String ) kdebug( (Level), (Area), (String) );
#define KDEBUG1( Level, Area, String, Par1 ) kdebug( (Level), (Area), (String), (Par1) );
#define KDEBUG2( Level, Area, String, Par1, Par2 ) kdebug( (Level), (Area), (String), (Par1), (Par2) );
#define KDEBUG3( Level, Area, String, Par1, Par2, Par3 ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3) );
#define KDEBUG4( Level, Area, String, Par1, Par2, Par3, Par4 ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4) );
#define KDEBUG5( Level, Area, String, Par1, Par2, Par3, Par4, Par5 ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5) );
#define KDEBUG6( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6 ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6) );
#define KDEBUG7( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7 ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6), (Par7) );
#define KDEBUG8( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8 ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6), (Par7), (Par8) );
#define KDEBUG9( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8, Par9 ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6), (Par7), (Par8), (Par9) );
#define KASSERT( Cond, Level, Area, String ) { if( !Cond ) kdebug( (Level), (Area), (String) ); }
#define KASSERT1( Cond, Level, Area, String, Par1 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1) ); }
#define KASSERT2( Cond, Level, Area, String, Par1, Par2 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2) ); }
#define KASSERT3( Cond, Level, Area, String, Par1, Par2, Par3 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3) ); }
#define KASSERT4( Cond, Level, Area, String, Par1, Par2, Par3, Par4 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4) ); }
#define KASSERT5( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5) ); }
#define KASSERT6( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6) ); }
#define KASSERT7( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6), (Par7) ); }
#define KASSERT8( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6), (Par7), (Par8) ); }
#define KASSERT9( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8, Par9 ) { if( !Cond ) kdebug( (Level), (Area), (String), (Par1), (Par2), (Par3), (Par4), (Par5), (Par6), (Par7), (Par8), (Par9) ); }
#else
#define KDEBUG( Level, Area, String )
#define KDEBUG1( Level, Area, String, Par1 )
#define KDEBUG2( Level, Area, String, Par1, Par2 )
#define KDEBUG3( Level, Area, String, Par1, Par2, Par3 )
#define KDEBUG4( Level, Area, String, Par1, Par2, Par3, Par4 )
#define KDEBUG5( Level, Area, String, Par1, Par2, Par3, Par4, Par5 )
#define KDEBUG6( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6 )
#define KDEBUG7( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7 )
#define KDEBUG8( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8 )
#define KDEBUG9( Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8, Par9 )
#define KASSERT( Cond, Level, Area, String )
#define KASSERT1( Cond, Level, Area, String, Par1 )
#define KASSERT2( Cond, Level, Area, String, Par1, Par2 )
#define KASSERT3( Cond, Level, Area, String, Par1, Par2, Par3 )
#define KASSERT4( Cond, Level, Area, String, Par1, Par2, Par3, Par4 )
#define KASSERT5( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5 )
#define KASSERT6( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6 )
#define KASSERT7( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7 )
#define KASSERT8( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8 )
#define KASSERT9( Cond, Level, Area, String, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8, Par9 )
#endif

enum DebugLevels {
	KDEBUG_INFO=	0,
	KDEBUG_WARN=	1,
	KDEBUG_ERROR=	2,
	KDEBUG_FATAL=	3
};

#endif

--- NEW FILE: kdebug.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include "kdebugdialog.h"
#include "kdebug.h"
#include "kapp.h"

#include <qfile.h>
#include <qmessagebox.h>
#include <qlist.h>
#include <qstring.h>
#include <qtextstream.h>

#include <stdlib.h>	// abort
#include <stdarg.h>	// vararg stuff
#include <syslog.h>
#include <math.h>	// pow

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

class KDebugEntry
{ 
public:
  KDebugEntry (int n, QString d) {number=n; descr=d.copy();}
  KDebugEntry (QString d, int n) {number=n; descr=d.copy();}
  unsigned int number;
  QString descr;
};

static QList<KDebugEntry> *KDebugCache;
#define MAX_CACHE 20

QString getDescrFromNum(unsigned short _num)
{
  QString data, filename(KApplication::kde_configdir()+"/kdebug.areas");
  QFile file(filename);
  QTextStream *ts;
  unsigned long number, space;
  bool longOK;

  if (!KDebugCache)
      KDebugCache = new QList<KDebugEntry>;

  KDebugEntry *ent=0L;
  for (ent=KDebugCache->first(); ent != 0; ent=KDebugCache->next()) {
    if (ent->number == _num) {
      return ent->descr.copy();
    }
  }
 
  if (!file.open(IO_ReadOnly)) {
    warning("Couldn't open %s", (const char *)filename);
    file.close();
    return "";
  }

  ts = new QTextStream(&file);
  while (!ts->eof()) {
    data=ts->readLine().stripWhiteSpace().copy();

    if (data.left(1) == "#")
      continue; // It's a comment

    if (data.find("#") != -1) {
      data.remove(data.find("#"), data.length());
      data=data.stripWhiteSpace();
    }

    if (data.isEmpty() || data.isNull())
      continue;

    if ( (data.find(" ") == -1) && (data.find("	") == -1) )
      continue; // It only has one "part", need two

    if (data.find(" ") == -1)
      space=data.find("	");
    else if (data.find("	") == -1)
      space=data.find(" ");
    else if (data.find(" ") < data.find("	"))
      space=data.find(" ");
    else
      space=data.find("	");

    number=data.left(space).toULong(&longOK);
    if (!longOK)
      continue; // The first part wasn't a number

    if (number != _num)
      continue; // Not the number we're looking for

    data.remove(0, space); data=data.stripWhiteSpace();

    if (KDebugCache->count() <= MAX_CACHE)
      KDebugCache->removeFirst();
    KDebugCache->append(new KDebugEntry(number,data.copy()));
    delete ts;
    file.close();
    return data.copy();
  }

  delete ts;
  file.close();
  return "";
}

void kdebug_null( ushort nLevel, ushort nArea, 
                         const char* pFormat, ... )
{
	return;
}

void kdebug( ushort nLevel, ushort nArea, 
                         const char* pFormat, ... )
{
#ifndef NO_DEBUG
  // Save old group
  QString aOldGroup = kapp->getConfig()->group();
  kapp->getConfig()->setGroup( "KDebug" );
  
  /* The QBitArrays should rather be application-static, but since
         some stupid platforms do not support that... */
  va_list arguments; /* Handle variable arguments */

  /* Determine output */
  short nOutput = 0;
  int nPriority = 0; // for syslog
  QString aCaption;
  QString aAppName = getDescrFromNum(nArea).copy();
  if (aAppName.isEmpty() || aAppName.isNull()) {
    aAppName=kapp->appName().copy();
  }
  switch( nLevel )
        {
        case KDEBUG_INFO:
          nOutput = kapp->getConfig()->readNumEntry( "InfoOutput", 4 );
          aCaption = "Info (" + aAppName.copy() + ")";
          nPriority = LOG_INFO;
          break;
        case KDEBUG_WARN:
          nOutput = kapp->getConfig()->readNumEntry( "WarnOutput", 2 );
          aCaption = "Warning (" + aAppName.copy() + ")";
          nPriority = LOG_WARNING;
          break;
        case KDEBUG_FATAL:
          nOutput = kapp->getConfig()->readNumEntry( "FatalOutput", 2 );
          aCaption = "Fatal Error (" + aAppName.copy() + ")";
          nPriority = LOG_CRIT;
          break;
        case KDEBUG_ERROR:
        default:
          /* Programmer error, use "Error" as default */
          nOutput = kapp->getConfig()->readNumEntry( "ErrorOutput", 2 );
          aCaption = "Error (" + aAppName.copy() + ")";
          nPriority = LOG_ERR;
          break;
        };

  // Output
  switch( nOutput )
        {
        case 0: // File
          {
                QString aOutputFileName;
                switch( nLevel )
                  {
                  case KDEBUG_INFO:
                        aOutputFileName = kapp->getConfig()->readEntry( "InfoFilename",
                                                                                                                        "kdebug.dbg" );
                        break;
                  case KDEBUG_WARN:
                        aOutputFileName = kapp->getConfig()->readEntry( "WarnFilename",
                                                                                                                        "kdebug.dbg" );
                        break;
                  case KDEBUG_FATAL:
                        aOutputFileName = kapp->getConfig()->readEntry( "FatalFilename",
                                                                                                                        "kdebug.dbg" );
                        break;
                  case KDEBUG_ERROR:
                  default:
                        aOutputFileName = kapp->getConfig()->readEntry( "ErrorFilename",
                                                                                                                        "kdebug.dbg" );
                        break;
                  };
                char buf[4096];
                int nPrefix = sprintf( buf, "%s: ", aAppName.data() );
                va_start( arguments, pFormat );
#ifdef HAVE_VSNPRINTF
                // use the more secure version if we have it
                int nSize = vsnprintf( buf, 4095, pFormat, arguments );
#else
                int nSize = vsprintf( buf, pFormat, arguments );
#endif
                if( nSize > (4094-nPrefix) ) nSize = 4094-nPrefix;
                buf[nSize] = '\n';
                buf[nSize+1] = '\0';
                va_end( arguments );
                QFile aOutputFile( aOutputFileName );
                aOutputFile.open( IO_WriteOnly );
                aOutputFile.writeBlock( buf, nSize+2 );
                aOutputFile.close();
                break;
          }
        case 1: // Message Box
          {
                // Since we are in kdecore here, we cannot use KMsgBox and use
                // QMessageBox instead 
                char buf[4096]; // constants are evil, but this is evil code anyway
                va_start( arguments, pFormat );
                int nSize = vsprintf( buf, pFormat, arguments );
                if( nSize > 4094 ) nSize = 4094;
                buf[nSize] = '\n';
                buf[nSize+1] = '\0';
                va_end( arguments );
                QMessageBox::message( aCaption, buf, "OK" );
                break;
          }
        case 2: // Shell
          {
                va_start( arguments, pFormat );
                fprintf( stderr, "%s: ", aAppName.data() );
                vfprintf( stderr, pFormat, arguments );
                fprintf( stderr, "\n" );
                va_end( arguments );
                break;
          }
        case 3: // syslog
          {
                char buf[4096];
                int nPrefix = sprintf( buf, "%s: ", aAppName.data() );
                va_start( arguments, pFormat );
                int nSize = vsprintf( &buf[nPrefix], pFormat, arguments );
                if( nSize > (4094-nPrefix) ) nSize = 4094-nPrefix;
                buf[nSize] = '\n';
                buf[nSize+1] = '\0';
                va_end( arguments );
                syslog( nPriority, buf );
          }       
        case 4: // nothing
          {
          }
        }

  // check if we should abort
  if( ( nLevel == KDEBUG_FATAL ) &&
          ( kapp->getConfig()->readNumEntry( "AbortFatal", 0 ) ) )
        abort();

  // restore old group
  kapp->getConfig()->setGroup( aOldGroup );
#endif
}


KDebugDialog::KDebugDialog() :
  QDialog( 0L, "Debug Settings", true )
{
  pInfoGroup = new QGroupBox( "Information", this );
  pInfoGroup->setGeometry( 5, 10, 140, 185 );
  pInfoGroup->show();
  pInfoLabel1 = new QLabel( "Output to:", this );
  pInfoLabel1->setGeometry( 15, 30, 120, 15 );
  pInfoLabel1->show();
  pInfoCombo = new QComboBox( false, this );
  pInfoCombo->setGeometry( 15, 50, 120, 20 );
  pInfoCombo->insertItem( "File" );
  pInfoCombo->insertItem( "Message Box" );
  pInfoCombo->insertItem( "Shell" );
  pInfoCombo->insertItem( "Syslog" );
  pInfoCombo->insertItem( "None" );
  pInfoCombo->show();
  pInfoLabel2 = new QLabel( "Filename:", this );
  pInfoLabel2->setGeometry( 15, 85, 120, 15 );
  pInfoLabel2->show();
  pInfoFile = new QLineEdit( this );
  pInfoFile->setGeometry( 15, 105, 120, 20 );
  pInfoFile->show();
  pInfoLabel3 = new QLabel( "Show only area(s):", this );
  pInfoLabel3->setGeometry( 15, 140, 120, 15 );
  pInfoLabel3->show();
  pInfoShow = new QLineEdit( this );
  pInfoShow->setGeometry( 15, 160, 120, 20 );
  pInfoShow->show();
  
  pWarnGroup = new QGroupBox( "Warning", this );
  pWarnGroup->setGeometry( 165, 10, 140, 185 );
  pWarnGroup->show();
  pWarnLabel1 = new QLabel( "Output to:", this );
  pWarnLabel1->setGeometry( 175, 30, 120, 15 );
  pWarnLabel1->show();
  pWarnCombo = new QComboBox( false, this );
  pWarnCombo->setGeometry( 175, 50, 120, 20 );
  pWarnCombo->insertItem( "File" );
  pWarnCombo->insertItem( "Message Box" );
  pWarnCombo->insertItem( "Shell" );
  pWarnCombo->insertItem( "Syslog" );
  pWarnCombo->insertItem( "None" );
  pWarnCombo->show();
  pWarnLabel2 = new QLabel( "Filename:", this );
  pWarnLabel2->setGeometry( 175, 85, 120, 15 );
  pWarnLabel2->show();
  pWarnFile = new QLineEdit( this );
  pWarnFile->setGeometry( 175, 105, 120, 20 );
  pWarnFile->show();
  pWarnLabel3 = new QLabel( "Show only area(s):", this );
  pWarnLabel3->setGeometry( 175, 140, 120, 15 );
  pWarnLabel3->show();
  pWarnShow = new QLineEdit( this );
  pWarnShow->setGeometry( 175, 160, 120, 20 );
  pWarnShow->show();

  pErrorGroup = new QGroupBox( "Error", this );
  pErrorGroup->setGeometry( 5, 215, 140, 185 );
  pErrorGroup->show();
  pErrorLabel1 = new QLabel( "Output to:", this );
  pErrorLabel1->setGeometry( 15, 235, 120, 15 );
  pErrorLabel1->show();
  pErrorCombo = new QComboBox( false, this );
  pErrorCombo->setGeometry( 15, 255, 120, 20 );
  pErrorCombo->insertItem( "File" );
  pErrorCombo->insertItem( "Message Box" );
  pErrorCombo->insertItem( "Shell" );
  pErrorCombo->insertItem( "Syslog" );
  pErrorCombo->insertItem( "None" );
  pErrorCombo->show();
  pErrorLabel2 = new QLabel( "Filename:", this );
  pErrorLabel2->setGeometry( 15, 290, 120, 15 );
  pErrorLabel2->show();
  pErrorFile = new QLineEdit( this );
  pErrorFile->setGeometry( 15, 310, 120, 20 );
  pErrorFile->show();
  pErrorLabel3 = new QLabel( "Show only area(s):", this );
  pErrorLabel3->setGeometry( 15, 345, 120, 15 );
  pErrorLabel3->show();
  pErrorShow = new QLineEdit( this );
  pErrorShow->setGeometry( 15, 365, 120, 20 );
  pErrorShow->show();

  pFatalGroup = new QGroupBox( "Fatal error", this );
  pFatalGroup->setGeometry( 165, 215, 140, 185 );
  pFatalGroup->show();
  pFatalLabel1 = new QLabel( "Output to:", this );
  pFatalLabel1->setGeometry( 175, 235, 120, 15 );
  pFatalLabel1->show();
  pFatalCombo = new QComboBox( false, this );
  pFatalCombo->setGeometry( 175, 255, 120, 20 );
  pFatalCombo->insertItem( "File" );
  pFatalCombo->insertItem( "Message Box" );
  pFatalCombo->insertItem( "Shell" );
  pFatalCombo->insertItem( "Syslog" );
  pFatalCombo->insertItem( "None" );
  pFatalCombo->show();
  pFatalLabel2 = new QLabel( "Filename:", this );
  pFatalLabel2->setGeometry( 175, 290, 120, 15 );
  pFatalLabel2->show();
  pFatalFile = new QLineEdit( this );
  pFatalFile->setGeometry( 175, 310, 100, 20 );
  pFatalFile->show();
  pFatalLabel3 = new QLabel( "Show only area(s):", this );
  pFatalLabel3->setGeometry( 175, 345, 120, 15 );
  pFatalLabel3->show();
  pFatalShow = new QLineEdit( this );
  pFatalShow->setGeometry( 175, 365, 120, 20 );
  pFatalShow->show();

  pAbortFatal = new QCheckBox( "Abort on fatal errors", this );
  pAbortFatal->setGeometry( 15, 420, 200, 15 );
  pAbortFatal->show();
  pOKButton = new QPushButton( "OK", this );
  pOKButton->setGeometry( 15, 460, 80, 20 );
  pOKButton->setDefault( true );
  pOKButton->show();
  connect( pOKButton, SIGNAL( clicked() ), SLOT( accept() ) );
  pCancelButton = new QPushButton( "Cancel", this );
  pCancelButton->setGeometry( 110, 460, 80, 20 );
  pCancelButton->show();
  connect( pCancelButton, SIGNAL( clicked() ), SLOT( reject() ) );
  pHelpButton = new QPushButton( "Help", this );
  pHelpButton->setGeometry( 205, 460, 80, 20 );
  pHelpButton->show();
  connect( pHelpButton, SIGNAL( clicked() ), SLOT( showHelp() ) );
}

KDebugDialog::~KDebugDialog()
{
  delete pInfoGroup;
  delete pInfoLabel1;
  delete pInfoCombo;
  delete pInfoLabel2;
  delete pInfoFile;
  delete pInfoLabel3;
  delete pInfoShow;
  delete pWarnGroup;
  delete pWarnLabel1;
  delete pWarnCombo;
  delete pWarnLabel2;
  delete pWarnFile;
  delete pWarnLabel3;
  delete pWarnShow;
  delete pErrorGroup;
  delete pErrorLabel1;
  delete pErrorCombo;
  delete pErrorLabel2;
  delete pErrorFile;
  delete pErrorLabel3;
  delete pErrorShow;
  delete pFatalGroup;
  delete pFatalLabel1;
  delete pFatalCombo;
  delete pFatalLabel2;
  delete pFatalFile;
  delete pFatalLabel3;
  delete pFatalShow;
  delete pAbortFatal;
  delete pOKButton;
  delete pCancelButton;
  delete pHelpButton;
}


void KDebugDialog::showHelp()
{
  kapp->invokeHTMLHelp( "kdelibs/kdebug.html", "" );
}

#include "kdebugdialog.moc"


--- NEW FILE: ksimpleconfig.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: ksimpleconfig.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
//
// $Log: ksimpleconfig.h,v $
// Revision 1.1  2006-10-03 11:26:27  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:05  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:59  jasonk
// Initial import of ViewML
//
// Revision 1.6  1998/01/18 14:39:02  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.4  1998/01/15 13:22:31  kalle
// Read-only mode for KSimpleConfig
//
// Revision 1.3  1997/10/16 11:15:02  torben
// Kalle: Copyright headers
// kdoctoolbar removed
//
// Revision 1.2  1997/10/08 19:28:53  kalle
// KSimpleConfig implemented
//
// Revision 1.1  1997/10/04 19:51:07  kalle
// new KConfig
//

#ifndef _KSIMPLECONFIG_H
#define _KSIMPLECONFIG_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kconfigbase.h>

/** 
* KDE Configuration entries
*
* This is a trivial implementation of KConfigBase for applications
* that need only one configuration file and no default system.
*
* @author Kalle Dalheimer (kalle at kde.org)
* @version $Id: ksimpleconfig.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
* @see KApplication::getConfig KConfigBase KConfig
* @short KDE Configuration Management class
*/
class KSimpleConfig : public KConfigBase
{
  Q_OBJECT 

  // copy-construction and assignment are not allowed
  KSimpleConfig( const KSimpleConfig& );
  KSimpleConfig& operator= ( const KSimpleConfig& rConfig );

protected:
  /** Open all appropriate configuration files and pass them on to
	* parseOneConfigFile()
	*/
  virtual void parseConfigFiles();

public:
  /** 
	* Construct a read-write KSimpleConfig object. 
	*
	* @param pfile The file used for saving the config data.
	*/
  KSimpleConfig( const char* pFile );

  /**
	* Construct a KSimpleConfig object and make it either read-write
	* or read-only.  
	*
	* @param pFile The file uses for saving the config data.
	*        bReadOnly Whether the object should be read-only.
	*/
  KSimpleConfig( const char* pFile, bool bReadOnly );

  /** 
	* Destructor. 
	*
	* Writes back any dirty configuration entries.
	*/
  virtual ~KSimpleConfig();

  
  /**
	* Returns true if the object is read-only
	*
	*/
  bool isReadOnly() const { return data()->bReadOnly; }

  /**
   * Write back the cache.
   *
   */
  virtual void sync();

  /** Write back the configuration data.
	*/
  bool writeConfigFile( QFile& rFile, bool bGlobal = false );

  /**
	* Delete a configuration entry.
	*
	* @param pKey The key of the entry to delete
	* @param bLocalized Whether the localized or the non-localized key should
	*                    be deleted
	* @return The old value of that key.
	*/
  const QString deleteEntry( const char* pKey, bool bLocalized );

  /**
	* Delete a configuration entry group
	*
	* If the group is not empty and bDeep is false, nothing gets
	* deleted and false is returned.
	* If this group is the current group and it is deleted, the
	* current group is undefined and should be set with setGroup()
	* before the next operation on the configuration object.
	*
	* @param pGroup The name of the group
	* @param bDeep Whether non-empty groups should be completely
	* deleted (including their entries)
	* @return If the group does not exist or is not empty and bDeep is
	* false, deleteGroup returns false.
	*/
  bool deleteGroup( const char* pGroup, bool bDeep = true );
};
  

 
#endif

--- NEW FILE: kaccel.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Mark Donohoe <donohoe at kde.org>
    Copyright (C) 1997 Nicolas Hadacek <hadacek at via.ecp.fr>
    Copyright (C) 1998 Matthias Ettrich <ettrich at kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef _KACCEL_H
#define _KACCEL_H

#include <qdict.h>
#include <qaccel.h>
#include <qpopupmenu.h>

#include <kconfig.h>

#include "kckey.h"

/**
 * Returns the key code corresponding to the string sKey or zero if the string
 * is not recognized. The string must be something like "SHIFT+A",
 * "F1+CTRL+ALT" or "Backspace" for example. That is, a key plus a combination
 * of SHIFT, CTRL and ALT.
 */	
uint stringToKey( const char * sKey );

/**
 * Returns a string corresponding to the key code keyCode, which is empty if
 * keyCode is not recognized or zero.
 */
const QString keyToString( uint keyCode, bool i18_n = false );

struct KKeyEntry {
	uint aCurrentKeyCode, aDefaultKeyCode, aConfigKeyCode;
	bool bConfigurable;
	bool bEnabled;
	int aAccelId;
	const QObject *receiver;
	QString member;
	QString descr;	
};

/**
 * The KAccel class handles keyboard accelerators, allowing a user to configure
 * key bindings through application configuration files or through the
 * KKeyChooser GUI.
 *
 * A KAccel contains a list of accelerator items. Each accelerator item
 * consists of an action name and a keyboard code combined with modifiers
 * (SHIFT, CTRL and ALT.)
 *
 * For example, "CTRL+P" could be a shortcut for printing a document. The key
 * codes are listed in ckey.h. "Print" could be the action name for printing.
 * The action name indentifies the key binding in configuration files and the
 * KKeyChooser GUI.
 *
 * When pressed, an accelerator key calls the slot to which it has been
 * connected. Accelerator items can be connected so that a key will activate
 * two different slots.
 *
 * A KAccel object handles key events to its parent widget and all children
 * of this parent widget.
 *
 * Key binding configuration during run time can be prevented by specifying
 * that an accelerator item is not configurable when it is inserted. A special
 * group of non-configurable key bindings are known as the standard accelerators.
 *
 * The standard accelerators appear repeatedly in applications for
 * standard document actions like printing and saving. Convenience methods are
 * available to insert and connect these accelerators which are configurable on
 * a desktop-wide basis.
 *
 * It is possible for a user to choose to have no key associated with an action.
 *
 * The translated first argument for insertItem is only used in the
 * configuration dialog.
 *<pre>
 * KAccel *a = new KAccel( myWindow );
 * a->insertItem( i18n("Scroll up"), "Scroll Up", "Up" );
 * a->connectItem( "Scroll up", myWindow, SLOT( scrollUp() ) );
 * // a->insertStdItem( KAccel::Print ); //not necessary, since it
 	// is done automatially with the
 	// connect below!
 * a->connectItem(KAccel::Print, myWindow, SLOT( printDoc() ) );
 *
 * a->readSettings();
 *</pre>
 *
 * If a shortcut has a menu entry as well, you could insert them like
 * this. The example is again the KAccel::Print from above.

 <pre>
 * int id;
 * id = popup->insertItem("&Print",this, SLOT(printDoc()));
 * a->changeMenuAccel(popup, id, KAccel::Print );
 </pre>
 *
 * If you want a somewhat "exotic" name for your standard print action, like
 *   id = popup->insertItem(i18n("Print &Document"),this, SLOT(printDoc()));
 * it might be a good idea to insert the standard action before as
 *          a->insertStdItem( KAccel::Print, i18n("Print Document") )
 * as well, so that the user can easily find the corresponding function.
 *
 * This technique works for other actions as well, your scroll up function
 * in a menu could be done with
 *
 <pre>
 *    id = popup->insertItem(i18n"Scroll &up",this, SLOT(scrollUp()));
 *    a->changeMenuAccel(popup, id, "Scroll Up" );
 </pre>
 *
 * Please keep the order right: first insert all functions in the
 * acceleratior, then call a->readSettings() and _then_ build your
 * menu structure.

 * @short Configurable key binding support.
 * @version $Id: kaccel.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
 */
class KAccel
{
 public:
 	enum StdAccel { Open=1, New, Close, Save, Print, Quit, Cut, Copy,
		Paste, Undo, Find, Replace, Insert, Home, End, Prior,
		Next, Help };
	/**
	 * Creates a KAccel object with a parent widget and a name.
	 */
	KAccel( QWidget * parent, const char * name = 0 );
			
	/**
	 * Destroys the accelerator object.
	 */
	~KAccel();
	
	/**
	 * Removes all accelerator items.
	 */
	void clear();
	
	/**
	 * Connect an accelerator item to a slot/signal in another object.
	 *
	 * Arguments:
	 *
	 *  @param action the accelerator item action name.
	 *  @param receiver the object to receive a signal
	 *  @param member a slot or signal in the receiver
	 *  @param activate indicates whether the accelerator item should be
	 *  enabled immediately
	 */
	void connectItem( const char * action,
			  const QObject* receiver, const char* member,
			  bool activate = TRUE );


	/**
	 * Same as connectItem from above, but for standard accelerators.
	 * If the standard accelerator was not inserted so far, it will be inserted
	 * automatically.
	 */
	void connectItem( StdAccel accel,
			  const QObject* receiver, const char* member,
			  bool activate = TRUE );

	/**
	* Returns the number of accelerator items.
	*/					
	uint count() const;
	
	/**
	* Returns the key code of the accelerator item with the action name
	* action, or zero if either the action name cannot be found or the current
	* key is set to no key.
	*/
	uint currentKey( const char * action );

	/**
	* Returns the description  of the accelerator item with the action name
	* action, or zero if the action name cannot be found. Useful for menus.
	*/
	const char*  description( const char * action );

	/**
	* Returns the default key code of the accelerator item with the action name
	* action, or zero if the action name cannot be found.
	*/
	uint defaultKey( const char * action);
	
	/**
	 * Disconnects an accelerator item from a function in another object.
	 */
	void disconnectItem( const char * action,
							const QObject* receiver, const char* member );
	
	/**
	 * Returns that identifier of the accelerator item with the keycode key,
	 * or zero if the item cannot be found.
	 */
	const char *findKey( int key ) const;
	
	/**
	 * Inserts an accelerator item and returns -1 if the key code
	 * 	defaultKeyCode is not valid.
	 *	
	 * Arguments:
	 *
	 *  @param descr is the localized name of the action, useful in menus or the keybinding
	 *            editor.
	 *  @param action is the internal accelerator item action name. It is supposed to be the same
	 *            for all language.
	 *  @param defaultKeyCode is a key code to be used as the default for the action.
	 *  @param configurable indicates whether a user can configure the key
	 *	binding using the KKeyChooser GUI and whether the key will be written
	 *	back to configuration files on calling writeSettings.
	 *
	 * If an action already exists the old association and connections will be
	 * removed..
	 * 	
	 */
	bool insertItem( const char* descr, const char * action, uint defaultKeyCode,
				 bool configurable = TRUE );
	
	 /**
	 * Inserts an accelerator item and returns -1 if the key code
	 * 	defaultKeyCode is not valid.
	 *	
	 * Arguments:
	 *
	 *  @param descr is the localized name of the action, useful in
	 *  menus or the keybinding
	 *	      editor.
	 *  @param action is the internal accelerator item action name. It
	 *  is supposed to be the same for all language.
	 *  @param defaultKeyCode is a key plus a combination of SHIFT, CTRL
	 *	and ALT to be used as the default for the action.
	 *  @param configurable indicates whether a user can configure
	 *  the key
	 *	binding using the KKeyChooser GUI and whether the key
	 *	will be written back to configuration files on calling
	 *	writeSettings.

	 * If an action already exists the old association and connections
	 * will be removed..
	 */
	bool insertItem( const char* descr, const char * action, const char * defaultKeyCode,
				 bool configurable = TRUE );
				
	/**
	 *	Inserts a standard accelerator item if id equal to Open,
	 *	New, Close, Save, Print, Quit, Cut, Copy, Paste, Undo,
	 *	Find, Replace, Insert, Home, End, Prior, Next, or Help.

	 * If an action already exists the old association and connections
	 * will be removed..

	 * You can (optional) also assign a description to the standard
	 * item which may be used a in a popup menu.
	 */
	bool insertStdItem( StdAccel id, const char* descr = 0 );


	/**
	 * Convenience function without the need to specify a
	 * localized function name for the user. This is useful if the accelerator is
	 * only used internally, without appearing in a menu or a keybinding editor.
	 */
	bool insertItem( const char * action, uint defaultKeyCode,
				 bool configurable = TRUE );


	/**
	 * Often (usually?) shortcuts should be visible in the menu
	 * structure of an application. Use this function for that
	 * purpose.  Note that the action must have been inserted
	 * before!
	 */

	void changeMenuAccel ( QPopupMenu *menu, int id,
			       const char* action );
	/**
	 * Same as changeMenuAccel but for standard accelerators
	 */
	void changeMenuAccel ( QPopupMenu *menu, int id,
				 StdAccel accel );


	bool isEnabled();
	bool isItemEnabled( const char *action );
				
	/**
	 * Returns the dictionary of accelerator action names and KKeyEntry
	 * objects. Note that only a shallow copy is returned so that
	 * items will be lost when the KKeyEntry objects are deleted.
	 */
	QDict<KKeyEntry> keyDict();
				
	/**
	 * Reads all key associations from the application's configuration
	 * files.
	 */	
	void readSettings(KConfig* config = 0);
		
 	/**
	 * Removes the accelerator item with the action name action.
	 */
	void removeItem( const char * action );

	void setConfigGroup( const char *group );
	void setConfigGlobal( bool global );
	
	const char * configGroup();
	bool configGlobal();
	
	/**
	 * Enables the accelerator if activate is TRUE, or disables it if
	 * activate is FALSE..
	 *
	 * Individual keys can also be enabled or disabled.
	 */
	void setEnabled( bool activate );
	
	/**
	 * Enables or disables an accelerator item.
	 *
	 * Arguments:
	 *
	 * @param action is the accelerator item action name.
	 * @param activate specifies whether the item should be enabled or
	 *	disabled.
	 */
	void setItemEnabled( const char * action, bool activate );
	
	/**
	* Sets the dictionary of accelerator action names and KKeyEntry
	* objects to nKeyDict.. Note that only a shallow copy is made so
	* that items will be lost when the KKeyEntry objects are deleted.
	*/	
	bool setKeyDict( QDict<KKeyEntry> nKeyDict );
	
	/**
	 *	Returns a standard action name if id equal to Open,
	 *	New, Close, Save, Print, Quit, Cut, Copy, Paste, Undo,
	 *	Find, Replace, Insert, Home, End, Prior, Next, or Help
	 *	and zero otherwise.
	 */
	static const char *stdAction( StdAccel id );

	/**
	 * Writes the current configurable associations to the application's
	 * configuration files
	 */	
	void writeSettings(KConfig* config = 0);
	
protected:
 	QAccel *pAccel;
	int aAvailableId;
	QDict<KKeyEntry> aKeyDict;
	bool bEnabled;
	bool bGlobal;
	QString aGroup;
	

};
	
#endif

--- NEW FILE: kdebug.areas ---
#This is a dummy kdebug.areas
#when you get a set of KDebug areas, and various descriptions for them
#please email kde at kde.org with the appropiate descriptions.
0	generic
750	kspell (kdelibs)
125	kaccel (kdecore)
1201	kfm (kdebase)
1300	kfm (kioslave)
1501	khexedit (kdeutils)
1901	kfind (kdebase)
1902	kfind (KfindWindow::updateResults)
1903	kfind (KfindTabDialog::createQuery)
2000	kfind (kdebase)

# 30001-65534 are for KOffice
30001 koffice
31000 koffice
31001 kxcl
32000 kxcl
32001 kword
33000 kword
33001 kpresenter
34000 kpresenter
34001 klyx
35000 klyx
35001 kchart
36000 kchart

--- NEW FILE: kglobalaccel.h ---
/* This file is part of the KDE libraries
   Copyright (C) 1997 Mark Donohoe <donohoe at kde.org>
   Copyright (C) 1997 Nicolas Hadacek <hadacek at via.ecp.fr>
   Copyright (C) 1998 Matthias Ettrich <ettrich at kde.org>

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Library General Public
	License as published by the Free Software Foundation; either
	version 2 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Library General Public License for more details.

	You should have received a copy of the GNU Library General Public License
	along with this library; see the file COPYING.LIB.  If not, write to
	the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
	Boston, MA 02111-1307, USA.
*/

#ifndef _KGLOBALACCEL_H_
#define _KGLOBALACCEL_H_

#include <kapp.h>
#include <qobject.h>
#include "kaccel.h"

/**
 * Returns the X key modifier for the key code keyCode.
 */	
uint keyToXMod( uint keyCode );

/**
 * Returns the X key sym for the key code keyCode.
 */	
uint keyToXSym( uint keyCode );

/**
 * The KGlobalAccel class handles global keyboard accelerators, allowing a
 * user to configure key bindings through application configuration files or
 * through the KKeyChooser GUI.
 *
 * A KGlobalAccel contains a list of accelerator items. Each accelerator item
 * consists of an action name and a keyboard code combined with modifiers
 * (SHIFT, CTRL and ALT.)
 *
 * For example, "CTRL+SHIFT+M" could be a shortcut for popping-up a menu of
 * monitor setting choices anywhere on the desktop. The key codes are listed
 * in ckey.h. "Monitor settings" could be the action name for this
 * accelerator. The action name indentifies the key binding in configuration
 * files and the KKeyChooser GUI.
 *
 * When pressed,an accelerator key calls the slot to which it has been
 * connected. Accelerator items can be connected so that a key will activate
 * two different slots.
 *
 * KApplication::x11EventFilter must be re-implemented to call
 * KAccel::x11EventFilter so that a KAccel object can handle all key events.
 *
 * Key binding configuration during run time can be prevented by specifying
 * that an accelerator item is not configurable when it is inserted.
 *
 * It is possible for a user to choose to have no key associated with an action.
 *
 *
 * The translated first argument for insertItem is only used in the
 * configuration dialog.
 *
 * MyApp::x11EventFilter( XEvent *ev ) {
 * if ( myObject->ga->x11EventFilter( ev ) )
 *		return true;
 * }
 *
 * ...
 *
 * ga = new KGlobalAccel();
 * ga->insertItem( i18n("Monitor settings"), "Monitor settings", "CTRL+SHIFT+M" );
 * ga->connectItem( "Monitor settings", myObject, SLOT( popupMenu() ) );
 *
 * ga->readSettings();
 *
 */
class KGlobalAccel : public QObject
{
	Q_OBJECT
	
 public:
	/**
	 * Creates a KGlobalAccel object.
	 */
	KGlobalAccel( bool _do_not_grab = false);
			
	/**
	   Creates a KGlobalAccel object with a parent and a name. The
	   parent has the only effect that the KGlobalAccel object
	   will be automatically destroyed in the parent's destructor,
	   thus releaseing the keys.
	*/
	KGlobalAccel(QWidget * parent, const char * name = 0, bool _do_not_grab = false);

    
	/**
	 * Destroys the accelerator object.and ungrabs any allocated key bindings.
	 */
	~KGlobalAccel();
	
	/**
	 * Removes all accelerator items.
	 */
	void clear();
	
	/**
	 * Connect an accelerator item to a slot/signal in another object.
	 *
	 * Arguments:
	 *
	 *  @param action is the accelerator item action name.
	 *  @param receiver is the object to receive a signal
	 *  @param member is a slot or signal in the receiver
	 *  @param activate indicates whether the accelrator item should be
	 *  enabled immediately
	 */
	void connectItem( const char * action,
						  const QObject* receiver, const char* member,
						  bool activate = TRUE );
						
	/**
	* Returns the number of accelerator items.
	*/					
	uint count() const;
	
	/**
	* Returns the key code of the accelerator item with the action name
	* action, or zero if either the action name cannot be found or the current
	* key is set to no key.
	*/
	uint currentKey( const char * action );

	/**
	* Returns the default key code of the accelerator item with the action name
	* action, or zero if the action name cannot be found.
	*/
	uint defaultKey( const char * action);
	
	/**
	 * Disconnects an accelerator item from a function in another object.
	 */
	void disconnectItem( const char * action,
							const QObject* receiver, const char* member );
	
	/**
	 * Returns that identifier of the accelerator item with the keycode key,
	 * or zero if the item cannot be found.
	 */
	const char *findKey( int key ) const;
	
	/**
	 * Attempts to make a passive X server grab of the key specified by key symbol
	 * keysym and modifier mod. Returns false if unsuccessful.
	 *
	 * Modifications with num lock and caps lock are also grabbed.
	 *
	 */
	bool grabKey(uint keysym, uint mod);
	
	/**
	 * Inserts an accelerator item and returns false if the key code
	 * 	defaultKeyCode is not valid.
	 *	
	 * Arguments:
	 *
	 *  @param action is the accelerator item action name.
	 *  @param defaultKeyCode is a key code to be used as the default for the action.
	 *  @param configurable indicates whether a user can configure the key
	 *	binding using the KKeyChooser GUI and whether the key will be written
	 *	back to configuration files on calling writeSettings.
	 *
	 * If an action already exists the old association and connections will be
	 * removed..
	 * 	
	 */
	bool insertItem( const char* descr, const char * action, uint defaultKeyCode,
				 bool configurable = TRUE );
	
	 /**
	 * Inserts an accelerator item and returns false if the key code
	 * 	defaultKeyCode is not valid.
	 *	
	 * Arguments:
	 *
	 *  @param action is the accelerator item action name.
	 *  @param defaultKeyCode is a key plus a combination of SHIFT, CTRL
	 *	and ALT to be used as the default for the action.
	 *  @param configurable indicates whether a user can configure
	 *  the key
	 *	binding using the KKeyChooser GUI and whether the key
	 *	will be written back to configuration files on calling
	 *	writeSettings.
	 *
	 * If an action already exists the old association and connections
	 * will be removed..

	 */
	bool insertItem( const char* descr, const char * action, const char * defaultKeyCode,
				 bool configurable = TRUE );
	
	bool isEnabled();
	bool isItemEnabled( const char *action );
	
	/**
	* Returns the dictionary of accelerator action names and KKeyEntry
	* objects. Note that only a shallow copy is returned so that
	* items will be lost when the KKeyEntry objects are deleted.
	*/	
	QDict<KKeyEntry> keyDict();
				
	/**
	 * Reads all key associations from the application's configuration
	 * files.
	 */
	void readSettings();
		
 	/**
	 * Removes the accelerator item with the action name action.
	 */
    void removeItem( const char * action );
	
	void setConfigGroup( const char *group );
	
	const char * configGroup();
	
	/**
	 * Enables the accelerator if activate is TRUE, or disables it if
	 * activate is FALSE..
	 *
	 * Individual keys can also be enabled or disabled.
	 */
	void setEnabled( bool activate );
	
	/**
	 * Enables or disables an accelerator item.
	 *
	 * Arguments:
	 *
	 *  @param action is the accelerator item action name.
	 *	@param activate specifies whether the item should be enabled or
	 *	disabled.
	 */
	void setItemEnabled( const char * action, bool activate );
	
	/**
	* Sets the dictionary of accelerator action names and KKeyEntry
	* objects to nKeyDict.. Note that only a shallow copy is made so that items will be
	* lost when the KKeyEntry objects are deleted.
	*/	
	bool setKeyDict( QDict<KKeyEntry> nKeyDict );
	
	/**
	 * Ungrabs the key specified by key symbol
	 * keysym and modifier mod. Returns false if unsuccessful.
	 *
	 * Modifications with num lock and caps lock are also ungrabbed.
	 *
	 */
	bool ungrabKey(uint keysym, uint mod);

	/**
	 * Writes the current configurable associations to the application's
	 * configuration files
	 */	
	void writeSettings();
	
	/**
	 * Filters X11 events ev for key bindings in the accelerator dictionary.
	 * If a match is found the activated activated is emitted and the function
	 * returns true. Return false if the event is not processed.
	 */
	bool x11EventFilter(const XEvent *);
	
signals:
	void activated();	

protected:
	int aAvailableId;
	QDict<KKeyEntry> aKeyDict;
	bool bEnabled;
	QString aGroup;
	bool do_not_grab;

 protected:
};

#endif // _KGLOBALACCEL_H_

--- NEW FILE: kwm.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Ettrich (ettrich at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
/*
[...1177 lines suppressed...]

bool KWM::isDockWindow(Window w){
  static Atom a = 0;
  if (!a)
    a = XInternAtom(qt_xdisplay(), "KWM_DOCKWINDOW", False);
  long result = 0;
  getSimpleProperty(w, a, result);
  return result != 0;
}

int KWM::getWindowState(Window w){
  static Atom a = 0;
  if (!a)
    a = XInternAtom(qt_xdisplay(), "WM_STATE", False);
  long result = WithdrawnState;
  getSimpleProperty(w, a, result);
  return (int) result;
}



--- NEW FILE: kcharsetsdata.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Jacek Konieczny (jajcus at zeus.polsl.gliwice.pl)
    $Id: kcharsetsdata.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
	*/

#ifndef _CHARSETSDATA_H
#define _CHARSETSDATA_H

//#define KCH_DEBUG

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <qfont.h>

#include <qdict.h>
#include <qlist.h>
#include <qintdict.h>
#include <kcharsets.h>

/**
* Charset internal structure.
* @internal
*/
struct KCharsetEntry{
  char *name;
  QFont::CharSet qtCharset;
  const unsigned *toUnicode;
  bool registered;
  QIntDict<unsigned> * toUnicodeDict;
  QString *good_family;  /* it must be pointer so charset entries can be compiled-in */
};

class KCharsetsData;


class KCharsetConverterData{
friend class KCharsets;
   static KCharsetsData *kcharsetsData;
   bool inAmps,outAmps;
   bool unicodeIn,unicodeOut;
   enum{
   	NoConversion,
 	ToUnicode,
     	FromUnicode,
     	UnicodeUnicode,
	EightToEight,
	Optimal
   }conversionType;
   enum Encoding{
        none,
        UTF7,
	UTF8
   }inputEnc,outputEnc;
   int inBits;
   int outBits;
   
   QIntDict<unsigned> *convToUniDict;
   QIntDict<unsigned> *convFromUniDict;
   const unsigned *convTable;
   
   const KCharsetEntry * input;
   const KCharsetEntry * output;
   bool isOK;

   KCharsetConversionResult *tempResult;

   void setInputSettings();
   void setOutputSettings();
   bool getToUnicodeTable();
   bool createFromUnicodeDict();
   bool decodeUTF7(const char*,unsigned int &code,int &extrachars);
   bool decodeUTF8(const char*,unsigned int &code,int &extrachars);
   bool encodeUTF7(unsigned int code,QString &result);
   bool encodeUTF8(unsigned int code,QString &result);
   bool createFromUnicodeTable();
   const char * convert(const char *str,KCharsetConversionResult &r
                       ,unsigned *pUnicode);
   bool initialize(const KCharsetEntry* inputCharset,
                   const KCharsetEntry * outputCharset);
public:
   KCharsetConverterData(const KCharsetEntry * inputCharset
                         ,const KCharsetEntry * outputCharset
                         ,int flags);
   KCharsetConverterData(const KCharsetEntry * inputCharset
                         ,int flags);
   ~KCharsetConverterData();
   void convert(const char *str,KCharsetConversionResult &r);
   void convert(const char *str){
     convert(str,*tempResult);
   }
   void convert(const char *str,QList<KCharsetConversionResult> &r);
   const KCharsetConversionResult & convert(unsigned code);
   const KCharsetConversionResult & convertTag(const char *tag,int &len);
   const char * outputCharset()const;
   bool ok()const{ return isOK; }

private:
  // Disallow assignment and copy-construction
  KCharsetConverterData( const KCharsetConverterData& ) {};
  KCharsetConverterData& operator= ( const KCharsetConverterData& ) { return *this; }
};

/**
* Charset support structure.
* @internal
*/
struct KCharTags{
  const char *tag;
  unsigned code;
};

#define CHAR_TAGS_COUNT (nrOfTags) 

class KSimpleConfig;

/**
* Charset support structure.
* @internal
*/
struct KDispCharEntry{
  KCharsetEntry *charset;
  unsigned code;
};
    
class KCharsetsData{
  static KCharsetEntry charsets[];
  QDict<KCharsetEntry> aliases;
  QDict<KCharsetEntry> i18nCharsets;
  QIntDict<KDispCharEntry> *displayableCharsDict;
  const KCharsetEntry * defaultCh;
  KSimpleConfig *config;
  void scanDirectory(const char *path);
  void createDictFromi18n(KCharsetEntry *e);
  KCharsetEntry * varCharsetEntry(const char *name);
  KCharsetConversionResult *tempResult;
public:
  static const KCharTags tags[];
  static const unsigned int nrOfTags;
  KCharsetsData();
  ~KCharsetsData();
  const char *faceForCharset(const KCharsetEntry *charset);
  QString charsetFace(const KCharsetEntry *charset,const QString &face);
  bool charsetOfFace(const KCharsetEntry *charset,const QString &face);
  const KCharsetEntry * charsetOfFace(const QString &face);
  const KCharsetEntry * charsetEntry(const char *name){
    return varCharsetEntry(name);
  }
  const KCharsetEntry * charsetEntry(int index);
  const KCharsetEntry * charsetEntry(QFont::CharSet);
  const KCharsetEntry * defaultCharset()const
                 { return defaultCh; }
  bool setDefaultCharset(const KCharsetEntry *charset);
  const unsigned *getToUnicodeTable(const  KCharsetEntry *charset);
  QIntDict<unsigned> *getToUnicodeDict(const KCharsetEntry *charset);
  const KCharsetEntry * conversionHint(const KCharsetEntry *charset);
  bool getFontList(QStrList *lst,QString xcharsetlist);
  bool isDisplayableHack(KCharsetEntry *charset);
  bool isDisplayable(KCharsetEntry * charset);
  unsigned decodeAmp(const char *seq,int &len);
  void convert(unsigned code,KCharsetConversionResult & r);
  KCharsetConversionResult & convert(unsigned code){
     convert(code,*tempResult);
     return *tempResult;
  }
  void convertTag(const char *tag,KCharsetConversionResult & r,int &l);
  KCharsetConversionResult & convertTag(const char *tag,int &l){
    convertTag(tag,*tempResult,l);
    return *tempResult;
  }
  QString fromX(QString name);
  QString toX(QString name);
  const QIntDict<KDispCharEntry> * getDisplayableDict();

private:
  // Disallow assignment and copy-construction
  KCharsetsData( const KCharsetsData& ) {};
  KCharsetsData& operator= ( const KCharsetsData& ) { return *this; }
};

#ifdef KCH_DEBUG
void kchdebug(const char *msg,...);
#else /* KCH_DEBUG */
inline void kchdebug(const char *,...){}
#endif /* KCH_DEBUG */

#endif

--- NEW FILE: dither.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Martin Jones (mjones at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
//-----------------------------------------------------------------------------
//
// Floyd-Steinberg dithering
// Ref: Bitmapped Graphics Programming in C++
//      Marv Luse, Addison-Wesley Publishing, 1993.
//

#ifndef __DITHER_H__
#define __DITHER_H__

#include <qimage.h>

/**
* Allows Floyd-Steinberg dithering for low-colour situations.
* @short Floyd-Steinberg dithering.
* @version $Id: dither.h,v 1.1 2006-10-03 11:26:25 dslinux_amadeus Exp $
* @author Marv Luse (tm Addison Wesley Publishing)
*/
class kFSDither
{
public:
	/**
	*/
	kFSDither( const QColor *pal, int pSize );

	/**
	*/
	QImage dither( const QImage &i );

private:
	/**
	*/
	int nearestColor( int r, int g, int b );

private:
	/**
	*/
	const QColor *palette;
	/**
	*/
	int palSize;
};

#endif	// __DITHER_H__


--- NEW FILE: kglobalaccel.cpp ---
/* This file is part of the KDE libraries
	Copyright (C) 1998 	Mark Donohoe <donohoe at kde.org>,
	Jani Jaakkola (jjaakkol at cs.helsinki.fi),
	Nicolas Hadacek <hadacek at via.ecp.fr>
	Matthias Ettrich (ettrich at kde.org)

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Library General Public
	License as published by the Free Software Foundation; either
	version 2 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Library General Public License for more details.

	You should have received a copy of the GNU Library General Public License
	along with this library; see the file COPYING.LIB.  If not, write to
	the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
	Boston, MA 02111-1307, USA.
*/

#include "kglobalaccel.h"
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <string.h>

#include <qkeycode.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qapplication.h>
#include <qdrawutil.h>
#include <qmessagebox.h>

#include <kapp.h>

// NOTE ABOUT CONFIGURATION CHANGES
// Test if keys enabled because these keys have made X server grabs

KGlobalAccel::KGlobalAccel(bool _do_not_grab)
 : QObject(), aKeyDict(100)
{
	aAvailableId = 1;
	bEnabled = true;
	aGroup = "Global Keys";
	do_not_grab =_do_not_grab;
}

KGlobalAccel::KGlobalAccel(QWidget * parent, const char * name, bool _do_not_grab)
    : QObject(parent, name), aKeyDict(100) {
    	aAvailableId = 1;
	bEnabled = true;
	aGroup = "Global Keys";
	do_not_grab =_do_not_grab;

}

KGlobalAccel::~KGlobalAccel()
{
	setEnabled( false );
}

void KGlobalAccel::clear()
{
	setEnabled( false );
	aKeyDict.clear();
}

void KGlobalAccel::connectItem( const char * action,
				const QObject* receiver, const char* member,
				bool activate )
{
    KKeyEntry *pEntry = aKeyDict[ action ];
	if ( !pEntry ) {
		QString str;
		str.sprintf(
			"KGlobalAccel : Cannot connect action %s"\
			"which is not in the object dictionary", action );
		warning( str );
		return;
	}
	
	pEntry->receiver = receiver;
	pEntry->member = member;
	pEntry->aAccelId = aAvailableId;
	aAvailableId++;
	
	setItemEnabled( action, activate );

}

uint KGlobalAccel::count() const
{
	return aKeyDict.count();
}

uint KGlobalAccel::currentKey( const char * action )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( !pEntry )
		return 0;
	else
		return pEntry->aCurrentKeyCode;
}

uint KGlobalAccel::defaultKey( const char * action )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( !pEntry )
        return 0;
    else
        return pEntry->aDefaultKeyCode;
}

void KGlobalAccel::disconnectItem( const char * action,
				   const QObject* /*receiver*/, const char* /*member*/ )
{
    KKeyEntry *pEntry = aKeyDict[ action ];
    if ( !pEntry )
		return;
	
}

const char * KGlobalAccel::findKey( int key ) const
{
	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
#define pE aKeyIt.current()
	while ( pE ) {
		if ( (unsigned int)key == pE->aCurrentKeyCode ) return aKeyIt.currentKey();
		++aKeyIt;
	}
#undef pE
	return 0;	
}

bool grabFailed;

static int XGrabErrorHandler( Display *, XErrorEvent *e ) {
	if ( e->error_code != BadAccess ) {
		warning( "grabKey: got X error %d instead of BadAccess", e->type );
	}
	grabFailed = true;
	return 0;
}

bool KGlobalAccel::grabKey( uint keysym, uint mod ) {
	// Most of this comes from kpanel/main.C
	// Copyright (C) 1996,97 Matthias Ettrich
	static int NumLockMask = 0;

	if (do_not_grab)
	  return true;

	if (!keysym || !XKeysymToKeycode(qt_xdisplay(), keysym)) return false;
	if (!NumLockMask){
		XModifierKeymap* xmk = XGetModifierMapping(qt_xdisplay());
		int i;
		for (i=0; i<8; i++){
		   if (xmk->modifiermap[xmk->max_keypermod * i] ==
		   		XKeysymToKeycode(qt_xdisplay(), XK_Num_Lock))
		   			NumLockMask = (1<<i);
		}
	}

	grabFailed = false;

	// We wan't to catch only our own errors
	XSync(qt_xdisplay(),0);
	XErrorHandler savedErrorHandler=XSetErrorHandler(XGrabErrorHandler);
	
	XGrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod,
		qt_xrootwin(), True,
		GrabModeAsync, GrabModeSync);
	XGrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod | LockMask,
		qt_xrootwin(), True,
		GrabModeAsync, GrabModeSync);
	XGrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod | NumLockMask,
		qt_xrootwin(), True,
		GrabModeAsync, GrabModeSync);
	XGrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod | LockMask | NumLockMask,
		qt_xrootwin(), True,
		GrabModeAsync, GrabModeSync);

	XSync(qt_xdisplay(),0);
	XSetErrorHandler(savedErrorHandler);
	
	if (grabFailed) {
		// FIXME: ungrab all successfull grabs!
		//warning("Global grab failed!");
   		return false;
	}
	return true;
}

bool KGlobalAccel::insertItem(  const char* descr, const char * action, uint keyCode,
					   bool configurable )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( pEntry )
		removeItem( action );

	pEntry = new KKeyEntry;
	aKeyDict.insert( action, pEntry );
	
	pEntry->aDefaultKeyCode = keyCode;
	pEntry->aCurrentKeyCode = keyCode;
	pEntry->bConfigurable = configurable;
	pEntry->bEnabled = false;
	pEntry->aAccelId = 0;
	pEntry->receiver = 0;
	pEntry->member = 0;
	pEntry->descr = descr;

	return TRUE;
}

bool KGlobalAccel::insertItem( const char* descr, const char * action,
					   const char * keyCode, bool configurable )
{
	uint iKeyCode = stringToKey( keyCode );
	return insertItem(descr, action, iKeyCode, configurable);
}

bool KGlobalAccel::isEnabled()
{
	return bEnabled;
}

bool KGlobalAccel::isItemEnabled( const char *action )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( !pEntry )
        return false;
    else
        return pEntry->bEnabled;
}

QDict<KKeyEntry> KGlobalAccel::keyDict()
{
	return aKeyDict;
}

void KGlobalAccel::readSettings()
{
	QString s;
	//KConfig *pConfig = kapp->getConfig();
	KConfig globalConfig;// this way we are certain to get the global stuff!
	KConfig *pConfig = &globalConfig;

	pConfig->setGroup( aGroup.data() );

	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
#define pE aKeyIt.current()
	// first ungrab
	while ( pE ) {
		s = pConfig->readEntry( aKeyIt.currentKey() );
		if ( pE->bEnabled ) {
			uint keysym = keyToXSym( pE->aCurrentKeyCode );
			uint mod = keyToXMod( pE->aCurrentKeyCode );
			ungrabKey( keysym, mod );
		}
		
		++aKeyIt;
	}
	// then grab
	aKeyIt.toFirst();
	while ( pE ) {
		s = pConfig->readEntry( aKeyIt.currentKey() );
		if ( s.isNull() )
			pE->aConfigKeyCode = pE->aDefaultKeyCode;
		else
			pE->aConfigKeyCode = stringToKey( s.data() );
		
		pE->aCurrentKeyCode = pE->aConfigKeyCode;
		
		if ( pE->bEnabled ) {
			uint keysym = keyToXSym( pE->aCurrentKeyCode );
			uint mod = keyToXMod( pE->aCurrentKeyCode );
			grabKey( keysym, mod );
		}
		
		++aKeyIt;
	}
#undef pE
}
	
void KGlobalAccel::removeItem( const char * action )
{
    KKeyEntry *pEntry = aKeyDict[ action ];
	
    if ( !pEntry )
		return;
	
	if ( pEntry->aAccelId ) {
	}
	
	aKeyDict.remove( action );
}

void KGlobalAccel::setConfigGroup( const char *group )
{
	aGroup = group;
}

const char *KGlobalAccel::configGroup()
{
	return aGroup.data();
}

void KGlobalAccel::setEnabled( bool activate )
{
	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
#define pE aKeyIt.current()
	while ( pE ) {
		setItemEnabled( aKeyIt.currentKey(), activate );
		++aKeyIt;
	}
#undef pE
	bEnabled = activate;
}

void KGlobalAccel::setItemEnabled( const char * action, bool activate )
{	

    KKeyEntry *pEntry = aKeyDict[ action ];
	if ( !pEntry ) {
		QString str;
		str.sprintf(
			"KGlobalAccel : cannont enable action %s"\
			"which is not in the object dictionary", action );
		warning( str );
		return;
	}

	bool old = pEntry->bEnabled;
	pEntry->bEnabled = activate;
	if ( pEntry->bEnabled == old ) return;

	if ( pEntry->aCurrentKeyCode == 0 ) return;
	
	uint keysym = keyToXSym( pEntry->aCurrentKeyCode );
	uint mod = keyToXMod( pEntry->aCurrentKeyCode );
	
	if ( keysym == NoSymbol ) return;

	if ( pEntry->bEnabled ) {
    		grabKey( keysym, mod );
	} else {
		ungrabKey( keysym, mod );
	}

	return;
}

bool KGlobalAccel::setKeyDict( QDict<KKeyEntry> nKeyDict )
{
	// ungrab all connected and enabled keys
	QDictIterator<KKeyEntry> *aKeyIt = new QDictIterator<KKeyEntry>( aKeyDict );
	aKeyIt->toFirst();
#define pE aKeyIt->current()
	while( pE ) {
		QString s;
		if ( pE->bEnabled ) {
			uint keysym = keyToXSym( pE->aCurrentKeyCode );
			uint mod = keyToXMod( pE->aCurrentKeyCode );
			ungrabKey( keysym, mod );
		}
		++*aKeyIt;
	}
#undef pE
	
	// Clear the dictionary
	aKeyDict.clear();
	
	// Insert the new items into the dictionary and reconnect if neccessary
	// Note also swap config and current key codes !!!!!!
	aKeyIt = new QDictIterator<KKeyEntry>( nKeyDict );
	aKeyIt->toFirst();
#define pE aKeyIt->current()
	KKeyEntry *pEntry;
	while( pE ) {
		pEntry = new KKeyEntry;
		aKeyDict.insert( aKeyIt->currentKey(), pEntry );

		pEntry->aDefaultKeyCode = pE->aDefaultKeyCode;
		// Not we write config key code to current key code !!
		pEntry->aCurrentKeyCode = pE->aConfigKeyCode;
		pEntry->aConfigKeyCode = pE->aConfigKeyCode;
		pEntry->bConfigurable = pE->bConfigurable;
		pEntry->aAccelId = pE->aAccelId;
		pEntry->receiver = pE->receiver;
		pEntry->member = pE->member;
		pEntry->descr = pE->descr; // tanghus
		pEntry->bEnabled = pE->bEnabled;
		
		if ( pEntry->bEnabled ) {
			uint keysym = keyToXSym( pEntry->aCurrentKeyCode );
			uint mod = keyToXMod( pEntry->aCurrentKeyCode );
			grabKey( keysym, mod );
		}
		
		++*aKeyIt;
	}
#undef pE
	delete aKeyIt;
	return true;
}

bool KGlobalAccel::ungrabKey( uint keysym, uint mod ) {
	// Most of this comes from kpanel/main.C
	// Copyright (C) 1996,97 Matthias Ettrich
	static int NumLockMask = 0;
	
	if (do_not_grab)
	  return true;

	if (!keysym||!XKeysymToKeycode(qt_xdisplay(), keysym)) return false;
	if (!NumLockMask){
		XModifierKeymap* xmk = XGetModifierMapping(qt_xdisplay());
		int i;
		for (i=0; i<8; i++){
		   if (xmk->modifiermap[xmk->max_keypermod * i] ==
		   		XKeysymToKeycode(qt_xdisplay(), XK_Num_Lock))
		   			NumLockMask = (1<<i);
		}
	}

	grabFailed = false;

	// We wan't to catch only our own errors
	XSync(qt_xdisplay(),0);
	XErrorHandler savedErrorHandler=XSetErrorHandler(XGrabErrorHandler);
	
	XUngrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod,
		qt_xrootwin());
	XUngrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod | LockMask,
		qt_xrootwin());
	XUngrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod | NumLockMask,
		qt_xrootwin());
	XUngrabKey(qt_xdisplay(),
		XKeysymToKeycode(qt_xdisplay(), keysym), mod | LockMask | NumLockMask,
		qt_xrootwin());

	XSync(qt_xdisplay(),0);
	XSetErrorHandler(savedErrorHandler);
	if (grabFailed) {
		// FIXME: ungrab all successfull grabs!
		//warning("Global grab failed!");
   		return false;
	}
	return true;
}

void KGlobalAccel::writeSettings()
{
	// KConfig *pConfig = kapp->getConfig();
	KConfig globalConfig;// this way we are certain to get the global stuff!
	KConfig *pConfig = &globalConfig;

	pConfig->setGroup( aGroup.data() );

	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
	while ( aKeyIt.current() ) {
	  if ( aKeyIt.current()->bConfigurable ){
		  pConfig->writeEntry( aKeyIt.currentKey(),
				       keyToString( aKeyIt.current()->aCurrentKeyCode),
				       true, true);
	  }
		++aKeyIt;
	}
	pConfig->sync();
}

bool KGlobalAccel::x11EventFilter( const XEvent *event_ ) {

	if ( aKeyDict.isEmpty() ) return false;
	if ( event_->type != KeyPress ) return false;
	
	uint mod=event_->xkey.state & (ControlMask | ShiftMask | Mod1Mask);
	uint keysym= XKeycodeToKeysym(qt_xdisplay(), event_->xkey.keycode, 0);
	

	QDictIterator<KKeyEntry> *aKeyIt = new QDictIterator<KKeyEntry>( aKeyDict );
	aKeyIt->toFirst();
#define pE aKeyIt->current()
	while( pE ) { 
		int kc = pE->aCurrentKeyCode;
		if ( mod == keyToXMod( kc ) && keysym == keyToXSym( kc ) ) {
		break;
		}
		++*aKeyIt;
	}
	
	if ( !pE ) {
		return false;
	}
	
	if ( !pE ) {
		return false;
	}


	XAllowEvents(qt_xdisplay(), AsyncKeyboard, CurrentTime);
	XUngrabKeyboard(qt_xdisplay(), CurrentTime);
	XSync(qt_xdisplay(), false);
	connect( this, SIGNAL( activated() ), pE->receiver, pE->member);
	emit activated();
	disconnect( this, SIGNAL( activated() ), pE->receiver, pE->member );

	return true;
}

/*****************************************************************************/

uint keyToXMod( uint keyCode )
{
	uint mod = 0;
	
	if ( keyCode == 0 ) return mod;
	
	if ( keyCode & SHIFT )
		 mod |= ShiftMask;
	if ( keyCode & CTRL )
		 mod |= ControlMask;
	if ( keyCode & ALT )
		 mod |= Mod1Mask;
		
	return mod;
}

uint keyToXSym( uint keyCode )
{
	char *toks[4], *next_tok;
	int nb_toks = 0;
	char sKey[200];

	uint keysym = 0;
	QString s = keyToString( keyCode);
	
	strncpy(sKey, (const char *)s.data(), 200);
	
	if ( s.isEmpty() ) return keysym;
	
	next_tok = strtok( sKey, "+" );
	
	if ( next_tok == 0L ) return 0;
	
	do {
		toks[nb_toks] = next_tok;
		nb_toks++;
		if ( nb_toks == 5 ) return 0;
		next_tok = strtok( 0L, "+" );
	} while ( next_tok != 0L );

	// Test for exactly one key (other tokens are accelerators)
	// Fill the keycode with infos
	bool  keyFound = FALSE;
	for ( int i=0; i<nb_toks; i++ ) {
		if ( strcmp( toks[i], "SHIFT" ) != 0 &&
			 strcmp( toks[i], "CTRL" ) != 0 &&
			 strcmp( toks[i], "ALT" ) != 0 ) {
		   if ( keyFound ) return 0;
		   keyFound = TRUE;
		   QString l = toks[i];
		   l = l.lower();
		   keysym = XStringToKeysym(l.data());
		   if (keysym == NoSymbol){
		     keysym = XStringToKeysym( toks[i] );
		   }
		   if ( keysym == NoSymbol ) {
			return 0;
		  }
		}
	}
	
	return keysym;
}

#include "kglobalaccel.moc"


--- NEW FILE: ckey.h ---
/* this file has been generated by convert_key */

typedef struct {
	 char name[15];
	 int code;
} KKey;

#define MAX_KEY_LENGTH 15
#define MAX_KEY_MODIFIER_LENGTH 15
#define NB_KEYS 234

// Please, everybody who inserts new keys _must_ update NB_KEYS!!!!

KKey KKeys[NB_KEYS] = {
	{ "Escape", 0x1000 },
	{ "Tab", 0x1001 },
	{ "Backtab", 0x1002 },
	{ "Backspace", 0x1003 },
	{ "Return", 0x1004 },
	{ "Enter", 0x1005 },
	{ "Insert", 0x1006 },
	{ "Delete", 0x1007 },
	{ "Pause", 0x1008 },
	{ "Print", 0x1009 },
	{ "SysReq", 0x100a },
	{ "Home", 0x1010 },
	{ "End", 0x1011 },
	{ "Left", 0x1012 },
	{ "Up", 0x1013 },
	{ "Right", 0x1014 },
	{ "Down", 0x1015 },
	{ "PageUp", Key_Prior },
	{ "Prior", 0x1016 },
	{ "PageDown", Key_Next },
	{ "Next", 0x1017 },
	{ "Shift", 0x1020 },
	{ "Control", 0x1021 },
	{ "Meta", 0x1022 },
	{ "Alt", 0x1023 },
	{ "CapsLock", 0x1024 },
	{ "NumLock", 0x1025 },
	{ "ScrollLock", 0x1026 },
	{ "F1", 0x1030 },
	{ "F2", 0x1031 },
	{ "F3", 0x1032 },
	{ "F4", 0x1033 },
	{ "F5", 0x1034 },
	{ "F6", 0x1035 },
	{ "F7", 0x1036 },
	{ "F8", 0x1037 },
	{ "F9", 0x1038 },
	{ "F10", 0x1039 },
	{ "F11", 0x103a },
	{ "F12", 0x103b },
	{ "F13", 0x103c },
	{ "F14", 0x103d },
	{ "F15", 0x103e },
	{ "F16", 0x103f },
	{ "F17", 0x1040 },
	{ "F18", 0x1041 },
	{ "F19", 0x1042 },
	{ "F20", 0x1043 },
	{ "F21", 0x1044 },
	{ "F22", 0x1045 },
	{ "F23", 0x1046 },
	{ "F24", 0x1047 },
	{ "F25", 0x1048 },
	{ "F26", 0x1049 },
	{ "F27", 0x104a },
	{ "F28", 0x104b },
	{ "F29", 0x104c },
	{ "F30", 0x104d },
	{ "F31", 0x104e },
	{ "F32", 0x104f },
	{ "F33", 0x1050 },
	{ "F34", 0x1051 },
	{ "F35", 0x1052 },
	{ "Super_L", 0x1053 },
	{ "Super_R", 0x1054 },
	{ "Menu", 0x1055 },
	{ "Hyper_L", 0x1056 },
	{ "Hyper_R", 0x1057 },
	{ "Space", 0x20 },
	{ "Exclam", 0x21 },
	{ "QuoteDbl", 0x22 },
	{ "NumberSign", 0x23 },
	{ "Dollar", 0x24 },
	{ "Percent", 0x25 },
	{ "Ampersand", 0x26 },
	{ "Apostrophe", 0x27 },
	{ "ParenLeft", 0x28 },
	{ "ParenRight", 0x29 },
	{ "Asterisk", 0x2a },
	{ "Plus", 0x2b },
	{ "Comma", 0x2c },
	{ "Minus", 0x2d },
	{ "Period", 0x2e },
	{ "Slash", 0x2f },
	{ "0", 0x30 },
	{ "1", 0x31 },
	{ "2", 0x32 },
	{ "3", 0x33 },
	{ "4", 0x34 },
	{ "5", 0x35 },
	{ "6", 0x36 },
	{ "7", 0x37 },
	{ "8", 0x38 },
	{ "9", 0x39 },
	{ "Colon", 0x3a },
	{ "Semicolon", 0x3b },
	{ "Less", 0x3c },
	{ "Equal", 0x3d },
	{ "Greater", 0x3e },
	{ "Question", 0x3f },
	{ "At", 0x40 },
	{ "A", 0x41 },
	{ "B", 0x42 },
	{ "C", 0x43 },
	{ "D", 0x44 },
	{ "E", 0x45 },
	{ "F", 0x46 },
	{ "G", 0x47 },
	{ "H", 0x48 },
	{ "I", 0x49 },
	{ "J", 0x4a },
	{ "K", 0x4b },
	{ "L", 0x4c },
	{ "M", 0x4d },
	{ "N", 0x4e },
	{ "O", 0x4f },
	{ "P", 0x50 },
	{ "Q", 0x51 },
	{ "R", 0x52 },
	{ "S", 0x53 },
	{ "T", 0x54 },
	{ "U", 0x55 },
	{ "V", 0x56 },
	{ "W", 0x57 },
	{ "X", 0x58 },
	{ "Y", 0x59 },
	{ "Z", 0x5a },
	{ "BracketLeft", 0x5b },
	{ "Backslash", 0x5c },
	{ "BracketRight", 0x5d },
	{ "AsciiCircum", 0x5e },
	{ "Underscore", 0x5f },
	{ "QuoteLeft", 0x60 },
	{ "BraceLeft", 0x7b },
	{ "Bar", 0x7c },
	{ "BraceRight", 0x7d },
	{ "AsciiTilde", 0x7e },
	{ "nobreakspace", 0x0a0 },
	{ "exclamdown", 0x0a1 },
	{ "cent", 0x0a2 },
	{ "sterling", 0x0a3 },
	{ "currency", 0x0a4 },
	{ "yen", 0x0a5 },
	{ "brokenbar", 0x0a6 },
	{ "section", 0x0a7 },
	{ "diaeresis", 0x0a8 },
	{ "copyright", 0x0a9 },
	{ "ordfeminine", 0x0aa },
	{ "guillemotleft", 0x0ab },
	{ "notsign", 0x0ac },
	{ "hyphen", 0x0ad },
	{ "registered", 0x0ae },
	{ "macron", 0x0af },
	{ "degree", 0x0b0 },
	{ "plusminus", 0x0b1 },
	{ "twosuperior", 0x0b2 },
	{ "threesuperior", 0x0b3 },
	{ "acute", 0x0b4 },
	{ "mu", 0x0b5 },
	{ "paragraph", 0x0b6 },
	{ "periodcentered", 0x0b7 },
	{ "cedilla", 0x0b8 },
	{ "onesuperior", 0x0b9 },
	{ "masculine", 0x0ba },
	{ "guillemotright", 0x0bb },
	{ "onequarter", 0x0bc },
	{ "onehalf", 0x0bd },
	{ "threequarters", 0x0be },
	{ "questiondown", 0x0bf },
	{ "Agrave", 0x0c0 },
	{ "Aacute", 0x0c1 },
	{ "Acircumflex", 0x0c2 },
	{ "Atilde", 0x0c3 },
	{ "Adiaeresis", 0x0c4 },
	{ "Aring", 0x0c5 },
	{ "AE", 0x0c6 },
	{ "Ccedilla", 0x0c7 },
	{ "Egrave", 0x0c8 },
	{ "Eacute", 0x0c9 },
	{ "Ecircumflex", 0x0ca },
	{ "Ediaeresis", 0x0cb },
	{ "Igrave", 0x0cc },
	{ "Iacute", 0x0cd },
	{ "Icircumflex", 0x0ce },
	{ "Idiaeresis", 0x0cf },
	{ "ETH", 0x0d0 },
	{ "Ntilde", 0x0d1 },
	{ "Ograve", 0x0d2 },
	{ "Oacute", 0x0d3 },
	{ "Ocircumflex", 0x0d4 },
	{ "Otilde", 0x0d5 },
	{ "Odiaeresis", 0x0d6 },
	{ "multiply", 0x0d7 },
	{ "Ooblique", 0x0d8 },
	{ "Ugrave", 0x0d9 },
	{ "Uacute", 0x0da },
	{ "Ucircumflex", 0x0db },
	{ "Udiaeresis", 0x0dc },
	{ "Yacute", 0x0dd },
	{ "THORN", 0x0de },
	{ "ssharp", 0x0df },
	{ "agrave", 0x0e0 },
	{ "aacute", 0x0e1 },
	{ "acircumflex", 0x0e2 },
	{ "atilde", 0x0e3 },
	{ "adiaeresis", 0x0e4 },
	{ "aring", 0x0e5 },
	{ "ae", 0x0e6 },
	{ "ccedilla", 0x0e7 },
	{ "egrave", 0x0e8 },
	{ "eacute", 0x0e9 },
	{ "ecircumflex", 0x0ea },
	{ "ediaeresis", 0x0eb },
	{ "igrave", 0x0ec },
	{ "iacute", 0x0ed },
	{ "icircumflex", 0x0ee },
	{ "idiaeresis", 0x0ef },
	{ "eth", 0x0f0 },
	{ "ntilde", 0x0f1 },
	{ "ograve", 0x0f2 },
	{ "oacute", 0x0f3 },
	{ "ocircumflex", 0x0f4 },
	{ "otilde", 0x0f5 },
	{ "odiaeresis", 0x0f6 },
	{ "division", 0x0f7 },
	{ "oslash", 0x0f8 },
	{ "ugrave", 0x0f9 },
	{ "uacute", 0x0fa },
	{ "ucircumflex", 0x0fb },
	{ "udiaeresis", 0x0fc },
	{ "yacute", 0x0fd },
	{ "thorn", 0x0fe },
	{ "ydiaeresis", 0x0ff },
	{ "unknown", 0xffff }
};

// Did you insert a new key?  Update NB_KEYS!!!!!!!

--- NEW FILE: kpixmap.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1998	Mark Donohoe <donohoe at kde.org>
						Stephan Kulow				

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <qpixmap.h>
#include <qpainter.h>
#include <qimage.h>
#include <qbitmap.h>
#include <qcolor.h>

#include <kapp.h>
#include <dither.h>

#include "kpixmap.h"

// Fast diffuse dither to 3x3x3 color cube
// Based on Qt's image conversion functions
static bool kdither_32_to_8( const QImage *src, QImage *dst )
{
    register QRgb *p;
    uchar  *b;
    int	    y;
	
	//printf("kconvert_32_to_8\n");
	
    if ( !dst->create(src->width(), src->height(), 8, 256) ) {
		warning("KPixmap: destination image not valid\n");
		return FALSE;
	}

    int ncols = 256;

    static uint bm[16][16];
    static int init=0;
    if (!init) {
		// Build a Bayer Matrix for dithering

		init = 1;
		int n, i, j;

		bm[0][0]=0;

		for (n=1; n<16; n*=2) {
	    	for (i=0; i<n; i++) {
			for (j=0; j<n; j++) {
		    	bm[i][j]*=4;
		    	bm[i+n][j]=bm[i][j]+2;
		    	bm[i][j+n]=bm[i][j]+3;
		    	bm[i+n][j+n]=bm[i][j]+1;
			}
	    	}
		}

		for (i=0; i<16; i++)
	    	for (j=0; j<16; j++)
			bm[i][j]<<=8;
    }

    dst->setNumColors( ncols );

#define MAX_R 2
#define MAX_G 2
#define MAX_B 2
#define INDEXOF(r,g,b) (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b))

	int rc, gc, bc;

	for ( rc=0; rc<=MAX_R; rc++ )		// build 2x2x2 color cube
	    for ( gc=0; gc<=MAX_G; gc++ )
		for ( bc=0; bc<=MAX_B; bc++ ) {
		    dst->setColor( INDEXOF(rc,gc,bc),
			qRgb( rc*255/MAX_R, gc*255/MAX_G, bc*255/MAX_B ) );
		}	

	int sw = src->width();
	int* line1[3];
	int* line2[3];
	int* pv[3];

	line1[0] = new int[src->width()];
	line2[0] = new int[src->width()];
	line1[1] = new int[src->width()];
	line2[1] = new int[src->width()];
	line1[2] = new int[src->width()];
	line2[2] = new int[src->width()];
	pv[0] = new int[sw];
	pv[1] = new int[sw];
	pv[2] = new int[sw];

	for ( y=0; y < src->height(); y++ ) {
	    p = (QRgb *)src->scanLine(y);
	    b = dst->scanLine(y);
		int endian = (QImage::systemByteOrder() == QImage::BigEndian);
		int x;
		uchar* q = src->scanLine(y);
		uchar* q2 = src->scanLine(y+1 < src->height() ? y + 1 : 0);
		for (int chan = 0; chan < 3; chan++) {
		    b = dst->scanLine(y);
		    int *l1 = (y&1) ? line2[chan] : line1[chan];
		    int *l2 = (y&1) ? line1[chan] : line2[chan];
		    if ( y == 0 ) {
			for (int i=0; i<sw; i++)
			    l1[i] = q[i*4+chan+endian];
		    }
		    if ( y+1 < src->height() ) {
			for (int i=0; i<sw; i++)
			    l2[i] = q2[i*4+chan+endian];
		    }
		    // Bi-directional error diffusion
		    if ( y&1 ) {
			for (x=0; x<sw; x++) {
			    int pix = QMAX(QMIN(2, (l1[x] * 2 + 128)/ 255), 0);
			    int err = l1[x] - pix * 255 / 2;
			    pv[chan][x] = pix;

			    // Spread the error around...
			    if ( x+1<sw ) {
				l1[x+1] += (err*7)>>4;
				l2[x+1] += err>>4;
			    }
			    l2[x]+=(err*5)>>4;
			    if (x>1)
				l2[x-1]+=(err*3)>>4;
			}
		    } else {
			for (x=sw; x-->0; ) {
			    int pix = QMAX(QMIN(2, (l1[x] * 2 + 128)/ 255), 0);
			    int err = l1[x] - pix * 255 / 2;
			    pv[chan][x] = pix;

			    // Spread the error around...
			    if ( x > 0 ) {
				l1[x-1] += (err*7)>>4;
				l2[x-1] += err>>4;
			    }
			    l2[x]+=(err*5)>>4;
			    if (x+1 < sw)
				l2[x+1]+=(err*3)>>4;
			}
		    }
		}
		if (endian) {
		    for (x=0; x<sw; x++) {
			*b++ = INDEXOF(pv[2][x],pv[1][x],pv[0][x]);
		    }
		} else {
		    for (x=0; x<sw; x++) {
			*b++ = INDEXOF(pv[0][x],pv[1][x],pv[2][x]);
		    }
		}
	}

	delete [] line1[0];
	delete [] line2[0];
	delete [] line1[1];
	delete [] line2[1];
	delete [] line1[2];
	delete [] line2[2];
	delete [] pv[0];
	delete [] pv[1];
	delete [] pv[2];
	
#undef MAX_R
#undef MAX_G
#undef MAX_B
#undef INDEXOF

    return TRUE;
}

void KPixmap::gradientFill( QColor ca, QColor cb, bool upDown, int ncols )
{				
	QPixmap pmCrop;
	QColor cRow;
    int ySize;
    int rca, gca, bca;
    int rDiff, gDiff, bDiff;
    float rat;
    uint *p;
    uint rgbRow;
	
	
	if( upDown )
    	ySize = height();
    else
    	ySize = width();

    pmCrop.resize( 30, ySize );
    QImage image( 30, ySize, 32 );

    rca = ca.red();
    gca = ca.green();
    bca = ca.blue();
    rDiff = cb.red() - ca.red();
    gDiff = cb.green() - ca.green();
    bDiff = cb.blue() - ca.blue();

    for ( int y = ySize - 1; y >= 0; y-- ) {
	    p = (uint *) image.scanLine( ySize - y - 1 );
	    rat = 1.0 * y / ySize;
	
		cRow.setRgb( rca + (int) ( rDiff * rat ),
						gca + (int) ( gDiff * rat ),
						bca + (int) ( bDiff * rat ) );
	
		rgbRow = cRow.rgb();
	
	    for( int x = 0; x < 30; x++ ) {
			*p = rgbRow;
			p++;
	    }
	}
	
	if ( depth() <= 16 ) {
	
		if( depth() == 16 ) ncols = 32;
		if ( ncols < 2 || ncols > 256 ) ncols = 3;

		QColor *dPal = new QColor[ncols];
		for ( int i=0; i<ncols; i++) {
			dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ),
								gca + gDiff * i / ( ncols - 1 ),
								bca + bDiff * i / ( ncols - 1 ) );
		}

		kFSDither dither( dPal, ncols );
		QImage dImage = dither.dither( image );
		pmCrop.convertFromImage( dImage );
		
		delete [] dPal;	
		
	} else
		pmCrop.convertFromImage( image );
	
	// Copy the cropped pixmap into the KPixmap.
	// Extract only a central column from the cropped pixmap
	// to avoid edge effects.
	
	int s;
	int sSize = 20;
	int sOffset = 5;
	
	if( upDown )
	    s = width() / sSize + 1;
	else
	    s = height() / sSize + 1;
	
	QPainter paint;
	paint.begin( this );
	
	if ( upDown )	
	    for( int i=0; i<s; i++ )
			paint.drawPixmap( sSize*i, 0, pmCrop, sOffset, 0 , sSize, ySize );
	else {
	    QWMatrix matrix;
	    matrix.translate( (float) width() - 1.0, 0.0 );
	    matrix.rotate( 90.0 );
	    paint.setWorldMatrix( matrix );
	    for( int i=0; i<s; i++)
			paint.drawPixmap( sSize*i, 0, pmCrop, sOffset, 0 , sSize, ySize );
	}
	
	paint.end();
}

void KPixmap::patternFill( QColor ca, QColor cb, uint pattern[8] )
{
    QPixmap tile( 8, 8 );
    tile.fill( cb );
	
    QPainter pt;
    pt.begin( &tile );
    pt.setBackgroundColor( cb );
    pt.setPen( ca );

    for ( int y = 0; y < 8; y++ ) {
		uint v = pattern[y];
		for ( int x = 0; x < 8; x++ ) {
	    	if ( v & 1 )
				pt.drawPoint( 7 - x, y );
	    	v /= 2;
		}
    }

    pt.end();

    int sx, sy = 0;
    while ( sy < height() ) {
		sx = 0;
		while (sx < width()) {
	    	bitBlt( this, sx, sy, &tile, 0, 0, 8, 8 );
	    	sx += 8;
		}
		sy += 8;
    }
}

bool KPixmap::load( const char *fileName, const char *format,
		    int conversion_flags )
{
	QImageIO io( fileName, format );

    bool result = io.read();
	
    if ( result ) {
	detach();
	result = convertFromImage( io.image(), conversion_flags );
    }
    return result;
}

bool KPixmap::load( const char *fileName, const char *format,
		    ColorMode mode )
{
    int conversion_flags = 0;
    switch (mode) {
      case Color:
		conversion_flags |= ColorOnly;
		break;
      case Mono:
		conversion_flags |= MonoOnly;
		break;
	  case LowColor:
		conversion_flags |= LowOnly;
		break;
	  case WebColor:
		conversion_flags |= WebOnly;
		break;
      default:
		break;// Nothing.
    }
    return load( fileName, format, conversion_flags );
}

bool KPixmap::convertFromImage( const QImage &img, ColorMode mode )
{
	int conversion_flags = 0;
    switch (mode) {
      case Color:
		conversion_flags |= ColorOnly;
		break;
      case Mono:
		conversion_flags |= MonoOnly;
		break;
		case LowColor:
		conversion_flags |= LowOnly;
		break;
	  case WebColor:
		conversion_flags |= WebOnly;
		break;
      default:
		break;	// Nothing.
    }
    return convertFromImage( img, conversion_flags );
}

bool KPixmap::convertFromImage( const QImage &img, int conversion_flags  )
{
	if ( img.isNull() ) {
#if defined(CHECK_NULL)
	warning( "KPixmap::convertFromImage: Cannot convert a null image" );
#endif
	return FALSE;
    }
    detach();					// detach other references
	
	int dd = defaultDepth();

	// If color mode not one of KPixmaps extra modes nothing to do
	if( ( conversion_flags & KColorMode_Mask ) != LowOnly &&
	     ( conversion_flags & KColorMode_Mask ) != WebOnly ) {
		return QPixmap::convertFromImage ( img, conversion_flags );
	}
	
	// If the default pixmap depth is not 8bpp, KPixmap color modes have no
	// effect. Ignore them and use AutoColor instead.
	if ( dd > 8 ) {
		if ( ( conversion_flags & KColorMode_Mask ) == LowOnly ||
			 ( conversion_flags & KColorMode_Mask ) == WebOnly )
			conversion_flags = (conversion_flags & ~KColorMode_Mask)
					| Auto;
		return QPixmap::convertFromImage ( img, conversion_flags );
	}
	
	if ( ( conversion_flags & KColorMode_Mask ) == LowOnly ) {
		// Here we skimp a little on the possible conversion modes
		// Don't offer ordered or threshold dither of RGB channels or
		// diffuse or ordered dither of alpha channel. It hardly seems
		// worth the effort for this specialised mode.
		
		// If image uses icon palette don't dither it.
		if( img.numColors() > 0 && img.numColors() <=40 ) {
			if ( checkColorTable( img ) ) {
				return QPixmap::convertFromImage( img, QPixmap::Auto );
			}
		}
		
		QBitmap mask;
		bool isMask = false;

		QImage  image = img.convertDepth(32);
		QImage tImage( image.width(), image.height(), 8, 256 );
		
		if( img.hasAlphaBuffer() ) {
			image.setAlphaBuffer( true );
			tImage.setAlphaBuffer( true );
			isMask = mask.convertFromImage( img.createAlphaMask() );
		}
		
		kdither_32_to_8( &image, &tImage );
		
		if( QPixmap::convertFromImage( tImage ) ) {
			if ( isMask ) QPixmap::setMask( mask );
			return true;
		} else
			return false;
	} else {
		QImage  image = img.convertDepth( 32 );
		image.setAlphaBuffer( img.hasAlphaBuffer() );
		conversion_flags = (conversion_flags & ~ColorMode_Mask) | Auto;
		return QPixmap::convertFromImage ( image, conversion_flags );
	}
}

static QColor* kpixmap_iconPalette = 0;

bool KPixmap::checkColorTable( const QImage &image )
{
    int i = 0;

    if (kpixmap_iconPalette == 0) {
	kpixmap_iconPalette = new QColor[40];
	
	// Standard palette
	kpixmap_iconPalette[i++] = red;
	kpixmap_iconPalette[i++] = green;
	kpixmap_iconPalette[i++] = blue;
	kpixmap_iconPalette[i++] = cyan;
	kpixmap_iconPalette[i++] = magenta;
	kpixmap_iconPalette[i++] = yellow;
	kpixmap_iconPalette[i++] = darkRed;
	kpixmap_iconPalette[i++] = darkGreen;
	kpixmap_iconPalette[i++] = darkBlue;
	kpixmap_iconPalette[i++] = darkCyan;
	kpixmap_iconPalette[i++] = darkMagenta;
	kpixmap_iconPalette[i++] = darkYellow;
	kpixmap_iconPalette[i++] = white;
	kpixmap_iconPalette[i++] = lightGray;
	kpixmap_iconPalette[i++] = gray;
	kpixmap_iconPalette[i++] = darkGray;
	kpixmap_iconPalette[i++] = black;
	
	// Pastels
	kpixmap_iconPalette[i++] = QColor( 255, 192, 192 );
	kpixmap_iconPalette[i++] = QColor( 192, 255, 192 );
	kpixmap_iconPalette[i++] = QColor( 192, 192, 255 );
	kpixmap_iconPalette[i++] = QColor( 255, 255, 192 );
	kpixmap_iconPalette[i++] = QColor( 255, 192, 255 );
	kpixmap_iconPalette[i++] = QColor( 192, 255, 255 );

	// Reds
	kpixmap_iconPalette[i++] = QColor( 64,   0,   0 );
	kpixmap_iconPalette[i++] = QColor( 192,  0,   0 );

	// Oranges
	kpixmap_iconPalette[i++] = QColor( 255, 128,   0 );
	kpixmap_iconPalette[i++] = QColor( 192,  88,   0 );
	kpixmap_iconPalette[i++] = QColor( 255, 168,  88 );
	kpixmap_iconPalette[i++] = QColor( 255, 220, 168 );

	// Blues
	kpixmap_iconPalette[i++] = QColor(   0,   0, 192 );

	// Turquoise
	kpixmap_iconPalette[i++] = QColor(   0,  64,  64 );
	kpixmap_iconPalette[i++] = QColor(   0, 192, 192 );

	// Yellows
	kpixmap_iconPalette[i++] = QColor(  64,  64,   0 );
	kpixmap_iconPalette[i++] = QColor( 192, 192,   0 );

	// Greens
	kpixmap_iconPalette[i++] = QColor(   0,  64,   0 );
	kpixmap_iconPalette[i++] = QColor(   0, 192,   0 );

	// Purples
	kpixmap_iconPalette[i++] = QColor( 192,   0, 192 );

	// Greys
	kpixmap_iconPalette[i++] = QColor(  88,  88,  88 );
	kpixmap_iconPalette[i++] = QColor(  48,  48,  48 );
	kpixmap_iconPalette[i++] = QColor( 220, 220, 220 );
	
    }

    QRgb* ctable = image.colorTable();

    int ncols = image.numColors();
    int j;

    // Allow one failure which could be transparent background
    int failures = 0;

    for ( i=0; i<ncols; i++ ) {
	for ( j=0; j<40; j++ ) {
	    if ( kpixmap_iconPalette[j].red() == qRed( ctable[i] ) &&
		 kpixmap_iconPalette[j].green() == qGreen( ctable[i] ) &&
		 kpixmap_iconPalette[j].blue() == qBlue( ctable[i] ) ) {
		break;
	    }
	}
	
	if ( j == 40 ) {
	    failures ++;			
	}
    }

    if( failures > 1 )
	return FALSE;
    else
	return TRUE;
}

--- NEW FILE: kiconloader.cpp ---
/* 
   $Id: kiconloader.cpp,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
   
   This file is part of the KDE libraries
   Copyright (C) 1997 Christoph Neerfeld (chris at kde.org)
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   
   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
   
   $Log: kiconloader.cpp,v $
   Revision 1.1  2006-10-03 11:26:27  dslinux_amadeus
   adding pristine copy of pixil to HEAD so I can branch from it

   Revision 1.1  2003/09/08 19:42:04  jasonk
   Addition of packages directory and associated files.

   Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
   Initial import of PIXIL into new cvs repository.

   Revision 1.1.1.1  2003/06/23 22:04:23  jasonk


   Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
   Initial import of ViewML

   Revision 1.26.4.4  1999/06/03 23:01:50  dfaure
   The second part of the patch - allows to set a per-application
   style of icons (large or normal), still keeping binary compatibility
   (implementation uses ~/.kderc to store the setting and kapp->appName()
   to read the setting for the current app)
   It's ugly, I completely agree with you, Taj, but it's the only way to
   keep binary compatibility. We should think of something better for KDE 2.
   (where this patch is already applied but is too ugly to remain as is)

   Revision 1.26.4.3  1999/05/29 18:41:25  denis
   File from 1.1.1 release restored.
   The old one was corrupted.

   Revision 1.26.4.2  1999/03/09 15:22:50  dfaure
   Moved path-list initialisation to a private initPath().
   Merged with Antonio's getIconPath(...) new method. (fixed missing .detach())
    loadInternal() uses it.
   Binary compatible. kfm will use it in a second :)

   Revision 1.26.4.1  1999/02/15 16:29:28  neerfeld
   reordered the searchpath: icons in ~/.kde/icons don't
   override application icons anymore

   Revision 1.26  1999/01/18 10:56:20  kulow
   .moc files are back in kdelibs. Built fine here using automake 1.3

   Revision 1.25  1999/01/15 09:30:37  kulow
   it's official - kdelibs builds with srcdir != builddir. For this I
   automocifized it, the generated rules are easier to maintain than
   selfwritten rules. I have to fight with some bugs of this tool, but
   generally it's better than keeping them updated by hand.

   Revision 1.24  1998/11/02 10:08:34  ettrich
   new reload method for kiconloader (Rene Beutler)

   Revision 1.23  1998/10/04 11:05:30  neerfeld
   fixed a bug in loadInternal; fixes the crash of kmenuedit

   Revision 1.22  1998/09/01 20:21:25  kulow
   I renamed all old qt header files to the new versions. I think, this looks
   nicer (and gives the change in configure a sense :)

   Revision 1.21  1998/08/26 18:37:47  neerfeld
   bug fix for loadInternal;  changed email address

   Revision 1.20  1998/08/17 10:34:02  konold

   Martin K.: Fixed a typo

   Revision 1.19  1998/06/15 12:49:32  kulow
   applied patch to replace .kde with localkdedir()

   Revision 1.18  1998/04/25 13:15:28  mark
   MD: Added KPixmap and changed KIconLoader to use it.

   Revision 1.17  1998/03/08 18:49:03  wuebben
   Bernd: fixed up the kiconloader class -- it was completely busted


*/

#include <qapplication.h>
#include <qdir.h>
#include <qpainter.h>
#include <qwmatrix.h>

#include "kiconloader.h"

#include <kpixmap.h>
#include <klocale.h>
#include <kapp.h>

void KIconLoader::initPath()
{
  // DF ---- Large icons --------------
  // set the key depending on the current application
  QString key = "KDE";
  if (strcmp( kapp->name(), "kpanel" ) == 0)
    key = "kpanel";
  if (strcmp( kapp->name(), "kfm" ) == 0)
    key = "kfm";
  KConfig config; // read .kderc
  config.setGroup("KDE");
  QString setting = config.readEntry( key + "IconStyle", "Normal" );
  //debug("App is %s - setting is %s", kapp->name(), setting.data());
  // DF
  
  // order is important! -- Bernd
  // higher priority at the end

  addPath( KApplication::kde_toolbardir() );
  addPath( KApplication::kde_icondir() );
  if (setting == "Large")
    addPath( KApplication::kde_icondir() + "/large" );

  addPath( KApplication::localkdedir() + "/share/toolbar" ); 
  addPath( KApplication::localkdedir() + "/share/icons" ); 
  if (setting == "Large")
    addPath( KApplication::localkdedir() + "/share/icons/large" );

  addPath( KApplication::kde_datadir() + "/" + kapp->appName() + "/toolbar" );
  addPath( KApplication::localkdedir() + "/share/apps/" + kapp->appName() + "/toolbar" ); 
  addPath( KApplication::kde_datadir() + "/" + kapp->appName() + "/pics" );
  if (setting == "Large")
    addPath( KApplication::kde_datadir() + "/" + kapp->appName() + "/pics/large" );
  addPath( KApplication::localkdedir() + "/share/apps/" + kapp->appName() + "/pics" ); 
  if (setting == "Large")
    addPath( KApplication::localkdedir() + "/share/apps/" + kapp->appName() + "/pics/large" ); 
}

KIconLoader::KIconLoader( KConfig *conf, 
			  const QString &app_name, const QString &var_name ){

  QStrList list;

  config = conf;
  config->setGroup(app_name);
  config->readListEntry( var_name, list, ':' );

  for (const char *it=list.first(); it; it = list.next())
    addPath(it);

  initPath();

  name_list.setAutoDelete(TRUE);
  pixmap_dirs.setAutoDelete(TRUE);
  pixmap_list.setAutoDelete(TRUE);

  /*
  for(char* c = pixmap_dirs.first(); c ; c = pixmap_dirs.next()){
    printf("in path:%s\n",pixmap_dirs.current());
  }
  */

}
 
KIconLoader::KIconLoader( ){

  QStrList list;

  config = KApplication::getKApplication()->getConfig();
  config->setGroup("KDE Setup");
  config->readListEntry( "IconPath", list, ':' );

  for (const char *it=list.first(); it; it = list.next())
    addPath(it);

  initPath();

  name_list.setAutoDelete(TRUE);
  pixmap_dirs.setAutoDelete(TRUE);
  pixmap_list.setAutoDelete(TRUE);

  /*
  for(char* c = pixmap_dirs.first(); c ; c = pixmap_dirs.next()){
    printf("()in path:%s\n",c);
  }
  */

}
 
KIconLoader::~KIconLoader()
{
  name_list.clear();
  pixmap_list.clear();
}

QPixmap KIconLoader::loadIcon ( const QString &name, int w, int h ){
  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);

*/

  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);
  }

  if (result.isNull())
    result = loadInternal(name, w, h);


/* 
   Stephan: See above
   if (result.isNull())
    warning(klocale->translate("ERROR: couldn't find mini icon: %s"), 
    (const char *) name);

*/

  return result;
}

QPixmap KIconLoader::loadApplicationIcon ( const QString &name, int w, int h ){

  //  addPath(KApplication::kde_icondir());
  //  addPath(KApplication::localkdedir() + "/share/icons" );

  QPixmap result = loadIcon(name, w, h);

  // this is trouble since you don't know whether the addPath was successful
  // I simply added icon dir to the set of standard paths. I hope
  // this will not give us too much of a performance hit. Other wise
  // I will have to break binary compatibiliy -- Bernd

  // pixmap_dirs.remove((unsigned int) 0);
  // pixmap_dirs.remove((unsigned int) 0);

  return result;

}


QPixmap KIconLoader::loadApplicationMiniIcon ( const QString &name, int w, int h ){

  //  addPath(KApplication::kde_icondir());
  //  addPath(KApplication::localkdedir() + "/share/icons" );

  QPixmap result = loadMiniIcon(name, w, h);

  // this is trouble since you don't know whether the addPath was successful
  // I simply added icon dir to the set of standard paths. I hope
  // this will not give us too much of a performance hit. Other wise
  // I will have to break binary compatibiliy -- Bernd

  //  pixmap_dirs.remove((unsigned int) 0);
  //  pixmap_dirs.remove((unsigned int) 0);

  return result;

}

QString KIconLoader::getIconPath( const QString &name, bool always_valid)
{
    QString full_path;
    QFileInfo finfo;

    if( name.left(1) == "/" ){
      full_path = name;
    }
    else{
      QStrListIterator it( pixmap_dirs );
      while ( it.current() ){
	
	full_path = it.current();
	full_path.detach();
	full_path += '/';
	full_path += name;
	finfo.setFile( full_path );
	if ( finfo.exists() )
	      break;
	++it;
      }
      if ( (always_valid) && (!it.current()) ){
        // Let's be recursive (but just once at most)
        full_path = getIconPath( "unknown.xpm" , false); 
      }
    }
    return full_path;
}

QPixmap KIconLoader::loadInternal ( const QString &name, int w,  int h ){

  QPixmap *pix;
  KPixmap new_xpm;

  int index;

  if ( (index = name_list.find(name)) < 0){
    
    pix = new QPixmap;
    new_xpm.load( getIconPath(name), 0L, KPixmap::LowColor );
    *pix = new_xpm;
    
    if( !(pix->isNull()) ){
      
      name_list.append(name);
      pixmap_list.append(pix);

    } 
    else {
      delete pix;
      return new_xpm;
    }
  }
  else{
    pix = pixmap_list.at(index);
  }
  

  if (pix && !pix->isNull() && w > 0 && h > 0 &&  
      (pix->width() > w || pix->height() > h)){

    QWMatrix m;
    m.scale(w/(float)pix->width(), h/(float)pix->height());

    return pix->xForm(m);

  }

  return *pix;
}


void KIconLoader::addPath(QString path){

  QDir dir(path.data());

  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 );
  }
}

#include "kiconloader.moc"


--- NEW FILE: README ---
This is the KDE "core" library.  The kdecore library provides basic non user
interface functionality.

CHANGES
=======

see ../CHANGES


How to use the KConfig class
============================
These thoughts are by no means complete or decided on forever, more accurate
and up to date information can be found on http://developer.kde.org

- Retreive the KConfig object from KApplication.  The correct way to do this is
  to use the KApplication::getConfig() method.
- Read values with readFOOEntry. Where FOO is the type of entry you wish to
  read (see the documentation on developer.kde.org for more info on this).
  The keys are searched for in the following files (sorted from least to
  highest priority):
	$KDEDIR/share/config/apprc    (global configuration dir)
	$HOME/.kde/share/config/apprc (local configuration dir)
  $KDEDIR is by default /usr/local/kde/, or in precompiled packages
  /opt/kde/. 
- Only keys that are in the current group will be found. After
  constructing a KConfig object, the current group is "" aka "the
  default group". You can set the group with setGroup(). A group is
  specified in a config file with the group name in brackets, the
  left bracket must be in column 0.
- Write values with writeEntry. writeEntry only writes to memory; the
  data is written to disk when you call sync() explicitly or when you
  destroy the KConfig object. The entries are always written to the most
  specific writeable config file.

How to use the kconfigtest test program
=======================================
- (The test program has been moved to the test directory.)
- You can find information about the last operation in the info field
at the bottom of the window.
- Enter a key left to the "=" character and press enter. If there was
entry with this key in the current group, the corresponding value will
be shown in the field right to the "=".
- To change the current group, enter a new group name in the group
field and press enter. To return to the default group, just clear the
field and press enter again.
- To provide an application-specific config file, enter its name in
the edit field in the first line and press enter.
- If you have changed the group or app config fields, you have to to
the key field and press enter there in order to see the effects your
changes may have on the key search.
- To write an entry, enter the value in the value field right to the
"=" and press the write button.
- To quit the application, press the quit button (now, this was easy!)
--- NEW FILE: Makefile.am ---
#	This file is part of the KDE libraries
#    Copyright (C) 1996-1997 Matthias Kalle Dalheimer (kalle at kde.org)
#			  (C) 1997 Stephan Kulow (coolo at kde.org)

#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Library General Public
#    License as published by the Free Software Foundation; either
#    version 2 of the License, or (at your option) any later version.

#    This library is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    Library General Public License for more details.

#    You should have received a copy of the GNU Library General Public License 
#    along with this library; see the file COPYING.LIB.  If not, write to
#    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#    Boston, MA 02111-1307, USA.

INCLUDES = $(QT_INCLUDES) $(X_INCLUDES)
EXTRA_DIST = convert_key.c charsets.config $(kdebug_DATA) kdebugareas.txt \
	kstddirs.h kstddirs.cpp
lib_LTLIBRARIES = libkdecore.la

include_HEADERS = kconfig.h kconfigdata.h ksimpleconfig.h kconfigbase.h \
	kcolorgroup.h kapp.h kcharsets.h \
	kurl.h ksock.h drag.h  ckey.h kmisc.h \
	kprocess.h kprocctrl.h klocale.h kiconloader.h kdebug.h	\
	kstdaccel.h kwm.h krootprop.h kstring.h kpixmap.h dither.h \
	kaccel.h kglobalaccel.h kckey.h kclipboard.h krect.h ksize.h \
	kpoint.h 

noinst_HEADERS = kdebugdialog.h kcharsetsdata.h 

libkdecore_la_SOURCES = kconfig.cpp kconfigbase.cpp ksimpleconfig.cpp \
	kcolorgroup.cpp kapp.cpp kurl.cpp ksock.cpp drag.cpp \
	 kprocess.cpp kprocctrl.cpp klocale.cpp \
	libintl.cpp fakes.cpp kiconloader.cpp kdebug.cpp \
	kstdaccel.cpp kwm.cpp krootprop.cpp kcharsets.cpp kcharsetsdata.cpp \
	kchartables.cpp kstring.cpp kpixmap.cpp dither.cpp \
	kckey.cpp kaccel.cpp kglobalaccel.cpp kclipboard.cpp \
	krect.cpp ksize.cpp kpoint.cpp


libkdecore_la_LDFLAGS = -version-info 2:0
# libkdecore_la_LIBADD = 

libkdecore_la_METASOURCES = drag.moc kapp.moc kclipboard.moc \
	kconfig.moc kconfigbase.moc kdebugdialog.moc kglobalaccel.moc \
	kiconloader.moc kprocctrl.moc kprocess.moc ksimpleconfig.moc \
	ksock.moc 

SRCDOC_DEST=$(kde_htmldir)/en/kdelibs/kdecore

kdebugdir = $(kde_confdir)
kdebug_DATA = kdebug.areas

## generate lib documentation
srcdoc:
	$(mkinstalldirs) $(SRCDOC_DEST)
	kdoc -H -d $(SRCDOC_DEST) kdecore \
		 $(include_HEADERS) -lqt

ckey.h : convert_key.c
	$(CC) $(CFLAGS) convert_key.c -o convert_key
	./convert_key $(QKEYCODE_H)
	cat ackey ckey > ckey.h
	rm -f ackey ckey

install-data-local: charsets.config 
	$(mkinstalldirs) $(kde_confdir)
	$(INSTALL_DATA) $(srcdir)/charsets.config $(kde_confdir)/charsets   

uninstall-local:
	-rm -f $(kde_confdir)/charsets

--- NEW FILE: kurl.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Steffen Hansen (stefh at dit.ou.dk)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef KURL_H
#define KURL_H

// -*-C++-*-
// KURL header
//

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <qstring.h>
#include <qstrlist.h>

/** 
* A class for URL processing.
*
* The KURL class deals with uniform resource locators in a 
* protocol independent way. It works on file:-type URLs
* much like @ref QDir does on normal directories; but KURL extends 
* the directory operations to work on general URLs. In fact, the 
* part of KURL that only deals with syntax doesn't care about 
* the protocol at all, so feel free to use it to format any 
* URL-like string. 
* 
* NOTE: KURL doesn't support URL's that don't look like files 
* (for example mailto:someone at somewhere). [If URL's like this were OK, 
* there would be no reason for isMalformed() since any string with a 
* ":" would be a valid URL.  Comments please.] 
*
* First version by Torben Weis, redesigned by Steffen Hansen (stefh at mip.ou.dk),
* maintained by Torben Weis (weis at kde.org). Endcoding/Decoding done by
* Stephan Kulow (coolo at kde.org).
*
* @author Torben Weis (weis at kde.org)
*
* @version $Id: kurl.h,v 1.1 2006-10-03 11:26:28 dslinux_amadeus Exp $
* @short A class for URL processing.
*/

class KURL
{ 
public:

    /** 
     * Construct a KURL object.
     */
    KURL();
    
    /** 
     * Construct a KURL object from _url. 
     *
     * A KURL object is always constructed, but if you plan to use it, 
     * you should check it with isMalformed().
     *
     * if the parameter is an absolute filename, it adds a file: prefix 
     * and encodes the path.
     */
    KURL( const char* _url);

    ~KURL();

    /** 
     * Construct a KURL object from its components. 
     */
    KURL( const char* _protocol, const char* _host, 
	  const char* _path, const char* _ref);
    
    /**
     * Constructs a URL.
     *
     * The second argument may be a relative URL, like '/home/weis/test.txt'.
     * If for example the first parameter is 'http://uni-frankfurt/pub/incoming' 
     * then the result will be 'http://uni-frankfurt/home/weis/test.txt'. 
     *
     * Of course the second argument may be a complete URL, too.
     */
    KURL( KURL & _base_url, const char* _rel_url );
    
    /** 
     * Returns true if the URL is not a valid URL. This is only syntax-checking;
     * whether the resource to which the URL points exists is not checked.
     *       
     * NOTE: Syntax checking is only done when constructing a KURL from a string. 
     */
    bool isMalformed() const { return malformed; }
    
    /**
     * Escapes some reserved characters within URLs (e.g. '#', '%').
     *
     * Some characters in filenames or directory names make troubles
     * For example '#' or '%' makes problem, if they are interpreted
     * and not ment to be interpreted. This why we must encode them.
     * This functions encodes the given URL and returns a reference
     * to the result for convidence.
     */
    static void encodeURL( QString& url );
    
    /**
     * Decodes escaped characters within URLs.
     *
     * This function looks for '%' within the URL and replaces this character 
     * with hexcode of the next two characters. If the next characters are not 
     * hex chararcters, 0 will be used and the character will be skipped.
     */
    static void decodeURL( QString& url );
    
    /** 
     * Returns the URL as a QString.
     */
    QString url() const;
    
    /** 
     * The function returns the protocolname up to, but not including the ":".
     */
    const char* protocol() const;
    
    /** 
     * This function returns the host. If there is no host (i.e.
     * the URL refers to a local file) this function returns "".
     */
    const char* host() const;
    
    /** 
     * This function returns the path-part of the URL.
     *
     * For example, path() on "tar://ftp.foo.org/bar/stuff.tar.gz#tex/doc.tex" 
     * returns "/bar/stuff.tar.gz".
     */
    const char* path() const;
    
    /** 
     * This function returns the path-part of an URL and leaves it as is.
     *
     * For example, path() on "http://www.foo.org/bar/cgi%2Dbin?value=blue%3f" 
     * returns "/bar/cgi%2Dbin".
     */
    const char* httpPath() const;
    
    /**
     * If we parse for example ftp://weis@localhost then we dont have a path.
     * The URL means: enter the home directory of user weis, while
     * ftp://weis@localhost/ means, login as user weis and enter the
     * root directory. KURL returns "/" as path in both cases. This function
     * lets you distinguish both URLs. It returns true in the first case.
     *
     * @see #bNoPath
     */
    bool hasPath() const { return !bNoPath; }
    
    /**
     * The search-part.
     *
     * @return the search-part, or NULL if no search-part was specified.
     */
    const char* searchPart() const;

    /** 
     * This function returns the reference. 
     *
     * If the URL is "http://www.nowhere/path/file.html#toc", this function 
     * will return "toc". If there is no reference it returns "".
     * If we have some subprotocol in the URL like in 
     * file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html#section
     * then only the last reference is going to be returned, in this case
     * "section". A URL like
     * file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html
     * would return "" since there is no reference. The stuff behind
     * the '#' is a subprotocol!
     */
    const char* reference() const;
    
    /**
     * This function returns the user name or an empty string if
     * no user has been specified.
     */
    const char* user() const;
    
    /**
     * The password.
     *
     * @return the password, or an empty string if no password was specified.
     */
    const char* passwd() const;
    
    /**
     * The port number.
     *
     * @return the port number, or 0 if none was specified.
     */
    unsigned int port() const;
    
    /**
     * Returns the directory only.
     *
     * If for example the URL is "file:/tmp/weis/file.html", then this call
     * will return "/tmp/weis/". If you pass "file:/tmp/weis/" to this
     * function, you will get "/tmp/weis/", because you already passed a directory.
     * Turning the '_trailing' flag off, causes the trailing '/' to be ignored.
     * "file:/tmp/weis/file.html" will result in "/tmp/weis/", too, but
     * "file:/tmp/weis/" will lead to "/tmp/". As you see, this is
     * a smart method to get the parent directory of a file/directory.
     *
     * This function is supplied for convenience only.
     */
    const char * directory( bool _trailing = TRUE );
    
    /**
     * Returns the URL with the directory only.
     *
     * If for example the URL is "file:/tmp/weis/file.html", then this call
     * will return "file:/tmp/weis/". For more details look at 'directory(...)'
     */
    const char * directoryURL( bool _trailing = TRUE );
    
    /**
     * @return TRUE if the URL has a sub protocol. For example file:/tmp/kde.tgz#tar:/kfm/main.cpp
     *         is a URL with subprotocol. Use this function to check wether some URL really
     *         references a complete file on your local hard disk and not some special data
     *         inside the file, like the example shows.
     */
    bool hasSubProtocol();

    /**
     * If the URL has no subprotocol, parentURL behaves like a call to @ref #url.
     * Otherwise the part of the URL left to the last subprotocol is returned.
     * For example file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html#section will return
     * file:/tmp/kde.tgz#tar:/kfm.rpm. As you can see, the last subprotocol is stripped.
     * If the original URL is for example file:/httpd/index.html#section
     * then exact this string is going to be returned.
     */
    QString parentURL();

    /**
     * This call returnes the other part of the URL, the part that is stripped by @ref #parentURL.
     * It returns always the right most subprotocol. If there is no subprotocol, the call
     * to this function returns an empty string. For example a URL 
     * file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html#section
     * would return rpm:/doc/index.html#section.
     */
    QString childURL();

    /**
     * This function behaves like @ref #childURL, but if there is no subprotocol,
     * this function returns the same @ref #url returns instead of an empty string.
     */
    QString nestedURL();

    /**
     * Parse a string.
     */
    void parse( const char *_url );
    
    /** 
     * Sets the protocol to newProto. Useful for example if an app hits
     * "file:/tmp/interesting.zip", then it might do setProtocol( "zip").
     */ 
    void setProtocol( const char* newProto) ;

   /** 
    * Sets the path to newPath.
    */ 
    void setPath( const char *newPath) ;   

   /** 
    * Sets the host
    */ 
    void setHost( const char *host) ;   

    /**
     * Set the password.
     */
    void setPassword( const char *password );

    /**
     * Set the user.
     */
    void setUser( const char *user );

    /**
     * Set the port.
     */
    void setPort( const unsigned int newPort );

    /**
     * Set the search-part.
     *
     * The search part of an URL is the part behind the '?'.
     * Example the URL "http://www.yahoo.com/search.cgi?country=netherland"
     * has "country=netherland" as search-part
     *
     * If NULL is specified, the search-part is cleared.
     */
    void setSearchPart( const char *_searchPart );
    
    /** 
     * Set reference. 
     *
     * A reference may be removed with setRef( ""). The function returns false 
     * if it could not make a reference (if there were no path to reference 
     * from) and true on succes.
     */
    bool setReference( const char* _ref);

    /** 
     * Changes directory by descending into the given directory. 
     * If dir starts with a "/" the 
     * current URL will be "protocol://host/dir" otherwise dir will 
     * be appended to the path.
     * If 'zapRef' is true, the reference will be deleted.
     */   
    bool cd( const char* _dir, bool zapRef = true);
    
    /** 
     * Go to parent dir. If zapRef is true, the reference is removed, 
     * otherwise it stays, but normally no one would want that. 
     */
    bool cdUp( bool zapRef = true);
    
    /**
     * Returns the filename or directory name of the URL.
     *
     * If 'file:/home/weis/test.txt' is the URL, the result will be 'test.txt'
     * If the URL us 'tar:/home/weis/test.tgz#foo/myfile' and isReference is TRUE,
     * the function will return 'myfile'
     */
    const char *filename();
    
    /**
     * Makes a copy of a URL.
     */
    KURL &operator=( const KURL &);
    
    /** 
     * Initialize the URL with the given string.
     * '_url' must be a valid URL.
     */
    KURL &operator=( const char* _url );
    
    /** 
     * Compare URL's.
     *
     * @return true if the URLs are equal, false otherwise.
     */
    bool operator==( const KURL &_url) const ;


    /**
      * Checks, if the URL refers to a usual file, that
      * can be openend with usual methods.
      *
      * Note: It doesn't check, if the file exist
      *
      * @return true, if the URL is a file, that can be opened
      **/
    bool isLocalFile();

protected:
    void cleanPath();
    
    bool malformed;
    /**
     * If we parse for example ftp://weis@localhost then we dont have a path.
     * The URL means: enter the home directory of user weis, while
     * ftp://weis@localhost/ means, login as user weis and enter the
     * root directory. KURL returns "/" as path in both cases. This variable
     * is used to distinguish both URLs. It is true in the first case.
     *
     * @see #hasPath
     */
    bool bNoPath;
    int port_number; 

    QString protocol_part;
    QString host_part;
    QString path_part;
    QString path_part_decoded;
    QString search_part;
    QString ref_part;
    // This variable is only valid after calling 'directory'.
    QString dir_part;
    QString user_part;
    QString passwd_part;
    
private:
    void detach();
};

#endif

--- NEW FILE: kstdaccel.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Stefan Taferner (taferner at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
#ifndef KSTDACCEL_H
#define KSTDACCEL_H

#include <qkeycode.h>
#include "kconfig.h"
#include "kaccel.h"
// #include <kkeyconf.h>

/**
 * Convenient methods for access of the common accelerator keys in
 * the key configuration. These standard keybindings that shall be used
 * in all Kde applications. They will be configurable, so do not hardcode
 * the default behaviour.
 *
 * If you want real configurable keybindings in your applications,
 * please checkout the class KAccel in kaccel.h
 */
class KStdAccel //: public KKeyConfig
{
public:
  KStdAccel(KConfig* cfg = 0);
  ~KStdAccel();

  /** Open file. Default: Ctrl-o */
  uint open(void) const;

  /** Create a new document (or whatever). Default: Ctrl-n */
  uint openNew(void) const;

  /** Close current document. Default: Ctrl-w */
  uint close(void) const;

  /** Save current document. Default: Ctrl-s */
  uint save(void) const;

  /** Print current document. Default: Ctrl-p */
  uint print(void) const;

  /** Quit the program. Default: Ctrl-q */
  uint quit(void) const;

  /** Cut selected area and store it in the clipboard. Default: Ctrl-x */
  uint cut(void) const;

  /** Copy selected area into the clipboard. Default: Ctrl-c */
  uint copy(void) const;

  /** Paste contents of clipboard at mouse/cursor position. Default: Ctrl-v */
  uint paste(void) const;

  /** Undo last operation. Default: Ctrl-z */
  uint undo(void) const;

  /** Find, search. Default: Ctrl-f */
  uint find(void) const;

  /** Find and replace matches. Default: Ctrl-r */
  uint replace(void) const;

  /** Toggle insert/overwrite (with visual feedback, e.g. in the statusbar). Default: Insert */
  uint insert(void) const;

  /** Goto beginning of current line. Default: Home */
  uint home(void) const;

  /** Goto end of current line. Default: End */
  uint end(void) const;

  /** Scroll up one page. Default: Prior */
  uint prior(void) const;

  /** Scroll down one page. Default: Next */
  uint next(void) const;

  /** Help the user in the current situation. Default: F1 */
  uint help(void) const;

protected:
  uint readKey(KAccel::StdAccel accel, uint defaultKey=0) const;
  KConfig* config;
};

#endif /*kshortcut_h*/

--- NEW FILE: klocale.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Stephan Kulow (coolo at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// Overloading of all standard locale functions makes no sense
// Let application use them
#ifdef HAVE_LOCALE_H 
#include <locale.h>
#endif

#include <stdlib.h>

#include <qdir.h>
/**
  * Stephan: I don't want to put this in an extra header file, since
  * this would let people think, they can use it within C files, but
  * this is not the case.
  **/

/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
   locale.  */
char *k_dcgettext (const char *__domainname, const char *__msgid,
		   const char *_language);

/* Set the current default message catalog to DOMAINNAME.
   If DOMAINNAME is null, return the current default.
   If DOMAINNAME is "", reset to the default of "messages".  */
char *k_textdomain (const char *__domainname);

/* Specify that the DOMAINNAME message catalog will be found
   in DIRNAME rather than in the system locale data base.  */
char *k_bindtextdomain (const char *__domainname,
			const char *__dirname);  


#include "klocale.h"
#include <kapp.h>
#include <kconfig.h>
#include <kcharsets.h>

#if !HAVE_LC_MESSAGES
/* This value determines the behaviour of the gettext() and dgettext()
   function.  But some system does not have this defined.  Define it
   to a default value.  */
# define LC_MESSAGES (-1)
#endif
 
#define SYSTEM_MESSAGES "kde"

static char *_categories[]={"LC_MESSAGES","LC_CTYPE","LC_COLLATE",
                            "LC_TIME","LC_NUMERIC","LC_MONETARY",0};

const QString KLocale::mergeLocale(const QString& lang,const QString& country,
				   const QString &charset)
{
    if (lang.isEmpty()) 
	return "C";
    QString ret = lang;
    if (!country.isEmpty()) 
	ret += "_" + country;
    if (!charset.isEmpty()) 
	ret+= "." +charset;
    return ret;
}

void KLocale::splitLocale(const QString& aStr,
			  QString& lang,
			  QString& country,
			  QString &chset){
   
    QString str = aStr.copy();

    // just in case, there is another language appended
    int f = str.find(':');
    if (f >= 0) {
	str = str.left(f);
    }

    country="";
    chset="";
    lang="";
    
    f = str.find('.');
    if (f >= 0) {
	chset = str.right(str.length() - f - 1);
	str = str.left(f);
    }
    
    f = str.find('_');
    if (f >= 0) { 
	country = str.right(str.length() - f - 1);
	str = str.left(f);
    }
    
    lang = str;
    
    if (chset.isEmpty() && kapp != 0){
	QString directory = KApplication::kde_localedir();
	QString dir=directory+"/"+lang+"_"+country;
	QDir d(dir);
	if (!d.exists("charset")){
	    dir=directory+"/"+lang;
	    d=QDir(dir);
	}  
	if (d.exists("charset")){
	    QFile f(dir+"/charset");   
	    if (f.exists() && f.open(IO_ReadOnly)){
		char *buf=new char[256];
		int l=f.readLine(buf,256);
		if (l>0){
		    if (buf[l-1]=='\n') buf[l-1]=0;
		    if (KCharset(buf).ok()) chset=buf;
		}
		delete [] buf;
		f.close();
	    }
	}    
    }  
}

#ifdef ENABLE_NLS

KLocale::KLocale( const char *catalogue )
{
#ifdef HAVE_SETLOCALE
    /* Set locale via LC_ALL according to environment variables  */
    setlocale (LC_ALL, "");
#endif
    chset="us-ascii";
    if ( ! catalogue )
	catalogue = kapp->appName().data();
    
    catalogues = new QStrList(true);
    catalogues->append(catalogue);
    
    QString languages;
    const char *g_lang = getenv("KDE_LANG");
    languages = g_lang;
    
    bool set_locale_vars=false;

    if (kapp) {
	QString setting;
	KConfig* config = kapp->getConfig();
	config->setGroup("Locale");
	if (!g_lang) 
	    languages = config->readEntry("Language", "default");
#ifdef HAVE_SETLOCALE
	setting = config->readEntry("Collate", "default");
	if (setting!="default") 
	    setlocale (LC_COLLATE, setting);
	setting = config->readEntry("Time", "default");
	if (setting!="default") 
	    setlocale (LC_TIME, setting);
	setting = config->readEntry("Monetary", "default");
	if (setting!="default") 
	    setlocale (LC_MONETARY, setting);
	setting = config->readEntry("CType", "default");
	if (setting!="default") 
	    setlocale (LC_CTYPE, setting);
	setting = config->readEntry("Numeric", "default");
	if (setting!="default") 
	    setlocale (LC_NUMERIC, setting);
#endif
	set_locale_vars  = config->readBoolEntry("SetLocaleVariables"
						 , false);
    }
    else 
	if (!g_lang) languages = "default";
    
#ifdef HAVE_SETLOCALE
    // setlocale reads variables LC_* and LANG, and it may use aliases,
    // so we don't have to do it
    g_lang = setlocale(LC_MESSAGES,0);
#else   
    g_lang = getenv("LANG");
#endif
    
    if (languages.isEmpty() || (languages == "default")) {
	if (g_lang && g_lang[0]!=0) // LANG value is set and is not ""
	    languages = g_lang;
	else
	    languages = "C";
    } else 
	languages = languages + ":C";

    QString directory = KApplication::kde_localedir();
    QString ln,ct,chrset;
   
    // save languages list requested by user
    langs=languages;    
    while (1) {
      int f = languages.find(':');
	if (f > 0) {
	    lang = languages.left(f);
	    languages = languages.right(languages.length() - 
					lang.length() - 1);
	} else {
	    lang = languages;
	    languages = "";
	}
	
	if (lang.isEmpty() || lang == "C")
	    break;

        splitLocale(lang,ln,ct,chrset);	

	QString lng[3];
	lng[0]=ln+"_"+ct+"."+chrset;
	lng[1]=ln+"_"+ct;
	lng[2]=ln;
	int i;
	for(i=0; i<3; i++) {
	  QDir d(directory + "/" + lng[i] + "/LC_MESSAGES");
	  if (d.exists(QString(catalogue) + ".mo") &&
	      d.exists(QString(SYSTEM_MESSAGES) + ".mo")) 
	      {
		  lang = lng[i];
		  break;
	      }
        }
	
	if (i != 3)
	    break;
    }
    
    chset=chrset;
#ifdef HAVE_SETLOCALE
    lc_numeric=setlocale(LC_NUMERIC,0);
    setlocale(LC_NUMERIC,"C");          // by default disable LC_NUMERIC
    setlocale(LC_MESSAGES,lang);       
    if (set_locale_vars){
        // set environment variables for all categories
	// maybe we should treat LC_NUMERIC differently (netscape problem)
	QString stmp;
        for(int i=0;_categories[i]!=0;i++) {
	  stmp = QString(_categories[i])+ "=" + getLocale(_categories[i]);
 	  putenv( stmp.data() );
	}
    }
    // we should use LC_CTYPE, not LC_MESSAGES for charset
    // however in most cases it should be the same for messages
    // to be readable (there is no i18n messages charset conversion yet)
    // So when LC_CTYPE is not set (is set to "C") better stay
    // with LC_MESSAGES
    QString lc_ctype=getLocale("LC_CTYPE");
    if ( !lc_ctype.isEmpty() && lc_ctype!="C"){
      splitLocale(getLocale("LC_CTYPE"),ln,ct,chrset);
      if (!chrset.isEmpty()) chset=chrset;
    }  
#else
    lc_numeric="C";
#endif
    numeric_enabled=false;

    insertCatalogue( catalogue );
    insertCatalogue( SYSTEM_MESSAGES );
    if (chset.isEmpty() || !KCharset(chset).ok()) chset="us-ascii";
}

void KLocale::insertCatalogue( const char *catalogue )
{
    k_bindtextdomain ( catalogue , KApplication::kde_localedir() );
    catalogues->append(catalogue);
}

KLocale::~KLocale()
{
    delete catalogues;
}

const char *KLocale::translate(const char *msgid)
{
    const char *text = msgid;
    for (const char *catalogue = catalogues->first(); catalogue; 
	 catalogue = catalogues->next()) 
    {
	text = k_dcgettext( catalogue, msgid, lang);
	if ( text != msgid) // we found it
	    break;
    }

    return text;
}

QString KLocale::directory() 
{
    return KApplication::kde_localedir() +  "/" + lang;
}

void KLocale::aliasLocale( const char* text, long int index)
{
    aliases.insert(index, translate(text));
}

// Using strings seems to be more portable (for systems without locale.h
const char *KLocale::getLocale(QString cat){

    cat.upper();
    if (cat=="LC_NUMERIC") return lc_numeric;
#ifdef HAVE_SETLOCALE        
    else if (cat=="LC_MESSAGES") return setlocale(LC_MESSAGES,0);
    else if (cat=="LC_COLLATE") return setlocale(LC_COLLATE,0);
    else if (cat=="LC_TIME") return setlocale(LC_TIME,0);
    else if (cat=="LC_CTYPE") return setlocale(LC_CTYPE,0);
    else if (cat=="LC_MONETARY") return setlocale(LC_MONETARY,0);
#endif	
    else return "C";
}

void KLocale::enableNumericLocale(bool on){
#ifdef HAVE_SETLOCALE
    if (on) 
	setlocale(LC_NUMERIC,lc_numeric);
    else 
	setlocale(LC_NUMERIC,"C");  
    numeric_enabled=on;
#else  
    numeric_enabled=false;
#endif
}

bool KLocale::numericLocaleEnabled()const{
    return numeric_enabled;
}
 
QStrList KLocale::languageList()const{

// a list to be returned
    QStrList list;
// temporary copy of language list
    QString str=langs;
    str.detach();
    
    while(!str.isEmpty()){
      int f = str.find(':');
      if (f >= 0) {
  	list.append(str.left(f));
        str=str.right(str.length()-f-1);
      }
      else{
        list.append(str);
        str="";
      }
    }   
    return list;
}

#else /* ENABLE_NLS */

KLocale::KLocale( const char *) 
{
}

KLocale::~KLocale() 
{
}

const char *KLocale::translate(const char *msgid)
{
    return msgid;
}

QString KLocale::directory() 
{
    return KApplication::kde_localedir();
}

void KLocale::aliasLocale(const char* text, long int index)
{
    aliases.insert(index, text);
}

const char *KLocale::getLocale(QString ){
    return "C";
}

void  KLocale::enableNumericLocale(bool){
}

bool  KLocale::numericLocaleEnabled()const{
    return false;
}
 
QStrList KLocale::languageList()const{
    return QStrList();
}
#endif /* ENABLE_NLS */


const char *KLocale::getAlias(long key) const
{
    return aliases[key];
}



--- NEW FILE: kcolorgroup.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: kcolorgroup.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
//
// $Log: kcolorgroup.h,v $
// Revision 1.1  2006-10-03 11:26:26  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:04  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
// Initial import of ViewML
//
// Revision 1.8  1998/06/16 06:03:20  kalle
// Implemented copy constructors and assignment operators or disabled them
//
// Revision 1.7  1998/01/18 14:38:36  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.5  1997/10/21 20:44:43  kulow
// removed all NULLs and replaced it with 0L or "".
// There are some left in mediatool, but this is not C++
//
// Revision 1.4  1997/10/16 11:14:29  torben
// Kalle: Copyright headers
// kdoctoolbar removed
//
// Revision 1.3  1997/10/09 11:46:20  kalle
// Assorted patches by Fritz Elfert, Rainer Bawidamann, Bernhard Kuhn and Lars Kneschke
//
// Revision 1.2  1997/10/04 19:42:46  kalle
// new KConfig
//
// Revision 1.1.1.1  1997/04/13 14:42:41  cvsuser
// Source imported
//
// Revision 1.1.1.1  1997/04/09 00:28:07  cvsuser
// Sources imported
//
// Revision 1.1  1996/11/24 12:54:42  kalle
// Initial revision
//
//
// KColorGroup header file - provide consistent colors for applications
//
// (C) 1996 Matthias Kalle Dalheimer <mda at stardivision.de>

#ifndef _KCOLORGROUP_H
#define _KCOLORGROUP_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef _KCONFIG_H
#include <kconfig.h>
#endif

#include <qpalette.h>
#include <qstring.h>

/// KColorGroup: A collection of color entries for application widgets
/** A KColorGroup provides seven colors for widgets: foreground,
  background, light, mid, dark, text and base - exactly as the
  QColorGroup. KColorGroup adds the possibility to store the
  KColorGroup via the KConfig mechanism. It would be nicer if
  KColorGroup was derived from QColorGroup, but QColorGroup provides
  no write access to its data members except via the constructor.
  */
class KColorGroup
{
private:
  QColorGroup* pQColorGroup;
public:
  /// Construct a KColorGroup with all colors black
  /** Construct a KColorGroup with all colors black */
  KColorGroup();

  /// Construct a KColorGroup with given colors.
  /** Construct a KColorGroup with given colors. */
  KColorGroup( const QColor& rForeground, const QColor& rBackground,
	       const QColor& rLight, const QColor& rMid, const QColor&
	       rDark, const QColor& rText, const QColor& rBase );

  /** Copy-constructor */
  KColorGroup( const KColorGroup& );
  
  /** assignment operator */
  KColorGroup& operator= ( const KColorGroup& );

  /// KColorGroup destructor
  /** KColorGroup destructor */
  ~KColorGroup();

  /// Retrieve the foreground value.
  /** Retrieve the foreground value. */
  const QColor& foreground() const 
  { return pQColorGroup->foreground(); }

  /// Retrieve the background value.
  /** Retrieve the background value. */
  const QColor& background() const 
  { return pQColorGroup->background(); }

  /// Retrieve the light value.
  /** Retrieve the light value. */
  const QColor& light() const 
  { return pQColorGroup->light(); }

  /// Retrieve the mid value.
  /** Retrieve the mid value. */
  const QColor& mid() const 
  { return pQColorGroup->mid(); }

  /// Retrieve the dark value.
  /** Retrieve the dark value. */
  const QColor& dark() const 
  { return pQColorGroup->dark(); }

  /// Retrieve the text value.
  /** Retrieve the text value. */
  const QColor& text() const 
  { return pQColorGroup->text(); }

  /// Retrieve the base value.
  /** Retrieve the base value. */
  const QColor& base() const 
  { return pQColorGroup->base(); }

  /// Compare two KColorGroups.
  /** Compare two KColorGroups. */
  bool operator==( const KColorGroup& rColorGroup ) const
  { return (*pQColorGroup) == (*rColorGroup.pQColorGroup); }

  /// Compare two KColorGroups.
  /** Compare two KColorGroups. */
  bool operator!=( const KColorGroup& rColorGroup ) const
  { return (*pQColorGroup) != (*rColorGroup.pQColorGroup); }

  /// Load color values from a KConfig object.
  /** Load color values from a KConfig object. The group "ColorGroup"
    is used. If pString is not 0, the value of pString is prepended
    to the group name.
    */
  void load( KConfig& rConfig, QString* pString = 0L );

  /// Save color values to a KConfig object.
  /** Save color values to a KConfig object. The group "ColorGroup" is
    used. If pString is not 0, the value of pString is prepended to
    the group name.
    */
  void save( KConfig& rConfig, QString* pString = 0L );
  
  /// Return the QColorGroup object
  /** Return the QColorGroup object (for drawing shades e.g.).
   */
  const QColorGroup *colorGroup() const;
};

#endif

--- NEW FILE: kcolorgroup.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: kcolorgroup.cpp,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
//
// $Log: kcolorgroup.cpp,v $
// Revision 1.1  2006-10-03 11:26:26  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:04  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
// Initial import of ViewML
//
// Revision 1.7  1998/06/16 06:03:19  kalle
// Implemented copy constructors and assignment operators or disabled them
//
// Revision 1.6  1998/01/18 14:38:34  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.4  1997/10/16 11:14:28  torben
// Kalle: Copyright headers
// kdoctoolbar removed
//
// Revision 1.3  1997/10/09 11:46:19  kalle
// Assorted patches by Fritz Elfert, Rainer Bawidamann, Bernhard Kuhn and Lars Kneschke
//
// Revision 1.2  1997/10/04 19:42:45  kalle
// new KConfig
//
// Revision 1.1.1.1  1997/04/13 14:42:41  cvsuser
// Source imported
//
// Revision 1.1.1.1  1997/04/09 00:28:05  cvsuser
// Sources imported
//
// Revision 1.2  1996/12/14 12:49:11  kalle
// method names start with a small letter
//
// Revision 1.1  1996/11/24 12:54:16  kalle
// Initial revision
//
//
// KColorGroup implementation
//
// (C) 1996 Matthias Kalle Dalheimer <mda at stardivision.de>

#ifndef _KCOLORGROUP_H
#include "kcolorgroup.h"
#endif

KColorGroup::KColorGroup()
{
  pQColorGroup = new QColorGroup();
}

KColorGroup::KColorGroup( const QColor& rForeground, const QColor& rBackground,
			  const QColor& rLight, const QColor& rMid, 
			  const QColor& rDark, const QColor& rText,
			  const QColor& rBase )
{
  pQColorGroup = new QColorGroup( rForeground, rBackground, rLight, rMid,
				  rDark, rText, rBase );
}

KColorGroup::~KColorGroup()
{
  delete pQColorGroup;
}


KColorGroup::KColorGroup( const KColorGroup& group )
{
  pQColorGroup = new QColorGroup( *group.pQColorGroup );
}


KColorGroup& KColorGroup::operator= ( const KColorGroup& group )
{
  if( this != &group ) {
	delete pQColorGroup;
	pQColorGroup = new QColorGroup( *group.pQColorGroup );
  }

  return *this;
}
	

void KColorGroup::load( KConfig& rConfig, QString* pString )
{
  QString aOldGroup = rConfig.getGroup();

  QString aGroupName;
  if (pString) 
	aGroupName = *pString;
  aGroupName += "ColorGroup";
  rConfig.setGroup( aGroupName );

  QColor aForeColor( rConfig.readColorEntry( "Foreground" ) );
  QColor aBackColor( rConfig.readColorEntry( "Background" ) );
  QColor aLightColor( rConfig.readColorEntry( "Light" ) );
  QColor aMidColor( rConfig.readColorEntry( "Mid" ) );
  QColor aDarkColor( rConfig.readColorEntry( "Dark" ) );
  QColor aTextColor( rConfig.readColorEntry( "Text" ) );
  QColor aBaseColor( rConfig.readColorEntry( "Base" ) );

  pQColorGroup = new QColorGroup( aForeColor, aBackColor, aLightColor, 
								  aMidColor, aDarkColor, aTextColor, 
								  aBaseColor );

  rConfig.setGroup( aOldGroup );
}

void KColorGroup::save( KConfig& rConfig, QString* pString )
{
  QString aOldGroup = rConfig.getGroup();

  QString aGroupName;
  if (pString) 
	aGroupName = *pString;
  aGroupName += "ColorGroup";
  rConfig.setGroup( aGroupName );
  

  rConfig.writeEntry( "Foreground", pQColorGroup->foreground() );
  rConfig.writeEntry( "Background", pQColorGroup->background() );
  rConfig.writeEntry( "Light", pQColorGroup->light() );
  rConfig.writeEntry( "Mid", pQColorGroup->mid() );
  rConfig.writeEntry( "Dark", pQColorGroup->dark() );
  rConfig.writeEntry( "Text", pQColorGroup->text() );
  rConfig.writeEntry( "Base", pQColorGroup->base() );

  rConfig.setGroup( aOldGroup );
}

const QColorGroup* KColorGroup::colorGroup() const
{
  return pQColorGroup;
}

--- NEW FILE: kconfigdata.h ---
// $Id: kconfigdata.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
//
// $Log: kconfigdata.h,v $
// Revision 1.1  2006-10-03 11:26:26  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:04  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
// Initial import of ViewML
//
// Revision 1.11  1998/10/07 06:49:24  kalle
// Correctly read double dollar signs (patch by Harri Porten)
// Dollar expansion can be turned off with setDollarExpansion( false ).
// \sa isDollarExpansion
//
// Revision 1.10  1998/09/01 20:21:21  kulow
// I renamed all old qt header files to the new versions. I think, this looks
// nicer (and gives the change in configure a sense :)
//
// Revision 1.9  1998/08/22 20:02:39  kulow
// make kdecore have nicer output, when compiled with -Weffc++ :)
//
// Revision 1.8  1998/04/26 02:24:45  ssk
// Some classes marked internal.
//
// Revision 1.7  1998/01/18 14:38:53  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.5  1998/01/15 13:22:29  kalle
// Read-only mode for KSimpleConfig
//
// Revision 1.4  1997/12/12 14:46:04  denis
// Reverting to lower case true/false
//
// Revision 1.3  1997/12/12 14:33:48  denis
// replaced true by TRUE and false by FALSE
//
// Revision 1.2  1997/10/10 19:24:11  kulow
// removed mutable and replace const_cast with a more portable way.
//
// Revision 1.1  1997/10/04 19:51:06  kalle
// new KConfig
//
//
// (C) 1996-1998 by Matthias Kalle Dalheimer

#ifndef _KCONFIGDATA_H
#define _KCONFIGDATA_H

#include <qdict.h> // QDict
#include <qtextstream.h> // QTextStream

/**
* Entry-dictionary entry.
* @internal
*/
struct KEntryDictEntry
{
  QString aValue;
  bool    bDirty; // must the entry be written back to disk?
  bool    bGlobal; // entry should be written to the global config file
  bool    bNLS;    // entry should be written with locale tag
};

typedef QDict<KEntryDictEntry> KEntryDict;
typedef QDict<KEntryDict> KGroupDict;
typedef QDictIterator<KEntryDict> KGroupIterator;
typedef QDictIterator<KEntryDictEntry> KEntryIterator;

/**
* Configuration data manager, used internally by KConfig.
* @short Configuration data manager, used internally by KConfig.
* @version $Id: kconfigdata.h,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
* @author Matthias Kalle Dalheimer (kalle at kde.org)
* @internal
*/
class KConfigBaseData
{
friend class KConfig;
friend class KConfigBase;
friend class KSimpleConfig;
private:
  QString aLocalAppFile;
  QString aGlobalAppFile;
  QString aGroup;
  QString aLocaleString; // locale code
  bool bDirty; // is there any entry that has to be written back to disk?
  bool bLocaleInitialized;
  bool bReadOnly; // currently only used by KSimpleConfig
	bool bExpand; // whether dollar expansion is used

  QDict<KEntryDict> aGroupDict;

#ifndef NDEBUG
  QString aFile;
#endif
  
public:
  KConfigBaseData();
  KConfigBaseData( const char* pGlobalAppFile, const char* pLocalAppFile );
  
  KGroupIterator* groupIterator( void );
};

inline KConfigBaseData::KConfigBaseData() :
    aLocalAppFile(0), aGlobalAppFile(0),
    aGroup("<default>"), aLocaleString(0), bDirty(false),
    bLocaleInitialized(false), bReadOnly(false), bExpand( true ),
	aGroupDict( 37, false )
#ifndef NDEBUG
  , aFile(0)
#endif
{
  aGroupDict.setAutoDelete( true );
}
  
inline KConfigBaseData::KConfigBaseData( const char* pGlobalAppFile,
					 const char* pLocalAppFile ) :
  aLocalAppFile(pLocalAppFile), aGlobalAppFile(pGlobalAppFile), 
  aGroup("<default>"), aLocaleString(0), bDirty(false), 
  bLocaleInitialized(false), bReadOnly(false), aGroupDict( 37, false )
#ifndef NDEBUG
  , aFile(0)
#endif
{
  aGroupDict.setAutoDelete( true );
}

inline KGroupIterator* KConfigBaseData::groupIterator(void)
{
  return new KGroupIterator(aGroupDict);
}


#endif

--- NEW FILE: kpixmap.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1998	Mark Donohoe <donohoe at kde.org>
						Stephan Kulow				  

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef __KPIXMAP_H__
#define __KPIXMAP_H__

#include <qpixmap.h>

const int KColorMode_Mask	= 0x00000300;
const int WebOnly 	= 0x00000200;
const int LowOnly	= 0x00000300;

/**
 * The KPixmap class is an off-screen buffer paint device that extends the
 * features of QPixmap.
 * 
 * KPixmap has two new color modes, WebColor and LowColor, applicable to 8bpp
 * displays.
 *
 * In WebColor mode all images are dithered to the Netscape palette, even when
 * they have their own color table. WebColor is the default mode for KPixmap so
 * that standard applications can share the Netscape palette across the desktop.
 *
 * In LowColor mode images are checked to see if their color table matches the
 * KDE icon palette. If the color tables do not match, the images are dithered
 * to a minimal 3x3x3 color cube. LowColor mode can be used to load icons,
 * background images etc. so that components of the desktop which are always
 * present use no more than 40 colors.
 *
 */
class KPixmap : public QPixmap
{
public:
	enum ColorMode { Auto, Color, Mono, LowColor, WebColor };
    
	/**
	 * Creates a null pixmap
	 */
	KPixmap() {};
	
	/**
	 * Destroys the pixmap.
	 */
	~KPixmap() {};
    
	/**
	 * Fills the pixmap with a color blend running from color ca to color cb.
	 *
	 * If upDown is TRUE the blend will run from the top to the bottom of the
	 * pixmap. If upDown is FALSE the blend will run from the right to the left
	 * of the pixmap.
	 *
	 * By default, the blend will use 3 colors on 8 bpp displays,
	 * 32 colors on 16 bpp displays and unlimited colors at higher dislay
	 * depths. For 8bpp displays ncols specifies an alternative number of colors
	 * to use. The greater the number of colors allocated the better the
	 * appearance of the gradient but the longer it takes to make. 
	 */
	void gradientFill( QColor ca, QColor cb, bool upDown = TRUE, int ncols = 3 );
	
	/**
	 * Fills the pixmap with a two color pattern, specified by the pattern bits
	 * in pattern[], the color ca to be used for the background and the color cb
	 * to be used for the foreground.
	 */
	void patternFill( QColor ca, QColor cb, uint pattern[8] );
	
	/** 
	 * Converts an image and sets this pixmap. Returns TRUE if
	 * successful. 
	 *
	 * The conversion_flags argument is a bitwise-OR from the
	 * following choices. The options marked (default) are the
	 * choice if no other choice from the list is included (they
	 * are zero):
	 *
	 * Color/Mono preference
	 *
	 * <itemize>
	 * <item>WebColor -  If the image has depth 1 and contains
	 * only black and white pixels then the pixmap becomes monochrome. If
	 * the pixmap has a depth of 8 bits per pixel then the Netscape
	 * palette is used for the pixmap color table.
	 * <item>LowColor - If the image has depth 1 and contains only black and
	 * white pixels then the pixmap becomes monochrome. If the pixmap has a
	 * depth of 8 bits per pixel and the image does not posess a color table
	 * that matches the Icon palette a 3x3x3 color cube is used for the
	 * pixmap color table.
	 * <item>AutoColor (default) - If the image has depth 1 and contains
	 * only black and white pixels, then the pixmap becomes
	 * monochrome.
	 * <item>ColorOnly - The pixmap is dithered/converted to the native
	 * display depth.
	 * <item>MonoOnly - The pixmap becomes monochrome. If necessary, it
	 * is dithered using the chosen dithering algorithm.
	 * </itemize>
	 *
	 * Dithering mode preference, for RGB channels
	 *
	 * <itemize>
	 * <item>DiffuseDither (default) - a high quality dither
	 * <item>OrderedDither - a faster more ordered dither
	 * <item>ThresholdDither - no dithering, closest color is used
	 * </itemize>
	 *
	 * Dithering mode preference, for alpha channel
	 *
	 * <itemize>
	 * <item>DiffuseAlphaDither - a high quality dither
	 * <item>OrderedAlphaDither - a faster more ordered dither
	 * <item>ThresholdAlphaDither (default) - no dithering
	 * </itemize>
	 *
	 * Color matching versus dithering preference
	 * 
	 * <itemize>
	 * <item>PreferDither - always dither 32-bit images when the image
	 * is being converted to 8-bits. This is the default when
	 * converting to a pixmap.
	 * <item>AvoidDither - only dither 32-bit images if the image has
	 * more than 256 colours and it is being converted to 8-bits.
	 * This is the default when an image is converted for the
	 * purpose of saving to a file.
	 * </itemize>
	 *
	 * Passing 0 for conversion_flags gives all the default
	 * options.
	 */
	bool convertFromImage( const QImage &img, int conversion_flags );
	
	/*
	 * This is an overloaded member function, provided for
	 * convenience. It differs from the above function only in
	 * what argument(s) it accepts.
	 */
	bool convertFromImage( const QImage &img, ColorMode mode = WebColor );
	
	/**
	 * Loads a pixmap from the file fileName. Returns TRUE if
	 * successful, or FALSE if the pixmap could not be loaded. 
	 * 
	 * If format is specified, the loader attempts to read the
	 * pixmap using the specified format. If format is not
	 * specified (default), the loader reads a few bytes from the
	 * header to guess the file format.
	 *
	 * See the convertFromImage() documentation for a description
	 * of the conversion_flags argument.
	 *
	 * The QImageIO documentation lists the supported image
	 * formats and explains how to add extra formats.
	 */
	bool load( const char *fileName, const char *format, int conversion_flags );
	
	/*
	 * This is an overloaded member function, provided for
	 * convenience. It differs from the above function only in
	 * what argument(s) it accepts.
	 */
	bool load( const char *fileName, const char *format = 0,
		ColorMode mode = WebColor );
	/*
	 * Returns TRUE of the image is posessed of a color table that matches the
	 * Icon palette or FALSE otherwise.
	 * 
	 * An image with one color not found in the Icon
	 * palette is considered to make a match, since this extra color may be a
	 * transparent background.
	 */
	bool checkColorTable(const QImage &image);	
};

#endif


--- NEW FILE: charsets.config ---
# KDE Config file
[general]
i18ndir=/usr/share/i18n/charmaps

[aliases]
iso-ir-111=koi8-r
koi8-ru=koi8-r
koi unified=koi8-r
windows-1250=cp1250
cp-1250=cp1250
x-cp-1250=cp1250
windows-1251=cp1251
x-windows-1251=cp1251
cp-1251=cp1251
x-cp-1251=cp1251
utf-8=unicode-1-1-utf-8
#utf-7=unicode-1-1-utf-7
x-utf-8=unicode-1-1-utf-8
#x-utf-7=unicode-1-1-utf-7

[conversionHints]
cp1250=iso-8859-2,iso-8859-1
koi8-r=iso-8859-5
cp852=iso-8859-2,iso-8859-1
#unicode-1-1-utf-7=iso-8859-1
unicode-1-1-utf-8=iso-8859-1

[faces]
adobe-symbol=symbol
koi8-r=*_koi8

[XNames]
us-ascii=iso8859-1

--- NEW FILE: convert_key.c ---
/* convert the QT keycodes in an useful form for kkeydlg */

#include <stdio.h>
#include <string.h>

#define CONV_FILE "ckey"
#define ADD_CONV_FILE "ackey"

FILE *qt_key, *conv_key;     

void fin(char *msg)
{
	fclose(qt_key);
	fclose(conv_key);
	printf(msg);
	exit(0);
}

int main( int argc, char ** argv )
{
	char qt_path[200], line[200];
	char *token, *result;
	int nb_lines;
	
	if ( argc != 2 ) {
		printf("Need qkeycode.h in argument\n");
		exit(1);
	}
	
	sprintf(qt_path, "%s", argv[1]);
	qt_key = fopen(qt_path, "r");
	if ( qt_key==0L ) {
		printf("Unable to read %s\n", qt_path);
		exit(0);
	}
	
	conv_key = fopen(CONV_FILE, "w");
	if ( conv_key==0L ) {
		printf("Unable to create %s\n", CONV_FILE);
		exit(0);
	}
	
	nb_lines = 0;
	do {
		result = fgets(line, 200, qt_key);
		if ( result==0L ) break;
		token = strtok(line, " ");
		if ( strcmp(token, "#define")!=0 ) continue;
		token = strtok(0L, "\t\t");
		if ( strncmp(token, "Key_", 4)!=0 ) continue;
		if ( nb_lines!=0 ) fprintf(conv_key, ",\n");        
		fprintf(conv_key, "\t{ \"%s\"", token+4);
		token = strtok(0L,"\t\n");
		fprintf(conv_key, ", %s }", token);
		nb_lines++;
	} while (1);
	fprintf(conv_key, "\n};\n\n");
	fclose(conv_key);
	
	conv_key = fopen(ADD_CONV_FILE, "w");
	if ( conv_key==0L ) {
		printf("Unable to read %s\n", ADD_CONV_FILE);
        exit(0);
	}

	fprintf(conv_key, "/* this file has been generated by convert_key */\n\n");
	fprintf(conv_key, "typedef struct {\n\t char name[15];\n\t int code;\n} KKey;\n\n");
	fprintf(conv_key, "#define MAX_KEY_LENGTH 15\n#define MAX_KEY_MODIFIER_LENGTH 15\n");
	fprintf(conv_key, "#define NB_KEYS %i\n\n", nb_lines);
	fprintf(conv_key, "KKey KKeys[NB_KEYS] = {\n");
	
	fin("conversion done\n");
}

--- NEW FILE: dither.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Martin Jones (mjones at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
//-----------------------------------------------------------------------------
//
// Floyd-Steinberg dithering
// Ref: Bitmapped Graphics Programming in C++
//      Marv Luse, Addison-Wesley Publishing, 1993.
//

#include <qcolor.h>
#include "dither.h"

kFSDither::kFSDither( const QColor *pal, int pSize )
{
	palette = pal;
	palSize = pSize;
}

QImage kFSDither::dither( const QImage &iImage )
{
	if ( iImage.depth() <= 8 )
	{
		warning( "Only dithering of 24bpp images supported" );
		return QImage();
	}

	QImage dImage( iImage.width(), iImage.height(), 8, palSize );
	int i;

	dImage.setNumColors( palSize );
	for ( i = 0; i < palSize; i++ )
		dImage.setColor( i, palette[ i ].rgb() );

	int *rerr1 = new int [ iImage.width() * 2 ];
	int *gerr1 = new int [ iImage.width() * 2 ];
	int *berr1 = new int [ iImage.width() * 2 ];

	memset( rerr1, 0, sizeof( int ) * iImage.width() * 2 );
	memset( gerr1, 0, sizeof( int ) * iImage.width() * 2 );
	memset( berr1, 0, sizeof( int ) * iImage.width() * 2 );

	int *rerr2 = rerr1 + iImage.width();
	int *gerr2 = gerr1 + iImage.width();
	int *berr2 = berr1 + iImage.width();

	for ( int j = 0; j < iImage.height(); j++ )
	{
		uint *ip = (uint * )iImage.scanLine( j );
		uchar *dp = dImage.scanLine( j );

		for ( i = 0; i < iImage.width(); i++ )
		{
			rerr1[i] = rerr2[i] + qRed( *ip );
			rerr2[i] = 0;
			gerr1[i] = gerr2[i] + qGreen( *ip );
			gerr2[i] = 0;
			berr1[i] = berr2[i] + qBlue( *ip );
			berr2[i] = 0;
			ip++;
		}

		*dp++ = nearestColor( rerr1[0], gerr1[0], berr1[0] );

		for ( i = 1; i < iImage.width()-1; i++ )
		{
			int indx = nearestColor( rerr1[i], gerr1[i], berr1[i] );
			*dp = indx;

			int rerr = rerr1[i];
			rerr -= palette[indx].red();
			int gerr = gerr1[i];
			gerr -= palette[indx].green();
			int berr = berr1[i];
			berr -= palette[indx].blue();

			// diffuse red error
			rerr1[ i+1 ] += ( rerr * 7 ) >> 4;
			rerr2[ i-1 ] += ( rerr * 3 ) >> 4;
			rerr2[  i  ] += ( rerr * 5 ) >> 4;
			rerr2[ i+1 ] += ( rerr ) >> 4;

			// diffuse green error
			gerr1[ i+1 ] += ( gerr * 7 ) >> 4;
			gerr2[ i-1 ] += ( gerr * 3 ) >> 4;
			gerr2[  i  ] += ( gerr * 5 ) >> 4;
			gerr2[ i+1 ] += ( gerr ) >> 4;

			// diffuse red error
			berr1[ i+1 ] += ( berr * 7 ) >> 4;
			berr2[ i-1 ] += ( berr * 3 ) >> 4;
			berr2[  i  ] += ( berr * 5 ) >> 4;
			berr2[ i+1 ] += ( berr ) >> 4;

			dp++;
		}

		*dp = nearestColor( rerr1[i], gerr1[i], berr1[i] );
	}

	delete [] rerr1;
	delete [] gerr1;
	delete [] berr1;

	return dImage;
}

int kFSDither::nearestColor( int r, int g, int b )
{
	int dr = palette[0].red() - r;
	int dg = palette[0].green() - g;
	int db = palette[0].blue() - b;

	int minDist =  dr*dr + dg*dg + db*db;
	int nearest = 0;

	for (int i = 1; i < palSize; i++ )
	{
		dr = palette[i].red() - r;
		dg = palette[i].green() - g;
		db = palette[i].blue() - b;

		int dist = dr*dr + dg*dg + db*db;

		if ( dist < minDist )
		{
			minDist = dist;
			nearest = i;
		}
	}

	return nearest;
}


--- NEW FILE: libintl.cpp ---
/* libintl.cpp -- gettext related functions from glibc-2.0.5
   Copyright (C) 1995 Software Foundation, Inc.

This file is part of the KDE libraries, but it's derived work out
of glibc. The master sources can be found in 

      bindtextdom.c
      dcgettext.c
      dgettext.c
      explodename.c
      finddomain.c
      gettext.c
      gettext.h
      gettextP.h
      hash-string.h
      l10nflist.c
      libintl.h
      loadinfo.h
      loadmsgcat.c
[...1774 lines suppressed...]
  else
    {
      /* If the following malloc fails `k_nl_current_default_domain'
	 will be NULL.  This value will be returned and so signals we
	 are out of core.  */
      size_t len = strlen (domainname) + 1;
      char *cp = (char *) malloc (len);
      if (cp != NULL)
	memcpy (cp, domainname, len);
      k_nl_current_default_domain = cp;
    }

  if (old != _nl_default_default_domain)
    free (old);

  return (char *) k_nl_current_default_domain;
}




--- NEW FILE: kckey.h ---
/* this file has been generated by convert_key */

#ifndef _KCKEY_H
#define _KCKEY_H

typedef struct {
	 char name[15];
	 int code;
} KKey;

#define MAX_KEY_LENGTH 15
#define MAX_KEY_MODIFIER_LENGTH 15
#define NB_KEYS 234

extern KKey KKeys[NB_KEYS];

#endif

--- NEW FILE: kprocctrl.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Christian Czezakte (e9025461 at student.tuwien.ac.at)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
//
//  KPROCESSCONTROLLER -- A helper class for KProcess
//
//  version 0.3.1, Jan, 8th 1997
//
//  (C) Christian Czezatke
//  e9025461 at student.tuwien.ac.at
//

#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>

#include <stdio.h>
#include <config.h>
#include "kprocess.h"

#include "kprocctrl.h"

KProcessController *theKProcessController = 0;

KProcessController::KProcessController()
{
  struct sigaction act;

  // initialize theKProcessList
  processList = new QList<KProcess>();
  CHECK_PTR(processList);
 
  if (0 > pipe(fd))
	printf(strerror(errno));
  
  if (-1 == fcntl(fd[0], F_SETFL, O_NONBLOCK))
	printf(strerror(errno));

  notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read);
  notifier->setEnabled(TRUE);
  QObject::connect(notifier, SIGNAL(activated(int)),
				   this, SLOT(slotDoHousekeeping(int)));
 		 
  act.sa_handler=theSigCHLDHandler;
  sigemptyset(&(act.sa_mask));
  sigaddset(&(act.sa_mask), SIGCHLD);
  act.sa_flags = SA_NOCLDSTOP;

  // CC: take care of SunOS which automatically restarts interrupted system
  // calls (and thus does not have SA_RESTART)

#ifdef SA_RESTART
  act.sa_flags |= SA_RESTART;
#endif

  sigaction( SIGCHLD, &act, 0L); 
  act.sa_handler=SIG_IGN;
  sigemptyset(&(act.sa_mask));
  sigaddset(&(act.sa_mask), SIGPIPE);
  act.sa_flags = 0;
  sigaction( SIGPIPE, &act, 0L);
}

#ifdef __sgi__
void KProcessController::theSigCHLDHandler()
#else
void KProcessController::theSigCHLDHandler(int )
#endif
{
  int status;
  pid_t this_pid;
  int saved_errno;

  saved_errno = errno;
  // since waitpid and write change errno, we have to save it and restore it
  // (Richard Stevens, Advanced programming in the Unix Environment)

  // Waba: Check for multiple childs exiting at the same time
  do
  {
    this_pid = waitpid(-1, &status, WNOHANG);
    // J6t: theKProcessController might be already destroyed
    if ((this_pid > 0) && (theKProcessController != 0)) {
      ::write(theKProcessController->fd[1], &this_pid, sizeof(this_pid));
      ::write(theKProcessController->fd[1], &status, sizeof(status));
    }
  }
  while (this_pid > 0); 

  errno = saved_errno;
}



void KProcessController::slotDoHousekeeping(int )
{
  KProcess *proc;
  int bytes_read;
  pid_t pid;
  int status;

  bytes_read  = ::read(fd[0], &pid, sizeof(pid_t));
  bytes_read += ::read(fd[0], &status, sizeof(int));

  if (bytes_read != sizeof(int)+sizeof(pid_t))
	fprintf(stderr,"Error: Could not read info from signal handler!\n");
 
  proc = processList->first();

  while (0L != proc) {
	if (proc->pid == pid) {
	  // process has exited, so do emit the respective events
	  if (proc->run_mode == KProcess::Block) {
	    // If the reads are done blocking then set the status in proc
	    // but do nothing else because KProcess will perform the other
	    // actions of processHasExited.
	    proc->status = status;
	  } else {
	    proc->processHasExited(status);
	  }
	}
	proc = processList->next();
  }
}

KProcessController::~KProcessController()
{
  struct sigaction act;

  notifier->setEnabled(FALSE);

  // Turn off notification for processes that have exited
  act.sa_handler=SIG_IGN;
  sigemptyset(&(act.sa_mask));
  sigaddset(&(act.sa_mask), SIGCHLD);
  act.sa_flags = 0;
  sigaction( SIGCHLD, &act, 0L);
  
  close(fd[0]);
  close(fd[1]);
  delete processList;
  delete notifier;
}
#include "kprocctrl.moc"

--- NEW FILE: kconfig.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
// $Id: kconfig.cpp,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $
//
// $Log: kconfig.cpp,v $
// Revision 1.1  2006-10-03 11:26:26  dslinux_amadeus
// adding pristine copy of pixil to HEAD so I can branch from it
//
// Revision 1.1  2003/09/08 19:42:04  jasonk
// Addition of packages directory and associated files.
//
// Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
// Initial import of PIXIL into new cvs repository.
//
// Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
//
//
// Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
// Initial import of ViewML
//
// Revision 1.21  1999/01/18 10:56:15  kulow
// .moc files are back in kdelibs. Built fine here using automake 1.3
//
// Revision 1.20  1999/01/15 09:30:33  kulow
// it's official - kdelibs builds with srcdir != builddir. For this I
// automocifized it, the generated rules are easier to maintain than
// selfwritten rules. I have to fight with some bugs of this tool, but
// generally it's better than keeping them updated by hand.
//
// Revision 1.19  1999/01/11 13:53:42  kulow
// fixing bug 1311 - don't use data.sprintf("%s", data.data());
// the meaning is undefined
//
// Revision 1.18  1998/11/08 19:06:46  esken
// Several security fixes by adding checkAccess() tests before the creation
// of files and directorys. This is neccesary for SUID programs. Added
// checkAccess(), which checks if the user may write a file.
//
// checkAccess() is a global function, perhaps it should be moved to some
// KTools class as static member funtion later.
//
// Revision 1.17  1998/09/01 20:21:19  kulow
// I renamed all old qt header files to the new versions. I think, this looks
// nicer (and gives the change in configure a sense :)
//
// Revision 1.16  1998/08/23 15:58:32  kulow
// fixed some more advanced warnings
//
// Revision 1.15  1998/07/23 12:05:15  ettrich
// Matthias: small bugfix. Writing of simple KConfig objects (without
//  arguments constructed) was broken.
//
// Revision 1.14  1998/06/15 12:49:31  kulow
// applied patch to replace .kde with localkdedir()
//
// Revision 1.13  1998/05/26 14:14:56  kalle
// Two bugfixes in KConfig:
//
// - security hole when saving to symlinks in SUID mode
// - trailing comma was needed in string list
//
// Revision 1.12  1998/05/04 20:08:12  ettrich
// Matthias: \n, \t, \r are stored as \\n, \\t and \\r now.
//
// Revision 1.11  1998/01/18 14:38:44  kulow
// reverted the changes, Jacek commited.
// Only the RCS comments were affected, but to keep them consistent, I
// thought, it's better to revert them.
// I checked twice, that only comments are affected ;)
//
// Revision 1.9  1997/12/27 22:57:26  kulow
// I was a little bit nerved by the QFile warnings caused by the KApplication
// constructor, so I investigated a little bit ;) Fixed now
//
// Revision 1.8  1997/12/18 20:51:27  kalle
// Some patches by Alex and me
//
// Revision 1.7  1997/11/20 08:44:54  kalle
// Whoever says A should also say B...
// (reading ~/.kderc works again)
//
// Revision 1.6  1997/11/18 21:40:51  kalle
// KApplication::localconfigdir()
// KApplication::localkdedir()
// KConfig searches in $KDEDIR/share/config/kderc
//
// Revision 1.5  1997/10/21 20:44:43  kulow
// removed all NULLs and replaced it with 0L or "".
// There are some left in mediatool, but this is not C++
//
// Revision 1.4  1997/10/16 11:35:25  kulow
// readded my yesterday bugfixes. I hope, I have not forgotten one.
// I'm not sure, why this have been removed, but I'm sure, they are
// needed.
//
// Revision 1.3  1997/10/16 11:14:29  torben
// Kalle: Copyright headers
// kdoctoolbar removed
//
// Revision 1.1  1997/10/04 19:50:58  kalle
// new KConfig
//

#include <kconfig.h>
#include <qfileinfo.h>
#include <stdlib.h>

#include "kapp.h"

#include "config.h"

#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

static const char* aConfigFileName[] = 
{ 
  // !!! If you add/remove pathnames here, update CONFIGFILECOUNT a few lines
  // below!!!
  "/etc/kderc",
  KDEDIR"/share/config/kderc",
  "/usr/lib/KDE/system.kderc",
  "/usr/local/lib/KDE/system.kderc",
  "~/.kderc",
};

const int CONFIGFILECOUNT = 5; // number of entries in aConfigFileName[]


static QString stringToPrintable(const QString& s){
  QString result;
  unsigned int i;
  for (i=0;i<s.length();i++){
    if (s[i] == '\n')
      result.append("\\n");
    else if (s[i] == '\t')
      result.append("\\t");
    else if (s[i] == '\r')
      result.append("\\r");
    else if (s[i] == '\\')
      result.append("\\\\");
    else
      result.insert(result.length(), s[i]);
  }
  return result;
}


KConfig::KConfig( const char* pGlobalAppFile, const char* pLocalAppFile )
{
  if( pGlobalAppFile )
	{
	  data()->aGlobalAppFile = pGlobalAppFile;
	  // the file should exist in any case
	  QFileInfo info( pGlobalAppFile );
	  if( !info.exists() )
		{
		  // Can we allow the write? (see above)
		  if( checkAccess( pGlobalAppFile, W_OK ) )
		    {
		      // Yes, write OK
		      QFile file( pGlobalAppFile );
		      file.open( IO_WriteOnly );
		      file.close();
		    }
		}
	}
  if( pLocalAppFile )
	{
	  data()->aLocalAppFile = pLocalAppFile;
	  // the file should exist in any case
	  QFileInfo info( pLocalAppFile );
	  if( !info.exists() )
		{
		  // Can we allow the write? (see above)
		  if ( checkAccess( pLocalAppFile, W_OK ) )
		    {
		      // Yes, write OK
		      QFile file( pLocalAppFile );
		      file.open( IO_WriteOnly );
                      // Set uid/gid (neccesary for SUID programs)
                      chown(file.name(), getuid(), getgid());
		      file.close();
		    }
		}
	}

  parseConfigFiles();
}


KConfig::~KConfig()
{
  sync();
}


void KConfig::parseConfigFiles()
{
  // Parse all desired files from the least to the most specific. This
  // gives the intended behaviour because the QDict returns the last
  // appropriate entry.
  
  // Parse the general config files
  for( int i = 0; i < CONFIGFILECOUNT; i++ )
    {
      QString aFileName = aConfigFileName[i];
     // replace a leading tilde with the home directory
      // is there a more portable way to find out the home directory?
      char* pHome = getenv( "HOME" );
      if( (aFileName[0] == '~') && pHome )
		aFileName.replace( 0, 1, pHome );

      QFile aConfigFile( aFileName );
      QFileInfo aInfo( aConfigFile );
      // only work with existing files currently
      if( !aInfo.exists() )
		continue;
      aConfigFile.open( IO_ReadOnly );
      parseOneConfigFile( aConfigFile, 0L, true ); 
	  aConfigFile.close();
    }
  
  // Parse app-specific config files if available
  if( !data()->aGlobalAppFile.isEmpty() )
	{
	  QFile aConfigFile( data()->aGlobalAppFile );
	  // we can already be sure that this file exists
	  aConfigFile.open( IO_ReadOnly );
	  parseOneConfigFile( aConfigFile, 0L, false );
	  aConfigFile.close();
	}
  if( !data()->aLocalAppFile.isEmpty() )
	{
	  QFile aConfigFile( data()->aLocalAppFile );
	  // we can already be sure that this file exists
 	  /* Actually, we can't: CHange by Alex */
 	  if (!aConfigFile.open( IO_ReadOnly)) {
		QString tmp = data()->aLocalAppFile.copy();
		data()->aLocalAppFile.sprintf("%s/share/config/%s",KApplication::localkdedir().data(),tmp.data());
 		aConfigFile.close();
 		aConfigFile.setName(data()->aLocalAppFile.data());
 		aConfigFile.open(IO_ReadOnly);
 	  } 

	  parseOneConfigFile( aConfigFile, 0L, false );
	  aConfigFile.close();
	}
}


bool KConfig::writeConfigFile( QFile& rConfigFile, bool bGlobal )
{
  bool bEntriesLeft = false;

  QTextStream* pStream = new QTextStream( &rConfigFile );

  // create a temporary dictionary that represents the file to be written
  QDict<KEntryDict> aTempDict( 37, FALSE );
  aTempDict.setAutoDelete( true );
  
  // setup a group entry for the default group
  KEntryDict* pDefGroup = new KEntryDict( 37, false );
  pDefGroup->setAutoDelete( true );
  aTempDict.insert( "<default>", pDefGroup );
  
  // fill the temporary structure with entries from the file
  parseOneConfigFile( rConfigFile, &aTempDict, bGlobal );

  // augment this structure with the dirty entries from the normal structure
  QDictIterator<KEntryDict> aIt( data()->aGroupDict );

  // loop over all the groups
  const char* pCurrentGroup;
  while( (pCurrentGroup = aIt.currentKey()) )
	{
	  QDictIterator<KEntryDictEntry> aInnerIt( *aIt.current() );
	  // loop over all the entries
	  KEntryDictEntry* pCurrentEntry;
	  while( (pCurrentEntry = aInnerIt.current()) )
		{
		  if( pCurrentEntry->bDirty )
			{
			  // only write back entries that have the same
			  // "globality" as the file
			  if( pCurrentEntry->bGlobal == bGlobal )
				{
				  // enter the
				  // *aInnerIt.currentKey()/pCurrentEntry->aValue pair
				  // into group *pCurrentGroup in aTempDict
				  KEntryDict* pTempGroup;
				  if( !( pTempGroup = aTempDict[ pCurrentGroup ] ) )
					{
					  // group does not exist in aTempDict
					  pTempGroup = new KEntryDict( 37, false );
					  pTempGroup->setAutoDelete( true );
					  aTempDict.insert( pCurrentGroup, pTempGroup );
					}
				  KEntryDictEntry* pNewEntry = new KEntryDictEntry();
				  pNewEntry->aValue = pCurrentEntry->aValue;
				  pNewEntry->bDirty = false;
				  pNewEntry->bGlobal = pCurrentEntry->bGlobal;
				  pNewEntry->bNLS = pCurrentEntry->bNLS;
				  pTempGroup->replace( aInnerIt.currentKey(), 
									   pNewEntry );
				}
			  else
				// wrong "globality" - might have to be saved later
				bEntriesLeft = true;
			}
		  ++aInnerIt;
		}
	  ++aIt;
	}
  // truncate file
  delete pStream;
  rConfigFile.close();

  /* Does program run SUID and user would not be allowed to write 
   * to the file, if it doesn't run  SUID?
   */
  if( ! checkAccess( rConfigFile.name(), W_OK ) ) // write not allowed
    return false; // can't allow to write config data.


  rConfigFile.open( IO_Truncate | IO_WriteOnly );
  // Set uid/gid (neccesary for SUID programs)
  chown(rConfigFile.name(), getuid(), getgid());
 
  pStream = new QTextStream( &rConfigFile );
  
  // write a magic cookie for Fritz' mime magic
  *pStream << "# KDE Config File\n";

  // write back -- start with the default group
  KEntryDict* pDefWriteGroup = aTempDict[ "<default>" ];
  if( pDefWriteGroup )
	{
	  QDictIterator<KEntryDictEntry> aWriteInnerIt( *pDefWriteGroup );
	  while( aWriteInnerIt.current() )
		{
		  if( aWriteInnerIt.current()->bNLS && 
			  QString( aWriteInnerIt.currentKey() ).right( 1 ) != "]" )
			// not yet localized, but should be
			*pStream << aWriteInnerIt.currentKey() << '[' 
					 << data()->aLocaleString << ']' << "=" 
					 << stringToPrintable(aWriteInnerIt.current()->aValue) << '\n';
		  else
			// need not be localized or already is
			*pStream << aWriteInnerIt.currentKey() << "=" 
					 << stringToPrintable(aWriteInnerIt.current()->aValue) << '\n';
		  ++aWriteInnerIt;
		}
	}
  
  QDictIterator<KEntryDict> aWriteIt( aTempDict );
  while( aWriteIt.current() )
	{
	  // check if it's not the default group (which has already been written)
	  if( strcmp (aWriteIt.currentKey(), "<default>" ) )
		{
		  *pStream << '[' << aWriteIt.currentKey() << ']' << '\n';
		  QDictIterator<KEntryDictEntry> aWriteInnerIt( *aWriteIt.current() );
		  while( aWriteInnerIt.current() )
			{
			  if( aWriteInnerIt.current()->bNLS && 
				  QString( aWriteInnerIt.currentKey() ).right( 1 ) != "]" )
				// not yet localized, but should be
				*pStream << aWriteInnerIt.currentKey() << '[' 
						 << data()->aLocaleString << ']' << "=" 
						 << stringToPrintable(aWriteInnerIt.current()->aValue) << '\n';
			  else
				// need not be localized or already is
				*pStream << aWriteInnerIt.currentKey() << "="
						 << stringToPrintable(aWriteInnerIt.current()->aValue) << '\n';
			  ++aWriteInnerIt;
			}
		}
	  ++aWriteIt;
	}
  
  // clean up
  delete pStream;
  rConfigFile.close();


  // Reopen the config file.

  // Can we allow the write? (see above)
  if( checkAccess( rConfigFile.name(), W_OK ) )
    // Yes, write OK
    rConfigFile.open( IO_ReadWrite );
  else
    rConfigFile.open( IO_ReadOnly );
  
  return bEntriesLeft;
}


void KConfig::sync()
{
  // write-sync is only necessary if there are dirty entries
  if( data()->bDirty ) 
	{
	  bool bEntriesLeft = true;
	  bool bLocalGood = false;

	  // find out the file to write to (most specific writable file)
	  // try local app-specific file first
	  if( !data()->aLocalAppFile.isEmpty() )
	    {
	      // Can we allow the write? We can, if the program
	      // doesn't run SUID. But if it runs SUID, we must
	      // check if the user would be allowed to write if
	      // it wasn't SUID.
	      if( checkAccess( data()->aLocalAppFile, W_OK ) ) // we would be allowed anyhow
		{    
		  // is it writable?
		  QFile aConfigFile( data()->aLocalAppFile );
		  aConfigFile.open( IO_ReadWrite );
                  // Set uid/gid (neccesary for SUID programs)
                  chown(aConfigFile.name(), getuid(), getgid());
 
		  if ( aConfigFile.isWritable() )
		    {
		      bEntriesLeft = writeConfigFile( aConfigFile, false );   
		      bLocalGood = true;
		    }
		  aConfigFile.close();
		}
	    }

	  // If we could not write to the local app-specific config file,
	  // we can try the global app-specific one. This will only work
	  // as root, but is worth a try.
	  if( !bLocalGood && !data()->aGlobalAppFile.isEmpty() )
	    {
	      // Can we allow the write? (see above)
	      if( checkAccess( data()->aGlobalAppFile, W_OK ) )
		{    
		  // is it writable?
		  QFile aConfigFile( data()->aGlobalAppFile );
		  aConfigFile.open( IO_ReadWrite );
		  if ( aConfigFile.isWritable() )
		    {
		      bEntriesLeft = writeConfigFile( aConfigFile, false );   
		      bLocalGood = true;
		    }
		  aConfigFile.close();
		}
	    }

	  if( bEntriesLeft )
		// If there are entries left, either something went wrong with
		// the app-specific files or there were global entries to write.
		{
		  // try other files
		  for( int i = CONFIGFILECOUNT-1; i >= 0; i-- )
			{
			  QString aFileName = aConfigFileName[i];
			  // replace a leading tilde with the home directory
			  // is there a more portable way to find out the home directory?
			  char* pHome = getenv( "HOME" );
			  if( (aFileName[0] == '~') && pHome )
				aFileName.replace( 0, 1, pHome );
	  
			  QFile aConfigFile( aFileName );
			  QFileInfo aInfo( aConfigFile );
			  // can we allow the write? (see above)
			  if( checkAccess ( aFileName, W_OK ) )
			    {

			      if( ( aInfo.exists() && aInfo.isWritable() ) ||
				  ( !aInfo.exists() && 
				    QFileInfo( aInfo.dirPath( true ) ).isWritable() ) )
				{
				  aConfigFile.open( IO_ReadWrite );
                                  // Set uid/gid (neccesary for SUID programs)
                                  chown(aConfigFile.name(), getuid(), getgid());
 				  writeConfigFile( aConfigFile, true );
				  break;
				}
			    }
			}
		}
	}

  // no more dirty entries
  rollback();
}
#include "kconfig.moc"


--- NEW FILE: TODO ---
- hierarchical config entries (how?)
- compilation to binary format

--- NEW FILE: kstdaccel.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Stefan Taferner (taferner at alpin.or.at)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include "kstdaccel.h"
#include "kapp.h"
#include "kconfig.h"

KStdAccel::KStdAccel(KConfig* /* cfg */) //: KKeyConfig(cfg)
{
  config = new KConfig; // we want the global stuff, and only the global stuff
  config->setGroup("Standard Keys");
}

KStdAccel::~KStdAccel()
{
    delete config;
}

uint KStdAccel::readKey(KAccel::StdAccel accel, uint defaultKey) const
{
  QString s = config->readEntry(KAccel::stdAction(accel));
  int v = stringToKey(s.data());
  return v?v:defaultKey;

}

uint KStdAccel::open(void) const
{
  return readKey(KAccel::Open, CTRL+Key_O);
}

uint KStdAccel::openNew(void) const
{
  return readKey(KAccel::New, CTRL+Key_N);
}

uint KStdAccel::close(void) const
{
  return readKey(KAccel::Close, CTRL+Key_W);
}

uint KStdAccel::save(void) const
{
  return readKey(KAccel::Save, CTRL+Key_S);
}

uint KStdAccel::print(void) const
{
  return readKey(KAccel::Print, CTRL+Key_P);
}

uint KStdAccel::quit(void) const
{
  return readKey(KAccel::Quit, CTRL+Key_Q);
}

uint KStdAccel::cut(void) const
{
  return readKey(KAccel::Cut, CTRL+Key_X);
}

uint KStdAccel::copy(void) const
{
  return readKey(KAccel::Copy, CTRL+Key_C);
}

uint KStdAccel::paste(void) const
{
  return readKey(KAccel::Paste, CTRL+Key_V);
}

uint KStdAccel::undo(void) const
{
  return readKey(KAccel::Undo, CTRL+Key_Z);
}

uint KStdAccel::find(void) const
{
  return readKey(KAccel::Find, CTRL+Key_F);
}

uint KStdAccel::replace(void) const
{
  return readKey(KAccel::Replace, CTRL+Key_R);
}

uint KStdAccel::insert(void) const
{
  return readKey(KAccel::Insert, CTRL+Key_Insert);
}

uint KStdAccel::home(void) const
{
  return readKey(KAccel::Home, CTRL+Key_Home);
}

uint KStdAccel::end(void) const
{
  return readKey(KAccel::End, CTRL+Key_End);
}

uint KStdAccel::prior(void) const
{
  return readKey(KAccel::Prior, Key_Prior);
}

uint KStdAccel::next(void) const
{
  return readKey(KAccel::Next, Key_Next);
}

uint KStdAccel::help(void) const
{
  return readKey(KAccel::Help, Key_F1);
}


--- NEW FILE: kchartables.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Jacek Konieczny (jajcus at zeus.polsl.gliwice.pl)
    $Id: kchartables.cpp,v 1.1 2006-10-03 11:26:26 dslinux_amadeus Exp $

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
	*/

#include "kcharsetsdata.h"
#include "qfont.h"

static const unsigned us_ascii_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
static const unsigned iso_8859_1_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x00a1,0x00a2,0x00a3,0x00a4,0x00a5,0x00a6,0x00a7,
	0x00a8,0x00a9,0x00aa,0x00ab,0x00ac,0x00ad,0x00ae,0x00af,
	0x00b0,0x00b1,0x00b2,0x00b3,0x00b4,0x00b5,0x00b6,0x00b7,
	0x00b8,0x00b9,0x00ba,0x00bb,0x00bc,0x00bd,0x00be,0x00bf,
	0x00c0,0x00c1,0x00c2,0x00c3,0x00c4,0x00c5,0x00c6,0x00c7,
	0x00c8,0x00c9,0x00ca,0x00cb,0x00cc,0x00cd,0x00ce,0x00cf,
	0x00d0,0x00d1,0x00d2,0x00d3,0x00d4,0x00d5,0x00d6,0x00d7,
	0x00d8,0x00d9,0x00da,0x00db,0x00dc,0x00dd,0x00de,0x00df,
	0x00e0,0x00e1,0x00e2,0x00e3,0x00e4,0x00e5,0x00e6,0x00e7,
	0x00e8,0x00e9,0x00ea,0x00eb,0x00ec,0x00ed,0x00ee,0x00ef,
	0x00f0,0x00f1,0x00f2,0x00f3,0x00f4,0x00f5,0x00f6,0x00f7,
	0x00f8,0x00f9,0x00fa,0x00fb,0x00fc,0x00fd,0x00fe,0x00ff};
static const unsigned iso_8859_2_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x0104,0x02d8,0x0141,0x00a4,0x013d,0x015a,0x00a7,
	0x00a8,0x0160,0x015e,0x0164,0x0179,0x00ad,0x017d,0x017b,
	0x00b0,0x0105,0x02db,0x0142,0x00b4,0x013e,0x015b,0x02c7,
	0x00b8,0x0161,0x015f,0x0165,0x017a,0x02dd,0x017e,0x017c,
	0x0154,0x00c1,0x00c2,0x0102,0x00c4,0x0139,0x0106,0x00c7,
	0x010c,0x00c9,0x0118,0x00cb,0x011a,0x00cd,0x00ce,0x010e,
	0x0110,0x0143,0x0147,0x00d3,0x00d4,0x0150,0x00d6,0x00d7,
	0x0158,0x016e,0x00da,0x0170,0x00dc,0x00dd,0x0162,0x00df,
	0x0155,0x00e1,0x00e2,0x0103,0x00e4,0x013a,0x0107,0x00e7,
	0x010d,0x00e9,0x0119,0x00eb,0x011b,0x00ed,0x00ee,0x010f,
	0x0111,0x0144,0x0148,0x00f3,0x00f4,0x0151,0x00f6,0x00f7,
	0x0159,0x016f,0x00fa,0x0171,0x00fc,0x00fd,0x0163,0x02d9};
static const unsigned iso_8859_3_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x0126,0x02d8,0x00a3,0x00a4,0x0000,0x0124,0x00a7,
	0x00a8,0x0130,0x015e,0x011e,0x0134,0x00ad,0x0000,0x017b,
	0x00b0,0x0127,0x00b2,0x00b3,0x00b4,0x00b5,0x0125,0x00b7,
	0x00b8,0x0131,0x015f,0x011f,0x0135,0x00bd,0x0000,0x017c,
	0x00c0,0x00c1,0x00c2,0x0000,0x00c4,0x010a,0x0108,0x00c7,
	0x00c8,0x00c9,0x00ca,0x00cb,0x00cc,0x00cd,0x00ce,0x00cf,
	0x0000,0x00d1,0x00d2,0x00d3,0x00d4,0x0120,0x00d6,0x00d7,
	0x011c,0x00d9,0x00da,0x00db,0x00dc,0x016c,0x015c,0x00df,
	0x00e0,0x00e1,0x00e2,0x0000,0x00e4,0x010b,0x0109,0x00e7,
	0x00e8,0x00e9,0x00ea,0x00eb,0x00ec,0x00ed,0x00ee,0x00ef,
	0x0000,0x00f1,0x00f2,0x00f3,0x00f4,0x0121,0x00f6,0x00f7,
	0x011d,0x00f9,0x00fa,0x00fb,0x00fc,0x016d,0x015d,0x02d9};
static const unsigned iso_8859_4_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x0104,0x0138,0x0156,0x00a4,0x0128,0x013b,0x00a7,
	0x00a8,0x0160,0x0112,0x0122,0x0166,0x00ad,0x017d,0x00af,
	0x00b0,0x0105,0x02db,0x0157,0x00b4,0x0129,0x013c,0x02c7,
	0x00b8,0x0161,0x0113,0x0123,0x0167,0x014a,0x017e,0x014b,
	0x0100,0x00c1,0x00c2,0x00c3,0x00c4,0x00c5,0x00c6,0x012e,
	0x010c,0x00c9,0x0118,0x00cb,0x0116,0x00cd,0x00ce,0x012a,
	0x0110,0x0145,0x014c,0x0136,0x00d4,0x00d5,0x00d6,0x00d7,
	0x00d8,0x0172,0x00da,0x00db,0x00dc,0x0168,0x016a,0x00df,
	0x0101,0x00e1,0x00e2,0x00e3,0x00e4,0x00e5,0x00e6,0x012f,
	0x010d,0x00e9,0x0119,0x00eb,0x0117,0x00ed,0x00ee,0x012b,
	0x0111,0x0146,0x014d,0x0137,0x00f4,0x00f5,0x00f6,0x00f7,
	0x00f8,0x0173,0x00fa,0x00fb,0x00fc,0x0169,0x016b,0x02d9};
static const unsigned iso_8859_5_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x0401,0x0402,0x0403,0x0404,0x0405,0x0406,0x0407,
	0x0408,0x0409,0x040a,0x040b,0x040c,0x00ad,0x040e,0x040f,
	0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,
	0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,0x041f,
	0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,
	0x0428,0x0429,0x042a,0x042b,0x042c,0x042d,0x042e,0x042f,
	0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,
	0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,0x043f,
	0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,
	0x0448,0x0449,0x044a,0x044b,0x044c,0x044d,0x044e,0x044f,
	0x2116,0x0451,0x0452,0x0453,0x0454,0x0455,0x0456,0x0457,
	0x0458,0x0459,0x045a,0x045b,0x045c,0x00a7,0x045e,0x045f};
static const unsigned iso_8859_6_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0660,0x0661,0x0662,0x0663,0x0664,0x0665,0x0666,0x0667,
	0x0668,0x0669,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x0000,0x0000,0x0000,0x00a4,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x060c,0x00ad,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x061b,0x0000,0x0000,0x0000,0x061f,
	0x0000,0x0621,0x0622,0x0623,0x0624,0x0625,0x0626,0x0627,
	0x0628,0x0629,0x062a,0x062b,0x062c,0x062d,0x062e,0x062f,
	0x0630,0x0631,0x0632,0x0633,0x0634,0x0635,0x0636,0x0637,
	0x0638,0x0639,0x063a,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0640,0x0641,0x0642,0x0643,0x0644,0x0645,0x0646,0x0647,
	0x0648,0x0649,0x064a,0x064b,0x064c,0x064d,0x064e,0x064f,
	0x0650,0x0651,0x0652,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
static const unsigned iso_8859_7_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x02bd,0x02bc,0x00a3,0x0000,0x0000,0x00a6,0x00a7,
	0x00a8,0x00a9,0x0000,0x00ab,0x00ac,0x00ad,0x0000,0x2015,
	0x00b0,0x00b1,0x00b2,0x00b3,0x0384,0x0385,0x0386,0x00b7,
	0x0388,0x0389,0x038a,0x00bb,0x038c,0x00bd,0x038e,0x038f,
	0x0390,0x0391,0x0392,0x0393,0x0394,0x0395,0x0396,0x0397,
	0x0398,0x0399,0x039a,0x039b,0x039c,0x039d,0x039e,0x039f,
	0x03a0,0x03a1,0x0000,0x03a3,0x03a4,0x03a5,0x03a6,0x03a7,
	0x03a8,0x03a9,0x03aa,0x03ab,0x03ac,0x03ad,0x03ae,0x03af,
	0x03b0,0x03b1,0x03b2,0x03b3,0x03b4,0x03b5,0x03b6,0x03b7,
	0x03b8,0x03b9,0x03ba,0x03bb,0x03bc,0x03bd,0x03be,0x03bf,
	0x03c0,0x03c1,0x03c2,0x03c3,0x03c4,0x03c5,0x03c6,0x03c7,
	0x03c8,0x03c9,0x03ca,0x03cb,0x03cc,0x03cd,0x03ce,0x0000};
static const unsigned iso_8859_8_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F,
	0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,
	0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,
	0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,
	0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F,
	0x00A0,0x00A1,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7,
	0x00A8,0x00A9,0x00D7,0x00AB,0x00AC,0x00AD,0x00AE,0x203E,
	0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7,
	0x00B8,0x00B9,0x00F7,0x00BB,0x00BC,0x00BD,0x00BE,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2017,
	0x05D0,0x05D1,0x05D2,0x05D3,0x05D4,0x05D5,0x05D6,0x05D7,
	0x05D8,0x05D9,0x05DA,0x05DB,0x05DC,0x05DD,0x05DE,0x05DF,
	0x05E0,0x05E1,0x05E2,0x05E3,0x05E4,0x05E5,0x05E6,0x05E7,
	0x05E8,0x05E9,0x05EA,0x0000,0x0000,0x0000,0x0000,0x0000};
static const unsigned iso_8859_9_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x00a0,0x00a1,0x00a2,0x00a3,0x00a4,0x00a5,0x00a6,0x00a7,
	0x00a8,0x00a9,0x00aa,0x00ab,0x00ac,0x00ad,0x00ae,0x00af,
	0x00b0,0x00b1,0x00b2,0x00b3,0x00b4,0x00b5,0x00b6,0x00b7,
	0x00b8,0x00b9,0x00ba,0x00bb,0x00bc,0x00bd,0x00be,0x00bf,
	0x00c0,0x00c1,0x00c2,0x00c3,0x00c4,0x00c5,0x00c6,0x00c7,
	0x00c8,0x00c9,0x00ca,0x00cb,0x00cc,0x00cd,0x00ce,0x00cf,
	0x011e,0x00d1,0x00d2,0x00d3,0x00d4,0x00d5,0x00d6,0x00d7,
	0x00d8,0x00d9,0x00da,0x00db,0x00dc,0x0130,0x015e,0x00df,
	0x00e0,0x00e1,0x00e2,0x00e3,0x00e4,0x00e5,0x00e6,0x00e7,
	0x00e8,0x00e9,0x00ea,0x00eb,0x00ec,0x00ed,0x00ee,0x00ef,
	0x011f,0x00f1,0x00f2,0x00f3,0x00f4,0x00f5,0x00f6,0x00f7,
	0x00f8,0x00f9,0x00fa,0x00fb,0x00fc,0x0131,0x015f,0x00ff};
static const unsigned koi8_r_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0022,0x00a4,0x0024,0x0025,0x0026,0x0027,
	0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
	0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,
	0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
	0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,
	0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
	0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
	0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
	0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
	0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x044e,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,
	0x0445,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,
	0x043f,0x044f,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432,
	0x044c,0x044b,0x0437,0x0448,0x044d,0x0449,0x0447,0x044a,
	0x042e,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,
	0x0425,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,
	0x041f,0x042f,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412,
	0x042c,0x042b,0x0417,0x0428,0x042d,0x0429,0x0427,0x0000};

static const unsigned symbol_tbl[]={
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0020,0x0021,0x0000,0x0023,0x2203,0x0025,0x0026,0x0000,
	0x0028,0x0029,0x2217,0x002b,0x002c,0x002d,0x002e,0x002f,
	0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,
	0x0038,0x0039,0x003a,0x0045,0x003c,0x003d,0x003e,0x003f,
	0x0000,0x0391,0x0392,0x03a7,0x0394,0x0395,0x03a6,0x0393,
	0x0397,0x0399,0x03b8,0x039a,0x039b,0x039c,0x039d,0x039f,
	0x03a0,0x0398,0x03a1,0x03a3,0x03a4,0x03a5,0x03f2,0x03a9,
	0x039e,0x03a8,0x0396,0x005b,0x2234,0x005d,0x0000,0x005f,
	0x0000,0x03b1,0x03b2,0x03c7,0x03b4,0x03b5,0x03c6,0x03b3,
	0x03b7,0x03b9,0x03c6,0x03ba,0x03bb,0x03bc,0x03bd,0x03bf,
	0x03c0,0x03b8,0x03c1,0x03c3,0x03c4,0x03c5,0x03c9,0x03c9,
	0x03be,0x03c8,0x03b6,0x0000,0x007c,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x03d2,0x0000,0x2264,0x2044,0x221e,0x221e,0x2263,
	0x2666,0x2665,0x2660,0x2194,0x2190,0x2191,0x2192,0x2193,
	0x00b0,0x00b1,0x0000,0x2265,0x00d7,0x221d,0x2202,0x2022,
	0x2223,0x2260,0x224d,0x2245,0x2026,0x0000,0x0000,0x240d,
	0x0000,0x0000,0x0000,0x0000,0x2297,0x2295,0x2205,0x2229,
	0x222a,0x2283,0x0000,0x2284,0x2282,0x0000,0x2208,0x2209,
	0x2220,0x0000,0x00ae,0x00a9,0x2122,0x0000,0x0000,0x22c5,
	0x00ac,0x2227,0x2228,0x21d4,0x21d0,0x21d1,0x21d2,0x21d3,
	0x25ca,0x0000,0x0000,0x0000,0x0000,0x2211,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x222b,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
static const unsigned null_tbl[]={0};

KCharsetEntry KCharsetsData::charsets[]={
    	{ "us-ascii",QFont::AnyCharSet,us_ascii_tbl,TRUE,0,0},
   	{ "iso-8859-1",QFont::ISO_8859_1,iso_8859_1_tbl,TRUE,0,0},
    	{ "iso-8859-2",QFont::ISO_8859_2,iso_8859_2_tbl,TRUE,0,0},
    	{ "iso-8859-3",QFont::ISO_8859_3,iso_8859_3_tbl,TRUE,0,0},
    	{ "iso-8859-4",QFont::ISO_8859_4,iso_8859_4_tbl,TRUE,0,0},
    	{ "iso-8859-5",QFont::ISO_8859_5,iso_8859_5_tbl,TRUE,0,0},
    	{ "iso-8859-6",QFont::ISO_8859_6,iso_8859_6_tbl,TRUE,0,0},
    	{ "iso-8859-7",QFont::ISO_8859_7,iso_8859_7_tbl,TRUE,0,0},
    	{ "iso-8859-8",QFont::ISO_8859_8,iso_8859_8_tbl,TRUE,0,0},
    	{ "iso-8859-9",QFont::ISO_8859_9,iso_8859_9_tbl,TRUE,0,0},
    	{ "adobe-symbol",QFont::AnyCharSet,symbol_tbl,FALSE,0,0},
//    	{ "koi8-r",QFont::AnyCharSet,koi8_r_tbl,TRUE,0,0},
#if QT_VERSION >= 140	
    	{ "koi8-r",QFont::KOI8R,koi8_r_tbl,TRUE,0,0},
#else	
    	{ "koi8-r",QFont::AnyCharSet,koi8_r_tbl,TRUE,0,0},
#endif	
//     	{ "unicode-1-1-utf-7",QFont::AnyCharSet,null_tbl,TRUE}, // not supported yet 
       	{ "unicode-1-1-utf-8",QFont::AnyCharSet,null_tbl,TRUE,0,0},
       	{ "unicode-1-1",QFont::AnyCharSet,null_tbl,FALSE,0,0},      // not really supported, but maybe it works
       	{0,QFont::AnyCharSet,null_tbl,FALSE,0,0}};


const KCharTags KCharsetsData::tags[]={
	{"AElig",0x00c6},
	{"Aacute",0x00c1},
	{"Acirc",0x00c2},
	{"Agrave",0x00c0},
	{"Alpha",0x0391},
	{"AMP",38},
	{"Aring",0x00c5},
	{"Atilde",0x00c3},
	{"Auml",0x00c4},
	{"Beta",0x0392},
	{"Ccedil",0x00c7},
	{"Chi",0x03a7},
	{"Dagger",0x2021},
	{"Delta",0x0394},
	{"ETH",0x00d0},
	{"Eacute",0x00c9},
	{"Ecirc",0x00ca},
	{"Egrave",0x00c8},
	{"Epsilon",0x0395},
	{"Eta",0x0397},
	{"Euml",0x00cb},
	{"Gamma",0x0393},
	{"GT",62},
	{"Iacute",0x00cd},
	{"Icirc",0x00ce},
	{"Igrave",0x00cc},
	{"Iota",0x0399},
	{"Iuml",0x00cf},
	{"Kappa",0x039a},
	{"Lambda",0x039b},
	{"LT",60},
	{"Mu",0x039c},
	{"Ntilde",0x00d1},
	{"Nu",0x039d},
	{"OElig",0x0152},
	{"Oacute",0x00d3},
	{"Ocirc",0x00d4},
	{"Ograve",0x00d2},
	{"Omega",0x03a9},
	{"Omicron",0x039f},
	{"Oslash",0x00d8},
	{"Otilde",0x00d5},
	{"Ouml",0x00d6},
	{"Phi",0x03a6},
	{"Pi",0x03a0},
	{"Prime",0x2033},
	{"Psi",0x03a8},
	{"QUOT",34},
	{"Rho",0x03a1},
	{"Scaron",0x0160},
	{"Sigma",0x03a3},
	{"THORN",0x00de},
	{"Tau",0x03a4},
	{"Theta",0x0398},
	{"Uacute",0x00da},
	{"Ucirc",0x00db},
	{"Ugrave",0x00d9},
	{"Upsilon",0x03a5},
	{"Uuml",0x00dc},
	{"Xi",0x039e},
	{"Yacute",0x00dd},
	{"Yuml",0x0178},
	{"Zeta",0x0396},
	{"aacute",0x00e1},
	{"acirc",0x00e2},
	{"acute",0x00b4},
	{"aelig",0x00e6},
	{"agrave",0x00e0},
	{"alefsym",0x2135},
	{"alpha",0x03b1},
	{"amp",38},
	{"and",0x22a5},
	{"ang",0x2220},
	{"aring",0x00e5},
	{"asymp",0x2248},
	{"atilde",0x00e3},
	{"auml",0x00e4},
	{"bdquo",0x201e},
	{"beta",0x03b2},
	{"brvbar",0x00a6},
	{"bull",0x2022},
	{"cap",0x2229},
	{"ccedil",0x00e7},
	{"cedil",0x00b8},
	{"cent",0x00a2},
	{"chi",0x03c7},
	{"circ",0x02c6},
	{"clubs",0x2663},
	{"cong",0x2245},
	{"copy",0x00a9},
	{"crarr",0x21b5},
	{"cup",0x222a},
	{"curren",0x00a4},
	{"dArr",0x21d3},
	{"dagger",0x2020},
	{"darr",0x2193},
	{"deg",0x00b0},
	{"delta",0x03b4},
	{"diams",0x2666},
	{"divide",0x00f7},
	{"eacute",0x00e9},
	{"ecirc",0x00ea},
	{"egrave",0x00e8},
	{"empty",0x2205},
	{"emsp",0x2003},
	{"ensp",0x2002},
	{"epsilon",0x03b5},
	{"equiv",0x2261},
	{"eta",0x03b7},
	{"eth",0x00f0},
	{"euml",0x00eb},
	{"exist",0x2203},
	{"fnof",0x0192},
	{"forall",0x2200},
	{"frac12",0x00bd},
	{"frac14",0x00bc},
	{"frac34",0x00be},
	{"frasl",0x2044},
	{"gamma",0x03b3},
	{"ge",0x2265},
	{"gt",62},
	{"hArr",0x21d4},
	{"harr",0x2194},
	{"hearts",0x2665},
	{"hellip",0x2026},
	{"iacute",0x00ed},
	{"icirc",0x00ee},
	{"iexcl",0x00a1},
	{"igrave",0x00ec},
	{"image",0x2111},
	{"infin",0x221e},
	{"int",0x222b},
	{"iota",0x03b9},
	{"iquest",0x00bf},
	{"isin",0x2208},
	{"iuml",0x00ef},
	{"kappa",0x03ba},
	{"lArr",0x21d0},
	{"lambda",0x03bb},
	{"lang",0x2329},
	{"laquo",0x00ab},
	{"larr",0x2190},
	{"lceil",0x2308},
	{"ldquo",0x201c},
	{"le",0x2264},
	{"lfloor",0x230a},
	{"lowast",0x2217},
	{"loz",0x25ca},
	{"lrm",0x200e},
	{"lsaquo",0x2039},
	{"lsquo",0x2018},
	{"lt",60},
	{"macr",0x00af},
	{"mdash",0x2014},
	{"micro",0x00b5},
	{"middot",0x00b7},
	{"minus",0x2212},
	{"mu",0x03bc},
	{"nabla",0x2207},
	{"nbsp",0x00a0},
	{"ndash",0x2013},
	{"ne",0x2260},
	{"ni",0x220b},
	{"not",0x00ac},
	{"notin",0x2209},
	{"nsub",0x2284},
	{"ntilde",0x00f1},
	{"nu",0x03bd},
	{"oacute",0x00f3},
	{"ocirc",0x00f4},
	{"oelig",0x0153},
	{"ograve",0x00f2},
	{"oline",0x203e},
	{"omega",0x03c9},
	{"omicron",0x03bf},
	{"oplus",0x2295},
	{"or;",0x22a6},
	{"ordf",0x00aa},
	{"ordm",0x00ba},
	{"oslash",0x00f8},
	{"otilde",0x00f5},
	{"otimes",0x2297},
	{"ouml",0x00f6},
	{"para",0x00b6},
	{"part",0x2202},
	{"permil",0x2030},
	{"perp",0x22a5},
	{"phi",0x03c6},
	{"pi;",0x03c0},
	{"piv",0x03d6},
	{"plusmn",0x00b1},
	{"pound",0x00a3},
	{"prime",0x2032},
	{"prod",0x220f},
	{"prop",0x221d},
	{"psi",0x03c8},
	{"quot",34},
	{"rArr",0x21d2},
	{"radic",0x221a},
	{"rang",0x232a},
	{"raquo",0x00bb},
	{"rarr",0x2192},
	{"rceil",0x2309},
	{"rdquo",0x201d},
	{"real",0x211c},
	{"reg",0x00ae},
	{"rfloor",0x230b},
	{"rho",0x03c1},
	{"rlm",0x200f},
	{"rsaquo",0x203a},
	{"rsquo",0x2019},
	{"sbquo",0x201a},
	{"scaron",0x0161},
	{"sdot",0x22c5},
	{"sect",0x00a7},
	{"shy",0x00ad},
	{"sigma",0x03c3},
	{"sigmaf",0x03c2},
	{"sim",0x223c},
	{"spades",0x2660},
	{"sub",0x2282},
	{"sube",0x2286},
	{"sum",0x2211},
	{"sup1",0x00b9},
	{"sup2",0x00b2},
	{"sup3",0x00b3},
	{"sup",0x2283},
	{"supe",0x2287},
	{"szlig",0x00df},
	{"tau",0x03c4},
	{"there4",0x2234},
	{"theta",0x03b8},
	{"thetasym",0x03d1},
	{"thinsp",0x2009},
	{"thorn",0x00fe},
	{"tilde",0x02dc},
	{"times",0x00d7},
	{"trade",0x2122},
	{"uArr",0x21d1},
	{"uacute",0x00fa},
	{"uarr",0x2191},
	{"ucirc",0x00fb},
	{"ugrave",0x00f9},
	{"uml",0x00a8},
	{"upsih",0x03d2},
	{"upsilon",0x03c5},
	{"uuml",0x00fc},
	{"weierp",0x2118},
	{"xi",0x03be},
	{"yacute",0x00fd},
	{"yen",0x00a5},
	{"yuml",0x00ff},
	{"zeta",0x03b6},
	{"zwj",0x200d},
	{"zwnj",0x200c}};

const unsigned int KCharsetsData::nrOfTags = sizeof(tags) / sizeof(KCharTags);

--- NEW FILE: ksock.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Torben Weis (weis at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
/*
 * $Id: ksock.cpp,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
 * $Log: ksock.cpp,v $
 * Revision 1.1  2006-10-03 11:26:27  dslinux_amadeus
 * adding pristine copy of pixil to HEAD so I can branch from it
 *
 * Revision 1.1  2003/09/08 19:42:05  jasonk
 * Addition of packages directory and associated files.
 *
 * Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
 * Initial import of PIXIL into new cvs repository.
 *
 * Revision 1.1.1.1  2003/06/23 22:04:23  jasonk
 *
 *
 * Revision 1.1.1.1  2000/07/07 16:10:59  jasonk
 * Initial import of ViewML
 *
 * Revision 1.24.4.5  1999/08/23 09:16:04  waba
 * WABA: Don't kill the application upon problems.
 *
 * Revision 1.24.4.4  1999/07/09 21:16:41  porten
 * patch for bug #1336,1549 from Ingo <schneidi at informatik.tu-muenchen.de>
 *
 * Revision 1.24.4.3  1999/04/18 19:49:23  kulow
 * fixing bug reported by litsch.iep at t-online.de (Stephan Litsch)
 *
 * Revision 1.24.4.2  1999/04/01 20:43:44  pbrown
 * socket patch from Dirk A. Mueller <dmuell at gmx.net>, forwarded to kde-devel
 * by Torben, applied.
 *
 * Revision 1.24.4.1  1999/02/24 12:49:17  dfaure
 * getdtablesize() -> getrlimit(). Fixes #447 and removes a #ifdef HPUX.
 *
 * Revision 1.25  1999/02/24 12:47:34  dfaure
 * getdtablesize() -> getrlimit(). Fixes #447 and removes a #ifdef HPUX.
 *
 * Revision 1.24  1999/01/18 10:56:25  kulow
 * .moc files are back in kdelibs. Built fine here using automake 1.3
 *
 * Revision 1.23  1999/01/15 09:30:42  kulow
 * it's official - kdelibs builds with srcdir != builddir. For this I
 * automocifized it, the generated rules are easier to maintain than
 * selfwritten rules. I have to fight with some bugs of this tool, but
 * generally it's better than keeping them updated by hand.
 *
 * Revision 1.22  1999/01/11 23:09:51  thufir
 * fix: fixes bug where it would loop n - tries, after a successful connect (would cause a pause after successful connect)
 *
 * Revision 1.21  1998/11/11 00:02:54  thufir
 * addes ability to set a connect Time Out, breaks binary compatability
 *
 * Revision 1.20  1998/08/02 14:49:31  kalle
 * ANother try at the socket problem. Hope that this works on _all_ platforms now.
 *
 * Revision 1.19  1998/07/29 12:39:17  kalle
 * Don't hardcode maximum of pending connections in listen(). Should work on all platforms including QNX.
 *
 * Revision 1.18  1998/02/20 02:37:25  torben
 * Torben: Fixes permissions
 *
 * Revision 1.17  1998/01/23 11:25:28  kulow
 * Solaris doesn't define UNIX_PATH_MAX
 *
 * Revision 1.16  1998/01/23 02:23:38  torben
 * Torben: Supports UNIX domain sockets now.
 *
 * Revision 1.15  1998/01/18 14:39:03  kulow
 * reverted the changes, Jacek commited.
 * Only the RCS comments were affected, but to keep them consistent, I
 * thought, it's better to revert them.
 * I checked twice, that only comments are affected ;)
 *
 * Revision 1.13  1997/12/18 01:56:24  torben
 * Torben: Secure string operations. Use instead of QString::sprintf
 *
 * Revision 1.12  1997/11/29 17:58:48  kalle
 * Alpha patches
 *
 * Revision 1.11  1997/11/09 01:52:47  torben
 * Torben: Fixed port number bug
 *
 * Revision 1.10  1997/10/21 20:44:52  kulow
 * removed all NULLs and replaced it with 0L or "".
 * There are some left in mediatool, but this is not C++
 *
 * Revision 1.9  1997/10/16 11:15:03  torben
 * Kalle: Copyright headers
 * kdoctoolbar removed
 *
 * Revision 1.8  1997/09/18 12:16:04  kulow
 * corrected some header dependencies. Removed most of them in drag.h and put
 * them in drag.cpp. Now it should compile even under SunOS 4.4.1 ;)
 *
 * Revision 1.7  1997/08/30 08:32:54  kdecvs
 * Coolo: changed the location of the include files to get rid of the
 * hardcoded HAVE_STDC_HEADERS
 *
 * Revision 1.6  1997/07/27 13:43:58  kalle
 * Even more SGI and SCC patches, security patch for kapp, various fixes for ksock
 *
 * Revision 1.5  1997/07/17 18:43:18  kalle
 * Kalle: new stopsign.xpm
 * 			KConfig: environment variables are resolved in readEntry()
 * 			(meaning you can write() an entry with an environment
 * 			variable and read it back in, and the value gets properly
 * 			expanded).
 * 			Fixed three bugs in ksock.cpp
 * 			Added KFloater
 * 			Added KCombo
 * 			Added KLineEdit
 * 			New KToolbar
 * 			New KToplevelWidget
 *
 * Revision 1.4  1997/05/30 20:04:38  kalle
 * Kalle:
 * 30.05.97:	signal handler for reaping zombie help processes reinstalls itself
 * 		patch to KIconLoader by Christian Esken
 * 		slightly better look for KTabCtl
 * 		kdecore Makefile does not expect current dir to be in path
 * 		Better Alpha support
 *
 * Revision 1.3  1997/05/09 15:10:11  kulow
 * Coolo: patched ltconfig for FreeBSD
 * removed some stupid warnings
 *
 * Revision 1.2  1997/04/28 06:57:46  kalle
 * Various widgets moved from apps to libs
 * Added KSeparator
 * Several bugs fixed
 * Patches from Matthias Ettrich
 * Made ksock.cpp more alpha-friendly
 * Removed XPM-Loading from KPixmap
 * Reaping zombie KDEHelp childs
 * WidgetStyle of KApplication objects configurable via kdisplay
 */

#include <qapplication.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <errno.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYSENT_H
#include <sysent.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
#ifdef HAVE_SYS_SOCKET_H
// on Linux/libc5, this includes linux/socket.h where SOMAXCONN is defined
#include <sys/socket.h>
#endif
// Play it safe, use a reasonable default, if SOMAXCONN was nowhere defined.
#ifndef SOMAXCONN
#warning Your header files do not seem to support SOMAXCONN
#define SOMAXCONN 5
#endif

#include <sys/resource.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <signal.h>

#include "ksock.h"

#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108 // this is the value, I found under Linux
#endif

KSocket::KSocket( const char *_host, unsigned short int _port, int _timeout ) :
  sock( -1 ), readNotifier( 0L ), writeNotifier( 0L )
{
    timeOut = _timeout;
    domain = PF_INET;
    connect( _host, _port );
}

KSocket::KSocket( const char *_host, unsigned short int _port ) :
  sock( -1 ), readNotifier( 0L ), writeNotifier( 0L )
{
    timeOut = 30;
    domain = PF_INET;
    connect( _host, _port );
}

KSocket::KSocket( const char *_path ) :
  sock( -1 ), readNotifier( 0L ), writeNotifier( 0L )
{
  domain = PF_UNIX;
  connect( _path );
}

void KSocket::enableRead( bool _state )
{
  if ( _state )
    {
	  if ( !readNotifier  )
		{
		  readNotifier = new QSocketNotifier( sock, QSocketNotifier::Read );
		  QObject::connect( readNotifier, SIGNAL( activated(int) ), this, SLOT( slotRead(int) ) );
		}
	  else
	    readNotifier->setEnabled( true );
    }
  else if ( readNotifier )
	readNotifier->setEnabled( false );
}

void KSocket::enableWrite( bool _state )
{
  if ( _state )
    {
	  if ( !writeNotifier )
		{
		  writeNotifier = new QSocketNotifier( sock, QSocketNotifier::Write );
		  QObject::connect( writeNotifier, SIGNAL( activated(int) ), this, 
							SLOT( slotWrite(int) ) );
		}
	  else
	    writeNotifier->setEnabled( true );
    }
  else if ( writeNotifier )
	writeNotifier->setEnabled( false );
}

void KSocket::slotRead( int )
{
  char buffer[2];
  
  int n = recv( sock, buffer, 1, MSG_PEEK );
  if ( n <= 0 )
	emit closeEvent( this );
  else
	emit readEvent( this );
}

void KSocket::slotWrite( int )
{
  emit writeEvent( this );
}

/*
 * Initializes a sockaddr structure. Do this after creating a socket and
 * before connecting to any other socket. Here you must specify the
 * host and port you want to connect to.
 */
bool KSocket::init_sockaddr( const char *hostname, unsigned short int port )
{
  if ( domain != PF_INET )
    return false;
  
  struct hostent *hostinfo;
  server_name.sin_family = AF_INET;
  server_name.sin_port = htons( port );
  hostinfo = gethostbyname( hostname );
  
  if ( !hostinfo )
    {
	  warning("Unknown host %s.\n",hostname);
	  return false;	
    }
  server_name.sin_addr = *(struct in_addr*) hostinfo->h_addr;    
  
  return true;
}

/*
 * Connects the PF_UNIX domain socket to _path.
 */
bool KSocket::connect( const char *_path )
{
  if ( domain != PF_UNIX )
    fatal( "Connecting a PF_INET socket to a PF_UNIX domain socket\n");
  
  unix_addr.sun_family = AF_UNIX;
  int l = strlen( _path );
  if ( l > UNIX_PATH_MAX - 1 )
  {      
    warning( "Too long PF_UNIX domain name '%s'\n",_path);
    return false;
  }  
  strcpy( unix_addr.sun_path, _path );

  sock = ::socket(PF_UNIX,SOCK_STREAM,0);
  if (sock < 0)
	return false;
  
  if ( 0 > ::connect( sock, (struct sockaddr*)(&unix_addr), 
					  sizeof( unix_addr ) ) )
  {
      ::close( sock );
      sock = -1;
      return false;
  }

  return true;
}

/*
 * Connects the socket to _host, _port.
 */
bool KSocket::connect( const char *_host, unsigned short int _port )
{
  if ( domain != PF_INET )
    fatal( "Connecting a PF_UNIX domain socket to a PF_INET domain socket\n");

  sock = ::socket(PF_INET,SOCK_STREAM,0);
  if (sock < 0)
	return false;
  
  if ( !init_sockaddr( _host, _port) )
	{
	  ::close( sock );
	  sock = -1;
	  return false;
	}

  fcntl(sock,F_SETFL,(fcntl(sock,F_GETFL)|O_NDELAY));

  errno = 0;
  if (::connect(sock, (struct sockaddr*)(&server_name), sizeof(server_name))){
      if(errno != EINPROGRESS && errno != EWOULDBLOCK){
          ::close( sock );
          sock = -1;
          return false;
      }
  }else
      return true;

  fd_set rd, wr;
  struct timeval timeout;
  int ret = 0, n;

  n = timeOut;
  FD_ZERO(&rd);
  FD_ZERO(&wr);
  FD_SET(sock, &rd);
  FD_SET(sock, &wr);
//  printf("timeout=%d\n", n);
  while(n--){
      timeout.tv_usec = 0;
      timeout.tv_sec = 1;

      struct rlimit rlp;
      getrlimit(RLIMIT_NOFILE, &rlp); // getdtablesize() equivalent. David Faure.

      ret = select(rlp.rlim_cur, (fd_set *)&rd, (fd_set *)&wr, (fd_set *)0,
                   (struct timeval *)&timeout);
      // if(ret)
      //    return(true);

      switch (ret)
      {
	  case 0: break; // Timeout
	  case 1: case 2: return(true); // Success
	  default: // Error
	      ::close(sock);
	      sock = -1;
	      return false;
      }

      qApp->processEvents();
      qApp->flushX();
  }
  warning("Timeout connecting socket...\n");
  ::close( sock );
  sock = -1;
  return false;
}

unsigned long KSocket::getAddr()
{
  if ( domain != PF_INET )
    return 0;
  
  struct sockaddr_in name; ksize_t len = sizeof(name);
  getsockname(sock, (struct sockaddr *) &name, &len);
  return ntohl(name.sin_addr.s_addr);
}

KSocket::~KSocket()
{
    if ( readNotifier )
    {
	delete readNotifier;
    }
    if ( writeNotifier )
	delete writeNotifier; 
  
    ::close( sock ); 
}


KServerSocket::KServerSocket( const char *_path ) :
  notifier( 0L), sock( -1 )
{
  domain = PF_UNIX;
  
  if ( !init ( _path ) )
  {
    // fatal("Error constructing PF_UNIX domain server socket\n");
    return;
  }
    
  notifier = new QSocketNotifier( sock, QSocketNotifier::Read );
  connect( notifier, SIGNAL( activated(int) ), this, SLOT( slotAccept(int) ) );
}

KServerSocket::KServerSocket( int _port ) :
  notifier( 0L ), sock( -1 )
{
  domain = PF_INET;

  if ( !init ( _port ) )
  {
    // fatal("Error constructing\n");
    return;
  }
    
  notifier = new QSocketNotifier( sock, QSocketNotifier::Read );
  connect( notifier, SIGNAL( activated(int) ), this, SLOT( slotAccept(int) ) );
}

bool KServerSocket::init( const char *_path )
{
  if ( domain != PF_UNIX )
    return false;
  
  int l = strlen( _path );
  if ( l > UNIX_PATH_MAX - 1 )
  {      
    warning( "Too long PF_UNIX domain name '%s'\n",_path);
    return false;
  }  
    
  sock = ::socket( PF_UNIX, SOCK_STREAM, 0 );
  if (sock < 0)
  {
    warning( "Could not create socket\n");
    return false;
  }

  unlink(_path);   

  struct sockaddr_un name;
  name.sun_family = AF_UNIX;
  strcpy( name.sun_path, _path );
    
  if ( bind( sock, (struct sockaddr*) &name,sizeof( name ) ) < 0 )
  {
    warning("Could not bind to socket\n");
    ::close( sock );
    sock = -1;
    return false;
  }
  
  if ( chmod( _path, 0600) < 0 )
  {
    warning("Could not setupt premissions for server socket\n");
    ::close( sock );
    sock = -1;
    return false;
  }
               
  if ( listen( sock, SOMAXCONN ) < 0 )
  {
    warning("Error listening on socket\n");
    ::close( sock );
    sock = -1;
    return false;
  }

  return true;
}

bool KServerSocket::init( unsigned short int _port )
{
  if ( domain != PF_INET )
    return false;
  
  sock = ::socket( PF_INET, SOCK_STREAM, 0 );
  if (sock < 0)
  {
    warning( "Could not create socket\n");
    return false;
  }

  struct sockaddr_in name;
    
  name.sin_family = AF_INET;
  name.sin_port = htons( _port );
  name.sin_addr.s_addr = htonl(INADDR_ANY);
    
  if ( bind( sock, (struct sockaddr*) &name,sizeof( name ) ) < 0 )
    {
	  warning("Could not bind to socket\n");
	  ::close( sock );
	  sock = -1;
	  return false;
    }
    
  if ( listen( sock, SOMAXCONN ) < 0 )
    {
	  warning("Error listening on socket\n");
	  ::close( sock );
	  sock = -1;
	  return false;
    }

  return true;
}

unsigned short KServerSocket::getPort()
{
  if ( domain != PF_INET )
    return false;

  struct sockaddr_in name; ksize_t len = sizeof(name);
  getsockname(sock, (struct sockaddr *) &name, &len);
  return ntohs(name.sin_port);
}

unsigned long KServerSocket::getAddr()
{
  if ( domain != PF_INET )
    return false;

  struct sockaddr_in name; ksize_t len = sizeof(name);
  getsockname(sock, (struct sockaddr *) &name, &len);
  return ntohl(name.sin_addr.s_addr);
}

void KServerSocket::slotAccept( int )
{
  if ( domain == PF_INET )
  {      
    struct sockaddr_in clientname;
    int new_sock;
    
    ksize_t size = sizeof(clientname);
    
    if ((new_sock = accept (sock, (struct sockaddr *) &clientname, &size)) < 0)
    {
      warning("Error accepting\n");
      return;
    }

    emit accepted( new KSocket( new_sock ) );
  }
  else if ( domain == PF_UNIX )
  {      
    struct sockaddr_un clientname;
    int new_sock;
    
    ksize_t size = sizeof(clientname);
    
    if ((new_sock = accept (sock, (struct sockaddr *) &clientname, &size)) < 0)
    {
      warning("Error accepting\n");
      return;
    }

    emit accepted( new KSocket( new_sock ) );
  }
}

KServerSocket::~KServerSocket()
{
  if ( notifier )
	delete notifier; 
  struct sockaddr_un name; ksize_t len = sizeof(name);
  getsockname(sock, (struct sockaddr *) &name, &len);
  close( sock );
  unlink(name.sun_path);                                                       
}

#include "ksock.moc"

--- NEW FILE: kdebugdialog.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Kalle Dalheimer (kalle at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
#ifndef _KDEBUGDIALOG
#define _KDEBUGDIALOG

#include <qdialog.h>
#include <qlineedit.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qgroupbox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>

class KDebugDialog : public QDialog
{
  Q_OBJECT

private:
  QGroupBox* pInfoGroup;
  QLabel* pInfoLabel1;
  QComboBox* pInfoCombo;
  QLabel* pInfoLabel2;
  QLineEdit* pInfoFile;
  QLabel* pInfoLabel3;
  QLineEdit* pInfoShow;
  QGroupBox* pWarnGroup;
  QLabel* pWarnLabel1;
  QComboBox* pWarnCombo;
  QLabel* pWarnLabel2;
  QLineEdit* pWarnFile;
  QLabel* pWarnLabel3;
  QLineEdit* pWarnShow;
  QGroupBox* pErrorGroup;
  QLabel* pErrorLabel1;
  QComboBox* pErrorCombo;
  QLabel* pErrorLabel2;
  QLineEdit* pErrorFile;
  QLabel* pErrorLabel3;
  QLineEdit* pErrorShow;
  QGroupBox* pFatalGroup;
  QLabel* pFatalLabel1;
  QComboBox* pFatalCombo;
  QLabel* pFatalLabel2;
  QLineEdit* pFatalFile;
  QLabel* pFatalLabel3;
  QLineEdit* pFatalShow;

  QCheckBox* pAbortFatal;
  QPushButton* pOKButton;
  QPushButton* pCancelButton;
  QPushButton* pHelpButton;

public:
  KDebugDialog();
  ~KDebugDialog();

  void setInfoOutput( int n )
	{ pInfoCombo->setCurrentItem( n ); }
  int infoOutput() const
	{ return pInfoCombo->currentItem(); }
  void setInfoFile( const char* pFileName )
	{ pInfoFile->setText( pFileName ); }
  const char* infoFile() const
	{ return pInfoFile->text(); }
  void setInfoShow( const char* pShowString )
	{ pInfoShow->setText( pShowString ); }
  const char* infoShow() const
	{ return pInfoShow->text(); }
  void setWarnOutput( int n )
	{ pWarnCombo->setCurrentItem( n ); }
  int warnOutput() const
	{ return pWarnCombo->currentItem(); }
  void setWarnFile( const char* pFileName )
	{ pWarnFile->setText( pFileName ); }
  const char* warnFile() const
	{ return pWarnFile->text(); }
  void setWarnShow( const char* pShowString )
	{ pWarnShow->setText( pShowString ); }
  const char* warnShow() const
	{ return pWarnShow->text(); }
  void setErrorOutput( int n )
	{ pErrorCombo->setCurrentItem( n ); }
  int errorOutput() const
	{ return pErrorCombo->currentItem(); }
  void setErrorFile( const char* pFileName )
	{ pErrorFile->setText( pFileName ); }
  const char* errorFile() const
	{ return pErrorFile->text(); }
  void setErrorShow( const char* pShowString )
	{ pErrorShow->setText( pShowString ); }
  const char* errorShow() const
	{ return pErrorShow->text(); }
  void setFatalOutput( int n )
	{ pFatalCombo->setCurrentItem( n ); }
  int fatalOutput() const
	{ return pFatalCombo->currentItem(); }
  void setFatalFile( const char* pFileName )
	{ pFatalFile->setText( pFileName ); }
  const char* fatalFile() const
	{ return pFatalFile->text(); }
  void setFatalShow( const char* pShowString )
	{ pFatalShow->setText( pShowString ); }
  const char* fatalShow() const
	{ return pFatalShow->text(); }
  void setAbortFatal( bool bAbort )
	{ pAbortFatal->setChecked( bAbort ); }
  bool abortFatal() const
	{ return pAbortFatal->isChecked(); }

public slots:
  void showHelp();

private:
  // Disallow assignment and copy-construction
  KDebugDialog( const KDebugDialog& );
  KDebugDialog& operator= ( const KDebugDialog& );
};

#endif

--- NEW FILE: kaccel.cpp ---
/*
    Copyright (C) 1998 Mark Donohoe <donohoe at kde.org>
    Copyright (C) 1997 Nicolas Hadacek <hadacek at via.ecp.fr>
    Copyright (C) 1998 Matthias Ettrich <ettrich at kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <qkeycode.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qapplication.h>
#include <qdrawutil.h>
#include <qmessagebox.h>

#include <kapp.h>
#include <kdebug.h>

#include "kaccel.h"

KAccel::KAccel( QWidget * parent, const char * name ):
  aKeyDict(100){
	aAvailableId = 1;
	bEnabled = true;
	aGroup = "Keys";
	bGlobal = false;
	pAccel = new QAccel( parent, name );
}

KAccel::~KAccel()
{
  delete pAccel;
}

void KAccel::clear()
{
	pAccel->clear();
	aKeyDict.clear();
}

void KAccel::connectItem( const char * action,
			  const QObject* receiver, const char* member,
			  bool activate )
{
  if (!action)
    return;
    KKeyEntry *pEntry = aKeyDict[ action ];

	if ( !pEntry ) {
		QString str;
		str.sprintf( "KAccel : Cannot connect action %s ", action );
		str.append( "which is not in the object dictionary" );
		warning(str);
		return;
	}
	
	pEntry->receiver = receiver;
	pEntry->member = member;
	pEntry->aAccelId = aAvailableId;
	aAvailableId++;
	
	pAccel->insertItem( pEntry->aCurrentKeyCode, pEntry->aAccelId );
	pAccel->connectItem( pEntry->aAccelId, receiver, member );
	
	if ( !activate )
		setItemEnabled( action, FALSE );
}

void KAccel::connectItem( StdAccel accel,
			  const QObject* receiver, const char* member,
			  bool activate ){
  if (stdAction(accel) && !aKeyDict[ stdAction(accel) ]){
    insertStdItem(accel);
  }
  connectItem(stdAction(accel), receiver, member, activate);
}

uint KAccel::count() const
{
	return aKeyDict.count();
}

uint KAccel::currentKey( const char * action )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( !pEntry )
		return 0;
	else
		return pEntry->aCurrentKeyCode;
}

const char*  KAccel::description( const char * action ){
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( !pEntry )
		return 0;
	else
		return pEntry->descr;
}

uint KAccel::defaultKey( const char * action )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( !pEntry )
        return 0;
    else
        return pEntry->aDefaultKeyCode;
}

void  KAccel::disconnectItem( const char * action,
			      const QObject* receiver, const char* member )
{
    KKeyEntry *pEntry = aKeyDict[ action ];
    if ( !pEntry )
		return;
	
	pAccel->disconnectItem( pEntry->aAccelId, receiver, member  );
}

const char * KAccel::findKey( int key ) const
{
	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
#define pE aKeyIt.current()
	while ( pE ) {
		if ( (unsigned int)key == pE->aCurrentKeyCode ) return aKeyIt.currentKey();
		++aKeyIt;
	}
#undef pE
	return 0;	
}

bool KAccel::insertItem( const char* descr, const char * action, uint keyCode,
			 bool configurable )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( pEntry )
		removeItem( action );

	pEntry = new KKeyEntry;
	aKeyDict.insert( action, pEntry );
	
	pEntry->aDefaultKeyCode = keyCode;
	pEntry->aCurrentKeyCode = keyCode;
	pEntry->aConfigKeyCode = keyCode;
	pEntry->bConfigurable = configurable;
	pEntry->aAccelId = 0;
	pEntry->receiver = 0;
	pEntry->member = 0;
	pEntry->descr = descr;
	
	return TRUE;
}

bool KAccel::insertItem( const char* descr, const char * action,
					   const char * keyCode, bool configurable )
{
	uint iKeyCode = stringToKey( keyCode );
	return insertItem( descr, action, iKeyCode, configurable );
}


bool KAccel::insertItem( const char * action, uint keyCode,
			 bool configurable )
{
    return insertItem(action, action, keyCode, configurable);
}


void KAccel::changeMenuAccel ( QPopupMenu *menu, int id,
	const char *action )
{
	QString s = menu->text( id );
	if ( !s ) return;
	if (!action) return;
	
	int i = s.find('\t');
	
	QString k = keyToString( currentKey( action), true );
	if( !k ) return;
	
	if ( i >= 0 )
		s.replace( i+1, s.length()-i, k );
	else {
		s += '\t';
		s += k;
	}

	QPixmap *pp = menu->pixmap(id);
	if(pp && !pp->isNull())
	  menu->changeItem( *pp, s, id );
	else
	  menu->changeItem( s, id );
}

void KAccel::changeMenuAccel ( QPopupMenu *menu, int id,
			       StdAccel accel ){
  changeMenuAccel(menu, id, stdAction(accel));
}


bool KAccel::insertStdItem( StdAccel id, const char* descr )
{
	const char *key=0, *name = 0;
	switch( id ) {
		case Open:
			name=i18n("Open") ;
			key = "CTRL+O";
			break;
		case New:
			name=i18n("New") ;
			key = "CTRL+N";
			break;
		case Close:
			name=i18n("Close") ;
			key = "CTRL+W";
			break;
		case Save:
			name=i18n("Save") ;
			key = "CTRL+S";
			break;
		case Print:
			name=i18n("Print") ;
			key = "CTRL+P";
			break;
		case Quit:
			name=i18n("Quit") ;
			key = "CTRL+Q";
			break;
		case Cut:
			name=i18n("Cut") ;
			key = "CTRL+X";
			break;
		case Copy:
			name=i18n("Copy") ;
			key = "CTRL+C";
			break;
		case Paste:
			name=i18n("Paste") ;
			key = "CTRL+V";
			break;
		case Undo:
			name=i18n("Undo") ;
			key = "CTRL+Z";
			break;
		case Find:
			name=i18n("Find") ;
			key = "CTRL+F";
			break;
		case Replace:
			name=i18n("Replace") ;
			key = "CTRL+R";
			break;
		case Insert:
			name=i18n("Insert") ;
			key = "CTRL+Insert";
			break;
		case Home:
			name=i18n("Home") ;
			key = "CTRL+Home";
			break;
		case End:
			name=i18n("End") ;
			key = "CTRL+End";
			break;
		case Prior:
			name=i18n("Prior") ;
			key = "Prior";
			break;
		case Next:
			name=i18n("Next") ;
			key = "Next";
			break;
		case Help:
			name=i18n("Help") ;
			key = "F1";
			break;
		default:
			return false;
			break;
	}
	return insertItem( descr?descr:name, stdAction(id), key, false );
}

bool KAccel::isEnabled()
{
	return bEnabled;
}

bool KAccel::isItemEnabled( const char *action )
{
	KKeyEntry *pEntry = aKeyDict[ action ];
	
	if ( !pEntry )
        return false;
    else
        return pEntry->bEnabled;
}

QDict<KKeyEntry> KAccel::keyDict()
{
	return aKeyDict;
}

void KAccel::readSettings(KConfig* config)
{
	QString s;

	KConfig *pConfig = config?config:kapp->getConfig();
	pConfig->setGroup( aGroup.data() );
	
	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
#define pE aKeyIt.current()
	while ( pE ) {
		s = pConfig->readEntry( aKeyIt.currentKey() );
		
		if ( s.isNull() )
			pE->aConfigKeyCode = pE->aDefaultKeyCode;
		else
			pE->aConfigKeyCode = stringToKey( s.data() );
	
		pE->aCurrentKeyCode = pE->aConfigKeyCode;
		if ( pE->aAccelId && pE->aCurrentKeyCode ) {
			pAccel->disconnectItem( pE->aAccelId, pE->receiver,
						pE->member );
			pAccel->removeItem( pE->aAccelId );
			pAccel->insertItem( pE->aCurrentKeyCode, pE->aAccelId );
			pAccel->connectItem( pE->aAccelId, pE->receiver,
					     pE->member);
		}
		++aKeyIt;
	}
#undef pE
}

void KAccel::removeItem( const char * action )
{

    KKeyEntry *pEntry = aKeyDict[ action ];
	
    if ( !pEntry )
		return;
	
	if ( pEntry->aAccelId ) {
		pAccel->disconnectItem( pEntry->aAccelId, pEntry->receiver,
					pEntry->member);
		pAccel->removeItem( pEntry->aAccelId );
	}
	
	aKeyDict.remove( action );
}

void KAccel::setEnabled( bool activate )
{
	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
#define pE aKeyIt.current()
	while ( pE ) {
		setItemEnabled( aKeyIt.currentKey(), activate );
		++aKeyIt;
	}
#undef pE
	bEnabled = activate;
}

void KAccel::setItemEnabled( const char * action, bool activate )
{	
    KKeyEntry *pEntry = aKeyDict[ action ];
	if ( !pEntry ) {
		QString str;
		str.sprintf(
			"KAccel : cannont enable action %s"\
			"which is not in the object dictionary", action );
		warning( str );
		return;
	}

	pAccel->setItemEnabled( pEntry->aAccelId, activate );
}

bool KAccel::setKeyDict( QDict<KKeyEntry> nKeyDict )
{

	kdebug(KDEBUG_INFO, 125, "Disconenct and remove");
	// Disconnect and remove all items in pAccel
	QDictIterator<KKeyEntry> *aKeyIt = new QDictIterator<KKeyEntry>( aKeyDict );
	aKeyIt->toFirst();
#define pE aKeyIt->current()
	while( pE ) {
		QString s;
		if ( pE->aAccelId && pE->aCurrentKeyCode ) {
			pAccel->disconnectItem( pE->aAccelId, pE->receiver,
						pE->member );
			pAccel->removeItem( pE->aAccelId );
		}
		++*aKeyIt;
	}
#undef pE
	
	kdebug(KDEBUG_INFO, 125, "Clear the dictionary");
	
	// Clear the dictionary
	aKeyDict.clear();
	
	kdebug(KDEBUG_INFO, 125, "Insert new items");
	
	// Insert the new items into the dictionary and reconnect if neccessary
	// Note also swap config and current key codes !!!!!!
	delete aKeyIt; // tanghus
	aKeyIt = new QDictIterator<KKeyEntry>( nKeyDict );
	aKeyIt->toFirst();
#define pE aKeyIt->current()
	KKeyEntry *pEntry;
	while( pE ) {
		pEntry = new KKeyEntry;
		aKeyDict.insert( aKeyIt->currentKey(), pEntry );
		pEntry->aDefaultKeyCode = pE->aDefaultKeyCode;
		// Note we write config key code to current key code !!
		pEntry->aCurrentKeyCode = pE->aConfigKeyCode;
		pEntry->aConfigKeyCode = pE->aConfigKeyCode;
		pEntry->bConfigurable = pE->bConfigurable;
		pEntry->aAccelId = pE->aAccelId;
		pEntry->receiver = pE->receiver;
		pEntry->member = pE->member;
		pEntry->descr = pE->descr; // tanghus
		
		if ( pEntry->aAccelId && pEntry->aCurrentKeyCode ) {
			pAccel->insertItem( pEntry->aCurrentKeyCode, pEntry->aAccelId );
			pAccel->connectItem( pEntry->aAccelId, pEntry->receiver,
					     pEntry->member);
		}
		++*aKeyIt;
	}
#undef pE
		
	delete aKeyIt; // tanghus
	return true;
}

const char * KAccel::stdAction( StdAccel id ) {
	const char* action = 0;
	switch( id ) {
		case Open:
			action = "Open";
			break;
		case New:
			action = "New";
			break;
		case Close:
			action = "Close";
			break;
		case Save:
			action = "Save";
			break;
		case Print:
			action = "Print";
			break;
		case Quit:
			action = "Quit";
			break;
		case Cut:
			action = "Cut";
			break;
		case Copy:
			action = "Copy";
			break;
		case Paste:
			action = "Paste";
			break;
		case Undo:
			action = "Undo";
			break;
		case Find:
			action = "Find";
			break;
		case Replace:
			action = "Replace";
			break;
		case Insert:
			action = "Insert";
			break;
		case Home:
			action = "Home";
			break;
		case End:
			action = "End";
			break;
		case Prior:
			action = "Prior";
			break;
		case Next:
			action = "Next";
			break;
		case Help:
			action = "Help";
			break;
		default:
			return 0;
			break;
	}
	return action;
}

void KAccel::setConfigGroup( const char *group )
{
	aGroup = group;
}

void KAccel::setConfigGlobal( bool global )
{
	bGlobal = global;
}

const char *KAccel::configGroup()
{
	return aGroup.data();
}

bool KAccel::configGlobal()
{
	return bGlobal;
}

void KAccel::writeSettings(KConfig* config)
{
	KConfig *pConfig = config?config:kapp->getConfig();
	pConfig->setGroup( aGroup.data() );

	QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
	aKeyIt.toFirst();
	while ( aKeyIt.current() ) {
		if ( aKeyIt.current()->bConfigurable ) {
			if ( bGlobal )
				pConfig->writeEntry( aKeyIt.currentKey(),
					keyToString( aKeyIt.current()->aCurrentKeyCode),
					true, true );
			 else
				pConfig->writeEntry( aKeyIt.currentKey(),
					keyToString( aKeyIt.current()->aCurrentKeyCode ));
		}
		++aKeyIt;
	}
	pConfig->sync();
}

/*****************************************************************************/

const QString keyToString( uint keyCode, bool i18_n )
{
	QString res;
	
	if ( keyCode == 0 ) {
		res = "";
		return res;
	}
	if (!i18_n){
	  if ( keyCode & SHIFT ){
	    res += ("SHIFT");
	    res += "+";
	  }
	  if ( keyCode & CTRL ){
	    res +=("CTRL");
	    res += "+";
	  }
	  if ( keyCode & ALT ){
	    res +=("ALT");
	    res += "+";
	  }
	}
	else {
	  if ( keyCode & SHIFT ){
	    res = i18n("SHIFT");
	    res += "+";
	  }
	  if ( keyCode & CTRL ){
	    res += i18n("CTRL");
	    res += "+";
	  }
	  if ( keyCode & ALT ){
	    res += i18n("ALT");
	    res += "+";
	  }
	}

	uint kCode = keyCode & ~(SHIFT | CTRL | ALT);

	for (int i=0; i<NB_KEYS; i++) {
		if ( kCode == (uint)KKeys[i].code ) {
			res += KKeys[i].name;
			return res;
		}
	}
	
	return 0;
}

uint stringToKey(const char * key )
{
	char *toks[4], *next_tok;
	uint keyCode = 0;
	int j, nb_toks = 0;
	char sKey[200];
	
	//printf("string to key %s\n", key);
	if ( key == 0 ) { kdebug(KDEBUG_WARN, 125, "stringToKey::Null key");return 0; }
	if( strcmp( key, "" ) == -1 ) { kdebug(KDEBUG_WARN, 125, "stringToKey::Empty key");return 0; }
	
	strncpy(sKey, (const char *)key, 200);
	next_tok = strtok(sKey,"+");
	
	if ( next_tok== 0L ) return 0;
	
	do {
		toks[nb_toks] = next_tok;
		nb_toks++;
		if ( nb_toks==5 ) return 0;
		next_tok = strtok(0L, "+");
	} while ( next_tok!=0L );
	
	/* we test if there is one and only one key (the others tokens
	   are accelerators) ; we also fill the keycode with infos */
	bool  keyFound = FALSE;
	for (int i=0; i<nb_toks; i++) {
		if ( strcmp(toks[i], "SHIFT")==0 )
		  keyCode |= SHIFT;
		else if ( strcmp(toks[i], "CTRL")==0 )
		  keyCode |= CTRL;
		else if ( strcmp(toks[i], "ALT")==0 )
		  keyCode |= ALT;
		else if ( strcmp(toks[i], "Umschalt")==0 )
		  keyCode |= SHIFT;
		else if ( strcmp(toks[i], "Strg")==0 )
		  keyCode |= CTRL;
		else if ( strcmp(toks[i], "Alt")==0 )
		  keyCode |= ALT;
		else if ( strcmp(toks[i], i18n("SHIFT"))==0 )
		  keyCode |= SHIFT;
		else if ( strcmp(toks[i], i18n("CTRL"))==0 )
		  keyCode |= CTRL;
		else if ( strcmp(toks[i], i18n("ALT"))==0 )
		  keyCode |= ALT;
	    else {
			/* key already found ? */
			if ( keyFound ) return 0;
			keyFound = TRUE;
			
			/* search key */
			for(j=0; j<NB_KEYS; j++) {
				if ( strcmp(toks[i], KKeys[j].name)==0 ) {
				    keyCode |= KKeys[j].code;
					break;
				}
			}
			
			/* key name ot found ? */
			if ( j==NB_KEYS ) return 0;
		}
	}
	
	return keyCode;
}

--- NEW FILE: kwm.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Matthias Ettrich (ettrich at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
/*
 * Kwm.h. Part of the KDE project.
 */

#ifndef KWM_H
#define KWM_H

#include <qstring.h>
#include <qapplication.h>
#include <qpixmap.h>
#include <X11/Xlib.h>

#ifdef raise
#undef raise
#endif

/**
 * The class KWM allows usual X11 clients to get or modify window
 * properties and to interact with the windowmanager. It also offers
 * some high level functions to support the easy implementation of
 * session managment.
 * @short class for interaction with the window- and sessionmanager
 * @author Matthias Ettrich (ettrich at kde.org)
 */
class KWM {

public:

  /**
   * Return all window properties needed to restore a window in
   * a string. The string can be used as a command line argument
   * for the session management (See setWmCommand below).  */
  static QString getProperties(Window w);

  /**
   * Apply properties from a property string to a window. This will
   * have an immediate effect if the window is already managed by the
   * window manager (that means it is either in Normal- or in
   * IconicState). If the window is still WithDrawn, the windowmanager
   * will apply the properties when the window is mapped (This happens
   * for example with a QWidget::show() ). If setProperties is used
   * for session management, you should call it first and map the
   * window later, since this avoids unnecessary flickering.
   *
   * setProperties returns the geometry of the property string.
   *
   * Note: Some window managers may not understand all kwm properties,
   * but all common properties such as geometry or IconicState should
   * nevertheless work anyway.
   */
  static QRect setProperties(Window w, const QString &props);


  /**
   * This will tell the windowmanager that your client is able to do
   * session management. If you do this, your client MUST react on
   * WM_SAVE_YOURSELF client messages by setting the XA_WM_COMMAND
   * property. This can be easily done with a call to setWmCommand
   * (see below). If your application has several top level windows
   * which are not transient, you can enable session management only
   * for the main toplevel window, but call setWmCommand for the
   * others with an empty (not null) string as argument. You
   * should/can do that already when you create these windows. It will
   * prevent the session manager from believing that this window does
   * not support session management at all. Whenever you react on
   * WM_SAVE_YOURSELF, you will have to call setWmCommand. Passing an
   * empty (not null) string is legal: The session manager will
   * understand this as an indicator that everything is ok and that
   * your application window may be restored by somebody else ;-)
   *
   * Note: If you enable session management although your client does
   * not react correctly on WM_SAVE_YOURSELF client messages, the
   * window manager cannot perform the logout process, that means
   * the GUI will hang!
   *
   * Note 2: Session management needs a session manager. In KDE this is
   * also done by the windowmanager kwm. Other windowmangers might not
   * support this, so you may have to run a standalone session manager
   * instead. Anyway, enabling session management does not harm in the
   * case a user does not run a session manager. He/she simply will
   * not have session management, but all other functionality.
   *
   * Note 3: PSEUDO SESSION MANAGEMENT
   * There is also another way to do pseudo session management:
   *  1) do NOT enable session management
   *  2) call setWmCommand (see below) anyway and set the command
   *     which was used to start your application.
   *
   * This is exactly what old X11 applications like xterm, xedit or xv
   * do. BTW setWmCommand will also set the WM_CLIENT_MACHINE
   * property, which allows the session manager to restart the
   * application on the correct machine.
   *
   * kwm will act similar to smproxy: the window properties will be
   * stored and applied again when the window will be mapped after the
   * restart. To avoid unnecessary flickering or jumping of windows it
   * is important to call setWmCommand BEFORE your window is mapped!
   *
   * Anyway your application will appear in a warning box in kwm,
   * which indicates that the user might have some data loss. If you
   * do not want that (because your application does not contain any
   * data to be lost, for example a clock), you may simply call
   * setUnsavedDataHint with FALSE as value. Note that this hint is
   * read only when the user logs out, so the last value will be
   * used. You can also set it to TRUE to indicate that the user will
   * certainly have some data loss. All these things may of course
   * have no effect with other window- or session managers.
   *
   * Note 4: kwm also supports session management for toplevel windows
   * that are not mapped (and never have been mapped). This is very
   * usefull for programms with n windows, where n can be 0 (like kfm,
   * for example), which want to recieve a WM_SAVE_YOURSELF message
   * nevertheless. The same as usual: If you do not want the session
   * manager to restart your application, since it is already started
   * by the usual startup script (True for kfm), set the command to an
   * empty string (setWmCommand(<your window>, "");)
   */
  static void enableSessionManagement(Window w);


  /**
   * Store a shell command that can be used to restore the client.
   * This should be done as reaction on a WM_SAVE_YOURSELF client
   * message. setWmCommand also sets the WM_CLIENT_MACHINE property to
   * allow a session management to restart your application even on
   * the correct machine.
   */
  static void setWmCommand(Window w, const QString &command);

  /* Clients who react on WM_SAVE_YOURSELF should be able to save
   * their entire state. If not (version under developent, lazy
   * author, etc...)  they should at least save their geometry
   * informations and call setUnsavedDataHint. This will indicate to
   * the session manager that the user might lose some data if he/she
   * continues with the logout process.
   *
   * The hint can be set or unset either in the response to
   * WM_SAVE_YOURSELF or anytime during runtime. Please make sure that
   * the hint is also reset after the user saved the data!
   *
   * Note: The hint has also effect for clients that are not session management
   * enabled or do not even do pseudo session management
   *
   * Note 2: May have no effect with other window- or session managers
   */
  static void setUnsavedDataHint(Window w, bool value);

  /**
   * Set a mini icon for your application window. This icon may appear
   * in the window decoration as well as on taskbar buttons. Therefore
   * it should be very small (kwm for example will scale it to 14x14,
   * so 14x14 may be the size of choice).
   *
   * setMiniIcon will _not_ change the icon_pixmap property of the
   * standard XWMHints, but define a special KWM_WIN_ICON
   * property. This has the advantage, that your application can
   * support standard X11 icons (which are usually _very_ large) if it
   * runs with mwm for example, as well as modern KDE-like miniicons.
   *
   * Note: kwm will even detect changes of this property when your
   * window is mapped.
   *
   * Note 2: May have no effect with other windowmanagers */
  static void setMiniIcon(Window w, const QPixmap &pm);

  /**
   * Set a standard (large) icon for the application window. If you
   * are using Qt this should be almost aequivalent to a call to
   * QWidget::setIcon(..)
   */
  static void setIcon(Window w, const QPixmap &pm);

  /**
   * This declares a toplevel window to be a docking window. If a KWMDockModule
   * is running (for example kpanel), it will swallow the window on
   * its docking area when it is mapped.
   *
   * For docking call setDockWindow() on a new _unmapped_ toplevel
   * window. If this window will be mapped (show), it will appear on
   * the docking area, if you unmap it again (hide) it will disappear
   * from the docking area again. Docking windows MUST be toplevel
   * windows. If you create them with Qt (new QWidget()->winId()) be
   * sure not to pass any parent.
   *
   * Note: May have no effect with other window mangers
   */
  static void setDockWindow(Window w);

  /**
   *Some windows do not want to be decorated at all but should not be
   * override_redirect (for example toolbars which are dragged out of
   * their main window). This can be achieved with a simple call to
   * setDecoration() even if the window is already mapped.
   *
   * KWM understands the following values at present:
   *   noDecoration :      Not decorated at all
   *   normalDecoration :  Normal decoration (transient windows with
   *                       dialog decoration, shaped windows not decorated
   *                       at all)
   *
   *   tinyDecoration :    Tiny decoration (just a little frame)
   *
   * If your window does not want the focus, you can OR the decoration
   * property with noFocus, for example kpager:
   *    KWM::setDecoration(winId(), KWM::tinyDecoration | KWM::noFocus);
   *
   * Last not least, you can tell the window manager to keep the window
   * always on top of other windows by combing a decoration with the 
   * KWM::staysOnTop flag, for example
   *    KWM::setDecoration(winId(), KWM::normalDecoration | KWM::staysOnTop);
   *
   * Note: X11R6 does not offer a standard property or protocoll for
   * this purpose. So kwm uses a KDE specific property which may have
   * no effect with other window managers.
   */
  static void setDecoration(Window w, long value);

  enum {noDecoration = 0, normalDecoration = 1, tinyDecoration = 2,
	noFocus = 256, standaloneMenuBar = 512, desktopIcon = 1024 , staysOnTop = 2048};

  /**
   * Invokes the logout process (session management, logout dialog, ...)
   *
   * Note: May have no effect with other window mangers
   */
  static void logout();

  /**
   * Clients who draw over other windows should call refreshScreen()
   * afterwards to force an ExposureEvent on all visible windows.
   * Also necessary after darkenScreen();
   *
   * Note: May have no effect with other window mangers
   */
  static void refreshScreen();

  /**
   * Draw a black matrix over the entire screen to make it look darker.
   * Clients who use this should grab the X server afterwards and also
   * call refreshScreen() after releasing the X server.
   *
   * Note: May have no effect with other window mangers
   */
  static void darkenScreen();

  /**
   * Clients who manipulated the config file of the windowmanager
   * should call this afterwards
   *
   * Note: May have no effect with other window mangers
   */
  static void configureWm();


  /**
   * The current virtual desktop. This is usefull if your program behaves
   * different on different desktops (for example a background drawing
   * program) but does not itself need to be a window manager module
   * (which recieve a message when the current desktop changes)
   */
  static int currentDesktop();



  /**
    * Raise/register/unregister sound events. The number of character in
    * the event name is limited to 20.
    *
    Note: May have no effect with other window mangers
    */
  static void raiseSoundEvent(const QString &event);
  static void registerSoundEvent(const QString &event);
  static void unregisterSoundEvent(const QString &event);




  /**
   *************************************************************************
   *
   * Functions below are probably only important for window manager modules
   *
   * DO NOT USE THEM WITH REGULAR CLIENTS
   *
   *************************************************************************
   */

  /**
   * Declare a toplevel window to be used for module
   * communication. This window does not need to be mapped, although
   * it can be mapped of course.  Module windows MUST be toplevel
   * windows. If you create them with Qt (new QWidget()->winId()) be
   * sure not to pass any parent. Modules get the following client
   * messages from kwm. Argument is either a window ((Window)
   * XClientMessageEvent.data.l[0]), a (long) number or nothing.
   *
   * KWM_MODULE_INIT             - initialization starts
   * KWM_MODULE_INITIALIZED      - initialization is complete
   * KWM_MODULE_DESKTOP_CHANGE   - new current virtual desktop
   * KWM_MODULE_DESKTOP_NAME_CHANGE   - a desktop got a new name
   * KWM_MODULE_DESKTOP_NUMBER_CHANGE - the number of desktop changed
   * KWM_MODULE_WIN_ADD          - new window
   * KWM_MODULE_DIALOG_WIN_ADD     - new dialog window. The signal comes _before_
   *                        the WIN_ADD signal to allow clients to exclude dialog windows.
   * KWM_MODULE_WIN_REMOVE       - remove window
   * KWM_MODULE_WIN_CHANGE       - size, properties, map state etc.
   * KWM_MODULE_WIN_RAISE        - raise and lower allow a module (for example
   * KWM_MODULE_WIN_LOWER          a pager) to keep the stacking order
   * KWM_MODULE_WIN_ACTIVATE     - new active (focus) window
   * KWM_MODULE_WIN_ICON_CHANGE  - window got a (new) icon
   *
   * KDE_SOUND_EVENT             - a sound event
   * KDE_REGISTER_SOUND_EVENT    - registration of a new sound event
   * KDE_UNREGISTER_SOUND_EVENT  - remove a registration
   *
   * Please check out the KWMModuleApplication class which gives you easy
   * access to all these messages via Qt signals and slots. It also keeps
   * automatically a list of windows in both stacking and creation order.
   *
   */
  static void setKWMModule(Window w);
  /**
   * Is the window a kwm module?
   */
  static bool isKWMModule(Window w);

  /**
   * Note that there can only be one single KWMDockModule at the same
   * time.  The first one to come wins. The later can check the result
   * with isKWMDockModule.
   *
   * The KWMDockModule recieves two additional client messages:
   * KWM_MODULE_DOCKWIN_ADD
   * KWM_MODULE_DOCKWIN_REMOVE
   */
  static void setKWMDockModule(Window w);
  /**
   * Is the window a kwm dock module?
   */
  static bool isKWMDockModule(Window w);

  /**
    * This is usefull for modules which depend on a running
    * windowmanager for the correct settings of the number of desktops
    * or the desktop names (for example kpanel).
    * Just insert
    *         while (!KWM::isKWMInitialized()) sleep(1);
    * in the main function of your application to wait for kwm being
    * ready. As an alternative you can also wait for the init-signal
    * of KWMModuleApplication.
    */
  static bool isKWMInitialized();

  /**
   * Returns the window which has the focus
   */
  static Window activeWindow();
  /**
   * Switches to the specified virtual desktop
   */
  static void switchToDesktop(int desk);

  /**
   *Window region define the rectangle where windows can appear. A
   * window which can be fully maximized will exactly fill this
   * region. The regions are settable withing kwm to allow desktop
   * panels like kpanel to stay visible even if a window becomes maximized.
   * kwm will store the regions in the kwmrc when exiting.
   */
  static void setWindowRegion(int desk, const QRect &region);
  /**
    * Returns the window region of the specified virtual desktop.
    */
  static QRect getWindowRegion(int desk);

  /**
   * At present the maximium number of desktops is limited to 32
   *
   * As with the window regions, kwm will store the following properties in
   * the kwmrc when exiting
   */
  /**
    * Returns the number of virtual desktops.
    */
  static int numberOfDesktops();
  /**
    * Sets the number of virtual desktops. Modules like kpanel are informed.
    */
  static void setNumberOfDesktops(int num);
  /**
    * Changes a name of a virtual desktop. Modules like kpanel are informed.
    */
  static void setDesktopName(int desk, const QString &name);
  /**
    * Returns the name of the specified virtual desktop.
    */
  static QString getDesktopName(int desk);

  /**
   * low level kwm communication. This can also be used for a one-way
   * communication with modules, since kwm sends messages, which it
   * does not understand, to all modules. You module should declare a
   * short unque praefix for this task.
   *
   * Note: the length of a command is limited to 20 character. This
   * stems from the limitations of an ordinary X11 client messages.
   */
  static void sendKWMCommand(const QString &command);

  /**
   * The standard window title. If kwm runs, title() will return the
   * title kwm uses. These titles are always unique.
   */
  static QString title(Window w);

  /**
   *titleWithState is aequivalent to title(), but inside round brackets
   * for iconified window
   */
  static QString titleWithState(Window w);

  /**
   * if no miniicon is set, miniIcon() will return the standard
   * icon. The result will be scaled to (width, height) if it is
   * larger. Otherwise it will not be modified. If you do not specify
   * width or height, the result will be returned in its native
   * size. Returns a null pixmap in the case no
   * icon is defined.
   */
  static QPixmap miniIcon(Window w, int width=0, int height=0);
  /**
    * Same as miniIcon() above, but for the full icon.
    */
  static QPixmap icon(Window w, int width=0, int height=0);


  /**
   ***** GET WINDOW PROPERTIES *****
   */

  /**
    * Returns the virtual desktop on which the window is located.
    */
  static int desktop(Window w);
  /**
    * Returns the geometry of a window. If including_frame is set,
    * then the geometry of kwm's decoration frame is returned. This
    * functions tries to work even for non-KDE-compliant window
    * managers. Anyway, since this is a bit weird in X the result
    * cannot be guaranteed to be correct then.
    */
  static QRect geometry(Window w, bool including_frame = FALSE);

  /**
   * geometry restore is only defined for maximized window. It is the
   * geometry a window will get when it is unmaximized.
   */
  static QRect geometryRestore(Window w);

  /**
   *  Returns the icon geometry of a window. This is either the defined icon
   * geometry from a setIconGeometry() call, or the center of the window in case
   * there was no geometry or an empty geometry defined.
    */
  static QRect iconGeometry(Window w);

  /**
   * Is the window iconified?
   */
  static bool isIconified(Window w);
  /**
   * Is the window maximized?
   */
  static bool isMaximized(Window w);
  /**
   * Shall the window be maximized?
   */
  static bool isDoMaximize(Window w);


  enum {horizontal = 1, vertical = 2, fullscreen = 3};
  /**
   * The maximize mode, either horizontal, vertical or fullscreen
   */
  static int maximizeMode(Window w);

  /**
   * The doMaximize mode, either horizontal, vertical or fullscreen
   */
  static int doMaximizeMode(Window w);

  /**
   * Is the window sticky?
   */
  static bool isSticky(Window w);
  /**
   * Returns the KDE decoration hints of the window.
   */
  static long getDecoration(Window w);
  /**
   * Is the window sticky?
   */
  static bool fixedSize(Window w);
  /**
   * Does the window contain unsaved data? (KDE hint)
   */
  static bool containsUnsavedData(Window w);
  /**
   * Does the window define the KDE unsaved data hint at all?
   */
  static bool unsavedDataHintDefined(Window w);
  /**
   * Does the window have the focus?
   */
  static bool isActive(Window w);


  /**
   * ***** SET WINDOW PROPERTIES *****
   *
   * Note: The functions for some general properties (decoration,
   * icons) are in the general section at the beginning of this
   * document.
   */

  /**
   * Move the  window to another virutal desktop
   */
  static void moveToDesktop(Window w, int desk);
  /**
   * Set the geometry of a window
   */
  static void setGeometry(Window w, const QRect &geom);
  /**
   * Set the restore geometry (before maximize) of a window
   */
  static void setGeometryRestore(Window w, const QRect &geom);
  /**
   * Set the icon geometry of a window.
   */
  static void setIconGeometry(Window w, const QRect &geom);
  /**
   * Move a window to another geometric position
   */
  static void move(Window w, const QPoint &pos);

  /**
   * Maximize/Unmaximize a window according to value.  If the window
   *  is not mapped yet, this function only sets the _state_ of the
   *  maximize button, it does _not_ change the geometry. See
   * doMaximize below.
   *
   * The mode can either be horizontal or vertical or ( the default) fullscreen
   */
  static void setMaximize(Window w, bool value, int mode );
    /**
     * for binary compatibility, the above with default argument mode = horitzonal|vertical
     */
  static void setMaximize(Window w, bool value);
  /**
     Maximize a window (changing the geometry to fill the entire screen).
   */
  static void doMaximize(Window w, bool value, int mode);
    /**
     * for binary compatibility, the above with default argument mode = horitzonal|vertical
     */
  static void doMaximize(Window w, bool value);
  /**
   * Iconify/UnIconify a window according to value
   */
  static void setIconify(Window w, bool value);
  /**
   * Sticky/UnSticky a window according to value
   */
  static void setSticky(Window w, bool value);

  /**
   * close will send a WM_DELETE_WINDOW message to the window, if this window
   * requested for this protocol. Otherwise it will simply be destroyed.
   */
  static void close(Window w);

  /**
   *activate will deiconify the window, if is is iconified, or switch to
   * another desktop, if the window is there. Then the window is raised
   * and activated with activateInteral (see below)
   */
  static void activate(Window w);

  /**
   * activateInternal will simply activate the window. Be carefull: you might
   * run into trouble if the window is iconified or on another desktop!
   * You probably prefer activate (see above).
   */
  static void activateInternal(Window w);

  /**
   * raise the specified window. Should work with any windowmanager
   */
  static void raise(Window w);
  /**
   * lower the specified window. Should work with any windowmanager
   */
  static void lower(Window w);

  /**
   * if you like to swallow a mapped window ( == XReparentWindow)
   * you should call prepareForSwallowing before. This will set the
   * window to WithDrawnState (and also wait until the window achieved
   * this state), what usually let the windowmanager remove all its
   * decorations and re-reparent the window to the root window.
   *
   * You do not need to call prepareForSwallowing if you are sure that
   * the window is already in withdrawn state and unmanaged
   * (i.e. still a child of the root window). This is usually the case
   * if the window was never shown, but not always. Some
   * windowmanagers may even manage newly created unmapped windows,
   * although this is not a good idea to do. If the window is not in
   * withdrawn state but managed by the windowmanager, then the
   * windowmanager may react on the synthetic unmapNotify event
   * created from XReparentWindow by reparenting the window back to
   * the root window. Since this happen after your XReparentWindow,
   * you did not swallow it but put it onto the desktop without any
   * decoration frame instead!  prepareForSwallowing helps to avoid
   * this case.
   *
   * Note: You _never_ need to call prepareForSwallowing if you are
   * using kwm, since kwm is very clever regarding unmapNotify
   * events. If you like to ensure that your software works with other
   * windowmanager though, you should better do it. Please keep in
   * mind that taking windows away from windowmanagers is a sensitive
   * topic. That means: Even prepareForSwallowing may fail with
   * certain non-standard windowmanagers.
   *
   * Also note that all this stuff only affects toplevel
   * windows. Reparenting subwindows is no problem at all, since a
   * windowmanager does not care about them.  */
  static void prepareForSwallowing(Window w);

  /**
    * doNotManage(...) allows to define the first 20 character of a
      window title (or a regular expression) that should not be
      managed by the windowmanager. This is useful
    * to avoid flickering when a panel swallows legacy applications.
    * doNotManage(...) applies only for the first window which meets the
    * criteria.
    *
    * Note: May have no effect with other windowmanagers.
    */
  static void doNotManage(const QString&);


  /**
   * ***** CURRENT NAMES OF WINDOW OPERATION COMMANDS *****
   *
   * For 100% consitancy of the desktop, clients which do window operations
   * should use these strings.
   */
  /**
   * An i18n'ed string for maximize.
   */
  static QString getMaximizeString();
  /**
   * An i18n'ed string for unmaximize
   */
  static QString getUnMaximizeString();
  /**
   * An i18n'ed string for iconify
   */
  static QString getIconifyString();
  /**
   * An i18n'ed string for uniconify
   */
  static QString getUnIconifyString();
  /**
   * An i18n'ed string for sticky
   */
  static QString getStickyString();
  /**
   * An i18n'ed string for unsticky.
   */
  static QString getUnStickyString();
  /**
   * An i18n'ed string for move.
   */
  static QString getMoveString();
  /**
   * An i18n'ed string for resize.
   */
  static QString getResizeString();
  /**
   * An i18n'ed string for close.
   */
  static QString getCloseString();
  /**
   * An i18n'ed string for "toDesktop".
   */
  static QString getToDesktopString();
  /**
   * An i18n'ed string for "ontoCurrentDesktop".
   */
  static QString getOntoCurrentDesktopString();


  /**
   * ***** MORE OR LESS ONLY USEFULL FOR INTERNAL PURPOSES OR THE
   *       WINDOWMANAGER ITSELF *****
   */

  /**
   * Is the window a docking window?
   */
  static bool isDockWindow(Window w);
  /**
   * Returns the X window state of the specified winodw
   */
  static int getWindowState(Window w);

};

#endif // KWM_H




--- NEW FILE: ChangeLog ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: krootprop.cpp ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Mark Donohoe (donohoe at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include "krootprop.h"

KRootProp::KRootProp()
{
	kde_display = KApplication::desktop()->x11Display();
	screen = DefaultScreen(kde_display);
    root = RootWindow(kde_display, screen);
	at = 0;
}

KRootProp::~KRootProp()
{
	sync();
}

void KRootProp::sync()
{
	if ( !propDict.isEmpty() ) {
	
		QDictIterator <QString> it( propDict );
		QString propString;
		QString keyvalue;

    	while ( it.current() ) {

			QString *value = propDict.find( it.currentKey() );
        	keyvalue.sprintf( "%s=%s\n", it.currentKey(), value->data() );
			propString += keyvalue;
        	++it;
		}

		XChangeProperty(kde_display, root, at,
			XA_STRING, 8, PropModeReplace,
			(unsigned char *)propString.data(), propString.length());
			
		propDict.clear();
	}
}

void KRootProp::setProp( const QString& rProp )
{
	Atom type;
	int format;
	unsigned long nitems;
	unsigned long bytes_after;
	char *buf;
	
	// If a property has already been opened write
	// the dictionary back to the root window
	
	if( at )
		sync();

	if( !rProp.isEmpty() ) {
  		at = XInternAtom( kde_display, rProp.data(), False);
		
		XGetWindowProperty( kde_display, root, at, 0, 256,
			False, XA_STRING, &type, &format, &nitems, &bytes_after,
			(unsigned char **)&buf);
			
		// Parse through the property string stripping out key value pairs
		// and putting them in the dictionary
		
		QString s(buf);
		QString keypair;
		int i=0;
		QString key;
		QString value;
		
		while(s.length() >0 ) {
			
			// parse the string for first key-value pair separator '\n'
			
			i = s.find("\n");
			if(i == -1)
				i = s.length();
		
			// extract the key-values pair and remove from string
			
			keypair = s.left(i);
			s.remove(0,i+1);
			
			// split key and value and add to dictionary
			
			keypair.simplifyWhiteSpace();
			
			i = keypair.find( "=" );
			if( i != -1 ) {
				key = keypair.left( i );
				value = keypair.right( keypair.length() - i - 1 );
				propDict.insert( key.data(), new QString( value.data() ) );
			}
		}
	}
}

QString KRootProp::readEntry( const QString& rKey, 
			    const char* pDefault ) const 
{
	if( !propDict.isEmpty() ) {
	
		QString *aValue = propDict[ rKey.data() ];

		if (!aValue && pDefault )
			aValue->sprintf( pDefault );

		return *aValue;
	} else {
	
		QString aValue;
		
		if ( pDefault )
			aValue.sprintf( pDefault );
			
		return aValue;
	}
}

int KRootProp::readNumEntry( const QString& rKey, int nDefault ) const
{
  bool ok;
  int rc;

  QString aValue = readEntry( rKey );
  if( aValue.isNull() )
	return nDefault;
  else
	{
	  rc = aValue.toInt( &ok );
	  return( ok ? rc : 0 );
	}
}


QFont KRootProp::readFontEntry( const QString& rKey, 
							  const QFont* pDefault ) const
{
  QFont aRetFont;

  QString aValue = readEntry( rKey );
  if( !aValue.isNull() )
	{
	  // find first part (font family)
	  int nIndex = aValue.find( ',' );
	  if( nIndex == -1 )
		return aRetFont;
	  aRetFont.setFamily( aValue.left( nIndex ) );
	  
	  // find second part (point size)
	  int nOldIndex = nIndex;
	  nIndex = aValue.find( ',', nOldIndex+1 );
	  if( nIndex == -1 )
		return aRetFont;
	  aRetFont.setPointSize( aValue.mid( nOldIndex+1, 
										 nIndex-nOldIndex-1 ).toInt() );

	  // find third part (style hint)
	  nOldIndex = nIndex;
	  nIndex = aValue.find( ',', nOldIndex+1 );
	  if( nIndex == -1 )
		return aRetFont;
	  aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, 
													nIndex-nOldIndex-1 ).toUInt() );

	  // find fourth part (char set)
	  nOldIndex = nIndex;
	  nIndex = aValue.find( ',', nOldIndex+1 );
	  if( nIndex == -1 )
		return aRetFont;
	  aRetFont.setCharSet( (QFont::CharSet)aValue.mid( nOldIndex+1, 
									   nIndex-nOldIndex-1 ).toUInt() );

	  // find fifth part (weight)
	  nOldIndex = nIndex;
	  nIndex = aValue.find( ',', nOldIndex+1 );
	  if( nIndex == -1 )
		return aRetFont;
	  aRetFont.setWeight( aValue.mid( nOldIndex+1,
									  nIndex-nOldIndex-1 ).toUInt() );

	  // find sixth part (font bits)
	  uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
	  if( nFontBits & 0x01 )
		aRetFont.setItalic( true );
	  if( nFontBits & 0x02 )
		aRetFont.setUnderline( true );
	  if( nFontBits & 0x04 )
		aRetFont.setStrikeOut( true );
	  if( nFontBits & 0x08 )
		aRetFont.setFixedPitch( true );
	  if( nFontBits & 0x20 )
		aRetFont.setRawMode( true );
	}
  else if( pDefault )
	aRetFont = *pDefault;

  return aRetFont;
}


QColor KRootProp::readColorEntry( const QString& rKey,
								const QColor* pDefault ) const
{
  QColor aRetColor;
  int nRed = 0, nGreen = 0, nBlue = 0;

  QString aValue = readEntry( rKey );
  if( !aValue.isNull() )
	{
  	  bool bOK;
	  
	  // Support #ffffff style colour naming.
	  // Help ease transistion from legacy KDE setups
	  if( aValue.find("#") == 0 ) {
	  	aRetColor.setNamedColor( aValue );
		return aRetColor;
	  }
		
	  // find first part (red)
	  int nIndex = aValue.find( ',' );
	  if( nIndex == -1 )
		return aRetColor;
	  nRed = aValue.left( nIndex ).toInt( &bOK );
	  
	  // find second part (green)
	  int nOldIndex = nIndex;
	  nIndex = aValue.find( ',', nOldIndex+1 );
	  if( nIndex == -1 )
		return aRetColor;
	  nGreen = aValue.mid( nOldIndex+1,
						   nIndex-nOldIndex-1 ).toInt( &bOK );

	  // find third part (blue)
	  nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK );

	  aRetColor.setRgb( nRed, nGreen, nBlue );
	}
  else if( pDefault )
	aRetColor = *pDefault;

  return aRetColor;
}

QString KRootProp::writeEntry( const QString& rKey, const QString& rValue )
{
	QString *aValue = new QString();
	
	if( propDict[ rKey.data() ] )
		aValue = propDict[ rKey.data() ];

	propDict.replace( rKey.data(), new QString( rValue.data() ) );
	
	if ( !aValue )
		aValue->sprintf(rValue);
	
	return *aValue;
}

QString KRootProp::writeEntry( const QString& rKey, int nValue )
{
  QString aValue;

  aValue.setNum( nValue );

  return writeEntry( rKey, aValue );
}

QString KRootProp::writeEntry( const QString& rKey, const QFont& rFont )
{
  QString aValue;
  UINT8 nFontBits = 0;
  // this mimics get_font_bits() from qfont.cpp
  if( rFont.italic() )
	nFontBits = nFontBits | 0x01;
  if( rFont.underline() )
	nFontBits = nFontBits | 0x02;
  if( rFont.strikeOut() )
	nFontBits = nFontBits | 0x04;
  if( rFont.fixedPitch() )
	nFontBits = nFontBits | 0x08;
  if( rFont.rawMode() )
	nFontBits = nFontBits | 0x20;

  aValue.sprintf( "%s,%d,%d,%d,%d,%d", rFont.family(), rFont.pointSize(),
				  rFont.styleHint(), rFont.charSet(), rFont.weight(),
				  nFontBits );

  return writeEntry( rKey, aValue );
}

QString KRootProp::writeEntry( const QString& rKey, const QColor& rColor )
{
  QString aValue;
  aValue.sprintf( "%d,%d,%d", rColor.red(), rColor.green(), rColor.blue() );

  return writeEntry( rKey, aValue );
}

--- NEW FILE: kstddirs.cpp ---
/*
* kstddirs.cpp -- Implementation of class KStandardDirs.
* Author:	Sirtaj Singh Kang <taj at kde.org>
* Version:	$Id: kstddirs.cpp,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
* Generated:	Thu Mar  5 16:05:28 EST 1998
*/

#include"kstddirs.h"
#include"config.h"

#include<stdlib.h>

#include<qdict.h>
#include<qdir.h>
#include<qfileinf.h>
#include<qstring.h>
#include<qstrlist.h>

#define KDEDIR "/opt/kde"
#define KDEDIR_LEN 6

static const char *tokenize( QString& token, const char *str, 
		const char *delim );
static const char *selectStr( const char *env, 
		const char *builtin );

KStandardDirs::KStandardDirs( const char *appName ) :
	UserDir (	QDir::homeDirPath() ),
	KDEDir	(	selectStr( "KDEDIR", KDEDIR ) ),
	_appPath(	0	),
	_appName(	new QString( appName ) ),
	_app	(	new QDict<QString> ),
	_sysapp	(	new QDict<QString> ),
	_sys	(	new QDict<QString> ),
	_user	(	new QDict<QString> )

{
	if( _app ) _app->setAutoDelete( true );
	if( _sysapp ) _sysapp->setAutoDelete( true );
	if( _sys ) _sys->setAutoDelete( true );
	if( _user) _user->setAutoDelete( true );
}

KStandardDirs::~KStandardDirs()
{
	delete _app;
	delete _sysapp;
	delete _sys;
	delete _user;

	delete _appName;
}

QString KStandardDirs::findExe( const char *appname, 
		const char *pathstr, bool ignore)
{
	if( pathstr == 0 ) {
		pathstr = getenv( "PATH" );
	}

	QString onepath;
	QFileInfo info;

	const char *p = pathstr;

	// split path using : or \b as delimiters
        while( (p = tokenize( onepath, p, ":\b") ) != 0 ) {
		onepath += "/";
		onepath += appname;

		// Check for executable in this tokenized path
		info.setFile( onepath );

		if( info.exists() && ( ignore || info.isExecutable() )
			       	&& info.isFile() ) {
			return onepath;
		}
        }

	// If we reach here, the executable wasn't found.
	// So return empty string.

	onepath = (const char *)0;

	return onepath;
}

int KStandardDirs::findAllExe( QStrList& list, const char *appname,
			const char *pathstr=0, bool ignore )
{
	if( pathstr == 0 ) {
		pathstr = getenv( "PATH" );
	}

	QString onepath;
	QFileInfo info;

	const char *p = pathstr;

	list.clear();

	// split path using : or \b as delimiters
        while( (p = tokenize( onepath, p, ":\b") ) != 0 ) {
		onepath += "/";
		onepath += appname;

		// Check for executable in this tokenized path
		info.setFile( onepath );

		if( info.exists() && (ignore || info.isExecutable())
			       	&& info.isFile() ) {
			list.append( onepath );
		}
        }

	return list.count();
}


const char *KStandardDirs::closest( DirScope method, 
		const char *suffix ) const
{
	CHECK_PTR( suffix );
	CHECK_PTR( _app );
	CHECK_PTR( _sys );
	CHECK_PTR( _user );

	const char *sys, *sysapp, *user, *app;
	QString *found = _user->find( suffix );
       	

	// check dict for previous full-string insertion
	if( found == 0 ) {
		// not already inserted, so insert them now.
		const char *realsuffix = suffix;
		if( !strncmp( suffix, "KDEDIR", 
				KDEDIR_LEN ) ) {
			// remove prefix KDEDIR from path
			realsuffix += KDEDIR_LEN;
		}

		// system dir
		QString *name = new QString( KDEDir );
		*name += realsuffix;
		sys = name->data();

		const_cast<KStandardDirs*>(this)->_sys->insert( 
				suffix, name );

		// system app dir
		name = new QString( KDEDir );
		name->detach();

		*name += "/share/apps/";
		*name += realsuffix;

		sysapp = name->data();

		const_cast<KStandardDirs*>(this)->_sysapp->insert( 
				suffix, name );

		// user dir
		name = new QString( UserDir );
		name->detach();

		*name += "/.kde";
		*name += realsuffix;


		user = name->data();

		const_cast<KStandardDirs*>(this)->_user->insert( 
				suffix, name );


		// app dir
		name = new QString( UserDir );
		name->detach();

		*name += "/.kde/share/apps/";
		*name += *_appName;
		*name += realsuffix;

		app = name->data();

		const_cast<KStandardDirs*>(this)->_app->insert( 
				suffix, name );

	}
	else {
		// string's already in there
		user = found->data(); 
		sys = _sys->find( suffix )->data();
		sysapp = _sysapp->find( suffix )->data();
		app = _app->find( suffix )->data();
	}
			
	// return specific dirs

	switch( method ) {
		case User:	return user;
		case System:	return sys;
		case SysApp:	return sysapp;
		case App:	return app;
		default:	break;
	}

	// find closest

	QFileInfo info( app );	// app

	if( info.isDir() ) {
		return app;
	}

	info.setFile( user );	// user

	if( info.isDir() ) {
		return user;
	}

	info.setFile( sysapp );	// sysapp

	if( info.isDir() ) {
		return sysapp;
	}

	return sys;		// sys
}

const char *KStandardDirs::app( KStandardDirs::DirScope s ) const
{
	if( _appPath == 0 ) {
		QString app( "/share/apps/" );
		app += _appName->data();

		const_cast<KStandardDirs*>(this)->_appPath
			= closest( s, app.data() );
	}

	return _appPath;
}

const char *KStandardDirs::bin( DirScope s ) const
{
	return closest( s, KDE_BINDIR );
}

const char *KStandardDirs::cgi( DirScope s ) const
{

	return closest( s, KDE_CGIDIR );
}

const char *KStandardDirs::config( DirScope s ) const
{
	return closest( s, KDE_CONFIGDIR );
}

const char *KStandardDirs::apps( DirScope s ) const
{
	return closest( s, KDE_DATADIR );
}

const char *KStandardDirs::html( DirScope s ) const
{
	return closest( s, KDE_HTMLDIR );
}

const char *KStandardDirs::icon( DirScope s ) const
{
	return closest( s, KDE_ICONDIR );
}

const char *KStandardDirs::locale( DirScope s ) const
{
	return closest( s, KDE_LOCALE );
}

const char *KStandardDirs::mime( DirScope s ) const
{
	return closest( s, KDE_MIMEDIR );
}

const char *KStandardDirs::parts( DirScope s ) const
{
	return closest( s, KDE_PARTSDIR );
}

const char *KStandardDirs::toolbar( DirScope s ) const
{
	return closest( s, KDE_TOOLBARDIR );
}

const char *KStandardDirs::wallpaper( DirScope s ) const
{
	return closest( s, KDE_WALLPAPERDIR );
}

const char *KStandardDirs::sound( DirScope s ) const
{
	return closest( s, KDE_SOUNDDIR );
}

static const char *tokenize( QString& token, const char *str, 
		const char *delim )
{
        token = "";

        if( !str || !*str ) {
                return 0;
        }

        // find first non-delimiter character
        while( *str && strchr( delim, *str ) ) {
                str++;
        }

        if( !*str ) {
                return 0;
        }

        // find first delimiter or end, storing each non-qualifier into token
        while( *str && !strchr( delim, *str ) ) {
                token += *str;
                str++;
        }

        return str;
}

static const char *selectStr( const char *env, const char *builtin )
{
	const char *result = getenv( env );

	if( result == 0 ) {
		result = builtin;
	}

	return result;
}

--- NEW FILE: kprocctrl.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Christian Czezakte (e9025461 at student.tuwien.ac.at)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
//
//  KPROCESSCONTROLLER -- A helper class for KProcess
//
//  version 0.3.1, Jan 8th 1997
//
//  (C) Christian Czezatke
//  e9025461 at student.tuwien.ac.at
//

#ifndef __KPROCCTRL_H__
#define __KPROCCTRL_H__


#include <qsocketnotifier.h>
#include "kprocess.h"

/**
@short A class for internal use by KProcess only
@author Christian Czezakte e9025461 at student.tuwien.ac.at
  A class for internal use by KProcess only. -- Exactly one instance
  of this class is generated by the first instance of KProcess that is
  created (a pointer to it gets stored in "theKProcessController").

  This class takes care of the actual (UN*X) signal handling.
*/
class KProcessController : public QObject
{
  Q_OBJECT

public:
  KProcessController();
  ~KProcessController(); 
  //CC: WARNING! Destructor Not virtual (but you don't derive classes from this anyhow...)

  QList<KProcess> *processList;

 public slots:

 void slotDoHousekeeping(int socket);

private:
#ifdef __sgi__
  static void theSigCHLDHandler();
#else
  static void theSigCHLDHandler(int signal);
#endif
  // handler for sigchld

  int fd[2];
  QSocketNotifier *notifier;

  // Disallow assignment and copy-construction
  KProcessController( const KProcessController& );
  KProcessController& operator= ( const KProcessController& );
};

extern KProcessController *theKProcessController;

#endif


--- NEW FILE: kclipboard.h ---
#ifndef __kclipboard_h__
#define __kclipboard_h__

#include <qclipbrd.h>
#include <qobject.h>
#include <qapp.h>
#include <qbuffer.h>
#include <qwidget.h>
#include <qstring.h>
#include <qstrlist.h>

class KClipboard : public QObject, public QBuffer
{
  Q_OBJECT
public:
  KClipboard();
  ~KClipboard();
   
  bool open( int _mode );
  bool open( int _mode, const char *_format );
  void close();
    
  void clear();

  const char *format();

  /////////////////////////
  // Convenience functions
  /////////////////////////
  void setURLList( QStrList& _urls );
  bool urlList( QStrList& _urls );
  void setText( const char *_text );
  const char* text();
  QByteArray octetStream();
  void setOctetStream( QByteArray& _arr );

  static KClipboard* self();
  
signals:
  void ownerChanged();
    
protected:
  virtual bool event( QEvent *e );

  void fetchData();
  void setOwner();
  bool isOwner();
  bool isEmpty();
  QWidget* makeOwner();
    
private:
  bool m_bOwner;
  QWidget *m_pOwner;
  bool m_bEmpty;
  QString m_strFormat;
  int m_mimeTypeLen;
  
  static KClipboard* s_pSelf;
};

#endif

--- NEW FILE: NEWS ---
v0.7:		Default installation directory is $KDEDIR.
			KPanner widget included
			KPixmap reads formats other than XPM again
			KPixmap::load returns bool (like QPixmap::load)
			KTextStream removed, KConfig uses QTextStream
			KConfig::writeEntry makes a deep copy of the value.
			Changes from libkde 0.6.4 merged
			KColorDialog widget included
			Some patches to KURL applied
			KMessageBox widget included
			KPopupMenu included
			KTabControl included
			KTreeList included
			KFontDialog included
			KEdit included
			KDatePicker and KDateTable included
			KKeyConfig included and initialized in KApplication
			some bugfixes to KConfig
			KApplication::appName()
			KApplication searches for app config file in
				~/.kde/config/.appnamerc is USE_NEW_CONFIG_LOCATION is
				set

V0.6:		all method names start with a small letter
			Read and write numerical config entries.
			Possibility to set a logical app name in the KApplication 
				constructor
			State of the application config object can be queried.
			Merged Torben´s changes to KApplication and DND stuff
			Better XPM support from Matthias

v0.5:		Drag and Drop stuff from kfm included into libkdecore
(08.12.96)	(classes KDNDDropZone, KDNDIcon, KDNDWidget, KPixmap and
				additions to KApplication) 
			KSocket and KServerSocket included
			Bugfix in KApplication's config handling

v0.4:		new: libkdeui (contains KLedLamp and KProgress)
(01.12.96)	kconfigtest should now handle writes to app-specific files
				correctly 
			new: KURL class in libkdecore
			new: KApplication class in libkdecore
			KConfig can now roll back changes.

v0.3:		KTextStream class to provide a ReadLine() method
(23.11.96)	config entries may contain spaces
			KColorGroup class for reading/saving ColorGroups
				from/to KConfig objects  

v0.2:		Write access for the KConfig class.
(20.11.96)	Documentation in the doc directory (generated directly from 
				the header files with DOC++)

v0.1a:		Check if the C++ compiler supports the bool datatype
				(SPARCworks C++ 4.1 does not!) - not released

v0.1:		KConfig class (same as stand alone version 0.2)
			autoconf-configurable


--- NEW FILE: AUTHORS ---
Matthias Kalle Dalheimer <kalle at kde.org>:
classes KConfig, KTextStream, KColorSet, KApplication
automake, autoconf, maintenance

Richard Moore <moorer at cs.man.ac.uk>:
KLedLamp class

Martynas Kunigelis <algikun at santaka.ktu.lt>:
KProgress class

Steffen Hansen <stefh at dit.ou.dk>:
KURL class

Torben Weis <weis at stud.uni-frankfurt.de>
DnD stuff, KSocket and KServerSocket classes, KPixmap

Alexander Sanda <alex at darkstar.ping.at>
Read and write numerical config entries, KPanner, KTabControl,
KPopupMenu, KMessageBox, KEdit widgets. 

Martin Jones <mjones at powerup.com.au>
Bugfixes in KPixmap and KURL, KColorDialog, KSelector

Keith Brown <kbrown at pdq.net>
KTreeList class

Bernd Johannes Wuebben <wuebben at math.cornell.edu>
KFontDialog classes

Tim D. Gilman <tdgilman at best.com>
KDatePicker, KDateTable class

Nicolas Hadacek <hadacek at via.ecp.fr>
Key configuration classes, bug fixes

Michael Will <Michael.Will at student.uni-tuebingen.de>
loading routine in KPixmap

Christian Czezatke <e9025461 at student.tuwien.ac.at>
KProcess class

Matthias Ettrich <ettrich at kde.org>
KWM, Changes to KApplication and KIconLoader

Stephan Kulow <coolo at kde.org>
heavy modifications to KURL, autoconf and automake stuff

Jacek Konieczny <jajcus at zeus.polsl.gliwice.pl>
KCharset* classes

--- NEW FILE: kpoint.h ---
// KPoint - (c) by Reginald Stadlbauer 1998 <reggie at kde.org>
// Version: 0.0.1

#ifndef kpoint_h
#define kpoint_h

class QPoint;

/**
 * Class for reperesenting a point by its X and Y coordinate. It's sorce compatible
 * to the Qt class QPoint, but KPoint uses 32 bit integers for the coordinates.
 * @short Class for representing a point by (x,y)
 * @author Reginald Stadlbauer <reggie at kde.org>
 * @version 0.0.1
 */

class  KPoint
{
public:
  KPoint();
  KPoint(int _xpos,int _ypos);
  KPoint(const QPoint &_pnt);
  
  bool isNull() const;
  
  int x() const;
  int y() const;
  void setX(int _xpos);
  void setY(int _ypos);
  
  int &rx();
  int &ry();
  
  KPoint &operator+=(const KPoint &_pnt);
  KPoint &operator-=(const KPoint &_pnt);
  KPoint &operator*=(int _c);
  KPoint &operator*=(double _c);
  KPoint &operator/=(int _c);
  KPoint &operator/=(double _c);

  operator QPoint() const;
  
  friend bool operator==(const KPoint &_pnt1,const KPoint &_pnt2);
  friend bool operator!=(const KPoint &_pnt1,const KPoint &_pnt2);
  friend bool operator==(const QPoint &_pnt1,const KPoint &_pnt2);
  friend bool operator!=(const QPoint &_pnt1,const KPoint &_pnt2);
  friend bool operator==(const KPoint &_pnt1,const QPoint &_pnt2);
  friend bool operator!=(const KPoint &_pnt1,const QPoint &_pnt2);
  friend KPoint operator+(const KPoint &_pnt1,const KPoint &_pnt2);
  friend KPoint operator-(const KPoint &_pnt1,const KPoint &_pnt2);
  friend KPoint operator*(const KPoint &_pnt,int _c);
  friend KPoint operator*(int _c,const KPoint &_pnt);
  friend KPoint operator*(const KPoint &_pnt,double _c);
  friend KPoint operator*(double _c,const KPoint &_pnt);
  friend KPoint operator-(const KPoint &_pnt);
  friend KPoint operator/(const KPoint &_pnt,int _c);
  friend KPoint operator/(const KPoint &_pnt,double _c);

protected:
  int xpos,ypos;

};

#endif


--- NEW FILE: krootprop.h ---
/* This file is part of the KDE libraries
    Copyright (C) 1997 Mark Donohoe (donohoe at kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/
#ifndef _KROOTPROP_H
#define _KROOTPROP_H_

#include <kapp.h>

#include <X11/Xlib.h>
#include <X11/Xatom.h>

#include <qdict.h>

/** 
* KDE desktop resources stored on the root window.
*
* A companion to the KConfig class
*
* The KRootProp class is used for reading and writing configuration entries
* to properties on the root window.
*
* All configuration entries are of the form "key=value".
*
* @see KConfig::KConfig
* @author Mark Donohoe (donohe at kde.org)
* @version 
* @short KDE Configuration Management class
*/
class KRootProp
{
private:	
  Display *kde_display;
  Window root;
  int screen;
  Atom at;
  QDict <QString> propDict;

protected:

public:
/** 
* Construct a KRootProp object. 
*
*/
   KRootProp();
   
/** 
* Destructor. 
*
* Writes back any dirty configuration entries.
*/
  ~KRootProp();

/** 
* Specify the property in which keys will be searched.
*
*/	
  void setProp(const QString& rProp="");

/**
* Read the value of an entry specified by rKey in the current property
*
* @param rKey	The key to search for.
* @param pDefault A default value returned if the key was not found.
* @return The value for this key or an empty string if no value
*	  was found.
*/	
  QString readEntry( const QString& rKey, 
  	  	  	  	  	  const char* pDefault = 0 ) const ;
					  
/**
* Read a numerical value. 
*
* Read the value of an entry specified by rKey in the current property 
* and interpret it numerically.
*
* @param rKey The key to search for.
* @param nDefault A default value returned if the key was not found.
* @return The value for this key or 0 if no value was found.
*/
  int readNumEntry( const QString& rKey, int nDefault = 0 ) const;
  
/** 
* Read a QFont.
*
* Read the value of an entry specified by rKey in the current property 
* and interpret it as a font object.
*
* @param rKey		The key to search for.
* @param pDefault	A default value returned if the key was not found.
* @return The value for this key or a default font if no value was found.
*/ 
  QFont readFontEntry( const QString& rKey, 
							  const QFont* pDefault = 0 ) const;

/** 
* Read a QColor.
*
* Read the value of an entry specified by rKey in the current property 
* and interpret it as a color.
*
* @param rKey		The key to search for.
* @param pDefault	A default value returned if the key was not found.
* @return The value for this key or a default color if no value
* was found.
*/					  
  QColor readColorEntry( const QString& rKey,
								const QColor* pDefault = 0 ) const;
							  
	
/** 
* writeEntry() overridden to accept a const char * argument.
*
* This is stored to the current property when destroying the
* config object or when calling Sync().
*
* @param rKey		The key to write.
* @param rValue		The value to write.
* @return The old value for this key. If this key did not exist, 
*	  a null string is returned.	  
*
* @see #writeEntry
*/				
  QString writeEntry( const QString& rKey, const QString& rValue );
  
/** Write the key value pair.
* Same as above, but write a numerical value.
* @param rKey The key to write.
* @param nValue The value to write.
* @return The old value for this key. If this key did not
* exist, a null string is returned.	  
*/
  QString writeEntry( const QString& rKey, int nValue );
  
/** Write the key value pair.
* Same as above, but write a font
* @param rKey The key to write.
* @param rValue The value to write.
* @return The old value for this key. If this key did not
* exist, a null string is returned.	  
*/
  QString writeEntry( const QString& rKey, const QFont& rFont );
  
/** Write the key value pair.
* Same as above, but write a color
* @param rKey The key to write.
* @param rValue The value to write.
* @return The old value for this key. If this key did not
*  exist, a null string is returned.	  
*/
  QString writeEntry( const QString& rKey, const QColor& rColor );

/** Flush the entry cache.
* Write back dirty configuration entries to the current property,
*  This is called automatically from the destructor.
*/	
	void sync();
};

#endif

--- NEW FILE: kiconloader.h ---
/* 
   $Id: kiconloader.h,v 1.1 2006-10-03 11:26:27 dslinux_amadeus Exp $
   
   This file is part of the KDE libraries
   Copyright (C) 1997 Christoph Neerfeld (chris at kde.org)
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   
   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
   
   $Log: kiconloader.h,v $
   Revision 1.1  2006-10-03 11:26:27  dslinux_amadeus
   adding pristine copy of pixil to HEAD so I can branch from it

   Revision 1.1  2003/09/08 19:42:05  jasonk
   Addition of packages directory and associated files.

   Revision 1.1.1.1  2003/08/07 21:18:32  jasonk
   Initial import of PIXIL into new cvs repository.

   Revision 1.1.1.1  2003/06/23 22:04:23  jasonk


   Revision 1.1.1.1  2000/07/07 16:10:58  jasonk
   Initial import of ViewML

   Revision 1.15.4.3  1999/03/12 18:41:10  pbrown
   removed KIconLoader:: from method getIconPath (extra qualification
   unneeded and causing warnings).

   Revision 1.15.4.2  1999/03/09 15:46:29  dfaure
   Doc update (the path order was changed)

   Revision 1.15.4.1  1999/03/09 15:22:52  dfaure
   Moved path-list initialisation to a private initPath().
   Merged with Antonio's getIconPath(...) new method. (fixed missing .detach())
    loadInternal() uses it.
   Binary compatible. kfm will use it in a second :)

   Revision 1.15  1998/11/02 10:08:35  ettrich
   new reload method for kiconloader (Rene Beutler)

   Revision 1.14  1998/09/01 20:21:27  kulow
   I renamed all old qt header files to the new versions. I think, this looks
   nicer (and gives the change in configure a sense :)

   Revision 1.13  1998/08/26 18:37:48  neerfeld
   bug fix for loadInternal;  changed email address

   Revision 1.12  1998/08/22 20:02:41  kulow
   make kdecore have nicer output, when compiled with -Weffc++ :)

   Revision 1.11  1998/08/17 10:34:03  konold

   Martin K.: Fixed a typo

   Revision 1.10  1998/06/16 06:03:22  kalle
   Implemented copy constructors and assignment operators or disabled them

   Revision 1.9  1998/03/08 18:50:23  wuebben
   Bernd: fixed up the kiconloader class -- it was completely busted


*/


#ifndef KICONLOADER_H
#define KICONLOADER_H

#ifndef _KCONFIG_H
#include <kconfig.h>
#endif

#include <qapplication.h>
#include <qlist.h>
#include <qpixmap.h>
#include <qstrlist.h>
#include <qstring.h>

/// Load icons from disk
/**
   KIconLoader is a derived class from QObject.
   It supports loading of icons from disk. It puts the icon and its name
   into a QList and if you call loadIcon() for a second time, the icon is taken
   out of the list and not reread from disk.
   So you can call loadIcon() as many times as you wish and you don't have
   to take care about multiple copies of the icon in memory.
*/
class KIconLoader : public QObject
{
  Q_OBJECT
public:
  /// Constructor
  /**
	 config is the pointer to a KConfig object; 
	 normally the global KConfig object.
	 group is the name of a group in a config file.
	 key is the name of an entry within this group.
	 
	 Normaly group == "KDE Setup" and key == "IconPath"
	 Example for an entry in .kderc:
	 [KDE Setup]
	 IconPath=/usr/local/lib/kde/lib/pics:/usr/local/lib/kde/lib/pics/toolbar
	 
	 This gives KIconLoader the path to search the icons in.
	 
	 If you want to use another path in your application then write into
	 your .my_application_rc:
	 [MyApplication]
	 PixmapPath=/..../my_pixmap_path
	 and call KIconLoader( config, "MyApplication", "PixmapPath" ).
  */
  KIconLoader ( KConfig *conf, const QString &app_name, const QString &var_name );

  /**
	 There now exists a simple-to-use version of KIconLoader. If you
 	 create a KIconLoader without giving arguments, KIconLoader searches for 
	 the path in [KDE Setup]:IconPath=... as a default.
  */
  KIconLoader();

  /// Destructor
  ~KIconLoader ();

  /// Load an icon from disk
  /**
	 This function searches for the icon called name 
	 and returns a QPixmap object
	 of this icon if it was found and 0 otherwise.
	 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
	 with the same name argument won't load the icon again, but gets it out of
	 its cache. By this you don't have to worry about multiple copies
	 of one and the same icon in memory, and you can call loadIcon() 
	 as often as you like.

         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 
   * usual loadIcon functions except that they look in
   * kdedir()/share/icon first.
   *
   * These function should be used if you are loading the
   * application icons. Normally KApplication does this for
   * you, but special programs like kpanel or kmenuedit
   * need to load the application icons of foreign applications.
   */
  QPixmap loadApplicationIcon( const QString &name, int w = 0, int h = 0 );
  QPixmap loadApplicationMiniIcon( const QString &name, int w = 0, int h = 0 );


  /// Insert directory into searchpath
  /**
         This functions inserts a new directory into the searchpath at 
	 position index.
	 It returns TRUE if successful, or FALSE if index is out of range.
	 Note that the default searchpath looks like this:

	       1: $HOME/.kde/share/apps/<appName>/pics
	       2: $KDEDIR/share/apps/<appName>/pics
	       3: $HOME/.kde/share/apps/<appName>/toolbar
	       4: $KDEDIR/share/apps/<appName>/toolbar

	       5: $HOME/.kde/share/icons
	       6: $HOME/.kde/share/toolbar

	       7: $KDEDIR/share/icons
	       8: $KDEDIR/share/toolbar

	     9-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; }

  /// Get the complete path for an icon filename
  /**
      Set always_valid to true if you want this function to return a valid
      pixmap is your wishes cannot be satisfied (Be aware, that if unknown.xpm
      is not found you will receive a null string)
  */
  QString getIconPath( const QString &name, bool always_valid=false);


  /// 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 );

private:
  void initPath();
  void addPath(QString path);

  // Disallow assignment and copy-construction
  KIconLoader( const KIconLoader& );
  KIconLoader& operator= ( const KIconLoader& );

};

#endif // KICONLOADER_H





--- NEW FILE: ksize.h ---
// KSize - (c) by Reginald Stadlbauer 1998 <reggie at kde.org>
// Version: 0.0.1

#ifndef ksize_h
#define ksize_h

class QSize;

/**
 * Class for reperesenting a size by its WIDTH and HEIGHT. It's sorce compatible
 * to the Qt class QSize, but KSize uses 32 bit integers for the width/height.
 * @short Class for representing a size by (width,height)
 * @author Reginald Stadlbauer <reggie at kde.org>
 * @version 0.0.1
 */

class  KSize
{
public:
  KSize();
  KSize(int _wid,int _hei);
  KSize(const QSize &_size);
  
  bool isNull() const;
  bool isEmpty() const;
  bool isValid() const;
  
  int width() const;
  int height() const;
  void setWidth(int _wid);
  void setHeight(int _hei);
  void transpose();
  
  KSize expandedTo(const KSize &_size) const;
  KSize boundedTo(const KSize &_size) const;
  
  int &rwidth();
  int &rheight();
  
  KSize &operator+=(const KSize &_size);
  KSize &operator-=(const KSize &_size);
  KSize &operator*=(int _c);
  KSize &operator*=(float _c);
  KSize &operator/=(int _c);
  KSize &operator/=(float _c);
  
  operator QSize() const;

  friend bool operator==(const KSize &_size1,const KSize &_size2);
  friend bool operator!=(const KSize &_size1,const KSize &_size2);
  friend bool operator==(const QSize &_size1,const KSize &_size2);
  friend bool operator!=(const QSize &_size1,const KSize &_size2);
  friend bool operator==(const KSize &_size1,const QSize &_size2);
  friend bool operator!=(const KSize &_size1,const QSize &_size2);
  friend KSize operator+(const KSize &_size1,const KSize &_size2);
  friend KSize operator-(const KSize &_size1,const KSize &_size2);
  friend KSize operator*(const KSize &_size,int _c);
  friend KSize operator*(int _c,const KSize &_size);
  friend KSize operator*(const KSize &_size,float _c);
  friend KSize operator*(float _c,const KSize &_size);
  friend KSize operator/(const KSize &_size,int _c);
  friend KSize operator/(const KSize &_size,float _c);

protected:
  int wid,hei;

};

#endif




More information about the dslinux-commit mailing list