1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

PyFalkon: Fix C linkage issues

BUG: 413093
FIXED-IN: 3.1.1
This commit is contained in:
David Rosca 2019-10-31 10:37:24 +01:00
parent 1363b848a5
commit bfb9420cbb
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 19 additions and 20 deletions

View File

@ -220,11 +220,12 @@ void Plugins::loadAvailablePlugins()
// PythonPlugin
if (m_pythonPlugin) {
auto f = (QVector<Plugin>(*)()) m_pythonPlugin->resolve("pyfalkon_load_available_plugins");
auto f = (void(*)(QVector<Plugin>*)) m_pythonPlugin->resolve("pyfalkon_load_available_plugins");
if (!f) {
qWarning() << "Failed to resolve" << "pyfalkon_load_available_plugins";
} else {
const auto plugins = f();
QVector<Plugin> plugins;
f(&plugins);
for (const auto &plugin : plugins) {
registerAvailablePlugin(plugin);
}
@ -382,13 +383,15 @@ Plugins::Plugin Plugins::loadPythonPlugin(const QString &name)
return Plugin();
}
auto f = (Plugin(*)(const QString &)) m_pythonPlugin->resolve("pyfalkon_load_plugin");
auto f = (bool(*)(const QString &,Plugin*)) m_pythonPlugin->resolve("pyfalkon_load_plugin");
if (!f) {
qWarning() << "Failed to resolve" << "pyfalkon_load_plugin";
return Plugin();
}
return f(name);
Plugin plugin;
f(name, &plugin);
return plugin;
}
bool Plugins::initPlugin(PluginInterface::InitState state, Plugin *plugin)

View File

@ -91,7 +91,7 @@ void pyfalkon_register_plugin(PluginInterface *plugin)
pluginInterface = plugin;
}
Plugins::Plugin pyfalkon_load_plugin(const QString &name)
bool pyfalkon_load_plugin(const QString &name, Plugins::Plugin *out)
{
QString fullPath;
if (QFileInfo(name).isAbsolute()) {
@ -100,15 +100,14 @@ Plugins::Plugin pyfalkon_load_plugin(const QString &name)
fullPath = DataPaths::locate(DataPaths::Plugins, QSL("python/") + name);
if (fullPath.isEmpty()) {
qWarning() << "Plugin" << name << "not found";
return Plugins::Plugin();
return false;
}
}
Plugins::Plugin plugin;
plugin.type = Plugins::Plugin::PythonPlugin;
plugin.pluginId = QSL("python:%1").arg(QFileInfo(name).fileName());
plugin.pluginSpec = Plugins::createSpec(DesktopFile(fullPath + QSL("/metadata.desktop")));
return plugin;
out->type = Plugins::Plugin::PythonPlugin;
out->pluginId = QSL("python:%1").arg(QFileInfo(name).fileName());
out->pluginSpec = Plugins::createSpec(DesktopFile(fullPath + QSL("/metadata.desktop")));
return true;
}
void pyfalkon_init_plugin(Plugins::Plugin *plugin)
@ -143,24 +142,21 @@ void pyfalkon_init_plugin(Plugins::Plugin *plugin)
plugin->data = QVariant::fromValue(static_cast<void*>(module));
}
QVector<Plugins::Plugin> pyfalkon_load_available_plugins()
void pyfalkon_load_available_plugins(QVector<Plugins::Plugin> *out)
{
QVector<Plugins::Plugin> plugins;
const QStringList dirs = script_paths();
for (const QString &dir : dirs) {
const auto modules = QDir(dir).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const QFileInfo &info : modules) {
Plugins::Plugin plugin = pyfalkon_load_plugin(info.absoluteFilePath());
Plugins::Plugin plugin;
pyfalkon_load_plugin(info.absoluteFilePath(), &plugin);
if (plugin.pluginSpec.name.isEmpty()) {
qWarning() << "Invalid plugin spec of" << info.absoluteFilePath() << "plugin";
continue;
}
plugins.append(plugin);
out->append(plugin);
}
}
return plugins;
}
bool pyfalkon_run_script(const QByteArray &script)

View File

@ -21,8 +21,8 @@
void pyfalkon_register_plugin(PluginInterface *plugin);
extern "C" Q_DECL_EXPORT Plugins::Plugin pyfalkon_load_plugin(const QString &name);
extern "C" Q_DECL_EXPORT bool pyfalkon_load_plugin(const QString &name, Plugins::Plugin *out);
extern "C" Q_DECL_EXPORT void pyfalkon_init_plugin(Plugins::Plugin *plugin);
extern "C" Q_DECL_EXPORT QVector<Plugins::Plugin> pyfalkon_load_available_plugins();
extern "C" Q_DECL_EXPORT void pyfalkon_load_available_plugins(QVector<Plugins::Plugin> *out);
extern "C" Q_DECL_EXPORT bool pyfalkon_run_script(const QByteArray &script);