• 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
  • uiserver
prepencryptcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  uiserver/prepencryptcommand.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 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 "prepencryptcommand.h"
36 
37 #include <crypto/newsignencryptemailcontroller.h>
38 
39 #include <kleo/exception.h>
40 
41 #include <KLocale>
42 
43 #include <QPointer>
44 
45 using namespace Kleo;
46 using namespace Kleo::Crypto;
47 using namespace boost;
48 
49 class PrepEncryptCommand::Private : public QObject {
50  Q_OBJECT
51 private:
52  friend class ::Kleo::PrepEncryptCommand;
53  PrepEncryptCommand * const q;
54 public:
55  explicit Private( PrepEncryptCommand * qq )
56  : q( qq ), controller() {}
57 
58 private:
59  void checkForErrors() const;
60 
61 public Q_SLOTS:
62  void slotRecipientsResolved();
63  void slotError( int, const QString & );
64 
65 private:
66  shared_ptr<NewSignEncryptEMailController> controller;
67 };
68 
69 PrepEncryptCommand::PrepEncryptCommand()
70  : AssuanCommandMixin<PrepEncryptCommand>(), d( new Private( this ) )
71 {
72 
73 }
74 
75 PrepEncryptCommand::~PrepEncryptCommand() {}
76 
77 void PrepEncryptCommand::Private::checkForErrors() const {
78 
79  if ( !q->inputs().empty() || !q->outputs().empty() || !q->messages().empty() )
80  throw Exception( makeError( GPG_ERR_CONFLICT ),
81  i18n( "INPUT/OUTPUT/MESSAGE may only be given after PREP_ENCRYPT" ) );
82 
83  if ( q->numFiles() )
84  throw Exception( makeError( GPG_ERR_CONFLICT ),
85  i18n( "PREP_ENCRYPT is an email mode command, connection seems to be in filemanager mode" ) );
86 
87  if ( !q->senders().empty() && !q->informativeSenders() )
88  throw Exception( makeError( GPG_ERR_CONFLICT ),
89  i18n( "SENDER may not be given prior to PREP_ENCRYPT, except with --info" ) );
90 
91  if ( q->recipients().empty() || q->informativeRecipients() )
92  throw Exception( makeError( GPG_ERR_MISSING_VALUE ),
93  i18n( "No recipients given, or only with --info" ) );
94 
95 }
96 
97 int PrepEncryptCommand::doStart() {
98 
99  removeMemento( NewSignEncryptEMailController::mementoName() );
100 
101  d->checkForErrors();
102 
103  d->controller.reset( new NewSignEncryptEMailController( shared_from_this() ) );
104  d->controller->setEncrypting( true );
105 
106  const QString session = sessionTitle();
107  if ( !session.isEmpty() )
108  d->controller->setSubject( session );
109 
110  if ( hasOption( "protocol" ) )
111  // --protocol is optional for PREP_ENCRYPT
112  d->controller->setProtocol( checkProtocol( EMail ) );
113 
114  d->controller->setSigning( hasOption( "expect-sign" ) );
115 
116  QObject::connect( d->controller.get(), SIGNAL(certificatesResolved()), d.get(), SLOT(slotRecipientsResolved()) );
117  QObject::connect( d->controller.get(), SIGNAL(error(int,QString)), d.get(), SLOT(slotError(int,QString)) );
118 
119  d->controller->startResolveCertificates( recipients(), senders() );
120 
121  return 0;
122 }
123 
124 void PrepEncryptCommand::Private::slotRecipientsResolved() {
125  //hold local shared_ptr to member as q->done() deletes *this
126  const shared_ptr<NewSignEncryptEMailController> cont = controller;
127  QPointer<Private> that( this );
128 
129  try {
130 
131  q->sendStatus( "PROTOCOL", QLatin1String(controller->protocolAsString()) );
132  q->registerMemento( NewSignEncryptEMailController::mementoName(),
133  make_typed_memento( controller ) );
134  q->done();
135  return;
136 
137  } catch ( const Exception & e ) {
138  q->done( e.error(), e.message() );
139  } catch ( const std::exception & e ) {
140  q->done( makeError( GPG_ERR_UNEXPECTED ),
141  i18n("Caught unexpected exception in PrepEncryptCommand::Private::slotRecipientsResolved: %1",
142  QString::fromLocal8Bit( e.what() ) ) );
143  } catch ( ... ) {
144  q->done( makeError( GPG_ERR_UNEXPECTED ),
145  i18n("Caught unknown exception in PrepEncryptCommand::Private::slotRecipientsResolved") );
146  }
147  if ( that ) // isn't this always deleted here and thus unnecessary?
148  q->removeMemento( NewSignEncryptEMailController::mementoName() );
149  cont->cancel();
150 }
151 
152 void PrepEncryptCommand::Private::slotError( int err, const QString & details ) {
153  q->done( err, details );
154 }
155 
156 void PrepEncryptCommand::doCanceled() {
157  if ( d->controller )
158  d->controller->cancel();
159 }
160 
161 #include "prepencryptcommand.moc"
Kleo::PrepEncryptCommand::~PrepEncryptCommand
virtual ~PrepEncryptCommand()
Definition: prepencryptcommand.cpp:75
Kleo::AssuanCommandMixin
Definition: assuancommand.h:367
Kleo::PrepEncryptCommand
Definition: prepencryptcommand.h:42
boost::shared_ptr< NewSignEncryptEMailController >
d
#define d
Definition: adduseridcommand.cpp:90
newsignencryptemailcontroller.h
Kleo::PrepEncryptCommand::PrepEncryptCommand
PrepEncryptCommand()
Definition: prepencryptcommand.cpp:69
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
prepencryptcommand.h
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::Crypto::NewSignEncryptEMailController
Definition: newsignencryptemailcontroller.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 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