Better wording
[kdepim.git] / kleopatra / uiserver / signencryptfilescommand.cpp
blobc47213ace8353c66e33812e3c68241b0a2cce335
1 /* -*- mode: c++; c-basic-offset:4 -*-
2 uiserver/signencryptfilescommand.cpp
4 This file is part of Kleopatra, the KDE keymanager
5 Copyright (c) 2007 Klarälvdalens Datakonsult AB
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.
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.
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
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.
33 #include <config-kleopatra.h>
35 #include "signencryptfilescommand.h"
37 #include <crypto/signencryptfilescontroller.h>
39 #include <kleo/exception.h>
41 #include <KLocale>
43 using namespace Kleo;
44 using namespace Kleo::Crypto;
45 using namespace boost;
47 class SignEncryptFilesCommand::Private : public QObject {
48 Q_OBJECT
49 private:
50 friend class ::Kleo::SignEncryptFilesCommand;
51 SignEncryptFilesCommand * const q;
52 public:
53 explicit Private( SignEncryptFilesCommand * qq )
54 : q( qq ),
55 controller()
60 private:
61 void checkForErrors() const;
63 private Q_SLOTS:
64 void slotDone();
65 void slotError( int, const QString & );
67 private:
68 shared_ptr<SignEncryptFilesController> controller;
71 SignEncryptFilesCommand::SignEncryptFilesCommand()
72 : AssuanCommandMixin<SignEncryptFilesCommand>(), d( new Private( this ) )
77 SignEncryptFilesCommand::~SignEncryptFilesCommand() {}
79 void SignEncryptFilesCommand::Private::checkForErrors() const {
81 if ( !q->numFiles() )
82 throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
83 i18n("At least one FILE must be present") );
86 if ( !q->senders().empty() )
87 throw Exception( makeError( GPG_ERR_CONFLICT ),
88 i18n( "%1 is a filemanager mode command, "
89 "connection seems to be in email mode (%2 present)",
90 QString::fromLatin1( q->name() ), QLatin1String("SENDER") ) );
91 if ( !q->recipients().empty() )
92 throw Exception( makeError( GPG_ERR_CONFLICT ),
93 i18n( "%1 is a filemanager mode command, "
94 "connection seems to be in email mode (%2 present)",
95 QString::fromLatin1( q->name() ), QLatin1String("RECIPIENT") ) );
97 if ( !q->inputs().empty() )
98 throw Exception( makeError( GPG_ERR_CONFLICT ),
99 i18n( "%1 is a filemanager mode command, "
100 "connection seems to be in email mode (%2 present)",
101 QString::fromLatin1( q->name() ), QLatin1String("INPUT") ) );
102 if ( !q->outputs().empty() )
103 throw Exception( makeError( GPG_ERR_CONFLICT ),
104 i18n( "%1 is a filemanager mode command, "
105 "connection seems to be in email mode (%2 present)",
106 QString::fromLatin1( q->name() ), QLatin1String("OUTPUT") ) );
107 if ( !q->messages().empty() )
108 throw Exception( makeError( GPG_ERR_CONFLICT ),
109 i18n( "%1 is a filemanager mode command, "
110 "connection seems to be in email mode (%2 present)",
111 QString::fromLatin1( q->name() ), QLatin1String("MESSAGE") ) );
114 int SignEncryptFilesCommand::doStart() {
116 d->checkForErrors();
118 d->controller.reset( new SignEncryptFilesController( shared_from_this() ) );
120 d->controller->setProtocol( checkProtocol( FileManager ) );
122 unsigned int op = operation();
123 if ( hasOption( "archive" ) )
124 op |= SignEncryptFilesController::ArchiveForced;
125 else
126 op |= SignEncryptFilesController::ArchiveAllowed;
127 d->controller->setOperationMode( op );
128 d->controller->setFiles( fileNames() );
130 QObject::connect( d->controller.get(), SIGNAL(done()), d.get(), SLOT(slotDone()), Qt::QueuedConnection );
131 QObject::connect( d->controller.get(), SIGNAL(error(int,QString)), d.get(), SLOT(slotError(int,QString)), Qt::QueuedConnection );
133 d->controller->start();
135 return 0;
138 void SignEncryptFilesCommand::Private::slotDone() {
139 q->done();
142 void SignEncryptFilesCommand::Private::slotError( int err, const QString & details ) {
143 q->done( err, details );
146 void SignEncryptFilesCommand::doCanceled() {
147 if ( d->controller )
148 d->controller->cancel();
151 #include "signencryptfilescommand.moc"