Line data Source code
1 : /*
2 : qgpgmenewcryptoconfig.h
3 :
4 : This file is part of qgpgme, the Qt API binding for gpgme
5 : Copyright (c) 2010 Klarälvdalens Datakonsult AB
6 : Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
7 : Software engineering by Intevation GmbH
8 :
9 : QGpgME is free software; you can redistribute it and/or
10 : modify it under the terms of the GNU General Public License as
11 : published by the Free Software Foundation; either version 2 of the
12 : License, or (at your option) any later version.
13 :
14 : QGpgME is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 :
23 : In addition, as a special exception, the copyright holders give
24 : permission to link the code of this program with any edition of
25 : the Qt library by Trolltech AS, Norway (or with modified versions
26 : of Qt that use the same license as Qt), and distribute linked
27 : combinations including the two. You must obey the GNU General
28 : Public License in all respects for all of the code used other than
29 : Qt. If you modify this file, you may extend this exception to
30 : your version of the file, but you are not obligated to do so. If
31 : you do not wish to do so, delete this exception statement from
32 : your version.
33 : */
34 :
35 : #ifndef QGPGME_QGPGMENEWCRYPTOCONFIG_H
36 : #define QGPGME_QGPGMENEWCRYPTOCONFIG_H
37 :
38 : #include "qgpgme_export.h"
39 : #include "cryptoconfig.h"
40 :
41 : #include <QHash>
42 : #include <QStringList>
43 : #include <QVariant>
44 :
45 : #ifdef BUILDING_QGPGME
46 : # include "configuration.h"
47 : #else
48 : # include <gpgme++/configuration.h>
49 : #endif
50 :
51 :
52 : #include <vector>
53 : #include <utility>
54 :
55 : class QGpgMENewCryptoConfig;
56 : class QGpgMENewCryptoConfigComponent;
57 : class QGpgMENewCryptoConfigGroup;
58 : class QGpgMENewCryptoConfigEntry;
59 :
60 : class QGpgMENewCryptoConfigEntry : public QGpgME::CryptoConfigEntry
61 : {
62 : public:
63 : QGpgMENewCryptoConfigEntry(const std::shared_ptr<QGpgMENewCryptoConfigGroup> &group, const GpgME::Configuration::Option &option);
64 : ~QGpgMENewCryptoConfigEntry();
65 :
66 : QString name() const Q_DECL_OVERRIDE;
67 : QString description() const Q_DECL_OVERRIDE;
68 : QString path() const Q_DECL_OVERRIDE;
69 : bool isOptional() const Q_DECL_OVERRIDE;
70 : bool isReadOnly() const Q_DECL_OVERRIDE;
71 : bool isList() const Q_DECL_OVERRIDE;
72 : bool isRuntime() const Q_DECL_OVERRIDE;
73 : Level level() const Q_DECL_OVERRIDE;
74 : ArgType argType() const Q_DECL_OVERRIDE;
75 : bool isSet() const Q_DECL_OVERRIDE;
76 : bool boolValue() const Q_DECL_OVERRIDE;
77 : QString stringValue() const Q_DECL_OVERRIDE;
78 : int intValue() const Q_DECL_OVERRIDE;
79 : unsigned int uintValue() const Q_DECL_OVERRIDE;
80 : QUrl urlValue() const Q_DECL_OVERRIDE;
81 : unsigned int numberOfTimesSet() const Q_DECL_OVERRIDE;
82 : std::vector<int> intValueList() const Q_DECL_OVERRIDE;
83 : std::vector<unsigned int> uintValueList() const Q_DECL_OVERRIDE;
84 : QList<QUrl> urlValueList() const Q_DECL_OVERRIDE;
85 : void resetToDefault() Q_DECL_OVERRIDE;
86 : void setBoolValue(bool) Q_DECL_OVERRIDE;
87 : void setStringValue(const QString &) Q_DECL_OVERRIDE;
88 : void setIntValue(int) Q_DECL_OVERRIDE;
89 : void setUIntValue(unsigned int) Q_DECL_OVERRIDE;
90 : void setURLValue(const QUrl &) Q_DECL_OVERRIDE;
91 : void setNumberOfTimesSet(unsigned int) Q_DECL_OVERRIDE;
92 : void setIntValueList(const std::vector<int> &) Q_DECL_OVERRIDE;
93 : void setUIntValueList(const std::vector<unsigned int> &) Q_DECL_OVERRIDE;
94 : void setURLValueList(const QList<QUrl> &) Q_DECL_OVERRIDE;
95 : bool isDirty() const Q_DECL_OVERRIDE;
96 :
97 : QStringList stringValueList() const;
98 :
99 : #if 0
100 : void setDirty(bool b);
101 : QString outputString() const;
102 :
103 : protected:
104 : bool isStringType() const;
105 : QVariant stringToValue(const QString &value, bool unescape) const;
106 : QString toString(bool escape) const;
107 : #endif
108 : private:
109 : std::weak_ptr<QGpgMENewCryptoConfigGroup> m_group;
110 : GpgME::Configuration::Option m_option;
111 : };
112 :
113 : class QGpgMENewCryptoConfigGroup : public QGpgME::CryptoConfigGroup
114 : {
115 : public:
116 : QGpgMENewCryptoConfigGroup(const std::shared_ptr<QGpgMENewCryptoConfigComponent> &parent, const GpgME::Configuration::Option &option);
117 : ~QGpgMENewCryptoConfigGroup();
118 :
119 : QString name() const Q_DECL_OVERRIDE;
120 0 : QString iconName() const Q_DECL_OVERRIDE
121 : {
122 0 : return QString();
123 : }
124 : QString description() const Q_DECL_OVERRIDE;
125 : QString path() const Q_DECL_OVERRIDE;
126 : QGpgME::CryptoConfigEntry::Level level() const Q_DECL_OVERRIDE;
127 : QStringList entryList() const Q_DECL_OVERRIDE;
128 : QGpgMENewCryptoConfigEntry *entry(const QString &name) const Q_DECL_OVERRIDE;
129 :
130 : private:
131 : friend class QGpgMENewCryptoConfigComponent; // it adds the entries
132 : std::weak_ptr<QGpgMENewCryptoConfigComponent> m_component;
133 : GpgME::Configuration::Option m_option;
134 : QStringList m_entryNames;
135 : QHash< QString, std::shared_ptr<QGpgMENewCryptoConfigEntry> > m_entriesByName;
136 : };
137 :
138 : /// For docu, see kleo/cryptoconfig.h
139 : class QGpgMENewCryptoConfigComponent : public QGpgME::CryptoConfigComponent, public std::enable_shared_from_this<QGpgMENewCryptoConfigComponent>
140 : {
141 : public:
142 : QGpgMENewCryptoConfigComponent();
143 : ~QGpgMENewCryptoConfigComponent();
144 :
145 : void setComponent(const GpgME::Configuration::Component &component);
146 :
147 : QString name() const Q_DECL_OVERRIDE;
148 0 : QString iconName() const Q_DECL_OVERRIDE
149 : {
150 0 : return name();
151 : }
152 : QString description() const Q_DECL_OVERRIDE;
153 : QStringList groupList() const Q_DECL_OVERRIDE;
154 : QGpgMENewCryptoConfigGroup *group(const QString &name) const Q_DECL_OVERRIDE;
155 :
156 : void sync(bool runtime);
157 :
158 : private:
159 : GpgME::Configuration::Component m_component;
160 : QHash< QString, std::shared_ptr<QGpgMENewCryptoConfigGroup> > m_groupsByName;
161 : };
162 :
163 : /**
164 : * CryptoConfig implementation around the gpgconf command-line tool
165 : * For method docu, see kleo/cryptoconfig.h
166 : */
167 : class QGPGME_EXPORT QGpgMENewCryptoConfig : public QGpgME::CryptoConfig
168 : {
169 : public:
170 : /**
171 : * Constructor
172 : */
173 : QGpgMENewCryptoConfig();
174 : ~QGpgMENewCryptoConfig();
175 :
176 : QStringList componentList() const Q_DECL_OVERRIDE;
177 :
178 : QGpgMENewCryptoConfigComponent *component(const QString &name) const Q_DECL_OVERRIDE;
179 :
180 : void clear() Q_DECL_OVERRIDE;
181 : void sync(bool runtime) Q_DECL_OVERRIDE;
182 :
183 : private:
184 : /// @param showErrors if true, a messagebox will be shown if e.g. gpgconf wasn't found
185 : void reloadConfiguration(bool showErrors);
186 :
187 : private:
188 : QHash< QString, std::shared_ptr<QGpgMENewCryptoConfigComponent> > m_componentsByName;
189 : bool m_parsed;
190 : };
191 :
192 : #endif /* QGPGME_QGPGMENEWCRYPTOCONFIG_H */
|