certmanager/lib

cryptobackendfactory.h
1 /*
2  kleo/cryptobackendfactory.h
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004,2005 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 #ifndef __KLEO_CRYPTOBACKENDFACTORY_H__
34 #define __KLEO_CRYPTOBACKENDFACTORY_H__
35 
36 #include <tqobject.h>
37 
38 #include "cryptobackend.h"
39 #include <tdemacros.h>
40 
41 #include <vector>
42 #include <map>
43 
44 namespace Kleo {
45  class BackendConfigWidget;
46 }
47 
48 class TQString;
49 class TDEConfig;
50 
51 namespace Kleo {
52 
53  struct lt_i_str {
54  bool operator()( const char * one, const char * two ) const {
55  return tqstricmp( one, two ) < 0;
56  }
57  };
58 
59  class TDE_EXPORT CryptoBackendFactory : public TQObject {
60  TQ_OBJECT
61 
62  protected:
63  CryptoBackendFactory();
64  ~CryptoBackendFactory();
65  public:
66  static CryptoBackendFactory * instance();
67 
68  const CryptoBackend::Protocol * smime() const;
69  const CryptoBackend::Protocol * openpgp() const;
70  const CryptoBackend::Protocol * protocol( const char * name ) const;
71  CryptoConfig * config() const;
72 
73  const CryptoBackend * backend( unsigned int idx ) const;
74 
75  bool hasBackends() const;
76 
77  Kleo::BackendConfigWidget * configWidget( TQWidget * parent=0, const char * name=0 ) const;
78 
79  TDEConfig* configObject() const;
80 
81  // The preferred backend for smime (can be 0) - currently unused
82  //const CryptoBackend* smimeBackend() const;
83  // The preferred backend for openpgp (can be 0) - currently unused
84  //const CryptoBackend* openpgpBackend() const;
85 
86  // For BackendConfigWidget to save the configuration
87  // 0 means no backend selected.
88  void setSMIMEBackend( const CryptoBackend* backend );
89  void setOpenPGPBackend( const CryptoBackend* backend );
90  void setProtocolBackend( const char * name, const CryptoBackend * backend );
91 
92  void scanForBackends( TQStringList * reasons=0 );
93 
94  const char * enumerateProtocols( int i ) const;
95 
96  bool knowsAboutProtocol( const char * name ) const;
97 
98  protected:
99  std::vector<CryptoBackend*> mBackendList;
100  mutable TDEConfig* mConfigObject;
101  typedef std::map<const char *, const CryptoBackend*, lt_i_str> BackendMap;
102  BackendMap mBackends;
103  typedef std::vector<const char *> ProtocolSet;
104  ProtocolSet mAvailableProtocols;
105 
106  private:
107  const CryptoBackend * backendByName( const TQString& name ) const;
108  void readConfig();
109  CryptoBackendFactory( const CryptoBackendFactory & );
110  void operator=( const CryptoBackendFactory & );
111 
112  static CryptoBackendFactory * mSelf;
113  };
114 
115 
116 }
117 
118 #endif // __KLEO_CRYPTOBACKENDFACTORY_H__