diff --git a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp index 0a7ae2c0..832fc6fd 100644 --- a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp +++ b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp @@ -47,9 +47,9 @@ void AdvancedServerSettingsLogic::onPushButtonClearServer() ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); if (e) { - uiLogic()->set_dialogConnectErrorText(tr("Error occurred while configuring server.") + "\n" + - errorString(e) + "\n" + tr("See logs for details.")); - emit uiLogic()->showConnectErrorDialog(); + emit uiLogic()->showWarningMessage(tr("Error occurred while configuring server.") + "\n" + + tr("Error message: ") + errorString(e) + "\n" + + tr("See logs for details.")); } else { set_labelWaitInfoVisible(true); set_labelWaitInfoText(tr("Amnezia server successfully uninstalled")); diff --git a/client/ui/pages_logic/AppSettingsLogic.cpp b/client/ui/pages_logic/AppSettingsLogic.cpp index 3590c480..e5358009 100644 --- a/client/ui/pages_logic/AppSettingsLogic.cpp +++ b/client/ui/pages_logic/AppSettingsLogic.cpp @@ -7,7 +7,6 @@ #include #include -#include #include using namespace amnezia; @@ -96,10 +95,8 @@ void AppSettingsLogic::onPushButtonRestoreAppConfigClicked() if (ok) { emit uiLogic()->goToPage(Page::Vpn); emit uiLogic()->setStartPage(Page::Vpn); - } - else { - QMessageBox::warning(nullptr, APPLICATION_NAME, - tr("Can't import config, file is corrupted.")); + } else { + emit uiLogic()->showWarningMessage(tr("Can't import config, file is corrupted.")); } } diff --git a/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp b/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp index c6e7085b..f6a8abdb 100644 --- a/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp +++ b/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp @@ -3,7 +3,6 @@ #include "core/errorstrings.h" #include #include -#include #include "core/servercontroller.h" @@ -142,9 +141,6 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::functiongoToPage(Page::ServerConfiguringProgress); qApp->processEvents(); - uiLogic()->getInstalledContainers(false); //todo its work like should be? - ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex); + ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, credentials); - if (!uiLogic()->isContainerAlreadyAddedToGui(c, credentials)) { - auto installAction = [this, c, &config](){ - return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config); - }; - ErrorCode error = uiLogic()->pageLogic()->doInstallAction(installAction); + if (errorCode == ErrorCode::NoError) { + if (!uiLogic()->isContainerAlreadyAddedToGui(c, credentials)) { + auto installAction = [this, c, &config]() { + return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config); + }; + errorCode = uiLogic()->pageLogic()->doInstallAction(installAction); - if (error == ErrorCode::NoError) { - m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, c, config); - if (ContainerProps::containerService(c) == ServiceType::Vpn) { - m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c); + if (errorCode == ErrorCode::NoError) { + m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, c, config); + if (ContainerProps::containerService(c) == ServiceType::Vpn) { + m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c); + } } + } else { + emit uiLogic()->showWarningMessage("Attention! The container you are trying to install is already installed on the server. " + "All installed containers have been added to the application "); } - } - uiLogic()->onUpdateAllPages(); + uiLogic()->onUpdateAllPages(); + } + if (errorCode != ErrorCode::NoError) { + emit uiLogic()->showWarningMessage(tr("Error occurred while configuring server.") + "\n" + + tr("Error message: ") + errorString(errorCode) + "\n" + + tr("See logs for details.")); + } emit uiLogic()->closePage(); } diff --git a/client/ui/pages_logic/ServerSettingsLogic.cpp b/client/ui/pages_logic/ServerSettingsLogic.cpp index 35a93bbb..858a77d1 100644 --- a/client/ui/pages_logic/ServerSettingsLogic.cpp +++ b/client/ui/pages_logic/ServerSettingsLogic.cpp @@ -16,10 +16,8 @@ ServerSettingsLogic::ServerSettingsLogic(UiLogic *logic, QObject *parent): PageLogicBase(logic, parent), m_labelWaitInfoVisible{true}, - m_pushButtonClearVisible{true}, m_pushButtonClearClientCacheVisible{true}, m_pushButtonShareFullVisible{true}, - m_pushButtonClearText{tr("Clear server from Amnezia software")}, m_pushButtonClearClientCacheText{tr("Clear client cached profile")} { } @@ -27,7 +25,6 @@ void ServerSettingsLogic::onUpdatePage() { set_labelWaitInfoVisible(false); set_labelWaitInfoText(""); - set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); const QJsonObject &server = m_settings->server(uiLogic()->m_selectedServerIndex); @@ -50,36 +47,6 @@ void ServerSettingsLogic::onUpdatePage() set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName); } -void ServerSettingsLogic::onPushButtonClearServer() -{ - set_pageEnabled(false); - set_pushButtonClearText(tr("Uninstalling Amnezia software...")); - - if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex) { - uiLogic()->pageLogic()->onDisconnect(); - } - - ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); - m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); - if (e) { - uiLogic()->set_dialogConnectErrorText( - tr("Error occurred while configuring server.") + "\n" + - errorString(e) + "\n" + - tr("See logs for details.")); - emit uiLogic()->showConnectErrorDialog(); - } - else { - set_labelWaitInfoVisible(true); - set_labelWaitInfoText(tr("Amnezia server successfully uninstalled")); - } - - m_settings->setContainers(uiLogic()->m_selectedServerIndex, {}); - m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None); - - set_pageEnabled(true); - set_pushButtonClearText(tr("Clear server from Amnezia software")); -} - void ServerSettingsLogic::onPushButtonForgetServer() { if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex && uiLogic()->m_vpnConnection->isConnected()) { diff --git a/client/ui/pages_logic/ServerSettingsLogic.h b/client/ui/pages_logic/ServerSettingsLogic.h index d561ec48..a75dfa47 100644 --- a/client/ui/pages_logic/ServerSettingsLogic.h +++ b/client/ui/pages_logic/ServerSettingsLogic.h @@ -16,9 +16,7 @@ class ServerSettingsLogic : public PageLogicBase AUTO_PROPERTY(bool, labelWaitInfoVisible) AUTO_PROPERTY(QString, labelWaitInfoText) - AUTO_PROPERTY(QString, pushButtonClearText) AUTO_PROPERTY(QString, pushButtonClearClientCacheText) - AUTO_PROPERTY(bool, pushButtonClearVisible) AUTO_PROPERTY(bool, pushButtonClearClientCacheVisible) AUTO_PROPERTY(bool, pushButtonShareFullVisible) AUTO_PROPERTY(QString, labelServerText) @@ -28,7 +26,6 @@ class ServerSettingsLogic : public PageLogicBase public: Q_INVOKABLE void onUpdatePage() override; - Q_INVOKABLE void onPushButtonClearServer(); Q_INVOKABLE void onPushButtonForgetServer(); Q_INVOKABLE void onPushButtonShareFullClicked(); Q_INVOKABLE void onPushButtonClearClientCacheClicked(); diff --git a/client/ui/pages_logic/ShareConnectionLogic.cpp b/client/ui/pages_logic/ShareConnectionLogic.cpp index 26563359..821cc0fc 100644 --- a/client/ui/pages_logic/ShareConnectionLogic.cpp +++ b/client/ui/pages_logic/ShareConnectionLogic.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include "qrcodegen.hpp" @@ -218,9 +217,9 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked() ErrorCode e = ErrorCode::NoError; QString cfg = m_configurator->wireguardConfigurator->genWireguardConfig(credentials, container, containerConfig, &e); if (e) { - QMessageBox::warning(nullptr, APPLICATION_NAME, - tr("Error occurred while configuring server.") + "\n" + - errorString(e)); + emit uiLogic()->showWarningMessage(tr("Error occurred while generating the config.") + "\n" + + tr("Error message: ") + errorString(e) + "\n" + + tr("See logs for details.")); return; } cfg = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, cfg); diff --git a/client/ui/pages_logic/ShareConnectionLogic.h b/client/ui/pages_logic/ShareConnectionLogic.h index 5d46be97..3b9655aa 100644 --- a/client/ui/pages_logic/ShareConnectionLogic.h +++ b/client/ui/pages_logic/ShareConnectionLogic.h @@ -50,6 +50,5 @@ public: QList genQrCodeImageSeries(const QByteArray &data); QString svgToBase64(const QString &image); - }; #endif // SHARE_CONNECTION_LOGIC_H diff --git a/client/ui/qml/Pages/PageAdvancedServerSettings.qml b/client/ui/qml/Pages/PageAdvancedServerSettings.qml index a0d2a3f6..4e9d1106 100644 --- a/client/ui/qml/Pages/PageAdvancedServerSettings.qml +++ b/client/ui/qml/Pages/PageAdvancedServerSettings.qml @@ -92,7 +92,6 @@ PageBase { } } - Logo { id : logo anchors.bottom: parent.bottom diff --git a/client/ui/qml/Pages/PageServerSettings.qml b/client/ui/qml/Pages/PageServerSettings.qml index 7a21bfd2..60459955 100644 --- a/client/ui/qml/Pages/PageServerSettings.qml +++ b/client/ui/qml/Pages/PageServerSettings.qml @@ -128,7 +128,6 @@ PageBase { } } - Logo { id : logo anchors.bottom: parent.bottom diff --git a/client/ui/qml/main.qml b/client/ui/qml/main.qml index 6e2c7911..b8758384 100644 --- a/client/ui/qml/main.qml +++ b/client/ui/qml/main.qml @@ -242,12 +242,6 @@ Window { text: qsTr("It's public key. Private key required") visible: false } - MessageDialog { - id: connectErrorDialog - title: "AmneziaVPN" - text: UiLogic.dialogConnectErrorText - visible: false - } Drawer { id: drawer_log diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index 1646b256..ed44efad 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -326,62 +325,64 @@ void UiLogic::installServer(QMap &containers) pageLogic()->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::iterator i = containers.begin(); i != containers.end(); i++, count++) { + if (isContainerAlreadyAddedToGui(i.key(), m_installCredentials)) { + continue; + } - int count = 0; - bool isSomethingInstalled = false; - for (QMap::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()->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()->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(); } -ErrorCode UiLogic::getInstalledContainers(bool addNewServerToGui) +ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials) { QMap 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; } diff --git a/client/ui/uilogic.h b/client/ui/uilogic.h index bc72223c..339f119c 100644 --- a/client/ui/uilogic.h +++ b/client/ui/uilogic.h @@ -61,7 +61,6 @@ class UiLogic : public QObject AUTO_PROPERTY(bool, pageEnabled) AUTO_PROPERTY(int, pagesStackDepth) AUTO_PROPERTY(int, currentPageValue) - AUTO_PROPERTY(QString, dialogConnectErrorText) AUTO_PROPERTY(QString, popupWarningText) READONLY_PROPERTY(QObject *, containersModel) @@ -115,7 +114,7 @@ public: Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data); Q_INVOKABLE void copyToClipboard(const QString& text); - Q_INVOKABLE amnezia::ErrorCode getInstalledContainers(bool addNewServerToGui); + Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials); void shareTempFile(const QString &suggestedName, QString ext, const QString& data);