• 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
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 <KLocalizedString>
50 #include <kdebug.h>
51 
52 #include <QDateTime>
53 
54 #include <cassert>
55 
56 using namespace Kleo;
57 using namespace Kleo::Commands;
58 using namespace Kleo::Dialogs;
59 using namespace GpgME;
60 
61 class ChangeExpiryCommand::Private : public Command::Private {
62  friend class ::Kleo::Commands::ChangeExpiryCommand;
63  ChangeExpiryCommand * q_func() const { return static_cast<ChangeExpiryCommand*>( q ); }
64 public:
65  explicit Private( ChangeExpiryCommand * qq, KeyListController * c );
66  ~Private();
67 
68  void init();
69 
70 private:
71  void slotDialogAccepted();
72  void slotDialogRejected();
73  void slotResult( const Error & err );
74 
75 private:
76  void ensureDialogCreated();
77  void createJob();
78  void showErrorDialog( const Error & error );
79  void showSuccessDialog();
80 
81 private:
82  GpgME::Key key;
83  QPointer<ExpiryDialog> dialog;
84  QPointer<ChangeExpiryJob> job;
85 };
86 
87 
88 ChangeExpiryCommand::Private * ChangeExpiryCommand::d_func() { return static_cast<Private*>( d.get() ); }
89 const ChangeExpiryCommand::Private * ChangeExpiryCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
90 
91 #define d d_func()
92 #define q q_func()
93 
94 ChangeExpiryCommand::Private::Private( ChangeExpiryCommand * qq, KeyListController * c )
95  : Command::Private( qq, c ),
96  key(),
97  dialog(),
98  job()
99 {
100 
101 }
102 
103 ChangeExpiryCommand::Private::~Private() { kDebug(); }
104 
105 ChangeExpiryCommand::ChangeExpiryCommand( KeyListController * c )
106  : Command( new Private( this, c ) )
107 {
108  d->init();
109 }
110 
111 ChangeExpiryCommand::ChangeExpiryCommand( QAbstractItemView * v, KeyListController * c )
112  : Command( v, new Private( this, c ) )
113 {
114  d->init();
115 }
116 
117 ChangeExpiryCommand::ChangeExpiryCommand( const GpgME::Key & key )
118  : Command( key, new Private( this, 0 ) )
119 {
120  d->init();
121 }
122 
123 void ChangeExpiryCommand::Private::init() {
124 
125 }
126 
127 ChangeExpiryCommand::~ChangeExpiryCommand() { kDebug(); }
128 
129 void ChangeExpiryCommand::doStart() {
130 
131  const std::vector<Key> keys = d->keys();
132  if ( keys.size() != 1 ||
133  keys.front().protocol() != GpgME::OpenPGP ||
134  !keys.front().hasSecret() ||
135  keys.front().subkey(0).isNull() ) {
136  d->finished();
137  return;
138  }
139 
140  d->key = keys.front();
141 
142  d->ensureDialogCreated();
143  assert( d->dialog );
144  const Subkey subkey = d->key.subkey(0);
145  d->dialog->setDateOfExpiry( subkey.neverExpires() ? QDate() : QDateTime::fromTime_t( d->key.subkey(0).expirationTime() ).date() );
146  d->dialog->show();
147 
148 }
149 
150 void ChangeExpiryCommand::Private::slotDialogAccepted() {
151  assert( dialog );
152 
153  static const QTime END_OF_DAY( 23, 59, 59 ); // not used, so as good as any
154 
155  const QDateTime expiry( dialog->dateOfExpiry(), END_OF_DAY );
156 
157  kDebug() << "expiry" << expiry;
158 
159  createJob();
160  assert( job );
161 
162  if ( const Error err = job->start( key, expiry ) ) {
163  showErrorDialog( err );
164  finished();
165  }
166 }
167 
168 void ChangeExpiryCommand::Private::slotDialogRejected() {
169  emit q->canceled();
170  finished();
171 }
172 
173 void ChangeExpiryCommand::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 ChangeExpiryCommand::doCancel() {
184  kDebug();
185  if ( d->job )
186  d->job->slotCancel();
187 }
188 
189 void ChangeExpiryCommand::Private::ensureDialogCreated() {
190  if ( dialog )
191  return;
192 
193  dialog = new ExpiryDialog;
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 ChangeExpiryCommand::Private::createJob() {
202  assert( !job );
203 
204  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key.protocol() );
205  if ( !backend )
206  return;
207 
208  ChangeExpiryJob * const j = backend->changeExpiryJob();
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 ChangeExpiryCommand::Private::showErrorDialog( const Error & err ) {
221  error( i18n("<p>An error occurred while trying to change "
222  "the expiry date for <b>%1</b>:</p><p>%2</p>",
223  Formatting::formatForComboBox( key ),
224  QString::fromLocal8Bit( err.asString() ) ),
225  i18n("Expiry Date Change Error") );
226 }
227 
228 void ChangeExpiryCommand::Private::showSuccessDialog() {
229  information( i18n("Expiry date changed successfully."),
230  i18n("Expiry Date Change Succeeded") );
231 }
232 
233 #undef d
234 #undef q
235 
236 #include "moc_changeexpirycommand.cpp"
QAbstractItemView
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::KeyListController
Definition: keylistcontroller.h:55
QPointer< ExpiryDialog >
formatting.h
QTime
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::Commands::ChangeExpiryCommand::ChangeExpiryCommand
ChangeExpiryCommand(QAbstractItemView *view, KeyListController *parent)
Definition: changeexpirycommand.cpp:111
Kleo::Class::OpenPGP
Definition: classify.h:49
QDate
QString
command_p.h
d
#define d
Definition: changeexpirycommand.cpp:91
Kleo::Commands::ChangeExpiryCommand::~ChangeExpiryCommand
~ChangeExpiryCommand()
Definition: changeexpirycommand.cpp:127
expirydialog.h
q
#define q
Definition: changeexpirycommand.cpp:92
Kleo::Dialogs::ExpiryDialog
Definition: expirydialog.h:45
Kleo::Commands::ChangeExpiryCommand
Definition: changeexpirycommand.h:41
changeexpirycommand.h
Kleo::Command
Definition: commands/command.h:58
QDateTime
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