amnezia-client/client/ui/controllers/connectionController.h
Nethius e0863a58aa
feature/api-controller-improvements (#567)
* added error handler for api controller
* while downloading the config from the api, the Connecting status is now displayed
* added a button to delete container config for api servers
* added crc check to avoid re-import of api configs
* fixed currentIndex of serversMenuContent after DefaultServerIndexChanged
* added closing the import window after re-importing the config from api
2024-02-09 18:23:26 +00:00

67 lines
2.1 KiB
C++

#ifndef CONNECTIONCONTROLLER_H
#define CONNECTIONCONTROLLER_H
#include "protocols/vpnprotocol.h"
#include "ui/models/containers_model.h"
#include "ui/models/servers_model.h"
#include "vpnconnection.h"
class ConnectionController : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(bool isConnected READ isConnected NOTIFY connectionStateChanged)
Q_PROPERTY(bool isConnectionInProgress READ isConnectionInProgress NOTIFY connectionStateChanged)
Q_PROPERTY(QString connectionStateText READ connectionStateText NOTIFY connectionStateChanged)
explicit ConnectionController(const QSharedPointer<ServersModel> &serversModel,
const QSharedPointer<ContainersModel> &containersModel,
const QSharedPointer<VpnConnection> &vpnConnection, QObject *parent = nullptr);
~ConnectionController() = default;
bool isConnected() const;
bool isConnectionInProgress() const;
QString connectionStateText() const;
public slots:
void toggleConnection(bool skipConnectionInProgressCheck);
void openConnection();
void closeConnection();
QString getLastConnectionError();
void onConnectionStateChanged(Vpn::ConnectionState state);
void onCurrentContainerUpdated();
void onTranslationsUpdated();
signals:
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
const QJsonObject &containerConfig);
void disconnectFromVpn();
void connectionStateChanged();
void connectionErrorOccurred(const QString &errorMessage);
void reconnectWithUpdatedContainer(const QString &message);
void noInstalledContainers();
private:
Vpn::ConnectionState getCurrentConnectionState();
QSharedPointer<ServersModel> m_serversModel;
QSharedPointer<ContainersModel> m_containersModel;
QSharedPointer<VpnConnection> m_vpnConnection;
bool m_isConnected = false;
bool m_isConnectionInProgress = false;
QString m_connectionStateText = tr("Connect");
Vpn::ConnectionState m_state;
};
#endif // CONNECTIONCONTROLLER_H