• 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
resolverecipientspage.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/gui/resolverecipientspage.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 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 "resolverecipientspage.h"
36 #include "resolverecipientspage_p.h"
37 
38 #include <dialogs/certificateselectiondialog.h>
39 
40 #include <crypto/certificateresolver.h>
41 
42 #include <models/keycache.h>
43 
44 #include <utils/formatting.h>
45 
46 #include <kmime/kmime_header_parsing.h>
47 
48 #include <gpgme++/key.h>
49 
50 #include <KLocalizedString>
51 
52 #include <QButtonGroup>
53 #include <QComboBox>
54 #include <QHBoxLayout>
55 #include <QLabel>
56 #include <QListWidget>
57 #include <QPointer>
58 #include <QPushButton>
59 #include <QRadioButton>
60 #include <QToolButton>
61 #include <QSignalMapper>
62 #include <QStringList>
63 #include <QVBoxLayout>
64 
65 #include <boost/bind.hpp>
66 #include <boost/shared_ptr.hpp>
67 
68 #include <cassert>
69 
70 using namespace GpgME;
71 using namespace boost;
72 using namespace Kleo;
73 using namespace Kleo::Dialogs;
74 using namespace Kleo::Crypto;
75 using namespace Kleo::Crypto::Gui;
76 using namespace KMime::Types;
77 
78 ResolveRecipientsPage::ListWidget::ListWidget( QWidget* parent, Qt::WindowFlags flags ) : QWidget( parent, flags ), m_protocol( UnknownProtocol )
79 {
80  m_listWidget = new QListWidget;
81  m_listWidget->setSelectionMode( QAbstractItemView::MultiSelection );
82  QVBoxLayout * const layout = new QVBoxLayout( this );
83  layout->addWidget( m_listWidget );
84  connect( m_listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onSelectionChange()) );
85 }
86 
87 ResolveRecipientsPage::ListWidget::~ListWidget()
88 {
89 }
90 
91 void ResolveRecipientsPage::ListWidget::onSelectionChange()
92 {
93  Q_FOREACH ( const QString& i, widgets.keys() ) { //krazy:exclude=foreach
94  assert( items.contains( i ) );
95  widgets[i]->setSelected( items[i]->isSelected() );
96  }
97  emit selectionChanged();
98 }
99 
100 void ResolveRecipientsPage::ListWidget::addEntry( const Mailbox& mbox )
101 {
102  addEntry( mbox.prettyAddress(), mbox.prettyAddress(), mbox );
103 }
104 
105 void ResolveRecipientsPage::ListWidget::addEntry( const QString& id, const QString& name )
106 {
107  addEntry( id, name, Mailbox() );
108 }
109 
110 void ResolveRecipientsPage::ListWidget::addEntry( const QString& id, const QString& name, const Mailbox& mbox )
111 {
112  assert( !widgets.contains( id ) && !items.contains( id ) );
113  QListWidgetItem* item = new QListWidgetItem;
114  item->setData( IdRole, id );
115  ItemWidget* wid = new ItemWidget( id, name, mbox, this );
116  connect( wid, SIGNAL(changed()), this, SIGNAL(completeChanged()) );
117  wid->setProtocol( m_protocol );
118  item->setSizeHint( wid->sizeHint() );
119  m_listWidget->addItem( item );
120  m_listWidget->setItemWidget( item, wid );
121  widgets[id] = wid;
122  items[id] = item;
123 }
124 
125 Mailbox ResolveRecipientsPage::ListWidget::mailbox( const QString& id ) const
126 {
127  return widgets.contains( id ) ? widgets[id]->mailbox() : Mailbox();
128 }
129 
130 void ResolveRecipientsPage::ListWidget::setCertificates( const QString& id, const std::vector<Key>& pgp, const std::vector<Key>& cms )
131 {
132  assert( widgets.contains( id ) );
133  widgets[id]->setCertificates( pgp, cms );
134 }
135 
136 Key ResolveRecipientsPage::ListWidget::selectedCertificate( const QString& id ) const
137 {
138  return widgets.contains( id ) ? widgets[id]->selectedCertificate() : Key();
139 }
140 
141 
142 GpgME::Key ResolveRecipientsPage::ListWidget::selectedCertificate( const QString& id, GpgME::Protocol prot ) const
143 {
144  return widgets.contains( id ) ? widgets[id]->selectedCertificate( prot ) : Key();
145 }
146 
147 QStringList ResolveRecipientsPage::ListWidget::identifiers() const
148 {
149  return widgets.keys();
150 }
151 
152 void ResolveRecipientsPage::ListWidget::setProtocol( GpgME::Protocol prot )
153 {
154  if ( m_protocol == prot )
155  return;
156  m_protocol = prot;
157  Q_FOREACH ( ItemWidget* i, widgets )
158  i->setProtocol( prot );
159 }
160 
161 void ResolveRecipientsPage::ListWidget::removeEntry( const QString& id )
162 {
163  if ( !widgets.contains( id ) )
164  return;
165  delete items[id];
166  items.remove( id );
167  delete widgets[id];
168  widgets.remove( id );
169 }
170 
171 void ResolveRecipientsPage::ListWidget::showSelectionDialog( const QString& id )
172 {
173  if ( !widgets.contains( id ) )
174  return;
175  widgets[id]->showSelectionDialog();
176 }
177 
178 QStringList ResolveRecipientsPage::ListWidget::selectedEntries() const
179 {
180  QStringList entries;
181  const QList<QListWidgetItem*> items = m_listWidget->selectedItems();
182  Q_FOREACH ( const QListWidgetItem* i, items )
183  {
184  entries.append( i->data( IdRole ).toString() );
185  }
186  return entries;
187 }
188 
189 ResolveRecipientsPage::ItemWidget::ItemWidget( const QString& id, const QString& name, const Mailbox& mbox,
190  QWidget* parent, Qt::WindowFlags flags ) : QWidget( parent, flags ), m_id( id ), m_mailbox( mbox ), m_protocol( UnknownProtocol ), m_selected( false )
191 {
192  assert( !m_id.isEmpty() );
193  setAutoFillBackground( true );
194  QHBoxLayout* layout = new QHBoxLayout( this );
195  layout->setMargin( 0 );
196  layout->addSpacing( 15 );
197  m_nameLabel = new QLabel;
198  m_nameLabel->setText( name );
199  layout->addWidget( m_nameLabel );
200  layout->addStretch();
201  m_certLabel = new QLabel;
202  m_certLabel->setText( i18n( "<i>No certificate selected</i>" ) );
203  layout->addWidget( m_certLabel );
204  m_certCombo = new QComboBox;
205  connect( m_certCombo, SIGNAL(currentIndexChanged(int)),
206  this, SIGNAL(changed()) );
207  layout->addWidget( m_certCombo );
208  m_selectButton = new QToolButton;
209  m_selectButton->setText( i18n( "..." ) );
210  connect( m_selectButton, SIGNAL(clicked()),
211  this, SLOT(showSelectionDialog()) );
212  layout->addWidget( m_selectButton );
213  layout->addSpacing( 15 );
214  setCertificates( std::vector<Key>(), std::vector<Key>() );
215 }
216 
217 void ResolveRecipientsPage::ItemWidget::updateVisibility()
218 {
219  m_certLabel->setVisible( m_certCombo->count() == 0 );
220  m_certCombo->setVisible( m_certCombo->count() > 0 );
221 }
222 
223 ResolveRecipientsPage::ItemWidget::~ItemWidget()
224 {
225 }
226 
227 QString ResolveRecipientsPage::ItemWidget::id() const
228 {
229  return m_id;
230 }
231 
232 void ResolveRecipientsPage::ItemWidget::setSelected( bool selected )
233 {
234  if ( m_selected == selected )
235  return;
236  m_selected = selected;
237  setBackgroundRole( selected ? QPalette::Highlight : QPalette::Base );
238  const QPalette::ColorRole foreground = selected ? QPalette::HighlightedText : QPalette::Text;
239  setForegroundRole( foreground );
240  m_nameLabel->setForegroundRole( foreground );
241  m_certLabel->setForegroundRole( foreground );
242 }
243 
244 bool ResolveRecipientsPage::ItemWidget::isSelected() const
245 {
246  return m_selected;
247 }
248 
249 static CertificateSelectionDialog::Option protocol2option( GpgME::Protocol proto ) {
250  switch ( proto ) {
251  case OpenPGP: return CertificateSelectionDialog::OpenPGPFormat;
252  case CMS: return CertificateSelectionDialog::CMSFormat;
253  default: return CertificateSelectionDialog::AnyFormat;
254  }
255 }
256 
257 static CertificateSelectionDialog * createCertificateSelectionDialog( QWidget* parent, GpgME::Protocol prot ) {
258  CertificateSelectionDialog * const dlg = new CertificateSelectionDialog( parent );
259  const CertificateSelectionDialog::Options options =
260  CertificateSelectionDialog::SingleSelection |
261  CertificateSelectionDialog::EncryptOnly |
262  CertificateSelectionDialog::MultiSelection |
263  protocol2option( prot );
264  dlg->setOptions( options );
265  return dlg;
266 }
267 
268 void ResolveRecipientsPage::ItemWidget::showSelectionDialog()
269 {
270  QPointer<CertificateSelectionDialog> dlg = createCertificateSelectionDialog( this, m_protocol );
271 
272  if ( dlg->exec() == QDialog::Accepted && dlg /* still with us? */ ) {
273  const GpgME::Key cert = dlg->selectedCertificate();
274  if ( !cert.isNull() ) {
275  addCertificateToComboBox( cert );
276  selectCertificateInComboBox( cert );
277  }
278  }
279  delete dlg;
280 }
281 
282 Mailbox ResolveRecipientsPage::ItemWidget::mailbox() const
283 {
284  return m_mailbox;
285 }
286 
287 void ResolveRecipientsPage::ItemWidget::selectCertificateInComboBox( const Key& key )
288 {
289  m_certCombo->setCurrentIndex( m_certCombo->findData( QLatin1String(key.keyID()) ) );
290 }
291 
292 void ResolveRecipientsPage::ItemWidget::addCertificateToComboBox( const GpgME::Key& key )
293 {
294  m_certCombo->addItem( Formatting::formatForComboBox( key ), QByteArray( key.keyID() ) );
295  if ( m_certCombo->count() == 1 )
296  m_certCombo->setCurrentIndex( 0 );
297  updateVisibility();
298 }
299 
300 void ResolveRecipientsPage::ItemWidget::resetCertificates()
301 {
302  std::vector<Key> certs;
303  Key selected;
304  switch ( m_protocol )
305  {
306  case OpenPGP:
307  certs = m_pgp;
308  break;
309  case CMS:
310  certs = m_cms;
311  break;
312  case UnknownProtocol:
313  certs = m_cms;
314  certs.insert( certs.end(), m_pgp.begin(), m_pgp.end() );
315  }
316 
317  m_certCombo->clear();
318  Q_FOREACH ( const Key& i, certs )
319  addCertificateToComboBox( i );
320  if ( !m_selectedCertificates[m_protocol].isNull() )
321  selectCertificateInComboBox( m_selectedCertificates[m_protocol] );
322  else if ( m_certCombo->count() > 0 )
323  m_certCombo->setCurrentIndex( 0 );
324  updateVisibility();
325  emit changed();
326 }
327 
328 void ResolveRecipientsPage::ItemWidget::setProtocol( Protocol prot )
329 {
330  if ( m_protocol == prot )
331  return;
332  m_selectedCertificates[m_protocol] = selectedCertificate();
333  if ( m_protocol != UnknownProtocol )
334  ( m_protocol == OpenPGP ? m_pgp : m_cms ) = certificates();
335  m_protocol = prot;
336  resetCertificates();
337 }
338 
339 void ResolveRecipientsPage::ItemWidget::setCertificates( const std::vector<Key>& pgp, const std::vector<Key>& cms )
340 {
341  m_pgp = pgp;
342  m_cms = cms;
343  resetCertificates();
344 }
345 
346 Key ResolveRecipientsPage::ItemWidget::selectedCertificate() const
347 {
348 #ifdef QT_STL
349  return KeyCache::instance()->findByKeyIDOrFingerprint( m_certCombo->itemData( m_certCombo->currentIndex(), ListWidget::IdRole ).toString().toStdString() );
350 #else
351  const QString tmpStr = m_certCombo->itemData( m_certCombo->currentIndex(), ListWidget::IdRole ).toString();
352  const QByteArray asc = tmpStr.toLatin1();
353  std::string tmpstdstring = std::string(asc.constData(), asc.length());
354  return KeyCache::instance()->findByKeyIDOrFingerprint( tmpstdstring );
355 #endif
356 }
357 
358 
359 GpgME::Key ResolveRecipientsPage::ItemWidget::selectedCertificate( GpgME::Protocol prot ) const
360 {
361  return prot == m_protocol ? selectedCertificate() : m_selectedCertificates.value( prot );
362 }
363 
364 std::vector<Key> ResolveRecipientsPage::ItemWidget::certificates() const
365 {
366  std::vector<Key> certs;
367  for ( int i = 0; i < m_certCombo->count(); ++i ) {
368 #ifdef QT_STL
369  certs.push_back( KeyCache::instance()->findByKeyIDOrFingerprint( m_certCombo->itemData( i, ListWidget::IdRole ).toString().toStdString() ) );
370 #else
371  const QString tmpStr = m_certCombo->itemData( i, ListWidget::IdRole ).toString();
372  const QByteArray asc = tmpStr.toLatin1();
373  std::string tmpstdstring = std::string(asc.constData(), asc.length());
374  certs.push_back( KeyCache::instance()->findByKeyIDOrFingerprint( tmpstdstring ) );
375 #endif
376  }
377  return certs;
378 }
379 
380 class ResolveRecipientsPage::Private {
381  friend class ::Kleo::Crypto::Gui::ResolveRecipientsPage;
382  ResolveRecipientsPage * const q;
383 public:
384  explicit Private( ResolveRecipientsPage * qq );
385  ~Private();
386 
387  void setSelectedProtocol( Protocol protocol );
388  void selectionChanged();
389  void removeSelectedEntries();
390  void addRecipient();
391  void addRecipient( const Mailbox& mbox );
392  void addRecipient( const QString& id, const QString& name );
393  void updateProtocolRBVisibility();
394  void protocolSelected( int prot );
395  void writeSelectedCertificatesToPreferences();
396  void completeChangedInternal();
397 
398 private:
399  ListWidget* m_listWidget;
400  QPushButton* m_addButton;
401  QPushButton* m_removeButton;
402  QRadioButton* m_pgpRB;
403  QRadioButton* m_cmsRB;
404  QLabel* m_additionalRecipientsLabel;
405  Protocol m_presetProtocol;
406  Protocol m_selectedProtocol;
407  bool m_multipleProtocolsAllowed;
408  boost::shared_ptr<RecipientPreferences> m_recipientPreferences;
409 };
410 
411 ResolveRecipientsPage::Private::Private( ResolveRecipientsPage * qq )
412  : q( qq ), m_presetProtocol( UnknownProtocol ), m_selectedProtocol( m_presetProtocol ), m_multipleProtocolsAllowed( false ), m_recipientPreferences()
413 {
414  connect( q, SIGNAL(completeChanged()), q, SLOT(completeChangedInternal()) );
415  q->setTitle( i18n( "<b>Recipients</b>" ) );
416  QVBoxLayout* const layout = new QVBoxLayout( q );
417  m_listWidget = new ListWidget;
418  connect( m_listWidget, SIGNAL(selectionChanged()), q, SLOT(selectionChanged()) );
419  connect( m_listWidget, SIGNAL(completeChanged()), q, SIGNAL(completeChanged()) );
420  layout->addWidget( m_listWidget );
421  m_additionalRecipientsLabel = new QLabel;
422  m_additionalRecipientsLabel->setWordWrap( true );
423  layout->addWidget( m_additionalRecipientsLabel );
424  m_additionalRecipientsLabel->setVisible( false );
425  QWidget* buttonWidget = new QWidget;
426  QHBoxLayout* buttonLayout = new QHBoxLayout( buttonWidget );
427  buttonLayout->setMargin( 0 );
428  m_addButton = new QPushButton;
429  connect( m_addButton, SIGNAL(clicked()), q, SLOT(addRecipient()) );
430  m_addButton->setText( i18n( "Add Recipient..." ) );
431  buttonLayout->addWidget( m_addButton );
432  m_removeButton = new QPushButton;
433  m_removeButton->setEnabled( false );
434  m_removeButton->setText( i18n( "Remove Selected" ) );
435  connect( m_removeButton, SIGNAL(clicked()),
436  q, SLOT(removeSelectedEntries()) );
437  buttonLayout->addWidget( m_removeButton );
438  buttonLayout->addStretch();
439  layout->addWidget( buttonWidget );
440  QWidget* protocolWidget = new QWidget;
441  QHBoxLayout* protocolLayout = new QHBoxLayout( protocolWidget );
442  QButtonGroup* protocolGroup = new QButtonGroup( q );
443  connect( protocolGroup, SIGNAL(buttonClicked(int)), q, SLOT(protocolSelected(int)) );
444  m_pgpRB = new QRadioButton;
445  m_pgpRB->setText( i18n( "OpenPGP" ) );
446  protocolGroup->addButton( m_pgpRB, OpenPGP );
447  protocolLayout->addWidget( m_pgpRB );
448  m_cmsRB = new QRadioButton;
449  m_cmsRB->setText( i18n( "S/MIME" ) );
450  protocolGroup->addButton( m_cmsRB, CMS );
451  protocolLayout->addWidget( m_cmsRB );
452  protocolLayout->addStretch();
453  layout->addWidget( protocolWidget );
454 }
455 
456 ResolveRecipientsPage::Private::~Private() {}
457 
458 void ResolveRecipientsPage::Private::completeChangedInternal()
459 {
460  const bool isComplete = q->isComplete();
461  const std::vector<Key> keys = q->resolvedCertificates();
462  const bool haveSecret = std::find_if( keys.begin(), keys.end(), boost::bind( &Key::hasSecret, _1 ) ) != keys.end();
463  if ( isComplete && !haveSecret )
464  q->setExplanation( i18n( "<b>Warning:</b> None of the selected certificates seem to be your own. You will not be able to decrypt the encrypted data again." ) );
465  else
466  q->setExplanation( QString() );
467 }
468 
469 void ResolveRecipientsPage::Private::updateProtocolRBVisibility()
470 {
471  const bool visible = !m_multipleProtocolsAllowed && m_presetProtocol == UnknownProtocol;
472  m_cmsRB->setVisible( visible );
473  m_pgpRB->setVisible( visible );
474  if ( visible )
475  {
476  if ( m_selectedProtocol == CMS )
477  m_cmsRB->click();
478  else
479  m_pgpRB->click();
480  }
481 }
482 
483 bool ResolveRecipientsPage::isComplete() const
484 {
485  const QStringList ids = d->m_listWidget->identifiers();
486  if ( ids.isEmpty() )
487  return false;
488 
489  Q_FOREACH ( const QString& i, ids )
490  {
491  if ( d->m_listWidget->selectedCertificate( i ).isNull() )
492  return false;
493  }
494 
495  return true;
496 }
497 
498 ResolveRecipientsPage::ResolveRecipientsPage( QWidget * parent )
499  : WizardPage( parent ), d( new Private( this ) )
500 {
501 }
502 
503 ResolveRecipientsPage::~ResolveRecipientsPage() {}
504 
505 Protocol ResolveRecipientsPage::selectedProtocol() const
506 {
507  return d->m_selectedProtocol;
508 }
509 
510 void ResolveRecipientsPage::Private::setSelectedProtocol( Protocol protocol )
511 {
512  if ( m_selectedProtocol == protocol )
513  return;
514  m_selectedProtocol = protocol;
515  m_listWidget->setProtocol( m_selectedProtocol );
516  emit q->selectedProtocolChanged();
517 }
518 
519 void ResolveRecipientsPage::Private::protocolSelected( int p )
520 {
521  const Protocol protocol = static_cast<Protocol>( p );
522  assert( protocol != UnknownProtocol );
523  setSelectedProtocol( protocol );
524 }
525 
526 void ResolveRecipientsPage::setPresetProtocol( Protocol prot )
527 {
528  if ( d->m_presetProtocol == prot )
529  return;
530  d->m_presetProtocol = prot;
531  d->setSelectedProtocol( prot );
532  if ( prot != UnknownProtocol )
533  d->m_multipleProtocolsAllowed = false;
534  d->updateProtocolRBVisibility();
535 }
536 
537 Protocol ResolveRecipientsPage::presetProtocol() const
538 {
539  return d->m_presetProtocol;
540 }
541 
542 bool ResolveRecipientsPage::multipleProtocolsAllowed() const
543 {
544  return d->m_multipleProtocolsAllowed;
545 }
546 
547 void ResolveRecipientsPage::setMultipleProtocolsAllowed( bool allowed )
548 {
549  if ( d->m_multipleProtocolsAllowed == allowed )
550  return;
551  d->m_multipleProtocolsAllowed = allowed;
552  if ( d->m_multipleProtocolsAllowed )
553  {
554  setPresetProtocol( UnknownProtocol );
555  d->setSelectedProtocol( UnknownProtocol );
556  }
557  d->updateProtocolRBVisibility();
558 }
559 
560 
561 void ResolveRecipientsPage::Private::addRecipient( const QString& id, const QString& name )
562 {
563  m_listWidget->addEntry( id, name );
564 }
565 
566 void ResolveRecipientsPage::Private::addRecipient( const Mailbox& mbox )
567 {
568  m_listWidget->addEntry( mbox );
569 }
570 
571 void ResolveRecipientsPage::Private::addRecipient()
572 {
573  QPointer<CertificateSelectionDialog> dlg = createCertificateSelectionDialog( q, q->selectedProtocol() );
574  if ( dlg->exec() != QDialog::Accepted || !dlg /*q already deleted*/ )
575  return;
576  const std::vector<Key> keys = dlg->selectedCertificates();
577 
578  int i = 0;
579  Q_FOREACH( const Key & key, keys ) {
580  const QStringList existing = m_listWidget->identifiers();
581  QString rec = i18n( "Recipient" );
582  while ( existing.contains( rec ) )
583  rec = i18nc( "%1 == number", "Recipient (%1)", ++i );
584  addRecipient( rec, rec );
585  const std::vector<Key> pgp = key.protocol() == OpenPGP ? std::vector<Key>( 1, key ) : std::vector<Key>();
586  const std::vector<Key> cms = key.protocol() == CMS ? std::vector<Key>( 1, key ) : std::vector<Key>();
587  m_listWidget->setCertificates( rec, pgp, cms );
588  }
589  emit q->completeChanged();
590 }
591 
592 namespace {
593 
594  std::vector<Key> makeSuggestions( const boost::shared_ptr<RecipientPreferences>& prefs, const Mailbox& mb, GpgME::Protocol prot )
595  {
596  std::vector<Key> suggestions;
597  const Key remembered = prefs ? prefs->preferredCertificate( mb, prot ) : Key();
598  if ( !remembered.isNull() )
599  suggestions.push_back( remembered );
600  else
601  suggestions = CertificateResolver::resolveRecipient( mb, prot );
602  return suggestions;
603  }
604 }
605 
606 static QString listKeysForInfo( const std::vector<Key> & keys ) {
607  QStringList list;
608  std::transform( keys.begin(), keys.end(), list.begin(), &Formatting::formatKeyLink );
609  return list.join( QLatin1String("<br/>") );
610 }
611 
612 void ResolveRecipientsPage::setAdditionalRecipientsInfo( const std::vector<Key> & recipients ) {
613  d->m_additionalRecipientsLabel->setVisible( !recipients.empty() );
614  if ( recipients.empty() )
615  return;
616  d->m_additionalRecipientsLabel->setText(
617  i18n( "<qt><p>Recipients predefined via GnuPG settings:</p>%1</qt>",
618  listKeysForInfo( recipients ) ) );
619 }
620 
621 void ResolveRecipientsPage::setRecipients( const std::vector<Mailbox>& recipients, const std::vector<Mailbox> & encryptToSelfRecipients )
622 {
623  uint cmsCount = 0;
624  uint pgpCount = 0;
625  uint senders = 0;
626  Q_FOREACH( const Mailbox & mb, encryptToSelfRecipients ) {
627  const QString id = QLatin1String("sender-") + QString::number( ++senders );
628  d->m_listWidget->addEntry( id, i18n("Sender"), mb );
629  const std::vector<Key> pgp = makeSuggestions( d->m_recipientPreferences, mb, OpenPGP );
630  const std::vector<Key> cms = makeSuggestions( d->m_recipientPreferences, mb, CMS );
631  pgpCount += !pgp.empty();
632  cmsCount += !cms.empty();
633  d->m_listWidget->setCertificates( id, pgp, cms );
634  }
635  Q_FOREACH( const Mailbox& i, recipients )
636  {
637  //TODO:
638  const QString address = i.prettyAddress();
639  d->addRecipient( i );
640  const std::vector<Key> pgp = makeSuggestions( d->m_recipientPreferences, i, OpenPGP );
641  const std::vector<Key> cms = makeSuggestions( d->m_recipientPreferences, i, CMS );
642  pgpCount += pgp.empty() ? 0 : 1;
643  cmsCount += cms.empty() ? 0 : 1;
644  d->m_listWidget->setCertificates( address, pgp, cms );
645  }
646  if ( d->m_presetProtocol == UnknownProtocol && !d->m_multipleProtocolsAllowed )
647  ( cmsCount > pgpCount ? d->m_cmsRB : d->m_pgpRB )->click();
648 }
649 
650 std::vector<Key> ResolveRecipientsPage::resolvedCertificates() const
651 {
652  std::vector<Key> certs;
653  Q_FOREACH( const QString& i, d->m_listWidget->identifiers() )
654  {
655  const GpgME::Key cert = d->m_listWidget->selectedCertificate( i );
656  if ( !cert.isNull() )
657  certs.push_back( cert );
658  }
659  return certs;
660 }
661 
662 void ResolveRecipientsPage::Private::selectionChanged()
663 {
664  m_removeButton->setEnabled( !m_listWidget->selectedEntries().isEmpty() );
665 }
666 
667 void ResolveRecipientsPage::Private::removeSelectedEntries()
668 {
669  Q_FOREACH ( const QString& i, m_listWidget->selectedEntries() )
670  m_listWidget->removeEntry( i );
671  emit q->completeChanged();
672 }
673 
674 void ResolveRecipientsPage::setRecipientsUserMutable( bool isMutable )
675 {
676  d->m_addButton->setVisible( isMutable );
677  d->m_removeButton->setVisible( isMutable );
678 }
679 
680 bool ResolveRecipientsPage::recipientsUserMutable() const
681 {
682  return d->m_addButton->isVisible();
683 }
684 
685 
686 boost::shared_ptr<RecipientPreferences> ResolveRecipientsPage::recipientPreferences() const
687 {
688  return d->m_recipientPreferences;
689 }
690 
691 void ResolveRecipientsPage::setRecipientPreferences( const boost::shared_ptr<RecipientPreferences>& prefs )
692 {
693  d->m_recipientPreferences = prefs;
694 }
695 
696 void ResolveRecipientsPage::Private::writeSelectedCertificatesToPreferences()
697 {
698  if ( !m_recipientPreferences )
699  return;
700 
701  Q_FOREACH ( const QString& i, m_listWidget->identifiers() )
702  {
703  const Mailbox mbox = m_listWidget->mailbox( i );
704  if ( !mbox.hasAddress() )
705  continue;
706  const Key pgp = m_listWidget->selectedCertificate( i, OpenPGP );
707  if ( !pgp.isNull() )
708  m_recipientPreferences->setPreferredCertificate( mbox, OpenPGP, pgp );
709  const Key cms = m_listWidget->selectedCertificate( i, CMS );
710  if ( !cms.isNull() )
711  m_recipientPreferences->setPreferredCertificate( mbox, CMS, cms );
712  }
713 }
714 
715 void ResolveRecipientsPage::onNext() {
716  d->writeSelectedCertificatesToPreferences();
717 }
718 
719 #include "moc_resolverecipientspage_p.cpp"
720 #include "moc_resolverecipientspage.cpp"
Kleo::Dialogs::CertificateSelectionDialog::setOptions
void setOptions(Options options)
Definition: certificateselectiondialog.cpp:206
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::changed
void changed()
flags
static const char * flags[]
Definition: readerstatus.cpp:115
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::IdRole
Definition: resolverecipientspage_p.h:71
Kleo::Crypto::Gui::ResolveRecipientsPage::isComplete
bool isComplete() const
Definition: resolverecipientspage.cpp:483
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::removeEntry
void removeEntry(const QString &id)
Definition: resolverecipientspage.cpp:161
Kleo::Crypto::Gui::ResolveRecipientsPage::setMultipleProtocolsAllowed
void setMultipleProtocolsAllowed(bool allowed)
Definition: resolverecipientspage.cpp:547
Kleo::Crypto::Gui::ResolveRecipientsPage::setPresetProtocol
void setPresetProtocol(GpgME::Protocol protocol)
Definition: resolverecipientspage.cpp:526
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::showSelectionDialog
void showSelectionDialog()
Definition: resolverecipientspage.cpp:268
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::setCertificates
void setCertificates(const std::vector< GpgME::Key > &pgp, const std::vector< GpgME::Key > &cms)
Definition: resolverecipientspage.cpp:339
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::addEntry
void addEntry(const QString &id, const QString &name)
Definition: resolverecipientspage.cpp:105
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::setProtocol
void setProtocol(GpgME::Protocol prot)
Definition: resolverecipientspage.cpp:152
QWidget
formatting.h
listKeysForInfo
static QString listKeysForInfo(const std::vector< Key > &keys)
Definition: resolverecipientspage.cpp:606
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget
Definition: resolverecipientspage_p.h:89
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::isSelected
bool isSelected() const
Definition: resolverecipientspage.cpp:244
Kleo::Crypto::Gui::WizardPage::completeChanged
void completeChanged()
Kleo::Crypto::Gui::ResolveRecipientsPage::setRecipientsUserMutable
void setRecipientsUserMutable(bool isMutable)
Definition: resolverecipientspage.cpp:674
Kleo::Crypto::Gui::ResolveRecipientsPage
Definition: resolverecipientspage.h:63
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::id
QString id() const
Definition: resolverecipientspage.cpp:227
Kleo::Dialogs::CertificateSelectionDialog::Option
Option
Definition: certificateselectiondialog.h:60
Kleo::Formatting::formatForComboBox
QString formatForComboBox(const GpgME::Key &key)
Definition: formatting.cpp:497
Kleo::Crypto::Gui::ResolveRecipientsPage::resolvedCertificates
std::vector< GpgME::Key > resolvedCertificates() const
Definition: resolverecipientspage.cpp:650
boost::shared_ptr
Definition: encryptemailcontroller.h:51
Kleo::Dialogs::CertificateSelectionDialog
Definition: certificateselectiondialog.h:56
Kleo::Crypto::Gui::ResolveRecipientsPage::~ResolveRecipientsPage
~ResolveRecipientsPage()
Definition: resolverecipientspage.cpp:503
Kleo::Crypto::CertificateResolver::resolveRecipient
static std::vector< GpgME::Key > resolveRecipient(const KMime::Types::Mailbox &recipient, GpgME::Protocol proto)
Definition: certificateresolver.cpp:67
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::selectedCertificate
GpgME::Key selectedCertificate() const
Definition: resolverecipientspage.cpp:346
certificateselectiondialog.h
Kleo::Class::OpenPGP
Definition: classify.h:49
Kleo::Dialogs::CertificateSelectionDialog::selectedCertificates
std::vector< GpgME::Key > selectedCertificates() const
Definition: certificateselectiondialog.cpp:246
Kleo::Class::CMS
Definition: classify.h:48
Kleo::Crypto::Gui::ResolveRecipientsPage::multipleProtocolsAllowed
bool multipleProtocolsAllowed() const
Definition: resolverecipientspage.cpp:542
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::certificates
std::vector< GpgME::Key > certificates() const
Definition: resolverecipientspage.cpp:364
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::identifiers
QStringList identifiers() const
Definition: resolverecipientspage.cpp:147
Kleo::Crypto::Gui::ResolveRecipientsPage::setRecipientPreferences
void setRecipientPreferences(const boost::shared_ptr< RecipientPreferences > &prefs)
Definition: resolverecipientspage.cpp:691
Kleo::Crypto::Gui::ResolveRecipientsPage::selectedProtocol
GpgME::Protocol selectedProtocol() const
The protocol selected by the user (which is chosen by the user in case none was preset) ...
Definition: resolverecipientspage.cpp:505
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget
Definition: resolverecipientspage_p.h:50
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::setCertificates
void setCertificates(const QString &id, const std::vector< GpgME::Key > &pgpCerts, const std::vector< GpgME::Key > &cmsCerts)
Definition: resolverecipientspage.cpp:130
createCertificateSelectionDialog
static CertificateSelectionDialog * createCertificateSelectionDialog(QWidget *parent, GpgME::Protocol prot)
Definition: resolverecipientspage.cpp:257
Kleo::Crypto::Gui::ResolveRecipientsPage::ResolveRecipientsPage
ResolveRecipientsPage(QWidget *parent=0)
Definition: resolverecipientspage.cpp:498
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::selectedEntries
QStringList selectedEntries() const
Definition: resolverecipientspage.cpp:178
string
const char * string
Definition: verifychecksumscontroller.cpp:511
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::setProtocol
void setProtocol(GpgME::Protocol protocol)
Definition: resolverecipientspage.cpp:328
Kleo::Crypto::Gui::ResolveRecipientsPage::recipientsUserMutable
bool recipientsUserMutable() const
if true, the user is allowed to remove/add recipients via the UI.
Definition: resolverecipientspage.cpp:680
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::showSelectionDialog
void showSelectionDialog(const QString &id)
Definition: resolverecipientspage.cpp:171
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::mailbox
KMime::Types::Mailbox mailbox() const
Definition: resolverecipientspage.cpp:282
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::mailbox
KMime::Types::Mailbox mailbox(const QString &id) const
Definition: resolverecipientspage.cpp:125
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:189
name
const char * name
Definition: uiserver/selectcertificatecommand.cpp:114
protocol2option
static CertificateSelectionDialog::Option protocol2option(GpgME::Protocol proto)
Definition: resolverecipientspage.cpp:249
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::setSelected
void setSelected(bool selected)
Definition: resolverecipientspage.cpp:232
certificateresolver.h
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::~ItemWidget
~ItemWidget()
Definition: resolverecipientspage.cpp:223
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::~ListWidget
~ListWidget()
Definition: resolverecipientspage.cpp:87
Kleo::Crypto::Gui::WizardPage
Definition: wizardpage.h:48
keycache.h
Kleo::Crypto::Gui::ResolveRecipientsPage::setAdditionalRecipientsInfo
void setAdditionalRecipientsInfo(const std::vector< GpgME::Key > &recipients)
Definition: resolverecipientspage.cpp:612
Kleo::Formatting::formatKeyLink
QString formatKeyLink(const GpgME::Key &key)
resolverecipientspage_p.h
Kleo::Crypto::Gui::ResolveRecipientsPage::recipientPreferences
boost::shared_ptr< RecipientPreferences > recipientPreferences() const
Definition: resolverecipientspage.cpp:686
Kleo::Crypto::Gui::ResolveRecipientsPage::presetProtocol
GpgME::Protocol presetProtocol() const
the protocol set before the dialog is shown.
Definition: resolverecipientspage.cpp:537
Kleo::Crypto::Gui::ResolveRecipientsPage::ItemWidget::ItemWidget
ItemWidget(const QString &id, const QString &name, const KMime::Types::Mailbox &mbox, QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: resolverecipientspage.cpp:189
Kleo::Crypto::Gui::ResolveRecipientsPage::setRecipients
void setRecipients(const std::vector< KMime::Types::Mailbox > &recipients, const std::vector< KMime::Types::Mailbox > &encryptToSelfRecipients)
Definition: resolverecipientspage.cpp:621
Kleo::Class::AnyFormat
Definition: classify.h:58
resolverecipientspage.h
QList
Definition: commands/command.h:46
Kleo::Crypto::Gui::ResolveRecipientsPage::ListWidget::selectedCertificate
GpgME::Key selectedCertificate(const QString &id) const
Definition: resolverecipientspage.cpp:136
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