25 #include "certmanager/lib/ui/keyrequester.h"
26 #include "certmanager/lib/cryptplugfactory.h"
27 #include "certmanager/lib/cryptplugwrapper.h"
28 #include "certmanager/lib/kleo/enum.h"
30 #include "gpgmepp/data.h"
31 #include "gpgmepp/key.h"
35 #include <kiconloader.h>
36 #include <tdelocale.h>
40 #include <tqcheckbox.h>
41 #include <tqcombobox.h>
42 #include <tqpushbutton.h>
43 #include <tqvgroupbox.h>
46 #include "cryptowidget.h"
49 void *init_libkaddrbk_cryptosettings()
51 return (
new CryptoWidgetFactory );
55 CryptoWidgetFactory::CryptoWidgetFactory()
57 TDEGlobal::locale()->insertCatalogue(
"libkleopatra" );
58 TDEGlobal::iconLoader()->addAppDir(
"libkleopatra" );
61 TQString CryptoWidgetFactory::pageTitle()
const
63 return i18n(
"Crypto Settings" );
66 TQString CryptoWidgetFactory::pageIdentifier()
const
71 CryptoWidget::CryptoWidget( TDEABC::AddressBook *ab, TQWidget *parent,
const char *name )
72 : KAB::ContactEditorWidget( ab, parent, name ), mReadOnly( false )
74 TQGridLayout *topLayout =
new TQGridLayout(
this, 2, 5, KDialog::marginHint(),
75 KDialog::spacingHint() );
76 topLayout->setColStretch( 1, 1 );
77 topLayout->setRowStretch( 4, 1 );
79 TQVGroupBox* protGB =
new TQVGroupBox( i18n(
"Allowed Protocols" ),
this );
80 topLayout->addMultiCellWidget( protGB, 0, 0, 0, 1 );
83 for ( uint i = 0 ; i < NumberOfProtocols ; ++i ) {
84 Kleo::CryptoMessageFormat f =
static_cast<Kleo::CryptoMessageFormat
>( msgFormat );
85 mProtocolCB[ i ] =
new TQCheckBox( Kleo::cryptoMessageFormatToLabel( f ), protGB );
86 connect( mProtocolCB[i], TQ_SIGNAL( clicked() ),
this, TQ_SLOT( setModified() ) );
92 TQLabel* l =
new TQLabel( i18n(
"Preferred OpenPGP encryption key:" ),
this );
93 topLayout->addWidget( l, 1, 0 );
95 mPgpKey =
new Kleo::EncryptionKeyRequester(
true, Kleo::EncryptionKeyRequester::OpenPGP,
this );
96 topLayout->addWidget( mPgpKey, 1, 1 );
98 l =
new TQLabel( i18n(
"Preferred S/MIME encryption certificate:" ),
this );
99 topLayout->addWidget( l, 2, 0 );
101 mSmimeCert =
new Kleo::EncryptionKeyRequester(
true, Kleo::EncryptionKeyRequester::SMIME,
this );
102 topLayout->addWidget( mSmimeCert, 2, 1 );
104 TQGroupBox* box =
new TQVGroupBox( i18n(
"Message Preference" ),
this );
105 topLayout->addMultiCellWidget( box, 3, 3, 0, 1 );
109 TQHBox* hbox =
new TQHBox( box );
111 l =
new TQLabel( i18n(
"Sign:" ), hbox );
113 mSignPref =
new TQComboBox(
false, hbox );
114 for (
unsigned int i = Kleo::UnknownSigningPreference; i < Kleo::MaxSigningPreference ; ++i )
115 mSignPref->insertItem( Kleo::signingPreferenceToLabel(
116 static_cast<Kleo::SigningPreference
>( i ) ) );
119 hbox =
new TQHBox( box );
121 l =
new TQLabel( i18n(
"Encrypt:"), hbox );
123 mCryptPref =
new TQComboBox(
false, hbox );
124 for (
unsigned int i = Kleo::UnknownPreference; i < Kleo::MaxEncryptionPreference ; ++i )
125 mCryptPref->insertItem( Kleo::encryptionPreferenceToLabel(
126 static_cast<Kleo::EncryptionPreference
>( i ) ) );
129 connect( mSignPref, TQ_SIGNAL( activated(
int) ),
this, TQ_SLOT( setModified() ) );
130 connect( mCryptPref, TQ_SIGNAL( activated(
int) ),
this, TQ_SLOT( setModified() ) );
132 connect( mPgpKey->eraseButton(), TQ_SIGNAL( clicked() ),
this, TQ_SLOT( setModified() ) );
133 connect( mPgpKey->dialogButton(), TQ_SIGNAL( clicked() ),
this, TQ_SLOT( setModified() ) );
134 connect( mSmimeCert->eraseButton(), TQ_SIGNAL( clicked() ),
this, TQ_SLOT( setModified() ) );
135 connect( mSmimeCert->dialogButton(), TQ_SIGNAL( clicked() ),
this, TQ_SLOT( setModified() ) );
138 CryptoWidget::~CryptoWidget()
142 void CryptoWidget::loadContact( TDEABC::Addressee *addr )
144 bool blocked = signalsBlocked();
145 blockSignals(
true );
147 TQStringList lst = TQStringList::split(
',', addr->custom(
"KADDRESSBOOK",
148 "CRYPTOPROTOPREF" ) );
149 uint cryptoFormats = Kleo::stringListToCryptoMessageFormats( lst );
152 for ( uint i = 0 ; i < NumberOfProtocols ; ++i, msgFormat *= 2 ) {
153 mProtocolCB[i]->setChecked( cryptoFormats & msgFormat );
156 mSignPref->setCurrentItem( Kleo::stringToSigningPreference( addr->custom(
"KADDRESSBOOK",
157 "CRYPTOSIGNPREF" ) ) );
158 mCryptPref->setCurrentItem( Kleo::stringToEncryptionPreference( addr->custom(
"KADDRESSBOOK",
159 "CRYPTOENCRYPTPREF" ) ) );
164 mPgpKey->setFingerprints( TQStringList::split(
",", addr->custom(
"KADDRESSBOOK",
"OPENPGPFP" ) ) );
165 mSmimeCert->setFingerprints( TQStringList::split(
",", addr->custom(
"KADDRESSBOOK",
"SMIMEFP" ) ) );
167 blockSignals( blocked );
170 void CryptoWidget::storeContact( TDEABC::Addressee *addr )
172 uint cryptoFormats = 0;
174 for ( uint i = 0 ; i < NumberOfProtocols ; ++i, msgFormat *= 2 ) {
175 if ( mProtocolCB[ i ]->isChecked() )
176 cryptoFormats |= msgFormat;
179 TQStringList lst = Kleo::cryptoMessageFormatsToStringList( cryptoFormats );
180 if ( !lst.isEmpty() )
181 addr->insertCustom(
"KADDRESSBOOK",
"CRYPTOPROTOPREF", lst.join(
"," ) );
183 addr->removeCustom(
"KADDRESSBOOK",
"CRYPTOPROTOPREF" );
185 Kleo::SigningPreference signPref =
186 static_cast<Kleo::SigningPreference
>( mSignPref->currentItem() );
187 if ( signPref != Kleo::UnknownSigningPreference )
188 addr->insertCustom(
"KADDRESSBOOK",
"CRYPTOSIGNPREF",
189 Kleo::signingPreferenceToString( signPref ) );
191 addr->removeCustom(
"KADDRESSBOOK",
"CRYPTOSIGNPREF" );
193 Kleo::EncryptionPreference encryptPref =
194 static_cast<Kleo::EncryptionPreference
>( mCryptPref->currentItem() );
195 if ( encryptPref != Kleo::UnknownPreference )
196 addr->insertCustom(
"KADDRESSBOOK",
"CRYPTOENCRYPTPREF",
197 Kleo::encryptionPreferenceToString( encryptPref ) );
199 addr->removeCustom(
"KADDRESSBOOK",
"CRYPTOENCRYPTPREF" );
201 TQStringList pfp = mPgpKey->fingerprints();
202 TQStringList sfp = mSmimeCert->fingerprints();
204 if ( !pfp.isEmpty() )
205 addr->insertCustom(
"KADDRESSBOOK",
"OPENPGPFP", pfp.join(
"," ) );
207 addr->removeCustom(
"KADDRESSBOOK",
"OPENPGPFP" );
209 if ( !sfp.isEmpty() )
210 addr->insertCustom(
"KADDRESSBOOK",
"SMIMEFP", sfp.join(
"," ) );
212 addr->removeCustom(
"KADDRESSBOOK",
"SMIMEFP" );
215 void CryptoWidget::setReadOnly(
bool readOnly )
217 mReadOnly = readOnly;
218 for ( uint i = 0 ; i < NumberOfProtocols ; ++i )
219 mProtocolCB[ i ]->setEnabled( !readOnly );
221 mSignPref->setEnabled( !readOnly );
222 mCryptPref->setEnabled( !readOnly );
223 mPgpKey->setEnabled( !readOnly );
224 mSmimeCert->setEnabled( !readOnly );
227 #include "cryptowidget.moc"