Removed the ability to add multiple servers with the same connection credentials via the "Add server" button
This commit is contained in:
parent
15c33014e7
commit
6e67946ae2
4 changed files with 26 additions and 20 deletions
|
@ -68,7 +68,7 @@ void AdvancedServerSettingsLogic::onPushButtonScanServerClicked()
|
||||||
|
|
||||||
bool isServerCreated;
|
bool isServerCreated;
|
||||||
auto containersCount = m_settings->containers(uiLogic()->m_selectedServerIndex).size();
|
auto containersCount = m_settings->containers(uiLogic()->m_selectedServerIndex).size();
|
||||||
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated);
|
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(isServerCreated);
|
||||||
if (errorCode != ErrorCode::NoError) {
|
if (errorCode != ErrorCode::NoError) {
|
||||||
emit uiLogic()->showWarningMessage(tr("Error occurred while scanning the server.") + "\n" +
|
emit uiLogic()->showWarningMessage(tr("Error occurred while scanning the server.") + "\n" +
|
||||||
tr("Error message: ") + errorString(errorCode) + "\n" +
|
tr("Error message: ") + errorString(errorCode) + "\n" +
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include "protocols/CloakLogic.h"
|
#include "protocols/PageProtocolLogicBase.h"
|
||||||
#include "protocols/OpenVpnLogic.h"
|
|
||||||
#include "protocols/ShadowSocksLogic.h"
|
|
||||||
|
|
||||||
#include "core/servercontroller.h"
|
#include "core/servercontroller.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -90,7 +88,7 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
|
|
||||||
bool isServerCreated = false;
|
bool isServerCreated = false;
|
||||||
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated);
|
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(isServerCreated);
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
if (!uiLogic()->isContainerAlreadyAddedToGui(c)) {
|
if (!uiLogic()->isContainerAlreadyAddedToGui(c)) {
|
||||||
|
|
|
@ -332,7 +332,7 @@ void UiLogic::installServer(QPair<DockerContainer, QJsonObject> &container)
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isServerCreated = false;
|
bool isServerCreated = false;
|
||||||
ErrorCode errorCode = addAlreadyInstalledContainersGui(true, isServerCreated);
|
ErrorCode errorCode = addAlreadyInstalledContainersGui(isServerCreated);
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
if (!isContainerAlreadyAddedToGui(container.first)) {
|
if (!isContainerAlreadyAddedToGui(container.first)) {
|
||||||
progressBarFunc.setTextFunc(QString("Installing %1").arg(ContainerProps::containerToString(container.first)));
|
progressBarFunc.setTextFunc(QString("Installing %1").arg(ContainerProps::containerToString(container.first)));
|
||||||
|
@ -520,18 +520,26 @@ void UiLogic::registerPagesLogic()
|
||||||
registerPageLogic<AdvancedServerSettingsLogic>();
|
registerPageLogic<AdvancedServerSettingsLogic>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated)
|
ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool &isServerCreated)
|
||||||
{
|
{
|
||||||
isServerCreated = false;
|
isServerCreated = false;
|
||||||
ServerCredentials credentials;
|
ServerCredentials installCredentials = m_installCredentials;
|
||||||
if (createNewServer) {
|
bool createNewServer = true;
|
||||||
credentials = m_installCredentials;
|
int serverIndex;
|
||||||
} else {
|
|
||||||
credentials = m_settings->serverCredentials(m_selectedServerIndex);
|
for (int i = 0; i < m_settings->serversCount(); i++) {
|
||||||
|
const ServerCredentials credentials = m_settings->serverCredentials(i);
|
||||||
|
if (m_installCredentials.hostName == credentials.hostName && m_installCredentials.port == credentials.port) {
|
||||||
|
createNewServer = false;
|
||||||
|
isServerCreated = true;
|
||||||
|
installCredentials = credentials;
|
||||||
|
serverIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<DockerContainer, QJsonObject> installedContainers;
|
QMap<DockerContainer, QJsonObject> installedContainers;
|
||||||
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers);
|
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(installCredentials, installedContainers);
|
||||||
if (errorCode != ErrorCode::NoError) {
|
if (errorCode != ErrorCode::NoError) {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
@ -540,10 +548,10 @@ ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &
|
||||||
QJsonObject server;
|
QJsonObject server;
|
||||||
QJsonArray containerConfigs;
|
QJsonArray containerConfigs;
|
||||||
if (createNewServer) {
|
if (createNewServer) {
|
||||||
server.insert(config_key::hostName, credentials.hostName);
|
server.insert(config_key::hostName, installCredentials.hostName);
|
||||||
server.insert(config_key::userName, credentials.userName);
|
server.insert(config_key::userName, installCredentials.userName);
|
||||||
server.insert(config_key::password, credentials.password);
|
server.insert(config_key::password, installCredentials.password);
|
||||||
server.insert(config_key::port, credentials.port);
|
server.insert(config_key::port, installCredentials.port);
|
||||||
server.insert(config_key::description, m_settings->nextAvailableServerName());
|
server.insert(config_key::description, m_settings->nextAvailableServerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,8 +564,8 @@ ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &
|
||||||
containerConfigs.append(container.value());
|
containerConfigs.append(container.value());
|
||||||
server.insert(config_key::containers, containerConfigs);
|
server.insert(config_key::containers, containerConfigs);
|
||||||
} else {
|
} else {
|
||||||
m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value());
|
m_settings->setContainerConfig(serverIndex, container.key(), container.value());
|
||||||
m_settings->setDefaultContainer(m_selectedServerIndex, installedContainers.firstKey());
|
m_settings->setDefaultContainer(serverIndex, installedContainers.firstKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ public:
|
||||||
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
|
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
|
||||||
Q_INVOKABLE void copyToClipboard(const QString& text);
|
Q_INVOKABLE void copyToClipboard(const QString& text);
|
||||||
|
|
||||||
Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated);
|
Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool &isServerCreated);
|
||||||
|
|
||||||
void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
|
void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue