mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
moved logic for QML plugins from Plugins to QmlPluginLoader
This commit is contained in:
parent
30cc7a8b89
commit
f9ac0727c5
|
@ -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
|
||||
|
|
|
@ -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<QmlPluginInterface*>(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<PluginInterface*>(plugin->qmlComponentInstance);
|
||||
plugin->qmlPluginLoader->setName(plugin->pluginSpec.name);
|
||||
plugin->instance = qobject_cast<PluginInterface*>(plugin->qmlPluginLoader->instance());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
49
src/lib/plugins/qml/qmlpluginloader.cpp
Normal file
49
src/lib/plugins/qml/qmlpluginloader.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#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<QmlPluginInterface*>(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;
|
||||
}
|
39
src/lib/plugins/qml/qmlpluginloader.h
Normal file
39
src/lib/plugins/qml/qmlpluginloader.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef QMLPLUGINLOADER_H
|
||||
#define QMLPLUGINLOADER_H
|
||||
|
||||
#include <QQmlEngine>
|
||||
#include <QQmlComponent>
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user