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 "qgpgmebackend.h"
00038
00039
#include "qgpgmecryptoconfig.h"
00040
#include "cryptplugwrapper.h"
00041
00042
#include <gpgmepp/context.h>
00043
#include <gpgmepp/engineinfo.h>
00044
00045
#include <klocale.h>
00046
#include <kstandarddirs.h>
00047
00048
#include <qfile.h>
00049
#include <qstring.h>
00050
00051 Kleo::QGpgMEBackend::QGpgMEBackend()
00052 : Kleo::CryptoBackend(),
00053 mCryptoConfig( 0 ),
00054 mOpenPGPProtocol( 0 ),
00055 mSMIMEProtocol( 0 )
00056 {
00057
00058 }
00059
00060 Kleo::QGpgMEBackend::~QGpgMEBackend() {
00061
delete mCryptoConfig; mCryptoConfig = 0;
00062
delete mOpenPGPProtocol; mOpenPGPProtocol = 0;
00063
delete mSMIMEProtocol; mSMIMEProtocol = 0;
00064 }
00065
00066
QString Kleo::QGpgMEBackend::name()
const {
00067
return "gpgme";
00068 }
00069
00070
QString Kleo::QGpgMEBackend::displayName()
const {
00071
return i18n(
"GpgME" );
00072 }
00073
00074
Kleo::CryptoConfig * Kleo::QGpgMEBackend::config()
const {
00075
if ( !mCryptoConfig ) {
00076
static bool hasGpgConf = !KStandardDirs::findExe(
"gpgconf" ).isEmpty();
00077
if ( hasGpgConf )
00078 mCryptoConfig =
new QGpgMECryptoConfig();
00079 }
00080
return mCryptoConfig;
00081 }
00082
00083
static bool check( GpgME::Context::Protocol proto,
QString * reason ) {
00084
if ( !GpgME::checkEngine( proto ) )
00085
return true;
00086
if ( !reason )
00087
return false;
00088
00089
const GpgME::EngineInfo ei = GpgME::engineInfo( proto );
00090
if ( ei.isNull() )
00091 *reason = i18n(
"GPGME was compiled without support for %1.").arg( proto == GpgME::Context::CMS ?
"S/MIME" :
"OpenPGP" );
00092
else if ( ei.fileName() && !ei.version() )
00093 *reason = i18n(
"Engine %1 is not installed properly.").arg( QFile::decodeName( ei.fileName() ) );
00094
else if ( ei.fileName() && ei.version() && ei.requiredVersion() )
00095 *reason = i18n(
"Engine %1 version %2 installed, "
00096
"but at least version %3 is required.")
00097 .arg( QFile::decodeName( ei.fileName() ), ei.version(), ei.requiredVersion() );
00098
else
00099 *reason = i18n(
"Unknown problem with engine for protocol %1.").arg( proto == GpgME::Context::CMS ?
"S/MIME" :
"OpenPGP" );
00100
return false;
00101 }
00102
00103
bool Kleo::QGpgMEBackend::checkForOpenPGP(
QString * reason )
const {
00104
return check( GpgME::Context::OpenPGP, reason );
00105 }
00106
00107
bool Kleo::QGpgMEBackend::checkForSMIME(
QString * reason )
const {
00108
return check( GpgME::Context::CMS, reason );
00109 }
00110
00111 Kleo::CryptoBackend::Protocol * Kleo::QGpgMEBackend::openpgp()
const {
00112
if ( !mOpenPGPProtocol )
00113
if ( checkForOpenPGP() )
00114 mOpenPGPProtocol =
new CryptPlugWrapper(
"gpg",
"openpgp" );
00115
return mOpenPGPProtocol;
00116 }
00117
00118 Kleo::CryptoBackend::Protocol * Kleo::QGpgMEBackend::smime()
const {
00119
if ( !mSMIMEProtocol )
00120
if ( checkForSMIME() )
00121 mSMIMEProtocol =
new CryptPlugWrapper(
"gpgsm",
"smime" );
00122
return mSMIMEProtocol;
00123 }