• 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
  • libkleopatraclient
  • gui
certificaterequester.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  gui/certificaterequester.h
3 
4  This file is part of KleopatraClient, the Kleopatra interface library
5  Copyright (c) 2008 Klarälvdalens Datakonsult AB
6 
7  KleopatraClient is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Library 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  KleopatraClient 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  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library 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 
22 #include "certificaterequester.h"
23 
24 #include <libkleopatraclient/core/selectcertificatecommand.h>
25 
26 #include <QPointer>
27 #include <QPushButton>
28 #include <QLabel>
29 #include <QLineEdit>
30 #include <QLayout>
31 #include <QMessageBox>
32 
33 #include <memory>
34 
35 using namespace KLEOPATRACLIENT_NAMESPACE;
36 using namespace KLEOPATRACLIENT_NAMESPACE::Gui;
37 
38 class CertificateRequester::Private {
39  friend class ::KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester;
40  CertificateRequester * const q;
41 public:
42  explicit Private( CertificateRequester * qq )
43  : q( qq ),
44  selectedCertificates(),
45  command(),
46  multipleCertificatesAllowed( false ),
47  onlySigningCertificatesAllowed( false ),
48  onlyEncryptionCertificatesAllowed( false ),
49  onlyOpenPGPCertificatesAllowed( false ),
50  onlyX509CertificatesAllowed( false ),
51  onlySecretKeysAllowed( false ),
52  ui( q )
53  {
54 
55  }
56 
57 private:
58  void updateLineEdit() {
59  ui.lineEdit.setText( selectedCertificates.join( QLatin1String( " " ) ) );
60  }
61  void createCommand() {
62  std::auto_ptr<SelectCertificateCommand> cmd( new SelectCertificateCommand );
63 
64  cmd->setMultipleCertificatesAllowed( multipleCertificatesAllowed );
65  cmd->setOnlySigningCertificatesAllowed( onlySigningCertificatesAllowed );
66  cmd->setOnlyEncryptionCertificatesAllowed( onlyEncryptionCertificatesAllowed );
67  cmd->setOnlyOpenPGPCertificatesAllowed( onlyOpenPGPCertificatesAllowed );
68  cmd->setOnlyX509CertificatesAllowed( onlyX509CertificatesAllowed );
69  cmd->setOnlySecretKeysAllowed( onlySecretKeysAllowed );
70 
71  cmd->setSelectedCertificates( selectedCertificates );
72 
73  if ( const QWidget * const window = q->window() )
74  cmd->setParentWId( window->effectiveWinId() );
75 
76  connect( cmd.get(), SIGNAL(finished()), q, SLOT(slotCommandFinished()) );
77 
78  command = cmd.release();
79  }
80 
81  void slotButtonClicked();
82  void slotCommandFinished();
83 
84 private:
85  QStringList selectedCertificates;
86 
87  QPointer<SelectCertificateCommand> command;
88 
89  bool multipleCertificatesAllowed : 1;
90  bool onlySigningCertificatesAllowed : 1;
91  bool onlyEncryptionCertificatesAllowed : 1;
92  bool onlyOpenPGPCertificatesAllowed : 1;
93  bool onlyX509CertificatesAllowed : 1;
94  bool onlySecretKeysAllowed : 1;
95 
96  struct Ui {
97  QLineEdit lineEdit;
98  QPushButton button;
99  QHBoxLayout hlay;
100 
101  explicit Ui( CertificateRequester * qq )
102  : lineEdit( qq ),
103  button( tr("Change..."), qq ),
104  hlay( qq )
105  {
106  lineEdit.setObjectName( QLatin1String( "lineEdit" ) );
107  button.setObjectName( QLatin1String( "button" ) );
108  hlay.setObjectName( QLatin1String( "hlay" ) );
109 
110  hlay.addWidget( &lineEdit, 1 );
111  hlay.addWidget( &button );
112 
113  lineEdit.setReadOnly( true );
114 
115  connect( &button, SIGNAL(clicked()),
116  qq, SLOT(slotButtonClicked()) );
117  }
118 
119  } ui;
120 };
121 
122 CertificateRequester::CertificateRequester( QWidget * p, Qt::WindowFlags f )
123  : QWidget( p, f ), d( new Private( this ) )
124 {
125 
126 }
127 
128 CertificateRequester::~CertificateRequester() {
129  delete d; d = 0;
130 }
131 
132 
133 
134 void CertificateRequester::setMultipleCertificatesAllowed( bool allow ) {
135  if ( allow == d->multipleCertificatesAllowed )
136  return;
137  d->multipleCertificatesAllowed = allow;
138 }
139 
140 bool CertificateRequester::multipleCertificatesAllowed() const {
141  return d->multipleCertificatesAllowed;
142 }
143 
144 
145 void CertificateRequester::setOnlySigningCertificatesAllowed( bool allow ) {
146  if ( allow == d->onlySigningCertificatesAllowed )
147  return;
148  d->onlySigningCertificatesAllowed = allow;
149 }
150 
151 bool CertificateRequester::onlySigningCertificatesAllowed() const {
152  return d->onlySigningCertificatesAllowed;
153 }
154 
155 
156 void CertificateRequester::setOnlyEncryptionCertificatesAllowed( bool allow ) {
157  if ( allow == d->onlyEncryptionCertificatesAllowed )
158  return;
159  d->onlyEncryptionCertificatesAllowed = allow;
160 }
161 
162 bool CertificateRequester::onlyEncryptionCertificatesAllowed() const {
163  return d->onlyEncryptionCertificatesAllowed;
164 }
165 
166 
167 void CertificateRequester::setOnlyOpenPGPCertificatesAllowed( bool allow ) {
168  if ( allow == d->onlyOpenPGPCertificatesAllowed )
169  return;
170  d->onlyOpenPGPCertificatesAllowed = allow;
171 }
172 
173 bool CertificateRequester::onlyOpenPGPCertificatesAllowed() const {
174  return d->onlyOpenPGPCertificatesAllowed;
175 }
176 
177 
178 void CertificateRequester::setOnlyX509CertificatesAllowed( bool allow ) {
179  if ( allow == d->onlyX509CertificatesAllowed )
180  return;
181  d->onlyX509CertificatesAllowed = allow;
182 }
183 
184 bool CertificateRequester::onlyX509CertificatesAllowed() const {
185  return d->onlyX509CertificatesAllowed;
186 }
187 
188 
189 void CertificateRequester::setOnlySecretKeysAllowed( bool allow ) {
190  if ( allow == d->onlySecretKeysAllowed )
191  return;
192  d->onlySecretKeysAllowed = allow;
193 }
194 
195 bool CertificateRequester::onlySecretKeysAllowed() const {
196  return d->onlySecretKeysAllowed;
197 }
198 
199 
200 void CertificateRequester::setSelectedCertificates( const QStringList & certs ) {
201  if ( certs == d->selectedCertificates )
202  return;
203  d->selectedCertificates = certs;
204  d->updateLineEdit();
205  /*emit*/ selectedCertificatesChanged( certs );
206 }
207 
208 QStringList CertificateRequester::selectedCertificates() const {
209  return d->selectedCertificates;
210 }
211 
212 
213 void CertificateRequester::setSelectedCertificate( const QString & cert ) {
214  setSelectedCertificates( QStringList( cert ) );
215 }
216 
217 QString CertificateRequester::selectedCertificate() const {
218  return d->selectedCertificates.empty() ? QString() : d->selectedCertificates.front() ;
219 }
220 
221 void CertificateRequester::Private::slotButtonClicked() {
222  if ( command )
223  return;
224  createCommand();
225  command->start();
226  ui.button.setEnabled( false );
227 }
228 
229 void CertificateRequester::Private::slotCommandFinished() {
230  if ( command->wasCanceled() )
231  /* do nothing */;
232  else if ( command->error() )
233  QMessageBox::information( q,
234  tr("Kleopatra Error"),
235  tr("There was an error while connecting to Kleopatra: %1" )
236  .arg( command->errorString() ) );
237  else
238  q->setSelectedCertificates( command->selectedCertificates() );
239  ui.button.setEnabled( true );
240  delete command;
241 }
242 
243 #include "moc_certificaterequester.cpp"
QWidget
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::onlyEncryptionCertificatesAllowed
bool onlyEncryptionCertificatesAllowed() const
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::multipleCertificatesAllowed
bool multipleCertificatesAllowed() const
d
#define d
Definition: adduseridcommand.cpp:90
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setOnlyX509CertificatesAllowed
void setOnlyX509CertificatesAllowed(bool allow)
Definition: certificaterequester.cpp:178
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setOnlyOpenPGPCertificatesAllowed
void setOnlyOpenPGPCertificatesAllowed(bool allow)
Definition: certificaterequester.cpp:167
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setSelectedCertificates
void setSelectedCertificates(const QStringList &certs)
Definition: certificaterequester.cpp:200
KLEOPATRACLIENT_NAMESPACE::SelectCertificateCommand
Definition: libkleopatraclient/core/selectcertificatecommand.h:29
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::onlySigningCertificatesAllowed
bool onlySigningCertificatesAllowed() const
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::selectedCertificatesChanged
void selectedCertificatesChanged(const QStringList &certs)
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::~CertificateRequester
~CertificateRequester()
Definition: certificaterequester.cpp:128
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::selectedCertificates
QStringList selectedCertificates() const
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setOnlyEncryptionCertificatesAllowed
void setOnlyEncryptionCertificatesAllowed(bool allow)
Definition: certificaterequester.cpp:156
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester
Definition: certificaterequester.h:32
selectcertificatecommand.h
q
#define q
Definition: adduseridcommand.cpp:91
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::onlyOpenPGPCertificatesAllowed
bool onlyOpenPGPCertificatesAllowed() const
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setOnlySecretKeysAllowed
void setOnlySecretKeysAllowed(bool allow)
Definition: certificaterequester.cpp:189
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::onlyX509CertificatesAllowed
bool onlyX509CertificatesAllowed() const
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::selectedCertificate
QString selectedCertificate() const
Definition: certificaterequester.cpp:217
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setMultipleCertificatesAllowed
void setMultipleCertificatesAllowed(bool allow)
Definition: certificaterequester.cpp:134
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setSelectedCertificate
void setSelectedCertificate(const QString &cert)
Definition: certificaterequester.cpp:213
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::onlySecretKeysAllowed
bool onlySecretKeysAllowed() const
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::setOnlySigningCertificatesAllowed
void setOnlySigningCertificatesAllowed(bool allow)
Definition: certificaterequester.cpp:145
KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester::CertificateRequester
CertificateRequester(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: certificaterequester.cpp:122
certificaterequester.h
KLEOPATRACLIENT_NAMESPACE
#define KLEOPATRACLIENT_NAMESPACE
Definition: kleopatraclient_export.h:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:40 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