File indexing completed on 2023-09-24 06:06:29
0001 /* 0002 SPDX-FileCopyrightText: 2009-2022 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KGPGEDITKEYTRANSACTION_H 0007 #define KGPGEDITKEYTRANSACTION_H 0008 0009 #include <QObject> 0010 0011 #include "kgpgtransaction.h" 0012 0013 /** 0014 * @brief edit a single property of a key 0015 */ 0016 class KGpgEditKeyTransaction: public KGpgTransaction { 0017 Q_OBJECT 0018 0019 Q_DISABLE_COPY(KGpgEditKeyTransaction) 0020 KGpgEditKeyTransaction() = delete; 0021 0022 protected: 0023 /** 0024 * @brief constructor 0025 * @param parent parent object 0026 * @param keyid key to edit 0027 * @param command GnuPG command to use 0028 * @param hasValue if the command takes an extra argument 0029 * @param autoSave if a "save" command should be sent to GnuPG immediately 0030 */ 0031 KGpgEditKeyTransaction(QObject *parent, const QString &keyid, const QString &command, const bool hasValue, const bool autoSave = true); 0032 0033 public: 0034 /** 0035 * @brief destructor 0036 */ 0037 ~KGpgEditKeyTransaction() override = default; 0038 0039 /** 0040 * @brief return the id of the key we are editing 0041 */ 0042 QString getKeyid() const; 0043 0044 protected: 0045 /** 0046 * @brief reset class before next operation starts 0047 * 0048 * If you inherit from this class make sure this method is called 0049 * from your inherited method before you do anything else there. 0050 */ 0051 bool preStart() override; 0052 0053 /** 0054 * @brief handle standard GnuPG prompts 0055 * @param line the line to handle 0056 * 0057 * By default this handles passphrase questions and quits the 0058 * operation when GnuPG returns to it's command prompt. The 0059 * "GOOD_PASSPHRASE" line is _not_ handled here. When you inherit 0060 * this class and need to handle specific line do them first and 0061 * then call this method at the end of your method to handle all 0062 * standard things (if you don't want to handle them yourself). 0063 * Every line sent here by GnuPG not recognised as command handled 0064 * here will set a sequence error so be sure to handle your stuff first! 0065 */ 0066 bool nextLine(const QString &line) override; 0067 0068 ts_boolanswer boolQuestion(const QString &line) override; 0069 0070 /** 0071 * @brief replace the argument of the edit command 0072 * @param arg new argument 0073 * 0074 * Calling this function when the hasValue parameter of the constructor was false is an error. 0075 */ 0076 void replaceValue(const QString &arg); 0077 0078 /** 0079 * @brief replace the command 0080 * @param cmd new command 0081 * 0082 * This is seldomly needed, only when a command has different names 0083 * for positive or negative action instead of taking that as argument. 0084 */ 0085 void replaceCommand(const QString &cmd); 0086 0087 private: 0088 int m_cmdpos; ///< position of the command thas is passed to the edit command 0089 int m_argpos; ///< position of the argument that is passed to the edit command 0090 const bool m_autosave; ///< if autosave was requested in constructor 0091 const QString m_keyid; ///< id of the key we are editing 0092 }; 0093 0094 #endif // KGPGEDITKEYTRANSACTION_H