Verified Commit a3bcd1c2 authored by azubieta's avatar azubieta
Browse files

Add thumbnailer module

parent a73fd54b
Pipeline #624 passed with stage
in 1 minute and 42 seconds
add_subdirectory(appimageservices-interface)
add_subdirectory(fileitem-actions)
add_subdirectory(metadata-extractor)
add_subdirectory(thumbnailer)
add_subdirectory(bin)
// libraries
#include <QString>
#include <QImage>
#include <QStandardPaths>
#include <QMimeType>
#include <QLoggingCategory>
#include <QUrl>
#include <QFile>
#include <QDir>
#include <QTemporaryFile>
#include <QStandardPaths>
#include <QCryptographicHash>
// local
#include "AppImageThumbnailCreator.h"
#include "InspectorInterface.h"
Q_LOGGING_CATEGORY(LOG_APPIMAGE_THUMBS, "AppImageThumbnailer")
extern "C"
{
Q_DECL_EXPORT ThumbCreator* new_creator() {
return new AppImageThumbnailCreator();
}
}
AppImageThumbnailCreator::AppImageThumbnailCreator(QObject* parent) : QObject(parent),
inspectorInterface(
new OrgAppimageServices1InspectorInterface(
"org.appimage.Services1.Inspector",
"/org/appimage/Services1/Inspector",
QDBusConnection::sessionBus(), this)) {
}
AppImageThumbnailCreator::~AppImageThumbnailCreator() = default;
ThumbCreator::Flags AppImageThumbnailCreator::flags() const {
return ThumbCreator::None;
}
bool AppImageThumbnailCreator::create(const QString& path, int w, int h, QImage& thumb) {
if (inspectorInterface->isValid()) {
QTemporaryFile temporaryFile;
if (temporaryFile.open()) {
auto reply = inspectorInterface->extractFile(path, ".DirIcon", temporaryFile.fileName());
reply.waitForFinished();
if (reply.isError()) {
return false;
} else {
bool res = thumb.load(temporaryFile.fileName());
thumb = thumb.scaled(w, h);
return res;
}
} else {
return false;
}
} else {
qCDebug(LOG_APPIMAGE_THUMBS) << "Unable to connect to appimage services dbus interface";
return false;
}
}
bool AppImageThumbnailCreator::isAnAcceptedMimeType(const QString& path) const {
QMimeType type = db.mimeTypeForFile(path);
return type.isValid() &&
(type.inherits("application/x-iso9660-appimage") || type.inherits("application/vnd.appimage"));
}
#pragma once
// libraries
#include <QObject>
#include <QMimeDatabase>
#include <QLoggingCategory>
#include <kio/thumbcreator.h>
Q_DECLARE_LOGGING_CATEGORY(LOG_APPIMAGE_THUMBS)
class OrgAppimageServices1InspectorInterface;
class AppImageThumbnailCreator : public QObject, public ThumbCreator {
Q_OBJECT
QMimeDatabase db;
public:
explicit AppImageThumbnailCreator(QObject* parent = 0);
~AppImageThumbnailCreator() override;
bool create(const QString& path, int w, int h, QImage& thumb) override;
Flags flags() const override;
bool isAnAcceptedMimeType(const QString& path) const;
private:
OrgAppimageServices1InspectorInterface *inspectorInterface;
};
add_library(appimage-thumbnailer MODULE AppImageThumbnailCreator.cpp)
target_link_libraries(appimage-thumbnailer PRIVATE KF5::KIOWidgets appimageservices-interfaces)
install(TARGETS appimage-thumbnailer DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES org.appimage.appimage-thumbnailer.desktop DESTINATION ${SERVICES_INSTALL_DIR})
[Desktop Entry]
Encoding=UTF-8
Type=Service
Name=AppImage
ServiceTypes=ThumbCreator
MimeType=application/x-iso9660-appimage;application/vnd.appimage;
CacheThumbnail=true
X-KDE-Library=appimage-thumbnailer
ThumbnailerVersion=6
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment