File indexing completed on 2024-06-23 05:13:49
0001 /* crypto/gui/certificatelineedit.h 0002 0003 This file is part of Kleopatra, the KDE keymanager 0004 SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik 0005 SPDX-FileContributor: Intevation GmbH 0006 SPDX-FileCopyrightText: 2021, 2022 g10 Code GmbH 0007 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 #pragma once 0012 0013 #include <Libkleo/KeyUsage> 0014 0015 #include <QWidget> 0016 0017 #include <memory> 0018 0019 namespace GpgME 0020 { 0021 class Key; 0022 } 0023 0024 namespace Kleo 0025 { 0026 class AbstractKeyListModel; 0027 class KeyFilter; 0028 class KeyGroup; 0029 0030 /** Line edit and completion based Certificate Selection Widget. 0031 * 0032 * Shows the status of the selection with a status label and icon. 0033 * 0034 * The widget will use a single line HBox Layout. For larger dialog 0035 * see certificateslectiondialog. 0036 */ 0037 class CertificateLineEdit : public QWidget 0038 { 0039 Q_OBJECT 0040 public: 0041 /** Create the certificate selection line. 0042 * 0043 * If parent is not NULL the model is not taken 0044 * over but the parent argument used as the parent of the model. 0045 * 0046 * @param model The keylistmodel to use. 0047 * @param usage the desired usage of the certificate 0048 * @param filter The filters to use. See certificateselectiondialog. 0049 * @param parent The usual widget parent. 0050 * 0051 * \a usage is used to mark certificates that cannot be used for the desired 0052 * usage with an appropriate icon. This is useful in combination with a suitable 0053 * key filter. 0054 * For example, the key filter could filter out any certificates without 0055 * encryption subkeys and the usage flags would mark certificates with expired 0056 * encryption subkeys as unusable, so that the users see that there is a 0057 * certificate, but that it cannot be used. 0058 */ 0059 explicit CertificateLineEdit(AbstractKeyListModel *model, KeyUsage::Flags usage = KeyUsage::None, KeyFilter *filter = nullptr, QWidget *parent = nullptr); 0060 0061 ~CertificateLineEdit() override; 0062 0063 /** Get the selected key */ 0064 GpgME::Key key() const; 0065 0066 KeyGroup group() const; 0067 0068 /** The current text */ 0069 QString text() const; 0070 0071 /** Check if the text is empty */ 0072 bool isEmpty() const; 0073 0074 /** Returns true, if the user is editing the input. */ 0075 bool isEditingInProgress() const; 0076 0077 /** Returns true if the field is empty or if a key or group is selected. */ 0078 bool hasAcceptableInput() const; 0079 0080 /** Set the preselected Key for this widget. */ 0081 void setKey(const GpgME::Key &key); 0082 0083 /** Set the preselected group for this widget. */ 0084 void setGroup(const KeyGroup &group); 0085 0086 /** Set the used keyfilter. */ 0087 void setKeyFilter(const std::shared_ptr<KeyFilter> &filter); 0088 0089 void setAccessibleNameOfLineEdit(const QString &name); 0090 0091 Q_SIGNALS: 0092 /** Emitted when the selected key changed. */ 0093 void keyChanged(); 0094 0095 /** Emitted when the entry is no longer empty. */ 0096 void editingStarted(); 0097 0098 /** Emitted when the input is cleared (i.e. becomes empty). */ 0099 void cleared(); 0100 0101 /** Emitted when the certificate selection dialog is requested. */ 0102 void certificateSelectionRequested(); 0103 0104 private: 0105 class Private; 0106 std::unique_ptr<Private> const d; 0107 }; 0108 0109 }