diff --git a/thumbnail/CMakeLists.txt b/thumbnail/CMakeLists.txt --- a/thumbnail/CMakeLists.txt +++ b/thumbnail/CMakeLists.txt @@ -7,6 +7,14 @@ PURPOSE "Provides support for OpenEXR formatted images in the thumbnail kioslave" ) +# TODO find libappimage only +find_package(AppImageKit) +set_package_properties(AppImageKit PROPERTIES DESCRIPTION "Core library of the AppImage project" + URL "https://github.com/AppImage/libappimage" + TYPE OPTIONAL + PURPOSE "Provides support for AppImage thumbnails" + ) + include_directories(${CMAKE_BINARY_DIR}) ########### next target ############### @@ -226,6 +234,24 @@ set(audiothumbnail_desktop audiothumbnail.desktop) endif(TAGLIB_FOUND) +# ########### next target ############### + +if(AppImageKit_FOUND) + +set(appimagethumbnail_SRCS appimagecreator.cpp) +add_library(appimagethumbnail MODULE ${appimagethumbnail_SRCS}) + +target_link_libraries(appimagethumbnail + KF5::KIOWidgets + Qt5::Gui + appimage +) + +install(TARGETS appimagethumbnail DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES appimagethumbnail.desktop DESTINATION ${SERVICES_INSTALL_DIR}) + +endif() + ########### install files ############### install(FILES thumbcreator.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) diff --git a/thumbnail/appimagecreator.h b/thumbnail/appimagecreator.h new file mode 100644 --- /dev/null +++ b/thumbnail/appimagecreator.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class AppImageCreator : public ThumbCreator +{ +public: + AppImageCreator(); + ~AppImageCreator() override; + + bool create(const QString &path, int width, int height, QImage &image) override; + Flags flags() const override; +}; diff --git a/thumbnail/appimagecreator.cpp b/thumbnail/appimagecreator.cpp new file mode 100644 --- /dev/null +++ b/thumbnail/appimagecreator.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "appimagecreator.h" + +#include +#include + +#include + +extern "C" +{ + Q_DECL_EXPORT ThumbCreator *new_creator() + { + return new AppImageCreator; + } +} + +AppImageCreator::AppImageCreator() = default; +AppImageCreator::~AppImageCreator() = default; + +bool AppImageCreator::create(const QString &path, int width, int height, QImage &image) +{ + // We just load the .DirIcon verbatim and let the PreviewJob figure out scaling to required size if needed + Q_UNUSED(width); + Q_UNUSED(height); + + QTemporaryFile file; + if (!file.open()) { + return false; + } + + appimage_extract_file_following_symlinks(qUtf8Printable(path), + ".DirIcon", + qUtf8Printable(file.fileName())); + + if (!image.load(file.fileName())) { + return false; + } + + return true; +} + +ThumbCreator::Flags AppImageCreator::flags() const +{ + return None; +} diff --git a/thumbnail/appimagethumbnail.desktop b/thumbnail/appimagethumbnail.desktop new file mode 100644 --- /dev/null +++ b/thumbnail/appimagethumbnail.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Service +Name=AppImage +X-KDE-ServiceTypes=ThumbCreator +MimeType=application/x-iso9660-appimage;application/vnd.appimage; +X-KDE-Library=appimagethumbnail +CacheThumbnail=true