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
@@ -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();
|
||||
}
|
||||
Reference in new issue
Block a user