libkdepim

kconfigpropagator.h

00001 /*
00002     This file is part of libkdepim.
00003 
00004     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 #ifndef KCONFIGPROPAGATOR_H
00022 #define KCONFIGPROPAGATOR_H
00023 
00024 #include <qstring.h>
00025 #include <qvaluelist.h>
00026 #include <qdom.h>
00027 #include <qptrlist.h>
00028 
00029 #include <kdepimmacros.h>
00030 
00031 class KConfigSkeleton;
00032 class KConfigSkeletonItem;
00033 
00034 class KDE_EXPORT KConfigPropagator
00035 {
00036   public:
00037 
00041     KConfigPropagator();
00048     KConfigPropagator( KConfigSkeleton *skeleton, const QString &kcfgFile );
00049     virtual ~KConfigPropagator() {}
00050 
00051     KConfigSkeleton *skeleton() { return mSkeleton; }
00052 
00053     /*
00054       Commit changes according to propagation rules.
00055     */
00056     void commit();
00057 
00058     class KDE_EXPORT Condition
00059     {
00060       public:
00061         Condition() : isValid( false ) {}
00062       
00063         QString file;
00064         QString group;
00065         QString key;
00066         QString value;
00067         
00068         bool isValid;
00069     };
00070 
00071     class KDE_EXPORT Rule
00072     {
00073       public:
00074         typedef QValueList<Rule> List;
00075         
00076         Rule() : hideValue( false ) {}
00077         
00078         QString sourceFile;
00079         QString sourceGroup;
00080         QString sourceEntry;
00081 
00082         QString targetFile;
00083         QString targetGroup;
00084         QString targetEntry;
00085 
00086         Condition condition;
00087 
00088         bool hideValue;
00089     };
00090 
00091     class KDE_EXPORT Change
00092     {
00093       public:
00094         typedef QPtrList<Change> List;
00095 
00096         Change( const QString &title ) : mTitle( title ) {}
00097         virtual ~Change();
00098       
00099         void setTitle( const QString &title ) { mTitle = title; }
00100         QString title() const { return mTitle; }
00101 
00102         virtual QString arg1() const { return QString::null; }
00103         virtual QString arg2() const { return QString::null; }
00104 
00105         virtual void apply() = 0;
00106 
00107       private:
00108         QString mTitle;
00109     };
00110 
00111     class KDE_EXPORT ChangeConfig : public Change
00112     {
00113       public:
00114         ChangeConfig();
00115         ~ChangeConfig() {}
00116 
00117         QString arg1() const;
00118         QString arg2() const;
00119 
00120         void apply();
00121 
00122         QString file;
00123         QString group;
00124         QString name;
00125         QString label;
00126         QString value;
00127         bool hideValue;
00128     };
00129 
00130     void updateChanges();
00131     
00132     Change::List changes();
00133 
00134     Rule::List rules();
00135 
00136   protected:
00137     void init();
00138 
00143     virtual void addCustomChanges( Change::List & ) {}
00144 
00145     KConfigSkeletonItem *findItem( const QString &group, const QString &name );
00146 
00147     QString itemValueAsString( KConfigSkeletonItem * );
00148 
00149     void readKcfgFile();
00150 
00151     Rule parsePropagation( const QDomElement &e );
00152     Condition parseCondition( const QDomElement &e );
00153 
00154     void parseConfigEntryPath( const QString &path, QString &file,
00155                                QString &group, QString &entry );
00156 
00157   private:
00158     KConfigSkeleton *mSkeleton;
00159     QString mKcfgFile;
00160 
00161     Rule::List mRules;
00162     Change::List mChanges;    
00163 };
00164 
00165 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys