KDE 4.9 PyKDE API Reference

- KDE's Python API

# KCoreConfigSkeleton Class Reference

`from PyKDE4.kdecore import *`

Inherits: QObject

## Detailed Description

\class KCoreConfigSkeleton kcoreconfigskeleton.h <KCoreConfigSkeleton>

Class for handling preferences settings for an application.

Author:
  Cornelius Schumacher

See also:
  KConfigSkeletonItem

This class provides an interface to preferences settings. Preferences items can be registered by the addItem() function corresponding to the data type of the setting. KCoreConfigSkeleton then handles reading and writing of config files and setting of default values.

Normally you will subclass KCoreConfigSkeleton, add data members for the preferences settings and register the members in the constructor of the subclass.

Example:

     class MyPrefs : public KCoreConfigSkeleton
     {
       public:
         MyPrefs()
         {
           setCurrentGroup("MyGroup");
           addItemBool("MySetting1", mMyBool, false);
           addItemPoint("MySetting2", mMyPoint, QPoint(100, 200));

           setCurrentGroup("MyOtherGroup");
           addItemDouble("MySetting3", mMyDouble, 3.14);
         }

         bool mMyBool;
         QPoint mMyPoint;
         double mMyDouble;
     }

It might be convenient in many cases to make this subclass of KCoreConfigSkeleton a singleton for global access from all over the application without passing references to the KCoreConfigSkeleton object around.

You can write the data to the configuration file by calling writeConfig() and read the data from the configuration file by calling readConfig(). If you want to watch for config changes, use configChanged() signal.

If you have items, which are not covered by the existing addItem() functions you can add customized code for reading, writing and default setting by implementing the functions usrUseDefaults(), usrReadConfig() and usrWriteConfig().

Internally preferences settings are stored in instances of subclasses of KConfigSkeletonItem. You can also add KConfigSkeletonItem subclasses for your own types and call the generic addItem() to register them.

In many cases you don't have to write the specific KCoreConfigSkeleton subclasses yourself, but you can use kconfig_compiler to automatically generate the C++ code from an XML description of the configuration options.

Use KConfigSkeleton if you need GUI types as well.

## Signals

| configChanged ()

## Methods

| __init__ (self, QString configname=QString(), QObject parent=0)
| __init__ (self, KSharedPtr<KSharedConfig> config, QObject parent=0)
| addItem (self, KConfigSkeletonItem a0, QString name=QString())
KCoreConfigSkeleton.ItemBool | addItemBool (self, QString name, bool reference, bool defaultValue=0, QString key=QString())
KCoreConfigSkeleton.ItemDateTime | addItemDateTime (self, QString name, QDateTime reference, QDateTime defaultValue=QDateTime(), QString key=QString())
KCoreConfigSkeleton.ItemDouble | addItemDouble (self, QString name, float reference, float defaultValue=0.0, QString key=QString())
KCoreConfigSkeleton.ItemInt | addItemInt (self, QString name, int reference, int defaultValue=0, QString key=QString())
KCoreConfigSkeleton.ItemLongLong | addItemInt64 (self, QString name, long reference, long defaultValue=0, QString key=QString())
KCoreConfigSkeleton.ItemIntList | addItemIntList (self, QString name, [int] reference, [int] defaultValue=QList<int>(), QString key=QString())
KCoreConfigSkeleton.ItemLongLong | addItemLongLong (self, QString name, long reference, long defaultValue=0, QString key=QString())
KCoreConfigSkeleton.ItemPassword | addItemPassword (self, QString name, QString reference, QString defaultValue=QLatin1String(""), QString key=QString())
KCoreConfigSkeleton.ItemPath | addItemPath (self, QString name, QString reference, QString defaultValue=QLatin1String(""), QString key=QString())
KCoreConfigSkeleton.ItemPoint | addItemPoint (self, QString name, QPoint reference, QPoint defaultValue=QPoint(), QString key=QString())
KCoreConfigSkeleton.ItemProperty | addItemProperty (self, QString name, QVariant reference, QVariant defaultValue=QVariant(), QString key=QString())
KCoreConfigSkeleton.ItemRect | addItemRect (self, QString name, QRect reference, QRect defaultValue=QRect(), QString key=QString())
KCoreConfigSkeleton.ItemSize | addItemSize (self, QString name, QSize reference, QSize defaultValue=QSize(), QString key=QString())
KCoreConfigSkeleton.ItemString | addItemString (self, QString name, QString reference, QString defaultValue=QLatin1String(""), QString key=QString())
KCoreConfigSkeleton.ItemStringList | addItemStringList (self, QString name, QStringList reference, QStringList defaultValue=QStringList(), QString key=QString())
KCoreConfigSkeleton.ItemUInt | addItemUInt (self, QString name, long reference, long defaultValue=0, QString key=QString())
KCoreConfigSkeleton.ItemULongLong | addItemUInt64 (self, QString name, long reference, long defaultValue=0, QString key=QString())
KCoreConfigSkeleton.ItemULongLong | addItemULongLong (self, QString name, long reference, long defaultValue=0, QString key=QString())
KConfig | config (self)
QString | currentGroup (self)
KConfigSkeletonItem | findItem (self, QString name)
bool | isImmutable (self, QString name)
[KConfigSkeletonItem] | items (self)
| readConfig (self)
| setCurrentGroup (self, QString group)
| setDefaults (self)
| setSharedConfig (self, KSharedPtr<KSharedConfig> pConfig)
bool | useDefaults (self, bool b)
| usrReadConfig (self)
| usrSetDefaults (self)
bool | usrUseDefaults (self, bool b)
| usrWriteConfig (self)
| writeConfig (self)

