Merge branch 'feature/new-gui' of github.com:amnezia-vpn/amnezia-client into feature/new-gui

This commit is contained in:
vladimir.kuznetsov 2023-06-07 18:28:44 +08:00
commit 3034019d5a
10 changed files with 87 additions and 88 deletions

View file

@ -69,14 +69,14 @@ void SshConfigurator::openSshTerminal(const ServerCredentials &credentials)
p->setProcessEnvironment(prepareEnv()); p->setProcessEnvironment(prepareEnv());
p->setProgram(qApp->applicationDirPath() + "\\cygwin\\putty.exe"); p->setProgram(qApp->applicationDirPath() + "\\cygwin\\putty.exe");
if (credentials.password.contains("PRIVATE KEY")) { if (credentials.secretData.contains("PRIVATE KEY")) {
// todo: connect by key // todo: connect by key
// p->setNativeArguments(QString("%1@%2") // p->setNativeArguments(QString("%1@%2")
// .arg(credentials.userName).arg(credentials.hostName).arg(credentials.password)); // .arg(credentials.userName).arg(credentials.hostName).arg(credentials.secretData));
} }
else { else {
p->setNativeArguments(QString("%1@%2 -pw %3") p->setNativeArguments(QString("%1@%2 -pw %3")
.arg(credentials.userName).arg(credentials.hostName).arg(credentials.password)); .arg(credentials.userName).arg(credentials.hostName).arg(credentials.secretData));
} }
#else #else
p->setProgram("/bin/bash"); p->setProgram("/bin/bash");

View file

