/src/kio-extras/thumbnail/djvucreator.cpp
Line | Count | Source |
1 | | /* |
2 | | SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-KDE-Accepted-GPL |
3 | | SPDX-FileCopyrightText: 2020 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> |
4 | | */ |
5 | | |
6 | | #include "djvucreator.h" |
7 | | #include "thumbnail-djvu-logsettings.h" |
8 | | |
9 | | #include <QImage> |
10 | | #include <QProcess> |
11 | | #include <QString> |
12 | | |
13 | | #include <KPluginFactory> |
14 | | |
15 | 0 | K_PLUGIN_CLASS_WITH_JSON(DjVuCreator, "djvuthumbnail.json") Unexecuted instantiation: djvuthumbnail_factory::tr(char const*, char const*, int) Unexecuted instantiation: djvuthumbnail_factory::~djvuthumbnail_factory() |
16 | 0 |
|
17 | 0 | DjVuCreator::DjVuCreator(QObject *parent, const QVariantList &args) |
18 | 802 | : KIO::ThumbnailCreator(parent, args) |
19 | 802 | { |
20 | 802 | } |
21 | | |
22 | | KIO::ThumbnailResult DjVuCreator::create(const KIO::ThumbnailRequest &request) |
23 | 802 | { |
24 | 802 | QProcess ddjvu; |
25 | | |
26 | 802 | const QStringList args{QStringLiteral("-page=1"), |
27 | 802 | QStringLiteral("-size=") + QString::number(request.targetSize().width()) + QChar('x') |
28 | 802 | + QString::number(request.targetSize().height()), |
29 | 802 | QStringLiteral("-format=ppm"), |
30 | 802 | request.url().toLocalFile()}; |
31 | | |
32 | 802 | ddjvu.start(QStringLiteral("ddjvu"), args); |
33 | 802 | ddjvu.waitForFinished(); |
34 | | |
35 | 802 | static bool warnOnce = true; |
36 | 802 | if (ddjvu.exitCode() != 0) { |
37 | 802 | if (warnOnce) { |
38 | 1 | qCWarning(KIO_THUMBNAIL_DJVU_LOG) << ddjvu.error() << ddjvu.readAllStandardError(); |
39 | 1 | warnOnce = false; |
40 | 1 | } |
41 | 802 | return KIO::ThumbnailResult::fail(); |
42 | 802 | } |
43 | | |
44 | 0 | QImage img; |
45 | 0 | bool okay = img.load(&ddjvu, "ppm"); |
46 | 0 | return okay ? KIO::ThumbnailResult::pass(img) : KIO::ThumbnailResult::fail(); |
47 | 802 | } |
48 | | |
49 | | #include "djvucreator.moc" |
50 | | #include "moc_djvucreator.cpp" |