Changeset View
Changeset View
Standalone View
Standalone View
thumbnail/opendocumentcreator.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 Kai Uwe Broulik <kde@broulik.de> | 2 | * Copyright (c) 2018-2019 Kai Uwe Broulik <kde@broulik.de> | ||
3 | * | 3 | * | ||
4 | * This library is free software; you can redistribute it and/or | 4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | 5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | 7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | 8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | 9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | 10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
Show All 30 Lines | 40 | { | |||
41 | Q_UNUSED(width); | 41 | Q_UNUSED(width); | ||
42 | Q_UNUSED(height); | 42 | Q_UNUSED(height); | ||
43 | 43 | | |||
44 | KZip zip(path); | 44 | KZip zip(path); | ||
45 | if (!zip.open(QIODevice::ReadOnly)) { | 45 | if (!zip.open(QIODevice::ReadOnly)) { | ||
46 | return false; | 46 | return false; | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | // Open Document | ||||
49 | const KArchiveEntry *entry = zip.directory()->entry(QStringLiteral("Thumbnails/thumbnail.png")); | 50 | const KArchiveEntry *entry = zip.directory()->entry(QStringLiteral("Thumbnails/thumbnail.png")); | ||
50 | 51 | | |||
52 | if (entry && entry->isFile()) { | ||||
53 | const KZipFileEntry *zipFileEntry = static_cast<const KZipFileEntry *>(entry); | ||||
54 | | ||||
55 | if (image.loadFromData(zipFileEntry->data(), "PNG")) { | ||||
56 | return true; | ||||
57 | } | ||||
58 | } | ||||
59 | | ||||
60 | // Office "Open" XML | ||||
61 | const KArchiveEntry *docPropsEntry = zip.directory()->entry(QStringLiteral("docProps")); | ||||
62 | | ||||
63 | if (docPropsEntry && docPropsEntry->isDirectory()) { | ||||
64 | const auto *docsPropsDir = static_cast<const KArchiveDirectory *>(docPropsEntry); | ||||
65 | | ||||
66 | const QStringList files = docsPropsDir->entries(); | ||||
67 | | ||||
68 | for (const QString &file : files) { | ||||
69 | // can be any format (usually .jpeg, but also .jpg, or .emf for templates) | ||||
70 | if (!file.startsWith(QLatin1String("thumbnail"), Qt::CaseInsensitive)) { | ||||
71 | continue; | ||||
72 | } | ||||
73 | | ||||
74 | entry = docsPropsDir->entry(file); | ||||
51 | if (!entry || !entry->isFile()) { | 75 | if (!entry || !entry->isFile()) { | ||
52 | return false; | 76 | continue; | ||
53 | } | 77 | } | ||
54 | 78 | | |||
55 | const KZipFileEntry *zipFileEntry = static_cast<const KZipFileEntry *>(entry); | 79 | const KZipFileEntry *zipFileEntry = static_cast<const KZipFileEntry *>(entry); | ||
56 | return image.loadFromData(zipFileEntry->data(), "PNG"); | 80 | return image.loadFromData(zipFileEntry->data()); | ||
81 | } | ||||
82 | } | ||||
83 | | ||||
84 | return false; | ||||
57 | } | 85 | } |