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
|
|
|
|
2024-04-12 20:00:21 +05:00
|
|
|
explicit ConnectionController(const QSharedPointer<ServersModel> &serversModel, const QSharedPointer<ContainersModel> &containersModel,
|
2024-04-01 20:20:02 +07:00
|
|
|
const QSharedPointer<ClientManagementModel> &clientManagementModel,
|
2024-04-12 20:00:21 +05:00
|
|
|
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
|
|
|
|
2024-05-25 13:00:51 +03:00
|
|
|
ErrorCode 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
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
signals:
|
2024-04-12 20:00:21 +05:00
|
|
|
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, 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
|
|
|
|
2024-05-25 13:00:51 +03:00
|
|
|
void connectionErrorOccurred(ErrorCode errorCode);
|
2023-09-17 17:03:39 +05:00
|
|
|
void reconnectWithUpdatedContainer(const QString &message);
|
2023-06-05 22:40:35 +08:00
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
void connectButtonClicked();
|
|
|
|
|
void preparingConfig();
|
2025-02-15 11:50:42 +07:00
|
|
|
void prepareConfig();
|
2024-08-20 16:54:05 +07:00
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
private:
|
2023-10-01 11:12:27 +08:00
|
|
|
Vpn::ConnectionState getCurrentConnectionState();
|
|
|
|
|
|
2024-08-20 16:54:05 +07:00
|
|
|
void continueConnection();
|
2024-05-16 06:19:56 -07: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
|