Commit 7431ad73 authored by Alexander Lohnau's avatar Alexander Lohnau 💬 Committed by Albert Astals Cid
Browse files

Port plugins away from desktop file loading

parent fb74c580
......@@ -8,4 +8,5 @@ install( FILES
k3bprojectplugin.h
DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel )
# TODO KF6 remove
install( FILES k3bplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR})
......@@ -18,6 +18,7 @@
#include "k3b_export.h"
#include <KPluginFactory>
#include <KPluginMetaData>
#include <KPluginInfo>
#include <QObject>
......@@ -41,7 +42,8 @@ namespace K3b {
explicit Plugin( QObject* parent = 0 );
~Plugin() override;
KPluginInfo pluginInfo() const { return m_pluginInfo; }
KPluginInfo pluginInfo() const { return KPluginInfo::fromMetaData(d->metadata); }
KPluginMetaData pluginMetaData() const { return d->metadata; }
/**
* Version of the plugin system this plugin was written for.
......@@ -56,7 +58,10 @@ namespace K3b {
virtual QString categoryName() const = 0;
private:
KPluginInfo m_pluginInfo;
struct Private {
KPluginMetaData metadata;
};
std::unique_ptr<Private> d=std::unique_ptr<Private>(new Private());
};
}
......
......@@ -23,6 +23,8 @@
#include <KPluginInfo>
#include <KService>
#include <KServiceTypeTrader>
#include <KPluginLoader>
#include <KPluginMetaData>
#include <KMessageBox>
#include <QDebug>
......@@ -40,17 +42,12 @@
class K3b::PluginManager::Private
{
public:
Private( K3b::PluginManager* parent )
: m_parent( parent ) {
Private(){
}
QList<K3b::Plugin*> plugins;
void loadPlugin( const KService::Ptr &service );
KCModuleProxy* getModuleProxy( Plugin* plugin ) const;
private:
K3b::PluginManager* m_parent;
};
......@@ -58,7 +55,7 @@ private:
K3b::PluginManager::PluginManager( QObject* parent )
: QObject( parent ),
d( new Private( this ) )
d( new Private() )
{
}
......@@ -94,46 +91,6 @@ QList<K3b::Plugin*> K3b::PluginManager::plugins( const QString& group ) const
return fl;
}
void K3b::PluginManager::Private::loadPlugin( const KService::Ptr &service )
{
qDebug() << service->name() << service->library();
QString err;
K3b::Plugin* plugin = service->createInstance<K3b::Plugin>( 0, m_parent, QVariantList(), &err );
if ( plugin ) {
qDebug() << "Loaded plugin" << service->name();
// FIXME: improve this versioning stuff
if( plugin->pluginSystemVersion() != K3B_PLUGIN_SYSTEM_VERSION ) {
delete plugin;
qDebug() << "plugin system does not fit";
}
else {
plugin->m_pluginInfo = KPluginInfo( service );
plugins.append( plugin );
}
}
else {
qDebug() << "Loading plugin" << service->name() << "failed. Error:" << err;
}
// // make sure to only use the latest version of one plugin
// bool addPlugin = true;
// for( Q3PtrListIterator<K3b::Plugin> it( d->plugins ); *it; ++it ) {
// if( it.current()->pluginInfo().name() == plugin->pluginInfo().name() ) {
// if( K3b::Version(it.current()->pluginInfo().version()) < K3b::Version(plugin->pluginInfo().version()) ) {
// K3b::Plugin* p = it.current();
// d->plugins.removeRef( p );
// delete p;
// }
// else {
// addPlugin = false;
// }
// break;
// }
}
KCModuleProxy* K3b::PluginManager::Private::getModuleProxy( Plugin* plugin ) const
{
foreach( const KService::Ptr& service, plugin->pluginInfo().kcmServices() ) {
......@@ -153,10 +110,17 @@ KCModuleProxy* K3b::PluginManager::Private::getModuleProxy( Plugin* plugin ) con
void K3b::PluginManager::loadAll()
{
qDebug();
KService::List services = KServiceTypeTrader::self()->query( "K3b/Plugin" );
Q_FOREACH( const KService::Ptr &service, services ) {
d->loadPlugin( service );
const QVector<KPluginMetaData> metadataList = KPluginLoader::findPlugins("k3b_plugins");
for (const auto &metadata : metadataList) {
KPluginLoader loader(metadata.fileName());
KPluginFactory *factory = loader.factory();
if (auto *plugin = factory->create<K3b::Plugin>()) {
plugin->d->metadata = metadata;
qDebug() << "Loaded plugin" << metadata.metaDataFileName();
d->plugins.append(plugin);
} else {
qDebug() << "failed to load plugin" << metadata.metaDataFileName();
}
}
}
......
add_library(k3bffmpegdecoder MODULE k3bffmpegdecoder.cpp k3bffmpegwrapper.cpp)
kcoreaddons_add_plugin(k3bffmpegdecoder SOURCES k3bffmpegdecoder.cpp k3bffmpegwrapper.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3bffmpegdecoder "k3bffmpegdecoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
if(FFMPEG_INCLUDE_DIR_OLD_STYLE)
message(STATUS "didn't find new ffmpegcodecpath")
......@@ -10,7 +11,3 @@ else()
endif()
target_link_libraries(k3bffmpegdecoder k3bdevice k3blib KF5::I18n ${FFMPEG_LIBRARIES})
install(TARGETS k3bffmpegdecoder DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES k3bffmpegdecoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -37,7 +37,7 @@ extern "C" {
#include <math.h>
K3B_EXPORT_PLUGIN(k3bffmpegdecoder, K3bFFMpegDecoderFactory)
K_PLUGIN_CLASS_WITH_JSON(K3bFFMpegDecoderFactory, "k3bffmpegdecoder.json")
K3bFFMpegDecoderFactory::K3bFFMpegDecoderFactory( QObject* parent, const QVariantList& )
: K3b::AudioDecoderFactory( parent )
......
......@@ -15,7 +15,8 @@ endif()
configure_file(config-flac.h.cmake config-flac.h )
add_library(k3bflacdecoder MODULE k3bflacdecoder.cpp)
kcoreaddons_add_plugin(k3bflacdecoder SOURCES k3bflacdecoder.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3bflacdecoder "k3bflacdecoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_include_directories(k3bflacdecoder PRIVATE ${FLAC++_INCLUDE_DIR} ${FLAC_INCLUDE_DIR} ${TAGLIB_INCLUDES})
......@@ -24,7 +25,3 @@ target_link_libraries(k3bflacdecoder k3bdevice k3blib KF5::I18n ${FLAC++_LIBRARI
if(ENABLE_TAGLIB)
target_link_libraries(k3bflacdecoder ${TAGLIB_LIBRARIES})
endif()
install(TARGETS k3bflacdecoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES k3bflacdecoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -21,12 +21,13 @@
#include <QFile>
#include <QStringList>
#include <kpluginfactory.h>
#include <string.h>
#include <math.h>
#include <FLAC++/metadata.h>
#include <FLAC++/decoder.h>
K3B_EXPORT_PLUGIN(k3bflacdecoder, K3bFLACDecoderFactory)
K_PLUGIN_CLASS_WITH_JSON(K3bFLACDecoderFactory, "k3bflacdecoder.json")
#ifdef ENABLE_TAGLIB
#include <tag.h>
......
add_library(k3blibsndfiledecoder MODULE k3blibsndfiledecoder.cpp)
kcoreaddons_add_plugin(k3blibsndfiledecoder SOURCES k3blibsndfiledecoder.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3blibsndfiledecoder "k3blibsndfiledecoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_include_directories(k3blibsndfiledecoder PRIVATE ${SNDFILE_INCLUDE_DIR})
target_link_libraries(k3blibsndfiledecoder k3bdevice k3blib KF5::I18n ${SNDFILE_LIBRARIES})
install(TARGETS k3blibsndfiledecoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES k3blibsndfiledecoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -26,7 +26,7 @@
#include <stdio.h>
#include <sndfile.h>
K3B_EXPORT_PLUGIN(k3blibsndfiledecoder, K3bLibsndfileDecoderFactory)
K_PLUGIN_CLASS_WITH_JSON(K3bLibsndfileDecoderFactory, "k3blibsndfiledecoder.json")
class K3bLibsndfileDecoder::Private
{
......
add_library(k3bmaddecoder MODULE k3bmad.cpp k3bmaddecoder.cpp)
kcoreaddons_add_plugin(k3bmaddecoder SOURCES k3bmad.cpp k3bmaddecoder.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3bmaddecoder "k3bmaddecoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_include_directories(k3bmaddecoder PRIVATE ${MAD_INCLUDE_DIR} ${TAGLIB_INCLUDES})
......@@ -7,7 +8,3 @@ target_link_libraries(k3bmaddecoder k3bdevice k3blib KF5::I18n ${MAD_LIBRARIES})
if(ENABLE_TAGLIB)
target_link_libraries(k3bmaddecoder ${TAGLIB_LIBRARIES})
endif()
install(TARGETS k3bmaddecoder DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES k3bmaddecoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -44,8 +44,7 @@
#endif
K3B_EXPORT_PLUGIN(k3bmaddecoder, K3bMadDecoderFactory)
K_PLUGIN_CLASS_WITH_JSON(K3bMadDecoderFactory, "k3bmaddecoder.json")
int K3bMadDecoder::MaxAllowedRecoverableErrors = 10;
......
configure_file(k3bmpc_config.h.cmake k3bmpc_config.h)
add_library(k3bmpcdecoder MODULE k3bmpcdecoder.cpp k3bmpcwrapper.cpp)
kcoreaddons_add_plugin(k3bmpcdecoder SOURCES k3bmpcdecoder.cpp k3bmpcwrapper.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3bmpcdecoder "k3bmpcdecoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_include_directories(k3bmpcdecoder PRIVATE ${MUSE_INCLUDE_DIR})
target_link_libraries(k3bmpcdecoder k3bdevice k3blib KF5::I18n ${MUSE_LIBRARIES})
install(TARGETS k3bmpcdecoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES k3bmpcdecoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -19,7 +19,7 @@
#include <config-k3b.h>
K3B_EXPORT_PLUGIN(k3bmpcdecoder, K3bMpcDecoderFactory)
K_PLUGIN_CLASS_WITH_JSON(K3bMpcDecoderFactory, "k3bmpcdecoder.json")
K3bMpcDecoderFactory::K3bMpcDecoderFactory( QObject* parent, const QVariantList& )
: K3b::AudioDecoderFactory( parent )
......
add_library(k3boggvorbisdecoder MODULE k3boggvorbisdecoder.cpp)
kcoreaddons_add_plugin(k3boggvorbisdecoder SOURCES k3boggvorbisdecoder.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3boggvorbisdecoder "k3boggvorbisdecoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_link_libraries(k3boggvorbisdecoder k3bdevice k3blib KF5::I18n ${OGGVORBIS_LIBRARIES})
install(TARGETS k3boggvorbisdecoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES k3boggvorbisdecoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -26,7 +26,7 @@
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
K3B_EXPORT_PLUGIN(k3boggvorbisdecoder, K3bOggVorbisDecoderFactory)
K_PLUGIN_CLASS_WITH_JSON(K3bOggVorbisDecoderFactory, "k3boggvorbisdecoder.json")
class K3bOggVorbisDecoder::Private
{
......
add_library(k3bwavedecoder MODULE k3bwavedecoder.cpp)
kcoreaddons_add_plugin(k3bwavedecoder SOURCES k3bwavedecoder.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3bwavedecoder "k3bwavedecoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_link_libraries(k3bwavedecoder k3bdevice k3blib KF5::I18n)
install(TARGETS k3bwavedecoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES k3bwavedecoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -21,7 +21,7 @@
#include <QFile>
K3B_EXPORT_PLUGIN(k3bwavedecoder, K3bWaveDecoderFactory)
K_PLUGIN_CLASS_WITH_JSON(K3bWaveDecoderFactory, "k3bwavedecoder.json")
static unsigned short le_a_to_u_short( unsigned char* a ) {
return ((unsigned short)
......
add_library(k3bexternalencoder MODULE
k3bexternalencoder.cpp
k3bexternalencodercommand.cpp
)
kcoreaddons_add_plugin(k3bexternalencoder SOURCES k3bexternalencoder.cpp k3bexternalencodercommand.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3bexternalencoder "k3bexternalencoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_link_libraries(k3bexternalencoder
k3bdevice
......@@ -26,6 +24,6 @@ target_link_libraries(kcm_k3bexternalencoder
KF5::I18n
)
install(TARGETS k3bexternalencoder kcm_k3bexternalencoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(TARGETS kcm_k3bexternalencoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES k3bexternalencoder.desktop kcm_k3bexternalencoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES kcm_k3bexternalencoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -32,7 +32,8 @@
#include <sys/types.h>
K3B_EXPORT_PLUGIN(k3bexternalencoder, K3bExternalEncoder)
K_PLUGIN_CLASS_WITH_JSON(K3bExternalEncoder, "k3bexternalencoder.json")
Q_DECLARE_METATYPE( QProcess::ExitStatus )
......
add_library(k3blameencoder MODULE k3blameencoder.cpp)
kcoreaddons_add_plugin(k3blameencoder SOURCES k3blameencoder.cpp INSTALL_NAMESPACE "k3b_plugins")
kcoreaddons_desktop_to_json(k3blameencoder "k3blameencoder.desktop" SERVICE_TYPES ${CMAKE_SOURCE_DIR}/libk3b/plugin/k3bplugin.desktop)
target_link_libraries(k3blameencoder
k3bdevice
......@@ -24,6 +25,6 @@ target_link_libraries(kcm_k3blameencoder
KF5::I18n
)
install(TARGETS k3blameencoder kcm_k3blameencoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(TARGETS kcm_k3blameencoder DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES k3blameencoder.desktop kcm_k3blameencoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES kcm_k3blameencoder.desktop DESTINATION ${SERVICES_INSTALL_DIR})
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