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