cryptobackendfactory.cpp
00001
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 "cryptobackendfactory.h"
00038
00039 #include <backends/qgpgme/qgpgmebackend.h>
00040 #include <backends/kpgp/pgp2backend.h>
00041 #include <backends/kpgp/pgp5backend.h>
00042 #include <backends/kpgp/pgp6backend.h>
00043 #include <backends/kpgp/gpg1backend.h>
00044 #include <ui/backendconfigwidget.h>
00045
00046 #include <kconfig.h>
00047 #include <klocale.h>
00048 #include <kdebug.h>
00049 #include <kmessagebox.h>
00050 #include <kapplication.h>
00051
00052 #include <assert.h>
00053
00054 Kleo::CryptoBackendFactory * Kleo::CryptoBackendFactory::mSelf = 0;
00055
00056 Kleo::CryptoBackendFactory::CryptoBackendFactory()
00057 : QObject( qApp, "CryptoBackendFactory::instance()" )
00058 {
00059 mSelf = this;
00060 mConfigObject = 0;
00061 mBackendList.push_back( new QGpgMEBackend() );
00062 #if 0 // disabled for kde-3.3
00063 mBackendList.push_back( new PGP2Backend() );
00064 mBackendList.push_back( new PGP5Backend() );
00065 mBackendList.push_back( new PGP6Backend() );
00066 mBackendList.push_back( new GPG1Backend() );
00067 #endif
00068 scanForBackends();
00069 readConfig();
00070 }
00071
00072 Kleo::CryptoBackendFactory::~CryptoBackendFactory() {
00073 mSelf = 0;
00074
00075 for ( QValueVector<CryptoBackend*>::iterator it = mBackendList.begin() ; it != mBackendList.end() ; ++it ) {
00076 delete *it;
00077 *it = 0;
00078 }
00079 delete mConfigObject;
00080 mConfigObject = 0;
00081 }
00082
00083 Kleo::CryptoBackendFactory * Kleo::CryptoBackendFactory::instance() {
00084 if ( !mSelf )
00085 mSelf = new CryptoBackendFactory();
00086 return mSelf;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 const Kleo::CryptoBackend::Protocol * Kleo::CryptoBackendFactory::smime() const {
00099 return mSMIMEBackend ? mSMIMEBackend->smime() : 0 ;
00100 }
00101
00102 const Kleo::CryptoBackend::Protocol * Kleo::CryptoBackendFactory::openpgp() const {
00103 return mOpenPGPBackend ? mOpenPGPBackend->openpgp() : 0 ;
00104 }
00105
00106 Kleo::CryptoConfig * Kleo::CryptoBackendFactory::config() const {
00107
00108 return backend( 0 ) ? backend( 0 )->config() : 0;
00109 }
00110
00111 bool Kleo::CryptoBackendFactory::hasBackends() const {
00112 return !mBackendList.empty();
00113 }
00114
00115 void Kleo::CryptoBackendFactory::scanForBackends( QStringList * reasons ) {
00116 if ( !reasons )
00117 return;
00118 for ( QValueVector<CryptoBackend*>::const_iterator it = mBackendList.begin() ; it != mBackendList.end() ; ++it ) {
00119 assert( *it );
00120 QString reason;
00121 if ( (*it)->supportsOpenPGP() && !(*it)->checkForOpenPGP( &reason ) ) {
00122 reasons->push_back( i18n("While scanning for OpenPGP support in backend %1:")
00123 .arg( (*it)->displayName() ) );
00124 reasons->push_back( " " + reason );
00125 }
00126 if ( (*it)->supportsSMIME() && !(*it)->checkForSMIME( &reason ) ) {
00127 reasons->push_back( i18n("While scanning for S/MIME support in backend %1:")
00128 .arg( (*it)->displayName() ) );
00129 reasons->push_back( " " + reason );
00130 }
00131 }
00132 }
00133
00134 const Kleo::CryptoBackend * Kleo::CryptoBackendFactory::backend( unsigned int idx ) const {
00135 return ( idx < mBackendList.size() ) ? mBackendList[idx] : 0 ;
00136 }
00137
00138 const Kleo::CryptoBackend * Kleo::CryptoBackendFactory::backendByName( const QString& name ) const {
00139 for ( QValueVector<CryptoBackend*>::const_iterator it = mBackendList.begin() ; it != mBackendList.end() ; ++it ) {
00140 if ( (*it)->name() == name )
00141 return *it;
00142 }
00143 return 0;
00144 }
00145
00146 Kleo::BackendConfigWidget * Kleo::CryptoBackendFactory::configWidget( QWidget * parent, const char * name ) const {
00147 return new Kleo::BackendConfigWidget( mSelf, parent, name );
00148 }
00149
00150 KConfig* Kleo::CryptoBackendFactory::configObject() const {
00151 if ( !mConfigObject )
00152 mConfigObject = new KConfig( "libkleopatrarc" );
00153 return mConfigObject;
00154 }
00155
00156 void Kleo::CryptoBackendFactory::setSMIMEBackend( const CryptoBackend* backend ) {
00157 const QString name = backend ? backend->name() : QString::null;
00158 KConfigGroup group( configObject(), "Backends" );
00159 group.writeEntry( "SMIME", name );
00160 configObject()->sync();
00161 mSMIMEBackend = backend;
00162 }
00163
00164 void Kleo::CryptoBackendFactory::setOpenPGPBackend( const CryptoBackend* backend ) {
00165 const QString name = backend ? backend->name() : QString::null;
00166 KConfigGroup group( configObject(), "Backends" );
00167 group.writeEntry( "OpenPGP", name );
00168 configObject()->sync();
00169 mOpenPGPBackend = backend;
00170 }
00171
00172 void Kleo::CryptoBackendFactory::readConfig() {
00173 const KConfigGroup group( configObject(), "Backends" );
00174 const QString smimeBackend = group.readEntry( "SMIME", "gpgme" );
00175 mSMIMEBackend = backendByName( smimeBackend );
00176
00177 const QString openPGPBackend = group.readEntry( "OpenPGP", "gpgme" );
00178 mOpenPGPBackend = backendByName( openPGPBackend );
00179 }
00180
00181 #include "cryptobackendfactory.moc"
00182
This file is part of the documentation for certmanager/lib Library Version 3.3.2.