- u_async.c: process immediate_queue BEFORE epoll_wait in uasync_poll - stcp_link.c: defensive NULL etcp_conn/etcp_link in stcp_link_close - utun_instance.c: move stcp_server_list_destroy_all to Phase J (before ETCP), add deferred drain in both Phase J and L - stcp.h/c: STCP_HS_ENC_CLIENT 6→38, STCP_HS_ENC_SERVER 7→39, exchange ed25519_pubkey in both handshake directions - etcp_connections.c: copy peer_ed25519 from STCP to ETCP_CONN in etcp_link_enter_ready_tcp; guard link->etcp in tcp_link_close_cb - chat_sync.c: fix lk->conn NULL dereference for TCP links - test_stcp.c: update stcp_server_create/stcp_client_connect callsites - tools/chat_tcp_test: change transport udp→tcp
93 lines
3.1 KiB
C++
93 lines
3.1 KiB
C++
#include "renamedialog.h"
|
|
#include "../db/db_manager.h"
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
|
|
RenameDialog::RenameDialog(DbManager* db, const QString& channelId,
|
|
quint64 nodeId, const QString& displayName,
|
|
QWidget* parent)
|
|
: QDialog(parent)
|
|
, m_db(db)
|
|
, m_channelId(channelId)
|
|
, m_nodeId(nodeId)
|
|
{
|
|
setWindowTitle("Rename");
|
|
setMinimumWidth(300);
|
|
setModal(true);
|
|
|
|
QString curNick;
|
|
if (m_db->m_db) {
|
|
QString tbl = m_db->peersTableName(channelId);
|
|
QByteArray sql = QString(
|
|
"SELECT local_nick FROM \"%1\" WHERE node_id=?"
|
|
).arg(tbl).toUtf8();
|
|
sqlite3_stmt* st = nullptr;
|
|
if (sqlite3_prepare_v2(m_db->m_db, sql.constData(), -1, &st, nullptr) == SQLITE_OK) {
|
|
sqlite3_bind_int64(st, 1, (sqlite3_int64)nodeId);
|
|
if (sqlite3_step(st) == SQLITE_ROW)
|
|
curNick = DbManager::colText(st, 0);
|
|
sqlite3_finalize(st);
|
|
}
|
|
}
|
|
|
|
auto* layout = new QVBoxLayout(this);
|
|
layout->setSpacing(12);
|
|
layout->setContentsMargins(20, 16, 20, 16);
|
|
|
|
auto* title = new QLabel(displayName, this);
|
|
title->setStyleSheet("font-weight: bold; font-size: 13px;");
|
|
layout->addWidget(title);
|
|
|
|
m_edit = new QLineEdit(this);
|
|
m_edit->setText(curNick);
|
|
m_edit->setPlaceholderText(displayName);
|
|
layout->addWidget(m_edit);
|
|
|
|
layout->addStretch();
|
|
|
|
auto* btnLayout = new QHBoxLayout();
|
|
btnLayout->addStretch();
|
|
|
|
auto* cancelBtn = new QPushButton("Cancel", this);
|
|
cancelBtn->setFixedWidth(90);
|
|
cancelBtn->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(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
|
|
btnLayout->addWidget(cancelBtn);
|
|
|
|
auto* saveBtn = new QPushButton("Save", this);
|
|
saveBtn->setFixedWidth(90);
|
|
saveBtn->setDefault(true);
|
|
saveBtn->setStyleSheet(
|
|
"QPushButton { border: none; border-radius: 4px;"
|
|
" padding: 6px 16px; font-size: 13px; font-weight: bold;"
|
|
" background: #3390EC; color: white; }"
|
|
"QPushButton:hover { background: #2B7ED4; }");
|
|
connect(saveBtn, &QPushButton::clicked, this, &RenameDialog::onSave);
|
|
btnLayout->addWidget(saveBtn);
|
|
|
|
layout->addLayout(btnLayout);
|
|
}
|
|
|
|
void RenameDialog::onSave() {
|
|
if (!m_db->m_db) return;
|
|
QString tbl = m_db->peersTableName(m_channelId);
|
|
QString nick = m_edit->text().trimmed();
|
|
QByteArray sql = QString(
|
|
"UPDATE \"%1\" SET local_nick=? WHERE node_id=?"
|
|
).arg(tbl).toUtf8();
|
|
sqlite3_stmt* st = nullptr;
|
|
if (sqlite3_prepare_v2(m_db->m_db, sql.constData(), -1, &st, nullptr) == SQLITE_OK) {
|
|
sqlite3_bind_text(st, 1, nick.isEmpty() ? nullptr : nick.toUtf8().constData(),
|
|
-1, nick.isEmpty() ? SQLITE_STATIC : SQLITE_TRANSIENT);
|
|
sqlite3_bind_int64(st, 2, (sqlite3_int64)m_nodeId);
|
|
sqlite3_step(st);
|
|
sqlite3_finalize(st);
|
|
}
|
|
accept();
|
|
}
|