From c92abc355a92ad8e272f2cf356a5fe18fac64a00 Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Fri, 8 Dec 2023 00:28:42 +0100 Subject: [PATCH] connect dialog: added auto connect option (enabled by default) --- client/src/dialog/connectdialog.cpp | 17 ++++++++++++++++- client/src/dialog/connectdialog.hpp | 4 +++- client/src/settings/generalsettings.hpp | 4 +++- client/src/settings/generalsettingswidget.cpp | 2 ++ shared/translations/en-us.json | 4 ++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/client/src/dialog/connectdialog.cpp b/client/src/dialog/connectdialog.cpp index d405be5f..d7f9f919 100644 --- a/client/src/dialog/connectdialog.cpp +++ b/client/src/dialog/connectdialog.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2021 Reinder Feenstra + * Copyright (C) 2019-2021,2023 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,12 +26,14 @@ #include #include #include +#include #include #include #include #include #include "../network/connection.hpp" #include "../network/object.hpp" +#include "../settings/generalsettings.hpp" #include ConnectDialog::ConnectDialog(QWidget* parent, const QString& url) : @@ -41,6 +43,7 @@ ConnectDialog::ConnectDialog(QWidget* parent, const QString& url) : m_server{new QComboBox()}, m_username{new QLineEdit()}, m_password{new QLineEdit()}, + m_connectAutomatically{new QCheckBox(Locale::tr("qtapp.settings.general:connect_automatically_to_discovered_server"))}, m_status{new QLabel()}, m_connect{new QPushButton(Locale::tr("qtapp.connect_dialog:connect"))} { @@ -52,6 +55,13 @@ ConnectDialog::ConnectDialog(QWidget* parent, const QString& url) : m_password->setEchoMode(QLineEdit::Password); + m_connectAutomatically->setChecked(GeneralSettings::instance().connectAutomaticallyToDiscoveredServer.value()); + connect(m_connectAutomatically, &QCheckBox::stateChanged, this, + [](int state) + { + GeneralSettings::instance().connectAutomaticallyToDiscoveredServer.setValue(state == Qt::Checked); + }); + m_status->setAlignment(Qt::AlignCenter); m_status->setMinimumWidth(400); @@ -62,6 +72,7 @@ ConnectDialog::ConnectDialog(QWidget* parent, const QString& url) : formLayout->addRow(Locale::tr("qtapp.connect_dialog:username"), m_username); formLayout->addRow(Locale::tr("qtapp.connect_dialog:password"), m_password); */ + formLayout->addRow("", m_connectAutomatically); QVBoxLayout* layout = new QVBoxLayout(); layout->addLayout(formLayout); @@ -147,6 +158,10 @@ void ConnectDialog::socketReadyRead() { m_servers[url] = {name, defaultTTL}; m_server->addItem(url.host() + (url.port() != Connection::defaultPort ? ":" + QString::number(url.port()) : "") + " (" + name + ")", url); + if(m_connectAutomatically->isChecked() && m_connect->isEnabled()) + { + m_connect->click(); + } } else it->second = defaultTTL; diff --git a/client/src/dialog/connectdialog.hpp b/client/src/dialog/connectdialog.hpp index 89e4af95..ab369acf 100644 --- a/client/src/dialog/connectdialog.hpp +++ b/client/src/dialog/connectdialog.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2021 Reinder Feenstra + * Copyright (C) 2019-2021,2023 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,6 +33,7 @@ class QUdpSocket; class QComboBox; class QLineEdit; +class QCheckBox; class QLabel; class QPushButton; class Connection; @@ -51,6 +52,7 @@ class ConnectDialog : public QDialog QComboBox* m_server; QLineEdit* m_username; QLineEdit* m_password; + QCheckBox* m_connectAutomatically; QLabel* m_status; QPushButton* m_connect; QUrl m_url; diff --git a/client/src/settings/generalsettings.hpp b/client/src/settings/generalsettings.hpp index 0487ee83..2ca1fcdb 100644 --- a/client/src/settings/generalsettings.hpp +++ b/client/src/settings/generalsettings.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2021 Reinder Feenstra + * Copyright (C) 2021,2023 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,6 +32,7 @@ class GeneralSettings : public SettingsBase GeneralSettings() : SettingsBase("general_") // "general" is special in Qt!! , language{*this, "language", "en-us"} + , connectAutomaticallyToDiscoveredServer{*this, "connect_automatically_to_discovered_server", true} { } @@ -43,6 +44,7 @@ class GeneralSettings : public SettingsBase } Setting language; + Setting connectAutomaticallyToDiscoveredServer; }; #endif diff --git a/client/src/settings/generalsettingswidget.cpp b/client/src/settings/generalsettingswidget.cpp index 09743772..beaf74fe 100644 --- a/client/src/settings/generalsettingswidget.cpp +++ b/client/src/settings/generalsettingswidget.cpp @@ -73,5 +73,7 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget* parent) add(s.language.name(), cb); } + addSetting(s.connectAutomaticallyToDiscoveredServer); + done(); } diff --git a/shared/translations/en-us.json b/shared/translations/en-us.json index 949f6239..4724de2b 100644 --- a/shared/translations/en-us.json +++ b/shared/translations/en-us.json @@ -4382,5 +4382,9 @@ { "term": "traintastic_diy_settings:startup_delay", "definition": "Startup delay" + }, + { + "term": "qtapp.settings.general:connect_automatically_to_discovered_server", + "definition": "Connect automatically to discovered server" } ] \ No newline at end of file