36 #include <kpimidentities/identitymanager.h>
39 #ifndef KDEPIM_MOBILE_UI
42 #include "pimcommon/widgets/simplestringlisteditor.h"
43 #include "folderrequester.h"
44 #ifndef KCM_KPIMIDENTITIES_STANDALONE
49 #include "kernel/mailkernel.h"
52 #include "kleo_util.h"
53 #include "utils/stringutil.h"
54 #ifndef KDEPIM_MOBILE_UI
55 #include "templatesconfiguration.h"
57 #include "templatesconfiguration_kfg.h"
59 #include <kpimidentities/identity.h>
60 #include <kpimidentities/signatureconfigurator.h>
62 #include "messagecomposer/autocorrection/composerautocorrectionlanguage.h"
66 #include "libkleo/ui/keyrequester.h"
67 #include "kleo/cryptobackendfactory.h"
69 #include <kpimutils/email.h>
70 #include <kpimutils/emailvalidator.h>
71 #include <mailtransport/transport.h>
72 #include <mailtransport/transportmanager.h>
73 #include <mailtransport/transportcombobox.h>
74 using MailTransport::TransportManager;
78 #include <kmessagebox.h>
79 #include <kfileitem.h>
82 #include <kpushbutton.h>
83 #include <kcombobox.h>
84 #include <ktabwidget.h>
85 #include <KStandardDirs>
86 #include <sonnet/dictionarycombobox.h>
91 #include <QVBoxLayout>
92 #include <QGridLayout>
96 #include <gpgme++/key.h>
100 #include <akonadi/entitydisplayattribute.h>
101 #include <akonadi/collectionmodifyjob.h>
104 using namespace KPIM;
105 using namespace MailTransport;
106 using namespace MailCommon;
110 IdentityDialog::IdentityDialog(
QWidget * parent )
113 setCaption( i18n(
"Edit Identity") );
114 #ifndef KDEPIM_MOBILE_UI
115 setButtons( Ok|Cancel|Help );
117 setButtons( Ok|Cancel );
119 setDefaultButton( Ok );
122 setWindowState( Qt::WindowFullScreen );
137 setMainWidget( page );
138 QVBoxLayout * vlay =
new QVBoxLayout( page );
139 vlay->setSpacing( spacingHint() );
140 vlay->setMargin( 0 );
141 mTabWidget =
new KTabWidget( page );
142 mTabWidget->setObjectName( QLatin1String(
"config-identity-tab") );
143 vlay->addWidget( mTabWidget );
145 tab =
new QWidget( mTabWidget );
146 mTabWidget->addTab( tab, i18nc(
"@title:tab General identity settings.",
"General") );
147 glay =
new QGridLayout( tab );
148 glay->setSpacing( spacingHint() );
149 glay->setMargin( marginHint() );
150 glay->setRowStretch( 3, 1 );
151 glay->setColumnStretch( 1, 1 );
156 glay->addWidget( mNameEdit, row, 1 );
157 label =
new QLabel( i18n(
"&Your name:"), tab );
158 label->setBuddy( mNameEdit );
159 glay->addWidget( label, row, 0 );
160 msg = i18n(
"<qt><h3>Your name</h3>"
161 "<p>This field should contain your name as you would like "
162 "it to appear in the email header that is sent out;</p>"
163 "<p>if you leave this blank your real name will not "
164 "appear, only the email address.</p></qt>");
165 label->setWhatsThis( msg );
166 mNameEdit->setWhatsThis( msg );
170 mOrganizationEdit =
new KLineEdit( tab );
171 glay->addWidget( mOrganizationEdit, row, 1 );
172 label =
new QLabel( i18n(
"Organi&zation:"), tab );
173 label->setBuddy( mOrganizationEdit );
174 glay->addWidget( label, row, 0 );
175 msg = i18n(
"<qt><h3>Organization</h3>"
176 "<p>This field should have the name of your organization "
177 "if you would like it to be shown in the email header that "
179 "<p>It is safe (and normal) to leave this blank.</p></qt>");
180 label->setWhatsThis( msg );
181 mOrganizationEdit->setWhatsThis( msg );
187 glay->addWidget( mEmailEdit, row, 1 );
188 label =
new QLabel( i18n(
"&Email address:"), tab );
189 label->setBuddy( mEmailEdit );
190 glay->addWidget( label, row, 0 );
191 msg = i18n(
"<qt><h3>Email address</h3>"
192 "<p>This field should have your full email address.</p>"
193 "<p>This address is the primary one, used for all outgoing mail. "
194 "If you have more than one address, either create a new identity, "
195 "or add additional alias addresses in the field below.</p>"
196 "<p>If you leave this blank, or get it wrong, people "
197 "will have trouble replying to you.</p></qt>");
198 label->setWhatsThis( msg );
199 mEmailEdit->setWhatsThis( msg );
201 KPIMUtils::EmailValidator* emailValidator =
new KPIMUtils::EmailValidator(
this );
202 mEmailEdit->setValidator( emailValidator );
206 mAliasEdit =
new PimCommon::SimpleStringListEditor( tab );
207 glay->addWidget( mAliasEdit, row, 1 );
208 label =
new QLabel( i18n(
"Email a&liases:"), tab );
209 label->setBuddy( mAliasEdit );
210 glay->addWidget( label, row, 0, Qt::AlignTop );
211 msg = i18n(
"<qt><h3>Email aliases</h3>"
212 "<p>This field contains alias addresses that should also "
213 "be considered as belonging to this identity (as opposed "
214 "to representing a different identity).</p>"
217 "<tr><th>Primary address:</th><td>first.last@example.org</td></tr>"
218 "<tr><th>Aliases:</th><td>first@example.org<br>last@example.org</td></tr>"
220 "<p>Type one alias address per line.</p></qt>");
221 label->setToolTip( msg );
222 mAliasEdit->setWhatsThis( msg );
228 mCryptographyTab = tab =
new QWidget( mTabWidget );
229 mTabWidget->addTab( tab, i18n(
"Cryptography") );
230 glay =
new QGridLayout( tab );
231 glay->setSpacing( spacingHint() );
232 glay->setMargin( marginHint() );
233 glay->setColumnStretch( 1, 1 );
237 mPGPSigningKeyRequester =
new Kleo::SigningKeyRequester(
false, Kleo::SigningKeyRequester::OpenPGP, tab );
238 mPGPSigningKeyRequester->dialogButton()->setText( i18n(
"Chang&e...") );
239 mPGPSigningKeyRequester->setDialogCaption( i18n(
"Your OpenPGP Signature Key") );
240 msg = i18n(
"Select the OpenPGP key which should be used to "
241 "digitally sign your messages.");
242 mPGPSigningKeyRequester->setDialogMessage( msg );
244 msg = i18n(
"<qt><p>The OpenPGP key you choose here will be used "
245 "to digitally sign messages. You can also use GnuPG keys.</p>"
246 "<p>You can leave this blank, but KMail will not be able "
247 "to digitally sign emails using OpenPGP; "
248 "normal mail functions will not be affected.</p>"
249 "<p>You can find out more about keys at <a>http://www.gnupg.org</a></p></qt>");
251 label =
new QLabel( i18n(
"OpenPGP signing key:"), tab );
252 label->setBuddy( mPGPSigningKeyRequester );
253 mPGPSigningKeyRequester->setWhatsThis( msg );
254 label->setWhatsThis( msg );
256 glay->addWidget( label, row, 0 );
257 glay->addWidget( mPGPSigningKeyRequester, row, 1 );
262 mPGPEncryptionKeyRequester =
new Kleo::EncryptionKeyRequester(
false, Kleo::EncryptionKeyRequester::OpenPGP, tab );
263 mPGPEncryptionKeyRequester->dialogButton()->setText( i18n(
"Chang&e...") );
264 mPGPEncryptionKeyRequester->setDialogCaption( i18n(
"Your OpenPGP Encryption Key") );
265 msg = i18n(
"Select the OpenPGP key which should be used when encrypting "
266 "to yourself and for the \"Attach My Public Key\" "
267 "feature in the composer.");
268 mPGPEncryptionKeyRequester->setDialogMessage( msg );
270 msg = i18n(
"<qt><p>The OpenPGP key you choose here will be used "
271 "to encrypt messages to yourself and for the \"Attach My Public Key\" "
272 "feature in the composer. You can also use GnuPG keys.</p>"
273 "<p>You can leave this blank, but KMail will not be able "
274 "to encrypt copies of outgoing messages to you using OpenPGP; "
275 "normal mail functions will not be affected.</p>"
276 "<p>You can find out more about keys at <a>http://www.gnupg.org</a></p></qt>");
277 label =
new QLabel( i18n(
"OpenPGP encryption key:"), tab );
278 label->setBuddy( mPGPEncryptionKeyRequester );
279 mPGPEncryptionKeyRequester->setWhatsThis( msg );
280 label->setWhatsThis( msg );
282 glay->addWidget( label, row, 0 );
283 glay->addWidget( mPGPEncryptionKeyRequester, row, 1 );
288 mSMIMESigningKeyRequester =
new Kleo::SigningKeyRequester(
false, Kleo::SigningKeyRequester::SMIME, tab );
289 mSMIMESigningKeyRequester->dialogButton()->setText( i18n(
"Chang&e...") );
290 mSMIMESigningKeyRequester->setDialogCaption( i18n(
"Your S/MIME Signature Certificate") );
291 msg = i18n(
"Select the S/MIME certificate which should be used to "
292 "digitally sign your messages.");
293 mSMIMESigningKeyRequester->setDialogMessage( msg );
295 msg = i18n(
"<qt><p>The S/MIME (X.509) certificate you choose here will be used "
296 "to digitally sign messages.</p>"
297 "<p>You can leave this blank, but KMail will not be able "
298 "to digitally sign emails using S/MIME; "
299 "normal mail functions will not be affected.</p></qt>");
300 label =
new QLabel( i18n(
"S/MIME signing certificate:"), tab );
301 label->setBuddy( mSMIMESigningKeyRequester );
302 mSMIMESigningKeyRequester->setWhatsThis( msg );
303 label->setWhatsThis( msg );
304 glay->addWidget( label, row, 0 );
305 glay->addWidget( mSMIMESigningKeyRequester, row, 1 );
307 const Kleo::CryptoBackend::Protocol * smimeProtocol
308 = Kleo::CryptoBackendFactory::instance()->smime();
310 label->setEnabled( smimeProtocol );
311 mSMIMESigningKeyRequester->setEnabled( smimeProtocol );
315 mSMIMEEncryptionKeyRequester =
new Kleo::EncryptionKeyRequester(
false, Kleo::EncryptionKeyRequester::SMIME, tab );
316 mSMIMEEncryptionKeyRequester->dialogButton()->setText( i18n(
"Chang&e...") );
317 mSMIMEEncryptionKeyRequester->setDialogCaption( i18n(
"Your S/MIME Encryption Certificate") );
318 msg = i18n(
"Select the S/MIME certificate which should be used when encrypting "
319 "to yourself and for the \"Attach My Certificate\" "
320 "feature in the composer.");
321 mSMIMEEncryptionKeyRequester->setDialogMessage( msg );
323 msg = i18n(
"<qt><p>The S/MIME certificate you choose here will be used "
324 "to encrypt messages to yourself and for the \"Attach My Certificate\" "
325 "feature in the composer.</p>"
326 "<p>You can leave this blank, but KMail will not be able "
327 "to encrypt copies of outgoing messages to you using S/MIME; "
328 "normal mail functions will not be affected.</p></qt>");
329 label =
new QLabel( i18n(
"S/MIME encryption certificate:"), tab );
330 label->setBuddy( mSMIMEEncryptionKeyRequester );
331 mSMIMEEncryptionKeyRequester->setWhatsThis( msg );
332 label->setWhatsThis( msg );
334 glay->addWidget( label, row, 0 );
335 glay->addWidget( mSMIMEEncryptionKeyRequester, row, 1 );
337 label->setEnabled( smimeProtocol );
338 mSMIMEEncryptionKeyRequester->setEnabled( smimeProtocol );
342 mPreferredCryptoMessageFormat =
new KComboBox( tab );
343 mPreferredCryptoMessageFormat->setEditable(
false );
345 l << Kleo::cryptoMessageFormatToLabel( Kleo::AutoFormat )
346 << Kleo::cryptoMessageFormatToLabel( Kleo::InlineOpenPGPFormat )
347 << Kleo::cryptoMessageFormatToLabel( Kleo::OpenPGPMIMEFormat )
348 << Kleo::cryptoMessageFormatToLabel( Kleo::SMIMEFormat )
349 << Kleo::cryptoMessageFormatToLabel( Kleo::SMIMEOpaqueFormat );
350 mPreferredCryptoMessageFormat->addItems( l );
351 label =
new QLabel( i18nc(
"preferred format of encrypted messages",
"Preferred format:"), tab );
352 label->setBuddy( mPreferredCryptoMessageFormat );
354 glay->addWidget( label, row, 0 );
355 glay->addWidget( mPreferredCryptoMessageFormat, row, 1 );
359 mAutoSign =
new QCheckBox(i18n(
"Automatically sign messages"));
360 glay->addWidget( mAutoSign, row, 0 );
363 glay->setRowStretch( row, 1 );
369 tab =
new QWidget( mTabWidget );
370 mTabWidget->addTab( tab, i18nc(
"@title:tab Advanced identity settings.",
"Advanced") );
371 glay =
new QGridLayout( tab );
372 glay->setSpacing( spacingHint() );
373 glay->setMargin( marginHint() );
375 glay->setColumnStretch( 1, 1 );
380 mReplyToEdit->setObjectName( QLatin1String(
"mReplyToEdit") );
381 glay->addWidget( mReplyToEdit, row, 1 );
382 label =
new QLabel ( i18n(
"&Reply-To address:"), tab );
383 label->setBuddy( mReplyToEdit );
384 glay->addWidget( label, row, 0 );
385 msg = i18n(
"<qt><h3>Reply-To addresses</h3>"
386 "<p>This sets the <tt>Reply-to:</tt> header to contain a "
387 "different email address to the normal <tt>From:</tt> "
389 "<p>This can be useful when you have a group of people "
390 "working together in similar roles. For example, you "
391 "might want any emails sent to have your email in the "
392 "<tt>From:</tt> field, but any responses to go to "
393 "a group address.</p>"
394 "<p>If in doubt, leave this field blank.</p></qt>");
395 label->setWhatsThis( msg );
396 mReplyToEdit->setWhatsThis( msg );
403 mCcEdit->setObjectName( QLatin1String(
"mCcEdit") );
404 glay->addWidget( mCcEdit, row, 1 );
405 label =
new QLabel( i18n(
"&CC addresses:"), tab );
406 label->setBuddy( mCcEdit );
407 glay->addWidget( label, row, 0 );
408 msg = i18n(
"<qt><h3>CC (Carbon Copy) addresses</h3>"
409 "<p>The addresses that you enter here will be added to each "
410 "outgoing mail that is sent with this identity.</p>"
411 "<p>This is commonly used to send a copy of each sent message to "
412 "another account of yours.</p>"
413 "<p>To specify more than one address, use commas to separate "
414 "the list of CC recipients.</p>"
415 "<p>If in doubt, leave this field blank.</p></qt>");
416 label->setWhatsThis( msg );
417 mCcEdit->setWhatsThis( msg );
423 mBccEdit->setObjectName( QLatin1String(
"mBccEdit") );
424 glay->addWidget( mBccEdit, row, 1 );
425 label =
new QLabel( i18n(
"&BCC addresses:"), tab );
426 label->setBuddy( mBccEdit );
427 glay->addWidget( label, row, 0 );
428 msg = i18n(
"<qt><h3>BCC (Blind Carbon Copy) addresses</h3>"
429 "<p>The addresses that you enter here will be added to each "
430 "outgoing mail that is sent with this identity. They will not "
431 "be visible to other recipients.</p>"
432 "<p>This is commonly used to send a copy of each sent message to "
433 "another account of yours.</p>"
434 "<p>To specify more than one address, use commas to separate "
435 "the list of BCC recipients.</p>"
436 "<p>If in doubt, leave this field blank.</p></qt>");
437 label->setWhatsThis( msg );
438 mBccEdit->setWhatsThis( msg );
442 mDictionaryCombo =
new Sonnet::DictionaryComboBox( tab );
443 glay->addWidget( mDictionaryCombo, row, 1 );
444 label =
new QLabel( i18n(
"D&ictionary:"), tab );
445 label->setBuddy( mDictionaryCombo );
446 glay->addWidget( label, row, 0 );
450 mFccCombo =
new FolderRequester( tab );
451 mFccCombo->setShowOutbox(
false );
452 glay->addWidget( mFccCombo, row, 1 );
453 mSentMailFolderCheck =
new QCheckBox( i18n(
"Sent-mail &folder:"), tab );
454 glay->addWidget( mSentMailFolderCheck, row, 0 );
455 connect(mSentMailFolderCheck,SIGNAL(toggled(
bool)),mFccCombo,SLOT(setEnabled(
bool)));
459 mDraftsCombo =
new FolderRequester( tab );
460 mDraftsCombo->setShowOutbox(
false );
461 glay->addWidget( mDraftsCombo, row, 1 );
462 label =
new QLabel( i18n(
"&Drafts folder:"), tab );
463 label->setBuddy( mDraftsCombo );
464 glay->addWidget( label, row, 0 );
468 mTemplatesCombo =
new FolderRequester( tab );
469 mTemplatesCombo->setShowOutbox(
false );
470 glay->addWidget( mTemplatesCombo, row, 1 );
471 label =
new QLabel( i18n(
"&Templates folder:"), tab );
472 label->setBuddy( mTemplatesCombo );
473 glay->addWidget( label, row, 0 );
477 mTransportCheck =
new QCheckBox( i18n(
"Outgoing Account:"), tab );
478 glay->addWidget( mTransportCheck, row, 0 );
479 mTransportCombo =
new TransportComboBox( tab );
480 mTransportCombo->setEnabled(
false );
481 glay->addWidget( mTransportCombo, row, 1 );
482 connect( mTransportCheck, SIGNAL(toggled(
bool)),
483 mTransportCombo, SLOT(setEnabled(
bool)) );
486 mAttachMyVCard =
new QCheckBox(i18n(
"Attach my vCard to message"), tab);
487 glay->addWidget( mAttachMyVCard, row, 0 );
488 mEditVCard =
new KPushButton(i18n(
"Create..."),tab);
489 connect(mEditVCard,SIGNAL(clicked()),SLOT(slotEditVcard()));
490 glay->addWidget( mEditVCard, row, 1 );
494 mAutoCorrectionLanguage =
new MessageComposer::ComposerAutoCorrectionLanguage(tab);
495 glay->addWidget( mAutoCorrectionLanguage, row, 1 );
496 label =
new QLabel( i18n(
"Autocorrection language:"), tab );
497 label->setBuddy( mAutoCorrectionLanguage );
498 glay->addWidget( label, row, 0 );
501 glay->setRowStretch( row, 1 );
508 tab =
new QWidget( mTabWidget );
509 vlay =
new QVBoxLayout( tab );
510 vlay->setMargin( marginHint() );
511 vlay->setSpacing( spacingHint() );
513 QHBoxLayout *tlay =
new QHBoxLayout();
514 vlay->addLayout( tlay );
516 mCustom =
new QCheckBox( i18n(
"&Use custom message templates for this identity"), tab );
517 tlay->addWidget( mCustom, Qt::AlignLeft );
519 #ifndef KDEPIM_MOBILE_UI
520 mWidget =
new TemplateParser::TemplatesConfiguration( tab, QLatin1String(
"identity-templates") );
521 mWidget->setEnabled(
false );
525 tlay->addStretch( 9 );
526 tlay->addWidget( mWidget->helpLabel(), Qt::AlignRight );
528 vlay->addWidget( mWidget );
531 QHBoxLayout *btns =
new QHBoxLayout();
532 btns->setSpacing( spacingHint() );
533 mCopyGlobal =
new KPushButton( i18n(
"&Copy Global Templates"), tab );
534 mCopyGlobal->setEnabled(
false );
535 btns->addWidget( mCopyGlobal );
536 vlay->addLayout( btns );
537 #ifndef KDEPIM_MOBILE_UI
538 connect( mCustom, SIGNAL(toggled(
bool)),
539 mWidget, SLOT(setEnabled(
bool)) );
541 connect( mCustom, SIGNAL(toggled(
bool)),
542 mCopyGlobal, SLOT(setEnabled(
bool)) );
543 connect( mCopyGlobal, SIGNAL(clicked()),
545 #ifdef KDEPIM_MOBILE_UI
548 mTabWidget->addTab( tab, i18n(
"Templates") );
554 mSignatureConfigurator =
new KPIMIdentities::SignatureConfigurator( mTabWidget );
555 mSignatureConfigurator->layout()->setMargin( KDialog::marginHint() );
556 mTabWidget->addTab( mSignatureConfigurator, i18n(
"Signature") );
562 #ifndef KDEPIM_MOBILE_UI
564 mXFaceConfigurator->layout()->setMargin( KDialog::marginHint() );
565 mTabWidget->addTab( mXFaceConfigurator, i18n(
"Picture") );
568 #ifndef KCM_KPIMIDENTITIES_STANDALONE
571 mNameEdit->setFocus();
573 connect( mTabWidget, SIGNAL(currentChanged(
int)),
575 setHelp( QLatin1String(
"configure-identity"), QLatin1String(
"kmail") );
579 #ifndef KCM_KPIMIDENTITIES_STANDALONE
585 QWidget *w = mTabWidget->widget( index );
586 if ( w == mCryptographyTab ) {
589 const QString
email = mEmailEdit->text().trimmed();
590 mPGPEncryptionKeyRequester->setInitialQuery( email );
591 mPGPSigningKeyRequester->setInitialQuery( email );
592 mSMIMEEncryptionKeyRequester->setInitialQuery( email );
593 mSMIMESigningKeyRequester->setInitialQuery( email );
598 #ifndef KDEPIM_MOBILE_UI
599 mWidget->loadFromGlobal();
604 struct DoesntMatchEMailAddress {
605 explicit DoesntMatchEMailAddress(
const QString & s )
606 :
email( s.trimmed().toLower() ) {}
607 bool operator()(
const GpgME::Key & key )
const;
609 bool checkForEmail(
const char *
email )
const;
610 static QString extractEmail(
const char *
email );
614 bool DoesntMatchEMailAddress::operator()(
const GpgME::Key & key )
const {
615 const std::vector<GpgME::UserID> uids = key.userIDs();
616 std::vector<GpgME::UserID>::const_iterator end = uids.end();
617 for ( std::vector<GpgME::UserID>::const_iterator it = uids.begin() ; it != end ; ++it )
618 if ( checkForEmail( it->email() ? it->email() : it->id() ) )
623 bool DoesntMatchEMailAddress::checkForEmail(
const char * e )
const {
624 const QString em = extractEmail( e );
625 return !em.isEmpty() &&
email.toLower() == em.toLower();
628 QString DoesntMatchEMailAddress::extractEmail(
const char * e ) {
631 const QString em = QString::fromUtf8( e );
633 return em.mid( 1, em.length() - 2 );
641 if ( button != KDialog::Ok ) {
642 KDialog::slotButtonClicked( button );
646 const QStringList aliases = mAliasEdit->stringList();
647 foreach (
const QString &alias, aliases ) {
648 if ( !KPIMUtils::isValidSimpleAddress( alias ) ) {
649 const QString errorMsg( KPIMUtils::simpleEmailAddressErrorMsg() );
650 KMessageBox::sorry(
this, errorMsg, i18n(
"Invalid Email Alias \"%1\"", alias ) );
656 const QString
email = mEmailEdit->text().trimmed();
657 if ( !KPIMUtils::isValidSimpleAddress( email ) ) {
658 QString errorMsg( KPIMUtils::simpleEmailAddressErrorMsg() );
659 KMessageBox::sorry(
this, errorMsg, i18n(
"Invalid Email Address") );
664 const QString recipients = mReplyToEdit->text().trimmed() + QLatin1String(
", " ) + mBccEdit->text().trimmed() + QLatin1String(
", " ) + mCcEdit->text().trimmed();
666 job->setProperty(
"email", email );
667 connect( job, SIGNAL(result(
KJob*)), SLOT(slotDelayedButtonClicked(
KJob*)) );
671 void IdentityDialog::slotDelayedButtonClicked(
KJob *job )
676 if ( !validationJob->
isValid() )
679 const QString
email = validationJob->property(
"email" ).toString();
681 const std::vector<GpgME::Key> &pgpSigningKeys =
682 mPGPSigningKeyRequester->keys();
683 const std::vector<GpgME::Key> &pgpEncryptionKeys =
684 mPGPEncryptionKeyRequester->keys();
685 const std::vector<GpgME::Key> &smimeSigningKeys =
686 mSMIMESigningKeyRequester->keys();
687 const std::vector<GpgME::Key> &smimeEncryptionKeys =
688 mSMIMEEncryptionKeyRequester->keys();
692 if ( std::find_if( pgpSigningKeys.begin(), pgpSigningKeys.end(),
693 DoesntMatchEMailAddress( email ) ) != pgpSigningKeys.end() ) {
694 msg = i18n(
"One of the configured OpenPGP signing keys does not contain "
695 "any user ID with the configured email address for this "
697 "This might result in warning messages on the receiving side "
698 "when trying to verify signatures made with this configuration.", email);
700 }
else if ( std::find_if( pgpEncryptionKeys.begin(), pgpEncryptionKeys.end(),
701 DoesntMatchEMailAddress( email ) ) != pgpEncryptionKeys.end() ) {
702 msg = i18n(
"One of the configured OpenPGP encryption keys does not contain "
703 "any user ID with the configured email address for this "
704 "identity (%1).", email);
706 }
else if ( std::find_if( smimeSigningKeys.begin(), smimeSigningKeys.end(),
707 DoesntMatchEMailAddress( email ) ) != smimeSigningKeys.end() ) {
708 msg = i18n(
"One of the configured S/MIME signing certificates does not contain "
709 "the configured email address for this "
711 "This might result in warning messages on the receiving side "
712 "when trying to verify signatures made with this configuration.", email);
714 }
else if ( std::find_if( smimeEncryptionKeys.begin(), smimeEncryptionKeys.end(),
715 DoesntMatchEMailAddress( email ) ) != smimeEncryptionKeys.end() ) {
716 msg = i18n(
"One of the configured S/MIME encryption certificates does not contain "
717 "the configured email address for this "
718 "identity (%1).", email);
723 if ( KMessageBox::warningContinueCancel(
this, msg,
724 i18n(
"Email Address Not Found in Key/Certificates"),
725 KStandardGuiItem::cont(),
726 KStandardGuiItem::cancel(),
727 QLatin1String(
"warn_email_not_in_certificate") )
728 != KMessageBox::Continue) {
734 if ( mSignatureConfigurator->isSignatureEnabled() &&
735 mSignatureConfigurator->signatureType()==Signature::FromFile ) {
736 KUrl url( mSignatureConfigurator->fileURL() );
737 KFileItem signatureFile( KFileItem::Unknown, KFileItem::Unknown, url );
738 if ( !signatureFile.isFile() || !signatureFile.isReadable() || !signatureFile.isLocalFile() ) {
739 KMessageBox::error(
this, i18n(
"The signature file is not valid" ) );
747 bool IdentityDialog::checkFolderExists(
const QString & folderID,
748 const QString & msg )
750 const Akonadi::Collection folder = CommonKernel->collectionFromId( folderID.toLongLong() );
751 if ( !folder.isValid() ) {
752 KMessageBox::sorry(
this, msg );
761 setCaption( i18n(
"Edit Identity \"%1\"", ident.identityName() ) );
764 mNameEdit->setText( ident.fullName() );
765 mOrganizationEdit->setText( ident.organization() );
766 mEmailEdit->setText( ident.primaryEmailAddress() );
767 mAliasEdit->setStringList( ident.emailAliases() );
770 mPGPSigningKeyRequester->setFingerprint( QLatin1String(ident.pgpSigningKey()) );
771 mPGPEncryptionKeyRequester->setFingerprint( QLatin1String(ident.pgpEncryptionKey()) );
772 mSMIMESigningKeyRequester->setFingerprint( QLatin1String(ident.smimeSigningKey()) );
773 mSMIMEEncryptionKeyRequester->setFingerprint( QLatin1String(ident.smimeEncryptionKey()) );
775 mPreferredCryptoMessageFormat->setCurrentIndex( format2cb(
776 Kleo::stringToCryptoMessageFormat( ident.preferredCryptoMessageFormat() ) ) );
777 mAutoSign->setChecked(ident.pgpAutoSign());
780 mReplyToEdit->setText( ident.replyToAddr() );
781 mBccEdit->setText( ident.bcc() );
782 mCcEdit->setText( ident.cc() );
783 const int transportId = ident.transport().isEmpty() ? -1 : ident.transport().toInt();
784 const Transport *transport = TransportManager::self()->transportById( transportId,
true );
785 mTransportCheck->setChecked( transportId != -1 );
786 mTransportCombo->setEnabled( transportId != -1 );
788 mTransportCombo->setCurrentTransport( transport->id() );
789 mDictionaryCombo->setCurrentByDictionaryName( ident.dictionary() );
791 mSentMailFolderCheck->setChecked(!ident.disabledFcc());
792 mFccCombo->setEnabled(mSentMailFolderCheck->isChecked());
793 if ( ident.fcc().isEmpty() ||
794 !checkFolderExists( ident.fcc(),
795 i18n(
"The custom sent-mail folder for identity "
796 "\"%1\" does not exist (anymore); "
797 "therefore, the default sent-mail folder "
799 ident.identityName() ) ) ) {
800 mFccCombo->setCollection( CommonKernel->sentCollectionFolder() );
803 mFccCombo->setCollection( Akonadi::Collection( ident.fcc().toLongLong() ) );
805 if ( ident.drafts().isEmpty() ||
806 !checkFolderExists( ident.drafts(),
807 i18n(
"The custom drafts folder for identity "
808 "\"%1\" does not exist (anymore); "
809 "therefore, the default drafts folder "
811 ident.identityName() ) ) ) {
812 mDraftsCombo->setCollection( CommonKernel->draftsCollectionFolder() );
815 mDraftsCombo->setCollection( Akonadi::Collection( ident.drafts().toLongLong() ) );
817 if ( ident.templates().isEmpty() ||
818 !checkFolderExists( ident.templates(),
819 i18n(
"The custom templates folder for identity "
820 "\"%1\" does not exist (anymore); "
821 "therefore, the default templates folder "
822 "will be used.", ident.identityName()) ) ) {
823 mTemplatesCombo->setCollection( CommonKernel->templatesCollectionFolder() );
827 mTemplatesCombo->setCollection( Akonadi::Collection( ident.templates().toLongLong() ) );
829 mVcardFilename = ident.vCardFile();
831 mAutoCorrectionLanguage->setLanguage(ident.autocorrectionLanguage());
833 if(mVcardFilename.isEmpty()) {
834 mVcardFilename = KStandardDirs::locateLocal(
"appdata",ident.identityName() + QLatin1String(
".vcf"));
836 mAttachMyVCard->setChecked(ident.attachVcard());
838 #ifndef KDEPIM_MOBILE_UI
839 uint identity = ident.uoid();
840 QString iid = TemplateParser::TemplatesConfiguration::configIdString( identity );
841 TemplateParser::Templates t( iid );
842 mCustom->setChecked(t.useCustomTemplates());
843 mWidget->loadFromIdentity( identity );
847 mSignatureConfigurator->setImageLocation( ident );
848 mSignatureConfigurator->setSignature( ident.signature() );
849 #ifndef KDEPIM_MOBILE_UI
850 mXFaceConfigurator->
setXFace( ident.xface() );
857 ident.setFullName( mNameEdit->text() );
858 ident.setOrganization( mOrganizationEdit->text() );
859 QString email = mEmailEdit->text();
860 ident.setPrimaryEmailAddress( email );
861 ident.setEmailAliases( mAliasEdit->stringList() );
863 ident.setPGPSigningKey( mPGPSigningKeyRequester->fingerprint().toLatin1() );
864 ident.setPGPEncryptionKey( mPGPEncryptionKeyRequester->fingerprint().toLatin1() );
865 ident.setSMIMESigningKey( mSMIMESigningKeyRequester->fingerprint().toLatin1() );
866 ident.setSMIMEEncryptionKey( mSMIMEEncryptionKeyRequester->fingerprint().toLatin1() );
867 ident.setPreferredCryptoMessageFormat(
868 QLatin1String(Kleo::cryptoMessageFormatToString(cb2format( mPreferredCryptoMessageFormat->currentIndex() ) )) );
869 ident.setPgpAutoSign(mAutoSign->isChecked());
871 ident.setReplyToAddr( mReplyToEdit->text() );
872 ident.setBcc( mBccEdit->text() );
873 ident.setCc( mCcEdit->text() );
874 ident.setTransport( mTransportCheck->isChecked() ? QString::number( mTransportCombo->currentTransportId() )
876 ident.setDictionary( mDictionaryCombo->currentDictionaryName() );
877 ident.setDisabledFcc( !mSentMailFolderCheck->isChecked() );
878 Akonadi::Collection collection = mFccCombo->collection();
879 if ( collection.isValid() ) {
880 ident.setFcc( QString::number( collection.id() ) );
881 Akonadi::EntityDisplayAttribute *attribute = collection.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Entity::AddIfMissing );
882 attribute->setIconName( QLatin1String(
"mail-folder-sent" ) );
883 new Akonadi::CollectionModifyJob( collection );
886 ident.setFcc( QString() );
888 collection = mDraftsCombo->collection();
889 if ( collection.isValid() ) {
890 ident.setDrafts( QString::number( collection.id() ) );
891 Akonadi::EntityDisplayAttribute *attribute = collection.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Entity::AddIfMissing );
892 attribute->setIconName( QLatin1String(
"document-properties" ) );
893 new Akonadi::CollectionModifyJob( collection );
896 ident.setDrafts( QString() );
898 collection = mTemplatesCombo->collection();
899 if ( collection.isValid() ) {
900 ident.setTemplates( QString::number( collection.id() ) );
901 Akonadi::EntityDisplayAttribute *attribute = collection.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Entity::AddIfMissing );
902 attribute->setIconName( QLatin1String(
"document-new" ) );
903 new Akonadi::CollectionModifyJob( collection );
906 ident.setTemplates( QString() );
907 ident.setVCardFile(mVcardFilename);
908 ident.setAutocorrectionLanguage(mAutoCorrectionLanguage->language());
910 ident.setAttachVcard(mAttachMyVCard->isChecked());
913 #ifndef KDEPIM_MOBILE_UI
914 uint identity = ident.uoid();
915 QString iid = TemplateParser::TemplatesConfiguration::configIdString( identity );
916 TemplateParser::Templates t( iid );
917 kDebug() <<
"use custom templates for identity" << identity <<
":" << mCustom->isChecked();
918 t.setUseCustomTemplates(mCustom->isChecked());
920 mWidget->saveToIdentity( identity );
924 ident.setSignature( mSignatureConfigurator->signature() );
925 #ifndef KDEPIM_MOBILE_UI
926 ident.setXFace( mXFaceConfigurator->
xface() );
931 void IdentityDialog::slotEditVcard()
933 if(QFile(mVcardFilename).exists()) {
934 editVcard(mVcardFilename);
936 if ( !MailCommon::Kernel::self()->kernelIsRegistered() ) {
939 KPIMIdentities::IdentityManager *manager = KernelIf->identityManager();
946 editVcard(mVcardFilename);
950 KPIMIdentities::Identity ident = manager->modifyIdentityForName( dlg->duplicateVcardFromIdentity() );
951 const QString filename = ident.vCardFile();
952 if(!filename.isEmpty()) {
953 QFile::copy(filename,mVcardFilename);
955 editVcard(mVcardFilename);
964 void IdentityDialog::editVcard(
const QString &filename)
968 mVcardFilename = dlg.saveVcard();
973 void IdentityDialog::updateVcardButton()
975 if(!QFile(mVcardFilename).exists()) {
976 mEditVCard->setText(i18n(
"Create..."));
978 mEditVCard->setText(i18n(
"Edit..."));
984 #include "identitydialog.moc"
void updateIdentity(KPIMIdentities::Identity &ident)
void slotAboutToShow(int)
void setXFaceEnabled(bool enable)
void setXFace(const QString &text)
bool isXFaceEnabled() const
void slotButtonClicked(int button)
static GlobalSettings * self()
void setIdentity(KPIMIdentities::Identity &ident)