mirror of
https://github.com/logos-storage/logos-storage-app-skeleton.git
synced 2026-06-15 04:49:29 +00:00
Remove from git
This commit is contained in:
parent
290b125cf7
commit
339d44d18c
@ -1,11 +0,0 @@
|
||||
#include "StorageUIComponent.h"
|
||||
#include "src/StorageWidget.h"
|
||||
|
||||
QWidget* StorageUIComponent::createWidget(LogosAPI* logosAPI) {
|
||||
// LogosAPI parameter available but not used - StorageWidget creates its own
|
||||
return new StorageWidget();
|
||||
}
|
||||
|
||||
void StorageUIComponent::destroyWidget(QWidget* widget) {
|
||||
delete widget;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <IComponent.h>
|
||||
#include <QObject>
|
||||
|
||||
class StorageUIComponent : public QObject, public IComponent {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(IComponent)
|
||||
Q_PLUGIN_METADATA(IID IComponent_iid FILE "metadata.json")
|
||||
|
||||
public:
|
||||
Q_INVOKABLE QWidget* createWidget(LogosAPI* logosAPI = nullptr) override;
|
||||
void destroyWidget(QWidget* widget) override;
|
||||
};
|
||||
@ -1,304 +0,0 @@
|
||||
#include "StorageWidget.h"
|
||||
#include "logos_api_client.h"
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
// #include <QQmlContext>
|
||||
#include <QTimer>
|
||||
|
||||
int RET_OK = 0;
|
||||
|
||||
// Static pointer to the active StorageWidget for callbacks
|
||||
static StorageWidget* activeWidget = nullptr;
|
||||
|
||||
StorageWidget::StorageWidget(QWidget* parent)
|
||||
: QWidget(parent), isStorageInitialized(false), m_isStorageRunning(false), m_logosAPI(nullptr) {
|
||||
|
||||
// Set as the active widget
|
||||
activeWidget = this;
|
||||
|
||||
m_logosAPI = new LogosAPI("core", this);
|
||||
logos = new LogosModules(m_logosAPI);
|
||||
|
||||
// mainLayout = new QVBoxLayout(this);
|
||||
// quickWidget = new QQuickWidget(this);
|
||||
// quickWidget->rootContext()->setContextProperty("storage", this);
|
||||
// quickWidget->setSource(QUrl("qrc:StorageWidget.qml"));
|
||||
// mainLayout->addWidget(quickWidget);
|
||||
|
||||
// // Main vertical layout
|
||||
mainLayout = new QVBoxLayout(this);
|
||||
|
||||
// Create status label
|
||||
statusLayout = new QHBoxLayout();
|
||||
statusLabel = new QLabel("Status: Not initialized", this);
|
||||
statusLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
|
||||
statusLabel->setLineWidth(1);
|
||||
statusLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
statusLabel->setMinimumHeight(30);
|
||||
statusLayout->addWidget(statusLabel, 4);
|
||||
|
||||
startButton = new QPushButton("Start", this);
|
||||
statusLayout->addWidget(startButton, 1);
|
||||
|
||||
debugButton = new QPushButton("Debug", this);
|
||||
statusLayout->addWidget(debugButton, 1);
|
||||
// Create display
|
||||
// storageDisplay = new QTextEdit(this);
|
||||
// storageDisplay->setReadOnly(true);
|
||||
// storageDisplay->setMinimumHeight(300);
|
||||
|
||||
// Create input layout
|
||||
// inputLayout = new QHBoxLayout();
|
||||
// messageInput = new QLineEdit(this);
|
||||
// messageInput->setPlaceholderText("Type your message here...");
|
||||
// sendButton = new QPushButton("Send", this);
|
||||
|
||||
// inputLayout->addWidget(messageInput, 4);
|
||||
// inputLayout->addWidget(sendButton, 1);
|
||||
|
||||
// Add all components to main layout
|
||||
mainLayout->addLayout(statusLayout);
|
||||
// mainLayout->addWidget(storageDisplay);
|
||||
// mainLayout->addLayout(inputLayout);
|
||||
|
||||
// Set spacing and margins
|
||||
mainLayout->setSpacing(10);
|
||||
mainLayout->setContentsMargins(20, 20, 20, 20);
|
||||
|
||||
// Connect signals to slots
|
||||
connect(startButton, &QPushButton::clicked, this, &StorageWidget::onStartButtonClicked);
|
||||
connect(debugButton, &QPushButton::clicked, this, &StorageWidget::onDebugButtonClicked);
|
||||
|
||||
// connect(messageInput, &QLineEdit::returnPressed, this, &StorageWidget::onStartButtonClicked);
|
||||
|
||||
// Disable UI components until Storage is initialized
|
||||
// messageInput->setEnabled(false);
|
||||
// sendButton->setEnabled(false);
|
||||
startButton->setEnabled(false);
|
||||
debugButton->setEnabled(false);
|
||||
|
||||
// Auto-initialize Storage
|
||||
initStorage();
|
||||
}
|
||||
|
||||
StorageWidget::~StorageWidget() {
|
||||
// Reset the active widget if it's this instance
|
||||
if (activeWidget == this) {
|
||||
activeWidget = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void StorageWidget::initStorage() {
|
||||
updateStatus("Initializing Storage...");
|
||||
emit storageRunningChanged();
|
||||
response = logos->storage_module.init("{}");
|
||||
|
||||
qDebug() << "StorageWidget: Storage module init response:" << response;
|
||||
|
||||
isStorageInitialized = true;
|
||||
m_isStorageRunning = false;
|
||||
|
||||
updateStatus("Storage initialized.");
|
||||
|
||||
if (!logos->storage_module.on("storageStart", [this](const QVariantList& data) {
|
||||
int code = data[0].toInt();
|
||||
|
||||
if (code != RET_OK) {
|
||||
updateStatus("Error starting Storage.");
|
||||
} else {
|
||||
updateStatus("Storage started successfully.");
|
||||
m_isStorageRunning = true;
|
||||
startButton->setText("Stop");
|
||||
// messageInput->setEnabled(true);
|
||||
// sendButton->setEnabled(true);
|
||||
}
|
||||
|
||||
startButton->setEnabled(true);
|
||||
debugButton->setEnabled(true);
|
||||
})) {
|
||||
qWarning() << "StorageWidget: failed to subscribe to storageStart events";
|
||||
}
|
||||
|
||||
if (!logos->storage_module.on("storageStop", [this](const QVariantList& data) {
|
||||
int code = data[0].toInt();
|
||||
|
||||
if (code != RET_OK) {
|
||||
updateStatus("Error stopping Storage.");
|
||||
} else {
|
||||
updateStatus("Storage stopped successfully.");
|
||||
m_isStorageRunning = false;
|
||||
startButton->setText("Start");
|
||||
// messageInput->setEnabled(false);
|
||||
// sendButton->setEnabled(false);
|
||||
}
|
||||
|
||||
startButton->setEnabled(true);
|
||||
|
||||
emit storageStop();
|
||||
})) {
|
||||
qWarning() << "StorageWidget: failed to subscribe to storageStop events";
|
||||
}
|
||||
|
||||
startStorage();
|
||||
// if (!storageModule.on("storageVersion", [this]
|
||||
// std::string version = data[1].toString().toStdString();(const QVariantList& data) {
|
||||
// qDebug() << "Storage Version:" << QString::fromStdString(version);
|
||||
// })) {
|
||||
// qWarning() << "ChatWidget: failed to subscribe to historyMessage events";
|
||||
// }
|
||||
// if (!storageModule.on("storageVersion", [this]
|
||||
// std::string version = data[1].toString().toStdString();(const QVariantList& data) {
|
||||
// qDebug() << "Storage Version:" << QString::fromStdString(version);
|
||||
// })) {
|
||||
// qWarning() << "ChatWidget: failed to subscribe to historyMessage events";
|
||||
// }
|
||||
}
|
||||
|
||||
QString StorageWidget::storageVersion() const {
|
||||
if (!isStorageInitialized) {
|
||||
qDebug() << "StorageWidget: Storage not initialized, cannot get version.";
|
||||
return "";
|
||||
}
|
||||
|
||||
return logos->storage_module.version();
|
||||
}
|
||||
|
||||
QString StorageWidget::storageDebug() const {
|
||||
if (!isStorageInitialized) {
|
||||
qDebug() << "StorageWidget: Storage not initialized, cannot get debug info.";
|
||||
return "";
|
||||
}
|
||||
|
||||
return logos->storage_module.debug();
|
||||
}
|
||||
|
||||
void StorageWidget::startStorage() {
|
||||
updateStatus("Starting Storage...");
|
||||
|
||||
if (!isStorageInitialized) {
|
||||
qDebug() << "StorageWidget: Storage not initialized, nothing to start.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isStorageRunning) {
|
||||
qDebug() << "StorageWidget: Storage already started.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!logos->storage_module.start()) {
|
||||
qWarning() << "StorageWidget: Failed to send start command to Storage.";
|
||||
} else {
|
||||
qDebug() << "StorageWidget: Start command sent to Storage.";
|
||||
}
|
||||
}
|
||||
|
||||
void StorageWidget::stopStorage() {
|
||||
if (!isStorageInitialized) {
|
||||
qDebug() << "StorageWidget: Storage not initialized, nothing to stop.";
|
||||
emit storageStop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_isStorageRunning) {
|
||||
qDebug() << "StorageWidget: Storage already stopped.";
|
||||
emit storageStop();
|
||||
return;
|
||||
}
|
||||
|
||||
updateStatus("Stopping Storage...");
|
||||
|
||||
if (!logos->storage_module.stop()) {
|
||||
qWarning() << "StorageWidget: Failed to send stop command to Storage.";
|
||||
} else {
|
||||
qDebug() << "StorageWidget: Stop command sent to Storage.";
|
||||
}
|
||||
}
|
||||
|
||||
void StorageWidget::destroy() {
|
||||
qDebug() << "StorageWidget: destroy function called...";
|
||||
|
||||
if (!isStorageInitialized) {
|
||||
qDebug() << "StorageWidget: Storage not initialized, nothing to stop.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!logos->storage_module.destroy()) {
|
||||
qWarning() << "StorageWidget: Failed to send destroy command to Storage.";
|
||||
} else {
|
||||
qDebug() << "StorageWidget: Destroy command sent to Storage.";
|
||||
}
|
||||
|
||||
qDebug() << "StorageWidget: Emitting storageCleanup signal.";
|
||||
|
||||
emit storageCleanup();
|
||||
}
|
||||
|
||||
void StorageWidget::onStartButtonClicked() {
|
||||
qDebug() << "Starting Storage from button";
|
||||
|
||||
startButton->setEnabled(false);
|
||||
|
||||
if (m_isStorageRunning) {
|
||||
stopStorage();
|
||||
} else {
|
||||
startStorage();
|
||||
}
|
||||
}
|
||||
|
||||
void StorageWidget::onDebugButtonClicked() {
|
||||
qDebug() << "version" << logos->storage_module.version();
|
||||
qDebug() << "spr" << logos->storage_module.spr();
|
||||
qDebug() << "peerId" << logos->storage_module.peerId();
|
||||
|
||||
logos->storage_module.updateLogLevel("TRACE");
|
||||
|
||||
qDebug() << "Debug button clicked";
|
||||
emit debug();
|
||||
}
|
||||
|
||||
void StorageWidget::onSendButtonClicked() {
|
||||
QString message = messageInput->text().trimmed();
|
||||
if (message.isEmpty()) {
|
||||
QMessageBox::warning(this, "Storage Error", "Message is empty.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if Storage is running
|
||||
if (!m_isStorageRunning) {
|
||||
QMessageBox::warning(this, "Storage Error", "Storage is not running. Please initialize Storage first.");
|
||||
return;
|
||||
}
|
||||
|
||||
// if (m_logosAPI && m_logosAPI->getClient("storage")->isConnected())
|
||||
// {
|
||||
|
||||
// logos->storage_module.storageVersion();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qDebug() << "LogosAPI not connected";
|
||||
// }
|
||||
|
||||
qDebug() << "LogosAPI not connected!!";
|
||||
|
||||
// Clear input field
|
||||
messageInput->clear();
|
||||
}
|
||||
|
||||
void StorageWidget::updateStatus(const QString& message) {
|
||||
statusLabel->setText(message);
|
||||
qDebug() << "StorageWidget Status:" << message;
|
||||
}
|
||||
|
||||
void StorageWidget::displayMessage(const QString& sender, const QString& message) {
|
||||
QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
|
||||
QString formattedMessage = QString("[%1] %2: %3").arg(timestamp, sender, message);
|
||||
storageDisplay->append(formattedMessage);
|
||||
}
|
||||
|
||||
QString StorageWidget::statusText() const { return m_statusText; }
|
||||
bool StorageWidget::storageRunning() const { return m_isStorageRunning; }
|
||||
|
||||
void StorageWidget::requestDebug() { emit debug(); }
|
||||
@ -1,85 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "logos_api.h"
|
||||
#include "logos_api_client.h"
|
||||
#include "logos_sdk.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
// #include <QQuickWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <string>
|
||||
|
||||
using StringCallback = std::function<void(int, const std::string&)>;
|
||||
|
||||
class StorageWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged)
|
||||
Q_PROPERTY(bool storageRunning READ storageRunning NOTIFY storageRunningChanged)
|
||||
|
||||
public:
|
||||
explicit StorageWidget(QWidget* parent = nullptr);
|
||||
~StorageWidget();
|
||||
|
||||
Q_INVOKABLE void requestDebug();
|
||||
|
||||
QString statusText() const;
|
||||
bool storageRunning() const;
|
||||
|
||||
// Storage operations
|
||||
Q_INVOKABLE void initStorage();
|
||||
Q_INVOKABLE void startStorage();
|
||||
Q_INVOKABLE void stopStorage();
|
||||
Q_INVOKABLE QString storageVersion() const;
|
||||
Q_INVOKABLE QString storageDebug() const;
|
||||
Q_INVOKABLE void destroy();
|
||||
|
||||
private slots:
|
||||
void onSendButtonClicked();
|
||||
void onStartButtonClicked();
|
||||
void onDebugButtonClicked();
|
||||
|
||||
private:
|
||||
// UI elements
|
||||
// QQuickWidget* quickWidget;
|
||||
QString m_statusText;
|
||||
|
||||
QVBoxLayout* mainLayout;
|
||||
QHBoxLayout* inputLayout;
|
||||
QHBoxLayout* statusLayout;
|
||||
QHBoxLayout* channelLayout;
|
||||
|
||||
QTextEdit* storageDisplay;
|
||||
QLineEdit* messageInput;
|
||||
QLineEdit* channelInput;
|
||||
QPushButton* sendButton;
|
||||
QPushButton* startButton;
|
||||
QPushButton* debugButton;
|
||||
QLabel* statusLabel;
|
||||
|
||||
// LogosAPI instance for remote method calls
|
||||
LogosAPI* m_logosAPI;
|
||||
LogosModules* logos;
|
||||
|
||||
// Connection status
|
||||
bool isStorageInitialized;
|
||||
bool m_isStorageRunning;
|
||||
QString currentPubSubTopic;
|
||||
QString currentChannel;
|
||||
bool response;
|
||||
|
||||
// Helper methods
|
||||
void updateStatus(const QString& message);
|
||||
void displayMessage(const QString& sender, const QString& message);
|
||||
void emitEvent(const QString& eventName, const QVariantList& data);
|
||||
|
||||
signals:
|
||||
void storageCleanup();
|
||||
void storageStop();
|
||||
void debug();
|
||||
void statusTextChanged();
|
||||
void storageRunningChanged();
|
||||
};
|
||||
@ -1,75 +0,0 @@
|
||||
#include "StorageWindow.h"
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
|
||||
StorageWindow::StorageWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
// Create central widget
|
||||
storageWidget = new StorageWidget(this);
|
||||
setCentralWidget(storageWidget);
|
||||
|
||||
// Setup the UI
|
||||
// setupMenu();
|
||||
setupStatusBar();
|
||||
|
||||
// Set window properties
|
||||
setMinimumSize(640, 480);
|
||||
|
||||
// connect(stor, &StorageWindow::onDebugButtonClicked, this, [this] {
|
||||
// debugDock->show();
|
||||
// debugDock->raise();
|
||||
// debugDock->setFocus();
|
||||
// });
|
||||
}
|
||||
|
||||
StorageWindow::~StorageWindow() {
|
||||
// StorageWidget will be deleted automatically as it's a child of this window
|
||||
}
|
||||
|
||||
void StorageWindow::setupStatusBar() {
|
||||
statusBar = new QStatusBar(this);
|
||||
setStatusBar(statusBar);
|
||||
statusBar->showMessage("Ready");
|
||||
}
|
||||
|
||||
void StorageWindow::onAboutAction() {
|
||||
QMessageBox::about(this, "About Logos Storage",
|
||||
"Logos Storage Application\n\n"
|
||||
"A sample Qt application demonstrating Storage integration.");
|
||||
}
|
||||
|
||||
void StorageWindow::onInitStorage() {
|
||||
qDebug() << "Initializing Storage from menu";
|
||||
storageWidget->initStorage();
|
||||
statusBar->showMessage("Storage initialization requested");
|
||||
}
|
||||
|
||||
// void StorageWindow::onStopStorage() {
|
||||
// qDebug() << "Stopping Storage from menu";
|
||||
// // storageWidget->stopStorage();
|
||||
// statusBar->showMessage("Storage stop requested");
|
||||
// }
|
||||
|
||||
// void StorageWindow::showAbout() {
|
||||
// QString version;
|
||||
|
||||
// qDebug() << "StorageWindow: Retrieving Storage version for About Dialog...";
|
||||
|
||||
// QMetaObject::invokeMethod(storageWidget, "storageVersion", Qt::DirectConnection, Q_RETURN_ARG(QString, version));
|
||||
|
||||
// qDebug() << "StorageWindow: Showing About Dialog, version:" << version;
|
||||
// AboutDialog dlg(this, version);
|
||||
// dlg.exec();
|
||||
// }
|
||||
|
||||
// void MainWindow::showDebug() {
|
||||
// QString debug;
|
||||
|
||||
// qDebug() << "MainWindow: Retrieving Storage debug for Debug Dialog...";
|
||||
|
||||
// QMetaObject::invokeMethod(storageWidget, "storageDebug", Qt::DirectConnection, Q_RETURN_ARG(QString, debug));
|
||||
|
||||
// qDebug() << "MainWindow: Showing Debug Dialog, debug:" << debug;
|
||||
// DebugDialog dlg(this, debug);
|
||||
// dlg.exec();
|
||||
// }
|
||||
@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "StorageWidget.h"
|
||||
#include <QMainWindow>
|
||||
#include <QMenuBar>
|
||||
#include <QStatusBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class StorageWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit StorageWindow(QWidget* parent = nullptr);
|
||||
~StorageWindow();
|
||||
|
||||
private slots:
|
||||
void onAboutAction();
|
||||
void onInitStorage();
|
||||
|
||||
private:
|
||||
void setupStatusBar();
|
||||
|
||||
StorageWidget* storageWidget;
|
||||
QStatusBar* statusBar;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user