@ -35,14 +35,14 @@ Ikev2Protocol::~Ikev2Protocol()
void Ikev2Protocol::stop() void Ikev2Protocol::stop()
{ {
setConnectionState(VpnProtocol::Disconnecting); setConnectionState(Vpn::ConnectionState::Disconnecting);
{ {
if (! disconnect_vpn() ){ if (! disconnect_vpn() ){
qDebug()<<"We don't disconnect"; qDebug()<<"We don't disconnect";
setConnectionState(VpnProtocol::Error); setConnectionState(Vpn::ConnectionState::Error);
} }
else { else {
setConnectionState(VpnProtocol::Disconnected); setConnectionState(Vpn::ConnectionState::Disconnected);
} }
} }
} }
@ -55,40 +55,40 @@ void Ikev2Protocol::newConnectionStateEventReceived(UINT unMsg, tagRASCONNSTATE
{ {
case RASCS_OpenPort: case RASCS_OpenPort:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
setConnectionState(Preparing); setConnectionState(Vpn::ConnectionState::Preparing);
break; break;
case RASCS_PortOpened: case RASCS_PortOpened:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
setConnectionState(Preparing); setConnectionState(Vpn::ConnectionState::Preparing);
break; break;
case RASCS_ConnectDevice: case RASCS_ConnectDevice:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
setConnectionState(Preparing); setConnectionState(Vpn::ConnectionState::Preparing);
break; break;
case RASCS_DeviceConnected: case RASCS_DeviceConnected:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
setConnectionState(Preparing); setConnectionState(Vpn::ConnectionState::Preparing);
break; break;
case RASCS_AllDevicesConnected: case RASCS_AllDevicesConnected:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
setConnectionState(Preparing); setConnectionState(Vpn::ConnectionState::Preparing);
break; break;
case RASCS_Authenticate: case RASCS_Authenticate:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
setConnectionState(Preparing); setConnectionState(Vpn::ConnectionState::Preparing);
break; break;
case RASCS_AuthNotify: case RASCS_AuthNotify:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
if (dwError != 0) { if (dwError != 0) {
//qDebug() << "have error" << dwError; //qDebug() << "have error" << dwError;
setConnectionState(Disconnected); setConnectionState(Vpn::ConnectionState::Disconnected);
} else { } else {
//qDebug() << "RASCS_AuthNotify but no error" << dwError; //qDebug() << "RASCS_AuthNotify but no error" << dwError;
} }
break; break;
case RASCS_AuthRetry: case RASCS_AuthRetry:
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
setConnectionState(Preparing); setConnectionState(Vpn::ConnectionState::Preparing);
break; break;
case RASCS_AuthCallback: case RASCS_AuthCallback:
qDebug()<<__FUNCTION__ << __LINE__; qDebug()<<__FUNCTION__ << __LINE__;
@ -151,16 +151,16 @@ void Ikev2Protocol::newConnectionStateEventReceived(UINT unMsg, tagRASCONNSTATE
qDebug()<<__FUNCTION__ << __LINE__; qDebug()<<__FUNCTION__ << __LINE__;
break; break;
case RASCS_PasswordExpired: case RASCS_PasswordExpired:
setConnectionState(Error); setConnectionState(Vpn::ConnectionState::Error);
qDebug()<<__FUNCTION__ << __LINE__; qDebug()<<__FUNCTION__ << __LINE__;
break; break;
case RASCS_Connected: // = RASCS_DONE: case RASCS_Connected: // = RASCS_DONE:
setConnectionState(Connected); setConnectionState(Vpn::ConnectionState::Connected);
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
break; break;
case RASCS_Disconnected: case RASCS_Disconnected:
setConnectionState(Disconnected); setConnectionState(Vpn::ConnectionState::Disconnected);
//qDebug()<<__FUNCTION__ << __LINE__; //qDebug()<<__FUNCTION__ << __LINE__;
break; break;
default: default:
@ -177,7 +177,7 @@ void Ikev2Protocol::readIkev2Configuration(const QJsonObject &configuration)
ErrorCode Ikev2Protocol::start() ErrorCode Ikev2Protocol::start()
{ {
QByteArray cert = QByteArray::fromBase64(m_config[config_key::cert].toString().toUtf8()); QByteArray cert = QByteArray::fromBase64(m_config[config_key::cert].toString().toUtf8());
setConnectionState(Connecting); setConnectionState(Vpn::ConnectionState::Connecting);
QTemporaryFile certFile; QTemporaryFile certFile;
certFile.setAutoRemove(false); certFile.setAutoRemove(false);

View file

@ -21,23 +21,25 @@ bool ContainersModel::setData(const QModelIndex &index, const QVariant &value, i
DockerContainer container = ContainerProps::allContainers().at(index.row()); DockerContainer container = ContainerProps::allContainers().at(index.row());
switch (role) { switch (role) {
case NameRole: case NameRole:
// return ContainerProps::containerHumanNames().value(container); // return ContainerProps::containerHumanNames().value(container);
case DescRole: case DescRole:
// return ContainerProps::containerDescriptions().value(container); // return ContainerProps::containerDescriptions().value(container);
case ConfigRole: case ConfigRole:
m_settings->setContainerConfig(m_currentlyProcessedServerIndex, m_settings->setContainerConfig(m_currentlyProcessedServerIndex,
container, container,
value.toJsonObject()); value.toJsonObject());
case ServiceTypeRole: case ServiceTypeRole:
// return ContainerProps::containerService(container); // return ContainerProps::containerService(container);
case DockerContainerRole: case DockerContainerRole:
// return container; // return container;
case IsInstalledRole: case IsInstalledRole:
// return m_settings->containers(m_currentlyProcessedServerIndex).contains(container); // return m_settings->containers(m_currentlyProcessedServerIndex).contains(container);
case IsDefaultRole: case IsDefaultRole: {
m_settings->setDefaultContainer(m_currentlyProcessedServerIndex, container); m_settings->setDefaultContainer(m_currentlyProcessedServerIndex, container);
emit defaultContainerChanged(); m_defaultContainerIndex = container;
emit defaultContainerChanged();
}
} }
emit dataChanged(index, index); emit dataChanged(index, index);
@ -58,8 +60,10 @@ QVariant ContainersModel::data(const QModelIndex &index, int role) const
return ContainerProps::containerHumanNames().value(container); return ContainerProps::containerHumanNames().value(container);
case DescRole: case DescRole:
return ContainerProps::containerDescriptions().value(container); return ContainerProps::containerDescriptions().value(container);
case ConfigRole: case ConfigRole: {
return m_settings->containerConfig(m_currentlyProcessedServerIndex, container); if (container == DockerContainer::None) return QJsonObject();
return m_containers.value(container);
}
case ServiceTypeRole: case ServiceTypeRole:
return ContainerProps::containerService(container); return ContainerProps::containerService(container);
case DockerContainerRole: case DockerContainerRole:
@ -71,11 +75,11 @@ QVariant ContainersModel::data(const QModelIndex &index, int role) const
case EasySetupDescriptionRole: case EasySetupDescriptionRole:
return ContainerProps::easySetupDescription(container); return ContainerProps::easySetupDescription(container);
case IsInstalledRole: case IsInstalledRole:
return m_settings->containers(m_currentlyProcessedServerIndex).contains(container); return m_containers.contains(container);
case IsCurrentlyInstalledRole: case IsCurrentlyInstalledRole:
return container == static_cast<DockerContainer>(m_currentlyInstalledContainerIndex); return container == static_cast<DockerContainer>(m_currentlyInstalledContainerIndex);
case IsDefaultRole: case IsDefaultRole:
return container == m_settings->defaultContainer(m_currentlyProcessedServerIndex); return container == m_defaultContainerIndex;
case IsSupportedRole: case IsSupportedRole:
return ContainerProps::isSupportedByCurrentPlatform(container); return ContainerProps::isSupportedByCurrentPlatform(container);
} }
@ -87,6 +91,8 @@ void ContainersModel::setCurrentlyProcessedServerIndex(int index)
{ {
beginResetModel(); beginResetModel();
m_currentlyProcessedServerIndex = index; m_currentlyProcessedServerIndex = index;
m_containers = m_settings->containers(m_currentlyProcessedServerIndex);
m_defaultContainerIndex = m_settings->defaultContainer(m_currentlyProcessedServerIndex);
endResetModel(); endResetModel();
emit defaultContainerChanged(); emit defaultContainerChanged();
} }
@ -98,12 +104,12 @@ void ContainersModel::setCurrentlyInstalledContainerIndex(int index)
DockerContainer ContainersModel::getDefaultContainer() DockerContainer ContainersModel::getDefaultContainer()
{ {
return m_settings->defaultContainer(m_currentlyProcessedServerIndex); return m_defaultContainerIndex;
} }
QString ContainersModel::getDefaultContainerName() QString ContainersModel::getDefaultContainerName()
{ {
return ContainerProps::containerHumanNames().value(getDefaultContainer()); return ContainerProps::containerHumanNames().value(m_defaultContainerIndex);
} }
int ContainersModel::getCurrentlyInstalledContainerIndex() int ContainersModel::getCurrentlyInstalledContainerIndex()

View file

@ -55,8 +55,13 @@ protected:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
private: private:
QMap<DockerContainer, QJsonObject> m_containers;
int m_currentlyProcessedServerIndex; int m_currentlyProcessedServerIndex;
int m_currentlyInstalledContainerIndex; int m_currentlyInstalledContainerIndex;
DockerContainer m_defaultContainerIndex;
std::shared_ptr<Settings> m_settings; std::shared_ptr<Settings> m_settings;
}; };

View file

@ -2,24 +2,28 @@
ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent) ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent)
{ {
m_servers = m_settings->serversArray();
m_defaultServerIndex = m_settings->defaultServerIndex();
} }
int ServersModel::rowCount(const QModelIndex &parent) const int ServersModel::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
return static_cast<int>(m_settings->serversCount()); return static_cast<int>(m_servers.size());
} }
bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int role) bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
if (!index.isValid() || index.row() < 0 if (!index.isValid() || index.row() < 0
|| index.row() >= static_cast<int>(m_settings->serversCount())) { || index.row() >= static_cast<int>(m_servers.size())) {
return false; return false;
} }
switch (role) { switch (role) {
case IsDefaultRole: m_settings->setDefaultServer(index.row()); case IsDefaultRole: {
m_settings->setDefaultServer(index.row());
m_defaultServerIndex = m_settings->defaultServerIndex();
}
default: return true; default: return true;
} }
@ -29,12 +33,11 @@ bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int
QVariant ServersModel::data(const QModelIndex &index, int role) const QVariant ServersModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_settings->serversCount())) { if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers.size())) {
return QVariant(); return QVariant();
} }
const QJsonArray &servers = m_settings->serversArray(); const QJsonObject server = m_servers.at(index.row()).toObject();
const QJsonObject server = servers.at(index.row()).toObject();
switch (role) { switch (role) {
case NameRole: { case NameRole: {
@ -49,7 +52,7 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
case CredentialsRole: case CredentialsRole:
return QVariant::fromValue(m_settings->serverCredentials(index.row())); return QVariant::fromValue(m_settings->serverCredentials(index.row()));
case IsDefaultRole: case IsDefaultRole:
return index.row() == m_settings->defaultServerIndex(); return index.row() == m_defaultServerIndex;
case IsCurrentlyProcessedRole: case IsCurrentlyProcessedRole:
return index.row() == m_currenlyProcessedServerIndex; return index.row() == m_currenlyProcessedServerIndex;
} }
@ -59,12 +62,12 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
const int ServersModel::getDefaultServerIndex() const int ServersModel::getDefaultServerIndex()
{ {
return m_settings->defaultServerIndex(); return m_defaultServerIndex;
} }
const int ServersModel::getServersCount() const int ServersModel::getServersCount()
{ {
return m_settings->serversCount(); return m_servers.count();
} }
void ServersModel::setCurrentlyProcessedServerIndex(int index) void ServersModel::setCurrentlyProcessedServerIndex(int index)
@ -74,7 +77,7 @@ void ServersModel::setCurrentlyProcessedServerIndex(int index)
bool ServersModel::isDefaultServerCurrentlyProcessed() bool ServersModel::isDefaultServerCurrentlyProcessed()
{ {
return m_settings->defaultServerIndex() == m_currenlyProcessedServerIndex; return m_defaultServerIndex == m_currenlyProcessedServerIndex;
} }
ServerCredentials ServersModel::getCurrentlyProcessedServerCredentials() ServerCredentials ServersModel::getCurrentlyProcessedServerCredentials()
@ -86,6 +89,7 @@ void ServersModel::addServer(const QJsonObject &server)
{ {
beginResetModel(); beginResetModel();
m_settings->addServer(server); m_settings->addServer(server);
m_servers = m_settings->serversArray();
endResetModel(); endResetModel();
} }
@ -93,6 +97,7 @@ void ServersModel::removeServer()
{ {
beginResetModel(); beginResetModel();
m_settings->removeServer(m_currenlyProcessedServerIndex); m_settings->removeServer(m_currenlyProcessedServerIndex);
m_servers = m_settings->serversArray();
if (m_settings->defaultServerIndex() == m_currenlyProcessedServerIndex) { if (m_settings->defaultServerIndex() == m_currenlyProcessedServerIndex) {
m_settings->setDefaultServer(0); m_settings->setDefaultServer(0);

View file

@ -46,8 +46,11 @@ protected:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
private: private:
QJsonArray m_servers;
std::shared_ptr<Settings> m_settings; std::shared_ptr<Settings> m_settings;
int m_defaultServerIndex;
int m_currenlyProcessedServerIndex; int m_currenlyProcessedServerIndex;
}; };

View file

@ -38,8 +38,6 @@ ListView {
ButtonGroup.group: containersRadioButtonGroup ButtonGroup.group: containersRadioButtonGroup
checked: isDefault
indicator: Rectangle { indicator: Rectangle {
anchors.fill: parent anchors.fill: parent
color: containerRadioButton.hovered ? Qt.rgba(1, 1, 1, 0.08) : "transparent" color: containerRadioButton.hovered ? Qt.rgba(1, 1, 1, 0.08) : "transparent"

View file

@ -34,22 +34,6 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
color: "transparent" color: "transparent"
ShaderEffectSource {
id: effectSource
sourceItem: background
anchors.fill: background
sourceRect: Qt.rect(x,y, width, height)
}
FastBlur {
id: blur
anchors.fill: effectSource
source: effectSource
radius: 100
}
} }
} }
} }

View file

@ -137,21 +137,6 @@ PageType {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
spacing: 8 spacing: 8
SortFilterProxyModel {
id: proxyContainersModel
sourceModel: ContainersModel
filters: [
ValueFilter {
roleName: "serviceType"
value: ProtocolEnum.Vpn
},
ValueFilter {
roleName: "isSupported"
value: true
}
]
}
DropDownType { DropDownType {
id: containersDropDown id: containersDropDown
@ -176,7 +161,20 @@ PageType {
listView: HomeContainersListView { listView: HomeContainersListView {
rootWidth: root.width rootWidth: root.width
model: proxyContainersModel model: SortFilterProxyModel {
id: proxyContainersModel
sourceModel: ContainersModel
filters: [
ValueFilter {
roleName: "serviceType"
value: ProtocolEnum.Vpn
},
ValueFilter {
roleName: "isSupported"
value: true
}
]
}
currentIndex: ContainersModel.getDefaultContainer() currentIndex: ContainersModel.getDefaultContainer()
} }
} }

View file

@ -45,9 +45,9 @@ PageType {
Component.onCompleted: { Component.onCompleted: {
var pagePath = PageController.getPagePath(PageEnum.PageHome) var pagePath = PageController.getPagePath(PageEnum.PageHome)
tabBarStackView.push(pagePath, { "objectName" : pagePath })
ServersModel.setCurrentlyProcessedServerIndex(ServersModel.getDefaultServerIndex()) ServersModel.setCurrentlyProcessedServerIndex(ServersModel.getDefaultServerIndex())
ContainersModel.setCurrentlyProcessedServerIndex(ServersModel.getDefaultServerIndex()) ContainersModel.setCurrentlyProcessedServerIndex(ServersModel.getDefaultServerIndex())
tabBarStackView.push(pagePath, { "objectName" : pagePath })
} }
} }
@ -71,8 +71,8 @@ PageType {
isSelected: tabBar.currentIndex === 0 isSelected: tabBar.currentIndex === 0
image: "qrc:/images/controls/home.svg" image: "qrc:/images/controls/home.svg"
onClicked: { onClicked: {
tabBarStackView.goToTabBarPage(PageEnum.PageHome)
ContainersModel.setCurrentlyProcessedServerIndex(ServersModel.getDefaultServerIndex()) ContainersModel.setCurrentlyProcessedServerIndex(ServersModel.getDefaultServerIndex())
tabBarStackView.goToTabBarPage(PageEnum.PageHome)
} }
} }
TabImageButtonType { TabImageButtonType {