diff --git a/src/plugins/PyFalkon/CMakeLists.txt b/src/plugins/PyFalkon/CMakeLists.txt index fd79f03ca..a2f4e420c 100644 --- a/src/plugins/PyFalkon/CMakeLists.txt +++ b/src/plugins/PyFalkon/CMakeLists.txt @@ -40,11 +40,13 @@ pyside2_config(--pyside2-shared-libraries-cmake PYSIDE2_SHARED_LIBRARIES 1) get_property(QT_CORE_INCLUDE_DIRS TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES) get_property(QT_GUI_INCLUDE_DIRS TARGET Qt5::Gui PROPERTY INTERFACE_INCLUDE_DIRECTORIES) get_property(QT_WIDGETS_INCLUDE_DIRS TARGET Qt5::Widgets PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +get_property(QT_WEBENGINECORE_INCLUDE_DIRS TARGET Qt5::WebEngineCore PROPERTY INTERFACE_INCLUDE_DIRECTORIES) get_property(QT_WEBENGINEWIDGETS_INCLUDE_DIRS TARGET Qt5::WebEngineWidgets PROPERTY INTERFACE_INCLUDE_DIRECTORIES) set(QT_INCLUDE_DIRS ${QT_CORE_INCLUDE_DIRS} ${QT_GUI_INCLUDE_DIRS} ${QT_WIDGETS_INCLUDE_DIRS} + ${QT_WEBENGINECORE_INCLUDE_DIRS} ${QT_WEBENGINEWIDGETS_INCLUDE_DIRS} ) set(INCLUDES "") @@ -93,7 +95,6 @@ set(GENERATED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/PyFalkon/pyfalkon_module_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PyFalkon/desktopfile_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PyFalkon/plugininterface_wrapper.cpp - ${CMAKE_CURRENT_BINARY_DIR}/PyFalkon/pythonpluginobject_wrapper.cpp ) set(GENERATED_SOURCES_DEPENDENCIES ${WRAPPED_HEADER} @@ -121,7 +122,6 @@ endforeach() set( PyFalkon_SRCS pythonplugin.cpp - pythonpluginobject.cpp ${GENERATED_SOURCES} ) diff --git a/src/plugins/PyFalkon/pyfalkon.xml b/src/plugins/PyFalkon/pyfalkon.xml index 8341af957..18986183f 100644 --- a/src/plugins/PyFalkon/pyfalkon.xml +++ b/src/plugins/PyFalkon/pyfalkon.xml @@ -2,17 +2,20 @@ + + #include <pythonplugin.h> + + - - - - - - - + + + Py_INCREF(%PYARG_1); + pyfalkon_register_plugin(%1); + + diff --git a/src/plugins/PyFalkon/pythonplugin.cpp b/src/plugins/PyFalkon/pythonplugin.cpp index b246c63f2..3f45e09ec 100644 --- a/src/plugins/PyFalkon/pythonplugin.cpp +++ b/src/plugins/PyFalkon/pythonplugin.cpp @@ -16,7 +16,6 @@ * along with this program. If not, see . * ============================================================ */ #include "pythonplugin.h" -#include "pythonpluginobject.h" #include "plugins.h" #include "datapaths.h" @@ -38,7 +37,7 @@ enum State State state = PythonUninitialized; -PythonPluginObject *pluginObject = nullptr; +PluginInterface *pluginInterface = nullptr; QHash pluginInstances; static QStringList script_paths() @@ -55,7 +54,6 @@ static void cleanup() if (state > PythonUninitialized) { Py_Finalize(); state = PythonUninitialized; - delete pluginObject; } } @@ -69,34 +67,6 @@ static void set_path(const QStringList &scriptPaths) qputenv("PYTHONPATH", paths.join(QL1C(':')).toLocal8Bit()); } -static void register_plugin_object() -{ - pluginObject = new PythonPluginObject(); - - PyTypeObject *typeObject = Shiboken::SbkType(); - PyObject *po = Shiboken::Conversions::pointerToPython(reinterpret_cast(typeObject), pluginObject); - if (!po) { - qWarning() << "Failed to create wrapper for" << pluginObject; - return; - } - Py_INCREF(po); - - PyObject *module = PyImport_AddModule("Falkon"); - if (!module) { - Py_DECREF(po); - PyErr_Print(); - qWarning() << "Failed to locate Falkon module!"; - return; - } - - if (PyModule_AddObject(module, "plugin", po) < 0) { - Py_DECREF(po); - PyErr_Print(); - qWarning() << "Failed to add plugin object to Falkon module!"; - return; - } -} - static State init() { if (state > PythonUninitialized) { @@ -121,11 +91,14 @@ static State init() return state = PythonError; } - register_plugin_object(); - return state; } +void pyfalkon_register_plugin(PluginInterface *plugin) +{ + pluginInterface = plugin; +} + Plugins::Plugin pyfalkon_load_plugin(const QString &name) { QString fullPath; @@ -160,7 +133,7 @@ void pyfalkon_init_plugin(Plugins::Plugin *plugin) const QString moduleName = plugin->pluginId.mid(7); - pluginObject->ptr = nullptr; + pluginInterface = nullptr; module = PyImport_ImportModule(qPrintable(moduleName)); if (!module) { @@ -168,13 +141,13 @@ void pyfalkon_init_plugin(Plugins::Plugin *plugin) qWarning() << "Failed to import module" << moduleName; return; } - if (!pluginObject->ptr) { - qWarning() << "No plugin registered! Falkon.plugin.registerPlugin() must be called from script."; + if (!pluginInterface) { + qWarning() << "No plugin registered! Falkon.registerPlugin() must be called from script."; return; } - pluginInstances[module] = pluginObject->ptr; - plugin->instance = pluginObject->ptr; + pluginInstances[module] = pluginInterface; + plugin->instance = pluginInterface; plugin->data = QVariant::fromValue(static_cast(module)); } diff --git a/src/plugins/PyFalkon/pythonplugin.h b/src/plugins/PyFalkon/pythonplugin.h index 63570ddd4..b32650cfa 100644 --- a/src/plugins/PyFalkon/pythonplugin.h +++ b/src/plugins/PyFalkon/pythonplugin.h @@ -19,6 +19,8 @@ #include "plugins.h" +void pyfalkon_register_plugin(PluginInterface *plugin); + extern "C" Q_DECL_EXPORT Plugins::Plugin pyfalkon_load_plugin(const QString &name); extern "C" Q_DECL_EXPORT void pyfalkon_init_plugin(Plugins::Plugin *plugin); extern "C" Q_DECL_EXPORT QVector pyfalkon_load_available_plugins(); diff --git a/src/plugins/PyFalkon/pythonpluginobject.cpp b/src/plugins/PyFalkon/pythonpluginobject.cpp deleted file mode 100644 index 0ba482b8e..000000000 --- a/src/plugins/PyFalkon/pythonpluginobject.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2018 David Rosca -* -* 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 "pythonpluginobject.h" - -PluginInterface *PythonPluginObject::ptr = nullptr; - -PythonPluginObject::PythonPluginObject(QObject *parent) - : QObject(parent) -{ -} - -void PythonPluginObject::registerPlugin(PluginInterface *plugin) -{ - ptr = plugin; -} diff --git a/src/plugins/PyFalkon/pythonpluginobject.h b/src/plugins/PyFalkon/pythonpluginobject.h deleted file mode 100644 index d31807ef5..000000000 --- a/src/plugins/PyFalkon/pythonpluginobject.h +++ /dev/null @@ -1,34 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2018 David Rosca -* -* 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 . -* ============================================================ */ -#pragma once - -#include - -class PluginInterface; - -class PythonPluginObject : public QObject -{ - Q_OBJECT - -public: - explicit PythonPluginObject(QObject *parent = nullptr); - - void registerPlugin(PluginInterface *plugin); - - static PluginInterface *ptr; -}; diff --git a/src/plugins/PyFalkon/wrappedclasses.h b/src/plugins/PyFalkon/wrappedclasses.h index 1b1c02859..a038af1f8 100644 --- a/src/plugins/PyFalkon/wrappedclasses.h +++ b/src/plugins/PyFalkon/wrappedclasses.h @@ -1,6 +1,21 @@ -// Falkon +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2018 David Rosca +* +* 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 "webview.h" #include "desktopfile.h" #include "plugininterface.h" - -// PyFalkon -#include "pythonpluginobject.h"