Commit 4ae2b622 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Embed JSON metadata in thumbnailers

By creating a macro for this, we avoid copying the same bit of boilerplate all over the place.
parent 65d1896b
Pipeline #109860 passed with stage
in 2 minutes and 17 seconds
......@@ -8,7 +8,7 @@ set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE
project(kio-extras VERSION ${RELEASE_SERVICE_VERSION})
set(QT_MIN_VERSION "5.15.0")
set(KF5_MIN_VERSION "5.82.0")
set(KF5_MIN_VERSION "5.89.0")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
......
......@@ -37,6 +37,14 @@ set_package_properties(Taglib PROPERTIES
include_directories(${CMAKE_BINARY_DIR})
include(ECMSetupQtPluginMacroNames)
ecm_setup_qtplugin_macro_names(
JSON_ARG2
"EXPORT_THUMBNAILER_WITH_JSON"
CONFIG_CODE_VARIABLE
PACKAGE_SETUP_AUTOMOC_VARIABLES
)
########### next target ###############
add_library(kio_thumbnail MODULE)
......@@ -75,13 +83,13 @@ install(TARGETS kio_thumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kio)
########### next target ###############
add_library(imagethumbnail MODULE imagecreator.cpp)
kcoreaddons_desktop_to_json(imagethumbnail imagethumbnail.desktop)
target_link_libraries(imagethumbnail
KF5::KIOWidgets
)
install(TARGETS imagethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES imagethumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS imagethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
########### next target ###############
......@@ -92,6 +100,7 @@ install(FILES directorythumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR
add_library(jpegthumbnail MODULE jpegcreator.cpp)
kconfig_add_kcfg_files(jpegthumbnail jpegcreatorsettings5.kcfgc)
kcoreaddons_desktop_to_json(jpegthumbnail jpegthumbnail.desktop)
target_link_libraries(jpegthumbnail
Qt5::Core
......@@ -104,13 +113,13 @@ target_link_libraries(jpegthumbnail
)
install(FILES jpegcreatorsettings5.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(TARGETS jpegthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES jpegthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS jpegthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
########### next target ###############
add_library(svgthumbnail MODULE svgcreator.cpp)
kcoreaddons_desktop_to_json(svgthumbnail svgthumbnail.desktop)
target_link_libraries(svgthumbnail
Qt5::Gui
Qt5::Svg
......@@ -118,21 +127,20 @@ target_link_libraries(svgthumbnail
KF5::KIOWidgets
)
install(TARGETS svgthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES svgthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS svgthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
########### next target ###############
add_library(textthumbnail MODULE textcreator.cpp)
kcoreaddons_desktop_to_json(textthumbnail textthumbnail.desktop)
target_link_libraries(textthumbnail
Qt5::Gui
KF5::KIOWidgets
KF5::SyntaxHighlighting
)
install(TARGETS textthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES textthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS textthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
########### next target ###############
......@@ -149,10 +157,10 @@ if(NOT WIN32)
EXPORT KIO_EXTRAS
)
kcoreaddons_desktop_to_json(djvuthumbnail djvuthumbnail.desktop)
target_link_libraries(djvuthumbnail KF5::KIOWidgets)
install(TARGETS djvuthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES djvuthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS djvuthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
endif()
......@@ -171,6 +179,7 @@ if(OpenEXR_FOUND)
EXPORT KIO_EXTRAS
)
kcoreaddons_desktop_to_json(exrthumbnail exrthumbnail.desktop)
target_link_libraries(exrthumbnail
KF5::KIOCore
KF5::KIOWidgets
......@@ -186,8 +195,7 @@ if(OpenEXR_FOUND)
# when exceptions are not enabled.
kde_source_files_enable_exceptions(exrcreator.cpp)
install(TARGETS exrthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES exrthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS exrthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
endif()
......@@ -195,16 +203,16 @@ endif()
if(X11_Xcursor_FOUND)
add_library(cursorthumbnail MODULE cursorcreator.cpp)
add_library(cursorthumbnail MODULE cursorcreator.cpp cursorcreatorplugin.cpp)
kcoreaddons_desktop_to_json(cursorthumbnail cursorthumbnail.desktop)
target_link_libraries(cursorthumbnail
KF5::KIOCore
KF5::KIOWidgets
${X11_Xcursor_LIB}
)
install(TARGETS cursorthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES cursorthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS cursorthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
endif()
......@@ -221,13 +229,13 @@ else()
target_sources(windowsimagethumbnail PRIVATE icoutils_wrestool.cpp)
endif()
kcoreaddons_desktop_to_json(windowsexethumbnail windowsexethumbnail.desktop)
target_link_libraries(windowsexethumbnail KF5::KIOWidgets)
install(TARGETS windowsexethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES windowsexethumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS windowsexethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
kcoreaddons_desktop_to_json(windowsimagethumbnail windowsimagethumbnail.desktop)
target_link_libraries(windowsimagethumbnail KF5::KIOWidgets)
install(TARGETS windowsimagethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES windowsimagethumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS windowsimagethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
########### next target ###############
......@@ -242,26 +250,26 @@ ecm_qt_declare_logging_category(comicbookthumbnail
EXPORT KIO_EXTRAS
)
kcoreaddons_desktop_to_json(comicbookthumbnail comicbookthumbnail.desktop)
target_link_libraries(comicbookthumbnail
Qt5::Gui
KF5::Archive
KF5::KIOWidgets
)
install(TARGETS comicbookthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES comicbookthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS comicbookthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
# ########### next target ###############
add_library(kritathumbnail MODULE kritacreator.cpp)
kcoreaddons_desktop_to_json(kritathumbnail kraorathumbnail.desktop)
target_link_libraries(kritathumbnail
KF5::KIOWidgets
KF5::Archive
)
install(TARGETS kritathumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES kraorathumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS kritathumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
########### next target #################
......@@ -269,13 +277,13 @@ if(Taglib_FOUND)
add_library(audiothumbnail MODULE audiocreator.cpp)
kcoreaddons_desktop_to_json(audiothumbnail audiothumbnail.desktop)
target_link_libraries(audiothumbnail
Taglib::Taglib
KF5::KIOWidgets
)
install(TARGETS audiothumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES audiothumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS audiothumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
endif()
......@@ -283,14 +291,14 @@ endif()
add_library(opendocumentthumbnail MODULE opendocumentcreator.cpp)
kcoreaddons_desktop_to_json(opendocumentthumbnail opendocumentthumbnail.desktop)
target_link_libraries(opendocumentthumbnail
Qt5::Gui
KF5::KIOWidgets
KF5::Archive
)
install(TARGETS opendocumentthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES opendocumentthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS opendocumentthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
# ########### next target ###############
......@@ -303,9 +311,9 @@ if(libappimage_FOUND)
Qt5::Gui
libappimage
)
kcoreaddons_desktop_to_json(appimagethumbnail appimagethumbnail.desktop)
install(TARGETS appimagethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES appimagethumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS appimagethumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
endif()
......@@ -313,14 +321,14 @@ endif()
add_library(ebookthumbnail MODULE ebookcreator.cpp)
kcoreaddons_desktop_to_json(ebookthumbnail ebookthumbnail.desktop)
target_link_libraries(ebookthumbnail
Qt5::Gui
KF5::KIOWidgets
KF5::Archive
)
install(TARGETS ebookthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES ebookthumbnail.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS ebookthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/thumbcreator)
########### install files ###############
......
......@@ -6,18 +6,14 @@
#include "appimagecreator.h"
#include "macros.h"
#include <QImage>
#include <QScopedPointer>
#include <appimage/appimage.h>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new AppImageCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(AppImageCreator, "appimagethumbnail.json")
AppImageCreator::AppImageCreator() = default;
AppImageCreator::~AppImageCreator() = default;
......@@ -45,3 +41,5 @@ bool AppImageCreator::create(const QString &path, int width, int height, QImage
return image.loadFromData(reinterpret_cast<uchar*>(buf), size);
}
#include "appimagecreator.moc"
......@@ -9,6 +9,8 @@
#include "audiocreator.h"
#include "macros.h"
#include <QFile>
#include <QImage>
#include <QMimeType>
......@@ -30,13 +32,7 @@
#include <flacpicture.h>
#include <attachedpictureframe.h>
extern "C"
{
Q_DECL_EXPORT ThumbCreator* new_creator()
{
return new AudioCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(AudioCreator, "audiothumbnail.json")
AudioCreator::AudioCreator()
{
......@@ -196,3 +192,5 @@ bool AudioCreator::create(const QString &path, int, int, QImage &img)
}
return false;
}
#include "audiocreator.moc"
......@@ -16,6 +16,8 @@
#include "comiccreator.h"
#include "thumbnail-comic-logsettings.h"
#include "macros.h"
#include <kzip.h>
#include <ktar.h>
#include <k7zip.h>
......@@ -30,13 +32,7 @@
#include <QStandardPaths>
#include <QTemporaryDir>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new ComicCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(ComicCreator, "comicbookthumbnail.json")
ComicCreator::ComicCreator() {}
......@@ -249,3 +245,5 @@ int ComicCreator::runProcess(const QString& processPath, const QStringList& args
return ret;
}
#include "comiccreator.moc"
......@@ -12,14 +12,6 @@
#include <X11/Xlib.h>
#include <X11/Xcursor/Xcursor.h>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new CursorCreator;
}
}
bool CursorCreator::create( const QString &path, int width, int height, QImage &img )
{
XcursorImage *cursor = XcursorFilenameLoadImage(
......
// SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include <qplugin.h>
#include "macros.h"
#include "cursorcreator.h"
EXPORT_THUMBNAILER_WITH_JSON(CursorCreator, "cursorthumbnail.json")
#include "cursorcreatorplugin.moc"
......@@ -6,17 +6,13 @@
#include "djvucreator.h"
#include "thumbnail-djvu-logsettings.h"
#include "macros.h"
#include <QProcess>
#include <QString>
#include <QImage>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new DjVuCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(DjVuCreator, "djvuthumbnail.json")
bool DjVuCreator::create(const QString &path, int width, int height, QImage &img)
{
......@@ -45,3 +41,5 @@ bool DjVuCreator::create(const QString &path, int width, int height, QImage &img
img.load(&ddjvu, "ppm");
return true;
}
#include "djvucreator.moc"
......@@ -6,6 +6,8 @@
#include "ebookcreator.h"
#include "macros.h"
#include <QFile>
#include <QImage>
#include <QMap>
......@@ -15,13 +17,7 @@
#include <KZip>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new EbookCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(EbookCreator, "ebookthumbnail.json")
EbookCreator::EbookCreator() = default;
......@@ -320,3 +316,5 @@ QStringList EbookCreator::getEntryList(const KArchiveDirectory *dir, const QStri
return list;
}
#include "ebookcreator.moc"
......@@ -7,6 +7,8 @@
#include "exrcreator.h"
#include "thumbnail-exr-logsettings.h"
#include "macros.h"
#include <QImage>
#include <QFile>
......@@ -19,13 +21,7 @@
#include <limits>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new EXRCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(EXRCreator, "exrthumbnail.json")
bool EXRCreator::create(const QString &path, int, int, QImage &img)
{
......@@ -69,3 +65,5 @@ bool EXRCreator::create(const QString &path, int, int, QImage &img)
}
}
}
#include "exrcreator.moc"
......@@ -7,15 +7,11 @@
#include "imagecreator.h"
#include "macros.h"
#include <QImageReader>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new ImageCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(ImageCreator, "imagethumbnail.json")
bool ImageCreator::create(const QString &path, int, int, QImage &img)
{
......@@ -29,3 +25,5 @@ bool ImageCreator::create(const QString &path, int, int, QImage &img)
img = img.convertToFormat(img.hasAlphaChannel() ? QImage::Format_ARGB32 : QImage::Format_RGB32);
return true;
}
#include "imagecreator.moc"
......@@ -8,17 +8,13 @@
#include "jpegcreator.h"
#include "jpegcreatorsettings5.h"
#include "macros.h"
#include <QImage>
#include <QImageReader>
#include <klocalizedstring.h>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new JpegCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(JpegCreator, "jpegthumbnail.json")
JpegCreator::JpegCreator()
{
......@@ -41,3 +37,5 @@ bool JpegCreator::create(const QString &path, int width, int height, QImage &ima
return imageReader.read(&image);
}
#include "jpegcreator.moc"
......@@ -6,19 +6,15 @@
#include "kritacreator.h"
#include "macros.h"
#include <kzip.h>
#include <memory>
#include <QImage>
#include <QIODevice>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new KritaCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(KritaCreator, "kraorathumbnail.json")
KritaCreator::KritaCreator()
{
......@@ -70,3 +66,5 @@ bool KritaCreator::create(const QString &path, int width, int height, QImage &im
return false;
}
#include "kritacreator.moc"
// SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
// clang-format off
#define EXPORT_THUMBNAILER_WITH_JSON(className, json) \
extern "C" \
{\
Q_DECL_EXPORT ThumbCreator *new_creator()\
{\
return new className;\
}\
}\
\
class KIOPluginForMetaData : public QObject\
{\
Q_OBJECT\
Q_PLUGIN_METADATA(IID "blaaa" FILE json)\
};\
......@@ -6,19 +6,15 @@
#include "opendocumentcreator.h"
#include "macros.h"
#include <QImage>
#include <QScopedPointer>
#include <QXmlStreamReader>
#include <KZip>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new OpenDocumentCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(OpenDocumentCreator, "opendocumentthumbnail.json")
OpenDocumentCreator::OpenDocumentCreator() = default;
......@@ -76,3 +72,5 @@ bool OpenDocumentCreator::create(const QString &path, int width, int height, QIm
return false;
}
#include "opendocumentcreator.moc"
......@@ -6,17 +6,13 @@
#include "svgcreator.h"
#include "macros.h"
#include <QImage>
#include <QPainter>
#include <QSvgRenderer>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new SvgCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(SvgCreator, "svgthumbnail.json")
bool SvgCreator::create(const QString &path, int w, int h, QImage &img)
{
......@@ -39,3 +35,5 @@ bool SvgCreator::create(const QString &path, int w, int h, QImage &img)
img = i;
return true;
}
#include "svgcreator.moc"
......@@ -24,6 +24,12 @@
// TODO Fix or remove kencodingprober code
// #include <kencodingprober.h>
class KIOPluginForMetaData : public QObject
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.thumbcreator" FILE "textthumbnail.json")
};
extern "C"
{
Q_DECL_EXPORT KIO::ThumbDevicePixelRatioDependentCreator *new_creator()
......@@ -166,3 +172,5 @@ bool TextCreator::create(const QString &path, int width, int height, QImage &img
}
return ok;
}
#include "textcreator.moc"
......@@ -8,17 +8,12 @@
#include "windowsexecreator.h"
#include "icoutils.h"
#include "macros.h"
#include <QString>
#include <QImage>
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new WindowsExeCreator;
}
}
EXPORT_THUMBNAILER_WITH_JSON(WindowsExeCreator, "windowsexethumbnail.json")
bool WindowsExeCreator::create(const QString &path, int width, int height, QImage &img)
{
......@@ -26,3 +21,5 @@ bool WindowsExeCreator::create(const QString &path, int width, int height, QImag
return IcoUtils::loadIcoImageFromExe(path, img, width, height);