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