certmanager/lib Library API Documentation

qgpgmebackend.cpp

00001 /* -*- mode: C++; c-file-style: "gnu" -*- 00002 qgpgmebackend.cpp 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klarälvdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. 00011 00012 Libkleopatra is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 Qt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 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 // error, check why: 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 }
KDE Logo
This file is part of the documentation for certmanager/lib Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:27 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003