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