home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / krootprop.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  5.9 KB  |  207 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Mark Donohoe (donohoe@kde.org)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef _KROOTPROP_H
  20. #define _KROOTPROP_H
  21.  
  22. typedef unsigned long Atom;
  23.  
  24. #include <qcolor.h>
  25. #include <qfont.h>
  26. #include <qmap.h>
  27. #include <qstringlist.h>
  28.  
  29. #include <kdelibs_export.h>
  30.  
  31. class KRootPropPrivate;
  32.  
  33. /**
  34. * Access KDE desktop resources stored on the root window.
  35. *
  36. * A companion to the KConfig class.
  37. *
  38. * The KRootProp class is used for reading and writing configuration entries
  39. * to properties on the root window.
  40. *
  41. * All configuration entries are of the form "key=value".
  42. *
  43. * @see  KConfig::KConfig
  44. * @author Mark Donohoe (donohe@kde.org)
  45. */
  46. class KDECORE_EXPORT KRootProp
  47. {
  48. private:    
  49.   Atom atom;
  50.   QMap<QString,QString> propDict;
  51.   QString property_;
  52.   bool dirty;
  53.   KRootPropPrivate *d;
  54.  
  55. public:
  56.   /**
  57.    * Constructs a KRootProp object for the property @p rProp.
  58.    * @param rProp the property that will be searched, null to
  59.    *              do nothing
  60.    * @see setProp()
  61.    **/
  62.    KRootProp( const QString& rProp = QString::null );
  63.   /**
  64.    * Destructs the KRootProp object.
  65.    *
  66.    * Writes back any dirty configuration entries.
  67.    **/
  68.   ~KRootProp();
  69.    
  70.   /**
  71.    * Sets the property in which keys will be searched.
  72.    * @param rProp the property that will be searched
  73.    **/    
  74.    void setProp(const QString& rProp=QString());
  75.    /**
  76.     * Returns the name of the property under which keys are searched.
  77.     * @return the property that will be searched
  78.     **/
  79.    QString prop() const;
  80.    
  81.    /**
  82.     * Destroys the property completely.
  83.     *
  84.     * I.e. all entries will be cleared
  85.     * and the property will be removed from the root window.
  86.     **/
  87.    void destroy();
  88.  
  89.  /**
  90.   * Reads the value of an entry specified by @p rKey in the current property.
  91.   *
  92.   * @param rKey    The key to search for.
  93.   * @param pDefault A default value returned if the key was not found.
  94.   * @return The value for this key or the default if no value
  95.   *      was found.
  96.   **/    
  97.  QString readEntry( const QString& rKey,
  98.             const QString& pDefault = QString::null ) const ;
  99.                     
  100.  /**
  101.   * Reads a numerical value.
  102.   *
  103.   * Reads the value of an entry specified by @p rKey in the current property
  104.   * and interprets it numerically.
  105.   *
  106.   * @param rKey The key to search for.
  107.   * @param nDefault A default value returned if the key was not found.
  108.   * @return The value for this key or the default if no value was found.
  109.   */
  110.  int readNumEntry( const QString& rKey, int nDefault = 0 ) const;
  111.  
  112.  /**
  113.   * Reads a QFont value.
  114.   *
  115.   * Reads the value of an entry specified by @p rKey in the current property
  116.   * and interpret it as a font object.
  117.   *
  118.   * @param rKey        The key to search for.
  119.   * @param pDefault    A default value returned if the key was not found.
  120.   * @return The value for this key or a default font if no value was found.
  121.   */
  122.  QFont readFontEntry( const QString& rKey,
  123.               const QFont* pDefault = 0 ) const;
  124.  
  125.  /**
  126.   * Reads a QColor.
  127.   *
  128.   * Reads the value of an entry specified by @p rKey in the current property
  129.   * and interprets it as a color.
  130.   *
  131.   * @param rKey        The key to search for.
  132.   * @param pDefault    A default value returned if the key was not found.
  133.   * @return The value for this key or a default color if no value
  134.   * was found.
  135.   */                    
  136.  QColor readColorEntry( const QString& rKey,
  137.             const QColor* pDefault = 0 ) const;
  138.                             
  139.     
  140.  /**
  141.   * Writes a (key/value) pair.
  142.   *
  143.   * This is stored to the current property when destroying the
  144.   * config object or when calling sync().
  145.   *
  146.   * @param rKey        The key to write.
  147.   * @param rValue        The value to write.
  148.   * @return The old value for this key. If this key did not exist,
  149.   *      a null string is returned.
  150.   *
  151.   **/
  152.  QString writeEntry( const QString& rKey, const QString& rValue );
  153.  
  154.  /**
  155.   * Writes the (key/value) pair.
  156.   * Same as above, but writes a numerical value.
  157.   * @param rKey The key to write.
  158.   * @param nValue The value to write.
  159.   * @return The old value for this key. If this key did not
  160.   * exist, a null string is returned.
  161.   **/
  162.  QString writeEntry( const QString& rKey, int nValue );
  163.  
  164.  /**
  165.   * Writes the (key/value) pair.
  166.   * Same as above, but writes a font.
  167.   * @param rKey The key to write.
  168.   * @param rFont The font to write.
  169.   * @return The old value for this key. If this key did not
  170.   * exist, a null string is returned.
  171.   **/
  172.   QString writeEntry( const QString& rKey, const QFont& rFont );
  173.  
  174.   /**
  175.    * Writes the (key/value) pair.
  176.    * Same as above, but writes a color.
  177.    * @param rKey The key to write.
  178.    * @param rColor The color to write.
  179.    * @return The old value for this key. If this key did not
  180.    *  exist, a null string is returned.
  181.    **/
  182.   QString writeEntry( const QString& rKey, const QColor& rColor );
  183.  
  184.   /**
  185.    * Removes an entry.
  186.    * @param rKey The key to remove.
  187.    * @return The old value for this key. If this key did not
  188.    *  exist, a null string is returned.
  189.    **/
  190.   QString removeEntry(const QString& rKey);
  191.  
  192.   /**
  193.    * Returns a list of all keys.
  194.    * @return A QStringList containing all the keys.
  195.    **/
  196.   QStringList listEntries() const;
  197.  
  198.   /**
  199.    * Flushes the entry cache.
  200.    * Writes back dirty configuration entries to the current property,
  201.    * This is called automatically from the destructor.
  202.    **/
  203.   void sync();
  204. };
  205.  
  206. #endif
  207.