• 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
  • view
keylistcontroller.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  controllers/keylistcontroller.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 "keylistcontroller.h"
36 #include "tabwidget.h"
37 
38 #include <models/keycache.h>
39 #include <models/keylistmodel.h>
40 
41 #include <smartcard/readerstatus.h>
42 
43 #include <utils/formatting.h>
44 #include <utils/action_data.h>
45 
46 #include "tooltippreferences.h"
47 
48 #include "commands/exportcertificatecommand.h"
49 #include "commands/exportopenpgpcertstoservercommand.h"
50 #include "commands/exportsecretkeycommand.h"
51 #include "commands/importcertificatefromfilecommand.h"
52 #include "commands/changepassphrasecommand.h"
53 #include "commands/lookupcertificatescommand.h"
54 #include "commands/reloadkeyscommand.h"
55 #include "commands/refreshx509certscommand.h"
56 #include "commands/refreshopenpgpcertscommand.h"
57 #include "commands/detailscommand.h"
58 #include "commands/deletecertificatescommand.h"
59 #include "commands/decryptverifyfilescommand.h"
60 #include "commands/signencryptfilescommand.h"
61 #include "commands/clearcrlcachecommand.h"
62 #include "commands/dumpcrlcachecommand.h"
63 #include "commands/dumpcertificatecommand.h"
64 #include "commands/importcrlcommand.h"
65 #include "commands/changeexpirycommand.h"
66 #include "commands/changeownertrustcommand.h"
67 #include "commands/changeroottrustcommand.h"
68 #include "commands/certifycertificatecommand.h"
69 #include "commands/adduseridcommand.h"
70 #include "commands/newcertificatecommand.h"
71 #include "commands/checksumverifyfilescommand.h"
72 #include "commands/checksumcreatefilescommand.h"
73 
74 #include <kleo/stl_util.h>
75 
76 #include <gpgme++/key.h>
77 
78 #include <KActionCollection>
79 #include <KLocalizedString>
80 
81 #include <QAbstractItemView>
82 #include <QPointer>
83 #include <QItemSelectionModel>
84 #include <QAction>
85 
86 #ifndef Q_MOC_RUN
87 #include <boost/bind.hpp>
88 #endif
89 
90 #include <algorithm>
91 #include <cassert>
92 
93 using namespace Kleo;
94 using namespace Kleo::Commands;
95 using namespace Kleo::SmartCard;
96 using namespace boost;
97 using namespace GpgME;
98 
99 class KeyListController::Private {
100  friend class ::Kleo::KeyListController;
101  KeyListController * const q;
102 public:
103  explicit Private( KeyListController * qq );
104  ~Private();
105 
106  void connectView( QAbstractItemView * view );
107  void connectCommand( Command * cmd );
108 
109  void connectTabWidget();
110  void disconnectTabWidget();
111 
112  void addCommand( Command * cmd ) {
113  connectCommand( cmd );
114  commands.insert( std::lower_bound( commands.begin(), commands.end(), cmd ), cmd );
115  }
116  void addView( QAbstractItemView * view ) {
117  connectView( view );
118  views.insert( std::lower_bound( views.begin(), views.end(), view ), view );
119  }
120  void removeView( QAbstractItemView * view ) {
121  view->disconnect( q );
122  view->selectionModel()->disconnect( q );
123  views.erase( std::remove( views.begin(), views.end(), view ), views.end() );
124  }
125 
126 public:
127  void slotDestroyed( QObject * o ) {
128  kDebug() << ( void* )o;
129  views.erase( std::remove( views.begin(), views.end(), o ), views.end() );
130  commands.erase( std::remove( commands.begin(), commands.end(), o ), commands.end() );
131  }
132  void slotDoubleClicked( const QModelIndex & idx );
133  void slotActivated( const QModelIndex & idx );
134  void slotSelectionChanged( const QItemSelection & old, const QItemSelection & new_ );
135  void slotContextMenu( const QPoint & pos );
136  void slotCommandFinished();
137  void slotAddKey( const Key & key );
138  void slotAboutToRemoveKey( const Key & key );
139  void slotProgress( const QString & what, int current, int total ) {
140  emit q->progress( current, total );
141  if ( !what.isEmpty() )
142  emit q->message( what );
143  }
144  void slotActionTriggered();
145  void slotCurrentViewChanged( QAbstractItemView * view ) {
146  if ( view && !kdtools::binary_search( views, view ) ) {
147  kDebug() << "you need to register view" << view << "before trying to set it as the current view!";
148  addView( view );
149  }
150  currentView = view;
151  q->enableDisableActions( view ? view->selectionModel() : 0 );
152  }
153 
154 private:
155  int toolTipOptions() const;
156 
157 private:
158  static Command::Restrictions calculateRestrictionsMask( const QItemSelectionModel * sm );
159 
160 private:
161  struct action_item {
162  QPointer<QAction> action;
163  Command::Restrictions restrictions;
164  Command * (*createCommand)( QAbstractItemView *, KeyListController * );
165  };
166  std::vector<action_item> actions;
167  std::vector<QAbstractItemView*> views;
168  std::vector<Command*> commands;
169  QPointer<QWidget> parentWidget;
170  QPointer<TabWidget> tabWidget;
171  QPointer<QAbstractItemView> currentView;
172  QPointer<AbstractKeyListModel> flatModel, hierarchicalModel;
173 };
174 
175 
176 KeyListController::Private::Private( KeyListController * qq )
177  : q( qq ),
178  actions(),
179  views(),
180  commands(),
181  parentWidget(),
182  tabWidget(),
183  flatModel(),
184  hierarchicalModel()
185 {
186  connect( KeyCache::mutableInstance().get(), SIGNAL(added(GpgME::Key)),
187  q, SLOT(slotAddKey(GpgME::Key)) );
188  connect( KeyCache::mutableInstance().get(), SIGNAL(aboutToRemove(GpgME::Key)),
189  q, SLOT(slotAboutToRemoveKey(GpgME::Key)) );
190 }
191 
192 KeyListController::Private::~Private() {}
193 
194 KeyListController::KeyListController( QObject * p )
195  : QObject( p ), d( new Private( this ) )
196 {
197 
198 }
199 
200 KeyListController::~KeyListController() {}
201 
202 
203 
204 void KeyListController::Private::slotAddKey( const Key & key ) {
205  // ### make model act on keycache directly...
206  if ( flatModel )
207  flatModel->addKey( key );
208  if ( hierarchicalModel )
209  hierarchicalModel->addKey( key );
210 }
211 
212 
213 void KeyListController::Private::slotAboutToRemoveKey( const Key & key ) {
214  // ### make model act on keycache directly...
215  if ( flatModel )
216  flatModel->removeKey( key );
217  if ( hierarchicalModel )
218  hierarchicalModel->removeKey( key );
219 }
220 
221 void KeyListController::addView( QAbstractItemView * view ) {
222  if ( !view || kdtools::binary_search( d->views, view ) )
223  return;
224  d->addView( view );
225 }
226 
227 void KeyListController::removeView( QAbstractItemView * view ) {
228  if ( !view || !kdtools::binary_search( d->views, view ) )
229  return;
230  d->removeView( view );
231 }
232 
233 void KeyListController::setCurrentView( QAbstractItemView * view ) {
234  d->slotCurrentViewChanged( view );
235 }
236 
237 std::vector<QAbstractItemView*> KeyListController::views() const {
238  return d->views;
239 }
240 
241 void KeyListController::setFlatModel( AbstractKeyListModel * model ) {
242  if ( model == d->flatModel )
243  return;
244 
245  d->flatModel = model;
246 
247  if ( model ) {
248  model->clear();
249  model->addKeys( KeyCache::instance()->keys() );
250  model->setToolTipOptions( d->toolTipOptions() );
251  }
252 }
253 
254 void KeyListController::setHierarchicalModel( AbstractKeyListModel * model ) {
255  if ( model == d->hierarchicalModel )
256  return;
257 
258  d->hierarchicalModel = model;
259 
260  if ( model ) {
261  model->clear();
262  model->addKeys( KeyCache::instance()->keys() );
263  model->setToolTipOptions( d->toolTipOptions() );
264  }
265 }
266 
267 void KeyListController::setTabWidget( TabWidget * tabWidget ) {
268  if ( tabWidget == d->tabWidget )
269  return;
270 
271  d->disconnectTabWidget();
272 
273  d->tabWidget = tabWidget;
274 
275  d->connectTabWidget();
276 
277  d->slotCurrentViewChanged( tabWidget ? tabWidget->currentView() : 0 );
278 }
279 
280 void KeyListController::setParentWidget( QWidget * parent ) {
281  d->parentWidget = parent;
282 }
283 
284 QWidget * KeyListController::parentWidget() const {
285  return d->parentWidget;
286 }
287 
288 static const struct {
289  const char * signal;
290  const char * slot;
291 } tabs2controller[] = {
292  { SIGNAL(viewAdded(QAbstractItemView*)), SLOT(addView(QAbstractItemView*)) },
293  { SIGNAL(viewAboutToBeRemoved(QAbstractItemView*)), SLOT(removeView(QAbstractItemView*)) },
294  { SIGNAL(currentViewChanged(QAbstractItemView*)), SLOT(slotCurrentViewChanged(QAbstractItemView*)) },
295 };
296 static const unsigned int numTabs2Controller = sizeof tabs2controller / sizeof *tabs2controller ;
297 
298 void KeyListController::Private::connectTabWidget() {
299  if ( !tabWidget )
300  return;
301  kdtools::for_each( tabWidget->views(), boost::bind( &Private::addView, this, _1 ) );
302  for ( unsigned int i = 0 ; i < numTabs2Controller ; ++i )
303  connect( tabWidget, tabs2controller[i].signal, q, tabs2controller[i].slot );
304 }
305 
306 void KeyListController::Private::disconnectTabWidget() {
307  if ( !tabWidget )
308  return;
309  for ( unsigned int i = 0 ; i < numTabs2Controller ; ++i )
310  disconnect( tabWidget, tabs2controller[i].signal, q, tabs2controller[i].slot );
311  kdtools::for_each( tabWidget->views(), boost::bind( &Private::removeView, this, _1 ) );
312 }
313 
314 AbstractKeyListModel * KeyListController::flatModel() const {
315  return d->flatModel;
316 }
317 
318 AbstractKeyListModel * KeyListController::hierarchicalModel() const {
319  return d->hierarchicalModel;
320 }
321 
322 QAbstractItemView * KeyListController::currentView() const {
323  return d->currentView;
324 }
325 
326 TabWidget * KeyListController::tabWidget() const {
327  return d->tabWidget;
328 }
329 
330 void KeyListController::createActions( KActionCollection * coll ) {
331 
332  const action_data action_data[] = {
333  // File menu
334  { "file_new_certificate", i18n("New Certificate..."), QString(),
335  "view-certificate-add", 0, 0, QLatin1String("Ctrl+N"), false, true },
336  { "file_export_certificates", i18n("Export Certificates..."), QString(),
337  "view-certificate-export", 0, 0, QLatin1String("Ctrl+E"), false, true },
338  { "file_export_certificates_to_server", i18n("Export Certificates to Server..."), QString(),
339  "view-certificate-export-server", 0, 0, QLatin1String("Ctrl+Shift+E"), false, true },
340  { "file_export_secret_keys", i18n("Export Secret Keys..."), QString(),
341  "view-certificate-export-secret", 0, 0, QString(), false, true },
342  { "file_lookup_certificates", i18n("Lookup Certificates on Server..."), QString(),
343  "edit-find", 0, 0, QLatin1String("Shift+Ctrl+I"), false, true },
344  { "file_import_certificates", i18n("Import Certificates..."), QString(),
345  "view-certificate-import", 0, 0, QLatin1String("Ctrl+I"), false, true },
346  { "file_decrypt_verify_files", i18n("Decrypt/Verify Files..."), QString(),
347  "document-edit-decrypt-verify", 0, 0, QString(), false, true },
348  { "file_sign_encrypt_files", i18n("Sign/Encrypt Files..."), QString(),
349  "document-edit-sign-encrypt", 0, 0, QString(), false, true },
350  { "file_checksum_create_files", i18n("Create Checksum Files..."), QString(),
351  0/*"document-checksum-create"*/, 0, 0, QString(), false, true },
352  { "file_checksum_verify_files", i18n("Verify Checksum Files..."), QString(),
353  0/*"document-checksum-verify"*/, 0, 0, QString(), false, true },
354  // View menu
355  { "view_redisplay", i18n("Redisplay"), QString(),
356  "view-refresh", 0, 0, QLatin1String("F5"), false, true },
357  { "view_stop_operations", i18n( "Stop Operation" ), QString(),
358  "process-stop", this, SLOT(cancelCommands()), QLatin1String("Escape"), false, false },
359  { "view_certificate_details", i18n( "Certificate Details" ), QString(),
360  "dialog-information", 0, 0, QString(), false, true },
361  // Certificate menu
362  { "certificates_delete", i18n("Delete" ), QString()/*i18n("Delete selected certificates")*/,
363  "edit-delete", 0, 0, QLatin1String("Delete"), false, true },
364  { "certificates_certify_certificate", i18n("Certify Certificate..."), QString(),
365  "view-certificate-sign", 0, 0, QString(), false, true },
366  { "certificates_change_expiry", i18n("Change Expiry Date..."), QString(),
367  0, 0, 0, QString(), false, true },
368  { "certificates_change_owner_trust", i18n("Change Owner Trust..."), QString(),
369  0, 0, 0, QString(), false, true },
370  { "certificates_trust_root", i18n("Trust Root Certificate"), QString(),
371  0, 0, 0, QString(), false, true },
372  { "certificates_distrust_root", i18n("Distrust Root Certificate"), QString(),
373  0, 0, 0, QString(), false, true },
374  { "certificates_change_passphrase", i18n("Change Passphrase..."), QString(),
375  0, 0, 0, QString(), false, true },
376  { "certificates_add_userid", i18n("Add User-ID..."), QString(),
377  0, 0, 0, QString(), false, true },
378  { "certificates_dump_certificate", i18n("Dump Certificate"), QString(),
379  0, 0, 0, QString(), false, true },
380  // Tools menu
381  { "tools_refresh_x509_certificates", i18n("Refresh X.509 Certificates"), QString(),
382  "view-refresh", 0, 0, QString(), false, true },
383  { "tools_refresh_openpgp_certificates", i18n("Refresh OpenPGP Certificates"), QString(),
384  "view-refresh", 0, 0, QString(), false, true },
385 #ifndef KDEPIM_ONLY_KLEO
386  { "crl_clear_crl_cache", i18n("Clear CRL Cache"), QString(),
387  0, 0, 0, QString(), false, true },
388  { "crl_dump_crl_cache", i18n("Dump CRL Cache"), QString(),
389  0, 0, 0, QString(), false, true },
390 #endif // KDEPIM_ONLY_KLEO
391  { "crl_import_crl", i18n("Import CRL From File..."), QString(),
392  0, 0, 0, QString(), false, true },
393  // Window menu
394  // (come from TabWidget)
395  // Help menu
396  // (come from MainWindow)
397  };
398 
399 
400  make_actions_from_data( action_data, coll );
401 
402  if ( QAction * action = coll->action( QLatin1String("view_stop_operations") ) )
403  connect( this, SIGNAL(commandsExecuting(bool)), action, SLOT(setEnabled(bool)) );
404 
405  // ### somehow make this better...
406  registerActionForCommand<NewCertificateCommand>( coll->action( QLatin1String("file_new_certificate") ) );
407  //---
408  registerActionForCommand<LookupCertificatesCommand>( coll->action( QLatin1String("file_lookup_certificates") ) );
409  registerActionForCommand<ImportCertificateFromFileCommand>( coll->action( QLatin1String("file_import_certificates") ) );
410  //---
411  registerActionForCommand<ExportCertificateCommand>( coll->action( QLatin1String("file_export_certificates") ) );
412  registerActionForCommand<ExportSecretKeyCommand>( coll->action( QLatin1String("file_export_secret_keys") ) );
413  registerActionForCommand<ExportOpenPGPCertsToServerCommand>( coll->action( QLatin1String("file_export_certificates_to_server") ) );
414  //---
415  registerActionForCommand<DecryptVerifyFilesCommand>( coll->action(QLatin1String( "file_decrypt_verify_files") ) );
416  registerActionForCommand<SignEncryptFilesCommand>( coll->action( QLatin1String("file_sign_encrypt_files") ) );
417  //---
418  registerActionForCommand<ChecksumCreateFilesCommand>(coll->action( QLatin1String("file_checksum_create_files") ) );
419  registerActionForCommand<ChecksumVerifyFilesCommand>(coll->action( QLatin1String("file_checksum_verify_files") ) );
420 
421  registerActionForCommand<ReloadKeysCommand>( coll->action( QLatin1String("view_redisplay") ) );
422  //coll->action( "view_stop_operations" ) <-- already dealt with in make_actions_from_data()
423  registerActionForCommand<DetailsCommand>( coll->action( QLatin1String("view_certificate_details") ) );
424 
425  registerActionForCommand<ChangeOwnerTrustCommand>( coll->action( QLatin1String("certificates_change_owner_trust") ) );
426  registerActionForCommand<TrustRootCommand>( coll->action( QLatin1String("certificates_trust_root") ) );
427  registerActionForCommand<DistrustRootCommand>( coll->action( QLatin1String("certificates_distrust_root") ) );
428  //---
429  registerActionForCommand<CertifyCertificateCommand>( coll->action( QLatin1String("certificates_certify_certificate") ) );
430  registerActionForCommand<ChangeExpiryCommand>( coll->action( QLatin1String("certificates_change_expiry") ) );
431  registerActionForCommand<ChangePassphraseCommand>( coll->action( QLatin1String("certificates_change_passphrase") ) );
432  registerActionForCommand<AddUserIDCommand>( coll->action( QLatin1String("certificates_add_userid") ) );
433  //---
434  registerActionForCommand<DeleteCertificatesCommand>( coll->action( QLatin1String("certificates_delete") ) );
435  //---
436  registerActionForCommand<DumpCertificateCommand>( coll->action( QLatin1String("certificates_dump_certificate") ) );
437 
438  registerActionForCommand<RefreshX509CertsCommand>( coll->action( QLatin1String("tools_refresh_x509_certificates") ) );
439  registerActionForCommand<RefreshOpenPGPCertsCommand>(coll->action( QLatin1String("tools_refresh_openpgp_certificates") ) );
440  //---
441  registerActionForCommand<ImportCrlCommand>( coll->action( QLatin1String("crl_import_crl") ) );
442  //---
443  registerActionForCommand<ClearCrlCacheCommand>( coll->action( QLatin1String("crl_clear_crl_cache") ) );
444  registerActionForCommand<DumpCrlCacheCommand>( coll->action( QLatin1String("crl_dump_crl_cache") ) );
445 
446  enableDisableActions( 0 );
447 }
448 
449 void KeyListController::registerAction( QAction * action, Command::Restrictions restrictions, Command * (*create)( QAbstractItemView *, KeyListController * ) ) {
450  if ( !action )
451  return;
452  assert( !action->isCheckable() ); // can be added later, for now, disallow
453 
454  const Private::action_item ai = {
455  action, restrictions, create
456  };
457  connect( action, SIGNAL(triggered()), this, SLOT(slotActionTriggered()) );
458  d->actions.push_back( ai );
459 }
460 
461 void KeyListController::registerCommand( Command * cmd ) {
462  if ( !cmd || kdtools::binary_search( d->commands, cmd ) )
463  return;
464  d->addCommand( cmd );
465  kDebug() << ( void* )cmd;
466  if ( d->commands.size() == 1 )
467  emit commandsExecuting( true );
468 }
469 
470 bool KeyListController::hasRunningCommands() const {
471  return !d->commands.empty();
472 }
473 
474 bool KeyListController::shutdownWarningRequired() const {
475  return kdtools::any( d->commands, mem_fn( &Command::warnWhenRunningAtShutdown ) );
476 }
477 
478 // slot
479 void KeyListController::cancelCommands() {
480  kdtools::for_each( d->commands, mem_fn( &Command::cancel ) );
481 }
482 
483 void KeyListController::Private::connectView( QAbstractItemView * view ) {
484 
485  connect( view, SIGNAL(destroyed(QObject*)),
486  q, SLOT(slotDestroyed(QObject*)) );
487  connect( view, SIGNAL(doubleClicked(QModelIndex)),
488  q, SLOT(slotDoubleClicked(QModelIndex)) );
489  connect( view, SIGNAL(activated(QModelIndex)),
490  q, SLOT(slotActivated(QModelIndex)) );
491  connect( view->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
492  q, SLOT(slotSelectionChanged(QItemSelection,QItemSelection)) );
493 
494  view->setContextMenuPolicy( Qt::CustomContextMenu );
495  connect( view, SIGNAL(customContextMenuRequested(QPoint)),
496  q, SLOT(slotContextMenu(QPoint)) );
497 }
498 
499 void KeyListController::Private::connectCommand( Command * cmd ) {
500  if ( !cmd )
501  return;
502  connect( cmd, SIGNAL(destroyed(QObject*)), q, SLOT(slotDestroyed(QObject*)) );
503  connect( cmd, SIGNAL(finished()), q, SLOT(slotCommandFinished()) );
504  //connect( cmd, SIGNAL(canceled()), q, SLOT(slotCommandCanceled()) );
505  connect( cmd, SIGNAL(info(QString,int)), q, SIGNAL(message(QString,int)) );
506  connect( cmd, SIGNAL(progress(QString,int,int)), q, SLOT(slotProgress(QString,int,int)) );
507 }
508 
509 
510 void KeyListController::Private::slotDoubleClicked( const QModelIndex & idx ) {
511  QAbstractItemView * const view = qobject_cast<QAbstractItemView*>( q->sender() );
512  if ( !view || !kdtools::binary_search( views, view ) )
513  return;
514 
515  DetailsCommand * const c = new DetailsCommand( view, q );
516  if ( parentWidget )
517  c->setParentWidget( parentWidget );
518 
519  c->setIndex( idx );
520  c->start();
521 }
522 
523 void KeyListController::Private::slotActivated( const QModelIndex & idx )
524 {
525  Q_UNUSED( idx );
526  QAbstractItemView * const view = qobject_cast<QAbstractItemView*>( q->sender() );
527  if ( !view || !kdtools::binary_search( views, view ) )
528  return;
529 
530 }
531 
532 void KeyListController::Private::slotSelectionChanged( const QItemSelection & old, const QItemSelection & new_ )
533 {
534  Q_UNUSED( old );
535  Q_UNUSED( new_ );
536 
537  const QItemSelectionModel * const sm = qobject_cast<QItemSelectionModel*>( q->sender() );
538  if ( !sm )
539  return;
540  q->enableDisableActions( sm );
541 }
542 
543 void KeyListController::Private::slotContextMenu( const QPoint & p ) {
544  QAbstractItemView * const view = qobject_cast<QAbstractItemView*>( q->sender() );
545  if ( view && kdtools::binary_search( views, view ) )
546  emit q->contextMenuRequested( view, view->viewport()->mapToGlobal( p ) );
547  else
548  kDebug() << "sender is not a QAbstractItemView*!";
549 }
550 
551 void KeyListController::Private::slotCommandFinished() {
552  Command * const cmd = qobject_cast<Command*>( q->sender() );
553  if ( !cmd || !kdtools::binary_search( commands, cmd ) )
554  return;
555  kDebug() << ( void* )cmd;
556  if ( commands.size() == 1 )
557  emit q->commandsExecuting( false );
558 }
559 
560 void KeyListController::enableDisableActions( const QItemSelectionModel * sm ) const {
561  const Command::Restrictions restrictionsMask = d->calculateRestrictionsMask( sm );
562  Q_FOREACH( const Private::action_item & ai, d->actions )
563  if ( ai.action )
564  ai.action->setEnabled( ai.restrictions == ( ai.restrictions & restrictionsMask ) );
565 }
566 
567 static bool all_secret_are_not_owner_trust_ultimate( const std::vector<Key> & keys ) {
568  Q_FOREACH( const Key & key, keys )
569  if ( key.hasSecret() && key.ownerTrust() == Key::Ultimate )
570  return false;
571  return true;
572 }
573 
574 Command::Restrictions find_root_restrictions( const std::vector<Key> & keys ) {
575  bool trusted = false, untrusted = false;
576  Q_FOREACH( const Key & key, keys )
577  if ( key.isRoot() )
578  if ( key.userID(0).validity() == UserID::Ultimate )
579  trusted = true;
580  else
581  untrusted = true;
582  else
583  return Command::NoRestriction;
584  if ( trusted )
585  if ( untrusted )
586  return Command::NoRestriction;
587  else
588  return Command::MustBeTrustedRoot;
589  else
590  if ( untrusted )
591  return Command::MustBeUntrustedRoot;
592  else
593  return Command::NoRestriction;
594 }
595 
596 Command::Restrictions KeyListController::Private::calculateRestrictionsMask( const QItemSelectionModel * sm ) {
597  if ( !sm )
598  return 0;
599 
600  const KeyListModelInterface * const m = dynamic_cast<const KeyListModelInterface*>( sm->model() );
601  if ( !m )
602  return 0;
603 
604  const std::vector<Key> keys = m->keys( sm->selectedRows() );
605  if ( keys.empty() )
606  return 0;
607 
608  Command::Restrictions result = Command::NeedSelection;
609 
610  if ( keys.size() == 1 )
611  result |= Command::OnlyOneKey;
612 
613  if ( kdtools::all( keys.begin(), keys.end(), boost::bind( &Key::hasSecret, _1 ) ) )
614  result |= Command::NeedSecretKey;
615  else if ( !kdtools::any( keys.begin(), keys.end(), boost::bind( &Key::hasSecret, _1 ) ) )
616  result |= Command::MustNotBeSecretKey;
617 
618  if ( kdtools::all( keys.begin(), keys.end(), boost::bind( &Key::protocol, _1 ) == OpenPGP ) )
619  result |= Command::MustBeOpenPGP;
620  else if ( kdtools::all( keys.begin(), keys.end(), boost::bind( &Key::protocol, _1 ) == CMS ) )
621  result |= Command::MustBeCMS;
622 
623  if ( all_secret_are_not_owner_trust_ultimate( keys ) )
624  result |= Command::MayOnlyBeSecretKeyIfOwnerTrustIsNotYetUltimate;
625 
626  result |= find_root_restrictions( keys );
627 
628  if ( const ReaderStatus * rs = ReaderStatus::instance() ) {
629  if ( rs->anyCardHasNullPin() )
630  result |= Command::AnyCardHasNullPin;
631  if ( rs->anyCardCanLearnKeys() )
632  result |= Command::AnyCardCanLearnKeys;
633  }
634 
635  return result;
636 }
637 
638 void KeyListController::Private::slotActionTriggered() {
639  if ( const QObject * const s = q->sender() ) {
640  const std::vector<action_item>::const_iterator it
641  = kdtools::find_if( actions, boost::bind( &action_item::action, _1 ) == q->sender() );
642  if ( it != actions.end() )
643  if ( Command * const c = it->createCommand( this->currentView, q ) )
644  {
645  if ( parentWidget )
646  c->setParentWidget( parentWidget );
647  c->start();
648  }
649  else
650  kDebug() << "createCommand() == NULL for action(?) \""
651  << qPrintable( s->objectName() ) << "\"";
652  else
653  kDebug() << "I don't know anything about action(?) \"%s\"", qPrintable( s->objectName() );
654  } else {
655  kDebug() << "not called through a signal/slot connection (sender() == NULL)";
656  }
657 }
658 
659 int KeyListController::Private::toolTipOptions() const
660 {
661  using namespace Kleo::Formatting;
662  static const int validityFlags = Validity|Issuer|ExpiryDates|CertificateUsage;
663  static const int ownerFlags = Subject|UserIDs|OwnerTrust;
664  static const int detailsFlags = StorageLocation|CertificateType|SerialNumber|Fingerprint;
665 
666  const TooltipPreferences prefs;
667 
668  int flags = KeyID;
669  flags |= prefs.showValidity() ? validityFlags : 0;
670  flags |= prefs.showOwnerInformation() ? ownerFlags : 0;
671  flags |= prefs.showCertificateDetails() ? detailsFlags : 0;
672  return flags;
673 }
674 
675 void KeyListController::updateConfig()
676 {
677  const int opts = d->toolTipOptions();
678  if ( d->flatModel )
679  d->flatModel->setToolTipOptions( opts );
680  if ( d->hierarchicalModel )
681  d->hierarchicalModel->setToolTipOptions( opts );
682 }
683 
684 #include "moc_keylistcontroller.cpp"
flags
static const char * flags[]
Definition: readerstatus.cpp:114
Kleo::KeyListController::removeView
void removeView(QAbstractItemView *view)
Definition: keylistcontroller.cpp:227
Kleo::Formatting::CertificateType
Definition: formatting.h:75
QModelIndex
Kleo::KeyListController::~KeyListController
~KeyListController()
Definition: keylistcontroller.cpp:200
decryptverifyfilescommand.h
QWidget
Kleo::KeyListController::shutdownWarningRequired
bool shutdownWarningRequired() const
Definition: keylistcontroller.cpp:474
adduseridcommand.h
keylistcontroller.h
Kleo::KeyListController::tabWidget
TabWidget * tabWidget() const
Definition: keylistcontroller.cpp:326
newcertificatecommand.h
Kleo::KeyListController::addView
void addView(QAbstractItemView *view)
Definition: keylistcontroller.cpp:221
QAbstractItemView
Kleo::Command::MustBeUntrustedRoot
Definition: commands/command.h:84
Kleo::TabWidget
Definition: tabwidget.h:58
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
changeroottrustcommand.h
Kleo::KeyListController::setCurrentView
void setCurrentView(QAbstractItemView *view)
Definition: keylistcontroller.cpp:233
Kleo::KeyListController
Definition: keylistcontroller.h:55
deletecertificatescommand.h
Kleo::KeyListController::setFlatModel
void setFlatModel(AbstractKeyListModel *model)
Definition: keylistcontroller.cpp:241
Kleo::KeyCache::added
void added(const GpgME::Key &key)
QPointer< QAction >
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
formatting.h
Kleo::KeyListController::setTabWidget
void setTabWidget(TabWidget *tabs)
Definition: keylistcontroller.cpp:267
Kleo::AbstractKeyListModel::clear
void clear()
Definition: keylistmodel.cpp:233
Kleo::Command::start
void start()
Definition: commands/command.cpp:182
QAbstractScrollArea::viewport
QWidget * viewport() const
Kleo::KeyListController::setHierarchicalModel
void setHierarchicalModel(AbstractKeyListModel *model)
Definition: keylistcontroller.cpp:254
Kleo::AbstractKeyListModel::setToolTipOptions
void setToolTipOptions(int opts)
Definition: keylistmodel.cpp:161
QPoint
Kleo::Command::AnyCardHasNullPin
Definition: commands/command.h:79
Kleo::KeyListController::KeyListController
KeyListController(QObject *parent=0)
Definition: keylistcontroller.cpp:194
Kleo::Command::NoRestriction
Definition: commands/command.h:68
readerstatus.h
Kleo::Command::AnyCardCanLearnKeys
Definition: commands/command.h:80
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
refreshx509certscommand.h
numTabs2Controller
static const unsigned int numTabs2Controller
Definition: keylistcontroller.cpp:296
tabs2controller
static const struct @9 tabs2controller[]
Kleo::Command::MayOnlyBeSecretKeyIfOwnerTrustIsNotYetUltimate
Definition: commands/command.h:77
Kleo::Formatting::UserIDs
Definition: formatting.h:78
Kleo::Command::warnWhenRunningAtShutdown
bool warnWhenRunningAtShutdown() const
Definition: commands/command.cpp:132
lookupcertificatescommand.h
tabwidget.h
Kleo::Command::NeedSelection
Definition: commands/command.h:69
Kleo::Command::OnlyOneKey
Definition: commands/command.h:70
Kleo::KeyListController::updateConfig
void updateConfig()
Definition: keylistcontroller.cpp:675
action_data.h
refreshopenpgpcertscommand.h
QObject
Kleo::Class::OpenPGP
Definition: classify.h:49
Kleo::Command::MustBeCMS
Definition: commands/command.h:74
exportsecretkeycommand.h
Kleo::KeyListController::registerCommand
void registerCommand(Command *cmd)
Definition: keylistcontroller.cpp:461
clearcrlcachecommand.h
Kleo::Formatting::ExpiryDates
Definition: formatting.h:74
QString::isEmpty
bool isEmpty() const
changeownertrustcommand.h
QItemSelectionModel::selectedRows
QModelIndexList selectedRows(int column) const
Kleo::Formatting::Issuer
Definition: formatting.h:72
Kleo::Class::CMS
Definition: classify.h:48
importcrlcommand.h
reloadkeyscommand.h
Kleo::Command::MustBeOpenPGP
Definition: commands/command.h:73
QString
Kleo::Command::setIndex
void setIndex(const QModelIndex &idx)
Definition: commands/command.cpp:162
Kleo::Command::cancel
void cancel()
Definition: commands/command.cpp:186
Kleo::KeyListController::cancelCommands
void cancelCommands()
Definition: keylistcontroller.cpp:479
Kleo::AbstractKeyListModel::addKeys
QList< QModelIndex > addKeys(const std::vector< GpgME::Key > &keys)
Definition: keylistmodel.cpp:223
dumpcrlcachecommand.h
detailscommand.h
exportopenpgpcertstoservercommand.h
Kleo::action_data
Definition: action_data.h:44
Kleo::AbstractKeyListModel
Definition: keylistmodel.h:49
Kleo::KeyListController::parentWidget
QWidget * parentWidget() const
Definition: keylistcontroller.cpp:284
Kleo::Command::MustNotBeSecretKey
Definition: commands/command.h:72
find_root_restrictions
Command::Restrictions find_root_restrictions(const std::vector< Key > &keys)
Definition: keylistcontroller.cpp:574
checksumverifyfilescommand.h
Kleo::KeyListController::flatModel
AbstractKeyListModel * flatModel() const
Definition: keylistcontroller.cpp:314
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
Kleo::KeyListModelInterface
Definition: keylistmodelinterface.h:47
Kleo::KeyListController::setParentWidget
void setParentWidget(QWidget *parent)
Definition: keylistcontroller.cpp:280
signal
const char * signal
Definition: keylistcontroller.cpp:289
QAction::isCheckable
bool isCheckable() const
Kleo::Command::MustBeTrustedRoot
Definition: commands/command.h:83
keylistmodel.h
Kleo::KeyListController::commandsExecuting
void commandsExecuting(bool)
Kleo::Commands::DetailsCommand
Definition: detailscommand.h:45
QItemSelection
Kleo::SmartCard::ReaderStatus
Definition: readerstatus.h:46
signencryptfilescommand.h
dumpcertificatecommand.h
QLatin1String
slot
const char * slot
Definition: keylistcontroller.cpp:290
Kleo::KeyCache::aboutToRemove
void aboutToRemove(const GpgME::Key &key)
q
#define q
Definition: adduseridcommand.cpp:90
QAction
Kleo::Formatting::StorageLocation
Definition: formatting.h:70
Kleo::Formatting::CertificateUsage
Definition: formatting.h:76
Kleo::Command::NeedSecretKey
Definition: commands/command.h:71
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:190
checksumcreatefilescommand.h
exportcertificatecommand.h
certifycertificatecommand.h
Kleo::Formatting::Validity
Definition: formatting.h:69
Kleo::KeyListModelInterface::keys
virtual std::vector< GpgME::Key > keys(const QList< QModelIndex > &idxs) const =0
Kleo::Formatting::Subject
Definition: formatting.h:73
Kleo::make_actions_from_data
void make_actions_from_data(const action_data *data, unsigned int numData, KActionCollection *collection)
Definition: action_data.cpp:66
Kleo::Formatting::SerialNumber
Definition: formatting.h:71
Kleo::KeyListController::createActions
void createActions(KActionCollection *collection)
Definition: keylistcontroller.cpp:330
Kleo::Formatting::OwnerTrust
Definition: formatting.h:79
keycache.h
QItemSelectionModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
Kleo::Command::setParentWidget
void setParentWidget(QWidget *widget)
Definition: commands/command.cpp:136
Kleo::KeyListController::currentView
QAbstractItemView * currentView() const
Definition: keylistcontroller.cpp:322
changeexpirycommand.h
Kleo::KeyListController::enableDisableActions
void enableDisableActions(const QItemSelectionModel *sm) const
Definition: keylistcontroller.cpp:560
Kleo::Formatting::KeyID
Definition: formatting.h:68
Kleo::Command
Definition: commands/command.h:58
QItemSelectionModel::model
const QAbstractItemModel * model() const
importcertificatefromfilecommand.h
Kleo::KeyListController::views
std::vector< QAbstractItemView * > views() const
Definition: keylistcontroller.cpp:237
Kleo::KeyListController::hasRunningCommands
bool hasRunningCommands() const
Definition: keylistcontroller.cpp:470
Kleo::KeyCache::mutableInstance
static boost::shared_ptr< KeyCache > mutableInstance()
Definition: keycache.cpp:194
Kleo::KeyListController::hierarchicalModel
AbstractKeyListModel * hierarchicalModel() const
Definition: keylistcontroller.cpp:318
changepassphrasecommand.h
Kleo::Formatting::Fingerprint
Definition: formatting.h:77
all_secret_are_not_owner_trust_ultimate
static bool all_secret_are_not_owner_trust_ultimate(const std::vector< Key > &keys)
Definition: keylistcontroller.cpp:567
Kleo::TabWidget::currentView
QAbstractItemView * currentView() const
Definition: tabwidget.cpp:656
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