Verified Commit 6261b87f authored by azubieta's avatar azubieta
Browse files

Add metadata-extractor

parent 1ebb67a8
...@@ -14,7 +14,7 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Widgets Netwo ...@@ -14,7 +14,7 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Widgets Netwo
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS XmlGui I18n KIO TextWidgets Notifications) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS XmlGui I18n KIO TextWidgets Notifications FileMetaData)
include(KDEInstallDirs) include(KDEInstallDirs)
include(KDECMakeSettings) include(KDECMakeSettings)
......
add_subdirectory(appimageservices-interface) add_subdirectory(appimageservices-interface)
add_subdirectory(fileitem-actions) add_subdirectory(fileitem-actions)
add_subdirectory(metadata-extractor)
add_subdirectory(bin) add_subdirectory(bin)
...@@ -2,14 +2,16 @@ set_source_files_properties( ...@@ -2,14 +2,16 @@ set_source_files_properties(
org.appimage.Services.Launcher.xml org.appimage.Services.Launcher.xml
org.appimage.Services.Updater.xml org.appimage.Services.Updater.xml
org.appimage.Services.Updater.Task.xml org.appimage.Services.Updater.Task.xml
org.appimage.Services.Inspector.xml
PROPERTIES NO_NAMESPACE ON PROPERTIES NO_NAMESPACE ON
) )
qt5_add_dbus_interface(appimageservices-interfaces-sources org.appimage.Services.Launcher.xml LauncherInterface) qt5_add_dbus_interface(appimageservices-interfaces-sources org.appimage.Services.Launcher.xml LauncherInterface)
qt5_add_dbus_interface(appimageservices-interfaces-sources org.appimage.Services.Updater.xml UpdaterInterface) qt5_add_dbus_interface(appimageservices-interfaces-sources org.appimage.Services.Updater.xml UpdaterInterface)
qt5_add_dbus_interface(appimageservices-interfaces-sources org.appimage.Services.Updater.Task.xml UpdaterTaskInterface) qt5_add_dbus_interface(appimageservices-interfaces-sources org.appimage.Services.Updater.Task.xml UpdaterTaskInterface)
qt5_add_dbus_interface(appimageservices-interfaces-sources org.appimage.Services.Inspector.xml InspectorInterface)
add_library(appimageservices-interfaces OBJECT ${appimageservices-interfaces-sources}) add_library(appimageservices-interfaces STATIC ${appimageservices-interfaces-sources})
target_link_libraries(appimageservices-interfaces PUBLIC Qt5::Core) target_link_libraries(appimageservices-interfaces PUBLIC Qt5::Core)
target_include_directories(appimageservices-interfaces PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(appimageservices-interfaces PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.appimage.Services1.Inspector">
<method name="getApplicationInfo">
<arg type="s" direction="out"/>
<arg name="appImagePath" type="s" direction="in"/>
</method>
<method name="listContents">
<arg type="as" direction="out"/>
<arg name="appImagePath" type="s" direction="in"/>
</method>
<method name="extractFile">
<arg type="b" direction="out"/>
<arg name="appImagePath" type="s" direction="in"/>
<arg name="source" type="s" direction="in"/>
<arg name="target" type="s" direction="in"/>
</method>
</interface>
</node>
// libraries
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonDocument>
#include <QDebug>
// local
#include "AppImageExtractor.h"
#include "InspectorInterface.h"
using namespace KFileMetaData;
AppImageExtractor::AppImageExtractor(QObject* parent)
: ExtractorPlugin(parent),
inspectorInterface(new OrgAppimageServices1InspectorInterface("org.appimage.Services1.Inspector",
"/org/appimage/Services1/Inspector",
QDBusConnection::sessionBus(), this)) {
if (!inspectorInterface->isValid())
qWarning() << "Unable to connect to the AppImage Updater Service";
}
QStringList AppImageExtractor::mimetypes() const {
return QStringList{
QStringLiteral("application/x-iso9660-appimage"),
QStringLiteral("application/vnd.appimage"),
};
}
void KFileMetaData::AppImageExtractor::extract(ExtractionResult* result) {
const auto appImageFilePath = result->inputUrl().toUtf8();
auto reply = inspectorInterface->getApplicationInfo(appImageFilePath);
reply.waitForFinished();
if (reply.isError())
qWarning() << "Unable to fetch AppImage information " << reply.error().message();
else {
QString response = reply.value();
QJsonDocument document = QJsonDocument::fromJson(response.toLocal8Bit());
QJsonObject root = document.object();
QJsonValue nameValue = root.value("name");
result->add(Property::Title, nameValue.toVariant());
QJsonValue summary = root.value("summary");
result->add(Property::Description, summary.toString());
QJsonValue license = root.value("license");
result->add(Property::License, license.toString());
QJsonValue links = root.value("links");
QJsonObject linksOjbect = links.toObject();;
for (const auto& link: linksOjbect.keys()) {
QJsonValue linkValue = linksOjbect.value(link);
result->add(Property::OriginUrl, linkValue.toString());
}
}
}
#pragma once
// libraries
#include <QObject>
#include <KFileMetaData/ExtractorPlugin>
class OrgAppimageServices1InspectorInterface;
namespace KFileMetaData {
class AppImageExtractor : public ExtractorPlugin {
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.kf5.kfilemetadata.ExtractorPlugin")
Q_INTERFACES(KFileMetaData::ExtractorPlugin)
public:
explicit AppImageExtractor(QObject* parent = nullptr);
public:
void extract(ExtractionResult* result) override;
QStringList mimetypes() const override;
private:
OrgAppimageServices1InspectorInterface * inspectorInterface;
};
}
add_library(kfilemetadata-appimageextractor MODULE AppImageExtractor.cpp)
target_link_libraries(kfilemetadata-appimageextractor
KF5::FileMetaData
KF5::ConfigCore
Qt5::Xml
Qt5::Gui
Qt5::DBus
appimageservices-interfaces
)
set_target_properties(kfilemetadata-appimageextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata")
install(TARGETS kfilemetadata-appimageextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata)
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