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

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 KeySelectionComboPrivate;
0029 
0030 class KLEO_EXPORT KeySelectionCombo : public QComboBox
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     explicit KeySelectionCombo(QWidget *parent = nullptr);
0036     explicit KeySelectionCombo(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 KeySelectionCombo(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 KeySelectionCombo(KeyUsage::Flag usage, QWidget *parent = nullptr);
0053     KeySelectionCombo(bool secretOnly, KeyUsage::Flags usage, QWidget *parent = nullptr);
0054     ~KeySelectionCombo() 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     void setDefaultKey(const QString &fingerprint);
0069     void setDefaultKey(const QString &fingerprint, GpgME::Protocol proto);
0070     QString defaultKey() const;
0071     QString defaultKey(GpgME::Protocol proto) const;
0072 
0073     void prependCustomItem(const QIcon &icon, const QString &text, const QVariant &data);
0074     void appendCustomItem(const QIcon &icon, const QString &text, const QVariant &data);
0075     void prependCustomItem(const QIcon &icon, const QString &text, const QVariant &data, const QString &toolTip);
0076     void appendCustomItem(const QIcon &icon, const QString &text, const QVariant &data, const QString &toolTip);
0077     void removeCustomItem(const QVariant &data);
0078 
0079 Q_SIGNALS:
0080     void customItemSelected(const QVariant &data);
0081     void currentKeyChanged(const GpgME::Key &key);
0082     void keyListingFinished();
0083 
0084 protected:
0085     virtual void init();
0086 
0087 private:
0088     std::unique_ptr<KeySelectionComboPrivate> const d;
0089 };
0090 
0091 }