diff --git a/app/main.cpp b/app/main.cpp index d40fd62..d91ebf0 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,18 +1,17 @@ #include "mainwindow.h" #include -#include #include +#include #include -#include // Replace CoreManager with direct C API functions extern "C" { - void logos_core_set_plugins_dir(const char* plugins_dir); - void logos_core_start(); - void logos_core_cleanup(); - char** logos_core_get_loaded_plugins(); - int logos_core_load_plugin(const char* plugin_name); +void logos_core_set_plugins_dir(const char* plugins_dir); +void logos_core_start(); +void logos_core_cleanup(); +char** logos_core_get_loaded_plugins(); +int logos_core_load_plugin(const char* plugin_name); } // Helper function to convert C-style array to QStringList @@ -26,8 +25,7 @@ QStringList convertPluginsToStringList(char** plugins) { return result; } -int main(int argc, char *argv[]) -{ +int main(int argc, char* argv[]) { // Create QApplication first QApplication app(argc, argv); @@ -42,30 +40,30 @@ int main(int argc, char *argv[]) // Explicitly load plugins in specified order std::cout << "Loading plugins in specified order..." << std::endl; - + // Load capability_module plugin first if (logos_core_load_plugin("capability_module")) { std::cout << "Successfully loaded capability_module plugin" << std::endl; } else { std::cerr << "Failed to load capability_module plugin" << std::endl; } - + // Load storage_module plugin second if (logos_core_load_plugin("storage_module")) { std::cout << "Successfully loaded storage_module plugin" << std::endl; } else { std::cerr << "Failed to load storage_module plugin" << std::endl; } - + // Print all loaded plugins char** loadedPlugins = logos_core_get_loaded_plugins(); QStringList plugins = convertPluginsToStringList(loadedPlugins); - + if (plugins.isEmpty()) { qInfo() << "No plugins loaded."; } else { qInfo() << "Currently loaded plugins:"; - for (const QString &plugin : plugins) { + for (const QString& plugin : plugins) { qInfo() << " -" << plugin; } qInfo() << "Total plugins:" << plugins.size(); @@ -75,7 +73,7 @@ int main(int argc, char *argv[]) MainWindow window; window.show(); - + // Run the application int result = app.exec(); @@ -85,6 +83,7 @@ int main(int argc, char *argv[]) // Cleanup core before exit logos_core_cleanup(); - + return result; -} \ No newline at end of file +} + diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index ada306d..2bc11f3 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -1,43 +1,30 @@ #include "mainwindow.h" #include #include -#include #include #include +#include #include -#include -#include extern "C" { - void logos_core_cleanup(); +void logos_core_cleanup(); } -void MainWindow::cleanup() -{ +void MainWindow::cleanup() { qDebug() << "MainWindow: Cleaning up before exit..."; - if (storageWidget) { - bool running = false; - if (storageWidget) { - QMetaObject::invokeMethod(storageWidget, "isStorageRunning", - Qt::DirectConnection, - Q_RETURN_ARG(bool, running)); - } + if (storageWidget) { + qDebug() << "MainWindow: Stopping Storage before destroying..."; - if (running) { - qDebug() << "MainWindow: Stopping Storage before destroying..."; + QEventLoop loop; + QObject::connect(storageWidget, SIGNAL(storageStop()), &loop, SLOT(quit())); + QMetaObject::invokeMethod(storageWidget, "stopStorage", Qt::QueuedConnection); + loop.exec(); - QEventLoop loop; - QObject::connect(storageWidget, SIGNAL(storageStop()), &loop, SLOT(quit())); - QMetaObject::invokeMethod(storageWidget, "stopStorage", Qt::QueuedConnection); - loop.exec(); - - qDebug() << "MainWindow: Storage stopped."; - } + qDebug() << "MainWindow: Storage stopped."; qDebug() << "MainWindow: Destroying Storage..."; - QEventLoop loop; QObject::connect(storageWidget, SIGNAL(storageCleanup()), &loop, SLOT(quit())); QMetaObject::invokeMethod(storageWidget, "destroy", Qt::QueuedConnection); loop.exec(); @@ -46,27 +33,20 @@ void MainWindow::cleanup() } } -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) -{ - setupUi(); -} +MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setupUi(); } -MainWindow::~MainWindow() -{ -} +MainWindow::~MainWindow() {} -void MainWindow::setupUi() -{ +void MainWindow::setupUi() { // Determine the appropriate plugin extension based on the platform QString pluginExtension; - #if defined(Q_OS_WIN) - pluginExtension = ".dll"; - #elif defined(Q_OS_MAC) - pluginExtension = ".dylib"; - #else // Linux and other Unix-like systems - pluginExtension = ".so"; - #endif +#if defined(Q_OS_WIN) + pluginExtension = ".dll"; +#elif defined(Q_OS_MAC) + pluginExtension = ".dylib"; +#else // Linux and other Unix-like systems + pluginExtension = ".so"; +#endif // Load the storage_ui plugin with the appropriate extension QString pluginPath = QCoreApplication::applicationDirPath() + "/../storage_ui" + pluginExtension; @@ -78,9 +58,7 @@ void MainWindow::setupUi() QObject* plugin = loader.instance(); if (plugin) { // Try to create the storage widget using the plugin's createWidget method - QMetaObject::invokeMethod(plugin, "createWidget", - Qt::DirectConnection, - Q_RETURN_ARG(QWidget*, widget)); + QMetaObject::invokeMethod(plugin, "createWidget", Qt::DirectConnection, Q_RETURN_ARG(QWidget*, widget)); } } @@ -92,7 +70,7 @@ void MainWindow::setupUi() qWarning() << "Failed to load storage UI plugin from:" << pluginPath; qWarning() << "Error:" << loader.errorString(); qWarning() << "================================================"; - + // Fallback: show a message when plugin is not found QWidget* fallbackWidget = new QWidget(this); QVBoxLayout* layout = new QVBoxLayout(fallbackWidget); @@ -108,6 +86,6 @@ void MainWindow::setupUi() } // Set window title and size - setWindowTitle("Logos Storage UI App"); - // resize(800, 600); + setWindowTitle("Logos Storage UI App !"); + resize(800, 600); } diff --git a/app/mainwindow.h b/app/mainwindow.h index 1790350..2cc3d99 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -5,20 +5,19 @@ class QCloseEvent; -class MainWindow : public QMainWindow -{ +class MainWindow : public QMainWindow { Q_OBJECT -public: - MainWindow(QWidget *parent = nullptr); + public: + MainWindow(QWidget* parent = nullptr); ~MainWindow(); void cleanup(); -private: + private: void setupUi(); + void setupMenu(); -private: - QWidget *storageWidget = nullptr; + QWidget* storageWidget = nullptr; }; #endif // MAINWINDOW_H