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

« back to all changes in this revision

Viewing changes to kgpg/transactions/kgpgtextorfiletransaction.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) 2008,2009,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 "kgpgtextorfiletransaction.h"
 
15
 
 
16
#include <KIO/NetAccess>
 
17
#include <KLocale>
 
18
 
 
19
#include "gpgproc.h"
 
20
 
 
21
KGpgTextOrFileTransaction::KGpgTextOrFileTransaction(QObject *parent, const QString &text, const bool allowChaining)
 
22
        : KGpgTransaction(parent, allowChaining),
 
23
        m_text(text)
 
24
{
 
25
}
 
26
 
 
27
KGpgTextOrFileTransaction::KGpgTextOrFileTransaction(QObject *parent, const KUrl::List &files, const bool allowChaining)
 
28
        : KGpgTransaction(parent, allowChaining)
 
29
{
 
30
        setUrls(files);
 
31
}
 
32
 
 
33
KGpgTextOrFileTransaction::~KGpgTextOrFileTransaction()
 
34
{
 
35
        cleanUrls();
 
36
}
 
37
 
 
38
void
 
39
KGpgTextOrFileTransaction::setText(const QString &text)
 
40
{
 
41
        m_text = text;
 
42
        cleanUrls();
 
43
}
 
44
 
 
45
void
 
46
KGpgTextOrFileTransaction::setUrls(const KUrl::List &files)
 
47
{
 
48
        m_text.clear();
 
49
        m_inpfiles = files;
 
50
}
 
51
 
 
52
bool
 
53
KGpgTextOrFileTransaction::preStart()
 
54
{
 
55
        m_messages.clear();
 
56
 
 
57
        QStringList locfiles;
 
58
 
 
59
        foreach (const KUrl &url, m_inpfiles) {
 
60
                if (url.isLocalFile()) {
 
61
                        locfiles.append(url.toLocalFile());
 
62
                } else {
 
63
                        QString tmpfile;
 
64
 
 
65
                        if (KIO::NetAccess::download(url, tmpfile, 0)) {
 
66
                                m_tempfiles.append(tmpfile);
 
67
                        } else {
 
68
                                m_messages.append(KIO::NetAccess::lastErrorString());
 
69
                                cleanUrls();
 
70
                                setSuccess(TS_KIO_FAILED);
 
71
                                return false;
 
72
                        }
 
73
                }
 
74
        }
 
75
 
 
76
        if (m_tempfiles.isEmpty() && m_text.isEmpty() && !hasInputTransaction()) {
 
77
                setSuccess(TS_MSG_SEQUENCE);
 
78
                return false;
 
79
        }
 
80
 
 
81
        GPGProc *proc = getProcess();
 
82
        QStringList args(proc->program().at(0));
 
83
 
 
84
        args << "--status-fd=1" << command() << locfiles << m_tempfiles;
 
85
 
 
86
        proc->setProgram(args);
 
87
 
 
88
        return true;
 
89
}
 
90
 
 
91
void
 
92
KGpgTextOrFileTransaction::postStart()
 
93
{
 
94
        if (!m_text.isEmpty()){
 
95
                GPGProc *proc = getProcess();
 
96
                proc->write(m_text.toAscii());
 
97
                proc->closeWriteChannel();
 
98
        }
 
99
}
 
100
 
 
101
bool
 
102
KGpgTextOrFileTransaction::nextLine(const QString &line)
 
103
{
 
104
        if (!line.startsWith(QLatin1String("[GNUPG:] SIGEXPIRED")) && !line.startsWith(QLatin1String("[GNUPG:] KEYEXPIRED ")))
 
105
                m_messages.append(line);
 
106
 
 
107
        return false;
 
108
}
 
109
 
 
110
void
 
111
KGpgTextOrFileTransaction::finish()
 
112
{
 
113
}
 
114
 
 
115
const QStringList &
 
116
KGpgTextOrFileTransaction::getMessages() const
 
117
{
 
118
        return m_messages;
 
119
}
 
120
 
 
121
void
 
122
KGpgTextOrFileTransaction::cleanUrls()
 
123
{
 
124
        foreach (const QString &u, m_tempfiles)
 
125
                KIO::NetAccess::removeTempFile(u);
 
126
 
 
127
        m_tempfiles.clear();
 
128
        m_locfiles.clear();
 
129
        m_inpfiles.clear();
 
130
}