obtainkeysjob.cpp
00001 /* 00002 obtainkeysjob.cpp 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2005 Klarälvdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. 00011 00012 Libkleopatra is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the TQt library by Trolltech AS, Norway (or with modified versions 00024 of TQt that use the same license as TQt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 TQt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 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 <tqdir.h> 00048 #include <tqstringlist.h> 00049 #include <tqvariant.h> 00050 #include <tqtimer.h> 00051 #include <tqfileinfo.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 = TQStringList( keypaths->urlValue().path() ); 00068 } 00069 00070 Kleo::ObtainKeysJob::~ObtainKeysJob() {} 00071 00072 GpgME::Error Kleo::ObtainKeysJob::start() { 00073 TQTimer::singleShot( 0, this, TQT_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, TQVariant( mResult ) ); 00096 return; 00097 } 00098 00099 emit progress( i18n( "Scanning directory %1..." ).arg( mKeyPaths[mIndex] ), 00100 mIndex, mKeyPaths.size() ); 00101 00102 const TQDir dir( KShell::tildeExpand( mKeyPaths[mIndex] ) ); 00103 00104 if ( const TQFileInfoList * xisFiles = dir.entryInfoList( "*.xis;*.XIS", TQDir::Files ) ) 00105 for ( TQFileInfoList::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 TQTimer::singleShot( 0, this, TQT_SLOT(slotPerform()) ); 00113 else 00114 slotPerform( false ); 00115 } 00116 00117 void Kleo::ObtainKeysJob::showErrorDialog( TQWidget * parent, const TQString & caption ) const { 00118 if ( !mError ) 00119 return; 00120 if ( mError.isCanceled() ) 00121 return; 00122 const TQString msg = TQString::fromUtf8( mError.asString() ); 00123 KMessageBox::error( parent, msg, caption ); 00124 } 00125 00126 #include "obtainkeysjob.moc"