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 "cryptplugfactory.h"
00038 #include "cryptplugwrapperlist.h"
00039
00040 #include <tdeconfig.h>
00041 #include <tdelocale.h>
00042 #include <kdebug.h>
00043 #include <tdemessagebox.h>
00044 #include <tdeapplication.h>
00045
00046 #include <assert.h>
00047
00048 KMail::CryptPlugFactory * KMail::CryptPlugFactory::mSelf = 0;
00049
00050
00051
00052
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 TQString & proto ) const {
00088 TQString 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( TQStringList * 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"