qgpgmecryptoconfig.h
1 /*
2  qgpgmecryptoconfig.h
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the TQt library by Trolltech AS, Norway (or with modified versions
24  of TQt that use the same license as TQt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  TQt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #ifndef KLEO_TQGPGMECRYPTOCONFIG_H
34 #define KLEO_TQGPGMECRYPTOCONFIG_H
35 
36 #include <kleo/cryptoconfig.h>
37 #include <tqdict.h>
38 #include <tqstringlist.h>
39 #include <tqobject.h>
40 #include <tqvariant.h>
41 class KProcIO;
42 
44 class QGpgMECryptoConfigEntry;
49 class QGpgMECryptoConfig : public TQObject, public Kleo::CryptoConfig {
50 
51  TQ_OBJECT
52 
53 public:
58  virtual ~QGpgMECryptoConfig();
59 
60  virtual TQStringList componentList() const;
61 
62  virtual Kleo::CryptoConfigComponent* component( const TQString& name ) const;
63 
64  virtual void clear();
65  virtual void sync( bool runtime );
66 
67 private slots:
68  void slotCollectStdOut( KProcIO* proc );
69 private:
71  void runGpgConf( bool showErrors );
72 
73 private:
74  TQDict<QGpgMECryptoConfigComponent> mComponents;
75  bool mParsed;
76 };
77 
78 class QGpgMECryptoConfigGroup;
79 
82 
83  TQ_OBJECT
84 
85 public:
86  QGpgMECryptoConfigComponent( QGpgMECryptoConfig*, const TQString& name, const TQString& description );
88 
89  TQString name() const { return mName; }
90  TQString iconName() const { return mName; }
91  TQString description() const { return mDescription; }
92  TQStringList groupList() const;
93  Kleo::CryptoConfigGroup* group( const TQString& name ) const;
94 
95  void sync( bool runtime );
96 
97 private slots:
98  void slotCollectStdOut( KProcIO* proc );
99 private:
100  void runGpgConf();
101 
102 private:
103  TQDict<QGpgMECryptoConfigGroup> mGroups;
104  TQString mName;
105  TQString mDescription;
106  QGpgMECryptoConfigGroup* mCurrentGroup; // during parsing
107  TQString mCurrentGroupName; // during parsing
108 };
109 
110 class QGpgMECryptoConfigGroup : public Kleo::CryptoConfigGroup {
111 
112 public:
113  QGpgMECryptoConfigGroup( const TQString & name, const TQString& description, int level );
114  ~QGpgMECryptoConfigGroup() {}
115 
116  TQString name() const { return mName; }
117  TQString iconName() const { return TQString(); }
118  TQString description() const { return mDescription; }
119  Kleo::CryptoConfigEntry::Level level() const { return mLevel; }
120  TQStringList entryList() const;
121  Kleo::CryptoConfigEntry* entry( const TQString& name ) const;
122 
123 private:
124  friend class QGpgMECryptoConfigComponent; // it adds the entries
125  TQDict<QGpgMECryptoConfigEntry> mEntries;
126  TQString mName;
127  TQString mDescription;
129 };
130 
131 class QGpgMECryptoConfigEntry : public Kleo::CryptoConfigEntry {
132 public:
133  QGpgMECryptoConfigEntry( const TQStringList& parsedLine );
134  ~QGpgMECryptoConfigEntry();
135 
136  TQString name() const { return mName; }
137  TQString description() const { return mDescription; }
138  bool isOptional() const;
139  bool isReadOnly() const;
140  bool isList() const;
141  bool isRuntime() const;
142  Level level() const { return static_cast<Level>( mLevel ); }
143  ArgType argType() const { return static_cast<ArgType>( mArgType ); }
144  bool isSet() const;
145  bool boolValue() const;
146  TQString stringValue() const;
147  int intValue() const;
148  unsigned int uintValue() const;
149  KURL urlValue() const;
150  unsigned int numberOfTimesSet() const;
151  TQStringList stringValueList() const;
152  TQValueList<int> intValueList() const;
153  TQValueList<unsigned int> uintValueList() const;
154  KURL::List urlValueList() const;
155  void resetToDefault();
156  void setBoolValue( bool );
157  void setStringValue( const TQString& );
158  void setIntValue( int );
159  void setUIntValue( unsigned int );
160  void setURLValue( const KURL& );
161  void setNumberOfTimesSet( unsigned int );
162  void setStringValueList( const TQStringList& );
163  void setIntValueList( const TQValueList<int>& );
164  void setUIntValueList( const TQValueList<unsigned int>& );
165  void setURLValueList( const KURL::List& );
166  bool isDirty() const { return mDirty; }
167 
168  void setDirty( bool b );
169  TQString outputString() const;
170 
171 protected:
172  bool isStringType() const;
173  TQVariant stringToValue( const TQString& value, bool unescape ) const;
174  TQString toString( bool escape ) const;
175 private:
176  TQString mName;
177  TQString mDescription;
178  TQVariant mDefaultValue;
179  TQVariant mValue;
180  uint mFlags : 8; // bitfield with 8 bits
181  uint mLevel : 3; // max is 4 (2, in fact) -> 3 bits
182  uint mRealArgType : 6; // max is 33 -> 6 bits
183  uint mArgType : 3; // max is 6 (ArgType enum) -> 3 bits;
184  uint mDirty : 1;
185  uint mSet : 1;
186 };
187 
188 #endif /* KLEO_TQGPGMECRYPTOCONFIG_H */
Crypto config for one component (e.g.
Definition: cryptoconfig.h:295
Description of a single option.
Definition: cryptoconfig.h:49
virtual void setBoolValue(bool)=0
Define whether the option is set or not (only allowed for ArgType_None)
virtual bool isList() const =0
virtual ArgType argType() const =0
Argument type.
virtual TQValueList< int > intValueList() const =0
Return value as a list of signed ints.
virtual TQStringList stringValueList() const =0
Return value as a list of strings (mostly meaningful for String, Path and URL argtypes,...
virtual void setNumberOfTimesSet(unsigned int)=0
Set the number of times the option is set (only valid for ArgType_None, if isList())
virtual void setUIntValueList(const TQValueList< unsigned int > &)=0
Set a new list of unsigned int values.
virtual bool isDirty() const =0
virtual void setStringValueList(const TQStringList &)=0
Set a new string-list value (only allowed for String, Path and URL argtypes, if isList())
virtual bool isOptional() const =0
virtual KURL::List urlValueList() const =0
Return value as a list of URLs (only meaningful for Path and URL argtypes, if isList())
virtual TQString name() const =0
Return the internal name of this entry.
virtual void setURLValue(const KURL &)=0
Set value as a URL (only meaningful for Path (if local) and URL argtypes)
ArgType
Type of the argument.
Definition: cryptoconfig.h:79
virtual TQString stringValue() const =0
Return value as a string (available for all argtypes) The returned string can be empty (explicitely s...
virtual unsigned int uintValue() const =0
Return value as an unsigned int.
virtual void setUIntValue(unsigned int)=0
Set a new unsigned int value.
virtual Level level() const =0
User level.
virtual TQString description() const =0
virtual bool boolValue() const =0
Return value as a bool (only allowed for ArgType_None)
virtual int intValue() const =0
Return value as a signed int.
virtual KURL urlValue() const =0
Return value as a URL (only meaningful for Path and URL argtypes)
virtual TQValueList< unsigned int > uintValueList() const =0
Return value as a list of unsigned ints.
virtual unsigned int numberOfTimesSet() const =0
Return number of times the option is set (only valid for ArgType_None, if isList())
virtual bool isRuntime() const =0
virtual void setURLValueList(const KURL::List &)=0
Set value as a URL list (only meaningful for Path (if all URLs are local) and URL argtypes,...
virtual void setStringValue(const TQString &)=0
Set string value (allowed for all argtypes)
virtual void setIntValueList(const TQValueList< int > &)=0
Set a new list of signed int values.
virtual void resetToDefault()=0
Reset an option to its default value.
virtual bool isSet() const =0
Return true if the option is set, i.e.
virtual void setIntValue(int)=0
Set a new signed int value.
virtual bool isReadOnly() const =0
Group containing a set of config options.
Definition: cryptoconfig.h:252
virtual CryptoConfigEntry::Level level() const =0
User level.
virtual CryptoConfigEntry * entry(const TQString &name) const =0
virtual TQString description() const =0
virtual TQStringList entryList() const =0
Returns the list of entries that are known by this group.
virtual TQString iconName() const =0
Return the name of the icon for this group.
virtual TQString name() const =0
Return the internal name of this group.
Main interface to crypto configuration.
Definition: cryptoconfig.h:334
For docu, see kleo/cryptoconfig.h.
TQStringList groupList() const
Returns the list of groups that are known about.
TQString description() const
Return user-visible description of this component.
TQString iconName() const
Return the name of the icon for this component.
TQString name() const
Return the internal name of this component.
Kleo::CryptoConfigGroup * group(const TQString &name) const
CryptoConfig implementation around the gpgconf command-line tool For method docu, see kleo/cryptoconf...
virtual TQStringList componentList() const
Returns the list of known components (e.g.
virtual void sync(bool runtime)
Write back changes.
virtual Kleo::CryptoConfigComponent * component(const TQString &name) const
virtual void clear()
Tells the CryptoConfig to discard any cached information, including all components,...
QGpgMECryptoConfig()
Constructor.