Libkleo

keyselectiondialog.h
1/* -*- c++ -*-
2 keyselectiondialog.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 SPDX-License-Identifier: GPL-2.0-or-later
12*/
13
14#pragma once
15
16#include "kleo_export.h"
17
18#include <QGpgME/Protocol>
19
20#include <QDialog>
21
22#include <gpgme++/key.h>
23
24#include <vector>
25
26class QCheckBox;
27class QLabel;
28class QPoint;
29class QTimer;
30class QVBoxLayout;
31
32namespace Kleo
33{
34class KeyListView;
35class KeyListViewItem;
36}
37
38namespace GpgME
39{
40class KeyListResult;
41}
42
43namespace Kleo
44{
45
46class KLEO_EXPORT KeySelectionDialog : public QDialog
47{
48 Q_OBJECT
49public:
50 enum Option {
51 // clang-format off
52 RereadKeys = 0x01,
53 ExternalCertificateManager = 0x02,
54 ExtendedSelection = 0x04,
55 RememberChoice = 0x08,
56 // clang-format on
57 };
58 Q_DECLARE_FLAGS(Options, Option)
59
60 enum KeyUsage {
61 // clang-format off
62 PublicKeys = 1,
63 SecretKeys = 2,
64 EncryptionKeys = 4,
65 SigningKeys = 8,
66 ValidKeys = 16,
67 TrustedKeys = 32,
68 CertificationKeys = 64,
69 AuthenticationKeys = 128,
70 OpenPGPKeys = 256,
71 SMIMEKeys = 512,
72 AllKeys = PublicKeys | SecretKeys | OpenPGPKeys | SMIMEKeys,
73 ValidEncryptionKeys = AllKeys | EncryptionKeys | ValidKeys,
74 ValidTrustedEncryptionKeys = AllKeys | EncryptionKeys | ValidKeys | TrustedKeys
75 // clang-format on
76 };
77
78 explicit KeySelectionDialog(QWidget *parent = nullptr, Options options = Options());
79
80 KeySelectionDialog(const QString &title,
81 const QString &text,
82 const std::vector<GpgME::Key> &selectedKeys = std::vector<GpgME::Key>(),
83 unsigned int keyUsage = AllKeys,
84 bool extendedSelection = false,
85 bool rememberChoice = false,
86 QWidget *parent = nullptr,
87 bool modal = true);
88 KeySelectionDialog(const QString &title,
89 const QString &text,
90 const QString &initialPattern,
91 const std::vector<GpgME::Key> &selectedKeys,
92 unsigned int keyUsage = AllKeys,
93 bool extendedSelection = false,
94 bool rememberChoice = false,
95 QWidget *parent = nullptr,
96 bool modal = true);
97 KeySelectionDialog(const QString &title,
98 const QString &text,
99 const QString &initialPattern,
100 unsigned int keyUsage = AllKeys,
101 bool extendedSelection = false,
102 bool rememberChoice = false,
103 QWidget *parent = nullptr,
104 bool modal = true);
105 ~KeySelectionDialog() override;
106
107 void setText(const QString &text);
108
109 void setKeys(const std::vector<GpgME::Key> &keys);
110
111 /** Returns the key ID of the selected key in single selection mode.
112 Otherwise it returns a null key. */
113 const GpgME::Key &selectedKey() const;
114
115 QString fingerprint() const;
116
117 /** Returns a list of selected key IDs. */
118 const std::vector<GpgME::Key> &selectedKeys() const
119 {
120 return mSelectedKeys;
121 }
122
123 /// Return all the selected fingerprints
124 QStringList fingerprints() const;
125
126 /// Return the selected openpgp fingerprints
127 QStringList pgpKeyFingerprints() const;
128 /// Return the selected smime fingerprints
129 QStringList smimeFingerprints() const;
130
131 bool rememberSelection() const;
132
133 // Could be used by derived classes to insert their own widget
134 QVBoxLayout *topLayout() const
135 {
136 return mTopLayout;
137 }
138
139private Q_SLOTS:
140 void slotRereadKeys();
141 void slotStartCertificateManager(const QString &query = QString());
142 void slotStartSearchForExternalCertificates()
143 {
144 slotStartCertificateManager(mInitialQuery);
145 }
146 void slotKeyListResult(const GpgME::KeyListResult &);
147 void slotSelectionChanged();
148 void slotCheckSelection()
149 {
150 slotCheckSelection(nullptr);
151 }
152 void slotCheckSelection(Kleo::KeyListViewItem *);
153 void slotRMB(Kleo::KeyListViewItem *, const QPoint &);
154 void slotRecheckKey();
155 void slotTryOk();
156 void slotOk();
157 void slotCancel();
158 void slotSearch(const QString &text);
159 void slotSearch();
160 void slotFilter();
161
162private:
163 void filterByKeyID(const QString &keyID);
164 void filterByKeyIDOrUID(const QString &keyID);
165 void filterByUID(const QString &uid);
166 void showAllItems();
167
168 void connectSignals();
169 void disconnectSignals();
170
171 void startKeyListJobForBackend(const QGpgME::Protocol *, const std::vector<GpgME::Key> &, bool);
172 void startValidatingKeyListing();
173
174 void setUpUI(Options options, const QString &);
175 void init(bool, bool, const QString &, const QString &);
176
177private:
178 QVBoxLayout *mTopLayout = nullptr;
179 QLabel *mTextLabel = nullptr;
180 Kleo::KeyListView *mKeyListView = nullptr;
181 Kleo::KeyListViewItem *mCurrentContextMenuItem = nullptr;
182 QCheckBox *mRememberCB = nullptr;
183 QPushButton *mOkButton = nullptr;
184
185 const QGpgME::Protocol *mOpenPGPBackend = nullptr;
186 const QGpgME::Protocol *mSMIMEBackend = nullptr;
187 std::vector<GpgME::Key> mSelectedKeys, mKeysToCheck;
188 unsigned int mKeyUsage;
189 QTimer *mCheckSelectionTimer = nullptr;
190 QTimer *mStartSearchTimer = nullptr;
191 // cross-eventloop temporaries:
192 QString mSearchText;
193 const QString mInitialQuery;
194 int mTruncated = 0;
195 int mListJobCount = 0;
196 int mSavedOffsetY = 0;
197};
198
199}
200
201Q_DECLARE_OPERATORS_FOR_FLAGS(Kleo::KeySelectionDialog::Options)
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 11:58:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.