kconfigskeleton.h
/*
* This file is part of KDE.
*
* Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
* Copyright (c) 2003 Waldo Bastian <bastian@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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KCONFIGSKELETON_H
#define _KCONFIGSKELETON_H
#include <qcolor.h>
#include <qdatetime.h>
#include <qfont.h>
#include <qpoint.h>
#include <qptrlist.h>
#include <qdict.h>
#include <qrect.h>
#include <qsize.h>
#include <qstringlist.h>
#include <qvariant.h>
#include <kconfig.h>
#include <kglobalsettings.h>
class KDECORE_EXPORT KConfigSkeletonItem
{
public:
typedef QValueList < KConfigSkeletonItem * >List;
typedef QDict < KConfigSkeletonItem > Dict;
typedef QDictIterator < KConfigSkeletonItem > DictIterator;
KConfigSkeletonItem(const QString & group, const QString & key)
:mGroup(group),mKey(key), mIsImmutable(true)
{
}
virtual ~KConfigSkeletonItem()
{
}
void setGroup( const QString &group )
{
mGroup = group;
}
QString group() const
{
return mGroup;
}
void setKey( const QString &key )
{
mKey = key;
}
QString key() const
{
return mKey;
}
void setName(const QString &name)
{
mName = name;
}
QString name() const
{
return mName;
}
void setLabel( const QString &l )
{
mLabel = l;
}
QString label() const
{
return mLabel;
}
void setWhatsThis( const QString &w )
{
mWhatsThis = w;
}
QString whatsThis() const
{
return mWhatsThis;
}
virtual void readConfig(KConfig *) = 0;
virtual void writeConfig(KConfig *) = 0;
virtual void readDefault(KConfig *) = 0;
virtual void setProperty(const QVariant &p) = 0;
virtual QVariant property() const = 0;
virtual QVariant minValue() const { return QVariant(); }
virtual QVariant maxValue() const { return QVariant(); }
virtual void setDefault() = 0;
virtual void swapDefault() = 0;
bool isImmutable() const
{
return mIsImmutable;
}
protected:
void readImmutability(KConfig *config);
QString mGroup;
QString mKey;
QString mName;
private:
bool mIsImmutable;
QString mLabel;
QString mWhatsThis;
};
template < typename T > class KConfigSkeletonGenericItem:public KConfigSkeletonItem
{
public:
KConfigSkeletonGenericItem(const QString & group, const QString & key, T & reference,
T defaultValue)
: KConfigSkeletonItem(group, key), mReference(reference),
mDefault(defaultValue), mLoadedValue(defaultValue)
{
}
void setValue(const T & v)
{
mReference = v;
}
T & value()
{
return mReference;
}
const T & value() const
{
return mReference;
}
virtual void setDefaultValue( const T &v )
{
mDefault = v;
}
virtual void setDefault()
{
mReference = mDefault;
}
virtual void writeConfig(KConfig * config)
{
if ( mReference != mLoadedValue ) // Is this needed?
{
config->setGroup(mGroup);
if ((mDefault == mReference) && !config->hasDefault( mKey))
config->revertToDefault( mKey );
else
config->writeEntry(mKey, mReference);
}
}
void readDefault(KConfig * config)
{
config->setReadDefaults(true);
readConfig(config);
config->setReadDefaults(false);
mDefault = mReference;
}
void swapDefault()
{
T tmp = mReference;
mReference = mDefault;
mDefault = tmp;
}
protected:
T & mReference;
T mDefault;
T mLoadedValue;
};
class KDECORE_EXPORT KConfigSkeleton
{
public:
class KDECORE_EXPORT ItemString:public KConfigSkeletonGenericItem < QString >
{
public:
enum Type { Normal, Password, Path };
ItemString(const QString & group, const QString & key,
QString & reference,
const QString & defaultValue = QString::fromLatin1(""), // NOT QString::null !!
Type type = Normal);
void writeConfig(KConfig * config);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
private:
Type mType;
};
class KDECORE_EXPORT ItemPassword:public ItemString
{
public:
ItemPassword(const QString & group, const QString & key,
QString & reference,
const QString & defaultValue = QString::fromLatin1("")); // NOT QString::null !!
};
class KDECORE_EXPORT ItemPath:public ItemString
{
public:
ItemPath(const QString & group, const QString & key,
QString & reference,
const QString & defaultValue = QString::null);
};
class KDECORE_EXPORT ItemProperty:public KConfigSkeletonGenericItem < QVariant >
{
public:
ItemProperty(const QString & group, const QString & key,
QVariant & reference, QVariant defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemBool:public KConfigSkeletonGenericItem < bool >
{
public:
ItemBool(const QString & group, const QString & key, bool & reference,
bool defaultValue = true);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemInt:public KConfigSkeletonGenericItem < int >
{
public:
ItemInt(const QString & group, const QString & key, int &reference,
int defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
QVariant minValue() const;
QVariant maxValue() const;
void setMinValue(int);
void setMaxValue(int);
private:
bool mHasMin : 1;
bool mHasMax : 1;
int mMin;
int mMax;
};
class KDECORE_EXPORT ItemInt64:public KConfigSkeletonGenericItem < Q_INT64 >
{
public:
ItemInt64(const QString & group, const QString & key, Q_INT64 &reference,
Q_INT64 defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
QVariant minValue() const;
QVariant maxValue() const;
void setMinValue(Q_INT64);
void setMaxValue(Q_INT64);
private:
bool mHasMin : 1;
bool mHasMax : 1;
Q_INT64 mMin;
Q_INT64 mMax;
};
class KDECORE_EXPORT ItemEnum:public ItemInt
{
public:
struct Choice
{
QString name;
QString label;
QString whatsThis;
};
ItemEnum(const QString & group, const QString & key, int &reference,
const QValueList<Choice> &choices, int defaultValue = 0);
QValueList<Choice> choices() const;
void readConfig(KConfig * config);
void writeConfig(KConfig * config);
private:
QValueList<Choice> mChoices;
};
class KDECORE_EXPORT ItemUInt:public KConfigSkeletonGenericItem < unsigned int >
{
public:
ItemUInt(const QString & group, const QString & key,
unsigned int &reference, unsigned int defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
QVariant minValue() const;
QVariant maxValue() const;
void setMinValue(unsigned int);
void setMaxValue(unsigned int);
private:
bool mHasMin : 1;
bool mHasMax : 1;
unsigned int mMin;
unsigned int mMax;
};
class KDECORE_EXPORT ItemLong:public KConfigSkeletonGenericItem < long >
{
public:
ItemLong(const QString & group, const QString & key, long &reference,
long defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
QVariant minValue() const;
QVariant maxValue() const;
void setMinValue(long);
void setMaxValue(long);
private:
bool mHasMin : 1;
bool mHasMax : 1;
long mMin;
long mMax;
};
class KDECORE_EXPORT ItemULong:public KConfigSkeletonGenericItem < unsigned long >
{
public:
ItemULong(const QString & group, const QString & key,
unsigned long &reference, unsigned long defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
QVariant minValue() const;
QVariant maxValue() const;
void setMinValue(unsigned long);
void setMaxValue(unsigned long);
private:
bool mHasMin : 1;
bool mHasMax : 1;
unsigned long mMin;
unsigned long mMax;
};
class KDECORE_EXPORT ItemUInt64:public KConfigSkeletonGenericItem < Q_UINT64 >
{
public:
ItemUInt64(const QString & group, const QString & key, Q_UINT64 &reference,
Q_UINT64 defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
QVariant minValue() const;
QVariant maxValue() const;
void setMinValue(Q_UINT64);
void setMaxValue(Q_UINT64);
private:
bool mHasMin : 1;
bool mHasMax : 1;
Q_UINT64 mMin;
Q_UINT64 mMax;
};
class KDECORE_EXPORT ItemDouble:public KConfigSkeletonGenericItem < double >
{
public:
ItemDouble(const QString & group, const QString & key,
double &reference, double defaultValue = 0);
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
QVariant minValue() const;
QVariant maxValue() const;
void setMinValue(double);
void setMaxValue(double);
private:
bool mHasMin : 1;
bool mHasMax : 1;
double mMin;
double mMax;
};
class KDECORE_EXPORT ItemColor:public KConfigSkeletonGenericItem < QColor >
{
public:
ItemColor(const QString & group, const QString & key,
QColor & reference,
const QColor & defaultValue = QColor(128, 128, 128));
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemFont:public KConfigSkeletonGenericItem < QFont >
{
public:
ItemFont(const QString & group, const QString & key, QFont & reference,
const QFont & defaultValue = KGlobalSettings::generalFont());
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemRect:public KConfigSkeletonGenericItem < QRect >
{
public:
ItemRect(const QString & group, const QString & key, QRect & reference,
const QRect & defaultValue = QRect());
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemPoint:public KConfigSkeletonGenericItem < QPoint >
{
public:
ItemPoint(const QString & group, const QString & key, QPoint & reference,
const QPoint & defaultValue = QPoint());
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemSize:public KConfigSkeletonGenericItem < QSize >
{
public:
ItemSize(const QString & group, const QString & key, QSize & reference,
const QSize & defaultValue = QSize());
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemDateTime:public KConfigSkeletonGenericItem < QDateTime >
{
public:
ItemDateTime(const QString & group, const QString & key,
QDateTime & reference,
const QDateTime & defaultValue = QDateTime());
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemStringList:public KConfigSkeletonGenericItem < QStringList >
{
public:
ItemStringList(const QString & group, const QString & key,
QStringList & reference,
const QStringList & defaultValue = QStringList());
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
class KDECORE_EXPORT ItemPathList:public ItemStringList
{
public:
ItemPathList(const QString & group, const QString & key,
QStringList & reference,
const QStringList & defaultValue = QStringList());
void readConfig(KConfig * config);
void writeConfig(KConfig * config);
};
class KDECORE_EXPORT ItemIntList:public KConfigSkeletonGenericItem < QValueList < int > >
{
public:
ItemIntList(const QString & group, const QString & key,
QValueList < int >&reference,
const QValueList < int >&defaultValue = QValueList < int >());
void readConfig(KConfig * config);
void setProperty(const QVariant & p);
QVariant property() const;
};
public:
KConfigSkeleton(const QString & configname = QString::null);
KConfigSkeleton(KSharedConfig::Ptr config);
virtual ~ KConfigSkeleton();
void setDefaults();
void readConfig();
void writeConfig();
void setCurrentGroup(const QString & group);
QString currentGroup() // ### KDE 4.0: make const
{
return mCurrentGroup;
}
void addItem(KConfigSkeletonItem *, const QString & name = QString::null );
ItemString *addItemString(const QString & name, QString & reference,
const QString & defaultValue = QString::fromLatin1(""), // NOT QString::null !!
const QString & key = QString::null);
ItemPassword *addItemPassword(const QString & name, QString & reference,
const QString & defaultValue = QString::fromLatin1(""),
const QString & key = QString::null);
ItemPath *addItemPath(const QString & name, QString & reference,
const QString & defaultValue = QString::fromLatin1(""),
const QString & key = QString::null);
ItemProperty *addItemProperty(const QString & name, QVariant & reference,
const QVariant & defaultValue = QVariant(),
const QString & key = QString::null);
ItemBool *addItemBool(const QString & name, bool & reference,
bool defaultValue = false,
const QString & key = QString::null);
ItemInt *addItemInt(const QString & name, int &reference, int defaultValue = 0,
const QString & key = QString::null);
ItemUInt *addItemUInt(const QString & name, unsigned int &reference,
unsigned int defaultValue = 0,
const QString & key = QString::null);
ItemLong *addItemLong(const QString & name, long &reference,
long defaultValue = 0,
const QString & key = QString::null);
ItemULong *addItemULong(const QString & name, unsigned long &reference,
unsigned long defaultValue = 0,
const QString & key = QString::null);
ItemInt64 *addItemInt64(const QString & name, Q_INT64 &reference,
Q_INT64 defaultValue = 0,
const QString & key = QString::null);
ItemUInt64 *addItemUInt64(const QString & name, Q_UINT64 &reference,
Q_UINT64 defaultValue = 0,
const QString & key = QString::null);
ItemDouble *addItemDouble(const QString & name, double &reference,
double defaultValue = 0.0,
const QString & key = QString::null);
ItemColor *addItemColor(const QString & name, QColor & reference,
const QColor & defaultValue = QColor(128, 128, 128),
const QString & key = QString::null);
ItemFont *addItemFont(const QString & name, QFont & reference,
const QFont & defaultValue =
KGlobalSettings::generalFont(),
const QString & key = QString::null);
ItemRect *addItemRect(const QString & name, QRect & reference,
const QRect & defaultValue = QRect(),
const QString & key = QString::null);
ItemPoint *addItemPoint(const QString & name, QPoint & reference,
const QPoint & defaultValue = QPoint(),
const QString & key = QString::null);
ItemSize *addItemSize(const QString & name, QSize & reference,
const QSize & defaultValue = QSize(),
const QString & key = QString::null);
ItemDateTime *addItemDateTime(const QString & name, QDateTime & reference,
const QDateTime & defaultValue = QDateTime(),
const QString & key = QString::null);
ItemStringList *addItemStringList(const QString & name, QStringList & reference,
const QStringList & defaultValue = QStringList(),
const QString & key = QString::null);
ItemIntList *addItemIntList(const QString & name, QValueList < int >&reference,
const QValueList < int >&defaultValue =
QValueList < int >(),
const QString & key = QString::null);
KConfig *config() const;
KConfigSkeletonItem::List items() const
{
return mItems;
}
bool isImmutable(const QString & name);
KConfigSkeletonItem * findItem(const QString & name);
bool useDefaults(bool b);
protected:
virtual void usrUseDefaults(bool)
{
}
virtual void usrSetDefaults()
{
}
virtual void usrReadConfig()
{
}
virtual void usrWriteConfig()
{
}
private:
QString mCurrentGroup;
KSharedConfig::Ptr mConfig; // pointer to KConfig object
KConfigSkeletonItem::List mItems;
KConfigSkeletonItem::Dict mItemDict;
bool mUseDefaults;
class Private;
Private *d;
};
#endif
KConfigSkeleton::usrUseDefaults
virtual void usrUseDefaults(bool)
Implemented by subclasses that use special defaults.
Definition: kconfigskeleton.h:1193
KSharedPtr< KSharedConfig >
KConfigSkeletonItem::setDefault
virtual void setDefault()=0
Sets the current value to the default value.
KConfigSkeletonItem::setName
void setName(const QString &name)
Set internal name of entry.
Definition: kconfigskeleton.h:110
KConfigSkeleton::ItemStringList::readConfig
void readConfig(KConfig *config)
This function is called by KConfigSkeleton to read the value for this setting from a config file...
Definition: kconfigskeleton.cpp:793
KConfigSkeletonItem::setGroup
void setGroup(const QString &group)
Set config file group.
Definition: kconfigskeleton.h:78
KConfigSkeleton::ItemRect
Class for handling a QRect preferences item.
Definition: kconfigskeleton.h:684
KConfigSkeletonItem::~KConfigSkeletonItem
virtual ~KConfigSkeletonItem()
Destructor.
Definition: kconfigskeleton.h:71
KConfigSkeletonItem::group
QString group() const
Return config file group.
Definition: kconfigskeleton.h:86
KConfigSkeleton::ItemInt
Class for handling an integer preferences item.
Definition: kconfigskeleton.h:447
KConfigSkeleton::ItemULong
Class for handling an unsigned long integer preferences item.
Definition: kconfigskeleton.h:576
KConfigSkeletonItem::readDefault
virtual void readDefault(KConfig *)=0
Read global default value.
KConfigSkeletonItem::isImmutable
bool isImmutable() const
Return if the entry can be modified.
Definition: kconfigskeleton.h:207
KConfigBase::hasDefault
bool hasDefault(const QString &key) const
Returns whether a default is specified for an entry in either the system wide configuration file or t...
Definition: kconfigbase.cpp:1761
KConfigSkeletonItem::writeConfig
virtual void writeConfig(KConfig *)=0
This function is called by KConfigSkeleton to write the value of this setting to a config file...
KConfigSkeletonItem::setKey
void setKey(const QString &key)
Set config file key.
Definition: kconfigskeleton.h:94
KConfigSkeleton::ItemProperty
Class for handling a QVariant preferences item.
Definition: kconfigskeleton.h:417
KConfigSkeleton
Class for handling preferences settings for an application.
Definition: kconfigskeleton.h:365
KConfigSkeleton::ItemUInt64
Class for handling unsigned 64-bit integer preferences item.
Definition: kconfigskeleton.h:601
KConfigSkeleton::ItemBool
Class for handling a bool preferences item.
Definition: kconfigskeleton.h:432
KConfigSkeleton::ItemInt::readConfig
void readConfig(KConfig *config)
This function is called by KConfigSkeleton to read the value for this setting from a config file...
Definition: kconfigskeleton.cpp:175
KConfigSkeleton::ItemStringList
Class for handling a string list preferences item.
Definition: kconfigskeleton.h:745
KConfigSkeletonItem::minValue
virtual QVariant minValue() const
Return minimum value of item or invalid if not specified.
Definition: kconfigskeleton.h:186
KConfigSkeleton::ItemFont
Class for handling a font preferences item.
Definition: kconfigskeleton.h:669
KConfigSkeletonItem::readConfig
virtual void readConfig(KConfig *)=0
This function is called by KConfigSkeleton to read the value for this setting from a config file...
KConfigSkeletonItem::setWhatsThis
void setWhatsThis(const QString &w)
Set WhatsThis description og item.
Definition: kconfigskeleton.h:142
KConfigSkeleton::usrWriteConfig
virtual void usrWriteConfig()
Implemented by subclasses that write special config values.
Definition: kconfigskeleton.h:1211
KConfigSkeleton::ItemInt64
Class for handling an 64-bit integer preferences item.
Definition: kconfigskeleton.h:472
KConfigSkeleton::ItemPassword
Class for handling a password preferences item.
Definition: kconfigskeleton.h:394
KConfigSkeleton::ItemPath
Class for handling a path preferences item.
Definition: kconfigskeleton.h:405
KConfigSkeleton::ItemPoint
Class for handling a QPoint preferences item.
Definition: kconfigskeleton.h:699
KConfigBase::setReadDefaults
void setReadDefaults(bool b)
When set, all readEntry and readXXXEntry calls return the system wide (default) values instead of the...
Definition: kconfigbase.cpp:1718
KConfigSkeletonItem::label
QString label() const
Return label of item.
Definition: kconfigskeleton.h:134
KConfigSkeleton::ItemLong
Class for hanlding a long integer preferences item.
Definition: kconfigskeleton.h:550
KConfigSkeletonItem::setLabel
void setLabel(const QString &l)
Set label providing a translated one-line description of the item.
Definition: kconfigskeleton.h:126
KConfigSkeletonItem::swapDefault
virtual void swapDefault()=0
Exchanges the current value with the default value Used by KConfigSkeleton::useDefaults(bool);.
KConfigSkeletonItem::KConfigSkeletonItem
KConfigSkeletonItem(const QString &group, const QString &key)
Constructor.
Definition: kconfigskeleton.h:63
KConfigSkeletonItem::name
QString name() const
Return internal name of entry.
Definition: kconfigskeleton.h:118
KConfigSkeleton::ItemDouble
Class for handling a floating point preference item.
Definition: kconfigskeleton.h:627
KConfigSkeletonItem::key
QString key() const
Return config file key.
Definition: kconfigskeleton.h:102
KConfigSkeleton::currentGroup
QString currentGroup()
Returns the current group used for addItem() calls.
Definition: kconfigskeleton.h:837
KConfigSkeleton::items
KConfigSkeletonItem::List items() const
Return list of items managed by this KConfigSkeleton object.
Definition: kconfigskeleton.h:1164
KConfigSkeleton::ItemPathList
Class for handling a path list preferences item.
Definition: kconfigskeleton.h:761
KConfigBase::revertToDefault
void revertToDefault(const QString &key)
Reverts the entry with key key in the current group in the application specific config file to either...
Definition: kconfigbase.cpp:1734
KConfig
Access KDE Configuration entries.
Definition: kconfig.h:43
KGlobalSettings::generalFont
static QFont generalFont()
Returns the default general font.
Definition: kglobalsettings.cpp:319
KConfigSkeleton::ItemUInt
Class for handling an unsingend integer preferences item.
Definition: kconfigskeleton.h:524
KConfigSkeleton::ItemSize
Class for handling a QSize preferences item.
Definition: kconfigskeleton.h:714
KConfigSkeletonItem::whatsThis
QString whatsThis() const
Return WhatsThis description of item.
Definition: kconfigskeleton.h:150
KConfigSkeleton::ItemColor
Class for handling a color preferences item.
Definition: kconfigskeleton.h:653
KConfigSkeletonItem
Class for storing a preferences setting.
Definition: kconfigskeleton.h:50
KConfigSkeleton::usrReadConfig
virtual void usrReadConfig()
Implemented by subclasses that read special config values.
Definition: kconfigskeleton.h:1204
KConfigSkeleton::ItemString
Class for handling a string preferences item.
Definition: kconfigskeleton.h:372
KConfigBase::setGroup
void setGroup(const QString &group)
Specifies the group in which keys will be read and written.
Definition: kconfigbase.cpp:79
KConfigSkeleton::ItemEnum
Class for handling enums.
Definition: kconfigskeleton.h:498
KConfigSkeletonItem::maxValue
virtual QVariant maxValue() const
Return maximum value of item or invalid if not specified.
Definition: kconfigskeleton.h:191
KConfigBase::writeEntry
void writeEntry(const QString &pKey, const QString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a key/value pair.
Definition: kconfigbase.cpp:1012
KConfigSkeleton::ItemIntList
Class for handling an integer list preferences item.
Definition: kconfigskeleton.h:776
KConfigSkeleton::ItemDateTime
Class for handling a QDateTime preferences item.
Definition: kconfigskeleton.h:729

KDE Home | KDE Accessibility Home | Description of Access Keys