/src/kio-extras/thumbnail/kritacreator.cpp
Line | Count | Source |
1 | | /* This file is part of the Calligra project. |
2 | | SPDX-FileCopyrightText: 2015 Friedrich W. H. Kossebau <kossebau@kde.org> |
3 | | |
4 | | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | | */ |
6 | | |
7 | | #include "kritacreator.h" |
8 | | |
9 | | #include <KPluginFactory> |
10 | | #include <KZip> |
11 | | |
12 | | #include <QIODevice> |
13 | | #include <QImage> |
14 | | #include <memory> |
15 | | |
16 | 0 | K_PLUGIN_CLASS_WITH_JSON(KritaCreator, "kraorathumbnail.json") Unexecuted instantiation: kraorathumbnail_factory::tr(char const*, char const*, int) Unexecuted instantiation: kraorathumbnail_factory::~kraorathumbnail_factory() |
17 | 0 |
|
18 | 0 | KritaCreator::KritaCreator(QObject *parent, const QVariantList &args) |
19 | 8.81k | : KIO::ThumbnailCreator(parent, args) |
20 | 8.81k | { |
21 | 8.81k | } |
22 | | |
23 | | KritaCreator::~KritaCreator() |
24 | 8.81k | { |
25 | 8.81k | } |
26 | | |
27 | | KIO::ThumbnailResult KritaCreator::create(const KIO::ThumbnailRequest &request) |
28 | 8.81k | { |
29 | | // for now just rely on the rendered data inside the file, |
30 | | // do not load Krita code for rendering ourselves, as that currently (2.9) |
31 | | // means loading all plugins, resources etc. |
32 | 8.81k | KZip zip(request.url().toLocalFile()); |
33 | 8.81k | if (!zip.open(QIODevice::ReadOnly)) { |
34 | 8.75k | return KIO::ThumbnailResult::fail(); |
35 | 8.75k | } |
36 | | |
37 | | // first check if normal thumbnail is good enough |
38 | | // ORA thumbnail? |
39 | 61 | const KArchiveFile *entry = zip.directory()->file(QLatin1String("Thumbnails/thumbnail.png")); |
40 | 61 | if (!entry) { |
41 | | // KRA thumbnail |
42 | 61 | entry = zip.directory()->file(QLatin1String("preview.png")); |
43 | 61 | } |
44 | | |
45 | 61 | if (!entry) { |
46 | 61 | return KIO::ThumbnailResult::fail(); |
47 | 61 | } |
48 | | |
49 | 0 | std::unique_ptr<QIODevice> fileDevice{entry->createDevice()}; |
50 | 0 | QImage image; |
51 | 0 | bool thumbLoaded = image.load(fileDevice.get(), "PNG"); |
52 | | // The requested size is a boundingbox, so meeting one size is sufficient |
53 | 0 | if (thumbLoaded && ((image.width() >= request.targetSize().width()) || (image.height() >= request.targetSize().height()))) { |
54 | 0 | return KIO::ThumbnailResult::pass(image); |
55 | 0 | } |
56 | | |
57 | 0 | entry = zip.directory()->file(QLatin1String("mergedimage.png")); |
58 | 0 | if (entry) { |
59 | 0 | QImage thumbnail; |
60 | 0 | fileDevice.reset(entry->createDevice()); |
61 | 0 | thumbLoaded = thumbnail.load(fileDevice.get(), "PNG"); |
62 | 0 | if (thumbLoaded) { |
63 | 0 | return KIO::ThumbnailResult::pass(thumbnail); |
64 | 0 | } |
65 | 0 | } |
66 | | |
67 | 0 | return KIO::ThumbnailResult::fail(); |
68 | 0 | } |
69 | | |
70 | | #include "kritacreator.moc" |
71 | | #include "moc_kritacreator.cpp" |