File indexing completed on 2024-04-28 04:58:02
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@broulik.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "appimagecreator.h" 0008 0009 #include <QImage> 0010 #include <QScopedPointer> 0011 0012 #include <appimage/appimage.h> 0013 0014 #include <KPluginFactory> 0015 0016 K_PLUGIN_CLASS_WITH_JSON(AppImageCreator, "appimagethumbnail.json") 0017 0018 AppImageCreator::AppImageCreator(QObject *parent, const QVariantList &args) 0019 : KIO::ThumbnailCreator(parent, args) 0020 { 0021 } 0022 0023 AppImageCreator::~AppImageCreator() = default; 0024 0025 KIO::ThumbnailResult AppImageCreator::create(const KIO::ThumbnailRequest &request) 0026 { 0027 unsigned long size = 0L; 0028 char *buf = nullptr; 0029 0030 bool ok = appimage_read_file_into_buffer_following_symlinks(qUtf8Printable(request.url().toLocalFile()), ".DirIcon", &buf, &size); 0031 0032 QScopedPointer<char, QScopedPointerPodDeleter> cleanup(buf); 0033 Q_UNUSED(cleanup); 0034 0035 if (!ok) { 0036 return KIO::ThumbnailResult::fail(); 0037 } 0038 0039 QImage image; 0040 image.loadFromData(reinterpret_cast<uchar *>(buf), size); 0041 return KIO::ThumbnailResult::pass(image); 0042 } 0043 0044 #include "appimagecreator.moc" 0045 #include "moc_appimagecreator.cpp"