File indexing completed on 2024-04-21 05:50:43
0001 /* 0002 SPDX-FileCopyrightText: 2008, 2009, 2010 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KGPGTEXTORFILETRANSACTION_H 0007 #define KGPGTEXTORFILETRANSACTION_H 0008 0009 #include <QObject> 0010 #include <QString> 0011 #include <QStringList> 0012 0013 #include <QUrl> 0014 0015 #include "kgpgtransaction.h" 0016 0017 /** 0018 * @brief feed a text or file through gpg 0019 */ 0020 class KGpgTextOrFileTransaction: public KGpgTransaction { 0021 Q_OBJECT 0022 0023 Q_DISABLE_COPY(KGpgTextOrFileTransaction) 0024 0025 public: 0026 /** 0027 * @brief additional status codes for KGpgImport 0028 */ 0029 enum ts_import { 0030 TS_KIO_FAILED = TS_COMMON_END + 1 ///< download of remote file failed 0031 }; 0032 0033 protected: 0034 /** 0035 * @brief work with given text 0036 * @param parent parent object 0037 * @param text text to work with 0038 * @param allowChaining whether to allow chaining 0039 */ 0040 explicit KGpgTextOrFileTransaction(QObject *parent = nullptr, const QString &text = QString(), const bool allowChaining = false); 0041 0042 /** 0043 * @brief work with given file(s) 0044 * @param parent parent object 0045 * @param files list of file locations to work with 0046 * @param allowChaining whether to allow chaining 0047 */ 0048 KGpgTextOrFileTransaction(QObject *parent, const QList<QUrl> &files, const bool allowChaining = false); 0049 0050 public: 0051 /** 0052 * @brief destructor 0053 */ 0054 ~KGpgTextOrFileTransaction() override; 0055 0056 /** 0057 * @brief set text to work with 0058 * @param text text to work with 0059 */ 0060 void setText(const QString &text); 0061 /** 0062 * @brief set file locations to work with 0063 * @param files list of file locations to work with 0064 */ 0065 void setUrls(const QList<QUrl> &files); 0066 0067 /** 0068 * @brief get gpg info message 0069 * @return the raw messages from gpg during the operation 0070 */ 0071 const QStringList &getMessages() const; 0072 0073 protected: 0074 /** 0075 * @brief construct the command line of the process 0076 */ 0077 bool preStart() override; 0078 bool nextLine(const QString &line) override; 0079 /** 0080 * @brief implement special handling for GnuPG return codes 0081 */ 0082 void finish() override; 0083 0084 virtual QStringList command() const = 0; 0085 0086 const QList<QUrl> &getInputFiles() const; 0087 0088 /** 0089 * @brief if the input channel of GnuPG should be closed when text is written 0090 * 0091 * This only has an effect in text mode (i.e. without urls). 0092 * 0093 * If not given the input channel is closed when "--command-fd" is not used. 0094 */ 0095 virtual bool closeInputAfterText() const 0096 { 0097 return false; 0098 } 0099 0100 private: 0101 QStringList m_tempfiles; 0102 QStringList m_locfiles; 0103 QList<QUrl> m_inpfiles; 0104 QString m_text; 0105 QStringList m_messages; 0106 bool m_closeInput = false; ///< if input channel of GnuPG should be closed after m_text is written 0107 0108 void cleanUrls(); 0109 0110 private Q_SLOTS: 0111 void postStart() override; 0112 }; 0113 0114 #endif // KGPGTEXTORFILETRANSACTION_H