1 /*
2 SPDX-FileCopyrightText: 2009, 2012 Rolf Eike Beer <kde@opensource.sf-tec.de>
3 SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include "kgpgsendkeys.h"
7
8 #include "gpgproc.h"
9
KGpgSendKeys(QObject * parent,const QString & keyserver,const QStringList & keys,const QString & attropt,const bool withProgress,const QString & proxy)10 KGpgSendKeys::KGpgSendKeys(QObject *parent, const QString &keyserver, const QStringList &keys, const QString &attropt, const bool withProgress, const QString &proxy)
11 : KGpgKeyserverTransaction(parent, keyserver, withProgress, proxy)
12 {
13 addArgument(QLatin1String( "--export-options" ));
14 m_attrpos = addArgument(QString());
15 addArgument(QLatin1String( "--send-keys" ));
16 setAttributeOptions(attropt);
17 setKeyIds(keys);
18
19 getProcess()->setOutputChannelMode(KProcess::MergedChannels);
20 }
21
~KGpgSendKeys()22 KGpgSendKeys::~KGpgSendKeys()
23 {
24 }
25
26 bool
preStart()27 KGpgSendKeys::preStart()
28 {
29 GPGProc *proc = getProcess();
30 QStringList args(proc->program());
31
32 int num = args.count();
33 while (num > m_attrpos + 2)
34 args.removeAt(--num);
35
36 args << m_keys;
37
38 proc->setProgram(args);
39
40 setSuccess(TS_MSG_SEQUENCE);
41
42 return KGpgKeyserverTransaction::preStart();
43 }
44
45 bool
nextLine(const QString & line)46 KGpgSendKeys::nextLine(const QString &line)
47 {
48 m_log.append(line);
49 setSuccess(TS_OK);
50
51 return false;
52 }
53
54 const QStringList &
getLog() const55 KGpgSendKeys::getLog() const
56 {
57 return m_log;
58 }
59
60 void
setKeyIds(const QStringList & keys)61 KGpgSendKeys::setKeyIds(const QStringList &keys)
62 {
63 m_keys = keys;
64 }
65
66 void
setAttributeOptions(const QString & opt)67 KGpgSendKeys::setAttributeOptions(const QString &opt)
68 {
69 if (opt.isEmpty())
70 m_attributeopt = QLatin1String( "no-export-attributes" );
71 else
72 m_attributeopt = opt;
73
74 replaceArgument(m_attrpos, m_attributeopt);
75 }
76