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