certmanager/lib Library API Documentation

cryptobackendfactory.cpp

00001 /* 00002 cryptobackendfactory.cpp 00003 00004 This file is part of libkleopatra, the KDE key management library 00005 Copyright (c) 2001,2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), 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 Qt. 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 "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 // const Kleo::CryptoBackend* Kleo::CryptoBackendFactory::smimeBackend() const { 00091 // return mSMIMEBackend; 00092 // } 00093 00094 // const Kleo::CryptoBackend* Kleo::CryptoBackendFactory::openpgpBackend() const { 00095 // return mOpenPGPBackend; 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 // ## should we use mSMIMEBackend? mOpenPGPBackend? backend(0) i.e. always qgpgme? 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
KDE Logo
This file is part of the documentation for certmanager/lib Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:26 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003