2
* Copyright (C) 2010 Rolf Eike Beer <kde@opensource.sf-tec.de>
5
/***************************************************************************
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
12
***************************************************************************/
14
#include "kgpggeneraterevoke.h"
18
#include <QtCore/QFile>
20
KGpgGenerateRevoke::KGpgGenerateRevoke(QObject *parent, const QString &keyID, const KUrl &revokeUrl, const int reason, const QString &description)
21
: KGpgTransaction(parent),
25
m_description(description)
27
addArgument("--status-fd=1");
28
addArgument("--command-fd=0");
29
addArgument("--no-verbose");
30
addArgument("--no-greeting");
32
if (!revokeUrl.isEmpty()) {
34
addArgument(revokeUrl.toLocalFile());
36
addArgument("--gen-revoke");
40
KGpgGenerateRevoke::~KGpgGenerateRevoke()
45
KGpgGenerateRevoke::preStart()
47
setSuccess(TS_MSG_SEQUENCE);
49
setDescription(i18n("Generating Revocation Certificate for key %1", m_keyid));
55
KGpgGenerateRevoke::nextLine(const QString &line)
57
if (!line.startsWith(QLatin1String("[GNUPG:] "))) {
58
m_output.append(line + '\n');
62
if (line.contains("GOOD_PASSPHRASE")) {
64
} else if (line.contains("passphrase.enter")) {
65
if (!askPassphrase()) {
66
setSuccess(TS_USER_ABORTED);
69
} else if (line.contains("NEED_PASSPHRASE")) {
70
setSuccess(TS_USER_ABORTED);
71
} else if (line.contains("ask_revocation_reason.code")) {
72
write(QByteArray::number(m_reason));
73
} else if (line.contains("ask_revocation_reason.text")) {
74
write(m_description.toUtf8());
75
// GnuPG stops asking if we pass an empty line
76
m_description.clear();
77
} else if (line.contains("GET_")) {
78
setSuccess(TS_MSG_SEQUENCE);
86
KGpgTransaction::ts_boolanswer
87
KGpgGenerateRevoke::boolQuestion(const QString& line)
89
if (line == QLatin1String("gen_revoke.okay")) {
91
} else if (line == QLatin1String("ask_revocation_reason.okay")) {
93
} else if (line == QLatin1String("openfile.overwrite.okay")) {
96
return KGpgTransaction::boolQuestion(line);
101
KGpgGenerateRevoke::finish()
103
if (getSuccess() == TS_OK) {
104
if (!m_revUrl.isEmpty()) {
105
QFile of(m_revUrl.toLocalFile());
106
if (of.open(QIODevice::ReadOnly)) {
107
m_output = of.readAll();
111
emit revokeCertificate(m_output);
116
KGpgGenerateRevoke::getOutput() const