1 /* crypto/gui/signencryptwidget.h 2 3 This file is part of Kleopatra, the KDE keymanager 4 SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik 5 SPDX-FileContributor: Intevation GmbH 6 7 SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 #pragma once 10 11 #include <QWidget> 12 #include <QVector> 13 #include <gpgme++/key.h> 14 15 class QCheckBox; 16 class QVBoxLayout; 17 18 namespace Kleo 19 { 20 class CertificateLineEdit; 21 class KeyGroup; 22 class KeySelectionCombo; 23 class AbstractKeyListModel; 24 class UnknownRecipientWidget; 25 26 class SignEncryptWidget: public QWidget 27 { 28 Q_OBJECT 29 public: 30 /** If cmsSigEncExclusive is true CMS operations can be 31 * done only either as sign or as encrypt */ 32 explicit SignEncryptWidget(QWidget *parent = nullptr, bool cmsSigEncExclusive = false); 33 34 /** Overwrite default text with custom text, e.g. with a character marked 35 * as shortcut key. */ 36 void setSignAsText(const QString &text); 37 void setEncryptForMeText(const QString &text); 38 void setEncryptForOthersText(const QString &text); 39 void setEncryptWithPasswordText(const QString &text); 40 41 /** Returns the list of recipients selected in the dialog 42 * or an empty list if encryption is disabled */ 43 std::vector<GpgME::Key> recipients() const; 44 45 /** Returns the selected signing key or a null key if signing 46 * is disabled. */ 47 GpgME::Key signKey() const; 48 49 /** Returns the selected encrypt to self key or a null key if 50 * encrypt to self is disabled. */ 51 GpgME::Key selfKey() const; 52 53 /** Returns the operation based on the current selection or 54 * a null string if nothing would happen. */ 55 QString currentOp() const; 56 57 /** Whether or not symmetric encryption should also be used. */ 58 bool encryptSymmetric() const; 59 60 /** Save the currently selected signing and encrypt to self keys. */ 61 void saveOwnKeys() const; 62 63 /** Return whether or not all keys involved in the operation are 64 compliant with CO_DE_VS, and all keys are valid (i.e. all 65 userIDs have Validity >= Full). */ 66 bool isDeVsAndValid() const; 67 68 /** Set whether or not signing group should be checked */ 69 void setSigningChecked(bool value); 70 71 /** Set whether or not encryption group should be checked */ 72 void setEncryptionChecked(bool value); 73 74 /** Filter for a specific protocol. Use UnknownProtocol for both 75 * S/MIME and OpenPGP */ 76 void setProtocol(GpgME::Protocol protocol); 77 78 /** Add a recipient with the key key */ 79 void addRecipient(const GpgME::Key &key); 80 81 /** Add a group of recipients */ 82 void addRecipient(const Kleo::KeyGroup &group); 83 84 /** Add a placehoder for an unknown key */ 85 void addUnknownRecipient(const char *keyId); 86 87 /** Remove all Recipients added by keyId or by key. */ 88 void clearAddedRecipients(); 89 90 /** Remove a Recipient key */ 91 void removeRecipient(const GpgME::Key &key); 92 93 /** Remove a recipient group */ 94 void removeRecipient(const Kleo::KeyGroup &group); 95 96 /** Validate that each line edit with content has a key. */ 97 bool validate(); 98 99 protected Q_SLOTS: 100 void updateOp(); 101 void recipientsChanged(); 102 void recpRemovalRequested(CertificateLineEdit *w); 103 void dialogRequested(CertificateLineEdit *w); 104 105 protected: 106 void loadKeys(); 107 108 Q_SIGNALS: 109 /* Emitted when the certificate selection changed the operation 110 * with that selection. e.g. "Sign" or "Sign/Encrypt". 111 * If no crypto operation is selected this returns a null string. */ 112 void operationChanged(const QString &op); 113 114 /* Emitted when the certificate selection might be changed. */ 115 void keysChanged(); 116 117 private: 118 CertificateLineEdit* addRecipientWidget(); 119 void onProtocolChanged(); 120 void updateCheckBoxes(); 121 122 private: 123 KeySelectionCombo *mSigSelect = nullptr; 124 KeySelectionCombo *mSelfSelect = nullptr; 125 QVector<CertificateLineEdit *> mRecpWidgets; 126 QVector<UnknownRecipientWidget *> mUnknownWidgets; 127 QVector<GpgME::Key> mAddedKeys; 128 QVector<KeyGroup> mAddedGroups; 129 QVBoxLayout *mRecpLayout = nullptr; 130 QString mOp; 131 AbstractKeyListModel *mModel = nullptr; 132 QCheckBox *mSymmetric = nullptr; 133 QCheckBox *mSigChk = nullptr; 134 QCheckBox *mEncOtherChk = nullptr; 135 QCheckBox *mEncSelfChk = nullptr; 136 GpgME::Protocol mCurrentProto = GpgME::UnknownProtocol; 137 const bool mIsExclusive; 138 }; 139 } // namespace Kleo 140