• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kleopatra

adduseridcommand.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset:4 -*-
00002     commands/adduseridcommand.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2008 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include <config-kleopatra.h>
00034 
00035 #include "adduseridcommand.h"
00036 
00037 #include "command_p.h"
00038 
00039 #include <dialogs/adduseriddialog.h>
00040 
00041 #include <utils/formatting.h>
00042 
00043 #include <kleo/cryptobackendfactory.h>
00044 #include <kleo/cryptobackend.h>
00045 #include <kleo/adduseridjob.h>
00046 
00047 #include <gpgme++/key.h>
00048 
00049 #include <KLocale>
00050 #include <KMessageBox>
00051 #include <kdebug.h>
00052 
00053 #include <cassert>
00054 
00055 using namespace Kleo;
00056 using namespace Kleo::Commands;
00057 using namespace Kleo::Dialogs;
00058 using namespace GpgME;
00059 
00060 class AddUserIDCommand::Private : public Command::Private {
00061     friend class ::Kleo::Commands::AddUserIDCommand;
00062     AddUserIDCommand * q_func() const { return static_cast<AddUserIDCommand*>( q ); }
00063 public:
00064     explicit Private( AddUserIDCommand * qq, KeyListController * c );
00065     ~Private();
00066 
00067     void init();
00068 
00069 private:
00070     void slotDialogAccepted();
00071     void slotDialogRejected();
00072     void slotResult( const Error & err );
00073 
00074 private:
00075     void ensureDialogCreated();
00076     void createJob();
00077     void showErrorDialog( const Error & error );
00078     void showSuccessDialog();
00079 
00080 private:
00081     GpgME::Key key;
00082     QPointer<AddUserIDDialog> dialog;
00083     QPointer<AddUserIDJob> job;
00084 };
00085 
00086 
00087 AddUserIDCommand::Private * AddUserIDCommand::d_func() { return static_cast<Private*>( d.get() ); }
00088 const AddUserIDCommand::Private * AddUserIDCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
00089 
00090 #define d d_func()
00091 #define q q_func()
00092 
00093 AddUserIDCommand::Private::Private( AddUserIDCommand * qq, KeyListController * c )
00094     : Command::Private( qq, c ),
00095       key(),
00096       dialog(),
00097       job()
00098 {
00099 
00100 }
00101 
00102 AddUserIDCommand::Private::~Private() { kDebug(); }
00103 
00104 AddUserIDCommand::AddUserIDCommand( KeyListController * c )
00105     : Command( new Private( this, c ) )
00106 {
00107     d->init();
00108 }
00109 
00110 AddUserIDCommand::AddUserIDCommand( QAbstractItemView * v, KeyListController * c )
00111     : Command( v, new Private( this, c ) )
00112 {
00113     d->init();
00114 }
00115 
00116 AddUserIDCommand::AddUserIDCommand( const GpgME::Key & key )
00117     : Command( key, new Private( this, 0 ) )
00118 {
00119     d->init();
00120 }
00121 
00122 void AddUserIDCommand::Private::init() {
00123 
00124 }
00125 
00126 AddUserIDCommand::~AddUserIDCommand() { kDebug(); }
00127 
00128 void AddUserIDCommand::doStart() {
00129 
00130     const std::vector<Key> keys = d->keys();
00131     if ( keys.size() != 1 ||
00132          keys.front().protocol() != GpgME::OpenPGP ||
00133          !keys.front().hasSecret() ) {
00134         d->finished();
00135         return;
00136     }
00137 
00138     d->key = keys.front();
00139 
00140     d->ensureDialogCreated();
00141     assert( d->dialog );
00142     d->dialog->show();
00143 }
00144 
00145 void AddUserIDCommand::Private::slotDialogAccepted() {
00146     assert( dialog );
00147 
00148     createJob();
00149     if ( !job )
00150         finished();
00151 
00152     else if ( const Error err = job->start( key, dialog->name(), dialog->email(), dialog->comment() ) ) {
00153         showErrorDialog( err );
00154         finished();
00155     }
00156 }
00157 
00158 void AddUserIDCommand::Private::slotDialogRejected() {
00159     emit q->canceled();
00160     finished();
00161 }
00162 
00163 void AddUserIDCommand::Private::slotResult( const Error & err ) {
00164     if ( err.isCanceled() )
00165         ;
00166     else if ( err )
00167         showErrorDialog( err );
00168     else
00169         showSuccessDialog();
00170     finished();
00171 }
00172 
00173 void AddUserIDCommand::doCancel() {
00174     kDebug();
00175     if ( d->job )
00176         d->job->slotCancel();
00177 }
00178 
00179 void AddUserIDCommand::Private::ensureDialogCreated() {
00180     if ( dialog )
00181         return;
00182 
00183     dialog = new AddUserIDDialog( parentWidgetOrView() );
00184     dialog->setAttribute( Qt::WA_DeleteOnClose );
00185 
00186     connect( dialog, SIGNAL(accepted()), q, SLOT(slotDialogAccepted()) );
00187     connect( dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()) );
00188 }
00189 
00190 void AddUserIDCommand::Private::createJob() {
00191     assert( !job );
00192 
00193     const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key.protocol() );
00194     if ( !backend )
00195         return;
00196 
00197     AddUserIDJob * const j = backend->addUserIDJob();
00198     if ( !j )
00199         return;
00200 
00201     connect( j, SIGNAL(progress(QString,int,int)),
00202              q, SIGNAL(progress(QString,int,int)) );
00203     connect( j, SIGNAL(result(GpgME::Error)),
00204              q, SLOT(slotResult(GpgME::Error)) );
00205 
00206     job = j;
00207 }
00208 
00209 void AddUserIDCommand::Private::showErrorDialog( const Error & err ) {
00210     KMessageBox::error( parentWidgetOrView(),
00211                         i18nc("@info",
00212                              "<para>An error occurred while trying to add the user-id: "
00213                               "<message>%1</message></para>",
00214                              QString::fromLocal8Bit( err.asString() ) ),
00215                         i18n("Add User-ID Error") );
00216 }
00217 
00218 void AddUserIDCommand::Private::showSuccessDialog() {
00219     KMessageBox::information( parentWidgetOrView(),
00220                               i18n("User-ID successfully added."),
00221                               i18n("Add User-ID Succeeded") );
00222 }
00223 
00224 #undef d
00225 #undef q
00226 
00227 #include "moc_adduseridcommand.cpp"

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal