Libkleo

keyrequester.h
1/* -*- c++ -*-
2 keyrequester.h
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6
7 Based on kpgpui.h
8 SPDX-FileCopyrightText: 2001, 2002 the KPGP authors
9 See file libkdenetwork/AUTHORS.kpgp for details
10
11 This file is part of KPGP, the KDE PGP/GnuPG support library.
12
13 SPDX-License-Identifier: GPL-2.0-or-later
14 */
15
16#pragma once
17
18#include "kleo_export.h"
19
20#include <QGpgME/Protocol>
21
22#include <QLabel>
23#include <QStringList>
24#include <QWidget>
25
26#include <vector>
27
28namespace GpgME
29{
30class Key;
31class KeyListResult;
32}
33
34class QString;
35class QPushButton;
36
37namespace Kleo
38{
39
40/// Base class for SigningKeyRequester and EncryptionKeyRequester
41class KLEO_EXPORT KeyRequester : public QWidget
42{
43 Q_OBJECT
44public:
45 explicit KeyRequester(unsigned int allowedKeys, bool multipleKeys = false, QWidget *parent = nullptr);
46 // Constructor for Qt Designer
47 explicit KeyRequester(QWidget *parent = nullptr);
48 ~KeyRequester() override;
49
50 const GpgME::Key &key() const;
51 /** Preferred method to set a key for
52 non-multi-KeyRequesters. Doesn't start a backend
53 KeyListJob.
54 */
55 void setKey(const GpgME::Key &key);
56
57 const std::vector<GpgME::Key> &keys() const;
58 /** Preferred method to set a key for multi-KeyRequesters. Doesn't
59 start a backend KeyListJob.
60 */
61 void setKeys(const std::vector<GpgME::Key> &keys);
62
63 QString fingerprint() const;
64 /** Set the key by fingerprint. Starts a background KeyListJob to
65 retrieve the complete GpgME::Key object
66 */
67 void setFingerprint(const QString &fingerprint);
68
69 QStringList fingerprints() const;
70 /** Set the keys by fingerprint. Starts a background KeyListJob to
71 retrieve the complete GpgME::Key objects
72 */
73 void setFingerprints(const QStringList &fingerprints);
74
75 QPushButton *eraseButton();
76 QPushButton *dialogButton();
77
78 void setDialogCaption(const QString &caption);
79 void setDialogMessage(const QString &message);
80
81 bool isMultipleKeysEnabled() const;
82 void setMultipleKeysEnabled(bool enable);
83
84 unsigned int allowedKeys() const;
85 void setAllowedKeys(unsigned int allowed);
86
87 void setInitialQuery(const QString &s)
88 {
89 mInitialQuery = s;
90 }
91 const QString &initialQuery() const
92 {
93 return mInitialQuery;
94 }
95
96Q_SIGNALS:
97 void changed();
98
99private:
100 void init();
101 void startKeyListJob(const QStringList &fingerprints);
102 void updateKeys();
103
104private Q_SLOTS:
105 void slotNextKey(const GpgME::Key &key);
106 void slotKeyListResult(const GpgME::KeyListResult &result);
107 void slotDialogButtonClicked();
108 void slotEraseButtonClicked();
109
110private:
111 const QGpgME::Protocol *mOpenPGPBackend = nullptr;
112 const QGpgME::Protocol *mSMIMEBackend = nullptr;
113 QLabel *mComplianceIcon = nullptr;
114 QLabel *mLabel = nullptr;
115 QPushButton *mEraseButton = nullptr;
116 QPushButton *mDialogButton = nullptr;
117 QString mDialogCaption, mDialogMessage, mInitialQuery;
118 bool mMulti;
119 unsigned int mKeyUsage;
120 int mJobs;
121 std::vector<GpgME::Key> mKeys;
122 std::vector<GpgME::Key> mTmpKeys;
123
124private:
125 class Private;
126 Private *const d;
127
128protected:
129 virtual void virtual_hook(int, void *);
130};
131
132class KLEO_EXPORT EncryptionKeyRequester : public KeyRequester
133{
134 Q_OBJECT
135public:
136 enum { OpenPGP = 1, SMIME = 2, AllProtocols = OpenPGP | SMIME };
137
138 /**
139 * Preferred constructor
140 */
141 explicit EncryptionKeyRequester(bool multipleKeys = false,
142 unsigned int proto = AllProtocols,
143 QWidget *parent = nullptr,
144 bool onlyTrusted = true,
145 bool onlyValid = true);
146 /**
147 * Constructor for Qt designer
148 */
149 explicit EncryptionKeyRequester(QWidget *parent);
150 ~EncryptionKeyRequester() override;
151
152 void setAllowedKeys(unsigned int proto, bool onlyTrusted = true, bool onlyValid = true);
153
154private:
155 class Private;
156 Private *const d;
157
158protected:
159 void virtual_hook(int, void *) override;
160};
161
162class KLEO_EXPORT SigningKeyRequester : public KeyRequester
163{
164 Q_OBJECT
165public:
166 enum { OpenPGP = 1, SMIME = 2, AllProtocols = OpenPGP | SMIME };
167
168 /**
169 * Preferred constructor
170 * @param multipleKeys whether multiple keys can be selected
171 *
172 * @param proto the allowed protocols, OpenPGP and/or SMIME
173 * @param parent the parent widget
174 * @param onlyTrusted only show trusted keys
175 * @param onlyValid only show valid keys
176 */
177 explicit SigningKeyRequester(bool multipleKeys = false,
178 unsigned int proto = AllProtocols,
179 QWidget *parent = nullptr,
180 bool onlyTrusted = true,
181 bool onlyValid = true);
182 /**
183 * Constructor for Qt designer
184 */
185 explicit SigningKeyRequester(QWidget *parent);
186 ~SigningKeyRequester() override;
187
188 /*
189 * Those parameters affect the parameters given to the key selection dialog.
190 * @param proto the allowed protocols, OpenPGP and/or SMIME
191 * @param onlyTrusted only show trusted keys
192 * @param onlyValid only show valid keys
193 */
194 void setAllowedKeys(unsigned int proto, bool onlyTrusted = true, bool onlyValid = true);
195
196private:
197 class Private;
198 Private *const d;
199
200protected:
201 void virtual_hook(int, void *) override;
202};
203
204}
Base class for SigningKeyRequester and EncryptionKeyRequester.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.