33 #include <config-kleopatra.h>
43 #include <kleo/cryptobackendfactory.h>
44 #include <kleo/cryptobackend.h>
45 #include <kleo/adduseridjob.h>
47 #include <gpgme++/key.h>
50 #include <KMessageBox>
56 using namespace Kleo::Commands;
57 using namespace Kleo::Dialogs;
58 using namespace GpgME;
61 friend class ::Kleo::Commands::AddUserIDCommand;
70 void slotDialogAccepted();
71 void slotDialogRejected();
72 void slotResult(
const Error & err );
75 void ensureDialogCreated();
77 void showErrorDialog(
const Error & error );
78 void showSuccessDialog();
82 QPointer<AddUserIDDialog> dialog;
83 QPointer<AddUserIDJob> job;
87 AddUserIDCommand::Private * AddUserIDCommand::d_func() {
return static_cast<Private*
>(
d.get() ); }
88 const AddUserIDCommand::Private * AddUserIDCommand::d_func()
const {
return static_cast<const Private*
>(
d.get() ); }
102 AddUserIDCommand::Private::~Private() { kDebug(); }
105 :
Command( new Private( this, c ) )
111 :
Command( v, new Private( this, c ) )
117 :
Command( key, new Private( this, 0 ) )
122 void AddUserIDCommand::Private::init() {
128 void AddUserIDCommand::doStart() {
130 const std::vector<Key> keys =
d->keys();
131 if ( keys.size() != 1 ||
133 !keys.front().hasSecret() ) {
138 d->key = keys.front();
140 d->ensureDialogCreated();
143 const UserID uid =
d->key.userID(0);
145 d->dialog->setName( QString::fromUtf8( uid.name() ) );
147 d->dialog->setComment( QString::fromUtf8( uid.comment() ) );
152 void AddUserIDCommand::Private::slotDialogAccepted() {
159 else if (
const Error err = job->start( key, dialog->name(), dialog->email(), dialog->comment() ) ) {
160 showErrorDialog( err );
165 void AddUserIDCommand::Private::slotDialogRejected() {
170 void AddUserIDCommand::Private::slotResult(
const Error & err ) {
171 if ( err.isCanceled() )
174 showErrorDialog( err );
180 void AddUserIDCommand::doCancel() {
183 d->job->slotCancel();
186 void AddUserIDCommand::Private::ensureDialogCreated() {
191 applyWindowID( dialog );
192 dialog->setAttribute( Qt::WA_DeleteOnClose );
194 connect( dialog, SIGNAL(accepted()),
q, SLOT(slotDialogAccepted()) );
195 connect( dialog, SIGNAL(rejected()),
q, SLOT(slotDialogRejected()) );
198 void AddUserIDCommand::Private::createJob() {
201 const CryptoBackend::Protocol *
const backend = CryptoBackendFactory::instance()->protocol( key.protocol() );
205 AddUserIDJob *
const j = backend->addUserIDJob();
209 connect( j, SIGNAL(progress(QString,
int,
int)),
210 q, SIGNAL(progress(QString,
int,
int)) );
211 connect( j, SIGNAL(result(GpgME::Error)),
212 q, SLOT(slotResult(GpgME::Error)) );
217 void AddUserIDCommand::Private::showErrorDialog(
const Error & err ) {
218 error( i18nc(
"@info",
219 "<para>An error occurred while trying to add the user-id: "
220 "<message>%1</message></para>",
221 QString::fromLocal8Bit( err.asString() ) ),
222 i18nc(
"@title:window",
"Add User-ID Error") );
225 void AddUserIDCommand::Private::showSuccessDialog() {
226 information( i18nc(
"@info",
"User-ID successfully added."),
227 i18nc(
"@title:window",
"Add User-ID Succeeded") );
233 #include "moc_adduseridcommand.cpp"
kdtools::pimpl_ptr< Private > d
AddUserIDCommand(QAbstractItemView *view, KeyListController *parent)