00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <config.h>
00025 #include "certmanager/lib/ui/keyrequester.h"
00026 #include "certmanager/lib/cryptplugfactory.h"
00027 #include "certmanager/lib/cryptplugwrapper.h"
00028 #include "certmanager/lib/kleo/enum.h"
00029
00030 #include "gpgmepp/data.h"
00031 #include "gpgmepp/key.h"
00032
00033 #include <kdebug.h>
00034 #include <kdialog.h>
00035 #include <kiconloader.h>
00036 #include <klocale.h>
00037
00038 #include <qlayout.h>
00039 #include <qlabel.h>
00040 #include <qcheckbox.h>
00041 #include <qcombobox.h>
00042 #include <qpushbutton.h>
00043 #include <qvgroupbox.h>
00044 #include <qhbox.h>
00045
00046 #include "cryptowidget.h"
00047
00048 extern "C" {
00049 void *init_libkaddrbk_cryptosettings()
00050 {
00051 return ( new CryptoWidgetFactory );
00052 }
00053 }
00054
00055 CryptoWidgetFactory::CryptoWidgetFactory()
00056 {
00057 KGlobal::locale()->insertCatalogue( "libkleopatra" );
00058 KGlobal::iconLoader()->addAppDir( "libkleopatra" );
00059 }
00060
00061 QString CryptoWidgetFactory::pageTitle() const
00062 {
00063 return i18n( "Crypto Settings" );
00064 }
00065
00066 QString CryptoWidgetFactory::pageIdentifier() const
00067 {
00068 return "crypto";
00069 }
00070
00071 CryptoWidget::CryptoWidget( KABC::AddressBook *ab, QWidget *parent, const char *name )
00072 : KAB::ContactEditorWidget( ab, parent, name ), mReadOnly( false )
00073 {
00074 QGridLayout *topLayout = new QGridLayout( this, 2, 5, KDialog::marginHint(),
00075 KDialog::spacingHint() );
00076 topLayout->setColStretch( 1, 1 );
00077 topLayout->setRowStretch( 4, 1 );
00078
00079 QVGroupBox* protGB = new QVGroupBox( i18n("Allowed Protocols"), this );
00080 topLayout->addMultiCellWidget( protGB,0,0,0,1 );
00081
00082 uint msgFormat = 1;
00083 for ( uint i = 0 ; i < NumberOfProtocols ; ++i ) {
00084 Kleo::CryptoMessageFormat f = static_cast<Kleo::CryptoMessageFormat>( msgFormat );
00085 mProtocolCB[i] = new QCheckBox( Kleo::cryptoMessageFormatToLabel( f ), protGB );
00086 connect( mProtocolCB[i], SIGNAL( clicked() ), this, SLOT( setModified() ) );
00087
00088 msgFormat *= 2;
00089 }
00090
00091 QLabel* l = new QLabel( i18n("Preferred OpenPGP encryption key:"), this );
00092 topLayout->addWidget( l,1,0 );
00093
00094 mPgpKey =
00095 new Kleo::EncryptionKeyRequester( true, Kleo::EncryptionKeyRequester::OpenPGP, this );
00096 topLayout->addWidget( mPgpKey,1,1 );
00097
00098 l = new QLabel( i18n("Preferred S/MIME encryption certificate:"), this );
00099 topLayout->addWidget( l,2,0 );
00100
00101 mSmimeCert =
00102 new Kleo::EncryptionKeyRequester( true, Kleo::EncryptionKeyRequester::SMIME, this );
00103 topLayout->addWidget( mSmimeCert,2,1 );
00104
00105 QGroupBox* box = new QVGroupBox( i18n("Message Preference"), this );
00106 topLayout->addMultiCellWidget( box, 3,3,0,1 );
00107
00108
00109
00110 QHBox* hbox = new QHBox(box);
00111
00112 l = new QLabel( i18n("Sign:"), hbox );
00113
00114 mSignPref = new QComboBox( false, hbox );
00115 for ( unsigned int i = Kleo::UnknownSigningPreference ;
00116 i < Kleo::MaxSigningPreference ; ++i )
00117 mSignPref->insertItem( Kleo::signingPreferenceToLabel(
00118 static_cast<Kleo::SigningPreference>( i ) ) );
00119
00120
00121 hbox = new QHBox(box);
00122
00123 l = new QLabel( i18n("Encrypt:"), hbox );
00124
00125 mCryptPref = new QComboBox( false, hbox );
00126 for ( unsigned int i = Kleo::UnknownPreference ;
00127 i < Kleo::MaxEncryptionPreference ; ++i )
00128 mCryptPref->insertItem(
00129 Kleo::encryptionPreferenceToLabel( static_cast<Kleo::EncryptionPreference>( i ) ) );
00130
00131
00132 connect( mSignPref, SIGNAL( activated(int) ), this, SLOT( setModified() ) );
00133 connect( mCryptPref, SIGNAL( activated(int) ), this, SLOT( setModified() ) );
00134
00135 connect( mPgpKey->eraseButton(), SIGNAL( clicked() ), this, SLOT( setModified() ) );
00136 connect( mPgpKey->dialogButton(), SIGNAL( clicked() ), this, SLOT( setModified() ) );
00137 connect( mSmimeCert->eraseButton(), SIGNAL( clicked() ), this, SLOT( setModified() ) );
00138 connect( mSmimeCert->dialogButton(), SIGNAL( clicked() ), this, SLOT( setModified() ) );
00139 }
00140
00141 CryptoWidget::~CryptoWidget()
00142 {
00143 }
00144
00145 void CryptoWidget::loadContact( KABC::Addressee *addr )
00146 {
00147 bool blocked = signalsBlocked();
00148 blockSignals( true );
00149
00150 QStringList lst = QStringList::split( ',', addr->custom( "KADDRESSBOOK",
00151 "CRYPTOPROTOPREF" ) );
00152 uint cryptoFormats = Kleo::stringListToCryptoMessageFormats( lst );
00153
00154 uint msgFormat = 1;
00155 for ( uint i = 0 ; i < NumberOfProtocols ; ++i, msgFormat *= 2 ) {
00156 mProtocolCB[i]->setChecked( cryptoFormats & msgFormat );
00157 }
00158
00159 mSignPref->setCurrentItem( Kleo::stringToSigningPreference(addr->custom( "KADDRESSBOOK",
00160 "CRYPTOSIGNPREF" )) );
00161 mCryptPref->setCurrentItem( Kleo::stringToEncryptionPreference(addr->custom( "KADDRESSBOOK",
00162 "CRYPTOENCRYPTPREF" )) );
00163
00164
00165
00166
00167 mPgpKey->setFingerprints( QStringList::split( ",", addr->custom( "KADDRESSBOOK", "OPENPGPFP" ) ) );
00168 mSmimeCert->setFingerprints( QStringList::split( ",", addr->custom( "KADDRESSBOOK", "SMIMEFP" ) ) );
00169
00170 blockSignals( blocked );
00171 }
00172
00173 void CryptoWidget::storeContact( KABC::Addressee *addr )
00174 {
00175 uint cryptoFormats = 0;
00176 uint msgFormat = 1;
00177 for ( uint i = 0 ; i < NumberOfProtocols ; ++i, msgFormat *= 2 ) {
00178 if ( mProtocolCB[i]->isChecked() )
00179 cryptoFormats |= msgFormat;
00180 }
00181 QStringList lst = Kleo::cryptoMessageFormatsToStringList(cryptoFormats);
00182
00183 if ( !lst.isEmpty() )
00184 addr->insertCustom( "KADDRESSBOOK", "CRYPTOPROTOPREF", lst.join( "," ) );
00185 else
00186 addr->removeCustom( "KADDRESSBOOK", "CRYPTOPROTOPREF" );
00187
00188 Kleo::SigningPreference signPref =
00189 static_cast<Kleo::SigningPreference>( mSignPref->currentItem() );
00190 if ( signPref != Kleo::UnknownSigningPreference )
00191 addr->insertCustom( "KADDRESSBOOK", "CRYPTOSIGNPREF",
00192 Kleo::signingPreferenceToString( signPref ) );
00193 else
00194 addr->removeCustom( "KADDRESSBOOK", "CRYPTOSIGNPREF" );
00195
00196 Kleo::EncryptionPreference encryptPref =
00197 static_cast<Kleo::EncryptionPreference>( mCryptPref->currentItem() );
00198 if ( encryptPref != Kleo::UnknownPreference )
00199 addr->insertCustom( "KADDRESSBOOK", "CRYPTOENCRYPTPREF",
00200 Kleo::encryptionPreferenceToString( encryptPref ) );
00201 else
00202 addr->removeCustom( "KADDRESSBOOK", "CRYPTOENCRYPTPREF" );
00203
00204 QStringList pfp = mPgpKey->fingerprints();
00205 QStringList sfp = mSmimeCert->fingerprints();
00206
00207 if( !pfp.isEmpty() ) {
00208 addr->insertCustom( "KADDRESSBOOK", "OPENPGPFP", pfp.join( "," ) );
00209 } else {
00210 addr->removeCustom( "KADDRESSBOOK", "OPENPGPFP" );
00211 }
00212
00213 if( !sfp.isEmpty() ) {
00214 addr->insertCustom( "KADDRESSBOOK", "SMIMEFP", sfp.join( "," ) );
00215 } else {
00216 addr->removeCustom( "KADDRESSBOOK", "SMIMEFP" );
00217 }
00218
00219 }
00220
00221 void CryptoWidget::setReadOnly( bool readOnly )
00222 {
00223 mReadOnly = readOnly;
00224 for ( uint i = 0 ; i < NumberOfProtocols ; ++i )
00225 mProtocolCB[i]->setEnabled( !readOnly );
00226 mSignPref->setEnabled( !readOnly );
00227 mCryptPref->setEnabled( !readOnly );
00228 mPgpKey->setEnabled( !readOnly );
00229 mSmimeCert->setEnabled( !readOnly );
00230 }
00231
00232 #include "cryptowidget.moc"