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