moved handling of connection states from qml in connectionController
- added a check for already installed containers before installing the server/container - added a button to scan the server for installed containers - added separation for read/write and readonly servers for pageHome
This commit is contained in:
parent
3a264e6baf
commit
249be451f7
21 changed files with 466 additions and 245 deletions
|
|
@ -6,39 +6,27 @@
|
|||
|
||||
ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
const QSharedPointer<VpnConnection> &vpnConnection,
|
||||
QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_serversModel(serversModel)
|
||||
, m_containersModel(containersModel)
|
||||
, m_vpnConnection(vpnConnection)
|
||||
const QSharedPointer<VpnConnection> &vpnConnection, QObject *parent)
|
||||
: QObject(parent), m_serversModel(serversModel), m_containersModel(containersModel), m_vpnConnection(vpnConnection)
|
||||
{
|
||||
connect(m_vpnConnection.get(),
|
||||
&VpnConnection::connectionStateChanged,
|
||||
this,
|
||||
&ConnectionController::connectionStateChanged);
|
||||
connect(this,
|
||||
&ConnectionController::connectToVpn,
|
||||
m_vpnConnection.get(),
|
||||
&VpnConnection::connectToVpn,
|
||||
connect(m_vpnConnection.get(), &VpnConnection::connectionStateChanged, this,
|
||||
&ConnectionController::onConnectionStateChanged);
|
||||
connect(this, &ConnectionController::connectToVpn, m_vpnConnection.get(), &VpnConnection::connectToVpn,
|
||||
Qt::QueuedConnection);
|
||||
connect(this,
|
||||
&ConnectionController::disconnectFromVpn,
|
||||
m_vpnConnection.get(),
|
||||
&VpnConnection::disconnectFromVpn,
|
||||
connect(this, &ConnectionController::disconnectFromVpn, m_vpnConnection.get(), &VpnConnection::disconnectFromVpn,
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void ConnectionController::openConnection()
|
||||
{
|
||||
int serverIndex = m_serversModel->getDefaultServerIndex();
|
||||
ServerCredentials credentials = qvariant_cast<ServerCredentials>(
|
||||
m_serversModel->data(serverIndex, ServersModel::ServersModelRoles::CredentialsRole));
|
||||
ServerCredentials credentials =
|
||||
qvariant_cast<ServerCredentials>(m_serversModel->data(serverIndex, ServersModel::Roles::CredentialsRole));
|
||||
|
||||
DockerContainer container = m_containersModel->getDefaultContainer();
|
||||
QModelIndex containerModelIndex = m_containersModel->index(container);
|
||||
const QJsonObject &containerConfig = qvariant_cast<QJsonObject>(m_containersModel->data(containerModelIndex,
|
||||
ContainersModel::Roles::ConfigRole));
|
||||
const QJsonObject &containerConfig =
|
||||
qvariant_cast<QJsonObject>(m_containersModel->data(containerModelIndex, ContainersModel::Roles::ConfigRole));
|
||||
|
||||
if (container == DockerContainer::None) {
|
||||
emit connectionErrorOccurred(tr("VPN Protocols is not installed.\n Please install VPN container at first"));
|
||||
|
|
@ -59,13 +47,65 @@ QString ConnectionController::getLastConnectionError()
|
|||
return errorString(m_vpnConnection->lastError());
|
||||
}
|
||||
|
||||
bool ConnectionController::isConnected()
|
||||
void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state)
|
||||
{
|
||||
m_isConnected = false;
|
||||
m_connectionStateText = tr("Connection...");
|
||||
switch (state) {
|
||||
case Vpn::ConnectionState::Connected: {
|
||||
m_isConnectionInProgress = false;
|
||||
m_isConnected = true;
|
||||
m_connectionStateText = tr("Disconnect");
|
||||
break;
|
||||
}
|
||||
case Vpn::ConnectionState::Connecting: {
|
||||
m_isConnectionInProgress = true;
|
||||
break;
|
||||
}
|
||||
case Vpn::ConnectionState::Reconnecting: {
|
||||
m_isConnectionInProgress = true;
|
||||
m_connectionStateText = tr("Reconnection...");
|
||||
break;
|
||||
}
|
||||
case Vpn::ConnectionState::Disconnected: {
|
||||
m_isConnectionInProgress = false;
|
||||
m_connectionStateText = tr("Connect");
|
||||
break;
|
||||
}
|
||||
case Vpn::ConnectionState::Disconnecting: {
|
||||
m_isConnectionInProgress = true;
|
||||
m_connectionStateText = tr("Disconnection...");
|
||||
break;
|
||||
}
|
||||
case Vpn::ConnectionState::Preparing: {
|
||||
m_isConnectionInProgress = true;
|
||||
break;
|
||||
}
|
||||
case Vpn::ConnectionState::Error: {
|
||||
m_isConnectionInProgress = false;
|
||||
emit connectionErrorOccurred(getLastConnectionError());
|
||||
break;
|
||||
}
|
||||
case Vpn::ConnectionState::Unknown: {
|
||||
m_isConnectionInProgress = false;
|
||||
emit connectionErrorOccurred(getLastConnectionError());
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit connectionStateChanged();
|
||||
}
|
||||
|
||||
QString ConnectionController::connectionStateText() const
|
||||
{
|
||||
return m_connectionStateText;
|
||||
}
|
||||
|
||||
bool ConnectionController::isConnectionInProgress() const
|
||||
{
|
||||
return m_isConnectionInProgress;
|
||||
}
|
||||
|
||||
bool ConnectionController::isConnected() const
|
||||
{
|
||||
return m_isConnected;
|
||||
}
|
||||
|
||||
void ConnectionController::setIsConnected(bool isConnected)
|
||||
{
|
||||
m_isConnected = isConnected;
|
||||
emit isConnectedChanged();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue