33 #include <config-kleopatra.h>
43 #include <kleo/cryptobackendfactory.h>
44 #include <kleo/cryptobackend.h>
45 #include <kleo/changeexpiryjob.h>
47 #include <gpgme++/key.h>
50 #include <KMessageBox>
58 using namespace Kleo::Commands;
59 using namespace Kleo::Dialogs;
60 using namespace GpgME;
63 friend class ::Kleo::Commands::ChangeExpiryCommand;
72 void slotDialogAccepted();
73 void slotDialogRejected();
74 void slotResult(
const Error & err );
77 void ensureDialogCreated();
79 void showErrorDialog(
const Error & error );
80 void showSuccessDialog();
84 QPointer<ExpiryDialog> dialog;
85 QPointer<ChangeExpiryJob> job;
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() ); }
104 ChangeExpiryCommand::Private::~Private() { kDebug(); }
107 :
Command( new Private( this, c ) )
113 :
Command( v, new Private( this, c ) )
119 :
Command( key, new Private( this, 0 ) )
124 void ChangeExpiryCommand::Private::init() {
130 void ChangeExpiryCommand::doStart() {
132 const std::vector<Key> keys =
d->keys();
133 if ( keys.size() != 1 ||
135 !keys.front().hasSecret() ||
136 keys.front().subkey(0).isNull() ) {
141 d->key = keys.front();
143 d->ensureDialogCreated();
145 const Subkey subkey =
d->key.subkey(0);
146 d->dialog->setDateOfExpiry( subkey.neverExpires() ? QDate() : QDateTime::fromTime_t(
d->key.subkey(0).expirationTime() ).date() );
151 void ChangeExpiryCommand::Private::slotDialogAccepted() {
154 static const QTime END_OF_DAY( 23, 59, 59 );
156 const QDateTime expiry( dialog->dateOfExpiry(), END_OF_DAY );
158 kDebug() <<
"expiry" << expiry;
163 if (
const Error err = job->start( key, expiry ) ) {
164 showErrorDialog( err );
169 void ChangeExpiryCommand::Private::slotDialogRejected() {
174 void ChangeExpiryCommand::Private::slotResult(
const Error & err ) {
175 if ( err.isCanceled() )
178 showErrorDialog( err );
184 void ChangeExpiryCommand::doCancel() {
187 d->job->slotCancel();
190 void ChangeExpiryCommand::Private::ensureDialogCreated() {
195 applyWindowID( dialog );
196 dialog->setAttribute( Qt::WA_DeleteOnClose );
198 connect( dialog, SIGNAL(accepted()),
q, SLOT(slotDialogAccepted()) );
199 connect( dialog, SIGNAL(rejected()),
q, SLOT(slotDialogRejected()) );
202 void ChangeExpiryCommand::Private::createJob() {
205 const CryptoBackend::Protocol *
const backend = CryptoBackendFactory::instance()->protocol( key.protocol() );
209 ChangeExpiryJob *
const j = backend->changeExpiryJob();
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)) );
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>",
225 QString::fromLocal8Bit( err.asString() ) ),
226 i18n(
"Expiry Date Change Error") );
229 void ChangeExpiryCommand::Private::showSuccessDialog() {
230 information( i18n(
"Expiry date changed successfully."),
231 i18n(
"Expiry Date Change Succeeded") );
237 #include "moc_changeexpirycommand.cpp"
kdtools::pimpl_ptr< Private > d
ChangeExpiryCommand(QAbstractItemView *view, KeyListController *parent)