1 /* -*- mode: c++; c-basic-offset:4 -*- 2 utils/input.h 3 4 This file is part of Kleopatra, the KDE keymanager 5 SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB 6 7 SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 10 #pragma once 11 12 #include <kleo-assuan.h> // for assuan_fd_t 13 14 #include <memory> 15 16 class QIODevice; 17 class QString; 18 #include <QStringList> 19 class QByteArray; 20 class QFile; 21 class QDir; 22 23 namespace Kleo 24 { 25 class Output; 26 class Input 27 { 28 public: 29 virtual ~Input(); 30 31 virtual QString label() const = 0; 32 virtual void setLabel(const QString &label) = 0; 33 virtual std::shared_ptr<QIODevice> ioDevice() const = 0; 34 virtual unsigned int classification() const = 0; 35 virtual unsigned long long size() const = 0; 36 virtual QString errorString() const = 0; 37 /** Whether or not the input failed. */ failed()38 virtual bool failed() const { return false; } 39 40 void finalize(); // equivalent to ioDevice()->close(); 41 42 static std::shared_ptr<Input> createFromPipeDevice(assuan_fd_t fd, const QString &label); 43 static std::shared_ptr<Input> createFromFile(const QString &filename, bool dummy = false); 44 static std::shared_ptr<Input> createFromFile(const std::shared_ptr<QFile> &file); 45 static std::shared_ptr<Input> createFromOutput(const std::shared_ptr<Output> &output); // implemented in output.cpp 46 static std::shared_ptr<Input> createFromProcessStdOut(const QString &command); 47 static std::shared_ptr<Input> createFromProcessStdOut(const QString &command, const QStringList &args); 48 static std::shared_ptr<Input> createFromProcessStdOut(const QString &command, const QStringList &args, const QDir &workingDirectory); 49 static std::shared_ptr<Input> createFromProcessStdOut(const QString &command, const QByteArray &stdin_); 50 static std::shared_ptr<Input> createFromProcessStdOut(const QString &command, const QStringList &args, const QByteArray &stdin_); 51 static std::shared_ptr<Input> createFromProcessStdOut(const QString &command, const QStringList &args, const QDir &workingDirectory, const QByteArray &stdin_); 52 #ifndef QT_NO_CLIPBOARD 53 static std::shared_ptr<Input> createFromClipboard(); 54 #endif 55 static std::shared_ptr<Input> createFromByteArray(QByteArray *data, const QString &label); 56 }; 57 } 58 59 60