Line data Source code
1 : /*
2 : cryptoconfig.h
3 :
4 : This file is part of qgpgme, the Qt API binding for gpgme
5 : Copyright (c) 2004 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 CRYPTOCONFIG_H
35 : #define CRYPTOCONFIG_H
36 :
37 : #include "qgpgme_export.h"
38 : #ifdef __cplusplus
39 : /* we read this file from a C compiler, and are only interested in the
40 : * enums... */
41 :
42 : #include <QUrl>
43 :
44 : #include <vector>
45 :
46 : /* Start reading this file from the bottom up :) */
47 :
48 : namespace QGpgME
49 : {
50 :
51 : /**
52 : * Description of a single option
53 : */
54 1932 : class QGPGME_EXPORT CryptoConfigEntry
55 : {
56 :
57 : public:
58 : #endif /* __cplusplus */
59 : /**
60 : @li basic This option should always be offered to the user.
61 : @li advanced This option may be offered to advanced users.
62 : @li expert This option should only be offered to expert users.
63 : */
64 : enum Level { Level_Basic = 0,
65 : Level_Advanced = 1,
66 : Level_Expert = 2
67 : };
68 :
69 : /**
70 : Type of the argument
71 : @li ArgType_None The option is set or not set, but no argument.
72 : @li ArgType_String An unformatted string.
73 : @li ArgType_Int A signed integer number.
74 : @li ArgType_UInt An unsigned integer number.
75 : @li ArgType_Path A string that describes the pathname of a file.
76 : The file does not necessarily need to exist.
77 : Separated from string so that e.g. a FileDialog can be used.
78 : @li ArgType_DirPath A string that describes the pathname of a directory.
79 : The directory does not necessarily need to exist.
80 : Separated from path so that e.g. a FileDialog can be used which only
81 : allows directories to be selected.
82 : @li ArgType_LDAPURL A LDAP URL
83 : Separated from URL so that a more specific widget can be shown, hiding the url syntax
84 : */
85 : enum ArgType { ArgType_None = 0,
86 : ArgType_String = 1,
87 : ArgType_Int = 2,
88 : ArgType_UInt = 3,
89 : ArgType_Path = 4,
90 : /* Nr. 5 was URL historically. */
91 : ArgType_LDAPURL = 6,
92 : ArgType_DirPath = 7,
93 :
94 : NumArgType
95 : };
96 :
97 : #ifdef __cplusplus
98 1840 : virtual ~CryptoConfigEntry() {}
99 :
100 : /**
101 : * Return the internal name of this entry
102 : */
103 : virtual QString name() const = 0;
104 :
105 : /**
106 : * @return user-visible description of this entry
107 : */
108 : virtual QString description() const = 0;
109 :
110 : /**
111 : * @return "component/group/name"
112 : */
113 : virtual QString path() const = 0;
114 :
115 : /**
116 : * @return true if the argument is optional
117 : */
118 : virtual bool isOptional() const = 0;
119 :
120 : /**
121 : * @return true if the entry is readonly
122 : */
123 : virtual bool isReadOnly() const = 0;
124 :
125 : /**
126 : * @return true if the argument can be given multiple times
127 : */
128 : virtual bool isList() const = 0;
129 :
130 : /**
131 : * @return true if the argument can be changed at runtime
132 : */
133 : virtual bool isRuntime() const = 0;
134 :
135 : /**
136 : * User level
137 : */
138 : virtual Level level() const = 0;
139 :
140 : /**
141 : * Argument type
142 : */
143 : virtual ArgType argType() const = 0;
144 :
145 : /**
146 : * Return true if the option is set, i.e. different from default
147 : */
148 : virtual bool isSet() const = 0;
149 :
150 : /**
151 : * Return value as a bool (only allowed for ArgType_None)
152 : */
153 : virtual bool boolValue() const = 0;
154 :
155 : /**
156 : * Return value as a string (available for all argtypes)
157 : * The returned string can be empty (explicitly set to empty) or null (not set).
158 : */
159 : virtual QString stringValue() const = 0;
160 :
161 : /**
162 : * Return value as a signed int
163 : */
164 : virtual int intValue() const = 0;
165 :
166 : /**
167 : * Return value as an unsigned int
168 : */
169 : virtual unsigned int uintValue() const = 0;
170 :
171 : /**
172 : * Return value as a URL (only meaningful for Path and URL argtypes)
173 : */
174 : virtual QUrl urlValue() const = 0;
175 :
176 : /**
177 : * Return number of times the option is set (only valid for ArgType_None, if isList())
178 : */
179 : virtual unsigned int numberOfTimesSet() const = 0;
180 :
181 : /**
182 : * Return value as a list of signed ints
183 : */
184 : virtual std::vector<int> intValueList() const = 0;
185 :
186 : /**
187 : * Return value as a list of unsigned ints
188 : */
189 : virtual std::vector<unsigned int> uintValueList() const = 0;
190 :
191 : /**
192 : * Return value as a list of URLs (only meaningful for Path and URL argtypes, if isList())
193 : */
194 : virtual QList<QUrl> urlValueList() const = 0;
195 :
196 : /**
197 : * Reset an option to its default value
198 : */
199 : virtual void resetToDefault() = 0;
200 :
201 : /**
202 : * Define whether the option is set or not (only allowed for ArgType_None)
203 : * #### TODO: and for options with optional args
204 : */
205 : virtual void setBoolValue(bool) = 0;
206 :
207 : /**
208 : * Set string value (allowed for all argtypes)
209 : */
210 : virtual void setStringValue(const QString &) = 0;
211 :
212 : /**
213 : * Set a new signed int value
214 : */
215 : virtual void setIntValue(int) = 0;
216 :
217 : /**
218 : * Set a new unsigned int value
219 : */
220 : virtual void setUIntValue(unsigned int) = 0;
221 :
222 : /**
223 : * Set value as a URL (only meaningful for Path (if local) and URL argtypes)
224 : */
225 : virtual void setURLValue(const QUrl &) = 0;
226 :
227 : /**
228 : * Set the number of times the option is set (only valid for ArgType_None, if isList())
229 : */
230 : virtual void setNumberOfTimesSet(unsigned int) = 0;
231 :
232 : /**
233 : * Set a new list of signed int values
234 : */
235 : virtual void setIntValueList(const std::vector<int> &) = 0;
236 :
237 : /**
238 : * Set a new list of unsigned int values
239 : */
240 : virtual void setUIntValueList(const std::vector<unsigned int> &) = 0;
241 :
242 : /**
243 : * Set value as a URL list (only meaningful for Path (if all URLs are local) and URL argtypes, if isList())
244 : */
245 : virtual void setURLValueList(const QList<QUrl> &) = 0;
246 :
247 : /**
248 : * @return true if the value was changed
249 : */
250 : virtual bool isDirty() const = 0;
251 :
252 : // Design change from here on we are closely bound to one implementation
253 : // of cryptoconfig. To avoid ABI breaks with every new function we
254 : // add real functions from now on.
255 :
256 : /**
257 : * @return a stringValueList.
258 : */
259 : QStringList stringValueList() const;
260 : };
261 :
262 : /**
263 : * Group containing a set of config options
264 : */
265 567 : class QGPGME_EXPORT CryptoConfigGroup
266 : {
267 :
268 : public:
269 540 : virtual ~CryptoConfigGroup() {}
270 :
271 : /**
272 : * Return the internal name of this group
273 : */
274 : virtual QString name() const = 0;
275 :
276 : /**
277 : * Return the name of the icon for this group
278 : */
279 : virtual QString iconName() const = 0;
280 :
281 : /**
282 : * @return user-visible description of this group
283 : */
284 : virtual QString description() const = 0;
285 :
286 : /**
287 : * @return "component/group"
288 : */
289 : virtual QString path() const = 0;
290 :
291 : /**
292 : * User level
293 : */
294 : virtual CryptoConfigEntry::Level level() const = 0;
295 :
296 : /**
297 : * Returns the list of entries that are known by this group.
298 : *
299 : * @return list of group entry names.
300 : **/
301 : virtual QStringList entryList() const = 0;
302 :
303 : /**
304 : * @return the configuration object for a given entry in this group
305 : * The object is owned by CryptoConfigGroup, don't delete it.
306 : * Groups cannot be nested, so all entries returned here are pure entries, no groups.
307 : */
308 : virtual CryptoConfigEntry *entry(const QString &name) const = 0;
309 : };
310 :
311 : /**
312 : * Crypto config for one component (e.g. gpg-agent, dirmngr etc.)
313 : */
314 126 : class QGPGME_EXPORT CryptoConfigComponent
315 : {
316 :
317 : public:
318 120 : virtual ~CryptoConfigComponent() {}
319 :
320 : /**
321 : * Return the internal name of this component
322 : */
323 : virtual QString name() const = 0;
324 :
325 : /**
326 : * Return the name of the icon for this component
327 : */
328 : virtual QString iconName() const = 0;
329 :
330 : /**
331 : * Return user-visible description of this component
332 : */
333 : virtual QString description() const = 0;
334 :
335 : /**
336 : * Returns the list of groups that are known about.
337 : *
338 : * @return list of group names. One of them can be "<nogroup>", which is the group where all
339 : * "toplevel" options (belonging to no group) are.
340 : */
341 : virtual QStringList groupList() const = 0;
342 :
343 : /**
344 : * @return the configuration object for a given group
345 : * The object is owned by CryptoConfigComponent, don't delete it.
346 : */
347 : virtual CryptoConfigGroup *group(const QString &name) const = 0;
348 :
349 : };
350 :
351 : /**
352 : * Main interface to crypto configuration.
353 : */
354 1 : class QGPGME_EXPORT CryptoConfig
355 : {
356 :
357 : public:
358 0 : virtual ~CryptoConfig() {}
359 :
360 : /**
361 : * Returns the list of known components (e.g. "gpg-agent", "dirmngr" etc.).
362 : * Use @ref component() to retrieve more information about each one.
363 : * @return list of component names.
364 : **/
365 : virtual QStringList componentList() const = 0;
366 :
367 : /**
368 : * @return the configuration object for a given component
369 : * The object is owned by CryptoConfig, don't delete it.
370 : */
371 : virtual CryptoConfigComponent *component(const QString &name) const = 0;
372 :
373 : /**
374 : * Convenience method to get hold of a single configuration entry when
375 : * its component, group and name are known. This can be used to read
376 : * the value and/or to set a value to it.
377 : *
378 : * @return the configuration object for a single configuration entry, 0 if not found.
379 : * The object is owned by CryptoConfig, don't delete it.
380 : */
381 30 : CryptoConfigEntry *entry(const QString &componentName, const QString &groupName, const QString &entryName) const
382 : {
383 30 : const QGpgME::CryptoConfigComponent *comp = component(componentName);
384 30 : const QGpgME::CryptoConfigGroup *group = comp ? comp->group(groupName) : 0;
385 30 : return group ? group->entry(entryName) : 0;
386 : }
387 :
388 : /**
389 : * Write back changes
390 : *
391 : * @param runtime this parameter is ignored. Changes will always
392 : * be made with --runtime set.
393 : */
394 : virtual void sync(bool runtime) = 0;
395 :
396 : /**
397 : * Tells the CryptoConfig to discard any cached information, including
398 : * all components, groups and entries.
399 : * Call this to free some memory when you won't be using the object
400 : * for some time.
401 : * DON'T call this if you're holding pointers to components, groups or entries.
402 : */
403 : virtual void clear() = 0;
404 : };
405 :
406 : }
407 : #endif /* __cplusplus */
408 : #endif /* CRYPTOCONFIG_H */
|