78 lines
2.4 KiB
C++
Raw Normal View History

2026-01-12 18:58:51 +04:00
#include "mainwindow.h"
#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QLabel>
2026-01-22 17:11:17 +04:00
#include <QPluginLoader>
2026-01-12 18:58:51 +04:00
#include <QVBoxLayout>
extern "C" {
2026-01-22 17:11:17 +04:00
void logos_core_cleanup();
2026-01-12 18:58:51 +04:00
}
2026-01-30 21:20:41 +04:00
void MainWindow::destroy() {
qDebug() << "MainWindow: Destroying MainWindow...";
2026-01-12 18:58:51 +04:00
2026-01-30 21:20:41 +04:00
if (plugin && storageWidget) {
QMetaObject::invokeMethod(plugin, "destroyWidget", Qt::DirectConnection, Q_ARG(QWidget*, storageWidget));
2026-01-12 18:58:51 +04:00
}
}
2026-01-22 17:11:17 +04:00
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setupUi(); }
2026-01-12 18:58:51 +04:00
2026-01-22 17:11:17 +04:00
MainWindow::~MainWindow() {}
2026-01-12 18:58:51 +04:00
2026-01-22 17:11:17 +04:00
void MainWindow::setupUi() {
2026-01-12 18:58:51 +04:00
// Determine the appropriate plugin extension based on the platform
QString pluginExtension;
2026-01-30 21:20:41 +04:00
2026-01-22 17:11:17 +04:00
#if defined(Q_OS_WIN)
pluginExtension = ".dll";
#elif defined(Q_OS_MAC)
pluginExtension = ".dylib";
#else // Linux and other Unix-like systems
pluginExtension = ".so";
#endif
2026-01-12 18:58:51 +04:00
// Load the storage_ui plugin with the appropriate extension
QString pluginPath = QCoreApplication::applicationDirPath() + "/../storage_ui" + pluginExtension;
QPluginLoader loader(pluginPath);
QWidget* widget = nullptr;
if (loader.load()) {
2026-01-30 21:20:41 +04:00
plugin = loader.instance();
2026-01-12 18:58:51 +04:00
if (plugin) {
// Try to create the storage widget using the plugin's createWidget method
2026-01-22 17:11:17 +04:00
QMetaObject::invokeMethod(plugin, "createWidget", Qt::DirectConnection, Q_RETURN_ARG(QWidget*, widget));
2026-01-12 18:58:51 +04:00
}
}
if (widget) {
storageWidget = widget;
setCentralWidget(storageWidget);
} else {
qWarning() << "================================================";
qWarning() << "Failed to load storage UI plugin from:" << pluginPath;
qWarning() << "Error:" << loader.errorString();
qWarning() << "================================================";
2026-01-22 17:11:17 +04:00
2026-01-12 18:58:51 +04:00
// Fallback: show a message when plugin is not found
QWidget* fallbackWidget = new QWidget(this);
QVBoxLayout* layout = new QVBoxLayout(fallbackWidget);
QLabel* messageLabel = new QLabel("Storage UI module not loaded", fallbackWidget);
QFont font = messageLabel->font();
font.setPointSize(14);
messageLabel->setFont(font);
messageLabel->setAlignment(Qt::AlignCenter);
layout->addWidget(messageLabel);
setCentralWidget(fallbackWidget);
}
// Set window title and size
2026-01-30 21:20:41 +04:00
setWindowTitle("Logos Storage UI App");
2026-01-22 17:11:17 +04:00
resize(800, 600);
2026-01-12 18:58:51 +04:00
}