1 /* 2 SPDX-FileCopyrightText: 2009 Rolf Eike Beer <kde@opensource.sf-tec.de> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #ifndef KGPGEXPORT_H 7 #define KGPGEXPORT_H 8 9 #include <QObject> 10 #include <QStringList> 11 12 #include "kgpgtransaction.h" 13 14 class QProcess; 15 16 /** 17 * @brief export one or more keys from keyring 18 * 19 * The exported keys can be written to a file or sent to standard input of another 20 * QProcess. 21 */ 22 class KGpgExport: public KGpgTransaction { 23 Q_OBJECT 24 25 KGpgExport(); // = delete C++0x 26 Q_DISABLE_COPY(KGpgExport) 27 public: 28 /** 29 * @brief export keys to QProcess 30 * @param parent parent object 31 * @param ids ids to export 32 * @param outp process to write into 33 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 34 * @param secret if secret key exporting is allowed 35 */ 36 KGpgExport(QObject *parent, const QStringList &ids, QProcess *outp, const QStringList &options = QStringList(), const bool secret = false); 37 38 /** 39 * @brief export keys to KGpgTransaction 40 * @param parent parent object 41 * @param ids ids to export 42 * @param outt transaction to write into 43 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 44 * @param secret if secret key exporting is allowed 45 */ 46 KGpgExport(QObject *parent, const QStringList &ids, KGpgTransaction *outt, const QStringList &options = QStringList(), const bool secret = false); 47 48 /** 49 * @brief export keys to file 50 * @param parent parent object 51 * @param ids ids to export 52 * @param file filename to write into 53 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 54 * @param secret if secret key exporting is allowed 55 */ 56 KGpgExport(QObject *parent, const QStringList &ids, const QString &file, const QStringList &options = QStringList(), const bool secret = false); 57 58 /** 59 * @brief export keys to standard output 60 * @param parent parent object 61 * @param ids ids to export 62 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 63 * @param secret if secret key exporting is allowed 64 * 65 * Only ascii-armored export is supported in standard output mode. If it is not 66 * already set in the given option it will be added automatically. 67 */ 68 KGpgExport(QObject *parent, const QStringList &ids, const QStringList &options = QStringList(), const bool secret = false); 69 70 /** 71 * @brief destructor 72 */ 73 ~KGpgExport() override; 74 75 /** 76 * @brief set key id to export 77 * @param id key fingerprint 78 */ 79 void setKeyId(const QString &id); 80 /** 81 * @brief set key ids to export 82 * @param ids key fingerprints 83 */ 84 void setKeyIds(const QStringList &ids); 85 /** 86 * @brief return the key ids to export 87 * @return list of key fingerprints 88 */ 89 const QStringList &getKeyIds() const; 90 /** 91 * @brief set the process the output is sent to 92 * @param outp process to send output to 93 */ 94 void setOutputProcess(QProcess *outp); 95 /** 96 * @brief set the transaction the output is sent to 97 * @param outt transaction to send output to 98 */ 99 void setOutputTransaction(KGpgTransaction *outt); 100 /** 101 * @brief set filename to send output to 102 * @param filename file to send output to 103 */ 104 void setOutputFile(const QString &filename); 105 /** 106 * @brief return the output filename currently set 107 * @return filename key will get written to 108 */ 109 const QString &getOutputFile() const; 110 /** 111 * @brief return the data read from standard output 112 * @return standard output data 113 */ 114 const QByteArray &getOutputData() const; 115 116 protected: 117 bool preStart() override; 118 bool nextLine(const QString &line) override; 119 120 private: 121 QStringList m_keyids; 122 QProcess *m_outp; 123 QString m_outf; 124 QByteArray m_data; 125 126 enum OutputMode { 127 ModeFile = 0, 128 ModeProcess = 1, 129 ModeStdout = 2, 130 ModeTransaction = 3 131 }; 132 enum OutputMode m_outputmode; 133 134 void procSetup(const QStringList &options, const bool secret); 135 }; 136 137 #endif // KGPGEXPORT_H 138