chatgui: fix NodesPage truncated Node ID + add DB diagnostics
- NodesPage: show full 64-bit Node ID (hex16) instead of truncated 4 hex chars - NodesPage: show diagnostic when DB handle is NULL (was silent return) - DatabaseSettingsPage: show 'Database not connected' when DB handle is NULL - DatabaseSettingsPage: add refreshStatus() called on tab select - SettingsDialog: refresh Database tab on category change
This commit is contained in:
1 parent
e41d40ca4b
commit
e5ef007f79
4 files changed
+55
-5
No files matched your search
@@ -127,6 +127,48 @@ DatabaseSettingsPage::DatabaseSettingsPage(DbManager* db, QWidget* parent)
|
||||
layout->addWidget(m_resultText);
|
||||
|
||||
layout->addStretch();
|
||||
|
||||
if (!m_db || !m_db->m_db) {
|
||||
m_statusLabel->setText("Database not connected");
|
||||
m_statusLabel->setStyleSheet("font-size: 12px; font-weight: bold; color: red;");
|
||||
m_quickBtn->setEnabled(false);
|
||||
m_fullBtn->setEnabled(false);
|
||||
m_optimizeBtn->setEnabled(false);
|
||||
qWarning("DatabaseSettingsPage: DB not ready m_db=%p m_db->m_db=%p", (void*)m_db, m_db ? (void*)m_db->m_db : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseSettingsPage::refreshStatus() {
|
||||
if (!m_db || !m_db->m_db) {
|
||||
m_statusLabel->setText("Database not connected");
|
||||
m_statusLabel->setStyleSheet("font-size: 12px; font-weight: bold; color: red;");
|
||||
m_quickBtn->setEnabled(false);
|
||||
m_fullBtn->setEnabled(false);
|
||||
m_optimizeBtn->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
m_quickBtn->setEnabled(true);
|
||||
m_fullBtn->setEnabled(true);
|
||||
m_optimizeBtn->setEnabled(true);
|
||||
const char* fname = sqlite3_db_filename(m_db->m_db, "main");
|
||||
if (fname && fname[0]) {
|
||||
QString dbPath = QString::fromUtf8(fname);
|
||||
m_filePathLabel->setText(dbPath);
|
||||
QFileInfo fi(dbPath);
|
||||
if (fi.exists()) {
|
||||
qint64 sz = fi.size();
|
||||
if (sz < 1024) m_fileSizeLabel->setText(QString("%1 B").arg(sz));
|
||||
else if (sz < 1024 * 1024) m_fileSizeLabel->setText(QString("%1 KB").arg(sz / 1024));
|
||||
else m_fileSizeLabel->setText(QString("%1 MB").arg(sz / (1024.0 * 1024.0), 0, 'f', 2));
|
||||
QFileInfo walFi(dbPath + "-wal");
|
||||
if (walFi.exists()) {
|
||||
qint64 wsz = walFi.size();
|
||||
if (wsz < 1024) m_walSizeLabel->setText(QString("%1 B").arg(wsz));
|
||||
else if (wsz < 1024 * 1024) m_walSizeLabel->setText(QString("%1 KB").arg(wsz / 1024));
|
||||
else m_walSizeLabel->setText(QString("%1 MB").arg(wsz / (1024.0 * 1024.0), 0, 'f', 2));
|
||||
} else { m_walSizeLabel->setText("n/a"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseSettingsPage::setBusy(bool busy) {
|
||||
|
||||
@@ -12,6 +12,7 @@ class DatabaseSettingsPage : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DatabaseSettingsPage(DbManager* db, QWidget* parent = nullptr);
|
||||
void refreshStatus();
|
||||
|
||||
private slots:
|
||||
void onQuickCheck();
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
#include "../../../lib/platform_compat.h"
|
||||
|
||||
static QString hex4(uint32_t v) {
|
||||
return QString("%1").arg(v, 4, 16, QChar('0')).toUpper();
|
||||
static QString hex16(uint64_t v) {
|
||||
return QString("%1").arg(v, 16, 16, QChar('0')).toUpper();
|
||||
}
|
||||
|
||||
QString NodesPage::shortenKey(const QByteArray& key) {
|
||||
@@ -106,7 +106,13 @@ NodesPage::NodesPage(DbManager* db, QWidget* parent)
|
||||
void NodesPage::onRefreshClicked() { refreshNodes(); }
|
||||
|
||||
void NodesPage::refreshNodes() {
|
||||
if (!m_db || !m_db->m_db) return;
|
||||
if (!m_db || !m_db->m_db) {
|
||||
m_table->setRowCount(0);
|
||||
m_dumpText->setPlainText(QString("Database not connected (m_db=%1, m_db->m_db=%2)")
|
||||
.arg((quintptr)m_db, 0, 16).arg(m_db ? (quintptr)m_db->m_db : 0, 0, 16));
|
||||
qWarning("NodesPage::refreshNodes: DB not ready m_db=%p m_db->m_db=%p", (void*)m_db, m_db ? (void*)m_db->m_db : nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
sqlite3* d = m_db->m_db;
|
||||
|
||||
@@ -128,7 +134,7 @@ void NodesPage::refreshNodes() {
|
||||
m_table->setItem(row, col, new QTableWidgetItem(v));
|
||||
};
|
||||
|
||||
setCell(0, hex4((uint32_t)(nid & 0xFFFF)));
|
||||
setCell(0, hex16(nid));
|
||||
setCell(1, DbManager::colText(st, 1));
|
||||
setCell(2, sqlite3_column_int(st, 2) ? "yes" : "no");
|
||||
|
||||
@@ -176,7 +182,7 @@ void NodesPage::refreshNodes() {
|
||||
qint64 last_seen = sqlite3_column_int64(st, 5);
|
||||
qint64 created = sqlite3_column_int64(st, 6);
|
||||
|
||||
dump += QString("Node: %1").arg(hex4((uint32_t)(nid & 0xFFFF)));
|
||||
dump += QString("Node: %1").arg(hex16(nid));
|
||||
if (!name.isEmpty()) dump += QString(" (%1)").arg(name);
|
||||
dump += QString(" id=0x%1\n").arg(nid, 16, 16, QChar('0'));
|
||||
dump += QString(" online: %1\n").arg(online ? "yes" : "no");
|
||||
|
||||
@@ -139,6 +139,7 @@ void SettingsDialog::loadProfileFromConfig(const QString& path) {
|
||||
|
||||
void SettingsDialog::onCategoryChanged(int row) {
|
||||
m_pages->setCurrentIndex(row);
|
||||
if (row == 2) m_databasePage->refreshStatus();
|
||||
if (row == 3) m_statusPage->refreshStatus();
|
||||
if (row == 4) m_nodesPage->refreshNodes();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user