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