File indexing completed on 2024-04-21 05:50:43

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 "kgpgsendkeys.h"
0007 
0008 #include "gpgproc.h"
0009 
0010 KGpgSendKeys::KGpgSendKeys(QObject *parent, const QString &keyserver, const QStringList &keys, const QString &attropt, const bool withProgress, const QString &proxy)
0011     : KGpgKeyserverTransaction(parent, keyserver, withProgress, proxy)
0012 {
0013     addArgument(QLatin1String( "--export-options" ));
0014     m_attrpos = addArgument(QString());
0015     addArgument(QLatin1String( "--send-keys" ));
0016     setAttributeOptions(attropt);
0017     setKeyIds(keys);
0018 
0019     getProcess()->setOutputChannelMode(KProcess::MergedChannels);
0020 }
0021 
0022 bool
0023 KGpgSendKeys::preStart()
0024 {
0025     GPGProc *proc = getProcess();
0026     QStringList args(proc->program());
0027 
0028     int num = args.count();
0029     while (num > m_attrpos + 2)
0030         args.removeAt(--num);
0031 
0032     args << m_keys;
0033 
0034     proc->setProgram(args);
0035 
0036     setSuccess(TS_MSG_SEQUENCE);
0037 
0038     return KGpgKeyserverTransaction::preStart();
0039 }
0040 
0041 bool
0042 KGpgSendKeys::nextLine(const QString &line)
0043 {
0044     m_log.append(line);
0045     setSuccess(TS_OK);
0046 
0047     return false;
0048 }
0049 
0050 const QStringList &
0051 KGpgSendKeys::getLog() const
0052 {
0053     return m_log;
0054 }
0055 
0056 void
0057 KGpgSendKeys::setKeyIds(const QStringList &keys)
0058 {
0059     m_keys = keys;
0060 }
0061 
0062 void
0063 KGpgSendKeys::setAttributeOptions(const QString &opt)
0064 {
0065     if (opt.isEmpty())
0066         m_attributeopt = QLatin1String( "no-export-attributes" );
0067     else
0068         m_attributeopt = opt;
0069 
0070     replaceArgument(m_attrpos, m_attributeopt);
0071 }