diff --git a/CMakeLists.txt b/CMakeLists.txt index 992f284b..4b2c79b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ else() set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(NOSTALGIA_DIST_BIN bin) set(NOSTALGIA_DIST_LIB lib) - set(NOSTALGIA_DIST_PLUGIN lib) + set(NOSTALGIA_DIST_PLUGIN lib/nostalgia/plugins) set(NOSTALGIA_DIST_RESOURCES share) endif() diff --git a/src/nostalgia/core/studio/CMakeLists.txt b/src/nostalgia/core/studio/CMakeLists.txt index 075d418f..09bee3cc 100644 --- a/src/nostalgia/core/studio/CMakeLists.txt +++ b/src/nostalgia/core/studio/CMakeLists.txt @@ -20,7 +20,7 @@ install( TARGETS NostalgiaCore-Studio LIBRARY DESTINATION - ${NOSTALGIA_DIST_PLUGIN}/nostalgia + ${NOSTALGIA_DIST_PLUGIN} ) install( diff --git a/src/nostalgia/core/studio/core-studio.json b/src/nostalgia/core/studio/core-studio.json new file mode 100644 index 00000000..23100699 --- /dev/null +++ b/src/nostalgia/core/studio/core-studio.json @@ -0,0 +1,3 @@ +{ + "plugin_name": "Nostalgia Core" +} \ No newline at end of file diff --git a/src/nostalgia/core/studio/plugin.hpp b/src/nostalgia/core/studio/plugin.hpp index 11a8724d..6a4c5c0b 100644 --- a/src/nostalgia/core/studio/plugin.hpp +++ b/src/nostalgia/core/studio/plugin.hpp @@ -17,7 +17,7 @@ namespace core { class Plugin: public QObject, studio::Plugin { Q_OBJECT - Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.studio.Plugin") + Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.studio.Plugin" FILE "core-studio.json") Q_INTERFACES(nostalgia::studio::Plugin) public: diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index 72e9aac9..14975666 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -73,30 +73,48 @@ MainWindow::~MainWindow() { } void MainWindow::loadPlugins() { - for (auto p : m_profile.plugins) { -#if defined(Q_OS_WIN) - auto libName = p.libName + ".dll"; -#elif defined(Q_OS_MAC) - auto libName = "lib" + p.libName + ".dylib"; -#else - auto libName = "lib" + p.libName + ".so"; -#endif - auto pluginPath = QFileInfo(m_profilePath).absolutePath() + "/" + p.dir + "/" + libName; - - auto loader = new QPluginLoader(pluginPath); - auto plugin = qobject_cast(loader->instance()); - if (plugin) { - m_cleanupTasks.push_back([loader]() { - loader->unload(); - delete loader; - }); - m_plugins.push_back(plugin); - } else { - qInfo() << loader->errorString(); + for (auto dir : m_profile.pluginsPath) { + QFileInfo dirInfo(m_profilePath); + dir = dirInfo.absolutePath() + "/" + dir; + if (dirInfo.exists()) { + qDebug() << "Checking plugin directory:" << dir; + loadPluginDir(dir); } } } +void MainWindow::loadPluginDir(QString dir) { +#if defined(Q_OS_WIN) + constexpr auto libSuffix = ".dll"; +#elif defined(Q_OS_MAC) + constexpr auto libSuffix = ".dylib"; +#else + constexpr auto libSuffix = ".so"; +#endif + + for (auto pluginPath : QDir(dir).entryList()) { + pluginPath = dir + '/' + pluginPath; + if (pluginPath.endsWith(libSuffix)) { + loadPlugin(pluginPath); + } + } +} + +void MainWindow::loadPlugin(QString pluginPath) { + qDebug() << "Loading plugin:" << pluginPath; + auto loader = new QPluginLoader(pluginPath); + auto plugin = qobject_cast(loader->instance()); + if (plugin) { + m_cleanupTasks.push_back([loader]() { + loader->unload(); + delete loader; + }); + m_plugins.push_back(plugin); + } else { + qInfo() << loader->errorString(); + } +} + void MainWindow::setupMenu() { auto menu = menuBar(); auto fileMenu = menu->addMenu(tr("&File")); diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index 7203de77..8f4c8229 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -61,7 +61,7 @@ ox::Error ioOp(T *io, NostalgiaStudioPluginDef *obj) { struct NostalgiaStudioProfile { QString appName; QString orgName; - QVector plugins; + QVector pluginsPath; }; template @@ -70,7 +70,7 @@ ox::Error ioOp(T *io, NostalgiaStudioProfile *obj) { io->setFields(3); err |= io->op("app_name", &obj->appName); err |= io->op("org_name", &obj->orgName); - err |= io->op("plugins", &obj->plugins); + err |= io->op("plugins_path", &obj->pluginsPath); return err; } @@ -104,6 +104,10 @@ class MainWindow: public QMainWindow { private: void loadPlugins(); + void loadPluginDir(QString path); + + void loadPlugin(QString path); + void setupDockWidgets(); void setupMenu(); diff --git a/src/nostalgia/studio/nostalgia-studio.json b/src/nostalgia/studio/nostalgia-studio.json index 0328a1ea..c258dfbe 100644 --- a/src/nostalgia/studio/nostalgia-studio.json +++ b/src/nostalgia/studio/nostalgia-studio.json @@ -1,14 +1,8 @@ { "app_name": "Nostalgia Studio", "org_name": "Drinking Tea", - "plugins": [ - { - "dir": "../lib/nostalgia", - "lib_name": "NostalgiaCore-Studio" - }, - { - "dir": "../lib/nostalgia", - "lib_name": "NostalgiaWorld-Studio" - } + "plugins_path": [ + "../lib/nostalgia/plugins", + "../Plugins" ] } diff --git a/src/nostalgia/world/studio/CMakeLists.txt b/src/nostalgia/world/studio/CMakeLists.txt index f05db341..01a7fa2c 100644 --- a/src/nostalgia/world/studio/CMakeLists.txt +++ b/src/nostalgia/world/studio/CMakeLists.txt @@ -18,5 +18,5 @@ install( TARGETS NostalgiaWorld-Studio LIBRARY DESTINATION - ${NOSTALGIA_DIST_PLUGIN}/nostalgia + ${NOSTALGIA_DIST_PLUGIN} ) diff --git a/src/nostalgia/world/studio/world-studio.json b/src/nostalgia/world/studio/world-studio.json new file mode 100644 index 00000000..3cd12d3b --- /dev/null +++ b/src/nostalgia/world/studio/world-studio.json @@ -0,0 +1,3 @@ +{ + "plugin_name": "Nostalgia World" +} \ No newline at end of file