chatgui: add Status page in settings (NTP + connections status)
This commit is contained in:
1 parent
f0bb03c2cf
commit
960cde3eda
15 files changed
+651
-62
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include "settingsdialog.h"
|
||||
#include "networksettingspage.h"
|
||||
#include "databasesettingspage.h"
|
||||
#include "statuspage.h"
|
||||
#include "../transport/gui_bridge.h"
|
||||
#include "../../lib/mem.h"
|
||||
#include "../db/db_manager.h"
|
||||
@@ -40,6 +41,7 @@ SettingsDialog::SettingsDialog(const QString& configPath, DbManager* db, QWidget
|
||||
m_categoryList->addItem("Profile");
|
||||
m_categoryList->addItem("Network");
|
||||
m_categoryList->addItem("Database");
|
||||
m_categoryList->addItem("Status");
|
||||
mainLayout->addWidget(m_categoryList);
|
||||
|
||||
// --- Right panel: stacked pages ---
|
||||
@@ -71,6 +73,10 @@ SettingsDialog::SettingsDialog(const QString& configPath, DbManager* db, QWidget
|
||||
// Database page
|
||||
m_databasePage = new DatabaseSettingsPage(db, m_pages);
|
||||
m_pages->addWidget(m_databasePage);
|
||||
|
||||
// Status page
|
||||
m_statusPage = new StatusPage(m_pages);
|
||||
m_pages->addWidget(m_statusPage);
|
||||
rightLayout->addWidget(m_pages, 1);
|
||||
|
||||
// --- Bottom buttons ---
|
||||
@@ -127,6 +133,7 @@ void SettingsDialog::loadProfileFromConfig(const QString& path) {
|
||||
|
||||
void SettingsDialog::onCategoryChanged(int row) {
|
||||
m_pages->setCurrentIndex(row);
|
||||
if (row == 3) m_statusPage->refreshStatus();
|
||||
}
|
||||
|
||||
void SettingsDialog::onSave() {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
class NetworkSettingsPage;
|
||||
class DatabaseSettingsPage;
|
||||
class StatusPage;
|
||||
class DbManager;
|
||||
|
||||
class SettingsDialog : public QDialog {
|
||||
@@ -32,4 +33,5 @@ private:
|
||||
QString m_oldNickname;
|
||||
NetworkSettingsPage* m_networkPage;
|
||||
DatabaseSettingsPage* m_databasePage;
|
||||
StatusPage* m_statusPage;
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
// statuspage.cpp — Status page (NTP + connections) in settings
|
||||
#include "statuspage.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../transport/gui_bridge.h"
|
||||
#include "../transport/chat_core.h"
|
||||
}
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QFont>
|
||||
|
||||
static StatusPage* g_activeStatusPage = nullptr;
|
||||
|
||||
static void statusRefreshCallback(const char* text, int len) {
|
||||
if (g_activeStatusPage)
|
||||
g_activeStatusPage->setText(QString::fromUtf8(text, len));
|
||||
}
|
||||
|
||||
StatusPage::StatusPage(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
auto* layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(8);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
auto* title = new QLabel("System Status", this);
|
||||
title->setStyleSheet("font-weight: bold; font-size: 13px;");
|
||||
layout->addWidget(title);
|
||||
|
||||
m_textEdit = new QPlainTextEdit(this);
|
||||
m_textEdit->setReadOnly(true);
|
||||
m_textEdit->setFont(QFont("monospace", 10));
|
||||
m_textEdit->setStyleSheet(
|
||||
"QPlainTextEdit { border: 1px solid palette(mid); border-radius: 4px;"
|
||||
" padding: 8px; background: palette(base); }");
|
||||
m_textEdit->setPlaceholderText("Click Refresh to load status");
|
||||
layout->addWidget(m_textEdit, 1);
|
||||
|
||||
auto* btnLayout = new QHBoxLayout();
|
||||
btnLayout->addStretch();
|
||||
m_refreshBtn = new QPushButton("Refresh", this);
|
||||
m_refreshBtn->setFixedWidth(90);
|
||||
m_refreshBtn->setStyleSheet(
|
||||
"QPushButton { border: 1px solid palette(mid); border-radius: 4px;"
|
||||
" padding: 6px 16px; font-size: 13px; background: palette(button); }"
|
||||
"QPushButton:hover { background: palette(light); }");
|
||||
connect(m_refreshBtn, &QPushButton::clicked, this, &StatusPage::onRefreshClicked);
|
||||
btnLayout->addWidget(m_refreshBtn);
|
||||
layout->addLayout(btnLayout);
|
||||
|
||||
g_activeStatusPage = this;
|
||||
gui_bridge_set_status_refresh_cb(statusRefreshCallback);
|
||||
}
|
||||
|
||||
StatusPage::~StatusPage() {
|
||||
if (g_activeStatusPage == this) g_activeStatusPage = nullptr;
|
||||
}
|
||||
|
||||
void StatusPage::refreshStatus() {
|
||||
m_textEdit->setPlainText("Loading...");
|
||||
gui_bridge_post_uasync_fn(chat_core_collect_status_trampoline, NULL);
|
||||
}
|
||||
|
||||
void StatusPage::onRefreshClicked() {
|
||||
refreshStatus();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// statuspage.h — Status page (NTP + connections) in settings
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
class StatusPage : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StatusPage(QWidget* parent = nullptr);
|
||||
~StatusPage() override;
|
||||
void refreshStatus();
|
||||
void setText(const QString& text) { m_textEdit->setPlainText(text); }
|
||||
|
||||
private slots:
|
||||
void onRefreshClicked();
|
||||
|
||||
private:
|
||||
QPlainTextEdit* m_textEdit;
|
||||
QPushButton* m_refreshBtn;
|
||||
};
|
||||
Reference in new issue
Block a user