Server Connect Remade (#2452)
* Save multiple server configurations * Each server has its own password/port storage Close #2452
This commit is contained in:
parent
37b43f9916
commit
4cfcca33db
9 changed files with 280 additions and 58 deletions
|
@ -115,6 +115,7 @@ SET(cockatrice_SOURCES
|
||||||
src/update_downloader.cpp
|
src/update_downloader.cpp
|
||||||
src/logger.cpp
|
src/logger.cpp
|
||||||
src/releasechannel.cpp
|
src/releasechannel.cpp
|
||||||
|
src/userconnection_information.cpp
|
||||||
${VERSION_STRING_CPP}
|
${VERSION_STRING_CPP}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include "dlg_connect.h"
|
#include "dlg_connect.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
|
#include "userconnection_information.h"
|
||||||
|
|
||||||
DlgConnect::DlgConnect(QWidget *parent)
|
DlgConnect::DlgConnect(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
@ -22,21 +23,16 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
previousHosts = new QComboBox(this);
|
previousHosts = new QComboBox(this);
|
||||||
previousHosts->installEventFilter(new DeleteHighlightedItemWhenShiftDelPressedEventFilter);
|
previousHosts->installEventFilter(new DeleteHighlightedItemWhenShiftDelPressedEventFilter);
|
||||||
|
|
||||||
QStringList previousHostList = settingsCache->servers().getPreviousHostList();
|
rebuildComboBoxList();
|
||||||
if (previousHostList.isEmpty()) {
|
|
||||||
previousHostList << "cockatrice.woogerworks.com";
|
|
||||||
previousHostList << "chickatrice.net";
|
|
||||||
previousHostList << "mtg.tetrarch.co";
|
|
||||||
previousHostList << "cockatric.es";
|
|
||||||
}
|
|
||||||
previousHosts->addItems(previousHostList);
|
|
||||||
previousHosts->setCurrentIndex(settingsCache->servers().getPrevioushostindex());
|
|
||||||
|
|
||||||
newHostButton = new QRadioButton(tr("New Host"), this);
|
newHostButton = new QRadioButton(tr("New Host"), this);
|
||||||
|
|
||||||
|
saveLabel = new QLabel(tr("Name:"));
|
||||||
|
saveEdit = new QLineEdit(settingsCache->servers().getSaveName());
|
||||||
|
saveLabel->setBuddy(saveEdit);
|
||||||
|
|
||||||
hostLabel = new QLabel(tr("&Host:"));
|
hostLabel = new QLabel(tr("&Host:"));
|
||||||
hostEdit = new QLineEdit();
|
hostEdit = new QLineEdit(settingsCache->servers().getHostname());
|
||||||
hostEdit->setPlaceholderText(tr("Enter host name"));
|
|
||||||
hostLabel->setBuddy(hostEdit);
|
hostLabel->setBuddy(hostEdit);
|
||||||
|
|
||||||
portLabel = new QLabel(tr("&Port:"));
|
portLabel = new QLabel(tr("&Port:"));
|
||||||
|
@ -58,11 +54,13 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
autoConnectCheckBox = new QCheckBox(tr("A&uto connect"));
|
autoConnectCheckBox = new QCheckBox(tr("A&uto connect"));
|
||||||
autoConnectCheckBox->setToolTip(tr("Automatically connect to the most recent login when Cockatrice opens"));
|
autoConnectCheckBox->setToolTip(tr("Automatically connect to the most recent login when Cockatrice opens"));
|
||||||
|
|
||||||
if(savePasswordCheckBox->isChecked())
|
if (savePasswordCheckBox->isChecked())
|
||||||
{
|
{
|
||||||
autoConnectCheckBox->setChecked(settingsCache->servers().getAutoConnect());
|
autoConnectCheckBox->setChecked(settingsCache->servers().getAutoConnect());
|
||||||
autoConnectCheckBox->setEnabled(true);
|
autoConnectCheckBox->setEnabled(true);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
settingsCache->servers().setAutoConnect(0);
|
settingsCache->servers().setAutoConnect(0);
|
||||||
autoConnectCheckBox->setChecked(0);
|
autoConnectCheckBox->setChecked(0);
|
||||||
autoConnectCheckBox->setEnabled(false);
|
autoConnectCheckBox->setEnabled(false);
|
||||||
|
@ -85,11 +83,13 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
connectionLayout->addWidget(previousHostButton, 0, 1);
|
connectionLayout->addWidget(previousHostButton, 0, 1);
|
||||||
connectionLayout->addWidget(previousHosts, 1, 1);
|
connectionLayout->addWidget(previousHosts, 1, 1);
|
||||||
connectionLayout->addWidget(newHostButton, 2, 1);
|
connectionLayout->addWidget(newHostButton, 2, 1);
|
||||||
connectionLayout->addWidget(hostLabel, 3, 0);
|
connectionLayout->addWidget(saveLabel, 3, 0);
|
||||||
connectionLayout->addWidget(hostEdit, 3, 1);
|
connectionLayout->addWidget(saveEdit, 3, 1);
|
||||||
connectionLayout->addWidget(portLabel, 4, 0);
|
connectionLayout->addWidget(hostLabel, 4, 0);
|
||||||
connectionLayout->addWidget(portEdit, 4, 1);
|
connectionLayout->addWidget(hostEdit, 4, 1);
|
||||||
connectionLayout->addWidget(autoConnectCheckBox, 5, 1);
|
connectionLayout->addWidget(portLabel, 5, 0);
|
||||||
|
connectionLayout->addWidget(portEdit, 5, 1);
|
||||||
|
connectionLayout->addWidget(autoConnectCheckBox, 6, 1);
|
||||||
|
|
||||||
QGridLayout *buttons = new QGridLayout;
|
QGridLayout *buttons = new QGridLayout;
|
||||||
buttons->addWidget(btnOk, 0, 0);
|
buttons->addWidget(btnOk, 0, 0);
|
||||||
|
@ -132,24 +132,85 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
previousHostButton->setChecked(true);
|
previousHostButton->setChecked(true);
|
||||||
else
|
else
|
||||||
newHostButton->setChecked(true);
|
newHostButton->setChecked(true);
|
||||||
|
|
||||||
|
connect(previousHosts, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(updateDisplayInfo(const QString &)));
|
||||||
|
|
||||||
playernameEdit->setFocus();
|
playernameEdit->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgConnect::actSaveConfig()
|
||||||
|
{
|
||||||
|
if (!settingsCache->servers().updateExistingServer(saveEdit->text(), hostEdit->text(), portEdit->text(), playernameEdit->text(), passwordEdit->text(), savePasswordCheckBox->isChecked()))
|
||||||
|
settingsCache->servers().addNewServer(saveEdit->text(), hostEdit->text(), portEdit->text(), playernameEdit->text(), passwordEdit->text(), savePasswordCheckBox->isChecked());
|
||||||
|
|
||||||
|
rebuildComboBoxList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DlgConnect::rebuildComboBoxList()
|
||||||
|
{
|
||||||
|
previousHosts->clear();
|
||||||
|
|
||||||
|
UserConnection_Information uci;
|
||||||
|
savedHostList = uci.getServerInfo();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
savedHostList = uci.getServerInfo();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (UserConnection_Information tmp, savedHostList)
|
||||||
|
{
|
||||||
|
QString saveName = tmp.getSaveName();
|
||||||
|
if (saveName.size())
|
||||||
|
{
|
||||||
|
previousHosts->addItem(saveName);
|
||||||
|
|
||||||
|
if (settingsCache->servers().getPrevioushostName() == saveName)
|
||||||
|
previousHosts->setCurrentIndex(i);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DlgConnect::previousHostSelected(bool state) {
|
void DlgConnect::previousHostSelected(bool state) {
|
||||||
if (state) {
|
if (state) {
|
||||||
hostLabel->setDisabled(true);
|
|
||||||
hostEdit->setDisabled(true);
|
|
||||||
previousHosts->setDisabled(false);
|
previousHosts->setDisabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgConnect::updateDisplayInfo(const QString &saveName)
|
||||||
|
{
|
||||||
|
UserConnection_Information uci;
|
||||||
|
QStringList data = uci.getServerInfo(saveName);
|
||||||
|
|
||||||
|
if (saveEdit == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void DlgConnect::newHostSelected(bool state) {
|
void DlgConnect::newHostSelected(bool state) {
|
||||||
if (state) {
|
if (state)
|
||||||
hostEdit->setDisabled(false);
|
{
|
||||||
hostLabel->setDisabled(false);
|
|
||||||
previousHosts->setDisabled(true);
|
previousHosts->setDisabled(true);
|
||||||
|
saveEdit->clear();
|
||||||
|
saveEdit->setPlaceholderText("New Menu Name");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rebuildComboBoxList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,26 +228,15 @@ void DlgConnect::passwordSaved(int state)
|
||||||
|
|
||||||
void DlgConnect::actOk()
|
void DlgConnect::actOk()
|
||||||
{
|
{
|
||||||
settingsCache->servers().setPort(portEdit->text());
|
|
||||||
settingsCache->servers().setPlayerName(playernameEdit->text());
|
|
||||||
settingsCache->servers().setPassword(savePasswordCheckBox->isChecked() ? passwordEdit->text() : QString());
|
|
||||||
settingsCache->servers().setSavePassword(savePasswordCheckBox->isChecked() ? 1 : 0);
|
|
||||||
settingsCache->servers().setAutoConnect(autoConnectCheckBox->isChecked() ? 1 : 0);
|
|
||||||
settingsCache->servers().setPreviousHostLogin(previousHostButton->isChecked() ? 1 : 0);
|
|
||||||
|
|
||||||
QStringList hostList;
|
|
||||||
if (newHostButton->isChecked())
|
if (newHostButton->isChecked())
|
||||||
if (!hostEdit->text().trimmed().isEmpty())
|
settingsCache->servers().addNewServer(saveEdit->text(), hostEdit->text(), portEdit->text(), playernameEdit->text(), passwordEdit->text(), savePasswordCheckBox->isChecked());
|
||||||
hostList << hostEdit->text();
|
else
|
||||||
|
settingsCache->servers().updateExistingServer(saveEdit->text(), hostEdit->text(), portEdit->text(), playernameEdit->text(), passwordEdit->text(), savePasswordCheckBox->isChecked());
|
||||||
for (int i = 0; i < previousHosts->count(); i++)
|
|
||||||
if(!previousHosts->itemText(i).trimmed().isEmpty())
|
|
||||||
hostList << previousHosts->itemText(i);
|
|
||||||
|
|
||||||
settingsCache->servers().setPreviousHostList(hostList);
|
|
||||||
settingsCache->servers().setPrevioushostindex(previousHosts->currentIndex());
|
|
||||||
|
|
||||||
if(playernameEdit->text().isEmpty())
|
settingsCache->servers().setPrevioushostName(saveEdit->text());
|
||||||
|
settingsCache->servers().setAutoConnect(autoConnectCheckBox->isChecked() ? 1 : 0);
|
||||||
|
|
||||||
|
if (playernameEdit->text().isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Connect Warning"), tr("The player name can't be empty."));
|
QMessageBox::critical(this, tr("Connect Warning"), tr("The player name can't be empty."));
|
||||||
return;
|
return;
|
||||||
|
@ -197,7 +247,7 @@ void DlgConnect::actOk()
|
||||||
|
|
||||||
|
|
||||||
QString DlgConnect::getHost() const {
|
QString DlgConnect::getHost() const {
|
||||||
return previousHostButton->isChecked() ? previousHosts->currentText() : hostEdit->text();
|
return hostEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgConnect::actCancel()
|
void DlgConnect::actCancel()
|
||||||
|
@ -225,4 +275,5 @@ void DlgConnect::actForgotPassword()
|
||||||
{
|
{
|
||||||
emit sigStartForgotPasswordRequest();
|
emit sigStartForgotPasswordRequest();
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef DLG_CONNECT_H
|
#ifndef DLG_CONNECT_H
|
||||||
#define DLG_CONNECT_H
|
#define DLG_CONNECT_H
|
||||||
|
|
||||||
|
#include "userconnection_information.h"
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
@ -31,17 +32,21 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void actOk();
|
void actOk();
|
||||||
void actCancel();
|
void actCancel();
|
||||||
|
void actSaveConfig();
|
||||||
void passwordSaved(int state);
|
void passwordSaved(int state);
|
||||||
void previousHostSelected(bool state);
|
void previousHostSelected(bool state);
|
||||||
void newHostSelected(bool state);
|
void newHostSelected(bool state);
|
||||||
void actForgotPassword();
|
void actForgotPassword();
|
||||||
|
void updateDisplayInfo(const QString &saveName);
|
||||||
|
void rebuildComboBoxList();
|
||||||
private:
|
private:
|
||||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel, *saveLabel;
|
||||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit, *saveEdit;
|
||||||
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
||||||
QComboBox *previousHosts;
|
QComboBox *previousHosts;
|
||||||
QRadioButton *newHostButton, *previousHostButton;
|
QRadioButton *newHostButton, *previousHostButton;
|
||||||
QPushButton *btnOk, *btnCancel, *btnForgotPassword;
|
QPushButton *btnOk, *btnCancel, *btnForgotPassword;
|
||||||
|
QMap<QString, UserConnection_Information> savedHostList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "serverssettings.h"
|
#include "serverssettings.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
ServersSettings::ServersSettings(QString settingPath, QObject *parent)
|
ServersSettings::ServersSettings(QString settingPath, QObject *parent)
|
||||||
: SettingsManager(settingPath+"servers.ini", parent)
|
: SettingsManager(settingPath+"servers.ini", parent)
|
||||||
|
@ -26,14 +27,32 @@ QStringList ServersSettings::getPreviousHostList()
|
||||||
return getValue("previoushosts", "server").toStringList();
|
return getValue("previoushosts", "server").toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersSettings::setPrevioushostindex(int index)
|
void ServersSettings::setPrevioushostName(const QString &name)
|
||||||
{
|
{
|
||||||
setValue(index, "previoushostindex", "server");
|
setValue(name, "previoushostName", "server");
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServersSettings::getPrevioushostindex()
|
QString ServersSettings::getSaveName(QString defaultname)
|
||||||
{
|
{
|
||||||
return getValue("previoushostindex", "server").toInt();
|
int index = getPrevioushostindex(getPrevioushostName());
|
||||||
|
QVariant saveName = getValue(QString("saveName%1").arg(index), "server", "server_details");
|
||||||
|
return saveName == QVariant() ? defaultname : saveName.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServersSettings::getPrevioushostName()
|
||||||
|
{
|
||||||
|
return getValue("previoushostName", "server").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ServersSettings::getPrevioushostindex(const QString &saveName)
|
||||||
|
{
|
||||||
|
int size = getValue("totalServers", "server", "server_details").toInt() + 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
if (saveName == getValue(QString("saveName%1").arg(i), "server", "server_details").toString())
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersSettings::setHostName(QString hostname)
|
void ServersSettings::setHostName(QString hostname)
|
||||||
|
@ -43,7 +62,8 @@ void ServersSettings::setHostName(QString hostname)
|
||||||
|
|
||||||
QString ServersSettings::getHostname(QString defaultHost)
|
QString ServersSettings::getHostname(QString defaultHost)
|
||||||
{
|
{
|
||||||
QVariant hostname = getValue("hostname","server");
|
int index = getPrevioushostindex(getPrevioushostName());
|
||||||
|
QVariant hostname = getValue(QString("server%1").arg(index), "server", "server_details");
|
||||||
return hostname == QVariant() ? defaultHost : hostname.toString();
|
return hostname == QVariant() ? defaultHost : hostname.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +74,9 @@ void ServersSettings::setPort(QString port)
|
||||||
|
|
||||||
QString ServersSettings::getPort(QString defaultPort)
|
QString ServersSettings::getPort(QString defaultPort)
|
||||||
{
|
{
|
||||||
QVariant port = getValue("port","server");
|
int index = getPrevioushostindex(getPrevioushostName());
|
||||||
|
QVariant port = getValue(QString("port%1").arg(index), "server", "server_details");
|
||||||
|
qDebug() << "getPort() index = " << index << " port.val = " << port.toString();
|
||||||
return port == QVariant() ? defaultPort : port.toString();
|
return port == QVariant() ? defaultPort : port.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +87,9 @@ void ServersSettings::setPlayerName(QString playerName)
|
||||||
|
|
||||||
QString ServersSettings::getPlayerName(QString defaultName)
|
QString ServersSettings::getPlayerName(QString defaultName)
|
||||||
{
|
{
|
||||||
QVariant name = getValue("playername", "server");
|
int index = getPrevioushostindex(getPrevioushostName());
|
||||||
|
QVariant name = getValue(QString("username%1").arg(index), "server", "server_details");
|
||||||
|
qDebug() << "getPlayerName() index = " << index << " name.val = " << name.toString();
|
||||||
return name == QVariant() ? defaultName : name.toString();
|
return name == QVariant() ? defaultName : name.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +100,8 @@ void ServersSettings::setPassword(QString password)
|
||||||
|
|
||||||
QString ServersSettings::getPassword()
|
QString ServersSettings::getPassword()
|
||||||
{
|
{
|
||||||
return getValue("password", "server").toString();
|
int index = getPrevioushostindex(getPrevioushostName());
|
||||||
|
return getValue(QString("password%1").arg(index), "server", "server_details").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersSettings::setSavePassword(int save)
|
void ServersSettings::setSavePassword(int save)
|
||||||
|
@ -86,7 +111,8 @@ void ServersSettings::setSavePassword(int save)
|
||||||
|
|
||||||
int ServersSettings::getSavePassword()
|
int ServersSettings::getSavePassword()
|
||||||
{
|
{
|
||||||
QVariant save = getValue("save_password", "server");
|
int index = getPrevioushostindex(getPrevioushostName());
|
||||||
|
QVariant save = getValue(QString("savePassword%1").arg(index), "server", "server_details");
|
||||||
return save == QVariant() ? 1 : save.toInt();
|
return save == QVariant() ? 1 : save.toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,3 +159,39 @@ QString ServersSettings::getFPPlayerName(QString defaultName)
|
||||||
QVariant name = getValue("fpplayername", "server");
|
QVariant name = getValue("fpplayername", "server");
|
||||||
return name == QVariant() ? defaultName : name.toString();
|
return name == QVariant() ? defaultName : name.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServersSettings::addNewServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword)
|
||||||
|
{
|
||||||
|
if (updateExistingServer(saveName, serv, port, username, password, savePassword))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int index = getValue("totalServers", "server", "server_details").toInt() + 1;
|
||||||
|
|
||||||
|
setValue(saveName, QString("saveName%1").arg(index), "server", "server_details");
|
||||||
|
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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServersSettings::updateExistingServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword)
|
||||||
|
{
|
||||||
|
int size = getValue("totalServers", "server", "server_details").toInt() + 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
if (saveName == getValue(QString("saveName%1").arg(i), "server", "server_details").toString())
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -11,8 +11,9 @@ class ServersSettings : public SettingsManager
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int getPreviousHostLogin();
|
int getPreviousHostLogin();
|
||||||
|
int getPrevioushostindex(const QString &);
|
||||||
QStringList getPreviousHostList();
|
QStringList getPreviousHostList();
|
||||||
int getPrevioushostindex();
|
QString getPrevioushostName();
|
||||||
QString getHostname(QString defaultHost = "");
|
QString getHostname(QString defaultHost = "");
|
||||||
QString getPort(QString defaultPort = "");
|
QString getPort(QString defaultPort = "");
|
||||||
QString getPlayerName(QString defaultName = "");
|
QString getPlayerName(QString defaultName = "");
|
||||||
|
@ -20,10 +21,12 @@ public:
|
||||||
QString getFPPort(QString defaultPort = "");
|
QString getFPPort(QString defaultPort = "");
|
||||||
QString getFPPlayerName(QString defaultName = "");
|
QString getFPPlayerName(QString defaultName = "");
|
||||||
QString getPassword();
|
QString getPassword();
|
||||||
|
QString getSaveName(QString defaultname = "");
|
||||||
int getSavePassword();
|
int getSavePassword();
|
||||||
int getAutoConnect();
|
int getAutoConnect();
|
||||||
|
|
||||||
void setPreviousHostLogin(int previous);
|
void setPreviousHostLogin(int previous);
|
||||||
|
void setPrevioushostName(const QString &);
|
||||||
void setPreviousHostList(QStringList list);
|
void setPreviousHostList(QStringList list);
|
||||||
void setPrevioushostindex(int index);
|
void setPrevioushostindex(int index);
|
||||||
void setHostName(QString hostname);
|
void setHostName(QString hostname);
|
||||||
|
@ -35,6 +38,8 @@ public:
|
||||||
void setFPHostName(QString hostname);
|
void setFPHostName(QString hostname);
|
||||||
void setFPPort(QString port);
|
void setFPPort(QString port);
|
||||||
void setFPPlayerName(QString playerName);
|
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);
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -11,6 +11,7 @@ class SettingsManager : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SettingsManager(QString settingPath, QObject *parent = 0);
|
SettingsManager(QString settingPath, QObject *parent = 0);
|
||||||
|
QVariant getValue(QString name, QString group = "", QString subGroup = "");
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
@ -18,8 +19,7 @@ public slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QVariant getValue(QString name, QString group = "", QString subGroup = "" );
|
void setValue(QVariant value, QString name, QString group = "", QString subGroup = "");
|
||||||
void setValue(QVariant value, QString name, QString group = "", QString subGroup = "" );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGSMANAGER_H
|
#endif // SETTINGSMANAGER_H
|
||||||
|
|
|
@ -58,7 +58,6 @@ void SettingsCache::translateLegacySettings()
|
||||||
legacySetting.beginGroup("server");
|
legacySetting.beginGroup("server");
|
||||||
servers().setPreviousHostLogin(legacySetting.value("previoushostlogin").toInt());
|
servers().setPreviousHostLogin(legacySetting.value("previoushostlogin").toInt());
|
||||||
servers().setPreviousHostList(legacySetting.value("previoushosts").toStringList());
|
servers().setPreviousHostList(legacySetting.value("previoushosts").toStringList());
|
||||||
servers().setPrevioushostindex(legacySetting.value("previoushostindex").toInt());
|
|
||||||
servers().setHostName(legacySetting.value("hostname").toString());
|
servers().setHostName(legacySetting.value("hostname").toString());
|
||||||
servers().setPort(legacySetting.value("port").toString());
|
servers().setPort(legacySetting.value("port").toString());
|
||||||
servers().setPlayerName(legacySetting.value("playername").toString());
|
servers().setPlayerName(legacySetting.value("playername").toString());
|
||||||
|
|
68
cockatrice/src/userconnection_information.cpp
Normal file
68
cockatrice/src/userconnection_information.cpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#include "userconnection_information.h"
|
||||||
|
#include "settingscache.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
UserConnection_Information::UserConnection_Information()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
UserConnection_Information::UserConnection_Information(QString _saveName, QString _serverName, QString _portNum, QString _userName, QString _pass, bool _savePass)
|
||||||
|
: saveName(_saveName), server(_serverName), port(_portNum), username(_userName), password(_pass), savePassword(_savePass)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, UserConnection_Information> UserConnection_Information::getServerInfo()
|
||||||
|
{
|
||||||
|
QMap<QString, UserConnection_Information> serverList;
|
||||||
|
|
||||||
|
int size = settingsCache->servers().getValue("totalServers", "server", "server_details").toInt() + 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
QString saveName = settingsCache->servers().getValue(QString("saveName%1").arg(i), "server", "server_details").toString();
|
||||||
|
QString serverName = settingsCache->servers().getValue(QString("server%1").arg(i), "server", "server_details").toString();
|
||||||
|
QString portNum = settingsCache->servers().getValue(QString("port%1").arg(i), "server", "server_details").toString();
|
||||||
|
QString userName = settingsCache->servers().getValue(QString("username%1").arg(i), "server", "server_details").toString();
|
||||||
|
QString pass = settingsCache->servers().getValue(QString("password%1").arg(i), "server", "server_details").toString();
|
||||||
|
bool savePass =settingsCache->servers().getValue(QString("savePassword%1").arg(i), "server", "server_details").toBool();
|
||||||
|
|
||||||
|
UserConnection_Information userInfo(saveName, serverName, portNum, userName, pass, savePass);
|
||||||
|
serverList.insert(saveName, userInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList UserConnection_Information::getServerInfo(const QString &find)
|
||||||
|
{
|
||||||
|
QStringList server;
|
||||||
|
|
||||||
|
int size = settingsCache->servers().getValue("totalServers", "server", "server_details").toInt() + 1;
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
QString saveName = settingsCache->servers().getValue(QString("saveName%1").arg(i), "server", "server_details").toString();
|
||||||
|
|
||||||
|
if (find != saveName)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QString serverName = settingsCache->servers().getValue(QString("server%1").arg(i), "server", "server_details").toString();
|
||||||
|
QString portNum = settingsCache->servers().getValue(QString("port%1").arg(i), "server", "server_details").toString();
|
||||||
|
QString userName = settingsCache->servers().getValue(QString("username%1").arg(i), "server", "server_details").toString();
|
||||||
|
QString pass = settingsCache->servers().getValue(QString("password%1").arg(i), "server", "server_details").toString();
|
||||||
|
bool savePass =settingsCache->servers().getValue(QString("savePassword%1").arg(i), "server", "server_details").toBool();
|
||||||
|
|
||||||
|
server.append(saveName);
|
||||||
|
server.append(serverName);
|
||||||
|
server.append(portNum);
|
||||||
|
server.append(userName);
|
||||||
|
server.append(pass);
|
||||||
|
server.append(savePass ? "1" : "0");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!server.size())
|
||||||
|
qDebug() << "There was a problem!";
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
31
cockatrice/src/userconnection_information.h
Normal file
31
cockatrice/src/userconnection_information.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef USERCONNECTION_INFORMATION_H
|
||||||
|
#define USERCONNECTION_INFORMATION_H
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
class UserConnection_Information {
|
||||||
|
private:
|
||||||
|
QString saveName;
|
||||||
|
QString server;
|
||||||
|
QString port;
|
||||||
|
QString username;
|
||||||
|
QString password;
|
||||||
|
bool savePassword;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UserConnection_Information();
|
||||||
|
UserConnection_Information(QString, QString, QString, QString, QString, bool);
|
||||||
|
QString getSaveName() { return saveName; }
|
||||||
|
QString getServer() { return server; }
|
||||||
|
QString getPort() { return port; }
|
||||||
|
QString getUsername() { return username; }
|
||||||
|
QString getPassword() { return password; }
|
||||||
|
bool getSavePassword() { return savePassword; }
|
||||||
|
QMap<QString, UserConnection_Information> getServerInfo();
|
||||||
|
QStringList getServerInfo(const QString &find);
|
||||||
|
};
|
||||||
|
#endif
|
Loading…
Reference in a new issue