File indexing completed on 2024-06-23 05:13:50

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     crypto/gui/resolverecipientspage_p.h
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <crypto/gui/resolverecipientspage.h>
0013 
0014 #include <KMime/Types>
0015 
0016 #include <QHash>
0017 
0018 class QComboBox;
0019 class QLabel;
0020 class QListWidget;
0021 class QListWidgetItem;
0022 #include <QStringList>
0023 class QToolButton;
0024 
0025 class Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget : public QWidget
0026 {
0027     Q_OBJECT
0028 public:
0029     explicit ListWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = {});
0030     ~ListWidget() override;
0031 
0032     void addEntry(const QString &id, const QString &name);
0033     void addEntry(const KMime::Types::Mailbox &mbox);
0034     void addEntry(const QString &id, const QString &name, const KMime::Types::Mailbox &mbox);
0035 
0036     void removeEntry(const QString &id);
0037     QStringList selectedEntries() const;
0038     void setCertificates(const QString &id, const std::vector<GpgME::Key> &pgpCerts, const std::vector<GpgME::Key> &cmsCerts);
0039     GpgME::Key selectedCertificate(const QString &id) const;
0040     GpgME::Key selectedCertificate(const QString &id, GpgME::Protocol prot) const;
0041     KMime::Types::Mailbox mailbox(const QString &id) const;
0042     QStringList identifiers() const;
0043     void setProtocol(GpgME::Protocol prot);
0044     void showSelectionDialog(const QString &id);
0045 
0046     enum Role {
0047         IdRole = Qt::UserRole,
0048     };
0049 
0050 Q_SIGNALS:
0051     void selectionChanged();
0052     void completeChanged();
0053 
0054 private Q_SLOTS:
0055     void onSelectionChange();
0056 
0057 private:
0058     QListWidget *m_listWidget;
0059 
0060     QHash<QString, ItemWidget *> widgets;
0061     QHash<QString, QListWidgetItem *> items;
0062     GpgME::Protocol m_protocol;
0063 };
0064 
0065 class Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget : public QWidget
0066 {
0067     Q_OBJECT
0068 public:
0069     explicit ItemWidget(const QString &id, const QString &name, const KMime::Types::Mailbox &mbox, QWidget *parent = nullptr, Qt::WindowFlags flags = {});
0070     ~ItemWidget() override;
0071 
0072     QString id() const;
0073     KMime::Types::Mailbox mailbox() const;
0074     void setCertificates(const std::vector<GpgME::Key> &pgp, const std::vector<GpgME::Key> &cms);
0075     GpgME::Key selectedCertificate() const;
0076     GpgME::Key selectedCertificate(GpgME::Protocol prot) const;
0077     std::vector<GpgME::Key> certificates() const;
0078     void setProtocol(GpgME::Protocol protocol);
0079     void setSelected(bool selected);
0080     bool isSelected() const;
0081 
0082 public Q_SLOTS:
0083     void showSelectionDialog();
0084 
0085 Q_SIGNALS:
0086     void changed();
0087 
0088 private:
0089     void addCertificateToComboBox(const GpgME::Key &key);
0090     void resetCertificates();
0091     void selectCertificateInComboBox(const GpgME::Key &key);
0092     void updateVisibility();
0093 
0094 private:
0095     QString m_id;
0096     KMime::Types::Mailbox m_mailbox;
0097     QLabel *m_nameLabel;
0098     QLabel *m_certLabel;
0099     QComboBox *m_certCombo;
0100     QToolButton *m_selectButton;
0101     GpgME::Protocol m_protocol;
0102     QHash<GpgME::Protocol, GpgME::Key> m_selectedCertificates;
0103     std::vector<GpgME::Key> m_pgp, m_cms;
0104     bool m_selected;
0105 };