libtdepim

tdeconfigpropagator.h
1 /*
2  This file is part of libtdepim.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 #ifndef TDECONFIGPROPAGATOR_H
22 #define TDECONFIGPROPAGATOR_H
23 
24 #include <tqstring.h>
25 #include <tqvaluelist.h>
26 #include <tqdom.h>
27 #include <tqptrlist.h>
28 
29 #include <tdemacros.h>
30 
31 class TDEConfigSkeleton;
32 class TDEConfigSkeletonItem;
33 
34 class TDE_EXPORT TDEConfigPropagator
35 {
36  public:
37 
41  TDEConfigPropagator();
48  TDEConfigPropagator( TDEConfigSkeleton *skeleton, const TQString &kcfgFile );
49  virtual ~TDEConfigPropagator() {}
50 
51  TDEConfigSkeleton *skeleton() { return mSkeleton; }
52 
53  /*
54  Commit changes according to propagation rules.
55  */
56  void commit();
57 
58  class TDE_EXPORT Condition
59  {
60  public:
61  Condition() : isValid( false ) {}
62 
63  TQString file;
64  TQString group;
65  TQString key;
66  TQString value;
67 
68  bool isValid;
69  };
70 
71  class TDE_EXPORT Rule
72  {
73  public:
74  typedef TQValueList<Rule> List;
75 
76  Rule() : hideValue( false ) {}
77 
78  TQString sourceFile;
79  TQString sourceGroup;
80  TQString sourceEntry;
81 
82  TQString targetFile;
83  TQString targetGroup;
84  TQString targetEntry;
85 
86  Condition condition;
87 
88  bool hideValue;
89  };
90 
91  class TDE_EXPORT Change
92  {
93  public:
94  typedef TQPtrList<Change> List;
95 
96  Change( const TQString &title ) : mTitle( title ) {}
97  virtual ~Change();
98 
99  void setTitle( const TQString &title ) { mTitle = title; }
100  TQString title() const { return mTitle; }
101 
102  virtual TQString arg1() const { return TQString(); }
103  virtual TQString arg2() const { return TQString(); }
104 
105  virtual void apply() = 0;
106 
107  private:
108  TQString mTitle;
109  };
110 
111  class TDE_EXPORT ChangeConfig : public Change
112  {
113  public:
114  ChangeConfig();
115  ~ChangeConfig() {}
116 
117  TQString arg1() const;
118  TQString arg2() const;
119 
120  void apply();
121 
122  TQString file;
123  TQString group;
124  TQString name;
125  TQString label;
126  TQString value;
127  bool hideValue;
128  };
129 
130  void updateChanges();
131 
132  Change::List changes();
133 
134  Rule::List rules();
135 
136  protected:
137  void init();
138 
143  virtual void addCustomChanges( Change::List & ) {}
144 
145  TDEConfigSkeletonItem *findItem( const TQString &group, const TQString &name );
146 
147  TQString itemValueAsString( TDEConfigSkeletonItem * );
148 
149  void readKcfgFile();
150 
151  Rule parsePropagation( const TQDomElement &e );
152  Condition parseCondition( const TQDomElement &e );
153 
154  void parseConfigEntryPath( const TQString &path, TQString &file,
155  TQString &group, TQString &entry );
156 
157  private:
158  TDEConfigSkeleton *mSkeleton;
159  TQString mKcfgFile;
160 
161  Rule::List mRules;
162  Change::List mChanges;
163 };
164 
165 #endif