aboutsummaryrefslogtreecommitdiffstats
path: root/kgpg/transactions/kgpgtextorfiletransaction.h
blob: 46bf190c5754468dd8771bcb476d1c0cbb1ab92e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright (C) 2008,2009,2010 Rolf Eike Beer <[email protected]>
 */

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KGPGTEXTORFILETRANSACTION_H
#define KGPGTEXTORFILETRANSACTION_H

#include <QObject>
#include <QList>
#include <QString>
#include <QStringList>

#include <QUrl>

#include "kgpgtransaction.h"

/**
 * @brief feed a text or file through gpg
 */
class KGpgTextOrFileTransaction: public KGpgTransaction {
	Q_OBJECT

	Q_DISABLE_COPY(KGpgTextOrFileTransaction)

public:
	/**
	 * @brief additional status codes for KGpgImport
	 */
	enum ts_import {
		TS_KIO_FAILED = TS_COMMON_END + 1	///< download of remote file failed
	};

protected:
	/**
	 * @brief work with given text
	 * @param parent parent object
	 * @param text text to work with
	 */
	explicit KGpgTextOrFileTransaction(QObject *parent = 0, const QString &text = QString(), const bool allowChaining = false);

	/**
	 * @brief work with given file(s)
	 * @param parent parent object
	 * @param keys list of file locations to work with
	 */
    KGpgTextOrFileTransaction(QObject *parent, const QList<QUrl> &files, const bool allowChaining = false);

public:
	/**
	 * @brief destructor
	 */
	virtual ~KGpgTextOrFileTransaction();

	/**
	 * @brief set text to work with
	 * @param text text to work with
	 */
	void setText(const QString &text);
	/**
	 * @brief set file locations to work with
	 * @param keys list of file locations to work with
	 */
    void setUrls(const QList<QUrl> &files);

	/**
	 * @brief get gpg info message
	 * @return the raw messages from gpg during the operation
	 */
	const QStringList &getMessages() const;

protected:
	/**
	 * @brief construct the command line of the process
	 */
	virtual bool preStart();
	virtual bool nextLine(const QString &line);
	/**
	 * @brief implement special handling for GnuPG return codes
	 */
	virtual void finish();

	virtual QStringList command() const = 0;

    const QList<QUrl> &getInputFiles() const;

private:
	QStringList m_tempfiles;
	QStringList m_locfiles;
    QList<QUrl> m_inpfiles;
	QString m_text;
	QStringList m_messages;
	bool m_closeInput;	///< if input channel of GnuPG should be closed after m_text is written

	void cleanUrls();

private slots:
	void postStart();
};

#endif // KGPGTEXTORFILETRANSACTION_H