connect dialog: added auto connect option (enabled by default)

Dieser Commit ist enthalten in:
Reinder Feenstra 2023-12-08 00:28:42 +01:00
Ursprung 7e690d1fce
Commit c92abc355a
5 geänderte Dateien mit 28 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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 <QFormLayout>
#include <QComboBox>
#include <QLineEdit>
#include <QCheckBox>
#include <QLabel>
#include <QPushButton>
#include <QUrl>
#include <QTimer>
#include "../network/connection.hpp"
#include "../network/object.hpp"
#include "../settings/generalsettings.hpp"
#include <traintastic/locale/locale.hpp>
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;

Datei anzeigen

@ -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;

Datei anzeigen

@ -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<QString> language;
Setting<bool> connectAutomaticallyToDiscoveredServer;
};
#endif

Datei anzeigen

@ -73,5 +73,7 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget* parent)
add(s.language.name(), cb);
}
addSetting(s.connectAutomaticallyToDiscoveredServer);
done();
}

Datei anzeigen

@ -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"
}
]