• 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
  • crypto
  • gui
signingcertificateselectionwidget.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/gui/signingcertificateselectionwidget.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007, 2009 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 "signingcertificateselectionwidget.h"
36 
37 #include "ui_signingcertificateselectionwidget.h"
38 
39 #include <models/keycache.h>
40 
41 #include <utils/formatting.h>
42 
43 #include <kleo/stl_util.h>
44 
45 #include <KLocalizedString>
46 #include <QByteArray>
47 #include <QMap>
48 
49 #include <boost/bind.hpp>
50 
51 #include <cassert>
52 
53 using namespace Kleo;
54 using namespace Kleo::Crypto::Gui;
55 
56 class SigningCertificateSelectionWidget::Private {
57  friend class ::SigningCertificateSelectionWidget;
58  SigningCertificateSelectionWidget * const q;
59 public:
60  explicit Private( SigningCertificateSelectionWidget * qq );
61  ~Private();
62  static std::vector<GpgME::Key> candidates( GpgME::Protocol prot );
63  static void addCandidates( GpgME::Protocol prot, QComboBox* combo );
64 
65 private:
66  Ui::SigningCertificateSelectionWidget ui;
67 };
68 
69 
70 static GpgME::Key current_cert( const QComboBox & cb ) {
71  const QByteArray fpr = cb.itemData( cb.currentIndex() ).toByteArray();
72  return KeyCache::instance()->findByFingerprint( fpr.constData() );
73 }
74 
75 static void select_cert( QComboBox & cb, const GpgME::Key & key ) {
76  const QByteArray fpr = key.primaryFingerprint();
77  if ( !fpr.isEmpty() )
78  cb.setCurrentIndex( cb.findData( fpr ) );
79 }
80 
81 static void add_cert( QComboBox & cb, const GpgME::Key & key ) {
82  cb.addItem( Formatting::formatForComboBox( key ),
83  QVariant( QByteArray( key.primaryFingerprint() ) ) );
84 
85 }
86 
87 SigningCertificateSelectionWidget::Private::Private( SigningCertificateSelectionWidget * qq )
88  : q( qq ), ui()
89 {
90  ui.setupUi( q );
91  addCandidates( GpgME::CMS, ui.cmsCombo );
92  addCandidates( GpgME::OpenPGP, ui.pgpCombo );
93  ui.rememberCO->setChecked( true );
94 }
95 
96 SigningCertificateSelectionWidget::Private::~Private() {}
97 
98 
99 
100 SigningCertificateSelectionWidget::SigningCertificateSelectionWidget( QWidget * parent, Qt::WindowFlags f )
101  : QWidget( parent, f ), d( new Private( this ) )
102 {
103 
104 }
105 
106 SigningCertificateSelectionWidget::~SigningCertificateSelectionWidget() {}
107 
108 
109 void SigningCertificateSelectionWidget::setSelectedCertificates( const QMap<GpgME::Protocol, GpgME::Key>& certificates )
110 {
111  setSelectedCertificates( certificates[GpgME::OpenPGP], certificates[GpgME::CMS] );
112 }
113 
114 void SigningCertificateSelectionWidget::setSelectedCertificates( const GpgME::Key & pgp, const GpgME::Key & cms ) {
115  select_cert( *d->ui.pgpCombo, pgp );
116  select_cert( *d->ui.cmsCombo, cms );
117 }
118 
119 std::vector<GpgME::Key> SigningCertificateSelectionWidget::Private::candidates( GpgME::Protocol prot )
120 {
121  assert( prot != GpgME::UnknownProtocol );
122  std::vector<GpgME::Key> keys = KeyCache::instance()->keys();
123  std::vector<GpgME::Key>::iterator end = keys.end();
124 
125  end = std::remove_if( keys.begin(), end, boost::bind( &GpgME::Key::protocol, _1 ) != prot );
126  end = std::remove_if( keys.begin(), end, !boost::bind( &GpgME::Key::hasSecret, _1 ) );
127  assert( kdtools::all( keys.begin(), end, boost::bind( &GpgME::Key::hasSecret, _1 ) ) );
128  end = std::remove_if( keys.begin(), end, !boost::bind( &GpgME::Key::canReallySign, _1 ) );
129  end = std::remove_if( keys.begin(), end, boost::bind( &GpgME::Key::isExpired, _1 ) );
130  end = std::remove_if( keys.begin(), end, boost::bind( &GpgME::Key::isRevoked, _1 ) );
131  keys.erase( end, keys.end() );
132  return keys;
133 }
134 
135 void SigningCertificateSelectionWidget::Private::addCandidates( GpgME::Protocol prot, QComboBox* combo )
136 {
137  const std::vector<GpgME::Key> keys = candidates( prot );
138  Q_FOREACH( const GpgME::Key& i, keys )
139  add_cert( *combo, i );
140 }
141 
142 
143 QMap<GpgME::Protocol, GpgME::Key> SigningCertificateSelectionWidget::selectedCertificates() const
144 {
145  QMap<GpgME::Protocol, GpgME::Key> res;
146 
147  res.insert( GpgME::OpenPGP, current_cert( *d->ui.pgpCombo ) );
148  res.insert( GpgME::CMS, current_cert( *d->ui.cmsCombo ) );
149 
150  return res;
151 }
152 
153 bool SigningCertificateSelectionWidget::rememberAsDefault() const
154 {
155  return d->ui.rememberCO->isChecked();
156 }
157 
158 void SigningCertificateSelectionWidget::setAllowedProtocols( const QVector<GpgME::Protocol>& allowedProtocols )
159 {
160  setAllowedProtocols( allowedProtocols.contains( GpgME::OpenPGP ),
161  allowedProtocols.contains( GpgME::CMS ) );
162 }
163 
164 void SigningCertificateSelectionWidget::setAllowedProtocols( bool pgp, bool cms )
165 {
166  d->ui.pgpLabel->setVisible( pgp );
167  d->ui.pgpCombo->setVisible( pgp );
168 
169  d->ui.cmsLabel->setVisible( cms );
170  d->ui.cmsCombo->setVisible( cms );
171 }
172 
173 #include "moc_signingcertificateselectionwidget.cpp"
select_cert
static void select_cert(QComboBox &cb, const GpgME::Key &key)
Definition: signingcertificateselectionwidget.cpp:75
QWidget
formatting.h
Kleo::Crypto::Gui::SigningCertificateSelectionWidget::setSelectedCertificates
void setSelectedCertificates(const QMap< GpgME::Protocol, GpgME::Key > &certificates)
Definition: signingcertificateselectionwidget.cpp:109
Kleo::Formatting::formatForComboBox
QString formatForComboBox(const GpgME::Key &key)
Definition: formatting.cpp:497
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Crypto::Gui::SigningCertificateSelectionWidget::rememberAsDefault
bool rememberAsDefault() const
Definition: signingcertificateselectionwidget.cpp:153
Kleo::Class::OpenPGP
Definition: classify.h:49
Kleo::Class::CMS
Definition: classify.h:48
Kleo::Crypto::Gui::SigningCertificateSelectionWidget
Definition: signingcertificateselectionwidget.h:51
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:189
signingcertificateselectionwidget.h
Kleo::Crypto::Gui::SigningCertificateSelectionWidget::setAllowedProtocols
void setAllowedProtocols(const QVector< GpgME::Protocol > &allowedProtocols)
Definition: signingcertificateselectionwidget.cpp:158
add_cert
static void add_cert(QComboBox &cb, const GpgME::Key &key)
Definition: signingcertificateselectionwidget.cpp:81
keycache.h
QMap< GpgME::Protocol, GpgME::Key >
Kleo::Crypto::Gui::SigningCertificateSelectionWidget::~SigningCertificateSelectionWidget
~SigningCertificateSelectionWidget()
Definition: signingcertificateselectionwidget.cpp:106
current_cert
static GpgME::Key current_cert(const QComboBox &cb)
Definition: signingcertificateselectionwidget.cpp:70
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