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