Commit a3710013 authored by Richard Liebscher's avatar Richard Liebscher

Support only static plugins and some fixes

parent 3692ad3a
Pipeline #14076 failed with stage
in 8 minutes and 4 seconds
......@@ -22,7 +22,9 @@ include(ECMSetupVersion)
include(ECMInstallIcons)
include(FeatureSummary)
include(GenerateExportHeader)
include(ECMQMLModules)
if (NOT SAILFISHOS)
include(ECMQMLModules)
endif()
include(KDEConnectMacros.cmake)
......
......@@ -2,7 +2,25 @@
# Redistribution and use is allowed according to the terms of the BSD license.
# Thoroughly inspired in kdevplatform_add_plugin
function(kdeconnect_add_plugin)
kcoreaddons_add_plugin(${ARGN} INSTALL_NAMESPACE kdeconnect)
endfunction()
if (SAILFISHOS)
function(kdeconnect_add_plugin plugin)
set(options)
set(oneValueArgs JSON)
set(multiValueArgs SOURCES)
cmake_parse_arguments(KC_ADD_PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT KC_ADD_PLUGIN_SOURCES)
message(FATAL_ERROR "kdeconnect_add_plugin called without SOURCES parameter")
endif()
get_filename_component(json "${KC_ADD_PLUGIN_JSON}" REALPATH)
add_library(${plugin} STATIC ${KC_ADD_PLUGIN_SOURCES})
set_property(TARGET ${plugin} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS ${json})
set_property(TARGET ${plugin} APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
endfunction()
else()
# Thoroughly inspired in kdevplatform_add_plugin
function(kdeconnect_add_plugin)
kcoreaddons_add_plugin(${ARGN} INSTALL_NAMESPACE kdeconnect)
endfunction()
endif()
......@@ -25,6 +25,7 @@
#include <KPluginMetaData>
#include <KPluginLoader>
#include <KPluginFactory>
#include <QStaticPlugin>
#include "core_debug.h"
#include "device.h"
......@@ -42,69 +43,56 @@ PluginLoader* PluginLoader::instance()
PluginLoader::PluginLoader()
{
#ifdef SAILFISHOS
QString pluginDir = QStringLiteral("/usr/share/harbour-sailfishconnect/lib/kdeconnect/");
const QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins();
for (auto& staticPlugin : staticPlugins) {
QJsonObject jsonMetadata = staticPlugin.metaData().value(QStringLiteral("MetaData")).toObject();
KPluginMetaData metadata(jsonMetadata, QString());
if (metadata.serviceTypes().contains(QStringLiteral("KdeConnect/Plugin"))) {
plugins.insert(metadata.pluginId(), metadata);
pluginsFactories.insert(
metadata.pluginId(),
qobject_cast<KPluginFactory*>(staticPlugin.instance()));
}
}
#else
QString pluginDir = QStringLiteral("kdeconnect/");
#endif
const QVector<KPluginMetaData> data = KPluginLoader::findPlugins(pluginDir);
const QVector<KPluginMetaData> data = KPluginLoader::findPlugins(QStringLiteral("kdeconnect/"));
for (const KPluginMetaData& metadata : data) {
plugins[metadata.pluginId()] = metadata;
}
qDebug() << pluginDir << plugins.keys();
const QVector<QStaticPlugin> staticPlugs = QPluginLoader::staticPlugins();
for (auto& staticPlugin : staticPlugs) {
KPluginMetaData metadata(staticPlugin.metaData(), QString());
if (metadata.serviceTypes().contains(QStringLiteral("KdeConnect/Plugin"))) {
staticPlugins.insert(metadata.pluginId(), std::make_tuple(metadata, staticPlugin));
}
}
#endif
}
QStringList PluginLoader::getPluginList() const
{
return plugins.keys() + staticPlugins.keys();
return plugins.keys();
}
KPluginMetaData PluginLoader::getPluginInfo(const QString& name) const
{
KPluginMetaData ret = std::get<0>(staticPlugins.value(name));
if (ret.isValid()) {
return ret;
}
return plugins.value(name);
}
KdeConnectPlugin* PluginLoader::instantiatePluginForDevice(const QString& pluginName, Device* device) const
{
KdeConnectPlugin* ret = nullptr;
KPluginFactory* factory = nullptr;
KPluginMetaData service;
auto staticPlugin = staticPlugins.value(pluginName);
if (std::get<0>(staticPlugin).isValid()) {
service = std::get<0>(staticPlugin);
factory = qobject_cast<KPluginFactory*>(std::get<1>(staticPlugin).instance());
Q_ASSERT(factory != nullptr);
} else {
service = plugins.value(pluginName);
if (!service.isValid()) {
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << pluginName;
return ret;
}
KPluginLoader loader(service.fileName());
factory = loader.factory();
if (!factory) {
qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service.pluginId() << loader.errorString();
return ret;
}
KPluginMetaData service = plugins.value(pluginName);
if (!service.isValid()) {
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << pluginName;
return ret;
}
#ifdef SAILFISHOS
KPluginFactory* factory = pluginsFactories.value(pluginName);
#else
KPluginLoader loader(service.fileName());
KPluginFactory* factory = loader.factory();
if (!factory) {
qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service.pluginId() << loader.errorString();
return ret;
}
#endif
const QStringList outgoingInterfaces = KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-OutgoingPacketType"));
QVariant deviceVariant = QVariant::fromValue<Device*>(device);
......
......@@ -24,7 +24,6 @@
#include <QObject>
#include <QHash>
#include <QString>
#include <QStaticPlugin>
#include <KPluginMetaData>
......@@ -32,6 +31,7 @@
class Device;
class KdeConnectPlugin;
class KPluginFactory;
class KDECONNECTCORE_EXPORT PluginLoader
{
......@@ -51,7 +51,9 @@ private:
PluginLoader();
QHash<QString, KPluginMetaData> plugins;
QHash<QString, std::tuple<KPluginMetaData, QStaticPlugin>> staticPlugins;
#ifdef SAILFISHOS
QHash<QString, KPluginFactory*> pluginsFactories;
#endif
};
#endif
......@@ -39,7 +39,7 @@ geninterface(${PROJECT_SOURCE_DIR}/plugins/sms/conversationsdbusinterface.h conv
geninterface(${PROJECT_SOURCE_DIR}/plugins/share/shareplugin.h shareinterface)
geninterface(${PROJECT_SOURCE_DIR}/plugins/remotesystemvolume/remotesystemvolumeplugin.h remotesystemvolumeinterface)
add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC})
add_library(kdeconnectinterfaces ${libkdeconnect_SRC})
set_target_properties(kdeconnectinterfaces PROPERTIES
VERSION ${KDECONNECT_VERSION}
SOVERSION ${KDECONNECT_VERSION_MAJOR}
......
......@@ -3,17 +3,19 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kdeconnect-plugins\")
install(FILES kdeconnect_plugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR})
add_subdirectory(ping)
add_subdirectory(battery)
add_subdirectory(remotecommands)
add_subdirectory(remotecontrol)
add_subdirectory(remotesystemvolume)
add_subdirectory(clipboard)
add_subdirectory(presenter)
if(NOT SAILFISHOS)
add_subdirectory(battery)
add_subdirectory(sendnotifications)
add_subdirectory(mpriscontrol)
add_subdirectory(photo)
add_subdirectory(remotecommands)
add_subdirectory(mprisremote)
add_subdirectory(remotecontrol)
add_subdirectory(lockdevice)
add_subdirectory(remotesystemvolume)
add_subdirectory(clipboard)
add_subdirectory(contacts)
add_subdirectory(share)
add_subdirectory(remotekeyboard)
......@@ -23,7 +25,6 @@ if(NOT SAILFISHOS)
add_subdirectory(mousepad)
add_subdirectory(sms)
add_subdirectory(runcommand)
add_subdirectory(presenter)
add_subdirectory(screensaver-inhibit)
if(NOT APPLE)
......
......@@ -34,7 +34,7 @@
K_PLUGIN_CLASS_WITH_JSON(RemoteSystemVolumePlugin, "kdeconnect_remotesystemvolume.json")
Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PING, "kdeconnect.plugin.remotesystemvolume")
Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_REMOTESYSTEMVOLUME, "kdeconnect.plugin.remotesystemvolume")
RemoteSystemVolumePlugin::RemoteSystemVolumePlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
......
......@@ -10,18 +10,19 @@ target_link_libraries(kdeconnect_runcommand
KF5::I18n)
#----------------------
if(NOT SAILFISHOS)
set( kdeconnect_runcommand_config_SRCS runcommand_config.cpp )
set( kdeconnect_runcommand_config_SRCS runcommand_config.cpp )
add_library(kdeconnect_runcommand_config MODULE ${kdeconnect_runcommand_config_SRCS} )
target_link_libraries( kdeconnect_runcommand_config
kdeconnectcore
kdeconnectpluginkcm
KF5::I18n
KF5::CoreAddons
KF5::ConfigWidgets
add_library(kdeconnect_runcommand_config MODULE ${kdeconnect_runcommand_config_SRCS} )
target_link_libraries( kdeconnect_runcommand_config
kdeconnectcore
kdeconnectpluginkcm
KF5::I18n
KF5::CoreAddons
KF5::ConfigWidgets
)
)
install(TARGETS kdeconnect_runcommand_config DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_runcommand_config.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install(TARGETS kdeconnect_runcommand_config DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_runcommand_config.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
endif()
Markdown is supported
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