• 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
  • dialogs
setinitialpindialog.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  dialogs/setinitialpindialog.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 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 "setinitialpindialog.h"
36 
37 #include "ui_setinitialpindialog.h"
38 
39 #include <KIconLoader>
40 #include <KLocalizedString>
41 
42 #include <QTextDocument> // for Qt::escape
43 
44 #include <gpgme++/error.h>
45 
46 #ifndef Q_MOC_RUN
47 #include <boost/static_assert.hpp>
48 #endif
49 
50 #include <cassert>
51 
52 using namespace Kleo;
53 using namespace Kleo::Dialogs;
54 using namespace GpgME;
55 
56 enum State {
57  Unknown = 0,
58  NotSet,
59  AlreadySet,
60  Ongoing,
61  Ok,
62  Failed,
63  NumStates
64 };
65 
66 const char * icons[] = {
67  // PENDING(marc) use better icons, once available
68  "", // Unknown
69  "", // NotSet
70  "security-medium", // AlreadySet
71  "movie-process-working-kde", // Ongoing
72  "security-high", // Ok
73  "security-low", // Failed
74 };
75 
76 BOOST_STATIC_ASSERT(( sizeof icons / sizeof (*icons) == NumStates ));
77 BOOST_STATIC_ASSERT(( sizeof("movie-") == 7 ));
78 
79 static void update_widget( State state, bool delay, QLabel * resultLB, QLabel * lb, QPushButton * pb, QLabel * statusLB ) {
80  assert( state >= 0 ); assert( state < NumStates );
81  const char * icon = icons[state];
82  if ( qstrncmp( icon, "movie-", sizeof("movie-")-1 ) == 0 )
83  resultLB->setMovie( KIconLoader::global()->loadMovie( QLatin1String(icon+sizeof("movie-")), KIconLoader::NoGroup ) );
84  else if ( icon && *icon )
85  resultLB->setPixmap( KIcon( QLatin1String(icon) ).pixmap( 32 ) );
86  else
87  resultLB->setPixmap( QPixmap() );
88  lb->setEnabled( ( state == NotSet || state == Failed ) && !delay );
89  pb->setEnabled( ( state == NotSet || state == Failed ) && !delay );
90  if ( state == AlreadySet )
91  statusLB->setText( i18nc("@info","No NullPin found. <warning>If this PIN was not set by you personally, the card might have been tampered with.</warning>") );
92 }
93 
94 static QString format_error( const Error & err ) {
95  if ( err.isCanceled() )
96  return i18nc("@info","Canceled setting PIN.");
97  if ( err )
98  return i18nc("@info",
99  "There was an error setting the PIN: <message>%1</message>.",
100  Qt::escape( QString::fromLocal8Bit( err.asString() ) ) );
101  else
102  return i18nc("@info","PIN set successfully.");
103 }
104 
105 class SetInitialPinDialog::Private {
106  friend class ::Kleo::Dialogs::SetInitialPinDialog;
107  SetInitialPinDialog * const q;
108 public:
109  explicit Private( SetInitialPinDialog * qq )
110  : q( qq ),
111  nksState( Unknown ),
112  sigGState( Unknown ),
113  ui( q )
114  {
115 
116  }
117 
118 private:
119  void slotNksButtonClicked() {
120  nksState = Ongoing;
121  ui.nksStatusLB->clear();
122  updateWidgets();
123  emit q->nksPinRequested();
124  }
125 
126  void slotSigGButtonClicked() {
127  sigGState = Ongoing;
128  ui.sigGStatusLB->clear();
129  updateWidgets();
130  emit q->sigGPinRequested();
131  }
132 
133 private:
134  void updateWidgets() {
135  update_widget( nksState, false,
136  ui.nksResultIcon, ui.nksLB, ui.nksPB, ui.nksStatusLB );
137  update_widget( sigGState, nksState == NotSet || nksState == Failed || nksState == Ongoing,
138  ui.sigGResultIcon, ui.sigGLB, ui.sigGPB, ui.sigGStatusLB );
139  ui.closePB()->setEnabled( q->isComplete() );
140  ui.cancelPB()->setEnabled( !q->isComplete() );
141  }
142 
143 private:
144  State nksState, sigGState;
145 
146  struct UI : public Ui::SetInitialPinDialog {
147  explicit UI( Dialogs::SetInitialPinDialog * qq )
148  : Ui::SetInitialPinDialog()
149  {
150  setupUi( qq );
151 
152  closePB()->setEnabled( false );
153 
154  connect( closePB(), SIGNAL(clicked()), qq, SLOT(accept()) );
155  }
156 
157  QAbstractButton * closePB() const {
158  assert( dialogButtonBox );
159  return dialogButtonBox->button( QDialogButtonBox::Close );
160  }
161 
162  QAbstractButton * cancelPB() const {
163  assert( dialogButtonBox );
164  return dialogButtonBox->button( QDialogButtonBox::Cancel );
165  }
166 
167  } ui;
168 };
169 
170 SetInitialPinDialog::SetInitialPinDialog( QWidget * p, Qt::WindowFlags f )
171  : QDialog( p, f ), d( new Private( this ) )
172 {
173 
174 }
175 
176 SetInitialPinDialog::~SetInitialPinDialog() {}
177 
178 void SetInitialPinDialog::setNksPinPresent( bool on ) {
179  d->nksState = on ? AlreadySet : NotSet ;
180  d->updateWidgets();
181 }
182 
183 void SetInitialPinDialog::setSigGPinPresent( bool on ) {
184  d->sigGState = on ? AlreadySet : NotSet ;
185  d->updateWidgets();
186 }
187 
188 void SetInitialPinDialog::setNksPinSettingResult( const Error & err ) {
189  d->ui.nksStatusLB->setText( format_error( err ) );
190  d->nksState =
191  err.isCanceled() ? NotSet :
192  err ? Failed :
193  Ok ;
194  d->updateWidgets();
195 }
196 
197 void SetInitialPinDialog::setSigGPinSettingResult( const Error & err ) {
198  d->ui.sigGStatusLB->setText( format_error( err ) );
199  d->sigGState =
200  err.isCanceled() ? NotSet :
201  err ? Failed :
202  Ok ;
203  d->updateWidgets();
204 }
205 
206 bool SetInitialPinDialog::isComplete() const {
207  return ( d->nksState == Ok || d->nksState == AlreadySet )
208  && ( d->sigGState == Ok || d->sigGState == AlreadySet );
209 }
210 
211 #include "moc_setinitialpindialog.cpp"
Failed
Definition: setinitialpindialog.cpp:62
QWidget
Unknown
Definition: setinitialpindialog.cpp:57
QLabel::setPixmap
void setPixmap(const QPixmap &)
Kleo::Dialogs::SetInitialPinDialog::setSigGPinSettingResult
void setSigGPinSettingResult(const GpgME::Error &error)
Definition: setinitialpindialog.cpp:197
AlreadySet
Definition: setinitialpindialog.cpp:59
State
State
Definition: setinitialpindialog.cpp:56
Kleo::Dialogs::SetInitialPinDialog::setNksPinPresent
void setNksPinPresent(bool)
Definition: setinitialpindialog.cpp:178
QWidget::setEnabled
void setEnabled(bool)
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
d
#define d
Definition: adduseridcommand.cpp:89
QLabel::setMovie
void setMovie(QMovie *movie)
icons
const char * icons[]
Definition: setinitialpindialog.cpp:66
QLabel::setText
void setText(const QString &)
QString
QPixmap
Kleo::Dialogs::SetInitialPinDialog::~SetInitialPinDialog
~SetInitialPinDialog()
Definition: setinitialpindialog.cpp:176
Kleo::Dialogs::SetInitialPinDialog::setSigGPinPresent
void setSigGPinPresent(bool)
Definition: setinitialpindialog.cpp:183
Kleo::Dialogs::SetInitialPinDialog
Definition: setinitialpindialog.h:47
QAbstractButton
format_error
static QString format_error(const Error &err)
Definition: setinitialpindialog.cpp:94
QLatin1String
BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((sizeof icons/sizeof(*icons)==NumStates))
Qt::escape
QString escape(const QString &plain)
Ok
Definition: setinitialpindialog.cpp:61
NotSet
Definition: setinitialpindialog.cpp:58
Kleo::Dialogs::SetInitialPinDialog::SetInitialPinDialog
SetInitialPinDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: setinitialpindialog.cpp:170
q
#define q
Definition: adduseridcommand.cpp:90
QDialog
QPushButton
Qt::WindowFlags
typedef WindowFlags
Ongoing
Definition: setinitialpindialog.cpp:60
Kleo::Dialogs::SetInitialPinDialog::setNksPinSettingResult
void setNksPinSettingResult(const GpgME::Error &error)
Definition: setinitialpindialog.cpp:188
setinitialpindialog.h
QLabel
NumStates
Definition: setinitialpindialog.cpp:63
update_widget
static void update_widget(State state, bool delay, QLabel *resultLB, QLabel *lb, QPushButton *pb, QLabel *statusLB)
Definition: setinitialpindialog.cpp:79
Kleo::Dialogs::SetInitialPinDialog::isComplete
bool isComplete() const
Definition: setinitialpindialog.cpp:206
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