• 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
  • 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 <QTreeView>
83 #include <QTableView>
84 #include <QPointer>
85 #include <QItemSelectionModel>
86 #include <QAction>
87 
88 #include <boost/bind.hpp>
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 #ifndef _WIN32_WCE
419  registerActionForCommand<ChecksumCreateFilesCommand>(coll->action( QLatin1String("file_checksum_create_files") ) );
420  registerActionForCommand<ChecksumVerifyFilesCommand>(coll->action( QLatin1String("file_checksum_verify_files") ) );
421 #endif
422 
423  registerActionForCommand<ReloadKeysCommand>( coll->action( QLatin1String("view_redisplay") ) );
424  //coll->action( "view_stop_operations" ) <-- already dealt with in make_actions_from_data()
425  registerActionForCommand<DetailsCommand>( coll->action( QLatin1String("view_certificate_details") ) );
426 
427  registerActionForCommand<ChangeOwnerTrustCommand>( coll->action( QLatin1String("certificates_change_owner_trust") ) );
428  registerActionForCommand<TrustRootCommand>( coll->action( QLatin1String("certificates_trust_root") ) );
429  registerActionForCommand<DistrustRootCommand>( coll->action( QLatin1String("certificates_distrust_root") ) );
430  //---
431  registerActionForCommand<CertifyCertificateCommand>( coll->action( QLatin1String("certificates_certify_certificate") ) );
432  registerActionForCommand<ChangeExpiryCommand>( coll->action( QLatin1String("certificates_change_expiry") ) );
433  registerActionForCommand<ChangePassphraseCommand>( coll->action( QLatin1String("certificates_change_passphrase") ) );
434  registerActionForCommand<AddUserIDCommand>( coll->action( QLatin1String("certificates_add_userid") ) );
435  //---
436  registerActionForCommand<DeleteCertificatesCommand>( coll->action( QLatin1String("certificates_delete") ) );
437  //---
438  registerActionForCommand<DumpCertificateCommand>( coll->action( QLatin1String("certificates_dump_certificate") ) );
439 
440  registerActionForCommand<RefreshX509CertsCommand>( coll->action( QLatin1String("tools_refresh_x509_certificates") ) );
441  registerActionForCommand<RefreshOpenPGPCertsCommand>(coll->action( QLatin1String("tools_refresh_openpgp_certificates") ) );
442  //---
443  registerActionForCommand<ImportCrlCommand>( coll->action( QLatin1String("crl_import_crl") ) );
444  //---
445  registerActionForCommand<ClearCrlCacheCommand>( coll->action( QLatin1String("crl_clear_crl_cache") ) );
446  registerActionForCommand<DumpCrlCacheCommand>( coll->action( QLatin1String("crl_dump_crl_cache") ) );
447 
448  enableDisableActions( 0 );
449 }
450 
451 void KeyListController::registerAction( QAction * action, Command::Restrictions restrictions, Command * (*create)( QAbstractItemView *, KeyListController * ) ) {
452  if ( !action )
453  return;
454  assert( !action->isCheckable() ); // can be added later, for now, disallow
455 
456  const Private::action_item ai = {
457  action, restrictions, create
458  };
459  connect( action, SIGNAL(triggered()), this, SLOT(slotActionTriggered()) );
460  d->actions.push_back( ai );
461 }
462 
463 void KeyListController::registerCommand( Command * cmd ) {
464  if ( !cmd || kdtools::binary_search( d->commands, cmd ) )
465  return;
466  d->addCommand( cmd );
467  kDebug() << ( void* )cmd;
468  if ( d->commands.size() == 1 )
469  emit commandsExecuting( true );
470 }
471 
472 bool KeyListController::hasRunningCommands() const {
473  return !d->commands.empty();
474 }
475 
476 bool KeyListController::shutdownWarningRequired() const {
477  return kdtools::any( d->commands, mem_fn( &Command::warnWhenRunningAtShutdown ) );
478 }
479 
480 // slot
481 void KeyListController::cancelCommands() {
482  kdtools::for_each( d->commands, mem_fn( &Command::cancel ) );
483 }
484 
485 void KeyListController::Private::connectView( QAbstractItemView * view ) {
486 
487  connect( view, SIGNAL(destroyed(QObject*)),
488  q, SLOT(slotDestroyed(QObject*)) );
489  connect( view, SIGNAL(doubleClicked(QModelIndex)),
490  q, SLOT(slotDoubleClicked(QModelIndex)) );
491  connect( view, SIGNAL(activated(QModelIndex)),
492  q, SLOT(slotActivated(QModelIndex)) );
493  connect( view->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
494  q, SLOT(slotSelectionChanged(QItemSelection,QItemSelection)) );
495 
496  view->setContextMenuPolicy( Qt::CustomContextMenu );
497  connect( view, SIGNAL(customContextMenuRequested(QPoint)),
498  q, SLOT(slotContextMenu(QPoint)) );
499 }
500 
501 void KeyListController::Private::connectCommand( Command * cmd ) {
502  if ( !cmd )
503  return;
504  connect( cmd, SIGNAL(destroyed(QObject*)), q, SLOT(slotDestroyed(QObject*)) );
505  connect( cmd, SIGNAL(finished()), q, SLOT(slotCommandFinished()) );
506  //connect( cmd, SIGNAL(canceled()), q, SLOT(slotCommandCanceled()) );
507  connect( cmd, SIGNAL(info(QString,int)), q, SIGNAL(message(QString,int)) );
508  connect( cmd, SIGNAL(progress(QString,int,int)), q, SLOT(slotProgress(QString,int,int)) );
509 }
510 
511 
512 void KeyListController::Private::slotDoubleClicked( const QModelIndex & idx ) {
513  QAbstractItemView * const view = qobject_cast<QAbstractItemView*>( q->sender() );
514  if ( !view || !kdtools::binary_search( views, view ) )
515  return;
516 
517  DetailsCommand * const c = new DetailsCommand( view, q );
518  if ( parentWidget )
519  c->setParentWidget( parentWidget );
520 
521  c->setIndex( idx );
522  c->start();
523 }
524 
525 void KeyListController::Private::slotActivated( const QModelIndex & idx )
526 {
527  Q_UNUSED( idx );
528  QAbstractItemView * const view = qobject_cast<QAbstractItemView*>( q->sender() );
529  if ( !view || !kdtools::binary_search( views, view ) )
530  return;
531 
532 }
533 
534 void KeyListController::Private::slotSelectionChanged( const QItemSelection & old, const QItemSelection & new_ )
535 {
536  Q_UNUSED( old );
537  Q_UNUSED( new_ );
538 
539  const QItemSelectionModel * const sm = qobject_cast<QItemSelectionModel*>( q->sender() );
540  if ( !sm )
541  return;
542  q->enableDisableActions( sm );
543 }
544 
545 void KeyListController::Private::slotContextMenu( const QPoint & p ) {
546  QAbstractItemView * const view = qobject_cast<QAbstractItemView*>( q->sender() );
547  if ( view && kdtools::binary_search( views, view ) )
548  emit q->contextMenuRequested( view, view->viewport()->mapToGlobal( p ) );
549  else
550  kDebug() << "sender is not a QAbstractItemView*!";
551 }
552 
553 void KeyListController::Private::slotCommandFinished() {
554  Command * const cmd = qobject_cast<Command*>( q->sender() );
555  if ( !cmd || !kdtools::binary_search( commands, cmd ) )
556  return;
557  kDebug() << ( void* )cmd;
558  if ( commands.size() == 1 )
559  emit q->commandsExecuting( false );
560 }
561 
562 void KeyListController::enableDisableActions( const QItemSelectionModel * sm ) const {
563  const Command::Restrictions restrictionsMask = d->calculateRestrictionsMask( sm );
564  Q_FOREACH( const Private::action_item & ai, d->actions )
565  if ( ai.action )
566  ai.action->setEnabled( ai.restrictions == ( ai.restrictions & restrictionsMask ) );
567 }
568 
569 static bool all_secret_are_not_owner_trust_ultimate( const std::vector<Key> & keys ) {
570  Q_FOREACH( const Key & key, keys )
571  if ( key.hasSecret() && key.ownerTrust() == Key::Ultimate )
572  return false;
573  return true;
574 }
575 
576 Command::Restrictions find_root_restrictions( const std::vector<Key> & keys ) {
577  bool trusted = false, untrusted = false;
578  Q_FOREACH( const Key & key, keys )
579  if ( key.isRoot() )
580  if ( key.userID(0).validity() == UserID::Ultimate )
581  trusted = true;
582  else
583  untrusted = true;
584  else
585  return Command::NoRestriction;
586  if ( trusted )
587  if ( untrusted )
588  return Command::NoRestriction;
589  else
590  return Command::MustBeTrustedRoot;
591  else
592  if ( untrusted )
593  return Command::MustBeUntrustedRoot;
594  else
595  return Command::NoRestriction;
596 }
597 
598 Command::Restrictions KeyListController::Private::calculateRestrictionsMask( const QItemSelectionModel * sm ) {
599  if ( !sm )
600  return 0;
601 
602  const KeyListModelInterface * const m = dynamic_cast<const KeyListModelInterface*>( sm->model() );
603  if ( !m )
604  return 0;
605 
606  const std::vector<Key> keys = m->keys( sm->selectedRows() );
607  if ( keys.empty() )
608  return 0;
609 
610  Command::Restrictions result = Command::NeedSelection;
611 
612  if ( keys.size() == 1 )
613  result |= Command::OnlyOneKey;
614 
615  if ( kdtools::all( keys.begin(), keys.end(), boost::bind( &Key::hasSecret, _1 ) ) )
616  result |= Command::NeedSecretKey;
617  else if ( !kdtools::any( keys.begin(), keys.end(), boost::bind( &Key::hasSecret, _1 ) ) )
618  result |= Command::MustNotBeSecretKey;
619 
620  if ( kdtools::all( keys.begin(), keys.end(), boost::bind( &Key::protocol, _1 ) == OpenPGP ) )
621  result |= Command::MustBeOpenPGP;
622  else if ( kdtools::all( keys.begin(), keys.end(), boost::bind( &Key::protocol, _1 ) == CMS ) )
623  result |= Command::MustBeCMS;
624 
625  if ( all_secret_are_not_owner_trust_ultimate( keys ) )
626  result |= Command::MayOnlyBeSecretKeyIfOwnerTrustIsNotYetUltimate;
627 
628  result |= find_root_restrictions( keys );
629 
630 #ifndef _WIN32_WCE
631  if ( const ReaderStatus * rs = ReaderStatus::instance() ) {
632  if ( rs->anyCardHasNullPin() )
633  result |= Command::AnyCardHasNullPin;
634  if ( rs->anyCardCanLearnKeys() )
635  result |= Command::AnyCardCanLearnKeys;
636  }
637 #endif
638 
639  return result;
640 }
641 
642 void KeyListController::Private::slotActionTriggered() {
643  if ( const QObject * const s = q->sender() ) {
644  const std::vector<action_item>::const_iterator it
645  = kdtools::find_if( actions, boost::bind( &action_item::action, _1 ) == q->sender() );
646  if ( it != actions.end() )
647  if ( Command * const c = it->createCommand( this->currentView, q ) )
648  {
649  if ( parentWidget )
650  c->setParentWidget( parentWidget );
651  c->start();
652  }
653  else
654  kDebug() << "createCommand() == NULL for action(?) \""
655  << qPrintable( s->objectName() ) << "\"";
656  else
657  kDebug() << "I don't know anything about action(?) \"%s\"", qPrintable( s->objectName() );
658  } else {
659  kDebug() << "not called through a signal/slot connection (sender() == NULL)";
660  }
661 }
662 
663 int KeyListController::Private::toolTipOptions() const
664 {
665  using namespace Kleo::Formatting;
666  static const int validityFlags = Validity|Issuer|ExpiryDates|CertificateUsage;
667  static const int ownerFlags = Subject|UserIDs|OwnerTrust;
668  static const int detailsFlags = StorageLocation|CertificateType|SerialNumber|Fingerprint;
669 
670  const TooltipPreferences prefs;
671 
672  int flags = KeyID;
673  flags |= prefs.showValidity() ? validityFlags : 0;
674  flags |= prefs.showOwnerInformation() ? ownerFlags : 0;
675  flags |= prefs.showCertificateDetails() ? detailsFlags : 0;
676  return flags;
677 }
678 
679 void KeyListController::updateConfig()
680 {
681  const int opts = d->toolTipOptions();
682  if ( d->flatModel )
683  d->flatModel->setToolTipOptions( opts );
684  if ( d->hierarchicalModel )
685  d->hierarchicalModel->setToolTipOptions( opts );
686 }
687 
688 #include "moc_keylistcontroller.cpp"
flags
static const char * flags[]
Definition: readerstatus.cpp:115
Kleo::KeyListController::removeView
void removeView(QAbstractItemView *view)
Definition: keylistcontroller.cpp:227
Kleo::Formatting::CertificateType
Definition: formatting.h:75
Kleo::KeyListController::~KeyListController
~KeyListController()
Definition: keylistcontroller.cpp:200
signal
const char * signal
Definition: keytreeview.cpp:359
decryptverifyfilescommand.h
Kleo::KeyListController::shutdownWarningRequired
bool shutdownWarningRequired() const
Definition: keylistcontroller.cpp:476
adduseridcommand.h
Kleo::TooltipPreferences
Definition: tooltippreferences.h:12
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
Kleo::Command::MustBeUntrustedRoot
Definition: commands/command.h:84
Kleo::TabWidget
Definition: tabwidget.h:56
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
QWidget
Kleo::KeyCache::added
void added(const GpgME::Key &key)
formatting.h
Kleo::KeyListController::setTabWidget
void setTabWidget(TabWidget *tabs)
Definition: keylistcontroller.cpp:267
Kleo::AbstractKeyListModel::clear
void clear()
Definition: keylistmodel.cpp:239
Kleo::Command::start
void start()
Definition: commands/command.cpp:182
Kleo::KeyListController::setHierarchicalModel
void setHierarchicalModel(AbstractKeyListModel *model)
Definition: keylistcontroller.cpp:254
tooltippreferences.h
Kleo::AbstractKeyListModel::setToolTipOptions
void setToolTipOptions(int opts)
Definition: keylistmodel.cpp:167
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
refreshx509certscommand.h
numTabs2Controller
static const unsigned int numTabs2Controller
Definition: keylistcontroller.cpp:296
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:679
action_data.h
refreshopenpgpcertscommand.h
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:463
clearcrlcachecommand.h
Kleo::Formatting::ExpiryDates
Definition: formatting.h:74
changeownertrustcommand.h
Kleo::Formatting::Issuer
Definition: formatting.h:72
Kleo::Class::CMS
Definition: classify.h:48
tabs2controller
static const struct @13 tabs2controller[]
importcrlcommand.h
reloadkeyscommand.h
Kleo::Command::MustBeOpenPGP
Definition: commands/command.h:73
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:481
Kleo::AbstractKeyListModel::addKeys
QList< QModelIndex > addKeys(const std::vector< GpgME::Key > &keys)
Definition: keylistmodel.cpp:229
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:576
checksumverifyfilescommand.h
Kleo::KeyListController::flatModel
AbstractKeyListModel * flatModel() const
Definition: keylistcontroller.cpp:314
Kleo::KeyListModelInterface
Definition: keylistmodelinterface.h:47
Kleo::KeyListController::setParentWidget
void setParentWidget(QWidget *parent)
Definition: keylistcontroller.cpp:280
Kleo::Command::MustBeTrustedRoot
Definition: commands/command.h:83
keylistmodel.h
Kleo::KeyListController::commandsExecuting
void commandsExecuting(bool)
Kleo::Commands::DetailsCommand
Definition: detailscommand.h:45
Kleo::SmartCard::ReaderStatus
Definition: readerstatus.h:46
signencryptfilescommand.h
dumpcertificatecommand.h
Kleo::KeyCache::aboutToRemove
void aboutToRemove(const GpgME::Key &key)
q
#define q
Definition: adduseridcommand.cpp:91
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:189
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
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:562
Kleo::Formatting::KeyID
Definition: formatting.h:68
Kleo::Command
Definition: commands/command.h:58
importcertificatefromfilecommand.h
slot
const char * slot
Definition: keytreeview.cpp:360
Kleo::KeyListController::views
std::vector< QAbstractItemView * > views() const
Definition: keylistcontroller.cpp:237
Kleo::KeyListController::hasRunningCommands
bool hasRunningCommands() const
Definition: keylistcontroller.cpp:472
Kleo::KeyCache::mutableInstance
static boost::shared_ptr< KeyCache > mutableInstance()
Definition: keycache.cpp:193
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:569
Kleo::TabWidget::currentView
QAbstractItemView * currentView() const
Definition: tabwidget.cpp:660
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 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