• 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
commands/signencryptfilescommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/signencryptfilescommand.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 "signencryptfilescommand.h"
36 
37 #include "command_p.h"
38 
39 #include <crypto/signencryptfilescontroller.h>
40 
41 #include <utils/filedialog.h>
42 
43 #include <kleo/stl_util.h>
44 
45 #include <KLocalizedString>
46 #include <kdebug.h>
47 
48 #include <QStringList>
49 
50 #include <exception>
51 
52 using namespace Kleo;
53 using namespace Kleo::Commands;
54 using namespace Kleo::Crypto;
55 using namespace boost;
56 
57 class SignEncryptFilesCommand::Private : public Command::Private {
58  friend class ::Kleo::Commands::SignEncryptFilesCommand;
59  SignEncryptFilesCommand * q_func() const { return static_cast<SignEncryptFilesCommand*>( q ); }
60 public:
61  explicit Private( SignEncryptFilesCommand * qq, KeyListController * c );
62  ~Private();
63 
64  QStringList selectFiles() const;
65 
66  void init();
67 
68 private:
69  void slotControllerDone() {
70  finished();
71  }
72  void slotControllerError( int, const QString & ) {
73  finished();
74  }
75 
76 private:
77  QStringList files;
78  shared_ptr<const ExecutionContext> shared_qq;
79  SignEncryptFilesController controller;
80 };
81 
82 
83 SignEncryptFilesCommand::Private * SignEncryptFilesCommand::d_func() { return static_cast<Private*>( d.get() ); }
84 const SignEncryptFilesCommand::Private * SignEncryptFilesCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
85 
86 #define d d_func()
87 #define q q_func()
88 
89 SignEncryptFilesCommand::Private::Private( SignEncryptFilesCommand * qq, KeyListController * c )
90  : Command::Private( qq, c ),
91  files(),
92  shared_qq( qq, kdtools::nodelete() ),
93  controller()
94 {
95  controller.setOperationMode( SignEncryptFilesController::SignAllowed | SignEncryptFilesController::EncryptAllowed | SignEncryptFilesController::ArchiveAllowed );
96 }
97 
98 SignEncryptFilesCommand::Private::~Private() { kDebug(); }
99 
100 SignEncryptFilesCommand::SignEncryptFilesCommand( KeyListController * c )
101  : Command( new Private( this, c ) )
102 {
103  d->init();
104 }
105 
106 SignEncryptFilesCommand::SignEncryptFilesCommand( QAbstractItemView * v, KeyListController * c )
107  : Command( v, new Private( this, c ) )
108 {
109  d->init();
110 }
111 
112 SignEncryptFilesCommand::SignEncryptFilesCommand( const QStringList & files, KeyListController * c )
113  : Command( new Private( this, c ) )
114 {
115  d->init();
116  d->files = files;
117 }
118 
119 SignEncryptFilesCommand::SignEncryptFilesCommand( const QStringList & files, QAbstractItemView * v, KeyListController * c )
120  : Command( v, new Private( this, c ) )
121 {
122  d->init();
123  d->files = files;
124 }
125 
126 void SignEncryptFilesCommand::Private::init() {
127  controller.setExecutionContext( shared_qq );
128  connect( &controller, SIGNAL(done()), q, SLOT(slotControllerDone()) );
129  connect( &controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString)) );
130 }
131 
132 SignEncryptFilesCommand::~SignEncryptFilesCommand() { kDebug(); }
133 
134 void SignEncryptFilesCommand::setFiles( const QStringList & files ) {
135  d->files = files;
136 }
137 
138 void SignEncryptFilesCommand::setSigningPolicy( Policy policy ) {
139  unsigned int mode = d->controller.operationMode();
140  mode &= ~SignEncryptFilesController::SignMask;
141  switch ( policy ) {
142  case NoPolicy:
143  case Allow:
144  mode |= SignEncryptFilesController::SignAllowed ;
145  break;
146  case Deny:
147  mode |= SignEncryptFilesController::SignDisallowed ;
148  break;
149  case Force:
150  mode |= SignEncryptFilesController::SignForced ;
151  break;
152  }
153  try {
154  d->controller.setOperationMode( mode );
155  } catch ( ... ) {}
156 }
157 
158 Policy SignEncryptFilesCommand::signingPolicy() const {
159  const unsigned int mode = d->controller.operationMode();
160  switch ( mode & SignEncryptFilesController::SignMask ) {
161  default:
162  assert( !"This should not happen!" );
163  return NoPolicy;
164  case SignEncryptFilesController::SignAllowed:
165  return Allow;
166  case SignEncryptFilesController::SignForced:
167  return Force;
168  case SignEncryptFilesController::SignDisallowed:
169  return Deny;
170  }
171 }
172 
173 void SignEncryptFilesCommand::setEncryptionPolicy( Policy policy ) {
174  unsigned int mode = d->controller.operationMode();
175  mode &= ~SignEncryptFilesController::EncryptMask;
176  switch ( policy ) {
177  case NoPolicy:
178  case Allow:
179  mode |= SignEncryptFilesController::EncryptAllowed ;
180  break;
181  case Deny:
182  mode |= SignEncryptFilesController::EncryptDisallowed ;
183  break;
184  case Force:
185  mode |= SignEncryptFilesController::EncryptForced ;
186  break;
187  }
188  try {
189  d->controller.setOperationMode( mode );
190  } catch ( ... ) {}
191 }
192 
193 Policy SignEncryptFilesCommand::encryptionPolicy() const {
194  const unsigned int mode = d->controller.operationMode();
195  switch ( mode & SignEncryptFilesController::EncryptMask ) {
196  default:
197  assert( !"This should not happen!" );
198  return NoPolicy;
199  case SignEncryptFilesController::EncryptAllowed:
200  return Allow;
201  case SignEncryptFilesController::EncryptForced:
202  return Force;
203  case SignEncryptFilesController::EncryptDisallowed:
204  return Deny;
205  }
206 }
207 
208 void SignEncryptFilesCommand::setProtocol( GpgME::Protocol proto ) {
209  d->controller.setProtocol( proto );
210 }
211 
212 GpgME::Protocol SignEncryptFilesCommand::protocol() const {
213  return d->controller.protocol();
214 }
215 
216 void SignEncryptFilesCommand::doStart() {
217 
218  try {
219 
220  if ( d->files.empty() )
221  d->files = d->selectFiles();
222  if ( d->files.empty() ) {
223  d->finished();
224  return;
225  }
226 
227  d->controller.setFiles( d->files );
228  d->controller.start();
229 
230  } catch ( const std::exception & e ) {
231  d->information( i18n("An error occurred: %1",
232  QString::fromLocal8Bit( e.what() ) ),
233  i18n("Sign/Encrypt Files Error") );
234  d->finished();
235  }
236 }
237 
238 void SignEncryptFilesCommand::doCancel() {
239  kDebug();
240  d->controller.cancel();
241 }
242 
243 QStringList SignEncryptFilesCommand::Private::selectFiles() const {
244  return FileDialog::getOpenFileNames( parentWidgetOrView(), i18n( "Select One or More Files to Sign and/or Encrypt" ), QLatin1String("enc") );
245 }
246 
247 #undef d
248 #undef q
249 
250 #include "moc_signencryptfilescommand.cpp"
d
#define d
Definition: commands/signencryptfilescommand.cpp:86
Kleo::Force
Definition: types.h:61
QAbstractItemView
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::Deny
Definition: types.h:62
Kleo::KeyListController
Definition: keylistcontroller.h:55
Kleo::Policy
Policy
Definition: types.h:58
Kleo::Allow
Definition: types.h:60
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
Kleo::Command::Private::q
Command *const q
Definition: commands/command_p.h:55
boost::shared_ptr
Definition: encryptemailcontroller.h:51
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
Kleo::Commands::SignEncryptFilesCommand::SignEncryptFilesCommand
SignEncryptFilesCommand(QAbstractItemView *view, KeyListController *parent)
Definition: commands/signencryptfilescommand.cpp:106
signencryptfilescontroller.h
Kleo::FileDialog::getOpenFileNames
QStringList getOpenFileNames(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:116
QString
QStringList
command_p.h
Kleo::Command::Private::controller
KeyListController * controller() const
Definition: commands/command_p.h:63
Kleo::NoPolicy
Definition: types.h:59
signencryptfilescommand.h
QLatin1String
Kleo::Command::Private::finished
void finished()
Definition: commands/command_p.h:72
q
#define q
Definition: commands/signencryptfilescommand.cpp:87
Kleo::Command::Private::information
void information(const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), KMessageBox::Options options=KMessageBox::Notify) const
Definition: commands/command_p.h:89
Kleo::Crypto::SignEncryptFilesController
Definition: signencryptfilescontroller.h:52
Kleo::Commands::SignEncryptFilesCommand
Definition: commands/signencryptfilescommand.h:47
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Kleo::Command::Private::Private
Private(Command *qq, KeyListController *controller)
Definition: commands/command.cpp:48
Kleo::Command
Definition: commands/command.h:58
Kleo::SignEncryptFilesCommand::~SignEncryptFilesCommand
virtual ~SignEncryptFilesCommand()
Definition: uiserver/signencryptfilescommand.cpp:77
Kleo::Command::Private::error
void error(const QString &text, const QString &caption=QString(), KMessageBox::Options options=KMessageBox::Notify) const
Definition: commands/command_p.h:83
filedialog.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 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