now an instance of the serverController class is created at the place of use

This commit is contained in:
vladimir.kuznetsov 2023-04-04 10:22:25 +03:00
parent 1aa859b10d
commit a005ed2a84
33 changed files with 125 additions and 139 deletions

View file

@ -44,10 +44,11 @@ void AdvancedServerSettingsLogic::onPushButtonClearServerClicked()
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
}
ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
if (e) {
ServerController serverController(m_settings);
ErrorCode errorCode = serverController.removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
if (errorCode) {
emit uiLogic()->showWarningMessage(tr("Error occurred while cleaning the server.") + "\n" +
tr("Error message: ") + errorString(e) + "\n" +
tr("Error message: ") + errorString(errorCode) + "\n" +
tr("See logs for details."));
} else {
set_labelWaitInfoVisible(true);

View file

@ -11,7 +11,6 @@ PageLogicBase::PageLogicBase(UiLogic *logic, QObject *parent):
{
m_settings = logic->m_settings;
m_configurator = logic->m_configurator;
m_serverController = logic->m_serverController;
}

View file

@ -28,7 +28,6 @@ protected:
std::shared_ptr<Settings> m_settings;
std::shared_ptr<VpnConfigurator> m_configurator;
std::shared_ptr<ServerController> m_serverController;
signals:
void updatePage();

View file

@ -96,19 +96,18 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
progress.setValueFunc(0);
timer.start(1000);
ServerController serverController(m_settings);
QMetaObject::Connection cancelDoInstallActionConnection;
if (cancelButton.setVisibleFunc) {
cancelDoInstallActionConnection = connect(this, &ServerConfiguringProgressLogic::cancelDoInstallAction,
m_serverController.get(), &ServerController::setCancelInstallation);
&serverController, &ServerController::setCancelInstallation);
}
QMetaObject::Connection serverBusyConnection;
if (serverBusyInfo.setVisibleFunc && serverBusyInfo.setTextFunc) {
serverBusyConnection = connect(m_serverController.get(),
&ServerController::serverIsBusy,
this,
[&serverBusyInfo, &timer, &cancelButton](const bool isBusy) {
auto onServerIsBusy = [&serverBusyInfo, &timer, &cancelButton](const bool isBusy) {
isBusy ? timer.stop() : timer.start(1000);
serverBusyInfo.setVisibleFunc(isBusy);
serverBusyInfo.setTextFunc(isBusy ? "Amnesia has detected that your server is currently "
@ -118,7 +117,9 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
if (cancelButton.setVisibleFunc) {
cancelButton.setVisibleFunc(isBusy ? true : false);
}
});
};
serverBusyConnection = connect(&serverController, &ServerController::serverIsBusy, this, onServerIsBusy);
}
ErrorCode e = action();
@ -182,5 +183,5 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
void ServerConfiguringProgressLogic::onPushButtonCancelClicked()
{
cancelDoInstallAction(true);
emit cancelDoInstallAction(true);
}

View file

@ -70,7 +70,8 @@ void ServerContainersLogic::onPushButtonShareClicked(DockerContainer c)
void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container)
{
//buttonSetEnabledFunc(false);
ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), container);
ServerController serverController(m_settings);
ErrorCode e = serverController.removeContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), container);
m_settings->removeContainerConfig(uiLogic()->m_selectedServerIndex, container);
//buttonSetEnabledFunc(true);
@ -84,7 +85,8 @@ void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container)
void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int port, TransportProto tp)
{
QJsonObject config = m_serverController->createContainerInitialConfig(c, port, tp);
ServerController serverController(m_settings);
QJsonObject config = serverController.createContainerInitialConfig(c, port, tp);
emit uiLogic()->goToPage(Page::ServerConfiguringProgress);
qApp->processEvents();
@ -95,7 +97,8 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p
if (errorCode == ErrorCode::NoError) {
if (!uiLogic()->isContainerAlreadyAddedToGui(c)) {
auto installAction = [this, c, &config]() {
return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config);
ServerController serverController(m_settings);
return serverController.setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config);
};
errorCode = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction);

View file

@ -131,10 +131,11 @@ void StartPageLogic::onPushButtonConnect()
set_pushButtonConnectEnabled(false);
set_pushButtonConnectText(tr("Connecting..."));
ServerController serverController(m_settings);
ErrorCode errorCode = ErrorCode::NoError;
if (pushButtonConnectKeyChecked()) {
auto passphraseCallback = [this]() {
auto passphraseCallback = [this, &serverController]() {
emit showPassphraseRequestMessage();
QEventLoop loop;
QObject::connect(this, &StartPageLogic::passphraseDialogClosed, &loop, &QEventLoop::quit);
@ -142,14 +143,14 @@ void StartPageLogic::onPushButtonConnect()
return m_privateKeyPassphrase;
};
m_serverController->setPassphraseCallback(passphraseCallback);
serverController.setPassphraseCallback(passphraseCallback);
}
QString output = m_serverController->checkSshConnection(serverCredentials, &errorCode);
QString output = serverController.checkSshConnection(serverCredentials, &errorCode);
if (pushButtonConnectKeyChecked()) {
QString decryptedPrivateKey;
errorCode = uiLogic()->m_serverController->getDecryptedPrivateKey(serverCredentials, decryptedPrivateKey);
errorCode = serverController.getDecryptedPrivateKey(serverCredentials, decryptedPrivateKey);
if (errorCode == ErrorCode::NoError) {
serverCredentials.password = decryptedPrivateKey;
}

View file

@ -112,15 +112,16 @@ void CloakLogic::onPushButtonSaveClicked()
progressBarFunc.setTextVisibleFunc(true);
progressBarFunc.setTextFunc(QString("Configuring..."));
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->m_selectedDockerContainer,
containerConfig,
newContainerConfig);
},
pageFunc, progressBarFunc,
saveButtonFunc, waitInfoFunc,
busyInfoFuncy, cancelButtonFunc);
auto installAction = [this, containerConfig, &newContainerConfig]() {
ServerController serverController(m_settings);
return serverController.updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig);
};
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
saveButtonFunc, waitInfoFunc,
busyInfoFuncy, cancelButtonFunc);
if (!e) {
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);

View file

@ -162,15 +162,16 @@ void OpenVpnLogic::onPushButtonSaveClicked()
progressBarFunc.setTextVisibleFunc(true);
progressBarFunc.setTextFunc(QString("Configuring..."));
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->m_selectedDockerContainer,
containerConfig,
newContainerConfig);
},
pageFunc, progressBarFunc,
saveButtonFunc, waitInfoFunc,
busyInfoFuncy, cancelButtonFunc);
auto installAction = [this, containerConfig, &newContainerConfig]() {
ServerController serverController(m_settings);
return serverController.updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig);
};
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
saveButtonFunc, waitInfoFunc,
busyInfoFuncy, cancelButtonFunc);
if (!e) {
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);

View file

@ -104,8 +104,10 @@ void ShadowSocksLogic::onPushButtonSaveClicked()
progressBarFunc.setTextVisibleFunc(true);
progressBarFunc.setTextFunc(QString("Configuring..."));
auto installAction = [this, containerConfig, &newContainerConfig]() {
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
ServerController serverController(m_settings);
return serverController.updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig);
};
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,