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

kleopatra

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

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