• 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
adduseridcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/adduseridcommand.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 "adduseridcommand.h"
36 
37 #include "command_p.h"
38 
39 #include <dialogs/adduseriddialog.h>
40 
41 #include <utils/formatting.h>
42 
43 #include <kleo/cryptobackendfactory.h>
44 #include <kleo/cryptobackend.h>
45 #include <kleo/adduseridjob.h>
46 
47 #include <gpgme++/key.h>
48 
49 #include <KLocale>
50 #include <KMessageBox>
51 #include <kdebug.h>
52 
53 #include <cassert>
54 
55 using namespace Kleo;
56 using namespace Kleo::Commands;
57 using namespace Kleo::Dialogs;
58 using namespace GpgME;
59 
60 class AddUserIDCommand::Private : public Command::Private {
61  friend class ::Kleo::Commands::AddUserIDCommand;
62  AddUserIDCommand * q_func() const { return static_cast<AddUserIDCommand*>( q ); }
63 public:
64  explicit Private( AddUserIDCommand * qq, KeyListController * c );
65  ~Private();
66 
67  void init();
68 
69 private:
70  void slotDialogAccepted();
71  void slotDialogRejected();
72  void slotResult( const Error & err );
73 
74 private:
75  void ensureDialogCreated();
76  void createJob();
77  void showErrorDialog( const Error & error );
78  void showSuccessDialog();
79 
80 private:
81  GpgME::Key key;
82  QPointer<AddUserIDDialog> dialog;
83  QPointer<AddUserIDJob> job;
84 };
85 
86 
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() ); }
89 
90 #define d d_func()
91 #define q q_func()
92 
93 AddUserIDCommand::Private::Private( AddUserIDCommand * qq, KeyListController * c )
94  : Command::Private( qq, c ),
95  key(),
96  dialog(),
97  job()
98 {
99 
100 }
101 
102 AddUserIDCommand::Private::~Private() { kDebug(); }
103 
104 AddUserIDCommand::AddUserIDCommand( KeyListController * c )
105  : Command( new Private( this, c ) )
106 {
107  d->init();
108 }
109 
110 AddUserIDCommand::AddUserIDCommand( QAbstractItemView * v, KeyListController * c )
111  : Command( v, new Private( this, c ) )
112 {
113  d->init();
114 }
115 
116 AddUserIDCommand::AddUserIDCommand( const GpgME::Key & key )
117  : Command( key, new Private( this, 0 ) )
118 {
119  d->init();
120 }
121 
122 void AddUserIDCommand::Private::init() {
123 
124 }
125 
126 AddUserIDCommand::~AddUserIDCommand() { kDebug(); }
127 
128 void AddUserIDCommand::doStart() {
129 
130  const std::vector<Key> keys = d->keys();
131  if ( keys.size() != 1 ||
132  keys.front().protocol() != GpgME::OpenPGP ||
133  !keys.front().hasSecret() ) {
134  d->finished();
135  return;
136  }
137 
138  d->key = keys.front();
139 
140  d->ensureDialogCreated();
141  assert( d->dialog );
142 
143  const UserID uid = d->key.userID(0);
144 
145  d->dialog->setName( QString::fromUtf8( uid.name() ) );
146  d->dialog->setEmail( Formatting::prettyEMail( uid.email(), uid.id() ) );
147  d->dialog->setComment( QString::fromUtf8( uid.comment() ) );
148 
149  d->dialog->show();
150 }
151 
152 void AddUserIDCommand::Private::slotDialogAccepted() {
153  assert( dialog );
154 
155  createJob();
156  if ( !job )
157  finished();
158 
159  else if ( const Error err = job->start( key, dialog->name(), dialog->email(), dialog->comment() ) ) {
160  showErrorDialog( err );
161  finished();
162  }
163 }
164 
165 void AddUserIDCommand::Private::slotDialogRejected() {
166  emit q->canceled();
167  finished();
168 }
169 
170 void AddUserIDCommand::Private::slotResult( const Error & err ) {
171  if ( err.isCanceled() )
172  ;
173  else if ( err )
174  showErrorDialog( err );
175  else
176  showSuccessDialog();
177  finished();
178 }
179 
180 void AddUserIDCommand::doCancel() {
181  kDebug();
182  if ( d->job )
183  d->job->slotCancel();
184 }
185 
186 void AddUserIDCommand::Private::ensureDialogCreated() {
187  if ( dialog )
188  return;
189 
190  dialog = new AddUserIDDialog;
191  applyWindowID( dialog );
192  dialog->setAttribute( Qt::WA_DeleteOnClose );
193 
194  connect( dialog, SIGNAL(accepted()), q, SLOT(slotDialogAccepted()) );
195  connect( dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()) );
196 }
197 
198 void AddUserIDCommand::Private::createJob() {
199  assert( !job );
200 
201  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key.protocol() );
202  if ( !backend )
203  return;
204 
205  AddUserIDJob * const j = backend->addUserIDJob();
206  if ( !j )
207  return;
208 
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)) );
213 
214  job = j;
215 }
216 
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") );
223 }
224 
225 void AddUserIDCommand::Private::showSuccessDialog() {
226  information( i18nc("@info", "User-ID successfully added."),
227  i18nc("@title:window", "Add User-ID Succeeded") );
228 }
229 
230 #undef d
231 #undef q
232 
233 #include "moc_adduseridcommand.cpp"
adduseridcommand.h
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
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Commands::AddUserIDCommand::~AddUserIDCommand
~AddUserIDCommand()
Definition: adduseridcommand.cpp:126
Kleo::Commands::AddUserIDCommand
Definition: adduseridcommand.h:41
Kleo::Commands::AddUserIDCommand::AddUserIDCommand
AddUserIDCommand(QAbstractItemView *view, KeyListController *parent)
Definition: adduseridcommand.cpp:110
Kleo::Class::OpenPGP
Definition: classify.h:49
Kleo::Formatting::prettyEMail
QString prettyEMail(const char *email, const char *id)
Definition: formatting.cpp:184
command_p.h
Kleo::Dialogs::AddUserIDDialog
Definition: adduseriddialog.h:45
q
#define q
Definition: adduseridcommand.cpp:91
adduseriddialog.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