certmanager/lib

cryptplugfactory.cpp
1/*
2 cryptplugfactory.cpp
3
4 This file is part of libkleopatra, the KDE key management library
5 Copyright (c) 2001,2004 Klarälvdalens Datakonsult AB
6
7 Libkleopatra is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 Libkleopatra is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 In addition, as a special exception, the copyright holders give
22 permission to link the code of this program with any edition of
23 the TQt library by Trolltech AS, Norway (or with modified versions
24 of TQt that use the same license as TQt), and distribute linked
25 combinations including the two. You must obey the GNU General
26 Public License in all respects for all of the code used other than
27 TQt. If you modify this file, you may extend this exception to
28 your version of the file, but you are not obligated to do so. If
29 you do not wish to do so, delete this exception statement from
30 your version.
31*/
32
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "cryptplugfactory.h"
38#include "cryptplugwrapperlist.h"
39
40#include <tdeconfig.h>
41#include <tdelocale.h>
42#include <kdebug.h>
43#include <tdemessagebox.h>
44#include <tdeapplication.h>
45
46#include <assert.h>
47
48KMail::CryptPlugFactory * KMail::CryptPlugFactory::mSelf = 0;
49
50//
51//
52// KMail::CryptPlugFactory: backwards compat stuff (ugly)
53//
54//
55
56
57KMail::CryptPlugFactory::CryptPlugFactory()
58 : Kleo::CryptoBackendFactory(),
59 mCryptPlugWrapperList( 0 )
60{
61 mSelf = this;
62
63 mCryptPlugWrapperList = new CryptPlugWrapperList();
64 mCryptPlugWrapperList->setAutoDelete( false );
65 updateCryptPlugWrapperList();
66}
67
68KMail::CryptPlugFactory::~CryptPlugFactory() {
69 mSelf = 0;
70 delete mCryptPlugWrapperList; mCryptPlugWrapperList = 0;
71}
72
73KMail::CryptPlugFactory * KMail::CryptPlugFactory::instance() {
74 if ( !mSelf )
75 mSelf = new CryptPlugFactory();
76 return mSelf;
77}
78
79CryptPlugWrapper * KMail::CryptPlugFactory::active() const {
80 if ( smime() && smime()->active() )
81 return smime();
82 if ( openpgp() && openpgp()->active() )
83 return openpgp();
84 return 0;
85}
86
87CryptPlugWrapper * KMail::CryptPlugFactory::createForProtocol( const TQString & proto ) const {
88 TQString p = proto.lower();
89 if ( p == "application/pkcs7-signature" || p == "application/x-pkcs7-signature" )
90 return smime();
91 if ( p == "application/pgp-signature" || p == "application/x-pgp-signature" )
92 return openpgp();
93 return 0;
94}
95
96CryptPlugWrapper * KMail::CryptPlugFactory::smime() const {
97 return mCryptPlugWrapperList->findForLibName( "smime" );
98}
99
100CryptPlugWrapper * KMail::CryptPlugFactory::openpgp() const {
101 return mCryptPlugWrapperList->findForLibName( "openpgp" );
102}
103
104void KMail::CryptPlugFactory::scanForBackends( TQStringList * reason ) {
105 Kleo::CryptoBackendFactory::scanForBackends( reason );
106 updateCryptPlugWrapperList();
107}
108
109void KMail::CryptPlugFactory::updateCryptPlugWrapperList() {
110 mCryptPlugWrapperList->clear();
111 for ( std::vector<Kleo::CryptoBackend*>::const_iterator it = mBackendList.begin() ; it != mBackendList.end() ; ++it ) {
112 if ( CryptPlugWrapper * w = dynamic_cast<CryptPlugWrapper*>( (*it)->openpgp() ) )
113 mCryptPlugWrapperList->append( w );
114 if ( CryptPlugWrapper * w = dynamic_cast<CryptPlugWrapper*>( (*it)->smime() ) )
115 mCryptPlugWrapperList->append( w );
116 }
117}
118
119#include "cryptplugfactory.moc"
This class provides C++ access to the CRYPTPLUG API.