Changeset View
Changeset View
Standalone View
Standalone View
kerfuffle/archiveformat.cpp
Show All 19 Lines | |||||
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY | 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY | ||
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF | 22 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF | ||
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | */ | 24 | */ | ||
25 | 25 | | |||
26 | #include "archiveformat.h" | 26 | #include "archiveformat.h" | ||
27 | 27 | | |||
28 | #include <QJsonArray> | ||||
29 | | ||||
28 | namespace Kerfuffle | 30 | namespace Kerfuffle | ||
29 | { | 31 | { | ||
30 | 32 | | |||
31 | ArchiveFormat::ArchiveFormat() : | 33 | ArchiveFormat::ArchiveFormat() : | ||
32 | m_encryptionType(Archive::Unencrypted) | 34 | m_encryptionType(Archive::Unencrypted) | ||
33 | { | 35 | { | ||
34 | } | 36 | } | ||
35 | 37 | | |||
36 | ArchiveFormat::ArchiveFormat(const QMimeType& mimeType, | 38 | ArchiveFormat::ArchiveFormat(const QMimeType& mimeType, | ||
37 | Archive::EncryptionType encryptionType, | 39 | Archive::EncryptionType encryptionType, | ||
38 | int minCompLevel, | 40 | int minCompLevel, | ||
39 | int maxCompLevel, | 41 | int maxCompLevel, | ||
40 | int defaultCompLevel, | 42 | int defaultCompLevel, | ||
41 | bool supportsWriteComment, | 43 | bool supportsWriteComment, | ||
42 | bool supportsTesting, | 44 | bool supportsTesting, | ||
43 | bool supportsMultiVolume) : | 45 | bool supportsMultiVolume, | ||
46 | QStringList compressionMethods, | ||||
47 | QString defaultCompressionMethod) : | ||||
44 | m_mimeType(mimeType), | 48 | m_mimeType(mimeType), | ||
45 | m_encryptionType(encryptionType), | 49 | m_encryptionType(encryptionType), | ||
46 | m_minCompressionLevel(minCompLevel), | 50 | m_minCompressionLevel(minCompLevel), | ||
47 | m_maxCompressionLevel(maxCompLevel), | 51 | m_maxCompressionLevel(maxCompLevel), | ||
48 | m_defaultCompressionLevel(defaultCompLevel), | 52 | m_defaultCompressionLevel(defaultCompLevel), | ||
49 | m_supportsWriteComment(supportsWriteComment), | 53 | m_supportsWriteComment(supportsWriteComment), | ||
50 | m_supportsTesting(supportsTesting), | 54 | m_supportsTesting(supportsTesting), | ||
51 | m_supportsMultiVolume(supportsMultiVolume) | 55 | m_supportsMultiVolume(supportsMultiVolume), | ||
56 | m_compressionMethods(compressionMethods), | ||||
57 | m_defaultCompressionMethod(defaultCompressionMethod) | ||||
52 | { | 58 | { | ||
53 | } | 59 | } | ||
54 | 60 | | |||
55 | ArchiveFormat ArchiveFormat::fromMetadata(const QMimeType& mimeType, const KPluginMetaData& metadata) | 61 | ArchiveFormat ArchiveFormat::fromMetadata(const QMimeType& mimeType, const KPluginMetaData& metadata) | ||
56 | { | 62 | { | ||
57 | const QJsonObject json = metadata.rawData(); | 63 | const QJsonObject json = metadata.rawData(); | ||
58 | foreach (const QString& mime, metadata.mimeTypes()) { | 64 | foreach (const QString& mime, metadata.mimeTypes()) { | ||
59 | if (mimeType.name() != mime) { | 65 | if (mimeType.name() != mime) { | ||
60 | continue; | 66 | continue; | ||
61 | } | 67 | } | ||
62 | 68 | | |||
63 | const QJsonObject formatProps = json[mime].toObject(); | 69 | const QJsonObject formatProps = json[mime].toObject(); | ||
64 | 70 | | |||
65 | int minCompLevel = formatProps[QStringLiteral("CompressionLevelMin")].toInt(); | 71 | int minCompLevel = formatProps[QStringLiteral("CompressionLevelMin")].toInt(); | ||
66 | int maxCompLevel = formatProps[QStringLiteral("CompressionLevelMax")].toInt(); | 72 | int maxCompLevel = formatProps[QStringLiteral("CompressionLevelMax")].toInt(); | ||
67 | int defaultCompLevel = formatProps[QStringLiteral("CompressionLevelDefault")].toInt(); | 73 | int defaultCompLevel = formatProps[QStringLiteral("CompressionLevelDefault")].toInt(); | ||
68 | 74 | | |||
69 | bool supportsWriteComment = formatProps[QStringLiteral("SupportsWriteComment")].toBool(); | 75 | bool supportsWriteComment = formatProps[QStringLiteral("SupportsWriteComment")].toBool(); | ||
70 | bool supportsTesting = formatProps[QStringLiteral("SupportsTesting")].toBool(); | 76 | bool supportsTesting = formatProps[QStringLiteral("SupportsTesting")].toBool(); | ||
71 | bool supportsMultiVolume = formatProps[QStringLiteral("SupportsMultiVolume")].toBool(); | 77 | bool supportsMultiVolume = formatProps[QStringLiteral("SupportsMultiVolume")].toBool(); | ||
72 | 78 | | |||
79 | QStringList compressionMethods; | ||||
80 | QJsonArray array = formatProps[QStringLiteral("CompressionMethods")].toArray(); | ||||
81 | foreach (const QJsonValue &value, array) { | ||||
82 | compressionMethods.append(value.toString()); | ||||
83 | } | ||||
84 | QString defaultCompMethod = formatProps[QStringLiteral("CompressionMethodDefault")].toString(); | ||||
85 | | ||||
73 | Archive::EncryptionType encType = Archive::Unencrypted; | 86 | Archive::EncryptionType encType = Archive::Unencrypted; | ||
74 | if (formatProps[QStringLiteral("HeaderEncryption")].toBool()) { | 87 | if (formatProps[QStringLiteral("HeaderEncryption")].toBool()) { | ||
75 | encType = Archive::HeaderEncrypted; | 88 | encType = Archive::HeaderEncrypted; | ||
76 | } else if (formatProps[QStringLiteral("Encryption")].toBool()) { | 89 | } else if (formatProps[QStringLiteral("Encryption")].toBool()) { | ||
77 | encType = Archive::Encrypted; | 90 | encType = Archive::Encrypted; | ||
78 | } | 91 | } | ||
79 | 92 | | |||
80 | return ArchiveFormat(mimeType, encType, minCompLevel, maxCompLevel, defaultCompLevel, supportsWriteComment, supportsTesting, supportsMultiVolume); | 93 | return ArchiveFormat(mimeType, encType, minCompLevel, maxCompLevel, defaultCompLevel, supportsWriteComment, supportsTesting, supportsMultiVolume, compressionMethods, defaultCompMethod); | ||
81 | } | 94 | } | ||
82 | 95 | | |||
83 | return ArchiveFormat(); | 96 | return ArchiveFormat(); | ||
84 | } | 97 | } | ||
85 | 98 | | |||
86 | bool ArchiveFormat::isValid() const | 99 | bool ArchiveFormat::isValid() const | ||
87 | { | 100 | { | ||
88 | return m_mimeType.isValid(); | 101 | return m_mimeType.isValid(); | ||
Show All 29 Lines | 130 | { | |||
118 | return m_supportsTesting; | 131 | return m_supportsTesting; | ||
119 | } | 132 | } | ||
120 | 133 | | |||
121 | bool ArchiveFormat::supportsMultiVolume() const | 134 | bool ArchiveFormat::supportsMultiVolume() const | ||
122 | { | 135 | { | ||
123 | return m_supportsMultiVolume; | 136 | return m_supportsMultiVolume; | ||
124 | } | 137 | } | ||
125 | 138 | | |||
139 | QStringList ArchiveFormat::compressionMethods() const | ||||
140 | { | ||||
141 | return m_compressionMethods; | ||||
142 | } | ||||
143 | | ||||
144 | QString ArchiveFormat::defaultCompressionMethod() const | ||||
145 | { | ||||
146 | return m_defaultCompressionMethod; | ||||
147 | } | ||||
148 | | ||||
126 | } | 149 | } |