• 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
  • commands
changepassphrasecommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/changepassphrasecommand.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2010 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 "changepassphrasecommand.h"
36 
37 #include "command_p.h"
38 
39 #include <utils/formatting.h>
40 
41 #include <kleo/cryptobackendfactory.h>
42 #include <kleo/cryptobackend.h>
43 #include <kleo/changepasswdjob.h>
44 
45 #include <gpgme++/key.h>
46 
47 #include <KLocale>
48 #include <KMessageBox>
49 #include <kdebug.h>
50 
51 #include <gpg-error.h>
52 
53 #include <cassert>
54 
55 using namespace Kleo;
56 using namespace Kleo::Commands;
57 using namespace GpgME;
58 
59 class ChangePassphraseCommand::Private : public Command::Private {
60  friend class ::Kleo::Commands::ChangePassphraseCommand;
61  ChangePassphraseCommand * q_func() const { return static_cast<ChangePassphraseCommand*>( q ); }
62 public:
63  explicit Private( ChangePassphraseCommand * qq, KeyListController * c );
64  ~Private();
65 
66  void init();
67 
68 private:
69  void slotResult( const Error & err );
70 
71 private:
72  void createJob();
73  void startJob();
74  void showErrorDialog( const Error & error );
75  void showSuccessDialog();
76 
77 private:
78  GpgME::Key key;
79  QPointer<ChangePasswdJob> job;
80 };
81 
82 
83 ChangePassphraseCommand::Private * ChangePassphraseCommand::d_func() { return static_cast<Private*>( d.get() ); }
84 const ChangePassphraseCommand::Private * ChangePassphraseCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
85 
86 #define d d_func()
87 #define q q_func()
88 
89 ChangePassphraseCommand::Private::Private( ChangePassphraseCommand * qq, KeyListController * c )
90  : Command::Private( qq, c ),
91  key(),
92  job()
93 {
94 
95 }
96 
97 ChangePassphraseCommand::Private::~Private() { kDebug(); }
98 
99 ChangePassphraseCommand::ChangePassphraseCommand( KeyListController * c )
100  : Command( new Private( this, c ) )
101 {
102  d->init();
103 }
104 
105 ChangePassphraseCommand::ChangePassphraseCommand( QAbstractItemView * v, KeyListController * c )
106  : Command( v, new Private( this, c ) )
107 {
108  d->init();
109 }
110 
111 ChangePassphraseCommand::ChangePassphraseCommand( const GpgME::Key & key )
112  : Command( key, new Private( this, 0 ) )
113 {
114  d->init();
115 }
116 
117 void ChangePassphraseCommand::Private::init() {
118 
119 }
120 
121 ChangePassphraseCommand::~ChangePassphraseCommand() { kDebug(); }
122 
123 void ChangePassphraseCommand::doStart() {
124 
125  const std::vector<Key> keys = d->keys();
126  if ( keys.size() != 1 || !keys.front().hasSecret() ) {
127  d->finished();
128  return;
129  }
130 
131  d->key = keys.front();
132 
133  d->createJob();
134  d->startJob();
135 
136 }
137 
138 void ChangePassphraseCommand::Private::startJob() {
139  const Error err = job
140  ? job->start( key )
141  : Error( gpg_error( GPG_ERR_NOT_SUPPORTED ) )
142  ;
143  if ( err ) {
144  showErrorDialog( err );
145  finished();
146  }
147 }
148 
149 void ChangePassphraseCommand::Private::slotResult( const Error & err ) {
150  if ( err.isCanceled() )
151  ;
152  else if ( err )
153  showErrorDialog( err );
154  else
155  showSuccessDialog();
156  finished();
157 }
158 
159 void ChangePassphraseCommand::doCancel() {
160  kDebug();
161  if ( d->job )
162  d->job->slotCancel();
163 }
164 
165 void ChangePassphraseCommand::Private::createJob() {
166  assert( !job );
167 
168  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key.protocol() );
169  if ( !backend )
170  return;
171 
172  ChangePasswdJob * const j = backend->changePasswdJob();
173  if ( !j )
174  return;
175 
176  connect( j, SIGNAL(progress(QString,int,int)),
177  q, SIGNAL(progress(QString,int,int)) );
178  connect( j, SIGNAL(result(GpgME::Error)),
179  q, SLOT(slotResult(GpgME::Error)) );
180 
181  job = j;
182 }
183 
184 void ChangePassphraseCommand::Private::showErrorDialog( const Error & err ) {
185  error( i18n("<p>An error occurred while trying to change "
186  "the passphrase for <b>%1</b>:</p><p>%2</p>",
187  Formatting::formatForComboBox( key ),
188  QString::fromLocal8Bit( err.asString() ) ),
189  i18n("Passphrase Change Error") );
190 }
191 
192 void ChangePassphraseCommand::Private::showSuccessDialog() {
193  information( i18n("Passphrase changed successfully."),
194  i18n("Passphrase Change Succeeded") );
195 }
196 
197 #undef d
198 #undef q
199 
200 #include "moc_changepassphrasecommand.cpp"
Kleo::Commands::ChangePassphraseCommand::ChangePassphraseCommand
ChangePassphraseCommand(QAbstractItemView *view, KeyListController *parent)
Definition: changepassphrasecommand.cpp:105
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::KeyListController
Definition: keylistcontroller.h:55
formatting.h
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
d
#define d
Definition: changepassphrasecommand.cpp:86
Kleo::Formatting::formatForComboBox
QString formatForComboBox(const GpgME::Key &key)
Definition: formatting.cpp:497
Kleo::Commands::ChangePassphraseCommand::~ChangePassphraseCommand
~ChangePassphraseCommand()
Definition: changepassphrasecommand.cpp:121
command_p.h
Kleo::Commands::ChangePassphraseCommand
Definition: changepassphrasecommand.h:41
q
#define q
Definition: changepassphrasecommand.cpp:87
Kleo::Command
Definition: commands/command.h:58
changepassphrasecommand.h
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