File indexing completed on 2024-06-23 05:14:15
0001 /* -*- mode: c++; c-basic-offset:4 -*- 0002 utils/archivedefinition.h 0003 0004 This file is part of Kleopatra, the KDE keymanager 0005 SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include <QMetaType> 0013 #include <QString> 0014 #include <QStringList> 0015 0016 #include <gpgme++/global.h> // GpgME::Protocol 0017 0018 #include <memory> 0019 #include <vector> 0020 0021 class QDir; 0022 0023 namespace Kleo 0024 { 0025 class Input; 0026 class Output; 0027 } 0028 0029 namespace Kleo 0030 { 0031 0032 class ArchiveDefinition 0033 { 0034 protected: 0035 ArchiveDefinition(const QString &id, const QString &label); 0036 0037 public: 0038 virtual ~ArchiveDefinition(); 0039 0040 enum ArgumentPassingMethod { 0041 CommandLine, 0042 NewlineSeparatedInputFile, 0043 NullSeparatedInputFile, 0044 0045 NumArgumentPassingMethods 0046 }; 0047 0048 QString id() const 0049 { 0050 return m_id; 0051 } 0052 QString label() const 0053 { 0054 return m_label; 0055 } 0056 0057 const QStringList &extensions(GpgME::Protocol p) const 0058 { 0059 checkProtocol(p); 0060 return m_extensions[p]; 0061 } 0062 0063 QString stripExtension(GpgME::Protocol p, const QString &filePath) const; 0064 0065 std::shared_ptr<Input> createInputFromPackCommand(GpgME::Protocol p, const QStringList &files) const; 0066 ArgumentPassingMethod packCommandArgumentPassingMethod(GpgME::Protocol p) const 0067 { 0068 checkProtocol(p); 0069 return m_packCommandMethod[p]; 0070 } 0071 0072 std::shared_ptr<Output> createOutputFromUnpackCommand(GpgME::Protocol p, const QString &file, const QDir &wd) const; 0073 // unpack-command must use CommandLine ArgumentPassingMethod 0074 0075 static QString installPath(); 0076 static void setInstallPath(const QString &ip); 0077 0078 static std::vector<std::shared_ptr<ArchiveDefinition>> getArchiveDefinitions(); 0079 static std::vector<std::shared_ptr<ArchiveDefinition>> getArchiveDefinitions(QStringList &errors); 0080 0081 protected: 0082 void setPackCommandArgumentPassingMethod(GpgME::Protocol p, ArgumentPassingMethod method) 0083 { 0084 checkProtocol(p); 0085 m_packCommandMethod[p] = method; 0086 } 0087 void setExtensions(GpgME::Protocol p, const QStringList &extensions) 0088 { 0089 checkProtocol(p); 0090 m_extensions[p] = extensions; 0091 } 0092 0093 void checkProtocol(GpgME::Protocol p) const; 0094 0095 private: 0096 virtual QString doGetPackCommand(GpgME::Protocol p) const = 0; 0097 virtual QString doGetUnpackCommand(GpgME::Protocol p) const = 0; 0098 virtual QStringList doGetPackArguments(GpgME::Protocol p, const QStringList &files) const = 0; 0099 virtual QStringList doGetUnpackArguments(GpgME::Protocol p, const QString &file) const = 0; 0100 0101 private: 0102 const QString m_id; 0103 const QString m_label; 0104 /*const*/ QStringList m_extensions[2]; 0105 ArgumentPassingMethod m_packCommandMethod[2]; 0106 // m_unpackCommandMethod[2] <- must always be CommandLine 0107 }; 0108 0109 } 0110 0111 Q_DECLARE_METATYPE(std::shared_ptr<Kleo::ArchiveDefinition>)