File: djvucreator.cpp

package info (click to toggle)
kio-extras 4%3A25.04.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 31,928 kB
  • sloc: cpp: 28,852; ansic: 3,084; perl: 1,048; xml: 116; sh: 92; python: 28; makefile: 9
file content (50 lines) | stat: -rw-r--r-- 1,512 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
    SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-KDE-Accepted-GPL
    SPDX-FileCopyrightText: 2020 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
*/

#include "djvucreator.h"
#include "thumbnail-djvu-logsettings.h"

#include <QImage>
#include <QProcess>
#include <QString>

#include <KPluginFactory>

K_PLUGIN_CLASS_WITH_JSON(DjVuCreator, "djvuthumbnail.json")

DjVuCreator::DjVuCreator(QObject *parent, const QVariantList &args)
    : KIO::ThumbnailCreator(parent, args)
{
}

KIO::ThumbnailResult DjVuCreator::create(const KIO::ThumbnailRequest &request)
{
    QProcess ddjvu;

    const QStringList args{QStringLiteral("-page=1"),
                           QStringLiteral("-size=") + QString::number(request.targetSize().width()) + QChar('x')
                               + QString::number(request.targetSize().height()),
                           QStringLiteral("-format=ppm"),
                           request.url().toLocalFile()};

    ddjvu.start(QStringLiteral("ddjvu"), args);
    ddjvu.waitForFinished();

    static bool warnOnce = true;
    if (ddjvu.exitCode() != 0) {
        if (warnOnce) {
            qCWarning(KIO_THUMBNAIL_DJVU_LOG) << ddjvu.error() << ddjvu.readAllStandardError();
            warnOnce = false;
        }
        return KIO::ThumbnailResult::fail();
    }

    QImage img;
    bool okay = img.load(&ddjvu, "ppm");
    return okay ? KIO::ThumbnailResult::pass(img) : KIO::ThumbnailResult::fail();
}

#include "djvucreator.moc"
#include "moc_djvucreator.cpp"