diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 713e6256c..09e55d617 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,79 +1,78 @@ find_package(Qt5Test ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE) set_package_properties(Qt5Test PROPERTIES PURPOSE "Required for tests") set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_KEYWORDS) include(ECMMarkAsTest) include(ECMAddTests) find_package(KF5CoreAddons REQUIRED) find_package(KF5XmlGui REQUIRED) find_package(Qt5Widgets REQUIRED) # add_definitions( -DKDESRCDIR=${CMAKE_CURRENT_SOURCE_DIR} ) if(KDE_PLATFORM_FEATURE_BINARY_COMPATIBLE_FEATURE_REDUCTION) - set(PLASMA_NO_PACKAGEKIT TRUE) set(PLASMA_NO_PACKAGE_EXTRADATA TRUE) endif() MACRO(PLASMA_UNIT_TESTS) FOREACH(_testname ${ARGN}) set(libs Qt5::Qml Qt5::Test KF5::Plasma KF5::PlasmaQuick KF5::Archive KF5::CoreAddons KF5::ConfigGui KF5::I18n KF5::KIOCore KF5::Service KF5::IconThemes KF5::Declarative) if(QT_QTOPENGL_FOUND) list(APPEND libs Qt5::OpenGL) endif() ecm_add_test(${_testname}.cpp LINK_LIBRARIES ${libs} NAME_PREFIX "plasma-") target_include_directories(${_testname} PRIVATE "$>;") ENDFOREACH(_testname) ENDMACRO(PLASMA_UNIT_TESTS) PLASMA_UNIT_TESTS( dialogqmltest dialogstatetest fallbackpackagetest packagestructuretest pluginloadertest framesvgtest iconitemtest themetest configmodeltest # plasmoidpackagetest ) set(storagetest_libs Qt5::Gui Qt5::Test Qt5::Sql KF5::KIOCore KF5::Plasma KF5::CoreAddons) if(QT_QTOPENGL_FOUND) list(APPEND storagetest_libs Qt5::OpenGL) endif() set(storagetest_srcs storagetest.cpp ../src/plasma/private/storage.cpp ../src/plasma/private/storagethread.cpp ../src/plasma/debug_p.cpp) ecm_add_test(${storagetest_srcs} TEST_NAME plasma-storagetest LINK_LIBRARIES ${storagetest_libs}) if(HAVE_X11) set(dialognativetest_srcs dialognativetest.cpp) ecm_add_test(${dialognativetest_srcs} TEST_NAME dialognativetest LINK_LIBRARIES Qt5::Gui Qt5::Test Qt5::Qml Qt5::Quick KF5::WindowSystem KF5::Plasma KF5::PlasmaQuick) endif() set(coronatest_srcs coronatest.cpp) qt5_add_resources(coronatest_srcs coronatestresources.qrc) ecm_add_test(${coronatest_srcs} TEST_NAME coronatest LINK_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Test KF5::KIOCore KF5::Plasma KF5::CoreAddons KF5::XmlGui) set(sortfiltermodeltest_srcs sortfiltermodeltest.cpp ../src/declarativeimports/core/datamodel.cpp ../src/declarativeimports/core/datasource.cpp ) ecm_add_test(${sortfiltermodeltest_srcs} TEST_NAME plasma-sortfiltermodeltest LINK_LIBRARIES KF5::Plasma Qt5::Gui Qt5::Test KF5::I18n KF5::Service Qt5::Qml) #Add a test that i18n is not used directly in any import. # It should /always/ be i18nd find_program(SH bash) if(SH) add_test(i18ndcheck ${SH} ${CMAKE_CURRENT_SOURCE_DIR}/i18ndcheck.sh ${CMAKE_SOURCE_DIR}/src/declarativeimports) endif() diff --git a/src/plasma/CMakeLists.txt b/src/plasma/CMakeLists.txt index b3a85551a..0ef686341 100644 --- a/src/plasma/CMakeLists.txt +++ b/src/plasma/CMakeLists.txt @@ -1,239 +1,228 @@ add_subdirectory(packagestructure) # This option should be removed, or moved down as far as possible. # That means porting the existing frameworks to the CMake automoc # feature. Porting is mostly removing explicit moc includes, and # leaving the ones which are truly needed (ie, if you remove # them, the build fails). set(CMAKE_AUTOMOC_RELAXED_MODE ON) if(KDE_PLATFORM_FEATURE_BINARY_COMPATIBLE_FEATURE_REDUCTION) - set(PLASMA_NO_PACKAGEKIT TRUE) set(PLASMA_NO_PACKAGE_EXTRADATA TRUE) endif() -if(NOT HAVE_X11) - set(PLASMA_NO_PACKAGEKIT TRUE) -endif() - #find_package(KdepimLibs 4.5.60) #find_package(Gpgme) #set_package_properties(KDEPIMLIBS PROPERTIES DESCRIPTION "KDE PIM libraries" # URL "http://www.kde.org" TYPE OPTIONAL # PURPOSE "Needed for building several Plasma DataEngines") -if(NOT PLASMA_NO_PACKAGEKIT) - add_definitions(-DPLASMA_ENABLE_PACKAGEKIT_SUPPORT=1) - set(PLASMA_EXTRA_LIBS ${PLASMA_EXTRA_LIBS} Qt5::DBus) -endif() - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-plasma.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-plasma.h) #FIXME: gpgme++ is in kdepimlibs, must move somewhere else! include_directories(${KDEPIMLIBS_INCLUDE_DIRS} ${GPGME_INCLUDES}) add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1209) ########### next target ############### set(Plasma_LIB_SRCS #global plasma.cpp pluginloader.cpp version.cpp - private/componentinstaller.cpp #applets,containments,corona applet.cpp containment.cpp containmentactions.cpp corona.cpp private/applet_p.cpp private/associatedapplicationmanager.cpp private/containment_p.cpp private/timetracker.cpp #Dataengines, services datacontainer.cpp dataengine.cpp dataengineconsumer.cpp service.cpp servicejob.cpp private/datacontainer_p.cpp private/dataenginemanager.cpp private/storage.cpp private/storagethread.cpp #packages package.cpp packagestructure.cpp #graphics framesvg.cpp svg.cpp theme.cpp private/theme_p.cpp #scripting scripting/appletscript.cpp scripting/dataenginescript.cpp scripting/scriptengine.cpp ) if(HAVE_X11) set(Plasma_LIB_SRCS ${Plasma_LIB_SRCS} private/effectwatcher.cpp) endif() kconfig_add_kcfg_files(Plasma_LIB_SRCS data/kconfigxt/libplasma-theme-global.kcfgc) #NEPOMUK_GENERATE_FROM_ONTOLOGY( # nwc.nrl # ${metadata_test_BINARY_DIR} # TEST_HEADERS # TEST_SOURCES # TEST_INCLUDES #) ecm_qt_declare_logging_category(Plasma_LIB_SRCS HEADER debug_p.h IDENTIFIER LOG_PLASMA CATEGORY_NAME org.kde.plasma) add_library(KF5Plasma ${Plasma_LIB_SRCS}) add_library(KF5::Plasma ALIAS KF5Plasma) if(HAVE_X11) set(PLASMA_EXTRA_LIBS ${PLASMA_EXTRA_LIBS} Qt5::X11Extras ${X11_LIBRARIES} XCB::XCB) endif() if(DL_LIBRARY) set(PLASMA_EXTRA_LIBS ${PLASMA_EXTRA_LIBS} ${DL_LIBRARY}) endif() target_link_libraries(KF5Plasma PUBLIC KF5::Service # For kplugininfo.h and kservice.h Qt5::Gui KF5::Package PRIVATE Qt5::Sql Qt5::Svg Qt5::DBus KF5::Archive KF5::GuiAddons #kimagecache KF5::I18n KF5::KIOCore #ServiceJob KF5::KIOWidgets #KRun KF5::WindowSystem #compositingActive KF5::Declarative #runtimePlatform KF5::XmlGui #KActionCollection KF5::GlobalAccel #Applet::setGlobalShortcut KF5::Notifications KF5::IconThemes ${PLASMA_EXTRA_LIBS} ) target_include_directories(KF5Plasma PUBLIC "$" ) target_include_directories(KF5Plasma INTERFACE "$" ) set_target_properties(KF5Plasma PROPERTIES VERSION ${PLASMA_VERSION_STRING} SOVERSION ${PLASMA_SOVERSION} EXPORT_NAME Plasma ) ########### install files ############### generate_export_header(KF5Plasma BASE_NAME Plasma EXPORT_FILE_NAME plasma/plasma_export.h) ecm_generate_headers(Plasma_CamelCase_HEADERS HEADER_NAMES Applet Containment ContainmentActions Corona DataContainer DataEngine DataEngineConsumer PluginLoader FrameSvg Package PackageStructure Service ServiceJob Svg Theme Plasma REQUIRED_HEADERS Plasma_HEADERS PREFIX Plasma ) set(Plasma_HEADERS ${Plasma_HEADERS} version.h ) set(PlasmaScripting_HEADERS scripting/appletscript.h scripting/dataenginescript.h scripting/scriptengine.h ) install(FILES ${Plasma_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/plasma/plasma_export.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/plasma COMPONENT Devel) install(FILES ${Plasma_CamelCase_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/Plasma COMPONENT Devel) install(FILES ${PlasmaScripting_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/plasma/scripting COMPONENT Devel) install(FILES data/servicetypes/plasma-applet.desktop data/servicetypes/plasma-containment.desktop data/servicetypes/plasma-containmentactions.desktop data/servicetypes/plasma-dataengine.desktop data/servicetypes/plasma-generic.desktop data/servicetypes/plasma-packagestructure.desktop data/servicetypes/plasma-scriptengine.desktop data/servicetypes/plasma-service.desktop data/servicetypes/plasma-shell.desktop data/servicetypes/plasma-lookandfeel.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR}) install(FILES data/operations/dataengineservice.operations DESTINATION ${PLASMA_DATA_INSTALL_DIR}/services) install(FILES data/operations/plasmoidservice.operations DESTINATION ${PLASMA_DATA_INSTALL_DIR}/services) install(FILES data/operations/storage.operations DESTINATION ${PLASMA_DATA_INSTALL_DIR}/services) install(TARGETS KF5Plasma EXPORT KF5PlasmaTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) if(BUILD_QCH) ecm_add_qch( KF5Plasma_QCH NAME Plasma BASE_NAME KF5Plasma VERSION ${KF5_VERSION} ORG_DOMAIN org.kde SOURCES # using only public headers, to cover only public API ${Plasma_HEADERS} ${PlasmaScripting_HEADERS} Mainpage.dox MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" LINK_QCHS Qt5Gui_QCH KF5Service_QCH KF5Package_QCH BLANK_MACROS PLASMA_EXPORT PLASMA_DEPRECATED PLASMA_DEPRECATED_EXPORT TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} COMPONENT Devel ) endif() diff --git a/src/plasma/private/componentinstaller.cpp b/src/plasma/private/componentinstaller.cpp deleted file mode 100644 index 143685c5f..000000000 --- a/src/plasma/private/componentinstaller.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2011 Kevin Kofler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "private/componentinstaller_p.h" - -#include -#include -#include -#include -#include -#include - -namespace Plasma -{ - -class ComponentInstallerPrivate -{ -public: -#ifdef PLASMA_ENABLE_PACKAGEKIT_SUPPORT - QSet alreadyPrompted; -#endif -}; - -class ComponentInstallerSingleton -{ -public: - ComponentInstaller self; -}; - -Q_GLOBAL_STATIC(ComponentInstallerSingleton, privateComponentInstallerSelf) - -ComponentInstaller *ComponentInstaller::self() -{ - return &privateComponentInstallerSelf()->self; -} - -ComponentInstaller::ComponentInstaller() - : d(new ComponentInstallerPrivate) -{ -} - -ComponentInstaller::~ComponentInstaller() -{ - delete d; -} - -void ComponentInstaller::installMissingComponent(const QString &type, - const QString &name, - QWidget *parent, bool force) -{ -#ifdef PLASMA_ENABLE_PACKAGEKIT_SUPPORT - QString searchString = type + QLatin1Char('-') + name; - - if (!force) { - if (d->alreadyPrompted.contains(searchString)) { - return; - } - } - - d->alreadyPrompted.insert(searchString); - - QDBusInterface packageKit(QStringLiteral("org.freedesktop.PackageKit"), - QStringLiteral("/org/freedesktop/PackageKit"), - QStringLiteral("org.freedesktop.PackageKit.Modify")); - // We don't check packageKit.isValid() because the service is activated on - // demand, so it will show up as "not valid". - WId wid = 0; - if (parent) { - wid = parent->winId(); - } - QStringList resources; - resources.append(searchString); - packageKit.asyncCall(QStringLiteral("InstallResources"), (unsigned int) wid, - QLatin1String("plasma-service"), resources, QString()); -#else - Q_UNUSED(type); - Q_UNUSED(name); - Q_UNUSED(parent); - Q_UNUSED(force); -#endif -} - -} // namespace Plasma diff --git a/src/plasma/private/componentinstaller_p.h b/src/plasma/private/componentinstaller_p.h deleted file mode 100644 index 3e30e2a19..000000000 --- a/src/plasma/private/componentinstaller_p.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2011 Kevin Kofler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_COMPONENTINSTALLER_H -#define PLASMA_COMPONENTINSTALLER_H - -class QString; -class QWidget; - -namespace Plasma -{ - -class ComponentInstallerPrivate; - -/** - * @class ComponentInstaller plasma/private/componentinstaller_p.h - * - * @short This class provides a generic API for installation of components. - * - * @internal - * - * Plasma::ComponentInstaller allows searching for a missing data or script - * engine by name, and allowing the user to install the missing service. - * Currently, PackageKit is supported as the mechanism to install components, - * but more mechanisms could be supported in the future through the same API. - * - * @since 4.8 - */ -class ComponentInstaller -{ -public: - /** - * Singleton pattern accessor. - */ - static ComponentInstaller *self(); - - /** - * Installs a missing component asynchronously. - * - * By default, this method will cache requested components and not - * prompt again for the same engine in the same session. The force - * parameter can be used to disable this mechanism, e.g. when the user - * just installed a new widget written in a scripting language, and so - * is likely to want the script engine installed after all. - * - * In the case of on-demand installation, this will unfortunately not - * allow the call which triggered the missing component lookup to - * succeed, but we cannot afford to block all of Plasma until the - * mechanism is done installing the service. - * - * This function does nothing if PackageKit integration was disabled at - * compile time. - * - * @param type the type of the component, should be "scriptengine" or - * "dataengine" - * @param name the name of the component - * @param parent a parent widget, used to set the wid for PackageKit - * @param force whether to always prompt, even if recently prompted - */ - void installMissingComponent(const QString &type, const QString &name, - QWidget *parent = nullptr, bool force = false); - -private: - /** - * Default constructor. The singleton method self() is the - * preferred access mechanism. - */ - ComponentInstaller(); - ~ComponentInstaller(); - - ComponentInstallerPrivate *const d; - - friend class ComponentInstallerSingleton; -}; - -} // namespace Plasma - -#endif // multiple inclusion guard diff --git a/src/plasma/private/dataenginemanager.cpp b/src/plasma/private/dataenginemanager.cpp index b58cae538..7fabb19de 100644 --- a/src/plasma/private/dataenginemanager.cpp +++ b/src/plasma/private/dataenginemanager.cpp @@ -1,213 +1,209 @@ /* * Copyright 2006-2007 Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dataenginemanager_p.h" #include #include #include #include #include "datacontainer.h" #include "pluginloader.h" -#include "private/componentinstaller_p.h" #include "private/dataengine_p.h" #include "private/datacontainer_p.h" #include "scripting/scriptengine.h" #include "debug_p.h" namespace Plasma { class NullEngine : public DataEngine { public: explicit NullEngine(QObject *parent = nullptr) : DataEngine(KPluginInfo(), parent) { setValid(false); // ref() ourselves to ensure we never get deleted d->ref(); } }; class DataEngineManagerPrivate { public: DataEngineManagerPrivate() : nullEng(nullptr) {} ~DataEngineManagerPrivate() { foreach (Plasma::DataEngine *engine, engines) { delete engine; } engines.clear(); delete nullEng; } DataEngine *nullEngine() { if (!nullEng) { nullEng = new NullEngine; } return nullEng; } DataEngine::Dict engines; DataEngine *nullEng; }; class DataEngineManagerSingleton { public: DataEngineManager self; }; Q_GLOBAL_STATIC(DataEngineManagerSingleton, privateDataEngineManagerSelf) DataEngineManager *DataEngineManager::self() { return &privateDataEngineManagerSelf()->self; } DataEngineManager::DataEngineManager() : d(new DataEngineManagerPrivate) { //startTimer(30000); } DataEngineManager::~DataEngineManager() { delete d; } Plasma::DataEngine *DataEngineManager::engine(const QString &name) const { if (name.isEmpty()) { return d->nullEngine(); } Plasma::DataEngine::Dict::const_iterator it = d->engines.constFind(name); if (it != d->engines.constEnd()) { return *it; } return d->nullEngine(); } Plasma::DataEngine *DataEngineManager::loadEngine(const QString &name) { if (name.isEmpty()) { qCDebug(LOG_PLASMA) << "Asked an engine with empty name"; return d->nullEngine(); } Plasma::DataEngine::Dict::const_iterator it = d->engines.constFind(name); if (it != d->engines.constEnd()) { DataEngine *engine = *it; engine->d->ref(); return engine; } DataEngine *engine = PluginLoader::self()->loadDataEngine(name); if (!engine) { qCDebug(LOG_PLASMA) << "Can't find a dataengine named" << name; - // Try installing the engine. However, it's too late for this request. - ComponentInstaller::self()->installMissingComponent(QStringLiteral("dataengine"), name); - return d->nullEngine(); } d->engines[name] = engine; return engine; } void DataEngineManager::unloadEngine(const QString &name) { Plasma::DataEngine::Dict::iterator it = d->engines.find(name); if (it != d->engines.end()) { Plasma::DataEngine *engine = *it; engine->d->deref(); if (!engine->d->isUsed()) { d->engines.erase(it); delete engine; } } } void DataEngineManager::timerEvent(QTimerEvent *) { #ifndef NDEBUG QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QStringLiteral("/plasma_dataenginemanager_log"); QFile f(path); if (!f.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) { // qCDebug(LOG_PLASMA) << "failed to open" << path; return; } QTextStream out(&f); QHashIterator it(d->engines); out << "================================== " << QLocale().toString(QDateTime::currentDateTime()) << endl; while (it.hasNext()) { it.next(); DataEngine *engine = it.value(); out << "DataEngine: " << it.key() << ' ' << engine << endl; out << " Claimed # of sources: " << engine->sources().count() << endl; out << " Actual # of sources: " << engine->containerDict().count() << endl; out << endl << " Source Details" << endl; foreach (DataContainer *dc, engine->containerDict()) { out << " * " << dc->objectName() << endl; out << " Data count: " << dc->d->data.count() << endl; out << " Stored: " << dc->isStorageEnabled() << ' ' << endl; const int directs = dc->receivers(SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data))); if (directs > 0) { out << " Direction Connections: " << directs << ' ' << endl; } const int relays = dc->d->relays.count(); if (relays > 0) { out << " Relays: " << dc->d->relays.count() << endl; QString times; foreach (SignalRelay *relay, dc->d->relays) { times.append(QLatin1Char(' ') + QString::number(relay->m_interval)); } out << " Relay Timeouts: " << times << ' ' << endl; } } out << endl << "-----" << endl; } out << endl << endl; #endif // killTimer(event->timerId()); } } // namespace Plasma #include "moc_dataenginemanager_p.cpp" diff --git a/src/plasma/scripting/scriptengine.cpp b/src/plasma/scripting/scriptengine.cpp index e9147de8d..5a5f726c9 100644 --- a/src/plasma/scripting/scriptengine.cpp +++ b/src/plasma/scripting/scriptengine.cpp @@ -1,137 +1,136 @@ /* * Copyright 2007 by Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "scripting/scriptengine.h" #include #include #include "applet.h" #include "dataengine.h" #include "package.h" -#include "private/componentinstaller_p.h" #include "scripting/appletscript.h" #include "scripting/dataenginescript.h" #include "debug_p.h" namespace Plasma { ScriptEngine::ScriptEngine(QObject *parent) : QObject(parent), d(nullptr) { } ScriptEngine::~ScriptEngine() { // delete d; } bool ScriptEngine::init() { return true; } Package ScriptEngine::package() const { return Package(); } QString ScriptEngine::mainScript() const { return QString(); } QStringList knownLanguages(Types::ComponentTypes types) { QStringList languages; const QVector plugins = KPluginLoader::findPlugins(QStringLiteral("plasma/scriptengines")); foreach (const auto &plugin, plugins) { const QStringList componentTypes = KPluginMetaData::readStringList(plugins.first().rawData(), QStringLiteral("X-Plasma-ComponentTypes")); if (((types & Types::AppletComponent) && componentTypes.contains(QStringLiteral("Applet"))) ||((types & Types::DataEngineComponent) && componentTypes.contains(QStringLiteral("DataEngine")))) { languages << plugin.value(QStringLiteral("X-Plasma-API")); } } return languages; } ScriptEngine *loadEngine(const QString &language, Types::ComponentType type, QObject *parent, const QVariantList &args = QVariantList()) { Q_UNUSED(parent); ScriptEngine *engine = nullptr; auto filter = [&language](const KPluginMetaData &md) -> bool { return md.value(QStringLiteral("X-Plasma-API")) == language; }; QVector plugins = KPluginLoader::findPlugins(QStringLiteral("plasma/scriptengines"), filter); if (!plugins.isEmpty()) { const QStringList componentTypes = KPluginMetaData::readStringList(plugins.first().rawData(), QStringLiteral("X-Plasma-ComponentTypes")); if (((type & Types::AppletComponent) && !componentTypes.contains(QStringLiteral("Applet"))) || ((type & Types::DataEngineComponent) && !componentTypes.contains(QStringLiteral("DataEngine")))) { qCWarning(LOG_PLASMA) << "ScriptEngine" << plugins.first().name() << "does not provide Applet or DataEngine components, returning empty."; return nullptr; } KPluginLoader loader(plugins.first().fileName()); KPluginFactory *factory = loader.factory(); if (factory) { engine = factory->create(nullptr, args); } else { qCWarning(LOG_PLASMA) << "Unable to load" << plugins.first().name() << "ScriptEngine"; } } return engine; } AppletScript *loadScriptEngine(const QString &language, Applet *applet, const QVariantList &args) { AppletScript *engine = static_cast(loadEngine(language, Types::AppletComponent, applet, args)); if (engine) { engine->setApplet(applet); } return engine; } DataEngineScript *loadScriptEngine(const QString &language, DataEngine *dataEngine, const QVariantList &args) { DataEngineScript *engine = static_cast(loadEngine(language, Types::DataEngineComponent, dataEngine, args)); if (engine) { engine->setDataEngine(dataEngine); } return engine; } } // namespace Plasma #include "moc_scriptengine.cpp"