2023-05-12 23:54:31 +08:00
|
|
|
#ifndef CONNECTIONCONTROLLER_H
|
|
|
|
|
#define CONNECTIONCONTROLLER_H
|
|
|
|
|
|
2023-05-14 21:11:19 +08:00
|
|
|
#include "protocols/vpnprotocol.h"
|
2024-04-01 20:20:02 +07:00
|
|
|
#include "ui/models/clientManagementModel.h"
|
2023-08-08 19:10:14 +05:00
|
|
|
#include "ui/models/containers_model.h"
|
|
|
|
|
#include "ui/models/servers_model.h"
|
2023-06-05 22:40:35 +08:00
|
|
|
#include "vpnconnection.h"
|
2023-05-12 23:54:31 +08:00
|
|
|
|
|
|
|
|
class ConnectionController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2023-06-21 20:56:00 +09:00
|
|
|
Q_PROPERTY(bool isConnected READ isConnected NOTIFY connectionStateChanged)
|
|
|
|
|
Q_PROPERTY(bool isConnectionInProgress READ isConnectionInProgress NOTIFY connectionStateChanged)
|
|
|
|
|
Q_PROPERTY(QString connectionStateText READ connectionStateText NOTIFY connectionStateChanged)
|
2023-06-05 15:49:10 +08:00
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
explicit ConnectionController(const QSharedPointer<ServersModel> &serversModel,
|
|
|
|
|
const QSharedPointer<ContainersModel> &containersModel,
|
2024-04-01 20:20:02 +07:00
|
|
|
const QSharedPointer<ClientManagementModel> &clientManagementModel,
|
|
|
|
|
const QSharedPointer<VpnConnection> &vpnConnection,
|
|
|
|
|
const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
|
2023-05-12 23:54:31 +08:00
|
|
|
|
2023-10-04 16:09:03 +01:00
|
|
|
~ConnectionController() = default;
|
2023-08-16 12:11:34 +05:00
|
|
|
|
2023-06-21 20:56:00 +09:00
|
|
|
bool isConnected() const;
|
|
|
|
|
bool isConnectionInProgress() const;
|
|
|
|
|
QString connectionStateText() const;
|
2023-06-05 15:49:10 +08:00
|
|
|
|
|
|
|
|
public slots:
|
2024-04-01 20:20:02 +07:00
|
|
|
void toggleConnection();
|
2024-02-09 23:23:26 +05:00
|
|
|
|
2023-06-05 15:49:10 +08:00
|
|
|
void openConnection();
|
|
|
|
|
void closeConnection();
|
2023-05-14 21:11:19 +08:00
|
|
|
|
2023-06-05 22:40:35 +08:00
|
|
|
QString getLastConnectionError();
|
2023-06-21 20:56:00 +09:00
|
|
|
void onConnectionStateChanged(Vpn::ConnectionState state);
|
2023-06-05 22:40:35 +08:00
|
|
|
|
2023-09-17 17:03:39 +05:00
|
|
|
void onCurrentContainerUpdated();
|
2023-09-13 20:49:44 +08:00
|
|
|
|
2023-10-06 14:37:10 +08:00
|
|
|
void onTranslationsUpdated();
|
2023-10-01 11:12:27 +08:00
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
ErrorCode updateProtocolConfig(const DockerContainer container, const ServerCredentials &credentials,
|
|
|
|
|
QJsonObject &containerConfig);
|
|
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
signals:
|
2023-08-08 19:10:14 +05:00
|
|
|
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
|
2024-04-01 20:20:02 +07:00
|
|
|
const QJsonObject &vpnConfiguration);
|
2023-05-12 23:54:31 +08:00
|
|
|
void disconnectFromVpn();
|
2023-06-21 20:56:00 +09:00
|
|
|
void connectionStateChanged();
|
2023-05-12 23:54:31 +08:00
|
|
|
|
2023-08-08 19:10:14 +05:00
|
|
|
void connectionErrorOccurred(const QString &errorMessage);
|
2023-09-17 17:03:39 +05:00
|
|
|
void reconnectWithUpdatedContainer(const QString &message);
|
2023-06-05 22:40:35 +08:00
|
|
|
|
2024-02-09 23:23:26 +05:00
|
|
|
void noInstalledContainers();
|
|
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
void connectButtonClicked();
|
|
|
|
|
void preparingConfig();
|
|
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
private:
|
2023-10-01 11:12:27 +08:00
|
|
|
Vpn::ConnectionState getCurrentConnectionState();
|
2024-04-01 20:20:02 +07:00
|
|
|
bool isProtocolConfigExists(const QJsonObject &containerConfig, const DockerContainer container);
|
2023-10-01 11:12:27 +08:00
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
QSharedPointer<ServersModel> m_serversModel;
|
|
|
|
|
QSharedPointer<ContainersModel> m_containersModel;
|
2024-04-01 20:20:02 +07:00
|
|
|
QSharedPointer<ClientManagementModel> m_clientManagementModel;
|
2023-05-12 23:54:31 +08:00
|
|
|
|
2023-06-05 22:40:35 +08:00
|
|
|
QSharedPointer<VpnConnection> m_vpnConnection;
|
|
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
std::shared_ptr<Settings> m_settings;
|
|
|
|
|
|
2023-05-14 21:11:19 +08:00
|
|
|
bool m_isConnected = false;
|
2023-06-21 20:56:00 +09:00
|
|
|
bool m_isConnectionInProgress = false;
|
|
|
|
|
QString m_connectionStateText = tr("Connect");
|
2023-10-01 11:12:27 +08:00
|
|
|
|
|
|
|
|
Vpn::ConnectionState m_state;
|
2023-05-12 23:54:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // CONNECTIONCONTROLLER_H
|