diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 694b9764a..f00ca1e78 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -154,6 +154,7 @@ set(SRCS ${SRCS} plugins/pluginproxy.cpp plugins/plugins.cpp plugins/speeddial.cpp + plugins/qml/qmlpluginloader.cpp plugins/qml/qmlplugins.cpp plugins/qml/qmlplugininterface.cpp popupwindow/popuplocationbar.cpp diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index c0c32afb0..bc2413624 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -391,13 +391,9 @@ Plugins::Plugin Plugins::loadQmlPlugin(const QString &name) plugin.type = Plugin::QmlPlugin; plugin.pluginId = QSL("qml:%1").arg(QFileInfo(name).fileName()); plugin.pluginSpec = createSpec(DesktopFile(fullPath + QSL("/metadata.desktop"))); - - QQmlEngine* engine = new QQmlEngine(); - QQmlComponent component(engine, QDir(fullPath).filePath(plugin.pluginSpec.entryPoint)); - plugin.qmlComponentInstance = qobject_cast(component.create()); - - if (!plugin.qmlComponentInstance) { - qWarning() << "Loading" << fullPath << "failed:" << component.errorString(); + plugin.qmlPluginLoader = new QmlPluginLoader(QDir(fullPath).filePath(plugin.pluginSpec.entryPoint)); + if (!plugin.qmlPluginLoader->instance()) { + qWarning() << "Loading" << fullPath << "failed:" << plugin.qmlPluginLoader->component()->errorString(); return Plugin(); } @@ -482,6 +478,6 @@ void Plugins::initQmlPlugin(Plugin *plugin) { Q_ASSERT(plugin->type == Plugin::QmlPlugin); - plugin->qmlComponentInstance->setName(plugin->pluginSpec.name); - plugin->instance = qobject_cast(plugin->qmlComponentInstance); + plugin->qmlPluginLoader->setName(plugin->pluginSpec.name); + plugin->instance = qobject_cast(plugin->qmlPluginLoader->instance()); } diff --git a/src/lib/plugins/plugins.h b/src/lib/plugins/plugins.h index a8c58caa4..999819918 100644 --- a/src/lib/plugins/plugins.h +++ b/src/lib/plugins/plugins.h @@ -24,12 +24,13 @@ #include "qzcommon.h" #include "plugininterface.h" -#include "qml/qmlplugininterface.h" +#include "qml/qmlpluginloader.h" class QLibrary; class QPluginLoader; class SpeedDial; +class QmlPluginLoader; struct PluginSpec { QString name; @@ -73,7 +74,7 @@ public: QPluginLoader *pluginLoader = nullptr; // QmlPlugin - QmlPluginInterface *qmlComponentInstance = nullptr; + QmlPluginLoader *qmlPluginLoader = nullptr; // Other QVariant data; diff --git a/src/lib/plugins/qml/qmlpluginloader.cpp b/src/lib/plugins/qml/qmlpluginloader.cpp new file mode 100644 index 000000000..6741b40b4 --- /dev/null +++ b/src/lib/plugins/qml/qmlpluginloader.cpp @@ -0,0 +1,49 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2018 Anmol Gautam +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, 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 General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "qmlpluginloader.h" + +QmlPluginLoader::QmlPluginLoader(const QString &path) +{ + m_engine = new QQmlEngine(); + m_component = new QQmlComponent(m_engine, path); + createComponent(); +} + +void QmlPluginLoader::createComponent() +{ + m_interface = qobject_cast(m_component->create()); +} + +void QmlPluginLoader::setName(const QString &name) +{ + if (!m_interface) { + return; + } + + m_interface->setName(name); +} + +QQmlComponent *QmlPluginLoader::component() const +{ + return m_component; +} + +QmlPluginInterface *QmlPluginLoader::instance() const +{ + return m_interface; +} diff --git a/src/lib/plugins/qml/qmlpluginloader.h b/src/lib/plugins/qml/qmlpluginloader.h new file mode 100644 index 000000000..9fd0a7015 --- /dev/null +++ b/src/lib/plugins/qml/qmlpluginloader.h @@ -0,0 +1,39 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2018 Anmol Gautam +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, 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 General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef QMLPLUGINLOADER_H +#define QMLPLUGINLOADER_H + +#include +#include + +#include "qmlplugininterface.h" + +class QmlPluginLoader +{ + QQmlEngine *m_engine; + QQmlComponent *m_component; + QmlPluginInterface *m_interface; +public: + QmlPluginLoader(const QString &path); + void createComponent(); + void setName(const QString &name); + QQmlComponent *component() const; + QmlPluginInterface *instance() const; +}; + +#endif // QMLPLUGINLOADER_H