1 /* crypto/gui/certificatelineedit.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 SPDX-FileCopyrightText: 2021 g10 Code GmbH 7 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 8 9 SPDX-License-Identifier: GPL-2.0-or-later 10 */ 11 #pragma once 12 13 #include <Libkleo/KeyGroup> 14 15 #include <QLineEdit> 16 17 #include <gpgme++/key.h> 18 19 #include <memory> 20 21 class QCompleter; 22 class QLabel; 23 class QAction; 24 25 namespace Kleo 26 { 27 class AbstractKeyListModel; 28 class KeyFilter; 29 class KeyListSortFilterProxyModel; 30 31 /** Line edit and completion based Certificate Selection Widget. 32 * 33 * Shows the status of the selection with a status label and icon. 34 * 35 * The widget will use a single line HBox Layout. For larger dialog 36 * see certificateslectiondialog. 37 */ 38 class CertificateLineEdit: public QLineEdit 39 { 40 Q_OBJECT 41 public: 42 /** Create the certificate selection line. 43 * 44 * If parent is not NULL the model is not taken 45 * over but the parent argument used as the parent of the model. 46 * 47 * @param model: The keylistmodel to use. 48 * @param parent: The usual widget parent. 49 * @param filter: The filters to use. See certificateselectiondialog. 50 */ 51 CertificateLineEdit(AbstractKeyListModel *model, 52 QWidget *parent = nullptr, 53 KeyFilter *filter = nullptr); 54 55 /** Get the selected key */ 56 GpgME::Key key() const; 57 58 KeyGroup group() const; 59 60 /** Check if the text is empty */ 61 bool isEmpty() const; 62 63 /** Set the preselected Key for this widget. */ 64 void setKey(const GpgME::Key &key); 65 66 /** Set the preselected group for this widget. */ 67 void setGroup(const KeyGroup &group); 68 69 /** Set the used keyfilter. */ 70 void setKeyFilter(const std::shared_ptr<KeyFilter> &filter); 71 72 Q_SIGNALS: 73 /** Emitted when the selected key changed. */ 74 void keyChanged(); 75 76 /** Emitted when the entry is empty and editing is finished. */ 77 void wantsRemoval(CertificateLineEdit *w); 78 79 /** Emitted when the entry is no longer empty. */ 80 void editingStarted(); 81 82 /** Emitted when the details dialog or the selection dialog is requested. */ 83 void dialogRequested(); 84 85 private Q_SLOTS: 86 void updateKey(); 87 void editChanged(); 88 void editFinished(); 89 void checkLocate(); 90 91 private: 92 KeyListSortFilterProxyModel *const mFilterModel; 93 KeyListSortFilterProxyModel *const mCompleterFilterModel; 94 QCompleter *mCompleter = nullptr; 95 QLabel *mStatusLabel, 96 *mStatusIcon; 97 GpgME::Key mKey; 98 KeyGroup mGroup; 99 GpgME::Protocol mCurrentProto; 100 std::shared_ptr<KeyFilter> mFilter; 101 bool mEditStarted = false; 102 bool mEditFinished = false; 103 QAction *const mLineAction; 104 }; 105 } 106