File: appimagecreator.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 (45 lines) | stat: -rw-r--r-- 1,165 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
/*
 * SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@broulik.de>
 *
 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#include "appimagecreator.h"

#include <QImage>
#include <QScopedPointer>

#include <appimage/appimage.h>

#include <KPluginFactory>

K_PLUGIN_CLASS_WITH_JSON(AppImageCreator, "appimagethumbnail.json")

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

AppImageCreator::~AppImageCreator() = default;

KIO::ThumbnailResult AppImageCreator::create(const KIO::ThumbnailRequest &request)
{
    unsigned long size = 0L;
    char *buf = nullptr;

    bool ok = appimage_read_file_into_buffer_following_symlinks(qUtf8Printable(request.url().toLocalFile()), ".DirIcon", &buf, &size);

    QScopedPointer<char, QScopedPointerPodDeleter> cleanup(buf);
    Q_UNUSED(cleanup);

    if (!ok) {
        return KIO::ThumbnailResult::fail();
    }

    QImage image;
    image.loadFromData(reinterpret_cast<uchar *>(buf), size);
    return KIO::ThumbnailResult::pass(image);
}

#include "appimagecreator.moc"
#include "moc_appimagecreator.cpp"