made error output in the same style

- some code style refactoring
This commit is contained in:
vladimir.kuznetsov 2023-02-22 10:01:43 +03:00
parent ddc3fe7807
commit 480b2181f0
13 changed files with 92 additions and 135 deletions

View file

@ -10,7 +10,6 @@
#include <QJsonObject>
#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
#include <QMetaEnum>
#include <QSysInfo>
#include <QThread>
@ -326,62 +325,64 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
pageLogic<ServerConfiguringProgressLogic>()->set_pushButtonCancelVisible(visible);
};
ErrorCode error = getInstalledContainers(true);
if (error != ErrorCode::NoError) {
return;
}
ErrorCode errorCode = addAlreadyInstalledContainersGui(true, m_installCredentials);
if (errorCode == ErrorCode::NoError) {
int count = 0;
bool isSomethingInstalled = false;
for (QMap<DockerContainer, QJsonObject>::iterator i = containers.begin(); i != containers.end(); i++, count++) {
if (isContainerAlreadyAddedToGui(i.key(), m_installCredentials)) {
continue;
}
int count = 0;
bool isSomethingInstalled = false;
for (QMap<DockerContainer, QJsonObject>::iterator i = containers.begin(); i != containers.end(); i++, count++) {
if (isContainerAlreadyAddedToGui(i.key(), m_installCredentials)) {
continue;
isSomethingInstalled = true;
progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count + 1).arg(tr("of")).arg(containers.size()));
auto installAction = [&] () {
return m_serverController->setupContainer(m_installCredentials, i.key(), i.value());
};
errorCode = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
noButton, waitInfoFunc,
busyInfoFunc, cancelButtonFunc);
m_serverController->disconnectFromHost(m_installCredentials);
}
isSomethingInstalled = true;
if (errorCode == ErrorCode::NoError) {
if (!isSomethingInstalled) {
onUpdateAllPages();
emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. "
"All installed containers have been added to the application ");
emit setStartPage(Page::Vpn);
return;
}
progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count + 1).arg(tr("of")).arg(containers.size()));
auto installAction = [&] () {
return m_serverController->setupContainer(m_installCredentials, i.key(), i.value());
};
error = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
noButton, waitInfoFunc,
busyInfoFunc, cancelButtonFunc);
QJsonObject server;
server.insert(config_key::hostName, m_installCredentials.hostName);
server.insert(config_key::userName, m_installCredentials.userName);
server.insert(config_key::password, m_installCredentials.password);
server.insert(config_key::port, m_installCredentials.port);
server.insert(config_key::description, m_settings->nextAvailableServerName());
m_serverController->disconnectFromHost(m_installCredentials);
}
QJsonArray containerConfigs;
for (const QJsonObject &cfg : containers) {
containerConfigs.append(cfg);
}
server.insert(config_key::containers, containerConfigs);
server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey()));
m_settings->addServer(server);
m_settings->setDefaultServer(m_settings->serversCount() - 1);
onUpdateAllPages();
if (error == ErrorCode::NoError) {
if (!isSomethingInstalled) {
emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. "
"All installed containers have been added to the application ");
emit setStartPage(Page::Vpn);
qApp->processEvents();
return;
}
QJsonObject server;
server.insert(config_key::hostName, m_installCredentials.hostName);
server.insert(config_key::userName, m_installCredentials.userName);
server.insert(config_key::password, m_installCredentials.password);
server.insert(config_key::port, m_installCredentials.port);
server.insert(config_key::description, m_settings->nextAvailableServerName());
QJsonArray containerConfigs;
for (const QJsonObject &cfg : containers) {
containerConfigs.append(cfg);
}
server.insert(config_key::containers, containerConfigs);
server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey()));
m_settings->addServer(server);
m_settings->setDefaultServer(m_settings->serversCount() - 1);
onUpdateAllPages();
emit setStartPage(Page::Vpn);
qApp->processEvents();
} else {
emit closePage();
}
emit showWarningMessage(tr("Error occurred while configuring server.") + "\n" +
tr("Error message: ") + errorString(errorCode) + "\n" +
tr("See logs for details."));
emit closePage();
}
PageProtocolLogicBase *UiLogic::protocolLogic(Proto p)
@ -520,45 +521,45 @@ void UiLogic::registerPagesLogic()
registerPageLogic<AdvancedServerSettingsLogic>();
}
ErrorCode UiLogic::getInstalledContainers(bool addNewServerToGui)
ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials)
{
QMap<DockerContainer, QJsonObject> installedContainers;
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(m_installCredentials, installedContainers);
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers);
m_serverController->disconnectFromHost(credentials);
if (errorCode != ErrorCode::NoError) {
return errorCode;
}
QJsonObject server;
QJsonArray containerConfigs;
if (addNewServerToGui) {
server.insert(config_key::hostName, m_installCredentials.hostName);
server.insert(config_key::userName, m_installCredentials.userName);
server.insert(config_key::password, m_installCredentials.password);
server.insert(config_key::port, m_installCredentials.port);
if (createNewServer) {
server.insert(config_key::hostName, credentials.hostName);
server.insert(config_key::userName, credentials.userName);
server.insert(config_key::password, credentials.password);
server.insert(config_key::port, credentials.port);
server.insert(config_key::description, m_settings->nextAvailableServerName());
}
for (auto container = installedContainers.begin(); container != installedContainers.end(); container++) {
if (isContainerAlreadyAddedToGui(container.key(), m_installCredentials)) {
if (isContainerAlreadyAddedToGui(container.key(), credentials)) {
continue;
}
if (addNewServerToGui) {
if (createNewServer) {
containerConfigs.append(container.value());
server.insert(config_key::containers, containerConfigs);
} else {
m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value());
m_settings->setDefaultContainer(m_selectedServerIndex, installedContainers.firstKey());
}
}
if (addNewServerToGui) {
if (createNewServer) {
server.insert(config_key::defaultContainer, ContainerProps::containerToString(installedContainers.firstKey()));
m_settings->addServer(server);
m_settings->setDefaultServer(m_settings->serversCount() - 1);
}
onUpdateAllPages();
return ErrorCode::NoError;
}