aboutsummaryrefslogtreecommitdiffstats
path: root/kgpg/transactions/kgpgexport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kgpg/transactions/kgpgexport.cpp')
-rw-r--r--kgpg/transactions/kgpgexport.cpp197
1 files changed, 197 insertions, 0 deletions
diff --git a/kgpg/transactions/kgpgexport.cpp b/kgpg/transactions/kgpgexport.cpp
new file mode 100644
index 0000000..79f6afe
--- /dev/null
+++ b/kgpg/transactions/kgpgexport.cpp
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2009,2012 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. *
+ * *
+ ***************************************************************************/
+
+#include "kgpgexport.h"
+
+#include "../gpgproc.h"
+
+#include <QFile>
+#include <QProcess>
+
+KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, QProcess *outp, const QStringList &options, const bool secret)
+ : KGpgTransaction(parent),
+ m_keyids(ids),
+ m_outp(outp),
+ m_outputmode(ModeProcess)
+{
+ procSetup(options, secret);
+}
+
+KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, const QString &file, const QStringList &options, const bool secret)
+ : KGpgTransaction(parent),
+ m_keyids(ids),
+ m_outp(NULL),
+ m_outf(file),
+ m_outputmode(ModeFile)
+{
+ procSetup(options, secret);
+}
+
+KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, const QStringList &options, const bool secret)
+ : KGpgTransaction(parent),
+ m_keyids(ids),
+ m_outp(NULL),
+ m_outputmode(ModeStdout)
+{
+ procSetup(options, secret);
+}
+
+KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, KGpgTransaction *outt, const QStringList &options, const bool secret)
+ : KGpgTransaction(parent),
+ m_keyids(ids),
+ m_outp(NULL),
+ m_outputmode(ModeTransaction)
+{
+ procSetup(options, secret);
+ outt->setInputTransaction(this);
+}
+
+KGpgExport::~KGpgExport()
+{
+}
+
+void
+KGpgExport::setKeyId(const QString &id)
+{
+ m_keyids.clear();
+ m_keyids.append(id);
+}
+
+void
+KGpgExport::setKeyIds(const QStringList &ids)
+{
+ m_keyids = ids;
+}
+
+const QStringList &
+KGpgExport::getKeyIds() const
+{
+ return m_keyids;
+}
+
+void
+KGpgExport::setOutputProcess(QProcess *outp)
+{
+ m_outf.clear();
+ m_outp = outp;
+ m_outputmode = ModeProcess;
+}
+
+void
+KGpgExport::setOutputFile(const QString &filename)
+{
+ m_outp = NULL;
+ m_outf = filename;
+ if (filename.isEmpty())
+ m_outputmode = ModeStdout;
+ else
+ m_outputmode = ModeFile;
+}
+
+void
+KGpgExport::setOutputTransaction(KGpgTransaction *outt)
+{
+ m_outp = NULL;
+ m_outf.clear();
+ m_outputmode = ModeTransaction;
+ outt->setInputTransaction(this);
+}
+
+const QString &
+KGpgExport::getOutputFile() const
+{
+ return m_outf;
+}
+
+const QByteArray &
+KGpgExport::getOutputData() const
+{
+ return m_data;
+}
+
+bool
+KGpgExport::preStart()
+{
+ setSuccess(TS_OK);
+
+ switch (m_outputmode) {
+ case ModeFile:
+ {
+ Q_ASSERT(!m_outf.isEmpty());
+ Q_ASSERT(m_outp == NULL);
+
+ addArgument(QLatin1String( "--output" ));
+ addArgument(m_outf);
+
+ QFile ofile(m_outf);
+ if (ofile.exists())
+ ofile.remove();
+
+ break;
+ }
+ case ModeProcess:
+ Q_ASSERT(m_outf.isEmpty());
+ Q_ASSERT(m_outp != NULL);
+
+ getProcess()->setStandardOutputProcess(m_outp);
+
+ break;
+ case ModeStdout:
+ Q_ASSERT(m_outf.isEmpty());
+ Q_ASSERT(m_outp == NULL);
+ break;
+ case ModeTransaction:
+ Q_ASSERT(m_outf.isEmpty());
+ Q_ASSERT(m_outp == NULL);
+ break;
+ default:
+ Q_ASSERT(0);
+ }
+
+ addArguments(m_keyids);
+
+ m_data.clear();
+
+ return true;
+}
+
+bool
+KGpgExport::nextLine(const QString &line)
+{
+ // key exporting does not send any messages
+
+ m_data.append(line.toAscii() + '\n');
+
+ if (m_outputmode != 2)
+ setSuccess(TS_MSG_SEQUENCE);
+
+ return false;
+}
+
+void
+KGpgExport::procSetup(const QStringList &options, const bool secret)
+{
+ getProcess()->resetProcess();
+
+ if (secret)
+ addArgument(QLatin1String( "--export-secret-key" ));
+ else
+ addArgument(QLatin1String( "--export" ));
+
+ if ((m_outputmode == 2) && !options.contains(QLatin1String( "--armor" )))
+ addArgument(QLatin1String( "--armor" ));
+
+ addArguments(options);
+}
+
+//#include "kgpgexport.moc"