Prepare for the removal of sendmail support in mailtransport.
[kdepim.git] / kleopatra / crypto / controller.cpp
blobdedd393c796ec88783e246c606023b4525e79946
1 /* -*- mode: c++; c-basic-offset:4 -*-
2 crypto/controller.cpp
4 This file is part of Kleopatra, the KDE keymanager
5 Copyright (c) 2008 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 "controller.h"
37 using namespace Kleo;
38 using namespace Kleo::Crypto;
39 using namespace boost;
41 class Controller::Private
43 friend class ::Kleo::Crypto::Controller;
44 Controller *const q;
45 public:
46 explicit Private(Controller *qq)
47 : q(qq),
48 lastError(0),
49 lastErrorString()
54 private:
55 int lastError;
56 QString lastErrorString;
59 Controller::Controller(QObject *parent)
60 : QObject(parent), ExecutionContextUser(), d(new Private(this))
65 Controller::Controller(const shared_ptr<const ExecutionContext> &ctx, QObject *parent)
66 : QObject(parent), ExecutionContextUser(ctx), d(new Private(this))
71 Controller::~Controller() {}
73 void Controller::taskDone(const boost::shared_ptr<const Task::Result> &result)
75 if (result->hasError()) {
76 d->lastError = result->errorCode();
77 d->lastErrorString = result->errorString();
79 const Task *task = qobject_cast<const Task *>(sender());
80 assert(task);
81 doTaskDone(task, result);
84 void Controller::doTaskDone(const Task *, const shared_ptr<const Task::Result> &) {}
86 void Controller::connectTask(const shared_ptr<Task> &task)
88 assert(task);
89 connect(task.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
90 this, SLOT(taskDone(boost::shared_ptr<const Kleo::Crypto::Task::Result>)));
93 void Controller::setLastError(int err, const QString &msg)
95 d->lastError = err;
96 d->lastErrorString = msg;
99 void Controller::emitDoneOrError()
101 if (d->lastError != 0) {
102 Q_EMIT error(d->lastError, d->lastErrorString);
103 } else {
104 Q_EMIT done();