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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • crypto
  • gui
signencryptemailconflictdialog.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/gui/signencryptemailconflictdialog.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2009 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "signencryptemailconflictdialog.h"
36 
37 #include <crypto/sender.h>
38 #include <crypto/recipient.h>
39 
40 #include <dialogs/certificateselectiondialog.h>
41 
42 #include <models/predicates.h>
43 
44 #include <utils/gui-helper.h>
45 #include <utils/formatting.h>
46 #include <utils/kleo_assert.h>
47 #include <utils/kdsignalblocker.h>
48 
49 #include <kleo/stl_util.h>
50 
51 #include <gpgme++/key.h>
52 
53 #include <kmime/kmime_header_parsing.h>
54 
55 #include <KLocalizedString>
56 
57 #include <QLabel>
58 #include <QComboBox>
59 #include <QLayout>
60 #include <QStackedWidget>
61 #include <QToolButton>
62 #include <QGroupBox>
63 #include <QDialogButtonBox>
64 #include <QCheckBox>
65 #include <QRadioButton>
66 #include <QPushButton>
67 #include <QStylePainter>
68 #include <QStyle>
69 #include <QPointer>
70 
71 #include <boost/shared_ptr.hpp>
72 #include <boost/bind.hpp>
73 
74 #include <iterator>
75 
76 using namespace Kleo;
77 using namespace Kleo::Crypto;
78 using namespace Kleo::Crypto::Gui;
79 using namespace Kleo::Dialogs;
80 using namespace GpgME;
81 using namespace boost;
82 
83 Q_DECLARE_METATYPE( GpgME::Key )
84 Q_DECLARE_METATYPE( GpgME::UserID )
85 
86 namespace {
87 
88  // A QComboBox with an initial text (as known from web browsers)
89  //
90  // only works with read-only QComboBoxen, doesn't affect sizeHint
91  // as it should...
92  //
93  class ComboBox : public QComboBox {
94  Q_OBJECT
95  Q_PROPERTY( QString initialText READ initialText WRITE setInitialText )
96  Q_PROPERTY( QIcon initialIcon READ initialIcon WRITE setInitialIcon )
97  public:
98  explicit ComboBox( QWidget * parent=0 )
99  : QComboBox( parent ),
100  m_initialText(),
101  m_initialIcon()
102  {
103 
104  }
105 
106  explicit ComboBox( const QString & initialText, QWidget * parent=0 )
107  : QComboBox( parent ),
108  m_initialText( initialText ),
109  m_initialIcon()
110  {
111 
112  }
113 
114  explicit ComboBox( const QIcon & initialIcon, const QString & initialText, QWidget * parent=0 )
115  : QComboBox( parent ),
116  m_initialText( initialText ),
117  m_initialIcon( initialIcon )
118  {
119 
120  }
121 
122  QString initialText() const { return m_initialText; }
123  QIcon initialIcon() const { return m_initialIcon; }
124 
125  public Q_SLOTS:
126  void setInitialText( const QString & txt ) {
127  if ( txt == m_initialText )
128  return;
129  m_initialText = txt;
130  if ( currentIndex() == -1 )
131  update();
132  }
133  void setInitialIcon( const QIcon & icon ) {
134  if ( icon.cacheKey() == m_initialIcon.cacheKey() )
135  return;
136  m_initialIcon = icon;
137  if ( currentIndex() == -1 )
138  update();
139  }
140 
141  protected:
142  void paintEvent( QPaintEvent * ) {
143  QStylePainter p( this );
144  p.setPen( palette().color( QPalette::Text ) );
145  QStyleOptionComboBox opt;
146  initStyleOption( &opt );
147  p.drawComplexControl( QStyle::CC_ComboBox, opt );
148 
149  if ( currentIndex() == -1 ) {
150  opt.currentText = m_initialText;
151  opt.currentIcon = m_initialIcon;
152  }
153  p.drawControl( QStyle::CE_ComboBoxLabel, opt );
154  }
155 
156  private:
157  QString m_initialText;
158  QIcon m_initialIcon;
159  };
160 
161  static QString make_initial_text( const std::vector<Key> & keys ) {
162  if ( keys.empty() )
163  return i18n("(no matching certificates found)");
164  else
165  return i18n("Please select a certificate");
166  }
167 
168  class KeysComboBox : public ComboBox {
169  Q_OBJECT
170  public:
171  explicit KeysComboBox( QWidget * parent=0 )
172  : ComboBox( parent ) {}
173  explicit KeysComboBox( const QString & initialText, QWidget * parent=0 )
174  : ComboBox( initialText, parent ) {}
175  explicit KeysComboBox( const std::vector<Key> & keys, QWidget * parent=0 )
176  : ComboBox( make_initial_text( keys ), parent ) { setKeys( keys ); }
177 
178  void setKeys( const std::vector<Key> & keys ) {
179  clear();
180  Q_FOREACH( const Key & key, keys )
181  addItem( Formatting::formatForComboBox( key ), qVariantFromValue( key ) );
182  }
183 
184  std::vector<Key> keys() const {
185  std::vector<Key> result;
186  result.reserve( count() );
187  for ( int i = 0, end = count() ; i != end ; ++i )
188  result.push_back( qvariant_cast<Key>( itemData(i) ) );
189  return result;;
190  }
191 
192  int findOrAdd( const Key & key ) {
193  for ( int i = 0, end = count() ; i != end ; ++i )
194  if ( _detail::ByFingerprint<std::equal_to>()( key, qvariant_cast<Key>( itemData(i) ) ) )
195  return i;
196  insertItem( 0, Formatting::formatForComboBox( key ), qVariantFromValue( key ) );
197  return 0;
198  }
199 
200  void addAndSelectCertificate( const Key & key ) {
201  setCurrentIndex( findOrAdd( key ) );
202  }
203 
204  Key currentKey() const {
205  return qvariant_cast<Key>( itemData( currentIndex() ) );
206  }
207 
208  };
209 
210  class Line {
211  public:
212  static const unsigned int NumColumns = 4;
213 
214  Line( const QString & toFrom, const QString & mailbox, const std::vector<Key> & pgp, bool pgpAmbig, const std::vector<Key> & cms, bool cmsAmbig, QWidget * q, QGridLayout & glay )
215  : pgpAmbiguous( pgpAmbig ),
216  cmsAmbiguous( cmsAmbig ),
217  toFromLB( new QLabel( toFrom, q ) ),
218  mailboxLB( new QLabel( mailbox, q ) ),
219  sbox( new QStackedWidget( q ) ),
220  pgpCB( new KeysComboBox( pgp, sbox ) ),
221  cmsCB( new KeysComboBox( cms, sbox ) ),
222  noProtocolCB( new KeysComboBox( i18n("(please choose between OpenPGP and S/MIME first)"), sbox ) ),
223  toolTB( new QToolButton( q ) )
224  {
225  KDAB_SET_OBJECT_NAME( toFromLB );
226  KDAB_SET_OBJECT_NAME( mailboxLB );
227  KDAB_SET_OBJECT_NAME( noProtocolCB );
228  KDAB_SET_OBJECT_NAME( pgpCB );
229  KDAB_SET_OBJECT_NAME( cmsCB );
230  KDAB_SET_OBJECT_NAME( sbox );
231  KDAB_SET_OBJECT_NAME( toolTB );
232 
233  QFont bold;
234  bold.setBold( true );
235  toFromLB->setFont( bold );
236 
237  mailboxLB->setTextFormat( Qt::PlainText );
238  toolTB->setText( i18n("...") );
239 
240  pgpCB->setEnabled( !pgp.empty() );
241  cmsCB->setEnabled( !cms.empty() );
242  noProtocolCB->setEnabled( false );
243 
244  pgpCB->setKeys( pgp );
245  if ( pgpAmbiguous )
246  pgpCB->setCurrentIndex( -1 );
247 
248  cmsCB->setKeys( cms );
249  if ( cmsAmbiguous )
250  cmsCB->setCurrentIndex( -1 );
251 
252  sbox->addWidget( pgpCB );
253  sbox->addWidget( cmsCB );
254  sbox->addWidget( noProtocolCB );
255  sbox->setCurrentWidget( noProtocolCB );
256 
257  const int row = glay.rowCount();
258  unsigned int col = 0;
259  glay.addWidget( toFromLB, row, col++ );
260  glay.addWidget( mailboxLB, row, col++ );
261  glay.addWidget( sbox, row, col++ );
262  glay.addWidget( toolTB, row, col++ );
263  assert( col == NumColumns );
264 
265  q->connect( pgpCB, SIGNAL(currentIndexChanged(int)), SLOT(slotCompleteChanged()) );
266  q->connect( cmsCB, SIGNAL(currentIndexChanged(int)), SLOT(slotCompleteChanged()) );
267  q->connect( toolTB, SIGNAL(clicked()), SLOT(slotCertificateSelectionDialogRequested()) );
268  }
269 
270  KeysComboBox * comboBox( Protocol proto ) const {
271  if ( proto == OpenPGP )
272  return pgpCB;
273  if ( proto == CMS )
274  return cmsCB;
275  return 0;
276  }
277 
278  QString mailboxText() const {
279  return mailboxLB->text();
280  }
281 
282  void addAndSelectCertificate( const Key & key ) const {
283  if ( KeysComboBox * const cb = comboBox( key.protocol() ) ) {
284  cb->addAndSelectCertificate( key );
285  cb->setEnabled( true );
286  }
287  }
288 
289  void showHide( Protocol proto, bool & first, bool showAll, bool op ) const {
290  if ( op && ( showAll || wasInitiallyAmbiguous( proto ) ) ) {
291 
292  toFromLB->setVisible( first );
293  first = false;
294 
295  QFont font = mailboxLB->font();
296  font.setBold( wasInitiallyAmbiguous( proto ) );
297  mailboxLB->setFont( font );
298 
299  sbox->setCurrentIndex( proto );
300 
301  mailboxLB->show();
302  sbox->show();
303  toolTB->show();
304  } else {
305  toFromLB->hide();
306  mailboxLB->hide();
307  sbox->hide();
308  toolTB->hide();
309  }
310 
311  }
312 
313  bool wasInitiallyAmbiguous( Protocol proto ) const {
314  return proto == OpenPGP && pgpAmbiguous
315  || proto == CMS && cmsAmbiguous ;
316  }
317 
318  bool isStillAmbiguous( Protocol proto ) const {
319  kleo_assert( proto == OpenPGP || proto == CMS );
320  const KeysComboBox * const cb = comboBox( proto );
321  return cb->currentIndex() == -1 ;
322  }
323 
324  Key key( Protocol proto ) const {
325  kleo_assert( proto == OpenPGP || proto == CMS );
326  const KeysComboBox * const cb = comboBox( proto );
327  return cb->currentKey();
328  }
329 
330  const QToolButton * toolButton() const { return toolTB; }
331 
332  void kill() {
333  delete toFromLB;
334  delete mailboxLB;
335  delete sbox;
336  delete toolTB;
337  }
338 
339  private:
340  bool pgpAmbiguous : 1;
341  bool cmsAmbiguous : 1;
342 
343  QLabel * toFromLB;
344  QLabel * mailboxLB;
345  QStackedWidget * sbox;
346  KeysComboBox * pgpCB;
347  KeysComboBox * cmsCB;
348  KeysComboBox * noProtocolCB;
349  QToolButton * toolTB;
350 
351  };
352 
353 }
354 
355 static CertificateSelectionDialog *
356 create_certificate_selection_dialog( QWidget * parent, Protocol proto ) {
357  CertificateSelectionDialog * const dlg = new CertificateSelectionDialog( parent );
358  dlg->setOptions( proto == OpenPGP ? CertificateSelectionDialog::OpenPGPFormat :
359  proto == CMS ? CertificateSelectionDialog::CMSFormat : CertificateSelectionDialog::AnyFormat );
360  return dlg;
361 }
362 
363 static CertificateSelectionDialog *
364 create_encryption_certificate_selection_dialog( QWidget * parent, Protocol proto, const QString & mailbox ) {
365  CertificateSelectionDialog * const dlg = create_certificate_selection_dialog( parent, proto );
366  dlg->setCustomLabelText( i18n("Please select an encryption certificate for recipient \"%1\"", mailbox ) );
367  dlg->setOptions( CertificateSelectionDialog::SingleSelection |
368  CertificateSelectionDialog::EncryptOnly |
369  dlg->options() );
370  return dlg;
371 }
372 
373 static CertificateSelectionDialog *
374 create_signing_certificate_selection_dialog( QWidget * parent, Protocol proto, const QString & mailbox ) {
375  CertificateSelectionDialog * const dlg = create_certificate_selection_dialog( parent, proto );
376  dlg->setCustomLabelText( i18n("Please select a signing certificate for sender \"%1\"", mailbox ) );
377  dlg->setOptions( CertificateSelectionDialog::SingleSelection |
378  CertificateSelectionDialog::SignOnly |
379  CertificateSelectionDialog::SecretKeys |
380  dlg->options() );
381  return dlg;
382 }
383 
384 static QString make_top_label_conflict_text( bool sign, bool enc ) {
385  return
386  sign && enc ? i18n("Kleopatra cannot unambiguously determine matching certificates "
387  "for all recipients/senders of the message.\n"
388  "Please select the correct certificates for each recipient:") :
389  sign ? i18n("Kleopatra cannot unambiguously determine matching certificates "
390  "for the sender of the message.\n"
391  "Please select the correct certificates for the sender:") :
392  enc ? i18n("Kleopatra cannot unambiguously determine matching certificates "
393  "for all recipients of the message.\n"
394  "Please select the correct certificates for each recipient:" ) :
395  /* else */ (kleo_assert_fail( sign || enc ),QString()) ;
396 }
397 
398 static QString make_top_label_quickmode_text( bool sign, bool enc ) {
399  return
400  enc ? i18n("Please verify that correct certificates have been selected for each recipient:") :
401  sign ? i18n("Please verify that the correct certificate has been selected for the sender:") :
402  /*else*/ (kleo_assert_fail( sign || enc ),QString()) ;
403 }
404 
405 class SignEncryptEMailConflictDialog::Private {
406  friend class ::Kleo::Crypto::Gui::SignEncryptEMailConflictDialog;
407  SignEncryptEMailConflictDialog * const q;
408 public:
409  explicit Private( SignEncryptEMailConflictDialog * qq )
410  : q( qq ),
411  senders(),
412  recipients(),
413  sign( true ),
414  encrypt( true ),
415  presetProtocol( UnknownProtocol ),
416  ui( q )
417  {
418 
419  }
420 
421 private:
422  void updateTopLabelText() {
423  ui.conflictTopLB.setText( make_top_label_conflict_text( sign, encrypt ) );
424  ui.quickModeTopLB.setText( make_top_label_quickmode_text( sign, encrypt ) );
425  }
426 
427  void showHideWidgets() {
428  const Protocol proto = q->selectedProtocol();
429  const bool quickMode = q->isQuickMode();
430 
431  const bool needProtocolSelection = presetProtocol == UnknownProtocol ;
432 
433  const bool needShowAllRecipientsCB =
434  quickMode ? false :
435  needProtocolSelection ? needShowAllRecipients( OpenPGP ) || needShowAllRecipients( CMS ) :
436  /* else */ needShowAllRecipients( proto )
437  ;
438 
439  ui.showAllRecipientsCB.setVisible( needShowAllRecipientsCB );
440 
441  ui.pgpRB.setVisible( needProtocolSelection );
442  ui.cmsRB.setVisible( needProtocolSelection );
443 
444  const bool showAll = !needShowAllRecipientsCB || ui.showAllRecipientsCB.isChecked();
445 
446  bool first;
447  first = true;
448  Q_FOREACH( const Line & line, ui.signers )
449  line.showHide( proto, first, showAll, sign );
450  ui.selectSigningCertificatesGB.setVisible( sign && ( showAll || !first ) );
451 
452  first = true;
453  Q_FOREACH( const Line & line, ui.recipients )
454  line.showHide( proto, first, showAll, encrypt );
455  ui.selectEncryptionCertificatesGB.setVisible( encrypt && ( showAll || !first ) );
456  }
457 
458  bool needShowAllRecipients( Protocol proto ) const {
459  if ( sign )
460  if ( const unsigned int num = kdtools::count_if( ui.signers, boost::bind( &Line::wasInitiallyAmbiguous, _1, proto ) ) )
461  if ( num != ui.signers.size() )
462  return true;
463  if ( encrypt )
464  if ( const unsigned int num = kdtools::count_if( ui.recipients, boost::bind( &Line::wasInitiallyAmbiguous, _1, proto ) ) )
465  if ( num != ui.recipients.size() )
466  return true;
467  return false;
468  }
469 
470  void createSendersAndRecipients() {
471  ui.clearSendersAndRecipients();
472 
473  ui.addSelectSigningCertificatesGB();
474  Q_FOREACH( const Sender & s, senders )
475  addSigner( s );
476 
477  ui.addSelectEncryptionCertificatesGB();
478  Q_FOREACH( const Sender & s, senders )
479  addRecipient( s );
480  Q_FOREACH( const Recipient & r, recipients )
481  addRecipient( r );
482  }
483 
484  void addSigner( const Sender & s ) {
485  ui.addSigner( s.mailbox().prettyAddress(),
486  s.signingCertificateCandidates( OpenPGP ),
487  s.isSigningAmbiguous( OpenPGP ),
488  s.signingCertificateCandidates( CMS ),
489  s.isSigningAmbiguous( CMS ),
490  q );
491  }
492 
493  void addRecipient( const Sender & s ) {
494  ui.addRecipient( s.mailbox().prettyAddress(),
495  s.encryptToSelfCertificateCandidates( OpenPGP ),
496  s.isEncryptionAmbiguous( OpenPGP ),
497  s.encryptToSelfCertificateCandidates( CMS ),
498  s.isEncryptionAmbiguous( CMS ),
499  q );
500  }
501 
502  void addRecipient( const Recipient & r ) {
503  ui.addRecipient( r.mailbox().prettyAddress(),
504  r.encryptionCertificateCandidates( OpenPGP ),
505  r.isEncryptionAmbiguous( OpenPGP ),
506  r.encryptionCertificateCandidates( CMS ),
507  r.isEncryptionAmbiguous( CMS ),
508  q );
509  }
510 
511  bool isComplete( Protocol proto ) const;
512 
513 private:
514  void enableDisableOkButton() {
515  ui.setOkButtonEnabled( q->isComplete() );
516  }
517  void slotCompleteChanged() {
518  enableDisableOkButton();
519  }
520  void slotShowAllRecipientsToggled( bool ) {
521  showHideWidgets();
522  }
523  void slotProtocolChanged() {
524  showHideWidgets();
525  enableDisableOkButton();
526  }
527  void slotCertificateSelectionDialogRequested() {
528  const QObject * const s = q->sender();
529  const Protocol proto = q->selectedProtocol();
530  QPointer<CertificateSelectionDialog> dlg;
531  Q_FOREACH( const Line & l, ui.signers )
532  if ( s == l.toolButton() ) {
533  dlg = create_signing_certificate_selection_dialog( q, proto, l.mailboxText() );
534  if ( dlg->exec() )
535  l.addAndSelectCertificate( dlg->selectedCertificate() );
536  // ### switch to key.protocol(), in case proto == UnknownProtocol
537  break;
538  }
539  Q_FOREACH( const Line & l, ui.recipients )
540  if ( s == l.toolButton() ) {
541  dlg = create_encryption_certificate_selection_dialog( q, proto, l.mailboxText() );
542  if ( dlg->exec() )
543  l.addAndSelectCertificate( dlg->selectedCertificate() );
544  // ### switch to key.protocol(), in case proto == UnknownProtocol
545  break;
546  }
547  delete dlg;
548  }
549 
550 private:
551  std::vector<Sender> senders;
552  std::vector<Recipient> recipients;
553 
554  bool sign : 1;
555  bool encrypt : 1;
556  Protocol presetProtocol;
557 
558 private:
559  struct Ui {
560  QLabel conflictTopLB, quickModeTopLB;
561  QCheckBox showAllRecipientsCB;
562  QRadioButton pgpRB, cmsRB;
563  QGroupBox selectSigningCertificatesGB;
564  QGroupBox selectEncryptionCertificatesGB;
565  QCheckBox quickModeCB;
566  QDialogButtonBox buttonBox;
567  QVBoxLayout vlay;
568  QHBoxLayout hlay;
569  QGridLayout glay;
570  std::vector<Line> signers, recipients;
571 
572  void setOkButtonEnabled( bool enable ) {
573  return buttonBox.button( QDialogButtonBox::Ok )->setEnabled( enable );
574  }
575 
576  explicit Ui( SignEncryptEMailConflictDialog * q )
577  : conflictTopLB( make_top_label_conflict_text( true, true ), q ),
578  quickModeTopLB( make_top_label_quickmode_text( true, true ), q ),
579  showAllRecipientsCB( i18n("Show all recipients"), q ),
580  pgpRB( i18n("OpenPGP"), q ),
581  cmsRB( i18n("S/MIME"), q ),
582  selectSigningCertificatesGB( i18n("Select Signing Certificate"), q ),
583  selectEncryptionCertificatesGB( i18n("Select Encryption Certificate"), q ),
584  quickModeCB( i18n("Only show this dialog in case of conflicts (experimental)"), q ),
585  buttonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, q ),
586  vlay( q ),
587  hlay(),
588  glay(),
589  signers(),
590  recipients()
591  {
592  KDAB_SET_OBJECT_NAME( conflictTopLB );
593  KDAB_SET_OBJECT_NAME( quickModeTopLB );
594  KDAB_SET_OBJECT_NAME( showAllRecipientsCB );
595  KDAB_SET_OBJECT_NAME( pgpRB );
596  KDAB_SET_OBJECT_NAME( cmsRB );
597  KDAB_SET_OBJECT_NAME( selectSigningCertificatesGB );
598  KDAB_SET_OBJECT_NAME( selectEncryptionCertificatesGB );
599  KDAB_SET_OBJECT_NAME( quickModeCB );
600  KDAB_SET_OBJECT_NAME( buttonBox );
601  KDAB_SET_OBJECT_NAME( hlay );
602  KDAB_SET_OBJECT_NAME( glay );
603  KDAB_SET_OBJECT_NAME( vlay );
604 
605  q->setWindowTitle( i18n("Select Certificates For Message") );
606 
607  conflictTopLB.hide();
608 
609  selectSigningCertificatesGB.setFlat( true );
610  selectEncryptionCertificatesGB.setFlat( true );
611  selectSigningCertificatesGB.setAlignment( Qt::AlignCenter );
612  selectEncryptionCertificatesGB.setAlignment( Qt::AlignCenter );
613 
614  glay.setColumnStretch( 2, 1 );
615  glay.setColumnStretch( 3, 1 );
616 
617  vlay.setSizeConstraint( QLayout::SetMinimumSize );
618 
619  vlay.addWidget( &conflictTopLB );
620  vlay.addWidget( &quickModeTopLB );
621 
622  hlay.addWidget( &showAllRecipientsCB );
623  hlay.addStretch( 1 );
624  hlay.addWidget( &pgpRB );
625  hlay.addWidget( &cmsRB );
626  vlay.addLayout( &hlay );
627 
628  addSelectSigningCertificatesGB();
629  addSelectEncryptionCertificatesGB();
630  vlay.addLayout( &glay );
631 
632  vlay.addStretch( 1 );
633 
634  vlay.addWidget( &quickModeCB, 0, Qt::AlignCenter );
635  vlay.addWidget( &buttonBox );
636 
637  connect( &buttonBox, SIGNAL(accepted()), q, SLOT(accept()) );
638  connect( &buttonBox, SIGNAL(rejected()), q, SLOT(reject()) );
639 
640  connect( &showAllRecipientsCB, SIGNAL(toggled(bool)),
641  q, SLOT(slotShowAllRecipientsToggled(bool)) );
642  connect( &pgpRB, SIGNAL(toggled(bool)),
643  q, SLOT(slotProtocolChanged()) );
644  connect( &cmsRB, SIGNAL(toggled(bool)),
645  q, SLOT(slotProtocolChanged()) );
646  }
647 
648  void clearSendersAndRecipients() {
649  std::vector<Line> sig, enc;
650  sig.swap( signers );
651  enc.swap( recipients );
652  kdtools::for_each( sig, mem_fn( &Line::kill ) );
653  kdtools::for_each( enc, mem_fn( &Line::kill ) );
654  glay.removeWidget( &selectSigningCertificatesGB );
655  glay.removeWidget( &selectEncryptionCertificatesGB );
656  }
657 
658  void addSelectSigningCertificatesGB() {
659  glay.addWidget( &selectSigningCertificatesGB, glay.rowCount(), 0, 1, Line::NumColumns );
660  }
661  void addSelectEncryptionCertificatesGB() {
662  glay.addWidget( &selectEncryptionCertificatesGB, glay.rowCount(), 0, 1, Line::NumColumns );
663  }
664 
665  void addSigner( const QString & mailbox,
666  const std::vector<Key> & pgp, bool pgpAmbiguous,
667  const std::vector<Key> & cms, bool cmsAmbiguous, QWidget * q )
668  {
669  Line line( i18n("From:"), mailbox, pgp, pgpAmbiguous, cms, cmsAmbiguous, q, glay );
670  signers.push_back( line );
671  }
672 
673  void addRecipient( const QString & mailbox,
674  const std::vector<Key> & pgp, bool pgpAmbiguous,
675  const std::vector<Key> & cms, bool cmsAmbiguous, QWidget * q )
676  {
677  Line line( i18n("To:"), mailbox, pgp, pgpAmbiguous, cms, cmsAmbiguous, q, glay );
678  recipients.push_back( line );
679  }
680 
681  } ui;
682 };
683 
684 SignEncryptEMailConflictDialog::SignEncryptEMailConflictDialog( QWidget * parent, Qt::WindowFlags f )
685  : QDialog( parent, f ), d( new Private( this ) )
686 {
687 
688 }
689 
690 SignEncryptEMailConflictDialog::~SignEncryptEMailConflictDialog() {}
691 
692 void SignEncryptEMailConflictDialog::setPresetProtocol( Protocol p ) {
693  if ( p == d->presetProtocol )
694  return;
695  const KDSignalBlocker pgpBlocker( d->ui.pgpRB );
696  const KDSignalBlocker cmsBlocker( d->ui.cmsRB );
697  really_check( d->ui.pgpRB, p == OpenPGP );
698  really_check( d->ui.cmsRB, p == CMS );
699  d->presetProtocol = p;
700  d->showHideWidgets();
701  d->enableDisableOkButton();
702 }
703 
704 Protocol SignEncryptEMailConflictDialog::selectedProtocol() const {
705  if ( d->presetProtocol != UnknownProtocol )
706  return d->presetProtocol;
707  if ( d->ui.pgpRB.isChecked() )
708  return OpenPGP;
709  if ( d->ui.cmsRB.isChecked() )
710  return CMS;
711  return UnknownProtocol;
712 }
713 
714 void SignEncryptEMailConflictDialog::setSubject( const QString & subject ) {
715  setWindowTitle( i18n("Select Certificates For Message \"%1\"", subject ) );
716 }
717 
718 void SignEncryptEMailConflictDialog::setSign( bool sign ) {
719  if ( sign == d->sign )
720  return;
721  d->sign = sign;
722  d->updateTopLabelText();
723  d->showHideWidgets();
724  d->enableDisableOkButton();
725 }
726 
727 void SignEncryptEMailConflictDialog::setEncrypt( bool encrypt ) {
728  if ( encrypt == d->encrypt )
729  return;
730  d->encrypt = encrypt;
731  d->updateTopLabelText();
732  d->showHideWidgets();
733  d->enableDisableOkButton();
734 }
735 
736 void SignEncryptEMailConflictDialog::setSenders( const std::vector<Sender> & senders ) {
737  if ( senders == d->senders )
738  return;
739  d->senders = senders;
740  d->createSendersAndRecipients();
741  d->showHideWidgets();
742  d->enableDisableOkButton();
743 }
744 
745 void SignEncryptEMailConflictDialog::setRecipients( const std::vector<Recipient> & recipients ) {
746  if ( d->recipients == recipients )
747  return;
748  d->recipients = recipients;
749  d->createSendersAndRecipients();
750  d->showHideWidgets();
751  d->enableDisableOkButton();
752 }
753 
754 void SignEncryptEMailConflictDialog::pickProtocol() {
755 
756  if ( selectedProtocol() != UnknownProtocol )
757  return; // already picked
758 
759  const bool pgp = d->isComplete( OpenPGP );
760  const bool cms = d->isComplete( CMS );
761 
762  if ( pgp && !cms )
763  d->ui.pgpRB.setChecked( true );
764  else if ( cms && !pgp )
765  d->ui.cmsRB.setChecked( true );
766 }
767 
768 bool SignEncryptEMailConflictDialog::isComplete() const {
769  const Protocol proto = selectedProtocol();
770  return proto != UnknownProtocol && d->isComplete( proto ) ;
771 }
772 
773 bool SignEncryptEMailConflictDialog::Private::isComplete( Protocol proto ) const {
774  return ( !sign || kdtools::none_of( ui.signers, boost::bind( &Line::isStillAmbiguous, _1, proto ) ) )
775  && ( !encrypt || kdtools::none_of( ui.recipients, boost::bind( &Line::isStillAmbiguous, _1, proto ) ) )
776  ;
777 }
778 
779 static std::vector<Key> get_keys( const std::vector<Line> & lines, Protocol proto ) {
780  if ( proto == UnknownProtocol )
781  return std::vector<Key>();
782  assert( proto == OpenPGP || proto == CMS );
783 
784  std::vector<Key> keys;
785  keys.reserve( lines.size() );
786  kdtools::transform( lines, std::back_inserter( keys ),
787  boost::bind( &Line::key, _1, proto ) );
788  kleo_assert( kdtools::none_of( keys, mem_fn( &Key::isNull ) ) );
789  return keys;
790 }
791 
792 std::vector<Key> SignEncryptEMailConflictDialog::resolvedSigningKeys() const {
793  return d->sign ? get_keys( d->ui.signers, selectedProtocol() ) : std::vector<Key>() ;
794 }
795 
796 std::vector<Key> SignEncryptEMailConflictDialog::resolvedEncryptionKeys() const {
797  return d->encrypt ? get_keys( d->ui.recipients, selectedProtocol() ) : std::vector<Key>() ;
798 }
799 
800 void SignEncryptEMailConflictDialog::setQuickMode( bool on ) {
801  d->ui.quickModeCB.setChecked( on );
802 }
803 
804 bool SignEncryptEMailConflictDialog::isQuickMode() const {
805  return d->ui.quickModeCB.isChecked();
806 }
807 
808 void SignEncryptEMailConflictDialog::setConflict( bool conflict ) {
809  d->ui.conflictTopLB.setVisible( conflict );
810  d->ui.quickModeTopLB.setVisible( !conflict );
811 }
812 
813 #include "moc_signencryptemailconflictdialog.cpp"
814 #include "signencryptemailconflictdialog.moc"
Kleo::Dialogs::CertificateSelectionDialog::setOptions
void setOptions(Options options)
Definition: certificateselectiondialog.cpp:206
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setConflict
void setConflict(bool conflict)
Definition: signencryptemailconflictdialog.cpp:808
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setSenders
void setSenders(const std::vector< Sender > &senders)
Definition: signencryptemailconflictdialog.cpp:736
make_top_label_conflict_text
static QString make_top_label_conflict_text(bool sign, bool enc)
Definition: signencryptemailconflictdialog.cpp:384
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setSign
void setSign(bool on)
Definition: signencryptemailconflictdialog.cpp:718
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setSubject
void setSubject(const QString &subject)
Definition: signencryptemailconflictdialog.cpp:714
Kleo::Dialogs::CertificateSelectionDialog::setCustomLabelText
void setCustomLabelText(const QString &text)
Definition: certificateselectiondialog.cpp:195
QDialog
QWidget
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog
Definition: signencryptemailconflictdialog.h:63
create_encryption_certificate_selection_dialog
static CertificateSelectionDialog * create_encryption_certificate_selection_dialog(QWidget *parent, Protocol proto, const QString &mailbox)
Definition: signencryptemailconflictdialog.cpp:364
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setPresetProtocol
void setPresetProtocol(GpgME::Protocol proto)
Definition: signencryptemailconflictdialog.cpp:692
formatting.h
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::isComplete
bool isComplete() const
Definition: signencryptemailconflictdialog.cpp:768
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::resolvedEncryptionKeys
std::vector< GpgME::Key > resolvedEncryptionKeys() const
Definition: signencryptemailconflictdialog.cpp:796
create_signing_certificate_selection_dialog
static CertificateSelectionDialog * create_signing_certificate_selection_dialog(QWidget *parent, Protocol proto, const QString &mailbox)
Definition: signencryptemailconflictdialog.cpp:374
Kleo::Crypto::Sender::mailbox
const KMime::Types::Mailbox & mailbox() const
Definition: sender.cpp:138
kdsignalblocker.h
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setRecipients
void setRecipients(const std::vector< Recipient > &recipients)
Definition: signencryptemailconflictdialog.cpp:745
Kleo::Dialogs::CertificateSelectionDialog::options
Options options() const
Definition: certificateselectiondialog.cpp:216
kleo_assert.h
Kleo::Formatting::formatForComboBox
QString formatForComboBox(const GpgME::Key &key)
Definition: formatting.cpp:497
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::pickProtocol
void pickProtocol()
Definition: signencryptemailconflictdialog.cpp:754
Kleo::Crypto::Recipient::encryptionCertificateCandidates
const std::vector< GpgME::Key > & encryptionCertificateCandidates(GpgME::Protocol proto) const
Definition: recipient.cpp:129
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Dialogs::CertificateSelectionDialog
Definition: certificateselectiondialog.h:56
Kleo::Crypto::Recipient::mailbox
const KMime::Types::Mailbox & mailbox() const
Definition: recipient.cpp:125
recipient.h
certificateselectiondialog.h
Kleo::Crypto::Sender::encryptToSelfCertificateCandidates
const std::vector< GpgME::Key > & encryptToSelfCertificateCandidates(GpgME::Protocol proto) const
Definition: sender.cpp:157
signencryptemailconflictdialog.h
Kleo::Class::OpenPGP
Definition: classify.h:49
get_keys
static std::vector< Key > get_keys(const std::vector< Line > &lines, Protocol proto)
Definition: signencryptemailconflictdialog.cpp:779
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setEncrypt
void setEncrypt(bool on)
Definition: signencryptemailconflictdialog.cpp:727
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::setQuickMode
void setQuickMode(bool on)
Definition: signencryptemailconflictdialog.cpp:800
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
Kleo::Crypto::Sender::isEncryptionAmbiguous
bool isEncryptionAmbiguous(GpgME::Protocol proto) const
Definition: sender.cpp:132
Kleo::Class::CMS
Definition: classify.h:48
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::isQuickMode
bool isQuickMode() const
Definition: signencryptemailconflictdialog.cpp:804
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::selectedProtocol
GpgME::Protocol selectedProtocol() const
Definition: signencryptemailconflictdialog.cpp:704
kleo_assert_fail
#define kleo_assert_fail(cond)
Definition: kleo_assert.h:88
create_certificate_selection_dialog
static CertificateSelectionDialog * create_certificate_selection_dialog(QWidget *parent, Protocol proto)
Definition: signencryptemailconflictdialog.cpp:356
kleo_assert
#define kleo_assert(cond)
Definition: kleo_assert.h:84
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::SignEncryptEMailConflictDialog
SignEncryptEMailConflictDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: signencryptemailconflictdialog.cpp:684
sender.h
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::~SignEncryptEMailConflictDialog
~SignEncryptEMailConflictDialog()
Definition: signencryptemailconflictdialog.cpp:690
predicates.h
gui-helper.h
Ok
Definition: setinitialpindialog.cpp:59
update
static void update(const QString &fname, const QString &id)
Definition: filedialog.cpp:61
q
#define q
Definition: adduseridcommand.cpp:91
make_top_label_quickmode_text
static QString make_top_label_quickmode_text(bool sign, bool enc)
Definition: signencryptemailconflictdialog.cpp:398
Kleo::Crypto::Gui::SignEncryptEMailConflictDialog::resolvedSigningKeys
std::vector< GpgME::Key > resolvedSigningKeys() const
Definition: signencryptemailconflictdialog.cpp:792
Kleo::Crypto::Recipient::isEncryptionAmbiguous
bool isEncryptionAmbiguous(GpgME::Protocol protocol) const
Definition: recipient.cpp:119
KDSignalBlocker
Exception-safe and convenient wrapper around QObject::blockSignals()
Definition: kdsignalblocker.h:30
Kleo::Crypto::Sender
Definition: sender.h:56
Kleo::Class::AnyFormat
Definition: classify.h:58
Kleo::really_check
static void really_check(QAbstractButton &b, bool on)
Definition: gui-helper.h:39
Kleo::Crypto::Recipient
Definition: recipient.h:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • 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