37 #include "qgpgmesecretkeyexportjob.h"
39 #include "gnupgprocessbase.h"
40 #include "qgpgmeprogresstokenmapper.h"
44 #include <gpgmepp/context.h>
45 #include <gpgmepp/data.h>
47 #include <qgpgme/eventloopinteractor.h>
49 #include <tqstringlist.h>
51 #include <gpg-error.h>
56 Kleo::QGpgMESecretKeyExportJob::QGpgMESecretKeyExportJob(
bool armour,
const TQString& charset )
57 : ExportJob( QGpgME::EventLoopInteractor::instance(),
"Kleo::QGpgMESecretKeyExportJob" ),
66 Kleo::QGpgMESecretKeyExportJob::~QGpgMESecretKeyExportJob() {
70 GpgME::Error Kleo::QGpgMESecretKeyExportJob::start(
const TQStringList & patterns ) {
71 assert( mKeyData.isEmpty() );
73 if ( patterns.size() != 1 || patterns.front().isEmpty() ) {
75 return mError = gpg_err_make( GPG_ERR_SOURCE_GPGSM, GPG_ERR_INV_VALUE );
79 mProcess =
new GnuPGProcessBase(
this,
"gpgsm --export-secret-key-p12" );
82 *mProcess <<
"gpgsm" <<
"--export-secret-key-p12";
84 *mProcess <<
"--armor";
85 if ( !mCharset.isEmpty() )
86 *mProcess <<
"--p12-charset" << mCharset;
87 *mProcess << patterns.front().utf8();
89 mProcess->setUsetStatusFD(
true );
91 connect( mProcess, TQ_SIGNAL(processExited(TDEProcess*)),
92 TQ_SLOT(slotProcessExited(TDEProcess*)) );
93 connect( mProcess, TQ_SIGNAL(receivedStdout(TDEProcess*,
char*,
int)),
94 TQ_SLOT(slotStdout(TDEProcess*,
char*,
int)) );
95 connect( mProcess, TQ_SIGNAL(receivedStderr(TDEProcess*,
char*,
int)),
96 TQ_SLOT(slotStderr(TDEProcess*,
char*,
int)) );
100 if ( !mProcess->start( TDEProcess::NotifyOnExit, TDEProcess::AllOutput ) ) {
101 mError = gpg_err_make( GPG_ERR_SOURCE_GPGSM, GPG_ERR_ENOENT );
108 void Kleo::QGpgMESecretKeyExportJob::slotCancel() {
112 mError = gpg_err_make( GPG_ERR_SOURCE_GPGSM, GPG_ERR_CANCELED );
115 void Kleo::QGpgMESecretKeyExportJob::slotStatus( GnuPGProcessBase * proc,
const TQString & type,
const TQStringList & args ) {
116 if ( proc != mProcess )
118 TQStringList::const_iterator it = args.begin();
121 if ( type ==
"ERROR" ) {
124 if ( args.size() < 2 ) {
125 kdDebug( 5150 ) <<
"Kleo::QGpgMESecretKeyExportJob::slotStatus() not recognising ERROR with < 2 args!" << endl;
128 const int source = (*++it).toInt( &ok );
130 kdDebug( 5150 ) <<
"Kleo::QGpgMESecretKeyExportJob::slotStatus() expected number for first ERROR arg, got something else" << endl;
134 const int code = (*++it).toInt( &ok );
136 kdDebug( 5150 ) <<
"Kleo::QGpgMESecretKeyExportJob::slotStatus() expected number for second ERROR arg, got something else" << endl;
139 mError = gpg_err_make( (gpg_err_source_t)source, (gpg_err_code_t)code );
142 }
else if ( type ==
"PROGRESS" ) {
145 if ( args.size() < 4 ) {
146 kdDebug( 5150 ) <<
"Kleo::QGpgMESecretKeyExportJob::slotStatus() not recognising PROGRESS with < 4 args!" << endl;
149 const TQString what = *++it;
151 const int cur = (*++it).toInt( &ok );
153 kdDebug( 5150 ) <<
"Kleo::QGpgMESecretKeyExportJob::slotStatus() expected number for \"cur\", got something else" << endl;
157 const int total = (*++it).toInt( &ok );
159 kdDebug( 5150 ) <<
"Kleo::QGpgMESecretKeyExportJob::slotStatus() expected number for \"total\", got something else" << endl;
162 emit progress( QGpgMEProgressTokenMapper::instance()->map( what, 0, cur, total ), cur, total );
168 void Kleo::QGpgMESecretKeyExportJob::slotStdout( TDEProcess * proc,
char * buf,
int buflen ) {
169 if ( proc != mProcess )
175 const unsigned int oldlen = mKeyData.size();
176 mKeyData.resize( oldlen + buflen );
177 memcpy( mKeyData.data() + oldlen, buf, buflen );
180 void Kleo::QGpgMESecretKeyExportJob::slotStderr( TDEProcess *,
char *,
int ) {
184 void Kleo::QGpgMESecretKeyExportJob::slotProcessExited( TDEProcess * proc ) {
185 if ( proc != mProcess )
190 ( !mProcess->normalExit() || mProcess->exitStatus() != 0 ) )
191 mError = gpg_err_make( GPG_ERR_SOURCE_GPGSM, GPG_ERR_GENERAL );
192 emit result( mError, mKeyData );
196 #include "qgpgmesecretkeyexportjob.moc"
a base class for GPG and GPGSM processes.