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

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • backends
  • qgpgme
qgpgmesecretkeyexportjob.cpp
Go to the documentation of this file.
1 /*
2  qgpgmesecretexportjob.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klar�vdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include "qgpgmesecretkeyexportjob.h"
34 
35 #include "gnupgprocessbase.h"
36 #include "qgpgmeprogresstokenmapper.h"
37 
38 #include <kdebug.h>
39 
40 #include <gpgme++/context.h>
41 #include <gpgme++/data.h>
42 
43 #include <QStringList>
44 
45 #include <gpg-error.h>
46 
47 #include <string.h>
48 #include <assert.h>
49 
50 Kleo::QGpgMESecretKeyExportJob::QGpgMESecretKeyExportJob( bool armour, const QString& charset )
51  : ExportJob( 0 ),
52  mProcess( 0 ),
53  mError( 0 ),
54  mArmour( armour ),
55  mCharset( charset )
56 {
57 
58 }
59 
60 Kleo::QGpgMESecretKeyExportJob::~QGpgMESecretKeyExportJob() {
61 
62 }
63 
64 GpgME::Error Kleo::QGpgMESecretKeyExportJob::start( const QStringList & patterns ) {
65  assert( mKeyData.isEmpty() );
66 
67  if ( patterns.size() != 1 || patterns.front().isEmpty() ) {
68  deleteLater();
69  return mError = GpgME::Error::fromCode( GPG_ERR_INV_VALUE, GPG_ERR_SOURCE_GPGSM );
70  }
71 
72  // create and start gpgsm process:
73  mProcess = new GnuPGProcessBase( this );
74  mProcess->setObjectName( QLatin1String("gpgsm --export-secret-key-p12") );
75 
76  // FIXME: obtain the path to gpgsm from gpgme, so we use the same instance.
77  *mProcess << QLatin1String("gpgsm") << QLatin1String("--export-secret-key-p12");
78  if ( mArmour )
79  *mProcess << QLatin1String("--armor");
80  if ( !mCharset.isEmpty() )
81  *mProcess << QLatin1String("--p12-charset") << mCharset;
82  *mProcess << QLatin1String(patterns.front().toUtf8());
83 
84  mProcess->setUseStatusFD( true );
85 
86  connect( mProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
87  SLOT(slotProcessExited(int,QProcess::ExitStatus)) );
88  connect( mProcess, SIGNAL(readyReadStandardOutput()),
89  SLOT(slotStdout()) );
90  connect( mProcess, SIGNAL(readyReadStandardError()),
91  SLOT(slotStderr()) );
92 
93  connect( mProcess, SIGNAL(status(Kleo::GnuPGProcessBase*,QString,QStringList)),
94  SLOT(slotStatus(Kleo::GnuPGProcessBase*,QString,QStringList)) );
95 
96  mProcess->setOutputChannelMode( KProcess::SeparateChannels );
97  mProcess->start();
98  if ( !mProcess->waitForStarted() ) {
99  mError = GpgME::Error::fromCode( GPG_ERR_ENOENT, GPG_ERR_SOURCE_GPGSM ); // what else?
100  deleteLater();
101  return mError;
102  } else
103  return GpgME::Error();
104 }
105 
106 void Kleo::QGpgMESecretKeyExportJob::slotCancel() {
107  if ( mProcess )
108  mProcess->kill();
109  mProcess = 0;
110  mError = GpgME::Error::fromCode( GPG_ERR_CANCELED, GPG_ERR_SOURCE_GPGSM );
111 }
112 
113 void Kleo::QGpgMESecretKeyExportJob::slotStatus( GnuPGProcessBase * proc, const QString & type, const QStringList & args ) {
114  if ( proc != mProcess )
115  return;
116  QStringList::const_iterator it = args.begin();
117  bool ok = false;
118 
119  if ( type == QLatin1String("ERROR") ) {
120 
121 
122  if ( args.size() < 2 ) {
123  kDebug( 5150 ) <<"Kleo::QGpgMESecretKeyExportJob::slotStatus() not recognising ERROR with < 2 args!";
124  return;
125  }
126  const int source = (*++it).toInt( &ok );
127  if ( !ok ) {
128  kDebug( 5150 ) <<"Kleo::QGpgMESecretKeyExportJob::slotStatus() expected number for first ERROR arg, got something else";
129  return;
130  }
131  ok = false;
132  const int code = (*++it).toInt( &ok );
133  if ( !ok ) {
134  kDebug( 5150 ) <<"expected number for second ERROR arg, got something else";
135  return;
136  }
137  mError = GpgME::Error::fromCode( code, source );
138 
139 
140  } else if ( type == QLatin1String("PROGRESS") ) {
141 
142 
143  if ( args.size() < 4 ) {
144  kDebug( 5150 ) <<"not recognising PROGRESS with < 4 args!";
145  return;
146  }
147  const QString what = *++it;
148  ok = false;
149  const int typ = (*++it).toInt( &ok );
150  if ( !ok ) {
151  kDebug( 5150 ) << "expected number for \"type\", got something else";
152  return;
153  }
154  ok = false;
155  const int cur = (*++it).toInt( &ok );
156  if ( !ok ) {
157  kDebug( 5150 ) <<"expected number for \"cur\", got something else";
158  return;
159  }
160  ok = false;
161  const int total = (*++it).toInt( &ok );
162  if ( !ok ) {
163  kDebug( 5150 ) <<"expected number for \"total\", got something else";
164  return;
165  }
166  emit progress( QGpgMEProgressTokenMapper::map( what, typ ), cur, total );
167 
168  }
169 }
170 
171 void Kleo::QGpgMESecretKeyExportJob::slotStdout() {
172  QString line = QString::fromLocal8Bit( mProcess->readLine() );
173  if ( !line.isEmpty() )
174  return;
175  const unsigned int oldlen = mKeyData.size();
176  mKeyData.resize( oldlen + line.length() );
177  memcpy( mKeyData.data() + oldlen, line.toLatin1(), line.length() );
178 }
179 
180 void Kleo::QGpgMESecretKeyExportJob::slotStderr() {
181  // implement? or not?
182 }
183 
184 void Kleo::QGpgMESecretKeyExportJob::slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus) {
185  emit done();
186  if ( !mError &&
187  ( exitStatus != QProcess::NormalExit || exitCode != 0 ) )
188  mError = GpgME::Error::fromCode( GPG_ERR_GENERAL, GPG_ERR_SOURCE_GPGSM );
189  emit result( mError, mKeyData );
190  deleteLater();
191 }
192 
193 #include "qgpgmesecretkeyexportjob.moc"
source
const char * source
Definition: keylistview.cpp:69
QString
Kleo::QGpgMESecretKeyExportJob::start
GpgME::Error start(const QStringList &patterns)
Definition: qgpgmesecretkeyexportjob.cpp:64
Kleo::QGpgMEProgressTokenMapper::map
QString map(const char *token, int subtoken)
Definition: qgpgmeprogresstokenmapper.cpp:91
gnupgprocessbase.h
qgpgmeprogresstokenmapper.h
Kleo::QGpgMESecretKeyExportJob::QGpgMESecretKeyExportJob
QGpgMESecretKeyExportJob(bool armour, const QString &charset)
Definition: qgpgmesecretkeyexportjob.cpp:50
Kleo::ExportJob
An abstract base class for asynchronous exporters.
Definition: exportjob.h:61
Kleo::QGpgMESecretKeyExportJob::~QGpgMESecretKeyExportJob
~QGpgMESecretKeyExportJob()
Definition: qgpgmesecretkeyexportjob.cpp:60
Kleo::GnuPGProcessBase
a base class for GPG and GPGSM processes.
Definition: gnupgprocessbase.h:49
qgpgmesecretkeyexportjob.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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