• 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
  • uiserver
uiserver/selectcertificatecommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  uiserver/selectcertificatecommand.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 "selectcertificatecommand.h"
36 
37 #include <dialogs/certificateselectiondialog.h>
38 
39 #include <models/keycache.h>
40 
41 #include <boost/mem_fn.hpp>
42 
43 #include <kleo/stl_util.h>
44 #include <kleo/exception.h>
45 
46 #include <gpgme++/key.h>
47 
48 #include <gpg-error.h>
49 
50 #include <KDebug>
51 #include <KLocale>
52 
53 #include <QVariant>
54 #include <QByteArray>
55 #include <QIODevice>
56 #include <QList>
57 #include <QPointer>
58 
59 #include <string>
60 #include <algorithm>
61 
62 using namespace Kleo;
63 using namespace Kleo::Dialogs;
64 using namespace GpgME;
65 using namespace boost;
66 
67 static const char option_prefix[] = "prefix";
68 
69 class SelectCertificateCommand::Private {
70  friend class ::Kleo::SelectCertificateCommand;
71  SelectCertificateCommand * const q;
72 public:
73  Private( SelectCertificateCommand * qq ) :
74  q( qq ),
75  dialog()
76  {
77 
78  }
79 
80 private:
81  void slotDialogAccepted();
82  void slotDialogRejected();
83  void slotSelectedCertificates( int, const QByteArray & );
84 
85 private:
86  void ensureDialogCreated() {
87  if ( dialog )
88  return;
89  dialog = new CertificateSelectionDialog;
90  q->applyWindowID( dialog );
91  dialog->setAttribute( Qt::WA_DeleteOnClose );
92  //dialog->setWindowTitle( i18nc( "@title", "Certificate Selection" ) );
93  connect( dialog, SIGNAL(accepted()), q, SLOT(slotDialogAccepted()) );
94  connect( dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()) );
95  }
96  void ensureDialogShown() {
97  ensureDialogCreated();
98  if ( dialog->isVisible() )
99  dialog->raise();
100  else
101  dialog->show();
102  }
103 
104 private:
105  QPointer<CertificateSelectionDialog> dialog;
106 };
107 
108 SelectCertificateCommand::SelectCertificateCommand()
109  : QObject(), AssuanCommandMixin<SelectCertificateCommand>(), d( new Private( this ) ) {}
110 
111 SelectCertificateCommand::~SelectCertificateCommand() {}
112 
113 static const struct {
114  const char * name;
115  CertificateSelectionDialog::Option option;
116 } option_table[] = {
117  { "multi", CertificateSelectionDialog::MultiSelection },
118  { "sign-only", CertificateSelectionDialog::SignOnly },
119  { "encrypt-only", CertificateSelectionDialog::EncryptOnly },
120  { "openpgp-only", CertificateSelectionDialog::OpenPGPFormat },
121  { "x509-only", CertificateSelectionDialog::CMSFormat },
122  { "secret-only", CertificateSelectionDialog::SecretKeys },
123 };
124 
125 int SelectCertificateCommand::doStart() {
126 
127  d->ensureDialogCreated();
128 
129  CertificateSelectionDialog::Options opts;
130  for ( unsigned int i = 0 ; i < sizeof option_table / sizeof *option_table ; ++i )
131  if ( hasOption( option_table[i].name ) )
132  opts |= option_table[i].option;
133 
134  d->dialog->setOptions( opts );
135 
136  if ( const int err = inquire( "SELECTED_CERTIFICATES",
137  this, SLOT(slotSelectedCertificates(int,QByteArray)) ) )
138  return err;
139 
140  d->ensureDialogShown();
141 
142  return 0;
143 }
144 
145 void SelectCertificateCommand::Private::slotSelectedCertificates( int err, const QByteArray & data ) {
146  kDebug() << err << ", " << data.constData();
147  if ( err )
148  return;
149  const std::vector<std::string> fprs = kdtools::transform< std::vector<std::string> >( data.split( '\n' ), mem_fn( &QByteArray::constData ) );
150  const std::vector<Key> keys = KeyCache::instance()->findByKeyIDOrFingerprint( fprs );
151  Q_FOREACH( const Key & key, keys )
152  kDebug() << "found key " << key.userID(0).id();
153  if ( dialog )
154  dialog->selectCertificates( keys );
155  else
156  kWarning() << "dialog == NULL in slotSelectedCertificates";
157 }
158 
159 void SelectCertificateCommand::doCanceled() {
160  if ( d->dialog )
161  d->dialog->close();
162 }
163 
164 void SelectCertificateCommand::Private::slotDialogAccepted() {
165  try {
166  QByteArray data;
167  Q_FOREACH( const Key & key, dialog->selectedCertificates() ) {
168  data += key.primaryFingerprint();
169  data += '\n';
170  }
171  q->sendData( data );
172  q->done();
173  } catch ( const Exception & e ) {
174  q->done( e.error(), e.message() );
175  } catch ( const std::exception & e ) {
176  q->done( makeError( GPG_ERR_UNEXPECTED ),
177  i18n("Caught unexpected exception in SelectCertificateCommand::Private::slotDialogAccepted: %1",
178  QString::fromLocal8Bit( e.what() ) ) );
179  } catch ( ... ) {
180  q->done( makeError( GPG_ERR_UNEXPECTED ),
181  i18n("Caught unknown exception in SelectCertificateCommand::Private::slotDialogAccepted") );
182  }
183 }
184 
185 void SelectCertificateCommand::Private::slotDialogRejected() {
186  dialog = 0;
187  q->done( makeError( GPG_ERR_CANCELED ) );
188 }
189 
190 #include "moc_selectcertificatecommand.cpp"
Kleo::AssuanCommandMixin< SelectCertificateCommand >::name
const char * name() const
Definition: assuancommand.h:369
selectcertificatecommand.h
option
CertificateSelectionDialog::Option option
Definition: uiserver/selectcertificatecommand.cpp:115
Kleo::AssuanCommandMixin
Definition: assuancommand.h:367
Kleo::SelectCertificateCommand::~SelectCertificateCommand
~SelectCertificateCommand()
Definition: uiserver/selectcertificatecommand.cpp:111
Kleo::Dialogs::CertificateSelectionDialog::Option
Option
Definition: certificateselectiondialog.h:60
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Dialogs::CertificateSelectionDialog
Definition: certificateselectiondialog.h:56
certificateselectiondialog.h
option_prefix
static const char option_prefix[]
Definition: uiserver/selectcertificatecommand.cpp:67
Kleo::SelectCertificateCommand::SelectCertificateCommand
SelectCertificateCommand()
Definition: uiserver/selectcertificatecommand.cpp:108
Kleo::SelectCertificateCommand
Definition: uiserver/selectcertificatecommand.h:41
option_table
static const struct @4 option_table[]
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:189
name
const char * name
Definition: uiserver/selectcertificatecommand.cpp:114
keycache.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal