diff --git a/tools/chatgui/src/main.cpp b/tools/chatgui/src/main.cpp index 905e7e6c..611da1a8 100644 --- a/tools/chatgui/src/main.cpp +++ b/tools/chatgui/src/main.cpp @@ -11,8 +11,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "gui_language.h" #include "call_camera_capture.h" +#include "config_parser.h" #include #include #include @@ -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", diff --git a/tools/chatgui/translations/chatgui_en.ts b/tools/chatgui/translations/chatgui_en.ts index 5ff35de2..164350f5 100644 --- a/tools/chatgui/translations/chatgui_en.ts +++ b/tools/chatgui/translations/chatgui_en.ts @@ -3,6 +3,12 @@ ChatGui + Welcome to vibechatWelcome to vibechat + Your nickname:Your nickname: + Others will see this name. You can change it later in Settings.Others will see this name. You can change it later in Settings. + Start chattingStart chatting + This nickname is too long. Please choose a shorter one.This nickname is too long. Please choose a shorter one. + Failed to save your profile. Check that the data folder is writable.Failed to save your profile. Check that the data folder is writable. BroadcastBroadcast Total subblocks:Total subblocks: Redundant RS subblocks:Redundant RS subblocks: diff --git a/tools/chatgui/translations/chatgui_ru.ts b/tools/chatgui/translations/chatgui_ru.ts index d54c8f76..d0209b87 100644 --- a/tools/chatgui/translations/chatgui_ru.ts +++ b/tools/chatgui/translations/chatgui_ru.ts @@ -3,6 +3,12 @@ ChatGui + Welcome to vibechatДобро пожаловать в vibechat + Your nickname:Ваш ник: + Others will see this name. You can change it later in Settings.Это имя увидят другие участники. Его можно изменить позже в настройках. + Start chattingНачать общение + This nickname is too long. Please choose a shorter one.Этот ник слишком длинный. Выберите имя покороче. + Failed to save your profile. Check that the data folder is writable.Не удалось сохранить профиль. Проверьте, доступна ли папка данных для записи. BroadcastТрансляция Total subblocks:Всего субблоков: Redundant RS subblocks:Избыточных субблоков RS: