mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
changes to connection dialog (#2503)
This commit is contained in:
parent
b5b9527c13
commit
4feb43cdcc
4 changed files with 61 additions and 30 deletions
|
|
@ -3,23 +3,23 @@
|
|||
#include <QComboBox>
|
||||
#include <QRadioButton>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QMessageBox>
|
||||
#include <iostream>
|
||||
#include <QGroupBox>
|
||||
#include <QPushButton>
|
||||
#include "dlg_connect.h"
|
||||
#include "settingscache.h"
|
||||
#include "userconnection_information.h"
|
||||
|
||||
#define PUBLIC_SERVERS_URL "https://github.com/Cockatrice/Cockatrice/wiki/Public-Servers"
|
||||
|
||||
DlgConnect::DlgConnect(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
previousHostButton = new QRadioButton(tr("Previous Host"), this);
|
||||
previousHostButton = new QRadioButton(tr("Known Hosts"), this);
|
||||
previousHosts = new QComboBox(this);
|
||||
previousHosts->installEventFilter(new DeleteHighlightedItemWhenShiftDelPressedEventFilter);
|
||||
|
||||
|
|
@ -54,6 +54,14 @@ DlgConnect::DlgConnect(QWidget *parent)
|
|||
autoConnectCheckBox = new QCheckBox(tr("A&uto connect"));
|
||||
autoConnectCheckBox->setToolTip(tr("Automatically connect to the most recent login when Cockatrice opens"));
|
||||
|
||||
publicServersLabel = new QLabel(tr("(<a href=\"%1\">Public Servers</a>)").arg(PUBLIC_SERVERS_URL));
|
||||
publicServersLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||
publicServersLabel->setWordWrap(true);
|
||||
publicServersLabel->setTextFormat(Qt::RichText);
|
||||
publicServersLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
publicServersLabel->setOpenExternalLinks(true);
|
||||
publicServersLabel->setAlignment(Qt::AlignCenter);
|
||||
|
||||
if (savePasswordCheckBox->isChecked())
|
||||
{
|
||||
autoConnectCheckBox->setChecked(settingsCache->servers().getAutoConnect());
|
||||
|
|
@ -79,10 +87,14 @@ DlgConnect::DlgConnect(QWidget *parent)
|
|||
btnCancel->setFixedWidth(100);
|
||||
connect(btnCancel, SIGNAL(released()), this, SLOT(actCancel()));
|
||||
|
||||
QGridLayout *newHostLayout = new QGridLayout;
|
||||
newHostLayout->addWidget(newHostButton, 0, 1);
|
||||
newHostLayout->addWidget(publicServersLabel, 0, 2);
|
||||
|
||||
QGridLayout *connectionLayout = new QGridLayout;
|
||||
connectionLayout->addWidget(previousHostButton, 0, 1);
|
||||
connectionLayout->addWidget(previousHosts, 1, 1);
|
||||
connectionLayout->addWidget(newHostButton, 2, 1);
|
||||
connectionLayout->addLayout(newHostLayout, 2, 1, 1, 2);
|
||||
connectionLayout->addWidget(saveLabel, 3, 0);
|
||||
connectionLayout->addWidget(saveEdit, 3, 1);
|
||||
connectionLayout->addWidget(hostLabel, 4, 0);
|
||||
|
|
@ -155,10 +167,10 @@ void DlgConnect::rebuildComboBoxList()
|
|||
|
||||
if (savedHostList.size() == 1)
|
||||
{
|
||||
settingsCache->servers().addNewServer("Woogerworks Cockatrice", "cockatrice.woogerworks.com", "4747", "", "", false);
|
||||
settingsCache->servers().addNewServer("Chickatrice Cockatrice", "chickatrice.net", "4747", "", "", false);
|
||||
settingsCache->servers().addNewServer("Cockatric.es Cockatrice", "cockatric.es", "4747", "", "", false);
|
||||
settingsCache->servers().addNewServer("Tetrarch Cockatrice", "mtg.tetrarch.co", "4747", "", "", false);
|
||||
settingsCache->servers().addNewServer("Woogerworks", "cockatrice.woogerworks.com", "4747", "", "", false);
|
||||
settingsCache->servers().addNewServer("Chickatrice", "chickatrice.net", "4747", "", "", false);
|
||||
settingsCache->servers().addNewServer("cockatric.es", "cockatric.es", "4747", "", "", false);
|
||||
settingsCache->servers().addNewServer("Tetrarch", "mtg.tetrarch.co", "4747", "", "", false);
|
||||
}
|
||||
savedHostList = uci.getServerInfo();
|
||||
|
||||
|
|
@ -181,6 +193,7 @@ void DlgConnect::rebuildComboBoxList()
|
|||
|
||||
void DlgConnect::previousHostSelected(bool state) {
|
||||
if (state) {
|
||||
saveEdit->setDisabled(true);
|
||||
previousHosts->setDisabled(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -192,21 +205,31 @@ void DlgConnect::updateDisplayInfo(const QString &saveName)
|
|||
|
||||
if (saveEdit == nullptr)
|
||||
return;
|
||||
|
||||
bool savePasswordStatus = data.at(5) == "1";
|
||||
|
||||
saveEdit->setText(data.at(0));
|
||||
hostEdit->setText(data.at(1));
|
||||
portEdit->setText(data.at(2));
|
||||
playernameEdit->setText(data.at(3));
|
||||
passwordEdit->setText(data.at(4));
|
||||
savePasswordCheckBox->setChecked(data.at(5) == "1" ? true : false);
|
||||
savePasswordCheckBox->setChecked(savePasswordStatus);
|
||||
|
||||
if (savePasswordStatus)
|
||||
passwordEdit->setText(data.at(4));
|
||||
}
|
||||
|
||||
void DlgConnect::newHostSelected(bool state) {
|
||||
if (state)
|
||||
{
|
||||
previousHosts->setDisabled(true);
|
||||
hostEdit->clear();
|
||||
portEdit->clear();
|
||||
playernameEdit->clear();
|
||||
passwordEdit->clear();
|
||||
savePasswordCheckBox->setChecked(false);
|
||||
saveEdit->clear();
|
||||
saveEdit->setPlaceholderText("New Menu Name");
|
||||
saveEdit->setDisabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -229,7 +252,15 @@ void DlgConnect::passwordSaved(int state)
|
|||
void DlgConnect::actOk()
|
||||
{
|
||||
if (newHostButton->isChecked())
|
||||
{
|
||||
if (saveEdit->text().isEmpty())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Connection Warning"), tr("You need to name your new connection profile."));
|
||||
return;
|
||||
}
|
||||
|
||||
settingsCache->servers().addNewServer(saveEdit->text(), hostEdit->text(), portEdit->text(), playernameEdit->text(), passwordEdit->text(), savePasswordCheckBox->isChecked());
|
||||
}
|
||||
else
|
||||
settingsCache->servers().updateExistingServer(saveEdit->text(), hostEdit->text(), portEdit->text(), playernameEdit->text(), passwordEdit->text(), savePasswordCheckBox->isChecked());
|
||||
|
||||
|
|
@ -257,7 +288,6 @@ void DlgConnect::actCancel()
|
|||
reject();
|
||||
}
|
||||
|
||||
|
||||
bool DeleteHighlightedItemWhenShiftDelPressedEventFilter::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
|
|
@ -275,5 +305,4 @@ void DlgConnect::actForgotPassword()
|
|||
{
|
||||
emit sigStartForgotPasswordRequest();
|
||||
reject();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue