certmanager/lib
qgpgmecryptoconfig.h
00001 /* 00002 qgpgmecryptoconfig.h 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klarälvdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. 00011 00012 Libkleopatra 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 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 Qt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 00031 */ 00032 00033 #ifndef KLEO_QGPGMECRYPTOCONFIG_H 00034 #define KLEO_QGPGMECRYPTOCONFIG_H 00035 00036 #include <kleo/cryptoconfig.h> 00037 #include <qdict.h> 00038 #include <qstringlist.h> 00039 #include <qobject.h> 00040 #include <qvariant.h> 00041 class KProcIO; 00042 00043 class QGpgMECryptoConfigComponent; 00044 class QGpgMECryptoConfigEntry; 00049 class QGpgMECryptoConfig : public QObject, public Kleo::CryptoConfig { 00050 00051 Q_OBJECT 00052 public: 00056 QGpgMECryptoConfig(); 00057 virtual ~QGpgMECryptoConfig(); 00058 00059 virtual QStringList componentList() const; 00060 00061 virtual Kleo::CryptoConfigComponent* component( const QString& name ) const; 00062 00063 virtual void clear(); 00064 virtual void sync( bool runtime ); 00065 00066 private slots: 00067 void slotCollectStdOut( KProcIO* proc ); 00068 private: 00070 void runGpgConf( bool showErrors ); 00071 00072 private: 00073 QDict<QGpgMECryptoConfigComponent> mComponents; 00074 bool mParsed; 00075 }; 00076 00077 class QGpgMECryptoConfigGroup; 00078 00080 class QGpgMECryptoConfigComponent : public QObject, public Kleo::CryptoConfigComponent { 00081 00082 Q_OBJECT 00083 public: 00084 QGpgMECryptoConfigComponent( QGpgMECryptoConfig*, const QString& name, const QString& description ); 00085 ~QGpgMECryptoConfigComponent(); 00086 00087 QString name() const { return mName; } 00088 QString iconName() const { return mName; } 00089 QString description() const { return mDescription; } 00090 QStringList groupList() const; 00091 Kleo::CryptoConfigGroup* group( const QString& name ) const; 00092 00093 void sync( bool runtime ); 00094 00095 private slots: 00096 void slotCollectStdOut( KProcIO* proc ); 00097 private: 00098 void runGpgConf(); 00099 00100 private: 00101 QDict<QGpgMECryptoConfigGroup> mGroups; 00102 QString mName; 00103 QString mDescription; 00104 QGpgMECryptoConfigGroup* mCurrentGroup; // during parsing 00105 QString mCurrentGroupName; // during parsing 00106 }; 00107 00108 class QGpgMECryptoConfigGroup : public Kleo::CryptoConfigGroup { 00109 00110 public: 00111 QGpgMECryptoConfigGroup( const QString & name, const QString& description, int level ); 00112 ~QGpgMECryptoConfigGroup() {} 00113 00114 QString name() const { return mName; } 00115 QString iconName() const { return QString::null; } 00116 QString description() const { return mDescription; } 00117 Kleo::CryptoConfigEntry::Level level() const { return mLevel; } 00118 QStringList entryList() const; 00119 Kleo::CryptoConfigEntry* entry( const QString& name ) const; 00120 00121 private: 00122 friend class QGpgMECryptoConfigComponent; // it adds the entries 00123 QDict<QGpgMECryptoConfigEntry> mEntries; 00124 QString mName; 00125 QString mDescription; 00126 Kleo::CryptoConfigEntry::Level mLevel; 00127 }; 00128 00129 class QGpgMECryptoConfigEntry : public Kleo::CryptoConfigEntry { 00130 public: 00131 QGpgMECryptoConfigEntry( const QStringList& parsedLine ); 00132 ~QGpgMECryptoConfigEntry(); 00133 00134 QString name() const { return mName; } 00135 QString description() const { return mDescription; } 00136 bool isOptional() const; 00137 bool isReadOnly() const; 00138 bool isList() const; 00139 bool isRuntime() const; 00140 Level level() const { return static_cast<Level>( mLevel ); } 00141 ArgType argType() const { return static_cast<ArgType>( mArgType ); } 00142 bool isSet() const; 00143 bool boolValue() const; 00144 QString stringValue() const; 00145 int intValue() const; 00146 unsigned int uintValue() const; 00147 KURL urlValue() const; 00148 unsigned int numberOfTimesSet() const; 00149 QStringList stringValueList() const; 00150 QValueList<int> intValueList() const; 00151 QValueList<unsigned int> uintValueList() const; 00152 KURL::List urlValueList() const; 00153 void resetToDefault(); 00154 void setBoolValue( bool ); 00155 void setStringValue( const QString& ); 00156 void setIntValue( int ); 00157 void setUIntValue( unsigned int ); 00158 void setURLValue( const KURL& ); 00159 void setNumberOfTimesSet( unsigned int ); 00160 void setStringValueList( const QStringList& ); 00161 void setIntValueList( const QValueList<int>& ); 00162 void setUIntValueList( const QValueList<unsigned int>& ); 00163 void setURLValueList( const KURL::List& ); 00164 bool isDirty() const { return mDirty; } 00165 00166 void setDirty( bool b ); 00167 QString outputString() const; 00168 00169 protected: 00170 bool isStringType() const; 00171 QVariant stringToValue( const QString& value, bool unescape ) const; 00172 QString toString( bool escape ) const; 00173 private: 00174 QString mName; 00175 QString mDescription; 00176 QVariant mDefaultValue; 00177 QVariant mValue; 00178 uint mFlags : 8; // bitfield with 8 bits 00179 uint mLevel : 3; // max is 4 (2, in fact) -> 3 bits 00180 uint mRealArgType : 6; // max is 33 -> 6 bits 00181 uint mArgType : 3; // max is 6 (ArgType enum) -> 3 bits; 00182 uint mDirty : 1; 00183 uint mSet : 1; 00184 }; 00185 00186 #endif /* KLEO_QGPGMECRYPTOCONFIG_H */