• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • identity
identitydialog.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2  identitydialog.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2002 Marc Mutz <mutz@kde.org>
6 
7  KMail is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License, version 2, as
9  published by the Free Software Foundation.
10 
11  KMail is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the Qt library by Trolltech AS, Norway (or with modified versions
23  of Qt that use the same license as Qt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  Qt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 */
31 
32 #include "identitydialog.h"
33 #include "identityeditvcarddialog.h"
34 #include "identityaddvcarddialog.h"
35 
36 #include <kpimidentities/identitymanager.h>
37 
38 // other KMail headers:
39 #ifndef KDEPIM_MOBILE_UI
40 #include "xfaceconfigurator.h"
41 #endif
42 #include "pimcommon/widgets/simplestringlisteditor.h"
43 #include "folderrequester.h"
44 #ifndef KCM_KPIMIDENTITIES_STANDALONE
45 #include "settings/globalsettings.h"
46 #include "kmkernel.h"
47 #endif
48 
49 #include "kernel/mailkernel.h"
50 
51 #include "job/addressvalidationjob.h"
52 #include "kleo_util.h"
53 #include "utils/stringutil.h"
54 #ifndef KDEPIM_MOBILE_UI
55 #include "templatesconfiguration.h"
56 #endif
57 #include "templatesconfiguration_kfg.h"
58 // other kdepim headers:
59 #include <kpimidentities/identity.h>
60 #include <kpimidentities/signatureconfigurator.h>
61 
62 #include "messagecomposer/autocorrection/composerautocorrectionlanguage.h"
63 
64 #include <libkdepim/addressline/addresseelineedit.h>
65 // libkleopatra:
66 #include "libkleo/ui/keyrequester.h"
67 #include "kleo/cryptobackendfactory.h"
68 
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;
75 
76 // other KDE headers:
77 #include <klocale.h>
78 #include <kmessagebox.h>
79 #include <kfileitem.h>
80 #include <kurl.h>
81 #include <kdebug.h>
82 #include <kpushbutton.h>
83 #include <kcombobox.h>
84 #include <ktabwidget.h>
85 #include <KStandardDirs>
86 #include <sonnet/dictionarycombobox.h>
87 
88 // Qt headers:
89 #include <QLabel>
90 #include <QCheckBox>
91 #include <QVBoxLayout>
92 #include <QGridLayout>
93 #include <QFile>
94 
95 // other headers:
96 #include <gpgme++/key.h>
97 #include <iterator>
98 #include <algorithm>
99 
100 #include <akonadi/entitydisplayattribute.h>
101 #include <akonadi/collectionmodifyjob.h>
102 
103 
104 using namespace KPIM;
105 using namespace MailTransport;
106 using namespace MailCommon;
107 
108 namespace KMail {
109 
110 IdentityDialog::IdentityDialog( QWidget * parent )
111  : KDialog( parent )
112 {
113  setCaption( i18n("Edit Identity") );
114 #ifndef KDEPIM_MOBILE_UI
115  setButtons( Ok|Cancel|Help );
116 #else
117  setButtons( Ok|Cancel );
118 #endif
119  setDefaultButton( Ok );
120 
121 #ifdef Q_OS_WINCE
122  setWindowState( Qt::WindowFullScreen );
123 #endif
124 
125  // tmp. vars:
126  QWidget * tab;
127  QLabel * label;
128  int row;
129  QGridLayout * glay;
130  QString msg;
131 
132  //
133  // Tab Widget: General
134  //
135  row = -1;
136  QWidget *page = new QWidget( this );
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 );
144 
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 );
152 
153  // "Name" line edit and label:
154  ++row;
155  mNameEdit = new KLineEdit( tab );
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 );
167 
168  // "Organization" line edit and label:
169  ++row;
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 "
178  "is sent out.</p>"
179  "<p>It is safe (and normal) to leave this blank.</p></qt>");
180  label->setWhatsThis( msg );
181  mOrganizationEdit->setWhatsThis( msg );
182 
183  // "Email Address" line edit and label:
184  // (row 3: spacer)
185  ++row;
186  mEmailEdit = new KLineEdit( tab );
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 );
200 
201  KPIMUtils::EmailValidator* emailValidator = new KPIMUtils::EmailValidator( this );
202  mEmailEdit->setValidator( emailValidator );
203 
204  // "Email Aliases" stsring text edit and label:
205  ++row;
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>"
215  "<p>Example:</p>"
216  "<table>"
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>"
219  "</table>"
220  "<p>Type one alias address per line.</p></qt>");
221  label->setToolTip( msg );
222  mAliasEdit->setWhatsThis( msg );
223 
224  //
225  // Tab Widget: Cryptography
226  //
227  row = -1;
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 );
234 
235  // "OpenPGP Signature Key" requester and label:
236  ++row;
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 );
243 
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>");
250 
251  label = new QLabel( i18n("OpenPGP signing key:"), tab );
252  label->setBuddy( mPGPSigningKeyRequester );
253  mPGPSigningKeyRequester->setWhatsThis( msg );
254  label->setWhatsThis( msg );
255 
256  glay->addWidget( label, row, 0 );
257  glay->addWidget( mPGPSigningKeyRequester, row, 1 );
258 
259 
260  // "OpenPGP Encryption Key" requester and label:
261  ++row;
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 );
269 
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 );
281 
282  glay->addWidget( label, row, 0 );
283  glay->addWidget( mPGPEncryptionKeyRequester, row, 1 );
284 
285 
286  // "S/MIME Signature Key" requester and label:
287  ++row;
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 );
294 
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 );
306 
307  const Kleo::CryptoBackend::Protocol * smimeProtocol
308  = Kleo::CryptoBackendFactory::instance()->smime();
309 
310  label->setEnabled( smimeProtocol );
311  mSMIMESigningKeyRequester->setEnabled( smimeProtocol );
312 
313  // "S/MIME Encryption Key" requester and label:
314  ++row;
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 );
322 
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 );
333 
334  glay->addWidget( label, row, 0 );
335  glay->addWidget( mSMIMEEncryptionKeyRequester, row, 1 );
336 
337  label->setEnabled( smimeProtocol );
338  mSMIMEEncryptionKeyRequester->setEnabled( smimeProtocol );
339 
340  // "Preferred Crypto Message Format" combobox and label:
341  ++row;
342  mPreferredCryptoMessageFormat = new KComboBox( tab );
343  mPreferredCryptoMessageFormat->setEditable( false );
344  QStringList l;
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 );
353 
354  glay->addWidget( label, row, 0 );
355  glay->addWidget( mPreferredCryptoMessageFormat, row, 1 );
356 
357 
358  ++row;
359  mAutoSign = new QCheckBox(i18n("Automatically sign messages"));
360  glay->addWidget( mAutoSign, row, 0 );
361 
362  ++row;
363  glay->setRowStretch( row, 1 );
364 
365  //
366  // Tab Widget: Advanced
367  //
368  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() );
374  // the last (empty) row takes all the remaining space
375  glay->setColumnStretch( 1, 1 );
376 
377  // "Reply-To Address" line edit and label:
378  ++row;
379  mReplyToEdit = new KPIM::AddresseeLineEdit( tab, true );
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> "
388  "address.</p>"
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 );
397 
398 
399 
400  // "CC addresses" line edit and label:
401  ++row;
402  mCcEdit = new KPIM::AddresseeLineEdit( tab, true );
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 );
418 
419 
420  // "BCC addresses" line edit and label:
421  ++row;
422  mBccEdit = new KPIM::AddresseeLineEdit( tab, true );
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 );
439 
440  // "Dictionary" combo box and label:
441  ++row;
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 );
447 
448  // "Sent-mail Folder" combo box and label:
449  ++row;
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)));
456 
457  // "Drafts Folder" combo box and label:
458  ++row;
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 );
465 
466  // "Templates Folder" combo box and label:
467  ++row;
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 );
474 
475  // "Special transport" combobox and label:
476  ++row;
477  mTransportCheck = new QCheckBox( i18n("Outgoing Account:"), tab );
478  glay->addWidget( mTransportCheck, row, 0 );
479  mTransportCombo = new TransportComboBox( tab );
480  mTransportCombo->setEnabled( false ); // since !mTransportCheck->isChecked()
481  glay->addWidget( mTransportCombo, row, 1 );
482  connect( mTransportCheck, SIGNAL(toggled(bool)),
483  mTransportCombo, SLOT(setEnabled(bool)) );
484 
485  ++row;
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 );
491 
492 
493  ++row;
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 );
499 
500  ++row;
501  glay->setRowStretch( row, 1 );
502 
503  // the last row is a spacer
504 
505  //
506  // Tab Widget: Templates
507  //
508  tab = new QWidget( mTabWidget );
509  vlay = new QVBoxLayout( tab );
510  vlay->setMargin( marginHint() );
511  vlay->setSpacing( spacingHint() );
512 
513  QHBoxLayout *tlay = new QHBoxLayout();
514  vlay->addLayout( tlay );
515 
516  mCustom = new QCheckBox( i18n("&Use custom message templates for this identity"), tab );
517  tlay->addWidget( mCustom, Qt::AlignLeft );
518 
519 #ifndef KDEPIM_MOBILE_UI
520  mWidget = new TemplateParser::TemplatesConfiguration( tab, QLatin1String("identity-templates") );
521  mWidget->setEnabled( false );
522 
523  // Move the help label outside of the templates configuration widget,
524  // so that the help can be read even if the widget is not enabled.
525  tlay->addStretch( 9 );
526  tlay->addWidget( mWidget->helpLabel(), Qt::AlignRight );
527 
528  vlay->addWidget( mWidget );
529 #endif
530 
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)) );
540 #endif
541  connect( mCustom, SIGNAL(toggled(bool)),
542  mCopyGlobal, SLOT(setEnabled(bool)) );
543  connect( mCopyGlobal, SIGNAL(clicked()),
544  this, SLOT(slotCopyGlobal()) );
545 #ifdef KDEPIM_MOBILE_UI
546  tab->hide(); // not yet mobile ready
547 #else
548  mTabWidget->addTab( tab, i18n("Templates") );
549 #endif
550 
551  //
552  // Tab Widget: Signature
553  //
554  mSignatureConfigurator = new KPIMIdentities::SignatureConfigurator( mTabWidget );
555  mSignatureConfigurator->layout()->setMargin( KDialog::marginHint() );
556  mTabWidget->addTab( mSignatureConfigurator, i18n("Signature") );
557 
558  //
559  // Tab Widget: Picture
560  //
561 
562 #ifndef KDEPIM_MOBILE_UI
563  mXFaceConfigurator = new XFaceConfigurator( mTabWidget );
564  mXFaceConfigurator->layout()->setMargin( KDialog::marginHint() );
565  mTabWidget->addTab( mXFaceConfigurator, i18n("Picture") );
566 #endif
567 
568 #ifndef KCM_KPIMIDENTITIES_STANDALONE
569  resize( GlobalSettings::self()->identityDialogSize() );
570 #endif
571  mNameEdit->setFocus();
572 
573  connect( mTabWidget, SIGNAL(currentChanged(int)),
574  SLOT(slotAboutToShow(int)) );
575  setHelp( QLatin1String("configure-identity"), QLatin1String("kmail") );
576 }
577 
578 IdentityDialog::~IdentityDialog() {
579 #ifndef KCM_KPIMIDENTITIES_STANDALONE
580  GlobalSettings::self()->setIdentityDialogSize( size() );
581 #endif
582 }
583 
584 void IdentityDialog::slotAboutToShow( int index ) {
585  QWidget *w = mTabWidget->widget( index );
586  if ( w == mCryptographyTab ) {
587  // set the configured email address as initial query of the key
588  // requesters:
589  const QString email = mEmailEdit->text().trimmed();
590  mPGPEncryptionKeyRequester->setInitialQuery( email );
591  mPGPSigningKeyRequester->setInitialQuery( email );
592  mSMIMEEncryptionKeyRequester->setInitialQuery( email );
593  mSMIMESigningKeyRequester->setInitialQuery( email );
594  }
595 }
596 
597 void IdentityDialog::slotCopyGlobal() {
598 #ifndef KDEPIM_MOBILE_UI
599  mWidget->loadFromGlobal();
600 #endif
601 }
602 
603 namespace {
604 struct DoesntMatchEMailAddress {
605  explicit DoesntMatchEMailAddress( const QString & s )
606  : email( s.trimmed().toLower() ) {}
607  bool operator()( const GpgME::Key & key ) const;
608 private:
609  bool checkForEmail( const char * email ) const;
610  static QString extractEmail( const char * email );
611  const QString email;
612 };
613 
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() ) )
619  return false;
620  return true; // note the negation!
621 }
622 
623 bool DoesntMatchEMailAddress::checkForEmail( const char * e ) const {
624  const QString em = extractEmail( e );
625  return !em.isEmpty() && email.toLower() == em.toLower();
626 }
627 
628 QString DoesntMatchEMailAddress::extractEmail( const char * e ) {
629  if ( !e || !*e )
630  return QString();
631  const QString em = QString::fromUtf8( e );
632  if ( e[0] == '<' )
633  return em.mid( 1, em.length() - 2 );
634  else
635  return em;
636 }
637 }
638 
639 void IdentityDialog::slotButtonClicked( int button )
640 {
641  if ( button != KDialog::Ok ) {
642  KDialog::slotButtonClicked( button );
643  return;
644  }
645 
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 ) );
651  return;
652  }
653  }
654 
655  // Validate email addresses
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") );
660  return;
661  }
662 
663  // Check if the 'Reply to' and 'BCC' recipients are valid
664  const QString recipients = mReplyToEdit->text().trimmed() + QLatin1String( ", " ) + mBccEdit->text().trimmed() + QLatin1String( ", " ) + mCcEdit->text().trimmed();
665  AddressValidationJob *job = new AddressValidationJob( recipients, this, this );
666  job->setProperty( "email", email );
667  connect( job, SIGNAL(result(KJob*)), SLOT(slotDelayedButtonClicked(KJob*)) );
668  job->start();
669 }
670 
671 void IdentityDialog::slotDelayedButtonClicked( KJob *job )
672 {
673  const AddressValidationJob *validationJob = qobject_cast<AddressValidationJob*>( job );
674 
675  // Abort if one of the recipient addresses is invalid
676  if ( !validationJob->isValid() )
677  return;
678 
679  const QString email = validationJob->property( "email" ).toString();
680 
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();
689 
690  QString msg;
691  bool err = false;
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 "
696  "identity (%1).\n"
697  "This might result in warning messages on the receiving side "
698  "when trying to verify signatures made with this configuration.", email);
699  err = true;
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);
705  err = true;
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 "
710  "identity (%1).\n"
711  "This might result in warning messages on the receiving side "
712  "when trying to verify signatures made with this configuration.", email);
713  err = true;
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);
719  err = true;
720  }
721 
722  if ( err ) {
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) {
729  return;
730  }
731  }
732 
733 
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" ) );
740  return;
741  }
742  }
743 
744  accept();
745 }
746 
747 bool IdentityDialog::checkFolderExists( const QString & folderID,
748  const QString & msg )
749 {
750  const Akonadi::Collection folder = CommonKernel->collectionFromId( folderID.toLongLong() );
751  if ( !folder.isValid() ) {
752  KMessageBox::sorry( this, msg );
753  return false;
754  }
755 
756  return true;
757 }
758 
759 void IdentityDialog::setIdentity( KPIMIdentities::Identity & ident ) {
760 
761  setCaption( i18n("Edit Identity \"%1\"", ident.identityName() ) );
762 
763  // "General" tab:
764  mNameEdit->setText( ident.fullName() );
765  mOrganizationEdit->setText( ident.organization() );
766  mEmailEdit->setText( ident.primaryEmailAddress() );
767  mAliasEdit->setStringList( ident.emailAliases() );
768 
769  // "Cryptography" tab:
770  mPGPSigningKeyRequester->setFingerprint( QLatin1String(ident.pgpSigningKey()) );
771  mPGPEncryptionKeyRequester->setFingerprint( QLatin1String(ident.pgpEncryptionKey()) );
772  mSMIMESigningKeyRequester->setFingerprint( QLatin1String(ident.smimeSigningKey()) );
773  mSMIMEEncryptionKeyRequester->setFingerprint( QLatin1String(ident.smimeEncryptionKey()) );
774 
775  mPreferredCryptoMessageFormat->setCurrentIndex( format2cb(
776  Kleo::stringToCryptoMessageFormat( ident.preferredCryptoMessageFormat() ) ) );
777  mAutoSign->setChecked(ident.pgpAutoSign());
778 
779  // "Advanced" tab:
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 );
787  if ( transport )
788  mTransportCombo->setCurrentTransport( transport->id() );
789  mDictionaryCombo->setCurrentByDictionaryName( ident.dictionary() );
790 
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 "
798  "will be used.",
799  ident.identityName() ) ) ) {
800  mFccCombo->setCollection( CommonKernel->sentCollectionFolder() );
801  }
802  else {
803  mFccCombo->setCollection( Akonadi::Collection( ident.fcc().toLongLong() ) );
804  }
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 "
810  "will be used.",
811  ident.identityName() ) ) ) {
812  mDraftsCombo->setCollection( CommonKernel->draftsCollectionFolder() );
813  }
814  else
815  mDraftsCombo->setCollection( Akonadi::Collection( ident.drafts().toLongLong() ) );
816 
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() );
824 
825  }
826  else
827  mTemplatesCombo->setCollection( Akonadi::Collection( ident.templates().toLongLong() ) );
828 
829  mVcardFilename = ident.vCardFile();
830 
831  mAutoCorrectionLanguage->setLanguage(ident.autocorrectionLanguage());
832  updateVcardButton();
833  if(mVcardFilename.isEmpty()) {
834  mVcardFilename = KStandardDirs::locateLocal("appdata",ident.identityName() + QLatin1String(".vcf"));
835  }
836  mAttachMyVCard->setChecked(ident.attachVcard());
837  // "Templates" tab:
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 );
844 #endif
845 
846  // "Signature" tab:
847  mSignatureConfigurator->setImageLocation( ident );
848  mSignatureConfigurator->setSignature( ident.signature() );
849 #ifndef KDEPIM_MOBILE_UI
850  mXFaceConfigurator->setXFace( ident.xface() );
851  mXFaceConfigurator->setXFaceEnabled( ident.isXFaceEnabled() );
852 #endif
853 }
854 
855 void IdentityDialog::updateIdentity( KPIMIdentities::Identity & ident ) {
856  // "General" tab:
857  ident.setFullName( mNameEdit->text() );
858  ident.setOrganization( mOrganizationEdit->text() );
859  QString email = mEmailEdit->text();
860  ident.setPrimaryEmailAddress( email );
861  ident.setEmailAliases( mAliasEdit->stringList() );
862  // "Cryptography" tab:
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());
870  // "Advanced" tab:
871  ident.setReplyToAddr( mReplyToEdit->text() );
872  ident.setBcc( mBccEdit->text() );
873  ident.setCc( mCcEdit->text() );
874  ident.setTransport( mTransportCheck->isChecked() ? QString::number( mTransportCombo->currentTransportId() )
875  : QString() );
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 );
884  }
885  else
886  ident.setFcc( QString() );
887 
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 );
894  }
895  else
896  ident.setDrafts( QString() );
897 
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 );
904  }
905  else
906  ident.setTemplates( QString() );
907  ident.setVCardFile(mVcardFilename);
908  ident.setAutocorrectionLanguage(mAutoCorrectionLanguage->language());
909  updateVcardButton();
910  ident.setAttachVcard(mAttachMyVCard->isChecked());
911 
912  // "Templates" tab:
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());
919  t.writeConfig();
920  mWidget->saveToIdentity( identity );
921 #endif
922 
923  // "Signature" tab:
924  ident.setSignature( mSignatureConfigurator->signature() );
925 #ifndef KDEPIM_MOBILE_UI
926  ident.setXFace( mXFaceConfigurator->xface() );
927  ident.setXFaceEnabled( mXFaceConfigurator->isXFaceEnabled() );
928 #endif
929 
930 }
931 void IdentityDialog::slotEditVcard()
932 {
933  if(QFile(mVcardFilename).exists()) {
934  editVcard(mVcardFilename);
935  } else {
936  if ( !MailCommon::Kernel::self()->kernelIsRegistered() ) {
937  return;
938  }
939  KPIMIdentities::IdentityManager *manager = KernelIf->identityManager();
940 
941  QPointer<IdentityAddVcardDialog> dlg = new IdentityAddVcardDialog(manager, this);
942  if(dlg->exec()) {
943  IdentityAddVcardDialog::DuplicateMode mode = dlg->duplicateMode();
944  switch(mode) {
945  case IdentityAddVcardDialog::Empty: {
946  editVcard(mVcardFilename);
947  break;
948  }
949  case IdentityAddVcardDialog::ExistingEntry: {
950  KPIMIdentities::Identity ident = manager->modifyIdentityForName( dlg->duplicateVcardFromIdentity() );
951  const QString filename = ident.vCardFile();
952  if(!filename.isEmpty()) {
953  QFile::copy(filename,mVcardFilename);
954  }
955  editVcard(mVcardFilename);
956  break;
957  }
958  }
959  }
960  delete dlg;
961  }
962 }
963 
964 void IdentityDialog::editVcard(const QString &filename)
965 {
966  IdentityEditVcardDialog dlg(filename, this);
967  if(dlg.exec()) {
968  mVcardFilename = dlg.saveVcard();
969  }
970  updateVcardButton();
971 }
972 
973 void IdentityDialog::updateVcardButton()
974 {
975  if(!QFile(mVcardFilename).exists()) {
976  mEditVCard->setText(i18n("Create..."));
977  } else {
978  mEditVCard->setText(i18n("Edit..."));
979  }
980 }
981 
982 }
983 
984 #include "identitydialog.moc"
AddressValidationJob
Definition: addressvalidationjob.h:28
globalsettings.h
identityaddvcarddialog.h
KMail::IdentityDialog::slotCopyGlobal
void slotCopyGlobal()
Definition: identitydialog.cpp:597
KMail::IdentityDialog::updateIdentity
void updateIdentity(KPIMIdentities::Identity &ident)
Definition: identitydialog.cpp:855
KMail::IdentityDialog::slotAboutToShow
void slotAboutToShow(int)
Definition: identitydialog.cpp:584
IdentityEditVcardDialog
Definition: identityeditvcarddialog.h:27
email
const QString email
Definition: identitydialog.cpp:611
AddressValidationJob::start
void start()
Definition: addressvalidationjob.cpp:111
QWidget
AddressValidationJob::isValid
bool isValid() const
Definition: addressvalidationjob.cpp:118
IdentityAddVcardDialog::DuplicateMode
DuplicateMode
Definition: identityaddvcarddialog.h:32
KDialog
KMail::IdentityDialog::~IdentityDialog
~IdentityDialog()
Definition: identitydialog.cpp:578
KMail::XFaceConfigurator::setXFaceEnabled
void setXFaceEnabled(bool enable)
Definition: xfaceconfigurator.cpp:212
KMail::XFaceConfigurator::setXFace
void setXFace(const QString &text)
Definition: xfaceconfigurator.cpp:222
addresseelineedit.h
KPIM::AddresseeLineEdit
KMail::XFaceConfigurator::isXFaceEnabled
bool isXFaceEnabled() const
Definition: xfaceconfigurator.cpp:207
KMail::IdentityDialog::slotButtonClicked
void slotButtonClicked(int button)
Definition: identitydialog.cpp:639
IdentityAddVcardDialog::Empty
Definition: identityaddvcarddialog.h:33
GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:30
kmkernel.h
KLineEdit
xfaceconfigurator.h
IdentityAddVcardDialog
Definition: identityaddvcarddialog.h:28
identitydialog.h
identityeditvcarddialog.h
QLabel
KComboBox
addressvalidationjob.h
KMail::XFaceConfigurator
Definition: xfaceconfigurator.h:32
IdentityAddVcardDialog::ExistingEntry
Definition: identityaddvcarddialog.h:34
KMail::XFaceConfigurator::xface
QString xface() const
Definition: xfaceconfigurator.cpp:217
KJob
KMail::IdentityDialog::setIdentity
void setIdentity(KPIMIdentities::Identity &ident)
Definition: identitydialog.cpp:759
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal