added PageSetupWizardViewConfig
- added a popup with a question when deleting containers/servers - added import from code and import error handling
This commit is contained in:
parent
de0cd976de
commit
420c33d3ba
37 changed files with 701 additions and 312 deletions
|
|
@ -9,21 +9,7 @@ ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &s
|
|||
|
||||
}
|
||||
|
||||
bool ConnectionController::onConnectionButtonClicked()
|
||||
{
|
||||
if (!isConnected()) {
|
||||
openVpnConnection();
|
||||
} else {
|
||||
closeVpnConnection();
|
||||
}
|
||||
}
|
||||
|
||||
bool ConnectionController::isConnected()
|
||||
{
|
||||
return m_isConnected;
|
||||
}
|
||||
|
||||
bool ConnectionController::openVpnConnection()
|
||||
void ConnectionController::openConnection()
|
||||
{
|
||||
int serverIndex = m_serversModel->getDefaultServerIndex();
|
||||
QModelIndex serverModelIndex = m_serversModel->index(serverIndex);
|
||||
|
|
@ -35,16 +21,6 @@ bool ConnectionController::openVpnConnection()
|
|||
const QJsonObject &containerConfig = qvariant_cast<QJsonObject>(m_containersModel->data(containerModelIndex,
|
||||
ContainersModel::Roles::ConfigRole));
|
||||
|
||||
//todo error handling
|
||||
qApp->processEvents();
|
||||
emit connectToVpn(serverIndex, credentials, container, containerConfig);
|
||||
m_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);
|
||||
|
|
@ -57,20 +33,23 @@ bool ConnectionController::openVpnConnection()
|
|||
// 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);
|
||||
//todo error handling
|
||||
qApp->processEvents();
|
||||
emit connectToVpn(serverIndex, credentials, container, containerConfig);
|
||||
}
|
||||
|
||||
bool ConnectionController::closeVpnConnection()
|
||||
void ConnectionController::closeConnection()
|
||||
{
|
||||
emit disconnectFromVpn();
|
||||
m_isConnected = false;
|
||||
}
|
||||
|
||||
bool ConnectionController::isConnected()
|
||||
{
|
||||
return m_isConnected;
|
||||
}
|
||||
|
||||
void ConnectionController::setIsConnected(bool isConnected)
|
||||
{
|
||||
m_isConnected = isConnected;
|
||||
emit isConnectedChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,24 +10,26 @@ class ConnectionController : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Q_PROPERTY(bool isConnected READ isConnected WRITE setIsConnected NOTIFY isConnectedChanged)
|
||||
|
||||
explicit ConnectionController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
bool onConnectionButtonClicked();
|
||||
|
||||
bool isConnected();
|
||||
void setIsConnected(bool isConnected);
|
||||
|
||||
public slots:
|
||||
void openConnection();
|
||||
void closeConnection();
|
||||
|
||||
signals:
|
||||
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig);
|
||||
void disconnectFromVpn();
|
||||
void connectionStateChanged(Vpn::ConnectionState state);
|
||||
void isConnectedChanged();
|
||||
|
||||
private:
|
||||
bool openVpnConnection();
|
||||
bool closeVpnConnection();
|
||||
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
QSharedPointer<ContainersModel> m_containersModel;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#include "importController.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "core/errorstrings.h"
|
||||
|
||||
namespace {
|
||||
enum class ConfigTypes {
|
||||
|
|
@ -39,50 +42,68 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
|||
|
||||
}
|
||||
|
||||
bool ImportController::importFromFile(const QUrl &fileUrl)
|
||||
void ImportController::extractConfigFromFile(const QUrl &fileUrl)
|
||||
{
|
||||
QFile file(fileUrl.toLocalFile());
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QByteArray data = file.readAll();
|
||||
QString data = file.readAll();
|
||||
|
||||
auto configFormat = checkConfigFormat(data);
|
||||
if (configFormat == ConfigTypes::OpenVpn) {
|
||||
return importOpenVpnConfig(data);
|
||||
m_config = extractOpenVpnConfig(data);
|
||||
} else if (configFormat == ConfigTypes::WireGuard) {
|
||||
return importWireGuardConfig(data);
|
||||
m_config = extractWireGuardConfig(data);
|
||||
} else {
|
||||
return importAmneziaConfig(data);
|
||||
m_config = extractAmneziaConfig(data);
|
||||
}
|
||||
|
||||
m_configFileName = QFileInfo(file.fileName()).fileName();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImportController::import(const QJsonObject &config)
|
||||
void ImportController::extractConfigFromCode(QString code)
|
||||
{
|
||||
m_config = extractAmneziaConfig(code);
|
||||
}
|
||||
|
||||
QString ImportController::getConfig()
|
||||
{
|
||||
return QJsonDocument(m_config).toJson(QJsonDocument::Indented);
|
||||
}
|
||||
|
||||
QString ImportController::getConfigFileName()
|
||||
{
|
||||
return m_configFileName;
|
||||
}
|
||||
|
||||
void ImportController::importConfig()
|
||||
{
|
||||
ServerCredentials credentials;
|
||||
credentials.hostName = config.value(config_key::hostName).toString();
|
||||
credentials.port = config.value(config_key::port).toInt();
|
||||
credentials.userName = config.value(config_key::userName).toString();
|
||||
credentials.secretData = config.value(config_key::password).toString();
|
||||
credentials.hostName = m_config.value(config_key::hostName).toString();
|
||||
credentials.port = m_config.value(config_key::port).toInt();
|
||||
credentials.userName = m_config.value(config_key::userName).toString();
|
||||
credentials.secretData = m_config.value(config_key::password).toString();
|
||||
|
||||
if (credentials.isValid() || config.contains(config_key::containers)) {
|
||||
m_settings->addServer(config);
|
||||
if (credentials.isValid() || m_config.contains(config_key::containers)) {
|
||||
m_serversModel->addServer(m_config);
|
||||
|
||||
if (config.value(config_key::containers).toArray().isEmpty()) {
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
if (!m_config.value(config_key::containers).toArray().isEmpty()) {
|
||||
auto newServerIndex = m_serversModel->index(m_serversModel->getServersCount() - 1);
|
||||
m_serversModel->setData(newServerIndex, true, ServersModel::ServersModelRoles::IsDefaultRole);
|
||||
}
|
||||
|
||||
emit importFinished();
|
||||
} else {
|
||||
qDebug() << "Failed to import profile";
|
||||
qDebug().noquote() << QJsonDocument(config).toJson();
|
||||
return false;
|
||||
qDebug().noquote() << QJsonDocument(m_config).toJson();
|
||||
emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError));
|
||||
}
|
||||
|
||||
return true;
|
||||
m_config = {};
|
||||
m_configFileName.clear();
|
||||
}
|
||||
|
||||
bool ImportController::importAmneziaConfig(QString data)
|
||||
QJsonObject ImportController::extractAmneziaConfig(QString &data)
|
||||
{
|
||||
data.replace("vpn://", "");
|
||||
QByteArray ba = QByteArray::fromBase64(data.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
|
|
@ -92,13 +113,7 @@ bool ImportController::importAmneziaConfig(QString data)
|
|||
ba = ba_uncompressed;
|
||||
}
|
||||
|
||||
QJsonObject config;
|
||||
config = QJsonDocument::fromJson(ba).object();
|
||||
if (!config.isEmpty()) {
|
||||
return import(config);
|
||||
}
|
||||
|
||||
return false;
|
||||
return QJsonDocument::fromJson(ba).object();
|
||||
}
|
||||
|
||||
//bool ImportController::importConnectionFromQr(const QByteArray &data)
|
||||
|
|
@ -116,7 +131,7 @@ bool ImportController::importAmneziaConfig(QString data)
|
|||
// return false;
|
||||
//}
|
||||
|
||||
bool ImportController::importOpenVpnConfig(const QString &data)
|
||||
QJsonObject ImportController::extractOpenVpnConfig(const QString &data)
|
||||
{
|
||||
QJsonObject openVpnConfig;
|
||||
openVpnConfig[config_key::config] = data;
|
||||
|
|
@ -156,10 +171,10 @@ bool ImportController::importOpenVpnConfig(const QString &data)
|
|||
|
||||
config[config_key::hostName] = hostName;
|
||||
|
||||
return import(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
bool ImportController::importWireGuardConfig(const QString &data)
|
||||
QJsonObject ImportController::extractWireGuardConfig(const QString &data)
|
||||
{
|
||||
QJsonObject lastConfig;
|
||||
lastConfig[config_key::config] = data;
|
||||
|
|
@ -200,5 +215,5 @@ bool ImportController::importWireGuardConfig(const QString &data)
|
|||
|
||||
config[config_key::hostName] = hostName;
|
||||
|
||||
return import(config);
|
||||
return config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,20 +18,27 @@ public:
|
|||
QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
bool importFromFile(const QUrl &fileUrl);
|
||||
void importConfig();
|
||||
void extractConfigFromFile(const QUrl &fileUrl);
|
||||
void extractConfigFromCode(QString code);
|
||||
QString getConfig();
|
||||
QString getConfigFileName();
|
||||
|
||||
signals:
|
||||
void importFinished();
|
||||
void importErrorOccurred(QString errorMessage);
|
||||
private:
|
||||
bool import(const QJsonObject &config);
|
||||
bool importAmneziaConfig(QString data);
|
||||
bool importOpenVpnConfig(const QString &data);
|
||||
bool importWireGuardConfig(const QString &data);
|
||||
QJsonObject extractAmneziaConfig(QString &data);
|
||||
QJsonObject extractOpenVpnConfig(const QString &data);
|
||||
QJsonObject extractWireGuardConfig(const QString &data);
|
||||
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
QSharedPointer<ContainersModel> m_containersModel;
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
||||
QJsonObject m_config;
|
||||
QString m_configFileName;
|
||||
|
||||
};
|
||||
|
||||
#endif // IMPORTCONTROLLER_H
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@
|
|||
namespace PageLoader
|
||||
{
|
||||
Q_NAMESPACE
|
||||
enum class PageEnum { PageStart = 0, PageHome, PageShare,
|
||||
enum class PageEnum { PageStart = 0, PageHome, PageShare, PageDeinstalling,
|
||||
|
||||
PageSettingsServersList, PageSettings, PageSettingsServerData, PageSettingsServerInfo,
|
||||
PageSettingsServerProtocols, PageSettingsServerServices,
|
||||
|
||||
PageSetupWizardStart, PageTest, PageSetupWizardCredentials, PageSetupWizardProtocols, PageSetupWizardEasy,
|
||||
PageSetupWizardProtocolSettings, PageSetupWizardInstalling, PageSetupWizardConfigSource,
|
||||
PageSetupWizardTextKey
|
||||
PageSetupWizardTextKey, PageSetupWizardViewConfig
|
||||
};
|
||||
Q_ENUM_NS(PageEnum)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue