libkdepim Library API Documentation

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., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, 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 class KConfigSkeleton;
00030 class KConfigSkeletonItem;
00031 
00032 class KConfigPropagator
00033 {
00034   public:
00035 
00039     KConfigPropagator();
00046     KConfigPropagator( KConfigSkeleton *skeleton, const QString &kcfgFile );
00047     virtual ~KConfigPropagator() {}
00048 
00049     KConfigSkeleton *skeleton() { return mSkeleton; }
00050 
00051     /*
00052       Commit changes according to propagation rules.
00053     */
00054     void commit();
00055 
00056     class Condition
00057     {
00058       public:
00059         Condition() : isValid( false ) {}
00060       
00061         QString file;
00062         QString group;
00063         QString key;
00064         QString value;
00065         
00066         bool isValid;
00067     };
00068 
00069     class Rule
00070     {
00071       public:
00072         typedef QValueList<Rule> List;
00073         
00074         Rule() : hideValue( false ) {}
00075         
00076         QString sourceFile;
00077         QString sourceGroup;
00078         QString sourceEntry;
00079 
00080         QString targetFile;
00081         QString targetGroup;
00082         QString targetEntry;
00083 
00084         Condition condition;
00085 
00086         bool hideValue;
00087     };
00088 
00089     class Change
00090     {
00091       public:
00092         typedef QPtrList<Change> List;
00093 
00094         Change( const QString &title ) : mTitle( title ) {}
00095         virtual ~Change();
00096       
00097         void setTitle( const QString &title ) { mTitle = title; }
00098         QString title() const { return mTitle; }
00099 
00100         virtual QString arg1() const { return QString::null; }
00101         virtual QString arg2() const { return QString::null; }
00102 
00103         virtual void apply() = 0;
00104 
00105       private:
00106         QString mTitle;
00107     };
00108 
00109     class ChangeConfig : public Change
00110     {
00111       public:
00112         ChangeConfig();
00113         ~ChangeConfig() {}
00114 
00115         QString arg1() const;
00116         QString arg2() const;
00117 
00118         void apply();
00119 
00120         QString file;
00121         QString group;
00122         QString name;
00123         QString label;
00124         QString value;
00125         bool hideValue;
00126     };
00127 
00128     void updateChanges();
00129     
00130     Change::List changes();
00131 
00132     Rule::List rules();
00133 
00134   protected:
00135     void init();
00136 
00141     virtual void addCustomChanges( Change::List & ) {}
00142 
00143     KConfigSkeletonItem *findItem( const QString &group, const QString &name );
00144 
00145     QString itemValueAsString( KConfigSkeletonItem * );
00146 
00147     void readKcfgFile();
00148 
00149     Rule parsePropagation( const QDomElement &e );
00150     Condition parseCondition( const QDomElement &e );
00151 
00152     void parseConfigEntryPath( const QString &path, QString &file,
00153                                QString &group, QString &entry );
00154 
00155   private:
00156     KConfigSkeleton *mSkeleton;
00157     QString mKcfgFile;
00158 
00159     Rule::List mRules;
00160     Change::List mChanges;    
00161 };
00162 
00163 #endif
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu May 3 20:20:05 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003