File indexing completed on 2025-01-05 04:55:51

0001 /*  This file is part of Kleopatra, the KDE keymanager
0002     SPDX-FileCopyrightText: 2016 Klarälvdalens Datakonsult AB
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kleo_export.h"
0010 
0011 #include <libkleo/enum.h>
0012 #include <libkleo/keyusage.h>
0013 
0014 #include <QComboBox>
0015 
0016 #include <gpgme++/global.h>
0017 
0018 #include <memory>
0019 
0020 namespace GpgME
0021 {
0022 class Key;
0023 }
0024 
0025 namespace Kleo
0026 {
0027 class KeyFilter;
0028 class UserIDSelectionComboPrivate;
0029 
0030 class KLEO_EXPORT UserIDSelectionCombo : public QComboBox
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     explicit UserIDSelectionCombo(QWidget *parent = nullptr);
0036     explicit UserIDSelectionCombo(bool secretOnly, QWidget *parent = nullptr);
0037     /**
0038      * @param usage the desired usage of the certificate
0039      *
0040      * \a usage is used to mark certificates that cannot be used for the desired
0041      * usage with an appropriate icon. This is useful in combination with a suitable
0042      * key filter.
0043      * For example, the key filter could filter out any certificates without
0044      * encryption subkeys and the usage flags would mark certificates with expired
0045      * encryption subkeys as unusable, so that the users see that there is a
0046      * certificate, but that it cannot be used.
0047      */
0048     explicit UserIDSelectionCombo(KeyUsage::Flags usage, QWidget *parent = nullptr);
0049     /* Overload to help the compiler choose the correct overload if a KeyUsage::Flag is passed as first argument.
0050      * Without this overload the compiler tries to use the bool-overload instead of the KeyUsage::Flags-overload
0051      * and throws an error. */
0052     explicit UserIDSelectionCombo(KeyUsage::Flag usage, QWidget *parent = nullptr);
0053     UserIDSelectionCombo(bool secretOnly, KeyUsage::Flags usage, QWidget *parent = nullptr);
0054     ~UserIDSelectionCombo() override;
0055 
0056     void setKeyFilter(const std::shared_ptr<const KeyFilter> &kf);
0057     std::shared_ptr<const KeyFilter> keyFilter() const;
0058 
0059     void setIdFilter(const QString &id);
0060     QString idFilter() const;
0061 
0062     void refreshKeys();
0063 
0064     GpgME::Key currentKey() const;
0065     void setCurrentKey(const GpgME::Key &key);
0066     void setCurrentKey(const QString &fingerprint);
0067 
0068     GpgME::UserID currentUserID() const;
0069     void setCurrentUserID(const GpgME::UserID &userID);
0070 
0071     void setDefaultKey(const QString &fingerprint);
0072     void setDefaultKey(const QString &fingerprint, GpgME::Protocol proto);
0073     QString defaultKey() const;
0074     QString defaultKey(GpgME::Protocol proto) const;
0075 
0076     void prependCustomItem(const QIcon &icon, const QString &text, const QVariant &data);
0077     void appendCustomItem(const QIcon &icon, const QString &text, const QVariant &data);
0078     void prependCustomItem(const QIcon &icon, const QString &text, const QVariant &data, const QString &toolTip);
0079     void appendCustomItem(const QIcon &icon, const QString &text, const QVariant &data, const QString &toolTip);
0080     void removeCustomItem(const QVariant &data);
0081 
0082 Q_SIGNALS:
0083     void customItemSelected(const QVariant &data);
0084     void currentKeyChanged(const GpgME::Key &key);
0085     void keyListingFinished();
0086 
0087 protected:
0088     virtual void init();
0089 
0090 private:
0091     std::unique_ptr<UserIDSelectionComboPrivate> const d;
0092 };
0093 
0094 }