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();
|
||||
}
|
||||
|
||||
}
|
|
@ -40,7 +40,7 @@ private slots:
|
|||
void updateDisplayInfo(const QString &saveName);
|
||||
void rebuildComboBoxList();
|
||||
private:
|
||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel, *saveLabel;
|
||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel, *saveLabel, *publicServersLabel;
|
||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit, *saveEdit;
|
||||
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
||||
QComboBox *previousHosts;
|
||||
|
@ -48,5 +48,4 @@ private:
|
|||
QPushButton *btnOk, *btnCancel, *btnForgotPassword;
|
||||
QMap<QString, UserConnection_Information> savedHostList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -93,20 +93,14 @@ QString ServersSettings::getPlayerName(QString defaultName)
|
|||
return name == QVariant() ? defaultName : name.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setPassword(QString password)
|
||||
{
|
||||
setValue(password, "password", "server");
|
||||
}
|
||||
|
||||
QString ServersSettings::getPassword()
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
return getValue(QString("password%1").arg(index), "server", "server_details").toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setSavePassword(int save)
|
||||
{
|
||||
setValue(save, "save_password", "server");
|
||||
if (getSavePassword())
|
||||
return getValue(QString("password%1").arg(index), "server", "server_details").toString();
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool ServersSettings::getSavePassword()
|
||||
|
@ -116,6 +110,16 @@ bool ServersSettings::getSavePassword()
|
|||
return save;
|
||||
}
|
||||
|
||||
void ServersSettings::setPassword(QString password)
|
||||
{
|
||||
setValue(password, "password", "server");
|
||||
}
|
||||
|
||||
void ServersSettings::setSavePassword(int save)
|
||||
{
|
||||
setValue(save, "save_password", "server");
|
||||
}
|
||||
|
||||
void ServersSettings::setAutoConnect(int autoconnect)
|
||||
{
|
||||
setValue(autoconnect, "auto_connect", "server");
|
||||
|
@ -171,9 +175,9 @@ void ServersSettings::addNewServer(QString saveName, QString serv, QString port,
|
|||
setValue(serv, QString("server%1").arg(index), "server", "server_details");
|
||||
setValue(port, QString("port%1").arg(index), "server", "server_details");
|
||||
setValue(username, QString("username%1").arg(index), "server", "server_details");
|
||||
setValue(password, QString("password%1").arg(index), "server", "server_details");
|
||||
setValue(savePassword, QString("savePassword%1").arg(index), "server", "server_details");
|
||||
setValue(index, "totalServers", "server", "server_details");
|
||||
setValue(password, QString("password%1").arg(index), "server", "server_details");
|
||||
|
||||
}
|
||||
|
||||
|
@ -188,8 +192,8 @@ bool ServersSettings::updateExistingServer(QString saveName, QString serv, QStri
|
|||
setValue(serv, QString("server%1").arg(i), "server", "server_details");
|
||||
setValue(port, QString("port%1").arg(i), "server", "server_details");
|
||||
setValue(username, QString("username%1").arg(i), "server", "server_details");
|
||||
setValue(password, QString("password%1").arg(i), "server", "server_details");
|
||||
setValue(savePassword, QString("savePassword%1").arg(i), "server", "server_details");
|
||||
setValue(password, QString("password%1").arg(i), "server", "server_details");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,15 +28,14 @@ public:
|
|||
void setPreviousHostLogin(int previous);
|
||||
void setPrevioushostName(const QString &);
|
||||
void setPreviousHostList(QStringList list);
|
||||
void setPrevioushostindex(int index);
|
||||
void setHostName(QString hostname);
|
||||
void setPort(QString port);
|
||||
void setPlayerName(QString playerName);
|
||||
void setPassword(QString password);
|
||||
void setSavePassword(int save);
|
||||
void setAutoConnect(int autoconnect);
|
||||
void setFPHostName(QString hostname);
|
||||
void setPassword(QString password);
|
||||
void setFPPort(QString port);
|
||||
void setSavePassword(int save);
|
||||
void setFPPlayerName(QString playerName);
|
||||
void addNewServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword);
|
||||
bool updateExistingServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword);
|
||||
|
|
Loading…
Reference in a new issue