diff --git a/src/lib/plugins/ocssupport.cpp b/src/lib/plugins/ocssupport.cpp index 138c15f1d..fd4983e5d 100644 --- a/src/lib/plugins/ocssupport.cpp +++ b/src/lib/plugins/ocssupport.cpp @@ -19,6 +19,7 @@ #include "pluginproxy.h" #include "datapaths.h" #include "networkmanager.h" +#include "desktopfile.h" #include "desktopnotificationsfactory.h" #include "mainapplication.h" @@ -31,6 +32,18 @@ Q_GLOBAL_STATIC(OcsSupport, qz_ocs_support) +static DesktopFile readMetaData(const KArchiveDirectory *directory) +{ + const KArchiveEntry *entry = directory->entry(QSL("metadata.desktop")); + if (!entry || !entry->isFile()) { + qWarning() << "No metadata.desktop found"; + return DesktopFile(); + } + const QString tempDir = DataPaths::path(DataPaths::Temp); + static_cast(entry)->copyTo(tempDir); + return DesktopFile(tempDir + QL1S("/metadata.desktop")); +} + OcsSupport::OcsSupport(QObject *parent) : QObject(parent) { @@ -124,6 +137,8 @@ void OcsSupport::installTheme(const KArchiveDirectory *directory) return; } + const DesktopFile metaData = readMetaData(static_cast(entry)); + const QString targetDir = DataPaths::path(DataPaths::Config) + QL1S("/themes"); QDir().mkpath(targetDir); @@ -141,7 +156,7 @@ void OcsSupport::installTheme(const KArchiveDirectory *directory) qInfo() << "Theme installed to" << targetDir; - mApp->desktopNotifications()->showNotification(tr("Theme installed"), tr("Theme was successfully installed")); + mApp->desktopNotifications()->showNotification(tr("Theme installed"), tr("'%1' was successfully installed").arg(metaData.name())); } void OcsSupport::installExtension(const KArchiveDirectory *directory) @@ -164,21 +179,23 @@ void OcsSupport::installExtension(const KArchiveDirectory *directory) return; } + const DesktopFile metaData = readMetaData(static_cast(entry)); + const QString extensionType = metaData.value(QSL("X-Falkon-Type")).toString(); + QString type; - const QStringList files = static_cast(entry)->entries(); - if (files.contains(QL1S("__init__.py"))) { + if (extensionType == QL1S("Extension/Python")) { type = QSL("python"); - } else if (files.contains(QL1S("main.qml"))) { + } else if (extensionType == QL1S("Extension/Qml")) { type = QSL("qml"); } if (type.isEmpty()) { - qWarning() << "Unsupported extension type"; + qWarning() << "Unsupported extension type" << extensionType; showError(); return; } - const QString targetDir = DataPaths::path(DataPaths::Config) + QL1S("/plugins/") + type; + const QString targetDir = DataPaths::path(DataPaths::Config) + QL1S("/plugins/"); QDir().mkpath(targetDir); if (QFileInfo::exists(targetDir + QL1S("/") + name)) { @@ -202,5 +219,5 @@ void OcsSupport::installExtension(const KArchiveDirectory *directory) return; } - mApp->desktopNotifications()->showNotification(tr("Extension installed"), tr("Extension was successfully installed")); + mApp->desktopNotifications()->showNotification(tr("Extension installed"), tr("'%1' was successfully installed").arg(metaData.name())); } diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index 77aa86bed..bdc8c3f59 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -236,50 +236,34 @@ void Plugins::loadAvailablePlugins() // InternalPlugin registerAvailablePlugin(loadInternalPlugin(QSL("adblock"))); - // SharedLibraryPlugin for (const QString &dir : dirs) { - const auto files = QDir(dir).entryInfoList(QDir::Files); + const auto files = QDir(dir).entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); for (const QFileInfo &info : files) { - if (info.baseName() == QL1S("PyFalkon")) { - continue; + Plugin plugin; + const QString pluginPath = info.absoluteFilePath(); + if (info.isFile()) { + // SharedLibraryPlugin + if (info.baseName() != QL1S("PyFalkon")) { + plugin = loadSharedLibraryPlugin(pluginPath); + } + } else if (info.isDir()) { + const DesktopFile metaData(QDir(pluginPath).filePath(QSL("metadata.desktop"))); + const QString type = metaData.value(QSL("X-Falkon-Type")).toString(); + if (type == QL1S("Extension/Python")) { + // PythonPlugin + plugin = loadPythonPlugin(pluginPath); + } else if (type == QL1S("Extension/Qml")) { + // QmlPlugin + plugin = QmlPlugin::loadPlugin(pluginPath); + } else { + qWarning() << "Invalid type" << type << "of" << pluginPath << "plugin"; + } } - Plugin plugin = loadSharedLibraryPlugin(info.absoluteFilePath()); if (plugin.type == Plugin::Invalid) { continue; } if (plugin.pluginSpec.name.isEmpty()) { - qWarning() << "Invalid plugin spec of" << info.absoluteFilePath() << "plugin"; - continue; - } - registerAvailablePlugin(plugin); - } - } - - // PythonPlugin - if (m_pythonPlugin) { - auto f = (QVector(*)()) m_pythonPlugin->resolve("pyfalkon_load_available_plugins"); - if (!f) { - qWarning() << "Failed to resolve" << "pyfalkon_load_available_plugins"; - } else { - const auto plugins = f(); - for (const auto &plugin : plugins) { - registerAvailablePlugin(plugin); - } - } - } - - // QmlPlugin - for (QString dir : dirs) { - // Qml plugins will be loaded from subdirectory qml - dir.append(QSL("/qml")); - const auto qmlDirs = QDir(dir).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); - for (const QFileInfo &info : qmlDirs) { - Plugin plugin = QmlPlugin::loadPlugin(info.absoluteFilePath()); - if (plugin.type == Plugin::Invalid) { - continue; - } - if (plugin.pluginSpec.name.isEmpty()) { - qWarning() << "Invalid plugin spec of" << info.absoluteFilePath() << "plugin"; + qWarning() << "Invalid plugin spec of" << pluginPath << "plugin"; continue; } registerAvailablePlugin(plugin); diff --git a/src/plugins/PyFalkon/pythonplugin.cpp b/src/plugins/PyFalkon/pythonplugin.cpp index fcce66fc8..88b03346f 100644 --- a/src/plugins/PyFalkon/pythonplugin.cpp +++ b/src/plugins/PyFalkon/pythonplugin.cpp @@ -40,15 +40,6 @@ State state = PythonUninitialized; PluginInterface *pluginInterface = nullptr; QHash pluginInstances; -static QStringList script_paths() -{ - QStringList dirs = DataPaths::allPaths(DataPaths::Plugins); - for (int i = 0; i < dirs.count(); ++i) { - dirs[i].append(QSL("/python")); - } - return dirs; -} - static void cleanup() { if (state > PythonUninitialized) { @@ -73,7 +64,7 @@ static State init() return state; } - set_path(script_paths()); + set_path(DataPaths::allPaths(DataPaths::Plugins)); if (PyImport_AppendInittab("Falkon", PyInit_PyFalkon) != 0) { PyErr_Print(); @@ -143,37 +134,3 @@ void pyfalkon_init_plugin(Plugins::Plugin *plugin) plugin->instance = pluginInterface; plugin->data = QVariant::fromValue(static_cast(module)); } - -QVector pyfalkon_load_available_plugins() -{ - QVector 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()); - if (plugin.pluginSpec.name.isEmpty()) { - qWarning() << "Invalid plugin spec of" << info.absoluteFilePath() << "plugin"; - continue; - } - plugins.append(plugin); - } - } - - return plugins; -} - -bool pyfalkon_run_script(const QByteArray &script) -{ - if (init() != PythonInitialized) { - return false; - } - - if (PyRun_SimpleString(script.constData()) != 0) { - PyErr_Print(); - return false; - } - - return true; -} diff --git a/src/plugins/PyFalkon/pythonplugin.h b/src/plugins/PyFalkon/pythonplugin.h index b52560aa7..db3bd8308 100644 --- a/src/plugins/PyFalkon/pythonplugin.h +++ b/src/plugins/PyFalkon/pythonplugin.h @@ -23,6 +23,3 @@ 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(); - -extern "C" Q_DECL_EXPORT bool pyfalkon_run_script(const QByteArray &script); diff --git a/src/scripts/CMakeLists.txt b/src/scripts/CMakeLists.txt index 6e18917ff..70a3fa893 100644 --- a/src/scripts/CMakeLists.txt +++ b/src/scripts/CMakeLists.txt @@ -2,23 +2,23 @@ function(install_python_script name) if (ENABLE_PYTHON_PLUGINS) install( DIRECTORY ${name} - DESTINATION "${FALKON_INSTALL_PLUGINDIR}/python" + DESTINATION ${FALKON_INSTALL_PLUGINDIR} FILES_MATCHING PATTERN "*" PATTERN "Messages.sh" EXCLUDE ) - install(FILES i18n.py DESTINATION "${FALKON_INSTALL_PLUGINDIR}/python/${name}") + install(FILES i18n.py DESTINATION "${FALKON_INSTALL_PLUGINDIR}/${name}") endif() endfunction() function(install_qml_script name) install( DIRECTORY ${name} - DESTINATION "${FALKON_INSTALL_PLUGINDIR}/qml" + DESTINATION ${FALKON_INSTALL_PLUGINDIR} FILES_MATCHING PATTERN "*" PATTERN "Messages.sh" EXCLUDE ) endfunction() -install_python_script(hellopython) +# install_python_script(hellopython) install_python_script(runaction) install_python_script(middleclickloader) -install_qml_script(helloqml) +# install_qml_script(helloqml) diff --git a/src/scripts/hellopython/metadata.desktop b/src/scripts/hellopython/metadata.desktop index 30957aaa1..ffe51f220 100644 --- a/src/scripts/hellopython/metadata.desktop +++ b/src/scripts/hellopython/metadata.desktop @@ -50,6 +50,7 @@ Comment[zh_TW]=Python 擴充程式範例 Icon= Type=Service +X-Falkon-Type=Extension/Python X-Falkon-Author=David Rosca X-Falkon-Email=nowrep@gmail.com diff --git a/src/scripts/helloqml/metadata.desktop b/src/scripts/helloqml/metadata.desktop index c18ea3d4c..dae7f2de9 100644 --- a/src/scripts/helloqml/metadata.desktop +++ b/src/scripts/helloqml/metadata.desktop @@ -43,8 +43,11 @@ Comment[uk]=Зразок додатка Qml Comment[x-test]=xxSample Qml Pluginxx Comment[zh_CN]=示例 Qml 插件 Comment[zh_TW]=簡易的 QML 外掛 + Icon= Type=Service +X-Falkon-Type=Extension/Qml + X-Falkon-Author=Anmol Gautam X-Falkon-Email=tarptaeya@gmail.com X-Falkon-Version=0.1.0 diff --git a/src/scripts/middleclickloader/metadata.desktop b/src/scripts/middleclickloader/metadata.desktop index cc83e40f5..f4102b7a8 100644 --- a/src/scripts/middleclickloader/metadata.desktop +++ b/src/scripts/middleclickloader/metadata.desktop @@ -46,6 +46,7 @@ Comment[zh_CN]=将选择剪贴板中的文本加载为 URL Icon= Type=Service +X-Falkon-Type=Extension/Python X-Falkon-Author=Juraj Oravec X-Falkon-Email=sgd.orava@gmail.com diff --git a/src/scripts/runaction/metadata.desktop b/src/scripts/runaction/metadata.desktop index be904445c..707687191 100644 --- a/src/scripts/runaction/metadata.desktop +++ b/src/scripts/runaction/metadata.desktop @@ -48,6 +48,7 @@ Comment[zh_TW]=在網站上執行各種動作 Icon=icon.svg Type=Service +X-Falkon-Type=Extension/Python X-Falkon-Author=David Rosca X-Falkon-Email=nowrep@gmail.com diff --git a/themes/chrome/metadata.desktop b/themes/chrome/metadata.desktop index 413445597..cbe6dbd26 100644 --- a/themes/chrome/metadata.desktop +++ b/themes/chrome/metadata.desktop @@ -49,6 +49,7 @@ Comment[zh_CN]=基于火狐 Chromifox 主题的类似于 Chrome 的 Falkon 主 Icon=theme.png Type=Service +X-Falkon-Type=Theme X-Falkon-Author=David Rosca X-Falkon-Email=nowrep@gmail.com diff --git a/themes/linux/metadata.desktop b/themes/linux/metadata.desktop index 2ec5ac335..2cf30f3ee 100644 --- a/themes/linux/metadata.desktop +++ b/themes/linux/metadata.desktop @@ -49,6 +49,7 @@ Comment[zh_CN]=给 Linux 设计的使用原生控件的默认简易主题,图 Icon=theme.png Type=Service +X-Falkon-Type=Theme X-Falkon-Author=David Rosca X-Falkon-Email=nowrep@gmail.com diff --git a/themes/mac/metadata.desktop b/themes/mac/metadata.desktop index 1f61db92b..cb9fc01c8 100644 --- a/themes/mac/metadata.desktop +++ b/themes/mac/metadata.desktop @@ -50,6 +50,7 @@ Comment[zh_TW]=適用於 Falkon,基於 Firefox Mac OS X 主題的類 Mac 主 Icon=theme.png Type=Service +X-Falkon-Type=Theme X-Falkon-Author=David Rosca X-Falkon-Email=nowrep@gmail.com diff --git a/themes/windows/metadata.desktop b/themes/windows/metadata.desktop index 8f9e12bd4..4ec0d08c8 100644 --- a/themes/windows/metadata.desktop +++ b/themes/windows/metadata.desktop @@ -50,6 +50,7 @@ Comment[zh_TW]=基於質感設計的類 Windows 主題 Icon=theme.png Type=Service +X-Falkon-Type=Theme X-Falkon-Author=David Rosca X-Falkon-Email=nowrep@gmail.com