• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 
00115     void setWhatsThis( const QString &w );
00116 
00120     QString whatsThis() const;
00121 
00126     virtual void readConfig(KConfig *) = 0;
00127 
00132     virtual void writeConfig(KConfig *) = 0;
00133 
00137     virtual void readDefault(KConfig *) = 0;
00138 
00142     virtual void setProperty(const QVariant &p) = 0;
00143 
00153     virtual bool isEqual(const QVariant &v) const = 0;
00154 
00158     virtual QVariant property() const = 0;
00159 
00163     virtual QVariant minValue() const;
00164 
00168     virtual QVariant maxValue() const;
00169 
00173     virtual void setDefault() = 0;
00174 
00179     virtual void swapDefault() = 0;
00180 
00184     bool isImmutable() const;
00185 
00186   protected:
00191     void readImmutability(const KConfigGroup &group);
00192 
00193     QString mGroup; 
00194     QString mKey; 
00195     QString mName; 
00196 
00197   private:
00198     KConfigSkeletonItemPrivate * const d;
00199   };
00200 
00201 
00205 template < typename T > class KConfigSkeletonGenericItem:public KConfigSkeletonItem
00206   {
00207   public:
00212     KConfigSkeletonGenericItem(const QString & _group, const QString & _key, T & reference,
00213                 T defaultValue)
00214       : KConfigSkeletonItem(_group, _key), mReference(reference),
00215         mDefault(defaultValue), mLoadedValue(defaultValue)
00216     {
00217     }
00218 
00222     void setValue(const T & v)
00223     {
00224       mReference = v;
00225     }
00226 
00230     T & value()
00231     {
00232       return mReference;
00233     }
00234 
00238     const T & value() const
00239     {
00240       return mReference;
00241     }
00242 
00246     virtual void setDefaultValue( const T &v )
00247     {
00248       mDefault = v;
00249     }
00250 
00254     virtual void setDefault()
00255     {
00256       mReference = mDefault;
00257     }
00258 
00260     virtual void writeConfig(KConfig * config)
00261     {
00262       if ( mReference != mLoadedValue ) // Is this needed?
00263       {
00264         KConfigGroup cg(config, mGroup);
00265         if ((mDefault == mReference) && !cg.hasDefault( mKey))
00266           cg.revertToDefault( mKey );
00267         else
00268           cg.writeEntry(mKey, mReference);
00269       }
00270     }
00271 
00273         void readDefault(KConfig * config)
00274     {
00275       config->setReadDefaults(true);
00276       readConfig(config);
00277       config->setReadDefaults(false);
00278       mDefault = mReference;
00279     }
00280 
00282     void swapDefault()
00283     {
00284       T tmp = mReference;
00285       mReference = mDefault;
00286       mDefault = tmp;
00287     }
00288 
00289   protected:
00290     T & mReference; 
00291     T mDefault; 
00292     T mLoadedValue;
00293   };
00294 
00354 class KDECORE_EXPORT KCoreConfigSkeleton : public QObject
00355 {
00356   Q_OBJECT
00357 public:
00361   class KDECORE_EXPORT ItemString:public KConfigSkeletonGenericItem < QString >
00362   {
00363   public:
00364     enum Type { Normal, Password, Path };
00365 
00383     ItemString(const QString & _group, const QString & _key,
00384                QString & reference,
00385                const QString & defaultValue = QLatin1String(""), // NOT QString() !!
00386                Type type = Normal);
00387 
00389     void writeConfig(KConfig * config);
00390 
00392     void readConfig(KConfig * config);
00393 
00395     void setProperty(const QVariant & p);
00396 
00398     bool isEqual(const QVariant &p) const;
00399 
00401     QVariant property() const;
00402 
00403   private:
00404     Type mType;
00405   };
00406 
00410   class KDECORE_EXPORT ItemPassword:public ItemString
00411   {
00412   public:
00414     ItemPassword(const QString & _group, const QString & _key,
00415                QString & reference,
00416                const QString & defaultValue = QLatin1String("")); // NOT QString() !!
00417   };
00418 
00422   class KDECORE_EXPORT ItemPath:public ItemString
00423   {
00424   public:
00426     ItemPath(const QString & _group, const QString & _key,
00427              QString & reference,
00428              const QString & defaultValue = QString());
00429   };
00430 
00434     class KDECORE_EXPORT ItemUrl:public KConfigSkeletonGenericItem < KUrl >
00435     {
00436     public:
00437 
00440         ItemUrl(const QString & _group, const QString & _key,
00441                    KUrl & reference,
00442                    const KUrl & defaultValue = KUrl());
00443 
00445         void writeConfig(KConfig * config);
00446 
00448         void readConfig(KConfig * config);
00449 
00451         void setProperty(const QVariant & p);
00452 
00454     bool isEqual(const QVariant &p) const;
00455 
00457         QVariant property() const;
00458     };
00459 
00463   class KDECORE_EXPORT ItemProperty:public KConfigSkeletonGenericItem < QVariant >
00464   {
00465   public:
00467     ItemProperty(const QString & _group, const QString & _key,
00468                  QVariant & reference, const QVariant & defaultValue = 0);
00469 
00470     void readConfig(KConfig * config);
00471     void setProperty(const QVariant & p);
00472 
00474     bool isEqual(const QVariant &p) const;
00475 
00476     QVariant property() const;
00477   };
00478 
00479 
00483   class KDECORE_EXPORT ItemBool:public KConfigSkeletonGenericItem < bool >
00484   {
00485   public:
00487     ItemBool(const QString & _group, const QString & _key, bool & reference,
00488              bool defaultValue = true);
00489 
00491     void readConfig(KConfig * config);
00492 
00494     void setProperty(const QVariant & p);
00495 
00497     bool isEqual(const QVariant &p) const;
00498 
00500     QVariant property() const;
00501   };
00502 
00503 
00507   class KDECORE_EXPORT ItemInt:public KConfigSkeletonGenericItem < qint32 >
00508   {
00509   public:
00511     ItemInt(const QString & _group, const QString & _key, qint32 &reference,
00512             qint32 defaultValue = 0);
00513 
00515     void readConfig(KConfig * config);
00516 
00518     void setProperty(const QVariant & p);
00519 
00521     bool isEqual(const QVariant &p) const;
00522 
00524     QVariant property() const;
00525 
00527     QVariant minValue() const;
00528 
00530     QVariant maxValue() const;
00531 
00535     void setMinValue(qint32);
00536 
00540     void setMaxValue(qint32);
00541 
00542   private:
00543     bool mHasMin : 1;
00544     bool mHasMax : 1;
00545     qint32 mMin;
00546     qint32 mMax;
00547   };
00548 
00552   class KDECORE_EXPORT ItemLongLong:public KConfigSkeletonGenericItem < qint64 >
00553   {
00554   public:
00556     ItemLongLong(const QString & _group, const QString & _key, qint64 &reference,
00557             qint64 defaultValue = 0);
00558 
00560     void readConfig(KConfig * config);
00561 
00563     void setProperty(const QVariant & p);
00564 
00566     bool isEqual(const QVariant &p) const;
00567 
00569     QVariant property() const;
00570 
00572     QVariant minValue() const;
00573 
00575     QVariant maxValue() const;
00576 
00578     void setMinValue(qint64);
00579 
00581     void setMaxValue(qint64);
00582 
00583   private:
00584     bool mHasMin : 1;
00585     bool mHasMax : 1;
00586     qint64 mMin;
00587     qint64 mMax;
00588   };
00589   typedef KDE_DEPRECATED ItemLongLong ItemInt64;
00590 
00594   class KDECORE_EXPORT ItemEnum:public ItemInt
00595   {
00596   public:
00597     struct Choice
00598     {
00599       QString name;
00600       QString label;
00601       QString whatsThis;
00602     };
00603 
00607     ItemEnum(const QString & _group, const QString & _key, qint32 &reference,
00608              const QList<Choice> &choices, qint32 defaultValue = 0);
00609 
00610     QList<Choice> choices() const;
00611 
00613     void readConfig(KConfig * config);
00614 
00616     void writeConfig(KConfig * config);
00617 
00618   private:
00619       QList<Choice> mChoices;
00620   };
00621 
00622 
00626   class KDECORE_EXPORT ItemUInt:public KConfigSkeletonGenericItem < quint32 >
00627   {
00628   public:
00630     ItemUInt(const QString & _group, const QString & _key,
00631              quint32 &reference, quint32 defaultValue = 0);
00632 
00634     void readConfig(KConfig * config);
00635 
00637     void setProperty(const QVariant & p);
00638 
00640     bool isEqual(const QVariant &p) const;
00641 
00643     QVariant property() const;
00644 
00646     QVariant minValue() const;
00647 
00649     QVariant maxValue() const;
00650 
00652     void setMinValue(quint32);
00653 
00655     void setMaxValue(quint32);
00656 
00657   private:
00658     bool mHasMin : 1;
00659     bool mHasMax : 1;
00660     quint32 mMin;
00661     quint32 mMax;
00662   };
00663 
00667   class KDECORE_EXPORT ItemULongLong:public KConfigSkeletonGenericItem < quint64 >
00668   {
00669   public:
00671     ItemULongLong(const QString & _group, const QString & _key, quint64 &reference,
00672             quint64 defaultValue = 0);
00673 
00675     void readConfig(KConfig * config);
00676 
00678     void setProperty(const QVariant & p);
00679 
00681     bool isEqual(const QVariant &p) const;
00682 
00684     QVariant property() const;
00685 
00687     QVariant minValue() const;
00688 
00690     QVariant maxValue() const;
00691 
00693     void setMinValue(quint64);
00694 
00696     void setMaxValue(quint64);
00697 
00698   private:
00699     bool mHasMin : 1;
00700     bool mHasMax : 1;
00701     quint64 mMin;
00702     quint64 mMax;
00703   };
00704   typedef KDE_DEPRECATED ItemULongLong ItemUInt64;
00705 
00709   class KDECORE_EXPORT ItemDouble:public KConfigSkeletonGenericItem < double >
00710   {
00711   public:
00713     ItemDouble(const QString & _group, const QString & _key,
00714                double &reference, double defaultValue = 0);
00715 
00717     void readConfig(KConfig * config);
00718 
00720     void setProperty(const QVariant & p);
00721 
00723     bool isEqual(const QVariant &p) const;
00724 
00726     QVariant property() const;
00727 
00729     QVariant minValue() const;
00730 
00732     QVariant maxValue() const;
00733 
00735     void setMinValue(double);
00736 
00738     void setMaxValue(double);
00739 
00740   private:
00741     bool mHasMin : 1;
00742     bool mHasMax : 1;
00743     double mMin;
00744     double mMax;
00745   };
00746 
00747 
00751   class KDECORE_EXPORT ItemRect:public KConfigSkeletonGenericItem < QRect >
00752   {
00753   public:
00755     ItemRect(const QString & _group, const QString & _key, QRect & reference,
00756              const QRect & defaultValue = QRect());
00757 
00759     void readConfig(KConfig * config);
00760 
00762     void setProperty(const QVariant & p);
00763 
00765     bool isEqual(const QVariant &p) const;
00766 
00768     QVariant property() const;
00769   };
00770 
00771 
00775   class KDECORE_EXPORT ItemPoint:public KConfigSkeletonGenericItem < QPoint >
00776   {
00777   public:
00779     ItemPoint(const QString & _group, const QString & _key, QPoint & reference,
00780               const QPoint & defaultValue = QPoint());
00781 
00783     void readConfig(KConfig * config);
00784 
00786     void setProperty(const QVariant & p);
00787 
00789     bool isEqual(const QVariant &p) const;
00790 
00792     QVariant property() const;
00793   };
00794 
00795 
00799   class KDECORE_EXPORT ItemSize:public KConfigSkeletonGenericItem < QSize >
00800   {
00801   public:
00803     ItemSize(const QString & _group, const QString & _key, QSize & reference,
00804              const QSize & defaultValue = QSize());
00805 
00807     void readConfig(KConfig * config);
00808 
00810     void setProperty(const QVariant & p);
00811 
00813     bool isEqual(const QVariant &p) const;
00814 
00816     QVariant property() const;
00817   };
00818 
00819 
00823   class KDECORE_EXPORT ItemDateTime:public KConfigSkeletonGenericItem < QDateTime >
00824   {
00825   public:
00827     ItemDateTime(const QString & _group, const QString & _key,
00828                  QDateTime & reference,
00829                  const QDateTime & defaultValue = QDateTime());
00830 
00832     void readConfig(KConfig * config);
00833 
00835     void setProperty(const QVariant & p);
00836 
00838     bool isEqual(const QVariant &p) const;
00839 
00841     QVariant property() const;
00842   };
00843 
00844 
00848   class KDECORE_EXPORT ItemStringList:public KConfigSkeletonGenericItem < QStringList >
00849   {
00850   public:
00852     ItemStringList(const QString & _group, const QString & _key,
00853                    QStringList & reference,
00854                    const QStringList & defaultValue = QStringList());
00855 
00857     void readConfig(KConfig * config);
00858 
00860     void setProperty(const QVariant & p);
00861 
00863     bool isEqual(const QVariant &p) const;
00864 
00866     QVariant property() const;
00867   };
00868 
00869 
00873   class KDECORE_EXPORT ItemPathList:public ItemStringList
00874   {
00875   public:
00877     ItemPathList(const QString & _group, const QString & _key,
00878                    QStringList & reference,
00879                    const QStringList & defaultValue = QStringList());
00880 
00882     void readConfig(KConfig * config);
00884     void writeConfig(KConfig * config);
00885   };
00886 
00890     class KDECORE_EXPORT ItemUrlList:public KConfigSkeletonGenericItem < KUrl::List >
00891     {
00892     public:
00894         ItemUrlList(const QString & _group, const QString & _key,
00895                      KUrl::List & reference,
00896                      const KUrl::List & defaultValue = KUrl::List());
00897 
00899         void readConfig(KConfig * config);
00900 
00902         void writeConfig(KConfig * config);
00903 
00905         void setProperty(const QVariant & p);
00906 
00908     bool isEqual(const QVariant &p) const;
00909 
00911         QVariant property() const;
00912     };
00913 
00917   class KDECORE_EXPORT ItemIntList:public KConfigSkeletonGenericItem < QList < int > >
00918   {
00919   public:
00921     ItemIntList(const QString & _group, const QString & _key,
00922                 QList < int >&reference,
00923                 const QList < int >&defaultValue = QList < int >());
00924 
00926     void readConfig(KConfig * config);
00927 
00929     void setProperty(const QVariant & p);
00930 
00932     bool isEqual(const QVariant &p) const;
00933 
00935     QVariant property() const;
00936   };
00937 
00938 
00939 public:
00946   explicit KCoreConfigSkeleton(const QString & configname = QString(), QObject* parent = 0);
00947 
00953   explicit KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject* parent = 0);
00954 
00958     virtual ~ KCoreConfigSkeleton();
00959 
00968   virtual void setDefaults();
00969 
00979   virtual void readConfig();
00980 
00990   virtual void writeConfig();
00991 
00997   void setCurrentGroup(const QString & group);
00998 
01002   QString currentGroup() const;
01003 
01010   void addItem(KConfigSkeletonItem *, const QString & name = QString() );
01011 
01023   ItemString *addItemString(const QString & name, QString & reference,
01024                             const QString & defaultValue = QLatin1String(""), // NOT QString() !!
01025                             const QString & key = QString());
01026 
01040   ItemPassword *addItemPassword(const QString & name, QString & reference,
01041                               const QString & defaultValue = QLatin1String(""),
01042                               const QString & key = QString());
01043 
01057   ItemPath *addItemPath(const QString & name, QString & reference,
01058                           const QString & defaultValue = QLatin1String(""),
01059                           const QString & key = QString());
01060 
01074   ItemProperty *addItemProperty(const QString & name, QVariant & reference,
01075                                 const QVariant & defaultValue = QVariant(),
01076                                 const QString & key = QString());
01088   ItemBool *addItemBool(const QString & name, bool & reference,
01089                         bool defaultValue = false,
01090                         const QString & key = QString());
01091 
01103   ItemInt *addItemInt(const QString & name, qint32 &reference, qint32 defaultValue = 0,
01104                       const QString & key = QString());
01105 
01117   ItemUInt *addItemUInt(const QString & name, quint32 &reference,
01118                         quint32 defaultValue = 0,
01119                         const QString & key = QString());
01120 
01132   ItemLongLong *addItemLongLong(const QString & name, qint64 &reference,
01133                           qint64 defaultValue = 0,
01134                           const QString & key = QString());
01135 
01136   KDE_DEPRECATED ItemLongLong *addItemInt64( const QString& name, qint64 &reference,
01137                           qint64 defaultValue = 0,
01138                           const QString & key = QString());
01139 
01151   ItemULongLong *addItemULongLong(const QString & name, quint64 &reference,
01152                             quint64 defaultValue = 0,
01153                             const QString & key = QString());
01154 
01155   KDE_DEPRECATED ItemULongLong *addItemUInt64(const QString & name, quint64 &reference,
01156                             quint64 defaultValue = 0,
01157                             const QString & key = QString());
01158 
01170   ItemDouble *addItemDouble(const QString & name, double &reference,
01171                             double defaultValue = 0.0,
01172                             const QString & key = QString());
01173 
01185   ItemRect *addItemRect(const QString & name, QRect & reference,
01186                         const QRect & defaultValue = QRect(),
01187                         const QString & key = QString());
01188 
01200   ItemPoint *addItemPoint(const QString & name, QPoint & reference,
01201                           const QPoint & defaultValue = QPoint(),
01202                           const QString & key = QString());
01203 
01215   ItemSize *addItemSize(const QString & name, QSize & reference,
01216                         const QSize & defaultValue = QSize(),
01217                         const QString & key = QString());
01218 
01230   ItemDateTime *addItemDateTime(const QString & name, QDateTime & reference,
01231                                 const QDateTime & defaultValue = QDateTime(),
01232                                 const QString & key = QString());
01233 
01245   ItemStringList *addItemStringList(const QString & name, QStringList & reference,
01246                                     const QStringList & defaultValue = QStringList(),
01247                                     const QString & key = QString());
01248 
01260   ItemIntList *addItemIntList(const QString & name, QList < int >&reference,
01261                               const QList < int >&defaultValue =
01262                               QList < int >(),
01263                               const QString & key = QString());
01264 
01268   KConfig *config();
01269 
01273   const KConfig *config() const;
01274 
01278   void setSharedConfig(KSharedConfig::Ptr pConfig);
01279 
01283   KConfigSkeletonItem::List items() const;
01284 
01288   bool isImmutable(const QString & name);
01289 
01293   KConfigSkeletonItem * findItem(const QString & name);
01294 
01307   virtual bool useDefaults(bool b);
01308 
01309 Q_SIGNALS:
01313   void configChanged();
01314 
01315 protected:
01324   virtual bool usrUseDefaults(bool b);
01325 
01331   virtual void usrSetDefaults();
01332 
01338   virtual void usrReadConfig();
01339 
01345   virtual void usrWriteConfig();
01346 
01347 private:
01348   class Private;
01349   Private * const d;
01350   friend class KConfigSkeleton;
01351 
01352 };
01353 
01354 #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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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