QGpgME  2.1.0-unknown
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 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 #include <gpgme++/configuration.h>
46 
47 #include <vector>
48 #include <utility>
49 
54 
55 class QGpgMENewCryptoConfigEntry : public QGpgME::CryptoConfigEntry
56 {
57 public:
58  QGpgMENewCryptoConfigEntry(const std::shared_ptr<QGpgMENewCryptoConfigGroup> &group, const GpgME::Configuration::Option &option);
60 
61  QString name() const override;
62  QString description() const override;
63  QString path() const override;
64  bool isOptional() const override;
65  bool isReadOnly() const override;
66  bool isList() const override;
67  bool isRuntime() const override;
68  Level level() const override;
69  ArgType argType() const override;
70  bool isSet() const override;
71  bool boolValue() const override;
72  QString stringValue() const override;
73  int intValue() const override;
74  unsigned int uintValue() const override;
75  QUrl urlValue() const override;
76  unsigned int numberOfTimesSet() const override;
77  std::vector<int> intValueList() const override;
78  std::vector<unsigned int> uintValueList() const override;
79  QList<QUrl> urlValueList() const override;
80  void resetToDefault() override;
81  void setBoolValue(bool) override;
82  void setStringValue(const QString &) override;
83  void setIntValue(int) override;
84  void setUIntValue(unsigned int) override;
85  void setURLValue(const QUrl &) override;
86  void setNumberOfTimesSet(unsigned int) override;
87  void setIntValueList(const std::vector<int> &) override;
88  void setUIntValueList(const std::vector<unsigned int> &) override;
89  void setURLValueList(const QList<QUrl> &) override;
90  bool isDirty() const override;
91 
92  QStringList stringValueList() const;
93  QVariant defaultValue() const;
94 
95 #if 0
96  void setDirty(bool b);
97  QString outputString() const;
98 
99 protected:
100  bool isStringType() const;
101  QVariant stringToValue(const QString &value, bool unescape) const;
102  QString toString(bool escape) const;
103 #endif
104 private:
105  std::weak_ptr<QGpgMENewCryptoConfigGroup> m_group;
106  GpgME::Configuration::Option m_option;
107 };
108 
109 class QGpgMENewCryptoConfigGroup : public QGpgME::CryptoConfigGroup
110 {
111 public:
112  QGpgMENewCryptoConfigGroup(const std::shared_ptr<QGpgMENewCryptoConfigComponent> &parent, const GpgME::Configuration::Option &option);
114 
115  QString name() const override;
116  QString iconName() const override
117  {
118  return QString();
119  }
120  QString description() const override;
121  QString path() const override;
122  QGpgME::CryptoConfigEntry::Level level() const override;
123  QStringList entryList() const override;
124  QGpgMENewCryptoConfigEntry *entry(const QString &name) const override;
125 
126 private:
127  friend class QGpgMENewCryptoConfigComponent; // it adds the entries
128  std::weak_ptr<QGpgMENewCryptoConfigComponent> m_component;
129  GpgME::Configuration::Option m_option;
130  QStringList m_entryNames;
131  QHash< QString, std::shared_ptr<QGpgMENewCryptoConfigEntry> > m_entriesByName;
132 };
133 
135 class QGpgMENewCryptoConfigComponent : public QGpgME::CryptoConfigComponent, public std::enable_shared_from_this<QGpgMENewCryptoConfigComponent>
136 {
137 public:
140 
141  void setComponent(const GpgME::Configuration::Component &component);
142 
143  QString name() const override;
144  QString iconName() const override
145  {
146  return name();
147  }
148  QString description() const override;
149  QStringList groupList() const override;
150  QGpgMENewCryptoConfigGroup *group(const QString &name) const override;
151 
152  void sync(bool runtime);
153 
154 private:
155  GpgME::Configuration::Component m_component;
156  QHash< QString, std::shared_ptr<QGpgMENewCryptoConfigGroup> > m_groupsByName;
157 };
158 
163 class QGPGME_EXPORT QGpgMENewCryptoConfig : public QGpgME::CryptoConfig
164 {
165 public:
171 
172  QStringList componentList() const override;
173 
174  QGpgMENewCryptoConfigComponent *component(const QString &name) const override;
175 
176  void clear() override;
177  void sync(bool runtime) override;
178 
179 private:
181  void reloadConfiguration(bool showErrors);
182 
183 private:
184  QHash< QString, std::shared_ptr<QGpgMENewCryptoConfigComponent> > m_componentsByName;
185  bool m_parsed;
186 };
187 
188 #endif /* QGPGME_QGPGMENEWCRYPTOCONFIG_H */
Definition: qgpgmenewcryptoconfig.h:163
Definition: qgpgmenewcryptoconfig.h:109
For docu, see kleo/cryptoconfig.h.
Definition: qgpgmenewcryptoconfig.h:135
Definition: qgpgmenewcryptoconfig.h:55