certmanager/lib
cryptplugfactory.cpp
00001 /* 00002 cryptplugfactory.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., 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 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 "cryptplugfactory.h" 00038 #include "cryptplugwrapperlist.h" 00039 00040 #include <kconfig.h> 00041 #include <klocale.h> 00042 #include <kdebug.h> 00043 #include <kmessagebox.h> 00044 #include <kapplication.h> 00045 00046 #include <assert.h> 00047 00048 KMail::CryptPlugFactory * KMail::CryptPlugFactory::mSelf = 0; 00049 00050 // 00051 // 00052 // KMail::CryptPlugFactory: backwards compat stuff (ugly) 00053 // 00054 // 00055 00056 00057 KMail::CryptPlugFactory::CryptPlugFactory() 00058 : Kleo::CryptoBackendFactory(), 00059 mCryptPlugWrapperList( 0 ) 00060 { 00061 mSelf = this; 00062 00063 mCryptPlugWrapperList = new CryptPlugWrapperList(); 00064 mCryptPlugWrapperList->setAutoDelete( false ); 00065 updateCryptPlugWrapperList(); 00066 } 00067 00068 KMail::CryptPlugFactory::~CryptPlugFactory() { 00069 mSelf = 0; 00070 delete mCryptPlugWrapperList; mCryptPlugWrapperList = 0; 00071 } 00072 00073 KMail::CryptPlugFactory * KMail::CryptPlugFactory::instance() { 00074 if ( !mSelf ) 00075 mSelf = new CryptPlugFactory(); 00076 return mSelf; 00077 } 00078 00079 CryptPlugWrapper * KMail::CryptPlugFactory::active() const { 00080 if ( smime() && smime()->active() ) 00081 return smime(); 00082 if ( openpgp() && openpgp()->active() ) 00083 return openpgp(); 00084 return 0; 00085 } 00086 00087 CryptPlugWrapper * KMail::CryptPlugFactory::createForProtocol( const QString & proto ) const { 00088 QString p = proto.lower(); 00089 if ( p == "application/pkcs7-signature" || p == "application/x-pkcs7-signature" ) 00090 return smime(); 00091 if ( p == "application/pgp-signature" || p == "application/x-pgp-signature" ) 00092 return openpgp(); 00093 return 0; 00094 } 00095 00096 CryptPlugWrapper * KMail::CryptPlugFactory::smime() const { 00097 return mCryptPlugWrapperList->findForLibName( "smime" ); 00098 } 00099 00100 CryptPlugWrapper * KMail::CryptPlugFactory::openpgp() const { 00101 return mCryptPlugWrapperList->findForLibName( "openpgp" ); 00102 } 00103 00104 void KMail::CryptPlugFactory::scanForBackends( QStringList * reason ) { 00105 Kleo::CryptoBackendFactory::scanForBackends( reason ); 00106 updateCryptPlugWrapperList(); 00107 } 00108 00109 void KMail::CryptPlugFactory::updateCryptPlugWrapperList() { 00110 mCryptPlugWrapperList->clear(); 00111 for ( std::vector<Kleo::CryptoBackend*>::const_iterator it = mBackendList.begin() ; it != mBackendList.end() ; ++it ) { 00112 if ( CryptPlugWrapper * w = dynamic_cast<CryptPlugWrapper*>( (*it)->openpgp() ) ) 00113 mCryptPlugWrapperList->append( w ); 00114 if ( CryptPlugWrapper * w = dynamic_cast<CryptPlugWrapper*>( (*it)->smime() ) ) 00115 mCryptPlugWrapperList->append( w ); 00116 } 00117 } 00118 00119 #include "cryptplugfactory.moc"