## Signal Documentation

configChanged | ( |  | ) |

This signal is emitted when the configuration change.

Signal syntax:
  `QObject.connect(source, SIGNAL("configChanged()"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QString | configname=QString(),
|  | QObject | parent=0
| ) |  |  |

Constructor.

Parameters:

  | configname | name of config file. If no name is given, the default config file as returned by KGlobal.config() is used
  | parent | the parent object (see QObject documentation)

__init__ | ( | self, |
|  | KSharedPtr<KSharedConfig> | config,
|  | QObject | parent=0
| ) |  |  |

Constructor.

Parameters:

  | config | configuration object to use
  | parent | the parent object (see QObject documentation)

addItem | ( | self, |
|  | KConfigSkeletonItem | a0,
|  | QString | name=QString()
| ) |  |  |

Register a custom KConfigSkeletonItem with a given name.

If the name parameter is null, take the name from KConfigSkeletonItem.key(). Note that all names must be unique but that multiple entries can have the same key if they reside in different groups.

KCoreConfigSkeleton takes ownership of the KConfigSkeletonItem.

KCoreConfigSkeleton.ItemBool addItemBool | ( | self, |
|  | QString | name,
|  | bool | reference,
|  | bool | defaultValue=0,
|  | QString | key=QString()
| ) |  |  |

Register an item of type bool.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemDateTime addItemDateTime | ( | self, |
|  | QString | name,
|  | QDateTime | reference,
|  | QDateTime | defaultValue=QDateTime(),
|  | QString | key=QString()
| ) |  |  |

Register an item of type QDateTime.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemDouble addItemDouble | ( | self, |
|  | QString | name,
|  | float | reference,
|  | float | defaultValue=0.0,
|  | QString | key=QString()
| ) |  |  |

Register an item of type double.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemInt addItemInt | ( | self, |
|  | QString | name,
|  | int | reference,
|  | int | defaultValue=0,
|  | QString | key=QString()
| ) |  |  |

Register an item of type qint32.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemLongLong addItemInt64 | ( | self, |
|  | QString | name,
|  | long | reference,
|  | long | defaultValue=0,
|  | QString | key=QString()
| ) |  |  |

Deprecated:
  Use addItemLongLong().

KCoreConfigSkeleton.ItemIntList addItemIntList | ( | self, |
|  | QString | name,
|  | [int] | reference,
|  | [int] | defaultValue=QList<int>(),
|  | QString | key=QString()
| ) |  |  |

Register an item of type QList<int>.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemLongLong addItemLongLong | ( | self, |
|  | QString | name,
|  | long | reference,
|  | long | defaultValue=0,
|  | QString | key=QString()
| ) |  |  |

Register an item of type qint64.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemPassword addItemPassword | ( | self, |
|  | QString | name,
|  | QString | reference,
|  | QString | defaultValue=QLatin1String(""),
|  | QString | key=QString()
| ) |  |  |

Register a password item of type QString. The string value is written encrypted to the config file. Note that the current encryption scheme is very weak.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemPath addItemPath | ( | self, |
|  | QString | name,
|  | QString | reference,
|  | QString | defaultValue=QLatin1String(""),
|  | QString | key=QString()
| ) |  |  |

Register a path item of type QString. The string value is interpreted as a path. This means, dollar expension is activated for this value, so that e.g. $HOME gets expanded.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemPoint addItemPoint | ( | self, |
|  | QString | name,
|  | QPoint | reference,
|  | QPoint | defaultValue=QPoint(),
|  | QString | key=QString()
| ) |  |  |

Register an item of type QPoint.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemProperty addItemProperty | ( | self, |
|  | QString | name,
|  | QVariant | reference,
|  | QVariant | defaultValue=QVariant(),
|  | QString | key=QString()
| ) |  |  |

Register a property item of type QVariant. Note that only the following QVariant types are allowed: String, StringList, Font, Point, Rect, Size, Color, Int, UInt, Bool, Double, DateTime and Date.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemRect addItemRect | ( | self, |
|  | QString | name,
|  | QRect | reference,
|  | QRect | defaultValue=QRect(),
|  | QString | key=QString()
| ) |  |  |

Register an item of type QRect.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemSize addItemSize | ( | self, |
|  | QString | name,
|  | QSize | reference,
|  | QSize | defaultValue=QSize(),
|  | QString | key=QString()
| ) |  |  |

Register an item of type QSize.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemString addItemString | ( | self, |
|  | QString | name,
|  | QString | reference,
|  | QString | defaultValue=QLatin1String(""),
|  | QString | key=QString()
| ) |  |  |

Register an item of type QString.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemStringList addItemStringList | ( | self, |
|  | QString | name,
|  | QStringList | reference,
|  | QStringList | defaultValue=QStringList(),
|  | QString | key=QString()
| ) |  |  |

Register an item of type QStringList.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemUInt addItemUInt | ( | self, |
|  | QString | name,
|  | long | reference,
|  | long | defaultValue=0,
|  | QString | key=QString()
| ) |  |  |

Register an item of type quint32.

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KCoreConfigSkeleton.ItemULongLong addItemUInt64 | ( | self, |
|  | QString | name,
|  | long | reference,
|  | long | defaultValue=0,
|  | QString | key=QString()
| ) |  |  |

Deprecated:
  Use addItemULongLong().

KCoreConfigSkeleton.ItemULongLong addItemULongLong | ( | self, |
|  | QString | name,
|  | long | reference,
|  | long | defaultValue=0,
|  | QString | key=QString()
| ) |  |  |

Register an item of type quint64

Parameters:

  | name | Name used to identify this setting. Names must be unique.
  | reference | Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls.
  | defaultValue | Default value, which is used when the config file does not yet contain the key of this item.
  | key | Key used in config file. If key is null, name is used as key.

Returns:
  The created item

KConfig config | ( |  | self ) |

Return the KConfig object used for reading and writing the settings.

QString currentGroup | ( |  | self ) |

Returns the current group used for addItem() calls.

KConfigSkeletonItem findItem | ( | self, |
|  | QString | name
| ) |  |  |

Lookup item by name

Since:
  4.4

bool isImmutable | ( | self, |
|  | QString | name
| ) |  |  |

Return whether a certain item is immutable

Since:
  4.4

[KConfigSkeletonItem] items | ( |  | self ) |

Return list of items managed by this KCoreConfigSkeleton object.

readConfig | ( |  | self ) |

Read preferences from config file. All registered items are set to the values read from disk. This method calls usrReadConfig() after reading the settings of the registered items from the KConfig. You can overridde usrReadConfig() in derived classes if you have special requirements. If you need more fine-grained control of storing the settings from the registered items you can override readConfig() in a derived class.

setCurrentGroup | ( | self, |
|  | QString | group
| ) |  |  |

Set the config file group for subsequent addItem() calls. It is valid until setCurrentGroup() is called with a new argument. Call this before you add any items. The default value is "No Group".

setDefaults | ( |  | self ) |

Set all registered items to their default values. This method calls usrSetDefaults() after setting the defaults for the registered items. You can overridde usrSetDefaults() in derived classes if you have special requirements. If you need more fine-grained control of setting the default values of the registered items you can override setDefaults() in a derived class.

setSharedConfig | ( | self, |
|  | KSharedPtr<KSharedConfig> | pConfig
| ) |  |  |

Set the KSharedConfig object used for reading and writing the settings.

bool useDefaults | ( | self, |
|  | bool | b
| ) |  |  |

Specify whether this object should reflect the actual values or the default values. This method is implemented by usrUseDefaults(), which can be overridden in derived classes if you have special requirements and can call usrUseDefaults() directly. If you don't have control whether useDefaults() or usrUseDefaults() is called override useDefaults() directly.

Parameters:

  | b | true to make this object reflect the default values, false to make it reflect the actual values.

Returns:
  The state prior to this call

usrReadConfig | ( |  | self ) |

Perform the actual reading of the configuration file. Override in derived classes to read special config values. Called from readConfig()

usrSetDefaults | ( |  | self ) |

Perform the actual setting of default values. Override in derived classes to set special default values. Called from setDefaults()

bool usrUseDefaults | ( | self, |
|  | bool | b
| ) |  |  |

Implemented by subclasses that use special defaults. It replaces the default values with the actual values and vice versa. Called from useDefaults()

Parameters:

  | b | true to make this object reflect the default values, false to make it reflect the actual values.

Returns:
  The state prior to this call

usrWriteConfig | ( |  | self ) |

Perform the actual writing of the configuration file. Override in derived classes to write special config values. Called from writeConfig()

writeConfig | ( |  | self ) |

Write preferences to config file. The values of all registered items are written to disk. This method calls usrWriteConfig() after writing the settings from the registered items to the KConfig. You can overridde usrWriteConfig() in derived classes if you have special requirements. If you need more fine-grained control of storing the settings from the registered items you can override writeConfig() in a derived class.