File indexing completed on 2024-04-28 05:50:18
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 #include "kgpgeditkeytransaction.h" 0007 0008 KGpgEditKeyTransaction::KGpgEditKeyTransaction(QObject *parent, const QString &keyid, 0009 const QString &command, const bool hasValue, const bool autoSave) 0010 : KGpgTransaction(parent), 0011 m_autosave(autoSave), 0012 m_keyid(keyid) 0013 { 0014 addArguments( { QLatin1String("--status-fd=1"), 0015 QLatin1String("--command-fd=0"), 0016 QLatin1String("--edit-key"), 0017 keyid 0018 } ); 0019 0020 m_cmdpos = addArgument(command); 0021 addArgumentRef(&m_cmdpos); 0022 0023 if (hasValue) { 0024 m_argpos = addArgument(QString()); 0025 addArgumentRef(&m_argpos); 0026 } else { 0027 m_argpos = -1; 0028 } 0029 0030 if (autoSave) 0031 addArgument(QLatin1String( "save" )); 0032 } 0033 0034 QString 0035 KGpgEditKeyTransaction::getKeyid() const 0036 { 0037 return m_keyid; 0038 } 0039 0040 bool 0041 KGpgEditKeyTransaction::preStart() 0042 { 0043 setSuccess(TS_MSG_SEQUENCE); 0044 0045 return true; 0046 } 0047 0048 bool 0049 KGpgEditKeyTransaction::nextLine(const QString &line) 0050 { 0051 if (line == QLatin1String("[GNUPG:] GOT_IT")) { 0052 setSuccess(TS_OK); 0053 return false; 0054 } else if (getSuccess() == TS_USER_ABORTED) { 0055 if (line.contains(QLatin1String( "GET_" ) )) 0056 return true; 0057 } else if ((getSuccess() == TS_OK) && line.contains(QLatin1String( "keyedit.prompt" ))) { 0058 return true; 0059 } else if (line.contains(QLatin1String( "NEED_PASSPHRASE" ))) { 0060 // nothing for now 0061 // we could use the id from NEED_PASSPHRASE as user id hint ... 0062 } else { 0063 if (getSuccess() != TS_BAD_PASSPHRASE) 0064 setSuccess(TS_MSG_SEQUENCE); 0065 return true; 0066 } 0067 0068 return false; 0069 } 0070 0071 KGpgTransaction::ts_boolanswer 0072 KGpgEditKeyTransaction::boolQuestion(const QString& line) 0073 { 0074 if ((getSuccess() == TS_OK) && (line == QLatin1String("keyedit.save.okay")) && !m_autosave) { 0075 return BA_YES; 0076 } else { 0077 return KGpgTransaction::boolQuestion(line); 0078 } 0079 } 0080 0081 void 0082 KGpgEditKeyTransaction::replaceValue(const QString &arg) 0083 { 0084 Q_ASSERT(m_argpos >= 0); 0085 0086 replaceArgument(m_argpos, arg); 0087 } 0088 0089 void 0090 KGpgEditKeyTransaction::replaceCommand(const QString &cmd) 0091 { 0092 replaceArgument(m_cmdpos, cmd); 0093 }