• 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
changeownertrustcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/changeexpirycommand.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 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 "changeownertrustcommand.h"
36 
37 #include "command_p.h"
38 
39 #include <dialogs/ownertrustdialog.h>
40 
41 #include <utils/formatting.h>
42 
43 #include <kleo/cryptobackendfactory.h>
44 #include <kleo/cryptobackend.h>
45 #include <kleo/changeownertrustjob.h>
46 
47 #include <gpgme++/key.h>
48 
49 #include <KLocalizedString>
50 #include <kdebug.h>
51 
52 
53 #include <cassert>
54 
55 using namespace Kleo;
56 using namespace Kleo::Commands;
57 using namespace Kleo::Dialogs;
58 using namespace GpgME;
59 
60 class ChangeOwnerTrustCommand::Private : public Command::Private {
61  friend class ::Kleo::Commands::ChangeOwnerTrustCommand;
62  ChangeOwnerTrustCommand * q_func() const { return static_cast<ChangeOwnerTrustCommand*>( q ); }
63 public:
64  explicit Private( ChangeOwnerTrustCommand * qq, KeyListController * c );
65  ~Private();
66 
67  void init();
68 
69 private:
70  void slotDialogAccepted();
71  void slotDialogRejected();
72  void slotResult( const Error & err );
73 
74 private:
75  void ensureDialogCreated();
76  void createJob();
77  void showErrorDialog( const Error & error );
78  void showSuccessDialog();
79 
80 private:
81  QPointer<OwnerTrustDialog> dialog;
82  QPointer<ChangeOwnerTrustJob> job;
83 };
84 
85 
86 ChangeOwnerTrustCommand::Private * ChangeOwnerTrustCommand::d_func() { return static_cast<Private*>( d.get() ); }
87 const ChangeOwnerTrustCommand::Private * ChangeOwnerTrustCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
88 
89 #define d d_func()
90 #define q q_func()
91 
92 ChangeOwnerTrustCommand::Private::Private( ChangeOwnerTrustCommand * qq, KeyListController * c )
93  : Command::Private( qq, c ),
94  dialog(),
95  job()
96 {
97 
98 }
99 
100 ChangeOwnerTrustCommand::Private::~Private() { kDebug(); }
101 
102 ChangeOwnerTrustCommand::ChangeOwnerTrustCommand( KeyListController * c )
103  : Command( new Private( this, c ) )
104 {
105  d->init();
106 }
107 
108 ChangeOwnerTrustCommand::ChangeOwnerTrustCommand( QAbstractItemView * v, KeyListController * c )
109  : Command( v, new Private( this, c ) )
110 {
111  d->init();
112 }
113 
114 ChangeOwnerTrustCommand::ChangeOwnerTrustCommand( const Key & key )
115  : Command( key, new Private( this, 0 ) )
116 {
117  d->init();
118 }
119 
120 void ChangeOwnerTrustCommand::Private::init() {
121 
122 }
123 
124 ChangeOwnerTrustCommand::~ChangeOwnerTrustCommand() { kDebug(); }
125 
126 void ChangeOwnerTrustCommand::doStart() {
127 
128  if ( d->keys().size() != 1 ) {
129  d->finished();
130  return;
131  }
132 
133  const Key key = d->key();
134  if ( key.protocol() != GpgME::OpenPGP || ( key.hasSecret() && key.ownerTrust() == Key::Ultimate ) ) {
135  d->finished();
136  return;
137  }
138 
139  d->ensureDialogCreated();
140  assert( d->dialog );
141 
142  d->dialog->setHasSecretKey( key.hasSecret() );
143  d->dialog->setFormattedCertificateName( Formatting::formatForComboBox( key ) );
144  d->dialog->setOwnerTrust( key.ownerTrust() );
145 
146  d->dialog->show();
147 
148 }
149 
150 void ChangeOwnerTrustCommand::Private::slotDialogAccepted() {
151  assert( dialog );
152 
153  const Key::OwnerTrust trust = dialog->ownerTrust();
154 
155  kDebug() << "trust " << trust;
156 
157  createJob();
158  assert( job );
159 
160  if ( const Error err = job->start( key(), trust ) ) {
161  showErrorDialog( err );
162  finished();
163  }
164 }
165 
166 void ChangeOwnerTrustCommand::Private::slotDialogRejected() {
167  emit q->canceled();
168  finished();
169 }
170 
171 void ChangeOwnerTrustCommand::Private::slotResult( const Error & err ) {
172  if ( err.isCanceled() )
173  ;
174  else if ( err )
175  showErrorDialog( err );
176  else
177  showSuccessDialog();
178  finished();
179 }
180 
181 void ChangeOwnerTrustCommand::doCancel() {
182  kDebug();
183  if ( d->job )
184  d->job->slotCancel();
185 }
186 
187 void ChangeOwnerTrustCommand::Private::ensureDialogCreated() {
188  if ( dialog )
189  return;
190 
191  dialog = new OwnerTrustDialog;
192  applyWindowID( dialog );
193  dialog->setAttribute( Qt::WA_DeleteOnClose );
194 
195  connect( dialog, SIGNAL(accepted()), q, SLOT(slotDialogAccepted()) );
196  connect( dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()) );
197 }
198 
199 void ChangeOwnerTrustCommand::Private::createJob() {
200  assert( !job );
201 
202  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key().protocol() );
203  if ( !backend )
204  return;
205 
206  ChangeOwnerTrustJob * const j = backend->changeOwnerTrustJob();
207  if ( !j )
208  return;
209 
210  connect( j, SIGNAL(progress(QString,int,int)),
211  q, SIGNAL(progress(QString,int,int)) );
212  connect( j, SIGNAL(result(GpgME::Error)),
213  q, SLOT(slotResult(GpgME::Error)) );
214 
215  job = j;
216 }
217 
218 void ChangeOwnerTrustCommand::Private::showErrorDialog( const Error & err ) {
219  error( i18n("<p>An error occurred while trying to change "
220  "the owner trust for <b>%1</b>:</p><p>%2</p>",
221  Formatting::formatForComboBox( key() ),
222  QString::fromLocal8Bit( err.asString() ) ),
223  i18n("Owner Trust Change Error") );
224 }
225 
226 void ChangeOwnerTrustCommand::Private::showSuccessDialog() {
227  information( i18n("Owner trust changed successfully."),
228  i18n("Owner Trust Change Succeeded") );
229 }
230 
231 #undef d
232 #undef q
233 
234 #include "moc_changeownertrustcommand.cpp"
QAbstractItemView
q
#define q
Definition: changeownertrustcommand.cpp:90
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::KeyListController
Definition: keylistcontroller.h:55
QPointer< OwnerTrustDialog >
formatting.h
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
Kleo::Formatting::formatForComboBox
QString formatForComboBox(const GpgME::Key &key)
Definition: formatting.cpp:497
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
Kleo::Dialogs::OwnerTrustDialog
Definition: ownertrustdialog.h:45
Kleo::Class::OpenPGP
Definition: classify.h:49
changeownertrustcommand.h
QString
Kleo::Commands::ChangeOwnerTrustCommand::~ChangeOwnerTrustCommand
~ChangeOwnerTrustCommand()
Definition: changeownertrustcommand.cpp:124
command_p.h
Kleo::Commands::ChangeOwnerTrustCommand
Definition: changeownertrustcommand.h:41
Kleo::Commands::ChangeOwnerTrustCommand::ChangeOwnerTrustCommand
ChangeOwnerTrustCommand(QAbstractItemView *view, KeyListController *parent)
Definition: changeownertrustcommand.cpp:108
d
#define d
Definition: changeownertrustcommand.cpp:89
Kleo::Formatting::OwnerTrust
Definition: formatting.h:79
Kleo::Command
Definition: commands/command.h:58
ownertrustdialog.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