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