• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
  • transactions
kgpgexport.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009,2012 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 "kgpgexport.h"
15 
16 #include "gpgproc.h"
17 
18 #include <QFile>
19 #include <QProcess>
20 
21 KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, QProcess *outp, const QStringList &options, const bool secret)
22  : KGpgTransaction(parent),
23  m_keyids(ids),
24  m_outp(outp),
25  m_outputmode(ModeProcess)
26 {
27  procSetup(options, secret);
28 }
29 
30 KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, const QString &file, const QStringList &options, const bool secret)
31  : KGpgTransaction(parent),
32  m_keyids(ids),
33  m_outp(NULL),
34  m_outf(file),
35  m_outputmode(ModeFile)
36 {
37  procSetup(options, secret);
38 }
39 
40 KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, const QStringList &options, const bool secret)
41  : KGpgTransaction(parent),
42  m_keyids(ids),
43  m_outp(NULL),
44  m_outputmode(ModeStdout)
45 {
46  procSetup(options, secret);
47 }
48 
49 KGpgExport::KGpgExport(QObject *parent, const QStringList &ids, KGpgTransaction *outt, const QStringList &options, const bool secret)
50  : KGpgTransaction(parent),
51  m_keyids(ids),
52  m_outp(NULL),
53  m_outputmode(ModeTransaction)
54 {
55  procSetup(options, secret);
56  outt->setInputTransaction(this);
57 }
58 
59 KGpgExport::~KGpgExport()
60 {
61 }
62 
63 void
64 KGpgExport::setKeyId(const QString &id)
65 {
66  m_keyids.clear();
67  m_keyids.append(id);
68 }
69 
70 void
71 KGpgExport::setKeyIds(const QStringList &ids)
72 {
73  m_keyids = ids;
74 }
75 
76 const QStringList &
77 KGpgExport::getKeyIds() const
78 {
79  return m_keyids;
80 }
81 
82 void
83 KGpgExport::setOutputProcess(QProcess *outp)
84 {
85  m_outf.clear();
86  m_outp = outp;
87  m_outputmode = ModeProcess;
88 }
89 
90 void
91 KGpgExport::setOutputFile(const QString &filename)
92 {
93  m_outp = NULL;
94  m_outf = filename;
95  if (filename.isEmpty())
96  m_outputmode = ModeStdout;
97  else
98  m_outputmode = ModeFile;
99 }
100 
101 void
102 KGpgExport::setOutputTransaction(KGpgTransaction *outt)
103 {
104  m_outp = NULL;
105  m_outf.clear();
106  m_outputmode = ModeTransaction;
107  outt->setInputTransaction(this);
108 }
109 
110 const QString &
111 KGpgExport::getOutputFile() const
112 {
113  return m_outf;
114 }
115 
116 const QByteArray &
117 KGpgExport::getOutputData() const
118 {
119  return m_data;
120 }
121 
122 bool
123 KGpgExport::preStart()
124 {
125  setSuccess(TS_OK);
126 
127  switch (m_outputmode) {
128  case ModeFile:
129  {
130  Q_ASSERT(!m_outf.isEmpty());
131  Q_ASSERT(m_outp == NULL);
132 
133  addArgument(QLatin1String( "--output" ));
134  addArgument(m_outf);
135 
136  QFile ofile(m_outf);
137  if (ofile.exists())
138  ofile.remove();
139 
140  break;
141  }
142  case ModeProcess:
143  Q_ASSERT(m_outf.isEmpty());
144  Q_ASSERT(m_outp != NULL);
145 
146  getProcess()->setStandardOutputProcess(m_outp);
147 
148  break;
149  case ModeStdout:
150  Q_ASSERT(m_outf.isEmpty());
151  Q_ASSERT(m_outp == NULL);
152  break;
153  case ModeTransaction:
154  Q_ASSERT(m_outf.isEmpty());
155  Q_ASSERT(m_outp == NULL);
156  break;
157  default:
158  Q_ASSERT(0);
159  }
160 
161  addArguments(m_keyids);
162 
163  m_data.clear();
164 
165  return true;
166 }
167 
168 bool
169 KGpgExport::nextLine(const QString &line)
170 {
171  // key exporting does not send any messages
172 
173  m_data.append(line.toAscii() + '\n');
174 
175  if (m_outputmode != 2)
176  setSuccess(TS_MSG_SEQUENCE);
177 
178  return false;
179 }
180 
181 void
182 KGpgExport::procSetup(const QStringList &options, const bool secret)
183 {
184  getProcess()->resetProcess();
185 
186  if (secret)
187  addArgument(QLatin1String( "--export-secret-key" ));
188  else
189  addArgument(QLatin1String( "--export" ));
190 
191  if ((m_outputmode == 2) && !options.contains(QLatin1String( "--armor" )))
192  addArgument(QLatin1String( "--armor" ));
193 
194  addArguments(options);
195 }
196 
197 #include "kgpgexport.moc"
QList::clear
void clear()
KGpgExport::setKeyId
void setKeyId(const QString &id)
set key id to export
Definition: kgpgexport.cpp:64
KGpgExport::getKeyIds
const QStringList & getKeyIds() const
return the key ids to export
Definition: kgpgexport.cpp:77
QByteArray::clear
void clear()
KGpgTransaction::addArgument
int addArgument(const QString &arg)
add a command line argument to gpg process
Definition: kgpgtransaction.cpp:562
KGpgTransaction::addArguments
int addArguments(const QStringList &args)
add command line arguments to gpg process
Definition: kgpgtransaction.cpp:572
KGpgTransaction::TS_OK
everything went fine
Definition: kgpgtransaction.h:60
KGpgExport::getOutputData
const QByteArray & getOutputData() const
return the data read from standard output
Definition: kgpgexport.cpp:117
QByteArray
KGpgExport::getOutputFile
const QString & getOutputFile() const
return the output filename currently set
Definition: kgpgexport.cpp:111
QFile::remove
bool remove()
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KGpgExport::nextLine
virtual bool nextLine(const QString &line)
Called for every line the gpg process writes.
Definition: kgpgexport.cpp:169
QFile::exists
bool exists() const
KGpgTransaction::setInputTransaction
void setInputTransaction(KGpgTransaction *ta)
connect the standard input of this transaction to another process
Definition: kgpgtransaction.cpp:709
QFile
KGpgTransaction::getProcess
GPGProc * getProcess()
get a reference to the gpg process object
Definition: kgpgtransaction.cpp:556
QString::clear
void clear()
QList::append
void append(const T &value)
KGpgExport::~KGpgExport
virtual ~KGpgExport()
destructor
Definition: kgpgexport.cpp:59
QProcess
QObject
KGpgExport::setOutputFile
void setOutputFile(const QString &filename)
set filename to send output to
Definition: kgpgexport.cpp:91
QString::isEmpty
bool isEmpty() const
KGpgExport::preStart
virtual bool preStart()
Called before the gpg process is started.
Definition: kgpgexport.cpp:123
gpgproc.h
KGpgExport::setKeyIds
void setKeyIds(const QStringList &ids)
set key ids to export
Definition: kgpgexport.cpp:71
QString
KGpgTransaction::TS_MSG_SEQUENCE
unexpected sequence of GnuPG messages
Definition: kgpgtransaction.h:62
kgpgexport.h
QStringList
QByteArray::append
QByteArray & append(char ch)
GPGProc::resetProcess
void resetProcess(const QString &binary=QString())
Reset the class to the state it had right after creation.
Definition: gpgproc.cpp:165
QLatin1String
KGpgTransaction::setSuccess
void setSuccess(const int v)
set the success value that will be returned with the done signal
Definition: kgpgtransaction.cpp:448
KGpgExport::setOutputTransaction
void setOutputTransaction(KGpgTransaction *outt)
set the transaction the output is sent to
Definition: kgpgexport.cpp:102
KGpgTransaction
Process one GnuPG operation.
Definition: kgpgtransaction.h:44
QObject::parent
QObject * parent() const
KGpgExport::setOutputProcess
void setOutputProcess(QProcess *outp)
set the process the output is sent to
Definition: kgpgexport.cpp:83
QString::toAscii
QByteArray toAscii() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal