~ubuntu-branches/ubuntu/maverick/kdeutils/maverick-proposed

« back to all changes in this revision

Viewing changes to kgpg/transactions/kgpggeneraterevoke.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-05-28 09:49:30 UTC
  • mfrom: (1.2.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20100528094930-jzynf0obv1n2v13a
Tags: 4:4.4.80-0ubuntu1~ppa1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Rolf Eike Beer <kde@opensource.sf-tec.de>
 
3
 */
 
4
 
 
5
/***************************************************************************
 
6
 *                                                                         *
 
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.                                   *
 
11
 *                                                                         *
 
12
 ***************************************************************************/
 
13
 
 
14
#include "kgpggeneraterevoke.h"
 
15
 
 
16
#include <KDebug>
 
17
#include <KLocale>
 
18
#include <QtCore/QFile>
 
19
 
 
20
KGpgGenerateRevoke::KGpgGenerateRevoke(QObject *parent, const QString &keyID, const KUrl &revokeUrl, const int reason, const QString &description)
 
21
        : KGpgTransaction(parent),
 
22
        m_keyid(keyID),
 
23
        m_revUrl(revokeUrl),
 
24
        m_reason(reason),
 
25
        m_description(description)
 
26
{
 
27
        addArgument("--status-fd=1");
 
28
        addArgument("--command-fd=0");
 
29
        addArgument("--no-verbose");
 
30
        addArgument("--no-greeting");
 
31
 
 
32
        if (!revokeUrl.isEmpty()) {
 
33
                addArgument("-o");
 
34
                addArgument(revokeUrl.toLocalFile());
 
35
        }
 
36
        addArgument("--gen-revoke");
 
37
        addArgument(keyID);
 
38
}
 
39
 
 
40
KGpgGenerateRevoke::~KGpgGenerateRevoke()
 
41
{
 
42
}
 
43
 
 
44
bool
 
45
KGpgGenerateRevoke::preStart()
 
46
{
 
47
        setSuccess(TS_MSG_SEQUENCE);
 
48
 
 
49
        setDescription(i18n("Generating Revocation Certificate for key %1", m_keyid));
 
50
 
 
51
        return true;
 
52
}
 
53
 
 
54
bool
 
55
KGpgGenerateRevoke::nextLine(const QString &line)
 
56
{
 
57
        if (!line.startsWith(QLatin1String("[GNUPG:] "))) {
 
58
                m_output.append(line + '\n');
 
59
                return false;
 
60
        }
 
61
 
 
62
        if (line.contains("GOOD_PASSPHRASE")) {
 
63
                setSuccess(TS_OK);
 
64
        } else if (line.contains("passphrase.enter")) {
 
65
                if (!askPassphrase()) {
 
66
                        setSuccess(TS_USER_ABORTED);
 
67
                        return true;
 
68
                }
 
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);
 
79
                kDebug(2100) << line;
 
80
                return true;
 
81
        }
 
82
 
 
83
        return false;
 
84
}
 
85
 
 
86
KGpgTransaction::ts_boolanswer
 
87
KGpgGenerateRevoke::boolQuestion(const QString& line)
 
88
{
 
89
        if (line == QLatin1String("gen_revoke.okay")) {
 
90
                return BA_YES;
 
91
        } else if (line == QLatin1String("ask_revocation_reason.okay")) {
 
92
                return BA_YES;
 
93
        } else if (line == QLatin1String("openfile.overwrite.okay")) {
 
94
                return BA_YES;
 
95
        } else {
 
96
                return KGpgTransaction::boolQuestion(line);
 
97
        }
 
98
}
 
99
 
 
100
void
 
101
KGpgGenerateRevoke::finish()
 
102
{
 
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();
 
108
                                of.close();
 
109
                        }
 
110
                }
 
111
                emit revokeCertificate(m_output);
 
112
        }
 
113
}
 
114
 
 
115
const QString &
 
116
KGpgGenerateRevoke::getOutput() const
 
117
{
 
118
        return m_output;
 
119
}