File indexing completed on 2024-10-06 08:17:37
0001 /* 0002 SPDX-FileCopyrightText: 2008-2022 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KGPGIMPORT_H 0007 #define KGPGIMPORT_H 0008 0009 #include <QObject> 0010 #include <QString> 0011 #include <QStringList> 0012 0013 #include <QUrl> 0014 0015 #include "kgpgtextorfiletransaction.h" 0016 0017 class KGpgItemModel; 0018 0019 /** 0020 * @brief import one or more keys into the keyring 0021 */ 0022 class KGpgImport: public KGpgTextOrFileTransaction { 0023 Q_OBJECT 0024 0025 Q_DISABLE_COPY(KGpgImport) 0026 public: 0027 /** 0028 * @brief import given text 0029 * @param parent parent object 0030 * @param text key text to import 0031 */ 0032 explicit KGpgImport(QObject *parent, const QString &text = QString()); 0033 0034 /** 0035 * @brief import key(s) from file(s) 0036 * @param parent parent object 0037 * @param files list of file locations to import from 0038 */ 0039 KGpgImport(QObject *parent, const QList<QUrl> &files); 0040 0041 /** 0042 * @brief destructor 0043 */ 0044 ~KGpgImport() override = default; 0045 0046 /** 0047 * @brief get the names and short fingerprints of the imported keys 0048 * @return list of keys that were imported 0049 */ 0050 QStringList getImportedKeys() const; 0051 0052 /** 0053 * @brief get the full fingerprints of the imported keys 0054 * @param log transaction log to scan 0055 * @param reason key import reason 0056 * @return list of ids that were imported 0057 * 0058 * You can filter the list of keys returned by the status of that key 0059 * as reported by GnuPG. See doc/DETAILS of GnuPG for the meaning of 0060 * the different flags. 0061 * 0062 * If reason is -1 (the default) all processed key ids are returned. 0063 * If reason is 0 only keys of status 0 (unchanged) are returned. For 0064 * any other value a key is returned if one of his status bits matched 0065 * one of the bits in reason (i.e. (reason & status) != 0). 0066 */ 0067 static QStringList getImportedIds(const QStringList &log, const int reason = -1); 0068 /** 0069 * @brief get the full fingerprints of the imported keys 0070 * 0071 * This is an overloaded member. It calls the static function with the 0072 * result log from this transaction object. 0073 */ 0074 QStringList getImportedIds(const int reason = -1) const; 0075 0076 /** 0077 * @brief get textual summary of the import events 0078 * @return messages describing what was imported 0079 * 0080 * This is an overloaded member. It calls the static function with the 0081 * result log from this transaction object. 0082 */ 0083 QString getImportMessage() const; 0084 0085 /** 0086 * @brief get textual summary of the import events 0087 * @param log import log 0088 * @return messages describing what was imported 0089 * 0090 * The log must contain a "IMPORT_RES" line. If this is not present 0091 * the result string will contain an error message. 0092 */ 0093 static QString getImportMessage(const QStringList &log); 0094 0095 /** 0096 * @brief get detailed summary of import 0097 * @param log import log 0098 * @param model item model, @see KGpgItemModel 0099 * @return message describing which keys changed and how 0100 * 0101 * The log must contain a "IMPORT_RES" line. If this is not present 0102 * the result string will contain an error message. 0103 */ 0104 static QString getDetailedImportMessage(const QStringList &log, const KGpgItemModel *model = nullptr); 0105 0106 /** 0107 * @brief check if the given text contains a private or public key 0108 * @param text text to check 0109 * @param incomplete assume text is only the beginning of the data 0110 * @return if text contains a key or not 0111 * @retval 0 no key found 0112 * @retval 1 public key found 0113 * @retval 2 private key found 0114 */ 0115 static int isKey(const QString &text, const bool incomplete = false); 0116 0117 protected: 0118 QStringList command() const override; 0119 }; 0120 0121 #endif // KGPGIMPORT_H