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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/*
* GPG Keys
* cdlgserversearch.cpp
* (c) 2001 Peter Mathiasson <peter@mathiasson.nu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation
*/
#include <qstatusbar.h>
#include <qlayout.h>
#include <qprocess.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include "cdlgsign.h"
#include "cgpgproc.h"
#include "functions.h"
#include "config.h"
/* --------------------------------------------------------------------------------- */
CDlgSign::CDlgSign( QWidget *parent, const QString tmpKeyId ) : CDlgSignUI( parent, 0, TRUE )
{
/* Set Font */
setFont( readConfigFont( "stdfont", STD_FONT ) );
/* Set Caption */
setCaption( tr( "Sign Key - Reading secret keys..." ) );
/* Save keyID */
keyId = tmpKeyId;
/* Connect Signals */
connect( btnSign, SIGNAL(clicked()), this, SLOT(doSign()) );
connect( btnCancel, SIGNAL(clicked()), this, SLOT(reject()) );
/* Read Secret Keys */
readSecretKeys();
}
/* --------------------------------------------------------------------------------- */
void CDlgSign::readSecretKeys()
{
/* Create Process */
gpgProc = new QProcess( this );
gpgProc->addArgument( readConfigString( "gpgpath", GPGPATH ) );
gpgProc->addArgument( "--list-secret-keys" );
gpgProc->addArgument( "--with-colon" );
connect( gpgProc, SIGNAL(processExited()), this, SLOT(processDone()) );
connect( gpgProc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()) );
/* Run GPG */
if ( !gpgProc->start() ) {
return;
}
}
/* --------------------------------------------------------------------------------- */
void CDlgSign::processDone()
{
setCaption( tr( "Sign Key" ) );
}
/* --------------------------------------------------------------------------------- */
void CDlgSign::readFromStdout()
{
QStringList entry;
while ( gpgProc->canReadLineStdout() ) {
/* Read/Split Line */
entry = QStringList::split( ':', gpgProc->readLineStdout(), TRUE );
/* Secret Key */
if ( entry[0] == "sec" ) {
/* Add to Secret Key Combo Box */
cbSecret->insertItem( entry[9] );
/* Save KeyID of Secret Key */
keyIdList << entry[4];
}
}
}
/* --------------------------------------------------------------------------------- */
void CDlgSign::doSign()
{
/* Get Secret Key ID */
int secId = 0;
for ( int i = 0; i < cbSecret->count(); i++ ) {
if ( cbSecret->text( i ) == cbSecret->currentText() )
secId = i;
}
/* Get Sign Type */
QString signArg;
if ( radioLocal->isOn() ) {
signArg = "--lsign-key";
} else {
signArg = "--sign-key";
}
/* Create Argument List */
QStringList args;
args << "--default-key" << keyIdList[secId] << signArg << keyId;
/* Run and Check Return Code */
switch ( CGPGProc::run( this, args, QString::null, TRUE ) ) {
case CGPGProc::RUNFAILED:
break;
default:
emit newPublic();
accept();
break;
}
}
/* --------------------------------------------------------------------------------- */
|