diff --git a/cockatrice/src/dlg_connect.h b/cockatrice/src/dlg_connect.h index b26ae671..31fe4e2b 100644 --- a/cockatrice/src/dlg_connect.h +++ b/cockatrice/src/dlg_connect.h @@ -47,6 +47,9 @@ public: return passwordEdit->text(); } +public slots: + void downloadThePublicServers(); + private slots: void actOk(); void actSaveConfig(); @@ -57,7 +60,6 @@ private slots: void updateDisplayInfo(const QString &saveName); void preRebuildComboBoxList(); void rebuildComboBoxList(int failure = -1); - void downloadThePublicServers(); private: QGridLayout *newHostLayout, *connectionLayout, *loginLayout, *serverInfoLayout, *grid; diff --git a/cockatrice/src/settings/serverssettings.cpp b/cockatrice/src/settings/serverssettings.cpp index c12e0bd4..629787e0 100644 --- a/cockatrice/src/settings/serverssettings.cpp +++ b/cockatrice/src/settings/serverssettings.cpp @@ -227,23 +227,41 @@ void ServersSettings::removeServer(QString servAddr) /** * Will only update fields with new values, ignores empty values */ -bool ServersSettings::updateExistingServerWithoutLoss(QString saveName, - QString serv, - QString port, - QString site, - QString username, - QString password, - bool savePassword) +bool ServersSettings::updateExistingServerWithoutLoss(QString saveName, QString serv, QString port, QString site) { int size = getValue("totalServers", "server", "server_details").toInt() + 1; for (int i = 0; i < size; i++) { if (serv == getValue(QString("server%1").arg(i), "server", "server_details").toString()) { - if (!port.isEmpty()) { setValue(port, QString("port%1").arg(i), "server", "server_details"); } + if (!site.isEmpty()) { + setValue(site, QString("site%1").arg(i), "server", "server_details"); + } + + setValue(saveName, QString("saveName%1").arg(i), "server", "server_details"); + + return true; + } + } + return false; +} + +bool ServersSettings::updateExistingServer(QString saveName, + QString serv, + QString port, + QString username, + QString password, + bool savePassword, + QString site) +{ + int size = getValue("totalServers", "server", "server_details").toInt() + 1; + + for (int i = 0; i < size; i++) { + if (serv == getValue(QString("server%1").arg(i), "server", "server_details").toString()) { + setValue(port, QString("port%1").arg(i), "server", "server_details"); if (!username.isEmpty()) { setValue(username, QString("username%1").arg(i), "server", "server_details"); } @@ -266,15 +284,3 @@ bool ServersSettings::updateExistingServerWithoutLoss(QString saveName, } return false; } - -bool ServersSettings::updateExistingServer(QString saveName, - QString serv, - QString port, - QString username, - QString password, - bool savePassword, - QString site) -{ - return updateExistingServerWithoutLoss(std::move(saveName), std::move(serv), std::move(port), std::move(site), - std::move(username), std::move(password), savePassword); -} diff --git a/cockatrice/src/settings/serverssettings.h b/cockatrice/src/settings/serverssettings.h index e5251c62..89550abf 100644 --- a/cockatrice/src/settings/serverssettings.h +++ b/cockatrice/src/settings/serverssettings.h @@ -58,10 +58,7 @@ public: bool updateExistingServerWithoutLoss(QString saveName, QString serv = QString(), QString port = QString(), - QString site = QString(), - QString username = QString(), - QString password = QString(), - bool savePassword = true); + QString site = QString()); void setClearDebugLogStatus(bool abIsChecked); bool getClearDebugLogStatus(bool abDefaultValue); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 24d19520..4ba1366a 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -864,6 +864,7 @@ void MainWindow::alertForcedOracleRun(const QString &newVersion) "Oracle will now launch to update your card database.") .arg(newVersion)); actCheckCardUpdates(); + actCheckServerUpdates(); } MainWindow::~MainWindow() @@ -1127,6 +1128,13 @@ void MainWindow::cardUpdateFinished(int, QProcess::ExitStatus) QtConcurrent::run(db, &CardDatabase::loadCardDatabases); } +void MainWindow::actCheckServerUpdates() +{ + auto hps = new HandlePublicServers(this); + hps->downloadPublicServers(); + connect(hps, &HandlePublicServers::sigPublicServersDownloadedSuccessfully, [=]() { hps->deleteLater(); }); +} + void MainWindow::refreshShortcuts() { aConnect->setShortcuts(settingsCache->shortcuts().getShortcut("MainWindow/aConnect")); diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index 15d3bc55..66787129 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -48,6 +48,7 @@ class MainWindow : public QMainWindow Q_OBJECT public slots: void actCheckCardUpdates(); + void actCheckServerUpdates(); private slots: void updateTabMenu(const QList &newMenuList); void statusChanged(ClientStatus _status);