certmanager/lib
obtainkeysjob.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036
00037 #include "obtainkeysjob.h"
00038
00039 #include "chiasmusbackend.h"
00040
00041 #include "kleo/cryptoconfig.h"
00042
00043 #include <klocale.h>
00044 #include <kmessagebox.h>
00045 #include <kshell.h>
00046
00047 #include <qdir.h>
00048 #include <qstringlist.h>
00049 #include <qvariant.h>
00050 #include <qtimer.h>
00051 #include <qfileinfo.h>
00052
00053 #include <gpg-error.h>
00054
00055 #include <cassert>
00056
00057 Kleo::ObtainKeysJob::ObtainKeysJob()
00058 : SpecialJob( 0, 0 ),
00059 mIndex( 0 ),
00060 mCanceled( false )
00061 {
00062 assert( ChiasmusBackend::instance() );
00063 assert( ChiasmusBackend::instance()->config() );
00064 const CryptoConfigEntry * keypaths =
00065 ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "keydir" );
00066 assert( keypaths );
00067 mKeyPaths = QStringList( keypaths->urlValue().path() );
00068 }
00069
00070 Kleo::ObtainKeysJob::~ObtainKeysJob() {}
00071
00072 GpgME::Error Kleo::ObtainKeysJob::start() {
00073 QTimer::singleShot( 0, this, SLOT(slotPerform()) );
00074 return mError = 0;
00075 }
00076
00077 GpgME::Error Kleo::ObtainKeysJob::exec() {
00078 slotPerform( false );
00079 return mError;
00080 }
00081
00082 void Kleo::ObtainKeysJob::slotCancel() {
00083 mCanceled = true;
00084 }
00085
00086 void Kleo::ObtainKeysJob::slotPerform() {
00087 slotPerform( true );
00088 }
00089
00090 void Kleo::ObtainKeysJob::slotPerform( bool async ) {
00091 if ( mCanceled && !mError )
00092 mError = gpg_error( GPG_ERR_CANCELED );
00093 if ( mIndex >= mKeyPaths.size() || mError ) {
00094 emit done();
00095 emit SpecialJob::result( mError, QVariant( mResult ) );
00096 return;
00097 }
00098
00099 emit progress( i18n( "Scanning directory %1..." ).arg( mKeyPaths[mIndex] ),
00100 mIndex, mKeyPaths.size() );
00101
00102 const QDir dir( KShell::tildeExpand( mKeyPaths[mIndex] ) );
00103
00104 if ( const QFileInfoList * xisFiles = dir.entryInfoList( "*.xis;*.XIS", QDir::Files ) )
00105 for ( QFileInfoList::const_iterator it = xisFiles->begin(), end = xisFiles->end() ; it != end ; ++it )
00106 if ( (*it)->isReadable() )
00107 mResult.push_back( (*it)->absFilePath() );
00108
00109 ++mIndex;
00110
00111 if ( async )
00112 QTimer::singleShot( 0, this, SLOT(slotPerform()) );
00113 else
00114 slotPerform( false );
00115 }
00116
00117 void Kleo::ObtainKeysJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
00118 if ( !mError )
00119 return;
00120 if ( mError.isCanceled() )
00121 return;
00122 const QString msg = QString::fromUtf8( mError.asString() );
00123 KMessageBox::error( parent, msg, caption );
00124 }
00125
00126 #include "obtainkeysjob.moc"
|