chatgui: preserve active channel selection on reload, members sync, profile settings, member list model
This commit is contained in:
1 parent
c3f946fb63
commit
d70cdbb040
28 files changed
+1895
-91
No files matched your search
@@ -1,10 +1,19 @@
|
||||
// settingsdialog.cpp — Settings dialog with category list
|
||||
#include "settingsdialog.h"
|
||||
#include "networksettingspage.h"
|
||||
#include "../transport/gui_bridge.h"
|
||||
#include "../../lib/mem.h"
|
||||
extern "C" {
|
||||
#include "../transport/chat_core.h"
|
||||
}
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
SettingsDialog::SettingsDialog(const QString& configPath, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
@@ -26,6 +35,7 @@ SettingsDialog::SettingsDialog(const QString& configPath, QWidget* parent)
|
||||
" background: palette(window); font-size: 13px; }"
|
||||
"QListWidget::item { padding: 10px 14px; }"
|
||||
"QListWidget::item:selected { background: #3390EC; color: white; }");
|
||||
m_categoryList->addItem("Profile");
|
||||
m_categoryList->addItem("Network");
|
||||
mainLayout->addWidget(m_categoryList);
|
||||
|
||||
@@ -36,6 +46,22 @@ SettingsDialog::SettingsDialog(const QString& configPath, QWidget* parent)
|
||||
rightLayout->setSpacing(0);
|
||||
|
||||
m_pages = new QStackedWidget(rightPanel);
|
||||
|
||||
// Profile page
|
||||
auto* profilePage = new QWidget(m_pages);
|
||||
auto* profLayout = new QFormLayout(profilePage);
|
||||
profLayout->setContentsMargins(0, 12, 0, 0);
|
||||
auto* nameLabel = new QLabel("Display name:", profilePage);
|
||||
m_nicknameEdit = new QLineEdit(profilePage);
|
||||
m_nicknameEdit->setPlaceholderText("Your name (shown to others)");
|
||||
m_nicknameEdit->setMaxLength(32);
|
||||
m_nicknameEdit->setStyleSheet(
|
||||
"QLineEdit { border: 1px solid palette(mid); border-radius: 4px;"
|
||||
" padding: 6px 10px; font-size: 13px; background: palette(base); }");
|
||||
profLayout->addRow(nameLabel, m_nicknameEdit);
|
||||
m_pages->addWidget(profilePage);
|
||||
|
||||
// Network page
|
||||
m_networkPage = new NetworkSettingsPage(m_pages);
|
||||
m_pages->addWidget(m_networkPage);
|
||||
rightLayout->addWidget(m_pages, 1);
|
||||
@@ -71,15 +97,68 @@ SettingsDialog::SettingsDialog(const QString& configPath, QWidget* parent)
|
||||
connect(m_categoryList, &QListWidget::currentRowChanged,
|
||||
this, &SettingsDialog::onCategoryChanged);
|
||||
|
||||
// Load current values
|
||||
loadProfileFromConfig(m_configPath);
|
||||
m_networkPage->loadFromConfig(m_configPath);
|
||||
m_categoryList->setCurrentRow(0);
|
||||
}
|
||||
|
||||
void SettingsDialog::loadProfileFromConfig(const QString& path) {
|
||||
QFile f(path);
|
||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) return;
|
||||
QTextStream in(&f);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine().trimmed();
|
||||
if (line.startsWith("my_node_name=")) {
|
||||
QString nm = line.mid(QString("my_node_name=").size()).trimmed();
|
||||
m_nicknameEdit->setText(nm);
|
||||
m_oldNickname = nm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::onCategoryChanged(int row) {
|
||||
m_pages->setCurrentIndex(row);
|
||||
}
|
||||
|
||||
void SettingsDialog::onSave() {
|
||||
QString newName = m_nicknameEdit->text().trimmed();
|
||||
|
||||
/* update name in uTun if changed */
|
||||
if (newName != m_oldNickname) {
|
||||
char* name_copy = u_strdup(newName.toUtf8().constData());
|
||||
if (name_copy) gui_bridge_post_uasync_fn(chat_core_update_my_name_trampoline, name_copy);
|
||||
m_oldNickname = newName;
|
||||
}
|
||||
|
||||
// Save nickname to config
|
||||
QFile f(m_configPath);
|
||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { accept(); return; }
|
||||
QString content = f.readAll();
|
||||
f.close();
|
||||
|
||||
QTextStream ts(&content);
|
||||
QStringList lines;
|
||||
while (!ts.atEnd()) lines << ts.readLine();
|
||||
|
||||
bool found = false;
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
if (lines[i].trimmed().startsWith("my_node_name=")) {
|
||||
lines[i] = "my_node_name=" + newName;
|
||||
found = true;
|
||||
} else if (!found && lines[i].trimmed().startsWith("[gui]")) {
|
||||
// insert before [gui] if not found yet
|
||||
lines.insert(i, "my_node_name=" + newName);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) lines << "my_node_name=" + newName;
|
||||
|
||||
f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
f.write(lines.join('\n').toUtf8());
|
||||
f.close();
|
||||
|
||||
m_networkPage->saveToConfig(m_configPath);
|
||||
accept();
|
||||
}
|
||||
Reference in new issue
Block a user