• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDECore

kcoreconfigskeleton.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of KDE.
00003  *
00004  * Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
00005  * Copyright (c) 2003 Waldo Bastian <bastian@kde.org>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public License
00018  * along with this library; see the file COPYING.LIB.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef KCORECONFIGSKELETON_H
00024 #define KCORECONFIGSKELETON_H
00025 
00026 #include <kdecore_export.h>
00027 
00028 #include <kurl.h>
00029 #include <ksharedconfig.h>
00030 #include <kconfiggroup.h>
00031 
00032 #include <QtCore/QDate>
00033 #include <QtCore/QHash>
00034 #include <QtCore/QRect>
00035 #include <QtCore/QStringList>
00036 #include <QtCore/QVariant>
00037 
00038   class KConfigSkeletonItemPrivate;
00052   class KDECORE_EXPORT KConfigSkeletonItem
00053   {
00054   public:
00055     typedef QList < KConfigSkeletonItem * >List;
00056     typedef QHash < QString, KConfigSkeletonItem* > Dict;
00057     typedef QHash < QString, KConfigSkeletonItem* >::Iterator DictIterator;
00058 
00065     KConfigSkeletonItem(const QString & _group, const QString & _key);
00066 
00070     virtual ~KConfigSkeletonItem();
00071 
00075     void setGroup( const QString &_group );
00076 
00080     QString group() const;
00081 
00085     void setKey( const QString &_key );
00086 
00090     QString key() const;
00091 
00095     void setName(const QString &_name);
00096 
00100     QString name() const;
00101 
00105     void setLabel( const QString &l );
00106 
00110     QString label() const;
00111 
00116     void setToolTip( const QString &t );
00117 
00122     QString toolTip() const;
00123 
00127     void setWhatsThis( const QString &w );
00128 
00132     QString whatsThis() const;
00133 
00138     virtual void readConfig(KConfig *) = 0;
00139 
00144     virtual void writeConfig(KConfig *) = 0;
00145 
00149     virtual void readDefault(KConfig *) = 0;
00150 
00154     virtual void setProperty(const QVariant &p) = 0;
00155 
00165     virtual bool isEqual(const QVariant &p) const = 0;
00166 
00170     virtual QVariant property() const = 0;
00171 
00175     virtual QVariant minValue() const;
00176 
00180     virtual QVariant maxValue() const;
00181 
00185     virtual void setDefault() = 0;
00186 
00191     virtual void swapDefault() = 0;
00192 
00196     bool isImmutable() const;
00197 
00198   protected:
00203     void readImmutability(const KConfigGroup &group);
00204 
00205     QString mGroup; 
00206     QString mKey; 
00207     QString mName; 
00208 
00209   private:
00210     KConfigSkeletonItemPrivate * const d;
00211   };
00212 
00213 
00217 template < typename T > class KConfigSkeletonGenericItem:public KConfigSkeletonItem
00218   {
00219   public:
00224     KConfigSkeletonGenericItem(const QString & _group, const QString & _key, T & reference,
00225                 T defaultValue)
00226       : KConfigSkeletonItem(_group, _key), mReference(reference),
00227         mDefault(defaultValue), mLoadedValue(defaultValue)
00228     {
00229     }
00230 
00234     void setValue(const T & v)
00235     {
00236       mReference = v;
00237     }
00238 
00242     T & value()
00243     {
00244       return mReference;
00245     }
00246 
00250     const T & value() const
00251     {
00252       return mReference;
00253     }
00254 
00258     virtual void setDefaultValue( const T &v )
00259     {
00260       mDefault = v;
00261     }
00262 
00266     virtual void setDefault()
00267     {
00268       mReference = mDefault;
00269     }
00270 
00272     virtual void writeConfig(KConfig * config)
00273     {
00274       if ( mReference != mLoadedValue ) // Is this needed?
00275       {
00276         KConfigGroup cg(config, mGroup);
00277         if ((mDefault == mReference) && !cg.hasDefault( mKey))
00278           cg.revertToDefault( mKey );
00279         else
00280           cg.writeEntry(mKey, mReference);
00281       }
00282     }
00283 
00285         void readDefault(KConfig * config)
00286     {
00287       config->setReadDefaults(true);
00288       readConfig(config);
00289       config->setReadDefaults(false);
00290       mDefault = mReference;
00291     }
00292 
00294     void swapDefault()
00295     {
00296       T tmp = mReference;
00297       mReference = mDefault;
00298       mDefault = tmp;
00299     }
00300 
00301   protected:
00302     T & mReference; 
00303     T mDefault; 
00304     T mLoadedValue;
00305   };
00306 
00366 class KDECORE_EXPORT KCoreConfigSkeleton : public QObject
00367 {
00368   Q_OBJECT
00369 public:
00373   class KDECORE_EXPORT ItemString:public KConfigSkeletonGenericItem < QString >
00374   {
00375   public:
00376     enum Type { Normal, Password, Path };
00377 
00395     ItemString(const QString & _group, const QString & _key,
00396                QString & reference,
00397                const QString & defaultValue = QLatin1String(""), // NOT QString() !!
00398                Type type = Normal);
00399 
00401     void writeConfig(KConfig * config);
00402 
00404     void readConfig(KConfig * config);
00405 
00407     void setProperty(const QVariant & p);
00408 
00410     bool isEqual(const QVariant &p) const;
00411 
00413     QVariant property() const;
00414 
00415   private:
00416     Type mType;
00417   };
00418 
00422   class KDECORE_EXPORT ItemPassword:public ItemString
00423   {
00424   public:
00426     ItemPassword(const QString & _group, const QString & _key,
00427                QString & reference,
00428                const QString & defaultValue = QLatin1String("")); // NOT QString() !!
00429   };
00430 
00434   class KDECORE_EXPORT ItemPath:public ItemString
00435   {
00436   public:
00438     ItemPath(const QString & _group, const QString & _key,
00439              QString & reference,
00440              const QString & defaultValue = QString());
00441   };
00442 
00446     class KDECORE_EXPORT ItemUrl:public KConfigSkeletonGenericItem < KUrl >
00447     {
00448     public:
00449 
00452         ItemUrl(const QString & _group, const QString & _key,
00453                    KUrl & reference,
00454                    const KUrl & defaultValue = KUrl());
00455 
00457         void writeConfig(KConfig * config);
00458 
00460         void readConfig(KConfig * config);
00461 
00463         void setProperty(const QVariant & p);
00464 
00466     bool isEqual(const QVariant &p) const;
00467 
00469         QVariant property() const;
00470     };
00471 
00475   class KDECORE_EXPORT ItemProperty:public KConfigSkeletonGenericItem < QVariant >
00476   {
00477   public:
00479     ItemProperty(const QString & _group, const QString & _key,
00480                  QVariant & reference, const QVariant & defaultValue = 0);
00481 
00482     void readConfig(KConfig * config);
00483     void setProperty(const QVariant & p);
00484 
00486     bool isEqual(const QVariant &p) const;
00487 
00489     QVariant property() const;
00490   };
00491 
00492 
00496   class KDECORE_EXPORT ItemBool:public KConfigSkeletonGenericItem < bool >
00497   {
00498   public:
00500     ItemBool(const QString & _group, const QString & _key, bool & reference,
00501              bool defaultValue = true);
00502 
00504     void readConfig(KConfig * config);
00505 
00507     void setProperty(const QVariant & p);
00508 
00510     bool isEqual(const QVariant &p) const;
00511 
00513     QVariant property() const;
00514   };
00515 
00516 
00520   class KDECORE_EXPORT ItemInt:public KConfigSkeletonGenericItem < qint32 >
00521   {
00522   public:
00524     ItemInt(const QString & _group, const QString & _key, qint32 &reference,
00525             qint32 defaultValue = 0);
00526 
00528     void readConfig(KConfig * config);
00529 
00531     void setProperty(const QVariant & p);
00532 
00534     bool isEqual(const QVariant &p) const;
00535 
00537     QVariant property() const;
00538 
00540     QVariant minValue() const;
00541 
00543     QVariant maxValue() const;
00544 
00548     void setMinValue(qint32);
00549 
00553     void setMaxValue(qint32);
00554 
00555   private:
00556     bool mHasMin : 1;
00557     bool mHasMax : 1;
00558     qint32 mMin;
00559     qint32 mMax;
00560   };
00561 
00565   class KDECORE_EXPORT ItemLongLong:public KConfigSkeletonGenericItem < qint64 >
00566   {
00567   public:
00569     ItemLongLong(const QString & _group, const QString & _key, qint64 &reference,
00570             qint64 defaultValue = 0);
00571 
00573     void readConfig(KConfig * config);
00574 
00576     void setProperty(const QVariant & p);
00577 
00579     bool isEqual(const QVariant &p) const;
00580 
00582     QVariant property() const;
00583 
00585     QVariant minValue() const;
00586 
00588     QVariant maxValue() const;
00589 
00591     void setMinValue(qint64);
00592 
00594     void setMaxValue(qint64);
00595 
00596   private:
00597     bool mHasMin : 1;
00598     bool mHasMax : 1;
00599     qint64 mMin;
00600     qint64 mMax;
00601   };
00602 #ifndef KDE_NO_DEPRECATED
00603   typedef KDE_DEPRECATED ItemLongLong ItemInt64;
00604 #endif
00605 
00609   class KDECORE_EXPORT ItemEnum:public ItemInt
00610   {
00611   public:
00612     //KDE5: remove the old Choice struct, rename Choice2 to Choice
00613     struct Choice
00614     {
00615       QString name;
00616       QString label;
00617       QString whatsThis;
00618     };
00619 
00620     struct Choice2
00621     {
00622       QString name;
00623       QString label;
00624       QString toolTip;
00625       QString whatsThis;
00626     };
00627 
00631     ItemEnum(const QString & _group, const QString & _key, qint32 &reference,
00632              const QList<Choice> &choices, qint32 defaultValue = 0);
00633 
00637     ItemEnum(const QString & _group, const QString & _key, qint32 &reference,
00638              const QList<Choice2> &choices, qint32 defaultValue = 0);
00639 
00640     QList<Choice> choices() const;
00641     QList<Choice2> choices2() const;
00642 
00644     void readConfig(KConfig * config);
00645 
00647     void writeConfig(KConfig * config);
00648 
00649   private:
00650     QList<Choice2> mChoices;
00651   };
00652 
00653 
00657   class KDECORE_EXPORT ItemUInt:public KConfigSkeletonGenericItem < quint32 >
00658   {
00659   public:
00661     ItemUInt(const QString & _group, const QString & _key,
00662              quint32 &reference, quint32 defaultValue = 0);
00663 
00665     void readConfig(KConfig * config);
00666 
00668     void setProperty(const QVariant & p);
00669 
00671     bool isEqual(const QVariant &p) const;
00672 
00674     QVariant property() const;
00675 
00677     QVariant minValue() const;
00678 
00680     QVariant maxValue() const;
00681 
00683     void setMinValue(quint32);
00684 
00686     void setMaxValue(quint32);
00687 
00688   private:
00689     bool mHasMin : 1;
00690     bool mHasMax : 1;
00691     quint32 mMin;
00692     quint32 mMax;
00693   };
00694 
00698   class KDECORE_EXPORT ItemULongLong:public KConfigSkeletonGenericItem < quint64 >
00699   {
00700   public:
00702     ItemULongLong(const QString & _group, const QString & _key, quint64 &reference,
00703             quint64 defaultValue = 0);
00704 
00706     void readConfig(KConfig * config);
00707 
00709     void setProperty(const QVariant & p);
00710 
00712     bool isEqual(const QVariant &p) const;
00713 
00715     QVariant property() const;
00716 
00718     QVariant minValue() const;
00719 
00721     QVariant maxValue() const;
00722 
00724     void setMinValue(quint64);
00725 
00727     void setMaxValue(quint64);
00728 
00729   private:
00730     bool mHasMin : 1;
00731     bool mHasMax : 1;
00732     quint64 mMin;
00733     quint64 mMax;
00734   };
00735 #ifndef KDE_NO_DEPRECATED
00736   typedef KDE_DEPRECATED ItemULongLong ItemUInt64;
00737 #endif
00738 
00742   class KDECORE_EXPORT ItemDouble:public KConfigSkeletonGenericItem < double >
00743   {
00744   public:
00746     ItemDouble(const QString & _group, const QString & _key,
00747                double &reference, double defaultValue = 0);
00748 
00750     void readConfig(KConfig * config);
00751 
00753     void setProperty(const QVariant & p);
00754 
00756     bool isEqual(const QVariant &p) const;
00757 
00759     QVariant property() const;
00760 
00762     QVariant minValue() const;
00763 
00765     QVariant maxValue() const;
00766 
00768     void setMinValue(double);
00769 
00771     void setMaxValue(double);
00772 
00773   private:
00774     bool mHasMin : 1;
00775     bool mHasMax : 1;
00776     double mMin;
00777     double mMax;
00778   };
00779 
00780 
00784   class KDECORE_EXPORT ItemRect:public KConfigSkeletonGenericItem < QRect >
00785   {
00786   public:
00788     ItemRect(const QString & _group, const QString & _key, QRect & reference,
00789              const QRect & defaultValue = QRect());
00790 
00792     void readConfig(KConfig * config);
00793 
00795     void setProperty(const QVariant & p);
00796 
00798     bool isEqual(const QVariant &p) const;
00799 
00801     QVariant property() const;
00802   };
00803 
00804 
00808   class KDECORE_EXPORT ItemPoint:public KConfigSkeletonGenericItem < QPoint >
00809   {
00810   public:
00812     ItemPoint(const QString & _group, const QString & _key, QPoint & reference,
00813               const QPoint & defaultValue = QPoint());
00814 
00816     void readConfig(KConfig * config);
00817 
00819     void setProperty(const QVariant & p);
00820 
00822     bool isEqual(const QVariant &p) const;
00823 
00825     QVariant property() const;
00826   };
00827 
00828 
00832   class KDECORE_EXPORT ItemSize:public KConfigSkeletonGenericItem < QSize >
00833   {
00834   public:
00836     ItemSize(const QString & _group, const QString & _key, QSize & reference,
00837              const QSize & defaultValue = QSize());
00838 
00840     void readConfig(KConfig * config);
00841 
00843     void setProperty(const QVariant & p);
00844 
00846     bool isEqual(const QVariant &p) const;
00847 
00849     QVariant property() const;
00850   };
00851 
00852 
00856   class KDECORE_EXPORT ItemDateTime:public KConfigSkeletonGenericItem < QDateTime >
00857   {
00858   public:
00860     ItemDateTime(const QString & _group, const QString & _key,
00861                  QDateTime & reference,
00862                  const QDateTime & defaultValue = QDateTime());
00863 
00865     void readConfig(KConfig * config);
00866 
00868     void setProperty(const QVariant & p);
00869 
00871     bool isEqual(const QVariant &p) const;
00872 
00874     QVariant property() const;
00875   };
00876 
00877 
00881   class KDECORE_EXPORT ItemStringList:public KConfigSkeletonGenericItem < QStringList >
00882   {
00883   public:
00885     ItemStringList(const QString & _group, const QString & _key,
00886                    QStringList & reference,
00887                    const QStringList & defaultValue = QStringList());
00888 
00890     void readConfig(KConfig * config);
00891 
00893     void setProperty(const QVariant & p);
00894 
00896     bool isEqual(const QVariant &p) const;
00897 
00899     QVariant property() const;
00900   };
00901 
00902 
00906   class KDECORE_EXPORT ItemPathList:public ItemStringList
00907   {
00908   public:
00910     ItemPathList(const QString & _group, const QString & _key,
00911                    QStringList & reference,
00912                    const QStringList & defaultValue = QStringList());
00913 
00915     void readConfig(KConfig * config);
00917     void writeConfig(KConfig * config);
00918   };
00919 
00923     class KDECORE_EXPORT ItemUrlList:public KConfigSkeletonGenericItem < KUrl::List >
00924     {
00925     public:
00927         ItemUrlList(const QString & _group, const QString & _key,
00928                      KUrl::List & reference,
00929                      const KUrl::List & defaultValue = KUrl::List());
00930 
00932         void readConfig(KConfig * config);
00933 
00935         void writeConfig(KConfig * config);
00936 
00938         void setProperty(const QVariant & p);
00939 
00941     bool isEqual(const QVariant &p) const;
00942 
00944         QVariant property() const;
00945     };
00946 
00950   class KDECORE_EXPORT ItemIntList:public KConfigSkeletonGenericItem < QList < int > >
00951   {
00952   public:
00954     ItemIntList(const QString & _group, const QString & _key,
00955                 QList < int >&reference,
00956                 const QList < int >&defaultValue = QList < int >());
00957 
00959     void readConfig(KConfig * config);
00960 
00962     void setProperty(const QVariant & p);
00963 
00965     bool isEqual(const QVariant &p) const;
00966 
00968     QVariant property() const;
00969   };
00970 
00971 
00972 public:
00980   explicit KCoreConfigSkeleton(const QString & configname = QString(), QObject* parent = 0);
00981 
00988   explicit KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject* parent = 0);
00989 
00993   virtual ~KCoreConfigSkeleton();
00994 
01003   virtual void setDefaults();
01004 
01014   virtual void readConfig();
01015 
01025   virtual void writeConfig();
01026 
01032   void setCurrentGroup(const QString & group);
01033 
01037   QString currentGroup() const;
01038 
01048   void addItem(KConfigSkeletonItem *, const QString & name = QString() );
01049 
01061   ItemString *addItemString(const QString & name, QString & reference,
01062                             const QString & defaultValue = QLatin1String(""), // NOT QString() !!
01063                             const QString & key = QString());
01064 
01078   ItemPassword *addItemPassword(const QString & name, QString & reference,
01079                               const QString & defaultValue = QLatin1String(""),
01080                               const QString & key = QString());
01081 
01095   ItemPath *addItemPath(const QString & name, QString & reference,
01096                           const QString & defaultValue = QLatin1String(""),
01097                           const QString & key = QString());
01098 
01112   ItemProperty *addItemProperty(const QString & name, QVariant & reference,
01113                                 const QVariant & defaultValue = QVariant(),
01114                                 const QString & key = QString());
01126   ItemBool *addItemBool(const QString & name, bool & reference,
01127                         bool defaultValue = false,
01128                         const QString & key = QString());
01129 
01141   ItemInt *addItemInt(const QString & name, qint32 &reference, qint32 defaultValue = 0,
01142                       const QString & key = QString());
01143 
01155   ItemUInt *addItemUInt(const QString & name, quint32 &reference,
01156                         quint32 defaultValue = 0,
01157                         const QString & key = QString());
01158 
01170   ItemLongLong *addItemLongLong(const QString & name, qint64 &reference,
01171                           qint64 defaultValue = 0,
01172                           const QString & key = QString());
01173 
01178 #ifndef KDE_NO_DEPRECATED
01179   KDE_DEPRECATED ItemLongLong *addItemInt64( const QString& name, qint64 &reference,
01180                           qint64 defaultValue = 0,
01181                           const QString & key = QString());
01182 #endif
01183 
01195   ItemULongLong *addItemULongLong(const QString & name, quint64 &reference,
01196                             quint64 defaultValue = 0,
01197                             const QString & key = QString());
01198 
01203 #ifndef KDE_NO_DEPRECATED
01204   KDE_DEPRECATED ItemULongLong *addItemUInt64(const QString & name, quint64 &reference,
01205                             quint64 defaultValue = 0,
01206                             const QString & key = QString());
01207 #endif
01208 
01220   ItemDouble *addItemDouble(const QString & name, double &reference,
01221                             double defaultValue = 0.0,
01222                             const QString & key = QString());
01223 
01235   ItemRect *addItemRect(const QString & name, QRect & reference,
01236                         const QRect & defaultValue = QRect(),
01237                         const QString & key = QString());
01238 
01250   ItemPoint *addItemPoint(const QString & name, QPoint & reference,
01251                           const QPoint & defaultValue = QPoint(),
01252                           const QString & key = QString());
01253 
01265   ItemSize *addItemSize(const QString & name, QSize & reference,
01266                         const QSize & defaultValue = QSize(),
01267                         const QString & key = QString());
01268 
01280   ItemDateTime *addItemDateTime(const QString & name, QDateTime & reference,
01281                                 const QDateTime & defaultValue = QDateTime(),
01282                                 const QString & key = QString());
01283 
01295   ItemStringList *addItemStringList(const QString & name, QStringList & reference,
01296                                     const QStringList & defaultValue = QStringList(),
01297                                     const QString & key = QString());
01298 
01310   ItemIntList *addItemIntList(const QString & name, QList < int >&reference,
01311                               const QList < int >&defaultValue =
01312                               QList < int >(),
01313                               const QString & key = QString());
01314 
01318   KConfig *config();
01319 
01323   const KConfig *config() const;
01324 
01328   void setSharedConfig(KSharedConfig::Ptr pConfig);
01329 
01333   KConfigSkeletonItem::List items() const;
01334 
01335   // KDE5 TODO: Remove this non-const version. Kept only for BC.
01339   bool isImmutable(const QString & name);
01340 
01345   bool isImmutable(const QString & name) const;
01346 
01347   // KDE5 TODO: Remove this non-const version. Kept only for BC.
01351   KConfigSkeletonItem * findItem(const QString & name);
01352 
01357   KConfigSkeletonItem * findItem(const QString & name) const;
01358 
01371   virtual bool useDefaults(bool b);
01372 
01373 Q_SIGNALS:
01377   void configChanged();
01378 
01379 protected:
01388   virtual bool usrUseDefaults(bool b);
01389 
01395   virtual void usrSetDefaults();
01396 
01402   virtual void usrReadConfig();
01403 
01409   virtual void usrWriteConfig();
01410 
01411 private:
01412   class Private;
01413   Private * const d;
01414   friend class KConfigSkeleton;
01415 
01416 };
01417 
01418 #endif

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal