37 #include "qgpgmebackend.h"
39 #include "qgpgmecryptoconfig.h"
42 #include <gpgmepp/context.h>
43 #include <gpgmepp/engineinfo.h>
45 #include <tdelocale.h>
46 #include <kstandarddirs.h>
51 Kleo::QGpgMEBackend::QGpgMEBackend()
52 : Kleo::CryptoBackend(),
54 mOpenPGPProtocol( 0 ),
57 GpgME::initializeLibrary();
60 Kleo::QGpgMEBackend::~QGpgMEBackend() {
61 delete mCryptoConfig; mCryptoConfig = 0;
62 delete mOpenPGPProtocol; mOpenPGPProtocol = 0;
63 delete mSMIMEProtocol; mSMIMEProtocol = 0;
66 TQString Kleo::QGpgMEBackend::name()
const {
70 TQString Kleo::QGpgMEBackend::displayName()
const {
71 return i18n(
"GpgME" );
75 if ( !mCryptoConfig ) {
76 static bool hasGpgConf = !TDEStandardDirs::findExe(
"gpgconf" ).isEmpty();
83 static bool check( GpgME::Context::Protocol proto, TQString * reason ) {
84 if ( !GpgME::checkEngine( proto ) )
89 const GpgME::EngineInfo ei = GpgME::engineInfo( proto );
91 *reason = i18n(
"GPGME was compiled without support for %1.").arg( proto == GpgME::Context::CMS ?
"S/MIME" :
"OpenPGP" );
92 else if ( ei.fileName() && !ei.version() )
93 *reason = i18n(
"Engine %1 is not installed properly.").arg( TQFile::decodeName( ei.fileName() ) );
94 else if ( ei.fileName() && ei.version() && ei.requiredVersion() )
95 *reason = i18n(
"Engine %1 version %2 installed, "
96 "but at least version %3 is required.")
97 .arg( TQFile::decodeName( ei.fileName() ), ei.version(), ei.requiredVersion() );
99 *reason = i18n(
"Unknown problem with engine for protocol %1.").arg( proto == GpgME::Context::CMS ?
"S/MIME" :
"OpenPGP" );
103 bool Kleo::QGpgMEBackend::checkForOpenPGP( TQString * reason )
const {
104 return check( GpgME::Context::OpenPGP, reason );
107 bool Kleo::QGpgMEBackend::checkForSMIME( TQString * reason )
const {
108 return check( GpgME::Context::CMS, reason );
111 bool Kleo::QGpgMEBackend::checkForProtocol(
const char * name, TQString * reason )
const {
112 if ( tqstricmp( name, OpenPGP ) == 0 )
113 return check( GpgME::Context::OpenPGP, reason );
114 if ( tqstricmp( name, SMIME ) == 0 )
115 return check( GpgME::Context::CMS, reason );
117 *reason = i18n(
"Unsupported protocol \"%1\"" ).arg( name );
121 Kleo::CryptoBackend::Protocol * Kleo::QGpgMEBackend::openpgp()
const {
122 if ( !mOpenPGPProtocol )
123 if ( checkForOpenPGP() )
125 return mOpenPGPProtocol;
128 Kleo::CryptoBackend::Protocol * Kleo::QGpgMEBackend::smime()
const {
129 if ( !mSMIMEProtocol )
130 if ( checkForSMIME() )
132 return mSMIMEProtocol;
135 Kleo::CryptoBackend::Protocol * Kleo::QGpgMEBackend::protocol(
const char * name )
const {
136 if ( tqstricmp( name, OpenPGP ) == 0 )
138 if ( tqstricmp( name, SMIME ) == 0 )
143 bool Kleo::QGpgMEBackend::supportsProtocol(
const char * name )
const {
144 return tqstricmp( name, OpenPGP ) == 0 || tqstricmp( name, SMIME ) == 0;
147 const char * Kleo::QGpgMEBackend::enumerateProtocols(
int i )
const {
149 case 0:
return OpenPGP;
150 case 1:
return SMIME;
This class provides C++ access to the CRYPTPLUG API.
Main interface to crypto configuration.
CryptoConfig implementation around the gpgconf command-line tool For method docu, see kleo/cryptoconf...
C++ wrapper for the CRYPTPLUG library API.