|
|
|
|
@ -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", |
|
|
|
|
|