-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added connectionController and ConnectionButton.qml
- Loading branch information
Showing
17 changed files
with
233 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "connectionController.h" | ||
|
||
#include <QApplication> | ||
|
||
ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &serversModel, | ||
const QSharedPointer<ContainersModel> &containersModel, | ||
QObject *parent) : QObject(parent), m_serversModel(serversModel), m_containersModel(containersModel) | ||
{ | ||
|
||
} | ||
|
||
bool ConnectionController::onConnectionButtonClicked() | ||
{ | ||
if (!isConnected) { | ||
openVpnConnection(); | ||
} else { | ||
closeVpnConnection(); | ||
} | ||
} | ||
|
||
bool ConnectionController::openVpnConnection() | ||
{ | ||
int serverIndex = m_serversModel->getDefaultServerIndex(); | ||
QModelIndex serverModelIndex = m_serversModel->index(serverIndex); | ||
ServerCredentials credentials = qvariant_cast<ServerCredentials>(m_serversModel->data(serverModelIndex, | ||
ServersModel::ServersModelRoles::CredentialsRole)); | ||
|
||
DockerContainer container = m_containersModel->getDefaultContainer(); | ||
QModelIndex containerModelIndex = m_containersModel->index(container); | ||
const QJsonObject &containerConfig = qvariant_cast<QJsonObject>(m_containersModel->data(containerModelIndex, | ||
ContainersModel::ContainersModelRoles::ConfigRole)); | ||
|
||
//todo error handling | ||
qApp->processEvents(); | ||
emit connectToVpn(serverIndex, credentials, container, containerConfig); | ||
isConnected = true; | ||
|
||
|
||
// int serverIndex = m_settings->defaultServerIndex(); | ||
// ServerCredentials credentials = m_settings->serverCredentials(serverIndex); | ||
// DockerContainer container = m_settings->defaultContainer(serverIndex); | ||
|
||
// if (m_settings->containers(serverIndex).isEmpty()) { | ||
// set_labelErrorText(tr("VPN Protocols is not installed.\n Please install VPN container at first")); | ||
// set_pushButtonConnectChecked(false); | ||
// return; | ||
// } | ||
|
||
// if (container == DockerContainer::None) { | ||
// set_labelErrorText(tr("VPN Protocol not chosen")); | ||
// set_pushButtonConnectChecked(false); | ||
// return; | ||
// } | ||
|
||
|
||
// const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container); | ||
|
||
// set_labelErrorText(""); | ||
// set_pushButtonConnectChecked(true); | ||
// set_pushButtonConnectEnabled(false); | ||
|
||
// qApp->processEvents(); | ||
|
||
// emit connectToVpn(serverIndex, credentials, container, containerConfig); | ||
} | ||
|
||
bool ConnectionController::closeVpnConnection() | ||
{ | ||
emit disconnectFromVpn(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef CONNECTIONCONTROLLER_H | ||
#define CONNECTIONCONTROLLER_H | ||
|
||
#include "ui/models/servers_model.h" | ||
#include "ui/models/containers_model.h" | ||
|
||
class ConnectionController : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ConnectionController(const QSharedPointer<ServersModel> &serversModel, | ||
const QSharedPointer<ContainersModel> &containersModel, | ||
QObject *parent = nullptr); | ||
|
||
public slots: | ||
bool onConnectionButtonClicked(); | ||
|
||
signals: | ||
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig); | ||
void disconnectFromVpn(); | ||
|
||
private: | ||
bool openVpnConnection(); | ||
bool closeVpnConnection(); | ||
|
||
QSharedPointer<ServersModel> m_serversModel; | ||
QSharedPointer<ContainersModel> m_containersModel; | ||
|
||
bool isConnected = false; | ||
}; | ||
|
||
#endif // CONNECTIONCONTROLLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import QtQuick | ||
import QtQuick.Controls | ||
import QtQuick.Layouts | ||
|
||
Button { | ||
id: root | ||
|
||
implicitHeight: 190 | ||
implicitWidth: 190 | ||
|
||
background: Rectangle { | ||
id: background | ||
|
||
radius: parent.width * 0.5 | ||
|
||
color: "transparent" | ||
|
||
border.width: 2 | ||
border.color: "white" | ||
} | ||
|
||
contentItem: Text { | ||
height: 24 | ||
|
||
font.family: "PT Root UI VF" | ||
font.weight: 700 | ||
font.pixelSize: 20 | ||
|
||
color: "#D7D8DB" | ||
text: root.text | ||
|
||
horizontalAlignment: Text.AlignHCenter | ||
verticalAlignment: Text.AlignVCenter | ||
} | ||
|
||
onClicked: { | ||
background.color = "red" | ||
ConnectionController.onConnectionButtonClicked() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.