File indexing completed on 2024-06-16 04:55:59

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     crypto/task_p.h
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <crypto/task.h>
0013 
0014 #include <QString>
0015 #include <QTimer>
0016 
0017 namespace Kleo
0018 {
0019 namespace Crypto
0020 {
0021 
0022 class SimpleTask : public Task
0023 {
0024     Q_OBJECT
0025 public:
0026     explicit SimpleTask(const QString &label)
0027         : m_result()
0028         , m_label(label)
0029     {
0030     }
0031 
0032     void setResult(const std::shared_ptr<const Task::Result> &res)
0033     {
0034         m_result = res;
0035     }
0036     GpgME::Protocol protocol() const override
0037     {
0038         return GpgME::UnknownProtocol;
0039     }
0040     QString label() const override
0041     {
0042         return m_label;
0043     }
0044     void cancel() override
0045     {
0046     }
0047 
0048 private:
0049     void doStart() override
0050     {
0051         QTimer::singleShot(0, this, &SimpleTask::slotEmitResult);
0052     }
0053     unsigned long long inputSize() const override
0054     {
0055         return 0;
0056     }
0057 
0058 private Q_SLOTS:
0059     void slotEmitResult()
0060     {
0061         emitResult(m_result);
0062     }
0063 
0064 private:
0065     std::shared_ptr<const Task::Result> m_result;
0066     QString m_label;
0067 };
0068 }
0069 }