• 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
changeexpirycommand.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 "changeexpirycommand.h"
36 
37 #include "command_p.h"
38 
39 #include <dialogs/expirydialog.h>
40 
41 #include <utils/formatting.h>
42 
43 #include <kleo/cryptobackendfactory.h>
44 #include <kleo/cryptobackend.h>
45 #include <kleo/changeexpiryjob.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 ChangeExpiryCommand::Private : public Command::Private {
63  friend class ::Kleo::Commands::ChangeExpiryCommand;
64  ChangeExpiryCommand * q_func() const { return static_cast<ChangeExpiryCommand*>( q ); }
65 public:
66  explicit Private( ChangeExpiryCommand * 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  GpgME::Key key;
84  QPointer<ExpiryDialog> dialog;
85  QPointer<ChangeExpiryJob> job;
86 };
87 
88 
89 ChangeExpiryCommand::Private * ChangeExpiryCommand::d_func() { return static_cast<Private*>( d.get() ); }
90 const ChangeExpiryCommand::Private * ChangeExpiryCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
91 
92 #define d d_func()
93 #define q q_func()
94 
95 ChangeExpiryCommand::Private::Private( ChangeExpiryCommand * qq, KeyListController * c )
96  : Command::Private( qq, c ),
97  key(),
98  dialog(),
99  job()
100 {
101 
102 }
103 
104 ChangeExpiryCommand::Private::~Private() { kDebug(); }
105 
106 ChangeExpiryCommand::ChangeExpiryCommand( KeyListController * c )
107  : Command( new Private( this, c ) )
108 {
109  d->init();
110 }
111 
112 ChangeExpiryCommand::ChangeExpiryCommand( QAbstractItemView * v, KeyListController * c )
113  : Command( v, new Private( this, c ) )
114 {
115  d->init();
116 }
117 
118 ChangeExpiryCommand::ChangeExpiryCommand( const GpgME::Key & key )
119  : Command( key, new Private( this, 0 ) )
120 {
121  d->init();
122 }
123 
124 void ChangeExpiryCommand::Private::init() {
125 
126 }
127 
128 ChangeExpiryCommand::~ChangeExpiryCommand() { kDebug(); }
129 
130 void ChangeExpiryCommand::doStart() {
131 
132  const std::vector<Key> keys = d->keys();
133  if ( keys.size() != 1 ||
134  keys.front().protocol() != GpgME::OpenPGP ||
135  !keys.front().hasSecret() ||
136  keys.front().subkey(0).isNull() ) {
137  d->finished();
138  return;
139  }
140 
141  d->key = keys.front();
142 
143  d->ensureDialogCreated();
144  assert( d->dialog );
145  const Subkey subkey = d->key.subkey(0);
146  d->dialog->setDateOfExpiry( subkey.neverExpires() ? QDate() : QDateTime::fromTime_t( d->key.subkey(0).expirationTime() ).date() );
147  d->dialog->show();
148 
149 }
150 
151 void ChangeExpiryCommand::Private::slotDialogAccepted() {
152  assert( dialog );
153 
154  static const QTime END_OF_DAY( 23, 59, 59 ); // not used, so as good as any
155 
156  const QDateTime expiry( dialog->dateOfExpiry(), END_OF_DAY );
157 
158  kDebug() << "expiry" << expiry;
159 
160  createJob();
161  assert( job );
162 
163  if ( const Error err = job->start( key, expiry ) ) {
164  showErrorDialog( err );
165  finished();
166  }
167 }
168 
169 void ChangeExpiryCommand::Private::slotDialogRejected() {
170  emit q->canceled();
171  finished();
172 }
173 
174 void ChangeExpiryCommand::Private::slotResult( const Error & err ) {
175  if ( err.isCanceled() )
176  ;
177  else if ( err )
178  showErrorDialog( err );
179  else
180  showSuccessDialog();
181  finished();
182 }
183 
184 void ChangeExpiryCommand::doCancel() {
185  kDebug();
186  if ( d->job )
187  d->job->slotCancel();
188 }
189 
190 void ChangeExpiryCommand::Private::ensureDialogCreated() {
191  if ( dialog )
192  return;
193 
194  dialog = new ExpiryDialog;
195  applyWindowID( dialog );
196  dialog->setAttribute( Qt::WA_DeleteOnClose );
197 
198  connect( dialog, SIGNAL(accepted()), q, SLOT(slotDialogAccepted()) );
199  connect( dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()) );
200 }
201 
202 void ChangeExpiryCommand::Private::createJob() {
203  assert( !job );
204 
205  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key.protocol() );
206  if ( !backend )
207  return;
208 
209  ChangeExpiryJob * const j = backend->changeExpiryJob();
210  if ( !j )
211  return;
212 
213  connect( j, SIGNAL(progress(QString,int,int)),
214  q, SIGNAL(progress(QString,int,int)) );
215  connect( j, SIGNAL(result(GpgME::Error)),
216  q, SLOT(slotResult(GpgME::Error)) );
217 
218  job = j;
219 }
220 
221 void ChangeExpiryCommand::Private::showErrorDialog( const Error & err ) {
222  error( i18n("<p>An error occurred while trying to change "
223  "the expiry date for <b>%1</b>:</p><p>%2</p>",
224  Formatting::formatForComboBox( key ),
225  QString::fromLocal8Bit( err.asString() ) ),
226  i18n("Expiry Date Change Error") );
227 }
228 
229 void ChangeExpiryCommand::Private::showSuccessDialog() {
230  information( i18n("Expiry date changed successfully."),
231  i18n("Expiry Date Change Succeeded") );
232 }
233 
234 #undef d
235 #undef q
236 
237 #include "moc_changeexpirycommand.cpp"
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::Commands::ChangeExpiryCommand::ChangeExpiryCommand
ChangeExpiryCommand(QAbstractItemView *view, KeyListController *parent)
Definition: changeexpirycommand.cpp:112
Kleo::Class::OpenPGP
Definition: classify.h:49
command_p.h
d
#define d
Definition: changeexpirycommand.cpp:92
Kleo::Commands::ChangeExpiryCommand::~ChangeExpiryCommand
~ChangeExpiryCommand()
Definition: changeexpirycommand.cpp:128
expirydialog.h
q
#define q
Definition: changeexpirycommand.cpp:93
Kleo::Dialogs::ExpiryDialog
Definition: expirydialog.h:45
Kleo::Commands::ChangeExpiryCommand
Definition: changeexpirycommand.h:41
changeexpirycommand.h
Kleo::Command
Definition: commands/command.h:58
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