diff --git a/src/lib/plugins/qml/qmlplugin.cpp b/src/lib/plugins/qml/qmlplugin.cpp index 3aeec86e..13e1b3a9 100644 --- a/src/lib/plugins/qml/qmlplugin.cpp +++ b/src/lib/plugins/qml/qmlplugin.cpp @@ -1,78 +1,78 @@ /* ============================================================ * 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 "qmlplugin.h" #include "qmlplugins.h" #include "qmlpluginloader.h" #include "datapaths.h" #include "desktopfile.h" #include #include QmlPlugin::QmlPlugin() { } Plugins::Plugin QmlPlugin::loadPlugin(const QString &name) { static bool qmlSupportLoaded = false; if (!qmlSupportLoaded) { QmlPlugins::registerQmlTypes(); qmlSupportLoaded = true; } QString fullPath; if (QFileInfo(name).isAbsolute()) { fullPath = name; } else { fullPath = DataPaths::locate(DataPaths::Plugins, QSL("qml/") + name); if (fullPath.isEmpty()) { qWarning() << "Plugin" << name << "not found"; return Plugins::Plugin(); } } Plugins::Plugin plugin; plugin.type = Plugins::Plugin::QmlPlugin; plugin.pluginId = QSL("qml:%1").arg(QFileInfo(name).fileName()); DesktopFile desktopFile(fullPath + QSL("/metadata.desktop")); plugin.pluginSpec = Plugins::createSpec(desktopFile); QString entryPoint = desktopFile.value(QSL("X-Falkon-EntryPoint")).toString(); plugin.data = QVariant::fromValue(new QmlPluginLoader(plugin.pluginSpec.name, fullPath, entryPoint)); return plugin; } void QmlPlugin::initPlugin(Plugins::Plugin *plugin) { Q_ASSERT(plugin->type == Plugins::Plugin::QmlPlugin); const QString name = plugin->pluginSpec.name; auto qmlPluginLoader = plugin->data.value(); if (!qmlPluginLoader) { qWarning() << "Failed to cast from data"; return; } qmlPluginLoader->createComponent(); if (!qmlPluginLoader->instance()) { - qWarning().noquote() << "Falied to create component for" << name << "plugin:" << qmlPluginLoader->component()->errorString(); + qWarning().noquote() << "Failed to create component for" << name << "plugin:" << qmlPluginLoader->component()->errorString(); return; } plugin->instance = qobject_cast(qmlPluginLoader->instance()); } diff --git a/src/lib/plugins/qml/qmlpluginloader.cpp b/src/lib/plugins/qml/qmlpluginloader.cpp index 2f393ff5..c2080008 100644 --- a/src/lib/plugins/qml/qmlpluginloader.cpp +++ b/src/lib/plugins/qml/qmlpluginloader.cpp @@ -1,78 +1,78 @@ /* ============================================================ * 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" #include "qmlengine.h" #include #include #include "../config.h" #if HAVE_LIBINTL #include "qml/api/i18n/qmli18n.h" #endif QmlPluginLoader::QmlPluginLoader(const QString &name, const QString &path, const QString &entryPoint) { m_name = name; m_path = path; - m_entryPoint = entryPoint; + m_entryPoint = entryPoint.isEmpty() ? QSL("main.qml") : entryPoint; initEngineAndComponent(); } void QmlPluginLoader::createComponent() { m_interface = qobject_cast(m_component->create(m_component->creationContext())); if (!m_interface) { return; } m_interface->setEngine(m_engine); m_interface->setName(m_name); connect(m_interface, &QmlPluginInterface::qmlPluginUnloaded, this, [this] { delete m_component; delete m_engine; initEngineAndComponent(); }); } QQmlComponent *QmlPluginLoader::component() const { return m_component; } QmlPluginInterface *QmlPluginLoader::instance() const { return m_interface; } void QmlPluginLoader::initEngineAndComponent() { m_engine = new QmlEngine(); m_component = new QQmlComponent(m_engine, QDir(m_path).filePath(m_entryPoint)); m_engine->setExtensionPath(m_path); m_engine->setExtensionName(m_name); #if HAVE_LIBINTL auto i18n = new QmlI18n(m_name); m_engine->globalObject().setProperty(QSL("__falkon_i18n"), m_engine->newQObject(i18n)); m_engine->evaluate(QSL("i18n = function (s) { return __falkon_i18n.i18n(s) };")); m_engine->evaluate(QSL("i18np = function (s1, s2) { return __falkon_i18n.i18np(s1, s2) }")); #else m_engine->evaluate(QSL("i18n = function (s) { return s; };")); m_engine->evaluate(QSL("i18np = function (s1, s2) { return s1; }")); #endif }