added logic to the connect to vpn button
This commit is contained in:
parent
35d4222c7a
commit
116fa6777b
27 changed files with 293 additions and 125 deletions
|
|
@ -11,13 +11,18 @@ ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &s
|
|||
|
||||
bool ConnectionController::onConnectionButtonClicked()
|
||||
{
|
||||
if (!isConnected) {
|
||||
if (!isConnected()) {
|
||||
openVpnConnection();
|
||||
} else {
|
||||
closeVpnConnection();
|
||||
}
|
||||
}
|
||||
|
||||
bool ConnectionController::isConnected()
|
||||
{
|
||||
return m_isConnected;
|
||||
}
|
||||
|
||||
bool ConnectionController::openVpnConnection()
|
||||
{
|
||||
int serverIndex = m_serversModel->getDefaultServerIndex();
|
||||
|
|
@ -33,7 +38,7 @@ bool ConnectionController::openVpnConnection()
|
|||
//todo error handling
|
||||
qApp->processEvents();
|
||||
emit connectToVpn(serverIndex, credentials, container, containerConfig);
|
||||
isConnected = true;
|
||||
m_isConnected = true;
|
||||
|
||||
|
||||
// int serverIndex = m_settings->defaultServerIndex();
|
||||
|
|
@ -67,5 +72,6 @@ bool ConnectionController::openVpnConnection()
|
|||
bool ConnectionController::closeVpnConnection()
|
||||
{
|
||||
emit disconnectFromVpn();
|
||||
m_isConnected = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "ui/models/servers_model.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "protocols/vpnprotocol.h"
|
||||
|
||||
class ConnectionController : public QObject
|
||||
{
|
||||
|
|
@ -16,9 +17,12 @@ public:
|
|||
public slots:
|
||||
bool onConnectionButtonClicked();
|
||||
|
||||
bool isConnected();
|
||||
|
||||
signals:
|
||||
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig);
|
||||
void disconnectFromVpn();
|
||||
void connectionStateChanged(Vpn::ConnectionState state);
|
||||
|
||||
private:
|
||||
bool openVpnConnection();
|
||||
|
|
@ -27,7 +31,7 @@ private:
|
|||
QSharedPointer<ServersModel> m_serversModel;
|
||||
QSharedPointer<ContainersModel> m_containersModel;
|
||||
|
||||
bool isConnected = false;
|
||||
bool m_isConnected = false;
|
||||
};
|
||||
|
||||
#endif // CONNECTIONCONTROLLER_H
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ NotificationHandler::~NotificationHandler() {
|
|||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
void NotificationHandler::setConnectionState(VpnProtocol::VpnConnectionState state)
|
||||
void NotificationHandler::setConnectionState(Vpn::ConnectionState state)
|
||||
{
|
||||
if (state != VpnProtocol::Connected && state != VpnProtocol::Disconnected) {
|
||||
if (state != Vpn::ConnectionState::Connected && state != Vpn::ConnectionState::Disconnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -62,14 +62,14 @@ void NotificationHandler::setConnectionState(VpnProtocol::VpnConnectionState sta
|
|||
QString message;
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::VpnConnectionState::Connected:
|
||||
case Vpn::ConnectionState::Connected:
|
||||
m_connected = true;
|
||||
|
||||
title = tr("AmneziaVPN");
|
||||
message = tr("VPN Connected");
|
||||
break;
|
||||
|
||||
case VpnProtocol::VpnConnectionState::Disconnected:
|
||||
case Vpn::ConnectionState::Disconnected:
|
||||
if (m_connected) {
|
||||
m_connected = false;
|
||||
title = tr("AmneziaVPN");
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public:
|
|||
void messageClickHandle();
|
||||
|
||||
public slots:
|
||||
virtual void setConnectionState(VpnProtocol::VpnConnectionState state);
|
||||
virtual void setConnectionState(Vpn::ConnectionState state);
|
||||
|
||||
signals:
|
||||
void notificationShown(const QString& title, const QString& message);
|
||||
|
|
|
|||
|
|
@ -116,14 +116,14 @@ void SitesLogic::onPushButtonSitesDeleteClicked(QStringList items)
|
|||
if (!ok || row < 0 || row >= siteModel->rowCount()) return;
|
||||
sites.append(siteModel->data(row, 0).toString());
|
||||
|
||||
if (uiLogic()->m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||
if (uiLogic()->m_vpnConnection->connectionState() == Vpn::ConnectionState::Connected) {
|
||||
ips.append(siteModel->data(row, 1).toString());
|
||||
}
|
||||
}
|
||||
|
||||
m_settings->removeVpnSites(mode, sites);
|
||||
|
||||
if (uiLogic()->m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||
if (uiLogic()->m_vpnConnection->connectionState() == Vpn::ConnectionState::Connected) {
|
||||
uiLogic()->m_vpnConnection->deleteRoutes(ips);
|
||||
uiLogic()->m_vpnConnection->flushDns();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ VpnLogic::VpnLogic(UiLogic *logic, QObject *parent):
|
|||
});
|
||||
}
|
||||
else {
|
||||
onConnectionStateChanged(VpnProtocol::Disconnected);
|
||||
onConnectionStateChanged(Vpn::ConnectionState::Disconnected);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ void VpnLogic::onBytesChanged(quint64 receivedData, quint64 sentData)
|
|||
set_labelSpeedSentText(VpnConnection::bytesPerSecToText(sentData));
|
||||
}
|
||||
|
||||
void VpnLogic::onConnectionStateChanged(VpnProtocol::VpnConnectionState state)
|
||||
void VpnLogic::onConnectionStateChanged(Vpn::ConnectionState state)
|
||||
{
|
||||
qDebug() << "VpnLogic::onConnectionStateChanged" << VpnProtocol::textConnectionState(state);
|
||||
if (uiLogic()->m_vpnConnection == NULL) {
|
||||
|
|
@ -134,50 +134,50 @@ void VpnLogic::onConnectionStateChanged(VpnProtocol::VpnConnectionState state)
|
|||
set_labelStateText(VpnProtocol::textConnectionState(state));
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::Disconnected:
|
||||
case Vpn::ConnectionState::Disconnected:
|
||||
onBytesChanged(0,0);
|
||||
pbConnectChecked = false;
|
||||
pbConnectEnabled = true;
|
||||
pbConnectVisible = true;
|
||||
rbModeEnabled = true;
|
||||
break;
|
||||
case VpnProtocol::Preparing:
|
||||
case Vpn::ConnectionState::Preparing:
|
||||
pbConnectChecked = true;
|
||||
pbConnectEnabled = false;
|
||||
pbConnectVisible = false;
|
||||
rbModeEnabled = false;
|
||||
break;
|
||||
case VpnProtocol::Connecting:
|
||||
case Vpn::ConnectionState::Connecting:
|
||||
pbConnectChecked = true;
|
||||
pbConnectEnabled = false;
|
||||
pbConnectVisible = false;
|
||||
rbModeEnabled = false;
|
||||
break;
|
||||
case VpnProtocol::Connected:
|
||||
case Vpn::ConnectionState::Connected:
|
||||
pbConnectChecked = true;
|
||||
pbConnectEnabled = true;
|
||||
pbConnectVisible = true;
|
||||
rbModeEnabled = false;
|
||||
break;
|
||||
case VpnProtocol::Disconnecting:
|
||||
case Vpn::ConnectionState::Disconnecting:
|
||||
pbConnectChecked = false;
|
||||
pbConnectEnabled = false;
|
||||
pbConnectVisible = false;
|
||||
rbModeEnabled = false;
|
||||
break;
|
||||
case VpnProtocol::Reconnecting:
|
||||
case Vpn::ConnectionState::Reconnecting:
|
||||
pbConnectChecked = true;
|
||||
pbConnectEnabled = true;
|
||||
pbConnectVisible = false;
|
||||
rbModeEnabled = false;
|
||||
break;
|
||||
case VpnProtocol::Error:
|
||||
case Vpn::ConnectionState::Error:
|
||||
pbConnectChecked = false;
|
||||
pbConnectEnabled = true;
|
||||
pbConnectVisible = true;
|
||||
rbModeEnabled = true;
|
||||
break;
|
||||
case VpnProtocol::Unknown:
|
||||
case Vpn::ConnectionState::Unknown:
|
||||
pbConnectChecked = false;
|
||||
pbConnectEnabled = true;
|
||||
pbConnectVisible = true;
|
||||
|
|
@ -241,6 +241,6 @@ void VpnLogic::onConnectWorker(int serverIndex, const ServerCredentials &credent
|
|||
|
||||
void VpnLogic::onDisconnect()
|
||||
{
|
||||
onConnectionStateChanged(VpnProtocol::Disconnected);
|
||||
onConnectionStateChanged(Vpn::ConnectionState::Disconnected);
|
||||
emit disconnectFromVpn();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public slots:
|
|||
void onDisconnect();
|
||||
|
||||
void onBytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
||||
void onConnectionStateChanged(VpnProtocol::VpnConnectionState state);
|
||||
void onConnectionStateChanged(Vpn::ConnectionState state);
|
||||
void onVpnProtocolError(amnezia::ErrorCode errorCode);
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -2,21 +2,40 @@ import QtQuick
|
|||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
import ConnectionState 1.0
|
||||
|
||||
Button {
|
||||
id: root
|
||||
|
||||
implicitHeight: 190
|
||||
implicitWidth: 190
|
||||
property var isConnected: ConnectionController.isConnected
|
||||
|
||||
background: Rectangle {
|
||||
id: background
|
||||
text: "Подключиться"
|
||||
|
||||
radius: parent.width * 0.5
|
||||
// implicitHeight: 190
|
||||
// implicitWidth: 190
|
||||
|
||||
color: "transparent"
|
||||
// color: "transparent"
|
||||
|
||||
border.width: 2
|
||||
border.color: "white"
|
||||
background: Image {
|
||||
id: border
|
||||
|
||||
source: connectionProccess.running ? "/images/connectionProgress.svg" :
|
||||
ConnectionController.isConnected() ? "/images/connectionOff.svg" : "/images/connectionOn.svg"
|
||||
|
||||
RotationAnimator {
|
||||
id: connectionProccess
|
||||
|
||||
target: border
|
||||
running: false
|
||||
from: 0
|
||||
to: 360
|
||||
loops: Animation.Infinite
|
||||
duration: 1250
|
||||
}
|
||||
|
||||
Behavior on source {
|
||||
PropertyAnimation { duration: 200 }
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
|
|
@ -34,7 +53,58 @@ Button {
|
|||
}
|
||||
|
||||
onClicked: {
|
||||
background.color = "red"
|
||||
ConnectionController.onConnectionButtonClicked()
|
||||
console.log(connectionProccess.from)
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: ConnectionController
|
||||
function onConnectionStateChanged(state) {
|
||||
switch(state) {
|
||||
case ConnectionState.Unknown: {
|
||||
console.log("Unknown")
|
||||
break
|
||||
}
|
||||
case ConnectionState.Disconnected: {
|
||||
console.log("Disconnected")
|
||||
connectionProccess.running = false
|
||||
root.text = "Подключиться"
|
||||
break
|
||||
}
|
||||
case ConnectionState.Preparing: {
|
||||
console.log("Preparing")
|
||||
break
|
||||
}
|
||||
case ConnectionState.Connecting: {
|
||||
console.log("Connecting")
|
||||
connectionProccess.running = true
|
||||
root.text = "Подключение..."
|
||||
break
|
||||
}
|
||||
case ConnectionState.Connected: {
|
||||
console.log("Connected")
|
||||
connectionProccess.running = false
|
||||
root.text = "Подключено"
|
||||
break
|
||||
}
|
||||
case ConnectionState.Disconnecting: {
|
||||
console.log("Disconnecting")
|
||||
connectionProccess.running = true
|
||||
root.text = "Отключение..."
|
||||
break
|
||||
}
|
||||
case ConnectionState.Reconnecting: {
|
||||
console.log("Reconnecting")
|
||||
connectionProccess.running = true
|
||||
root.text = "Переподключение..."
|
||||
break
|
||||
}
|
||||
case ConnectionState.Error: {
|
||||
console.log("Error")
|
||||
connectionProccess.running = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ PageBase {
|
|||
|
||||
ConnectButton {
|
||||
anchors.centerIn: parent
|
||||
|
||||
text: "Подключиться"
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
|
|
|
|||
|
|
@ -23,14 +23,8 @@ PageBase {
|
|||
anchors.left: parent.left
|
||||
anchors.bottom: tabBar.top
|
||||
|
||||
width: {
|
||||
console.log(parent.width)
|
||||
return parent.width
|
||||
}
|
||||
height: {
|
||||
console.log(root.height - tabBar.implicitHeight)
|
||||
return root.height - tabBar.implicitHeight
|
||||
}
|
||||
width: parent.width
|
||||
height: root.height - tabBar.implicitHeight
|
||||
|
||||
PageHome {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,13 +45,13 @@ SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
|
|||
});
|
||||
|
||||
m_systemTrayIcon.setContextMenu(&m_menu);
|
||||
setTrayState(VpnProtocol::Disconnected);
|
||||
setTrayState(Vpn::ConnectionState::Disconnected);
|
||||
}
|
||||
|
||||
SystemTrayNotificationHandler::~SystemTrayNotificationHandler() {
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::setConnectionState(VpnProtocol::VpnConnectionState state)
|
||||
void SystemTrayNotificationHandler::setConnectionState(Vpn::ConnectionState state)
|
||||
{
|
||||
setTrayState(state);
|
||||
NotificationHandler::setConnectionState(state);
|
||||
|
|
@ -73,47 +73,47 @@ void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationR
|
|||
#endif
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::setTrayState(VpnProtocol::VpnConnectionState state)
|
||||
void SystemTrayNotificationHandler::setTrayState(Vpn::ConnectionState state)
|
||||
{
|
||||
QString resourcesPath = ":/images/tray/%1";
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::Disconnected:
|
||||
case Vpn::ConnectionState::Disconnected:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(true);
|
||||
m_trayActionDisconnect->setEnabled(false);
|
||||
break;
|
||||
case VpnProtocol::Preparing:
|
||||
case Vpn::ConnectionState::Preparing:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Connecting:
|
||||
case Vpn::ConnectionState::Connecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Connected:
|
||||
case Vpn::ConnectionState::Connected:
|
||||
setTrayIcon(QString(resourcesPath).arg(ConnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Disconnecting:
|
||||
case Vpn::ConnectionState::Disconnecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Reconnecting:
|
||||
case Vpn::ConnectionState::Reconnecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Error:
|
||||
case Vpn::ConnectionState::Error:
|
||||
setTrayIcon(QString(resourcesPath).arg(ErrorTrayIconName));
|
||||
m_trayActionConnect->setEnabled(true);
|
||||
m_trayActionDisconnect->setEnabled(false);
|
||||
break;
|
||||
case VpnProtocol::Unknown:
|
||||
case Vpn::ConnectionState::Unknown:
|
||||
default:
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public:
|
|||
explicit SystemTrayNotificationHandler(QObject* parent);
|
||||
~SystemTrayNotificationHandler();
|
||||
|
||||
void setConnectionState(VpnProtocol::VpnConnectionState state) override;
|
||||
void setConnectionState(Vpn::ConnectionState state) override;
|
||||
|
||||
protected:
|
||||
virtual void notify(Message type, const QString& title,
|
||||
|
|
@ -26,7 +26,7 @@ protected:
|
|||
private:
|
||||
void showHideWindow();
|
||||
|
||||
void setTrayState(VpnProtocol::VpnConnectionState state);
|
||||
void setTrayState(Vpn::ConnectionState state);
|
||||
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
void setTrayIcon(const QString &iconPath);
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ UiLogic::~UiLogic()
|
|||
emit hide();
|
||||
|
||||
#ifdef AMNEZIA_DESKTOP
|
||||
if (m_vpnConnection->connectionState() != VpnProtocol::VpnConnectionState::Disconnected) {
|
||||
if (m_vpnConnection->connectionState() != Vpn::ConnectionState::Disconnected) {
|
||||
m_vpnConnection->disconnectFromVpn();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
|
|
@ -131,13 +131,13 @@ void UiLogic::initializeUiLogic()
|
|||
#ifdef Q_OS_ANDROID
|
||||
connect(AndroidController::instance(), &AndroidController::initialized, [this](bool status, bool connected, const QDateTime& connectionDate) {
|
||||
if (connected) {
|
||||
pageLogic<VpnLogic>()->onConnectionStateChanged(VpnProtocol::Connected);
|
||||
pageLogic<VpnLogic>()->onConnectionStateChanged(Vpn::ConnectionState::Connected);
|
||||
m_vpnConnection->restoreConnection();
|
||||
}
|
||||
});
|
||||
if (!AndroidController::instance()->initialize(pageLogic<StartPageLogic>())) {
|
||||
qCritical() << QString("Init failed") ;
|
||||
emit VpnProtocol::Error;
|
||||
emit Vpn::ConnectionState::Error;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue