File indexing completed on 2024-06-23 05:14:02

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     dialogs/certificateselectiondialog.h
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <QDialog>
0013 
0014 #include <utils/pimpl_ptr.h>
0015 
0016 #include <gpgme++/global.h>
0017 
0018 #include <memory>
0019 #include <vector>
0020 
0021 namespace GpgME
0022 {
0023 class Key;
0024 }
0025 
0026 namespace Kleo
0027 {
0028 
0029 class KeyFilter;
0030 class KeyGroup;
0031 
0032 namespace Dialogs
0033 {
0034 
0035 class CertificateSelectionDialog : public QDialog
0036 {
0037     Q_OBJECT
0038     Q_FLAGS(Options)
0039 public:
0040     enum Option {
0041         // clang-format off
0042         SingleSelection = 0x00,
0043         MultiSelection  = 0x01,
0044 
0045         SignOnly        = 0x02,
0046         EncryptOnly     = 0x04,
0047         AnyCertificate  = 0x06,
0048 
0049         OpenPGPFormat   = 0x08,
0050         CMSFormat       = 0x10,
0051         AnyFormat       = 0x18,
0052 
0053         Certificates    = 0x00,
0054         SecretKeys      = 0x20,
0055 
0056         IncludeGroups   = 0x40,
0057 
0058         OptionMask
0059         // clang-format on
0060     };
0061     Q_DECLARE_FLAGS(Options, Option)
0062 
0063     static Option optionsFromProtocol(GpgME::Protocol proto);
0064 
0065     explicit CertificateSelectionDialog(QWidget *parent = nullptr);
0066     ~CertificateSelectionDialog() override;
0067 
0068     void setCustomLabelText(const QString &text);
0069     QString customLabelText() const;
0070 
0071     void setOptions(Options options);
0072     Options options() const;
0073 
0074     void selectCertificates(const std::vector<GpgME::Key> &certs);
0075     void selectCertificate(const GpgME::Key &key);
0076 
0077     std::vector<GpgME::Key> selectedCertificates() const;
0078     GpgME::Key selectedCertificate() const;
0079 
0080     void selectGroups(const std::vector<Kleo::KeyGroup> &groups);
0081     std::vector<Kleo::KeyGroup> selectedGroups() const;
0082 
0083     static void filterAllowedKeys(std::vector<GpgME::Key> &keys, int options);
0084 
0085 public Q_SLOTS:
0086     void setStringFilter(const QString &text);
0087     void setKeyFilter(const std::shared_ptr<Kleo::KeyFilter> &filter);
0088     void accept() override;
0089 
0090 protected:
0091     void hideEvent(QHideEvent *) override;
0092 
0093 private:
0094     class Private;
0095     kdtools::pimpl_ptr<Private> d;
0096 };
0097 
0098 }
0099 }
0100 
0101 Q_DECLARE_OPERATORS_FOR_FLAGS(Kleo::Dialogs::CertificateSelectionDialog::Options)