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 
28 namespace GpgME
29 {
30 class Key;
31 class KeyListResult;
32 }
33 
34 class QString;
35 class QPushButton;
36 
37 namespace Kleo
38 {
39 
40 /// Base class for SigningKeyRequester and EncryptionKeyRequester
41 class KLEO_EXPORT KeyRequester : public QWidget
42 {
43  Q_OBJECT
44 public:
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 
96 Q_SIGNALS:
97  void changed();
98 
99 private:
100  void init();
101  void startKeyListJob(const QStringList &fingerprints);
102  void updateKeys();
103 
104 private Q_SLOTS:
105  void slotNextKey(const GpgME::Key &key);
106  void slotKeyListResult(const GpgME::KeyListResult &result);
107  void slotDialogButtonClicked();
108  void slotEraseButtonClicked();
109 
110 private:
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 
124 private:
125  class Private;
126  Private *const d;
127 
128 protected:
129  virtual void virtual_hook(int, void *);
130 };
131 
132 class KLEO_EXPORT EncryptionKeyRequester : public KeyRequester
133 {
134  Q_OBJECT
135 public:
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 
154 private:
155  class Private;
156  Private *const d;
157 
158 protected:
159  void virtual_hook(int, void *) override;
160 };
161 
162 class KLEO_EXPORT SigningKeyRequester : public KeyRequester
163 {
164  Q_OBJECT
165 public:
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 
196 private:
197  class Private;
198  Private *const d;
199 
200 protected:
201  void virtual_hook(int, void *) override;
202 };
203 
204 }
Base class for SigningKeyRequester and EncryptionKeyRequester.
Definition: keyrequester.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:56:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.