Browse Source

Add nickname setup on the first ChatGUI launch

master
evgeny 3 days ago
parent
commit
91620cec4e
  1. 57
      tools/chatgui/src/main.cpp
  2. 6
      tools/chatgui/translations/chatgui_en.ts
  3. 6
      tools/chatgui/translations/chatgui_ru.ts

57
tools/chatgui/src/main.cpp

@ -11,8 +11,15 @@
#include <QLockFile>
#include <QMessageBox>
#include <QTranslator>
#include <QDialogButtonBox>
#include <QHostInfo>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include "gui_language.h"
#include "call_camera_capture.h"
#include "config_parser.h"
#include <cstdio>
#include <cstring>
#include <cerrno>
@ -200,9 +207,51 @@ int main(int argc, char *argv[]) {
}
bool needSave = false;
if (!cfg.exists()) {
if (!cfg.create("", 1333)) {
qCritical("Failed to create config: %s", qPrintable(cfgPath));
const bool firstRun = !cfg.exists();
if (firstRun) {
QDialog wizard;
wizard.setWindowTitle(QCoreApplication::translate("ChatGui", "Welcome to vibechat"));
wizard.setMinimumWidth(380);
auto* layout = new QVBoxLayout(&wizard);
layout->addWidget(new QLabel(QCoreApplication::translate("ChatGui", "Your nickname:"), &wizard));
auto* nickname = new QLineEdit(&wizard);
nickname->setMaxLength(32);
const QString host = QHostInfo::localHostName();
nickname->setText(host.isEmpty() ? QStringLiteral("vibechat") : host);
layout->addWidget(nickname);
auto* hint = new QLabel(QCoreApplication::translate("ChatGui", "Others will see this name. You can change it later in Settings."), &wizard);
hint->setWordWrap(true);
layout->addWidget(hint);
layout->addSpacing(12);
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Cancel, &wizard);
auto* start = buttons->addButton(QCoreApplication::translate("ChatGui", "Start chatting"), QDialogButtonBox::AcceptRole);
start->setDefault(true);
layout->addWidget(buttons);
QObject::connect(nickname, &QLineEdit::textChanged, &wizard, [start](const QString& text) {
start->setEnabled(!text.trimmed().isEmpty());
});
QObject::connect(buttons, &QDialogButtonBox::accepted, &wizard, [&wizard, nickname] {
const QByteArray name = nickname->text().trimmed().toUtf8();
if (name.size() >= MAX_CONN_NAME_LEN) {
DEBUG_WARN(DEBUG_CATEGORY_CONFIG, "First-run setup: nickname too long, bytes=%d limit=%d", int(name.size()), MAX_CONN_NAME_LEN - 1);
QMessageBox::warning(&wizard, wizard.windowTitle(),
QCoreApplication::translate("ChatGui", "This nickname is too long. Please choose a shorter one."));
return;
}
wizard.accept();
});
QObject::connect(buttons, &QDialogButtonBox::rejected, &wizard, &QDialog::reject);
nickname->setFocus();
nickname->selectAll();
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "First-run setup: requesting nickname, config=%s", qPrintable(cfgPath));
if (wizard.exec() != QDialog::Accepted) {
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "First-run setup: cancelled, config not created");
return 0;
}
if (!cfg.create(nickname->text().trimmed(), 1333)) {
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "First-run setup: failed to create config=%s", qPrintable(cfgPath));
QMessageBox::critical(nullptr, wizard.windowTitle(),
QCoreApplication::translate("ChatGui", "Failed to save your profile. Check that the data folder is writable."));
return 1;
}
} else {
@ -245,6 +294,8 @@ int main(int argc, char *argv[]) {
if (lvl.isEmpty()) lvl = QStringLiteral("info");
debug_apply_global_level(lvl.toUtf8().constData());
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "vibechat: version=%s", qPrintable(app.applicationVersion()));
if (firstRun)
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "First-run setup: profile saved, nickname=%s config=%s", qPrintable(cfg.nodeName()), qPrintable(cfgPath));
#ifdef _WIN32
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "Windows console: attached=%d", consoleAttached);
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Windows storage: reason=%s config=%s db=%s log=%s lock=%s",

6
tools/chatgui/translations/chatgui_en.ts

@ -3,6 +3,12 @@
<TS version="2.1" language="en_US" sourcelanguage="en_US">
<context>
<name>ChatGui</name>
<message><source>Welcome to vibechat</source><translation>Welcome to vibechat</translation></message>
<message><source>Your nickname:</source><translation>Your nickname:</translation></message>
<message><source>Others will see this name. You can change it later in Settings.</source><translation>Others will see this name. You can change it later in Settings.</translation></message>
<message><source>Start chatting</source><translation>Start chatting</translation></message>
<message><source>This nickname is too long. Please choose a shorter one.</source><translation>This nickname is too long. Please choose a shorter one.</translation></message>
<message><source>Failed to save your profile. Check that the data folder is writable.</source><translation>Failed to save your profile. Check that the data folder is writable.</translation></message>
<message><source>Broadcast</source><translation>Broadcast</translation></message>
<message><source>Total subblocks:</source><translation>Total subblocks:</translation></message>
<message><source>Redundant RS subblocks:</source><translation>Redundant RS subblocks:</translation></message>

6
tools/chatgui/translations/chatgui_ru.ts

@ -3,6 +3,12 @@
<TS version="2.1" language="ru_RU" sourcelanguage="en_US">
<context>
<name>ChatGui</name>
<message><source>Welcome to vibechat</source><translation>Добро пожаловать в vibechat</translation></message>
<message><source>Your nickname:</source><translation>Ваш ник:</translation></message>
<message><source>Others will see this name. You can change it later in Settings.</source><translation>Это имя увидят другие участники. Его можно изменить позже в настройках.</translation></message>
<message><source>Start chatting</source><translation>Начать общение</translation></message>
<message><source>This nickname is too long. Please choose a shorter one.</source><translation>Этот ник слишком длинный. Выберите имя покороче.</translation></message>
<message><source>Failed to save your profile. Check that the data folder is writable.</source><translation>Не удалось сохранить профиль. Проверьте, доступна ли папка данных для записи.</translation></message>
<message><source>Broadcast</source><translation>Трансляция</translation></message>
<message><source>Total subblocks:</source><translation>Всего субблоков:</translation></message>
<message><source>Redundant RS subblocks:</source><translation>Избыточных субблоков RS:</translation></message>

Loading…
Cancel
Save