added display of amnesia dns container activity on the main page

This commit is contained in:
vladimir.kuznetsov 2023-06-27 19:07:42 +09:00
parent 2ef53c6df9
commit 795405c47d
21 changed files with 238 additions and 85 deletions

View file

@ -270,5 +270,6 @@
<file>images/controls/telegram.svg</file>
<file>ui/qml/Controls2/TextTypes/SmallTextType.qml</file>
<file>ui/qml/Filters/ContainersModelFilters.qml</file>
<file>ui/qml/Components/ShowDetailsDrawer.qml</file>
</qresource>
</RCC>

View file

@ -83,11 +83,13 @@ void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state)
}
case Vpn::ConnectionState::Error: {
m_isConnectionInProgress = false;
m_connectionStateText = tr("Connect");
emit connectionErrorOccurred(getLastConnectionError());
break;
}
case Vpn::ConnectionState::Unknown: {
m_isConnectionInProgress = false;
m_connectionStateText = tr("Connect");
emit connectionErrorOccurred(getLastConnectionError());
break;
}

View file

@ -8,15 +8,10 @@
SettingsController::SettingsController(const QSharedPointer<ServersModel> &serversModel,
const QSharedPointer<ContainersModel> &containersModel,
const std::shared_ptr<Settings> &settings,
QObject *parent)
: QObject(parent)
, m_serversModel(serversModel)
, m_containersModel(containersModel)
, m_settings(settings)
const std::shared_ptr<Settings> &settings, QObject *parent)
: QObject(parent), m_serversModel(serversModel), m_containersModel(containersModel), m_settings(settings)
{
m_appVersion = QString("%1: %2 (%3)")
.arg(tr("Software version"), QString(APP_MAJOR_VERSION), __DATE__);
m_appVersion = QString("%1: %2 (%3)").arg(tr("Software version"), QString(APP_MAJOR_VERSION), __DATE__);
}
void SettingsController::setAmneziaDns(bool enable)
@ -79,21 +74,16 @@ void SettingsController::clearLogs()
void SettingsController::backupAppConfig()
{
Utils::saveFile(".backup",
tr("Backup application config"),
"AmneziaVPN",
m_settings->backupAppConfig());
Utils::saveFile(".backup", tr("Backup application config"), "AmneziaVPN", m_settings->backupAppConfig());
}
void SettingsController::restoreAppConfig()
{
QString fileName = Utils::getFileName(Q_NULLPTR,
tr("Open backup"),
QStandardPaths::writableLocation(
QStandardPaths::DocumentsLocation),
"*.backup");
QString fileName =
Utils::getFileName(Q_NULLPTR, tr("Open backup"),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.backup");
//todo error processing
// todo error processing
if (fileName.isEmpty())
return;

View file

@ -12,12 +12,10 @@ class SettingsController : public QObject
public:
explicit SettingsController(const QSharedPointer<ServersModel> &serversModel,
const QSharedPointer<ContainersModel> &containersModel,
const std::shared_ptr<Settings> &settings,
QObject *parent = nullptr);
const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
Q_PROPERTY(QString primaryDns READ getPrimaryDns WRITE setPrimaryDns NOTIFY primaryDnsChanged)
Q_PROPERTY(
QString secondaryDns READ getSecondaryDns WRITE setSecondaryDns NOTIFY secondaryDnsChanged)
Q_PROPERTY(QString secondaryDns READ getSecondaryDns WRITE setSecondaryDns NOTIFY secondaryDnsChanged)
public slots:
void setAmneziaDns(bool enable);

View file

@ -132,6 +132,17 @@ void ContainersModel::clearCachedProfiles()
}
}
bool ContainersModel::isAmneziaDnsContainerInstalled()
{
return m_containers.contains(DockerContainer::Dns);
}
bool ContainersModel::isAmneziaDnsContainerInstalled(const int serverIndex)
{
QMap<DockerContainer, QJsonObject> containers = m_settings->containers(serverIndex);
return containers.contains(DockerContainer::Dns);
}
QHash<int, QByteArray> ContainersModel::roleNames() const
{
QHash<int, QByteArray> roles;

View file

@ -51,6 +51,9 @@ public slots:
void removeAllContainers();
void clearCachedProfiles();
bool isAmneziaDnsContainerInstalled();
bool isAmneziaDnsContainerInstalled(const int serverIndex);
protected:
QHash<int, QByteArray> roleNames() const override;

View file

@ -59,10 +59,14 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
case CredentialsLoginRole: return m_settings->serverCredentials(index.row()).userName;
case IsDefaultRole: return index.row() == m_defaultServerIndex;
case IsCurrentlyProcessedRole: return index.row() == m_currenlyProcessedServerIndex;
case HasWriteAccess: {
case HasWriteAccessRole: {
auto credentials = m_settings->serverCredentials(index.row());
return (!credentials.userName.isEmpty() && !credentials.secretData.isEmpty());
}
case ContainsAmneziaDnsRole: {
QString primaryDns = server.value(config_key::dns1).toString();
return primaryDns == protocols::dns::amneziaDnsIp;
}
}
return QVariant();
@ -109,7 +113,12 @@ bool ServersModel::isDefaultServerCurrentlyProcessed()
bool ServersModel::isCurrentlyProcessedServerHasWriteAccess()
{
return qvariant_cast<bool>(data(m_currenlyProcessedServerIndex, HasWriteAccess));
return qvariant_cast<bool>(data(m_currenlyProcessedServerIndex, HasWriteAccessRole));
}
bool ServersModel::isDefaultServerHasWriteAccess()
{
return qvariant_cast<bool>(data(m_currenlyProcessedServerIndex, HasWriteAccessRole));
}
void ServersModel::addServer(const QJsonObject &server)
@ -138,6 +147,13 @@ void ServersModel::removeServer()
endResetModel();
}
bool ServersModel::isDefaultServerConfigContainsAmneziaDns()
{
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
QString primaryDns = server.value(config_key::dns1).toString();
return primaryDns == protocols::dns::amneziaDnsIp;
}
QHash<int, QByteArray> ServersModel::roleNames() const
{
QHash<int, QByteArray> roles;
@ -147,6 +163,7 @@ QHash<int, QByteArray> ServersModel::roleNames() const
roles[CredentialsLoginRole] = "credentialsLogin";
roles[IsDefaultRole] = "isDefault";
roles[IsCurrentlyProcessedRole] = "isCurrentlyProcessed";
roles[HasWriteAccess] = "hasWriteAccess";
roles[HasWriteAccessRole] = "hasWriteAccess";
roles[ContainsAmneziaDnsRole] = "containsAmneziaDns";
return roles;
}

View file

@ -16,7 +16,8 @@ public:
CredentialsLoginRole,
IsDefaultRole,
IsCurrentlyProcessedRole,
HasWriteAccess
HasWriteAccessRole,
ContainsAmneziaDnsRole
};
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
@ -37,6 +38,7 @@ public slots:
bool isDefaultServerCurrentlyProcessed();
bool isCurrentlyProcessedServerHasWriteAccess();
bool isDefaultServerHasWriteAccess();
const int getServersCount();
@ -46,6 +48,8 @@ public slots:
void addServer(const QJsonObject &server);
void removeServer();
bool isDefaultServerConfigContainsAmneziaDns();
protected:
QHash<int, QByteArray> roleNames() const override;

View file

@ -17,6 +17,8 @@ Button {
text: ConnectionController.connectionStateText
enabled: !ConnectionController.isConnectionInProgress
background: Item {
clip: true

View file

@ -76,7 +76,6 @@ DrawerType {
}
}
BasicButtonType {
Layout.fillWidth: true
Layout.topMargin: 8

View file

@ -0,0 +1,10 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "../Controls2"
import "../Controls2/TextTypes"
Item {
}

View file

@ -8,11 +8,9 @@ import "../Controls2/TextTypes"
Rectangle {
id: root
property var rootWidth: root.width
property real rootWidth: root.width
property int currentIndex
property alias mouseArea: transportProtoButtonMouseArea
implicitWidth: transportProtoButtonGroup.implicitWidth
implicitHeight: transportProtoButtonGroup.implicitHeight
@ -30,8 +28,6 @@ Rectangle {
implicitWidth: (rootWidth - 32) / 2
text: "UDP"
hoverEnabled: !transportProtoButtonMouseArea.enabled
onClicked: {
root.currentIndex = 0
}
@ -43,17 +39,9 @@ Rectangle {
implicitWidth: (rootWidth - 32) / 2
text: "TCP"
hoverEnabled: !transportProtoButtonMouseArea.enabled
onClicked: {
root.currentIndex = 1
}
}
}
MouseArea {
id: transportProtoButtonMouseArea
anchors.fill: parent
}
}

View file

@ -19,7 +19,6 @@ Item {
property string rootButtonImage: "qrc:/images/controls/chevron-down.svg"
property string rootButtonImageColor: "#D7D8DB"
property string rootButtonBackgroundColor: "#1C1D21"
property int rootButtonMaximumWidth: 0
property string rootButtonHoveredBorderColor: "#494B50"
property string rootButtonDefaultBorderColor: "transparent"
@ -88,8 +87,6 @@ Item {
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
Layout.maximumWidth: rootButtonMaximumWidth ? rootButtonMaximumWidth : implicitWidth
color: root.textColor
text: root.text

View file

@ -88,4 +88,10 @@ RadioButton {
horizontalAlignment: Qt.AlignHCenter
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
enabled: false
}
}

View file

@ -95,13 +95,20 @@ PageType {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: {
var string = ""
if (SettingsController.isAmneziaDnsEnabled()) {
string += "Amnezia DNS | "
var description = ""
if (ServersModel.isDefaultServerHasWriteAccess()) {
if (SettingsController.isAmneziaDnsEnabled()
&& ContainersModel.isAmneziaDnsContainerInstalled(ServersModel.getDefaultServerIndex())) {
description += "Amnezia DNS | "
}
} else {
if (ServersModel.isDefaultServerConfigContainsAmneziaDns) {
description += "Amnezia DNS | "
}
}
string += root.currentContainerName + " | " + root.currentServerHostName
return string
description += root.currentContainerName + " | " + root.currentServerHostName
return description
}
}
}
@ -153,7 +160,6 @@ PageType {
rootButtonBorderWidth: 0
rootButtonImageColor: "#0E0E11"
rootButtonMaximumWidth: 150 //todo make it dynamic
rootButtonBackgroundColor: "#D7D8DB"
text: root.currentContainerName
@ -194,14 +200,6 @@ PageType {
currentIndex: ContainersModel.getDefaultContainer()
}
}
BasicButtonType {
id: dnsButton
implicitHeight: 40
text: "Amnezia DNS"
}
}
Header2Type {
@ -277,7 +275,21 @@ PageType {
Layout.fillWidth: true
text: name
descriptionText: hostName
descriptionText: {
var description = ""
if (hasWriteAccess) {
if (SettingsController.isAmneziaDnsEnabled()
&& ContainersModel.isAmneziaDnsContainerInstalled(index)) {
description += "AmneziaDNS | "
}
} else {
if (containsAmneziaDns) {
description += "AmneziaDNS | "
}
}
return description += hostName
}
checked: index === serversMenuContent.currentIndex

View file

@ -21,11 +21,12 @@ PageType {
property var installedProtocolsCount
SettingsContainersListView {
id: settingsContainersListView
Connections {
target: ServersModel
function onCurrentlyProcessedServerIndexChanged() {
updateContainersModelFilters()
settingsContainersListView.updateContainersModelFilters()
}
}

View file

@ -21,11 +21,12 @@ PageType {
property var installedServicesCount
SettingsContainersListView {
id: settingsContainersListView
Connections {
target: ServersModel
function onCurrentlyProcessedServerIndexChanged() {
updateContainersModelFilters()
settingsContainersListView.updateContainersModelFilters()
}
}

View file

@ -121,18 +121,18 @@ PageType {
var hasEmptyField = false
if (hostname.textFieldText === "") {
hostname.errorText = qsTr("ip address cannot be empty")
hostname.errorText = qsTr("Ip address cannot be empty")
hasEmptyField = true
} else if (!hostname.textField.acceptableInput) {
hostname.errorText = qsTr("Enter the address in the format 255.255.255.255:88")
}
if (username.textFieldText === "") {
username.errorText = qsTr("login cannot be empty")
username.errorText = qsTr("Login cannot be empty")
hasEmptyField = true
}
if (secretData.textFieldText === "") {
secretData.errorText = qsTr("password/private key cannot be empty")
secretData.errorText = qsTr("Password/private key cannot be empty")
hasEmptyField = true
}
return !hasEmptyField

View file

@ -29,7 +29,6 @@ PageType {
}
FlickableType {
id: fl
anchors.fill: parent
contentHeight: content.height
@ -41,18 +40,17 @@ PageType {
anchors.right: parent.right
ListView {
// todo change id naming
id: containers
id: processedContainerListView
width: parent.width
height: containers.contentItem.height
height: contentItem.height
currentIndex: -1
clip: true
interactive: false
model: proxyContainersModel
delegate: Item {
implicitWidth: containers.width
implicitHeight: delegateContent.implicitHeight
implicitWidth: processedContainerListView.width
implicitHeight: (delegateContent.implicitHeight > root.height) ? delegateContent.implicitHeight : root.height
ColumnLayout {
id: delegateContent
@ -72,8 +70,122 @@ PageType {
Layout.fillWidth: true
headerText: "Установка " + name
descriptionText: "Эти настройки можно будет изменить позже"
headerText: qsTr("Installing ") + name
descriptionText: qsTr("protocol description")
}
BasicButtonType {
id: showDetailsButton
Layout.topMargin: 16
Layout.leftMargin: -8
implicitHeight: 32
defaultColor: "transparent"
hoveredColor: Qt.rgba(1, 1, 1, 0.08)
pressedColor: Qt.rgba(1, 1, 1, 0.12)
disabledColor: "#878B91"
textColor: "#FBB26A"
text: qsTr("More detailed")
onClicked: {
showDetailsDrawer.open()
}
}
DrawerType {
id: showDetailsDrawer
width: parent.width
height: parent.height * 0.9
BackButtonType {
id: showDetailsBackButton
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: 16
anchors.leftMargin: 16
anchors.topMargin: 16
backButtonFunction: function() {
showDetailsDrawer.close()
}
}
FlickableType {
anchors.top: showDetailsBackButton.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
contentHeight: {
var emptySpaceHeight = parent.height - showDetailsBackButton.implicitHeight - showDetailsBackButton.anchors.topMargin
return (showDetailsDrawerContent.implicitHeight > emptySpaceHeight) ?
showDetailsDrawerContent.implicitHeight : emptySpaceHeight
}
ColumnLayout {
id: showDetailsDrawerContent
anchors.fill: parent
anchors.rightMargin: 16
anchors.leftMargin: 16
Header2Type {
id: showDetailsDrawerHeader
Layout.fillWidth: true
Layout.topMargin: 16
headerText: name
}
TextField {
Layout.fillWidth: true
Layout.topMargin: 16
Layout.bottomMargin: 16
padding: 0
leftPadding: 0
height: 24
color: "#D7D8DB"
font.pixelSize: 16
font.weight: Font.Medium
font.family: "PT Root UI VF"
text: qsTr("detailed protocol description")
wrapMode: Text.WordWrap
readOnly: true
background: Rectangle {
anchors.fill: parent
color: "transparent"
}
}
Rectangle {
Layout.fillHeight: true
color: "transparent"
}
BasicButtonType {
Layout.fillWidth: true
Layout.bottomMargin: 32
text: qsTr("Close")
onClicked: function() {
showDetailsDrawer.close()
}
}
}
}
}
ParagraphTextType {
@ -96,15 +208,12 @@ PageType {
Layout.fillWidth: true
Layout.topMargin: 16
headerText: "Port"
}
Rectangle {
// todo make it dynamic
implicitHeight: root.height - port.implicitHeight -
transportProtoSelector.implicitHeight - transportProtoHeader.implicitHeight -
header.implicitHeight - backButton.implicitHeight - installButton.implicitHeight - 116
Layout.fillHeight: true
color: "transparent"
}
@ -134,7 +243,9 @@ PageType {
transportProtoSelector.currentIndex = ProtocolProps.defaultTransportProto(defaultContainerProto)
port.enabled = ProtocolProps.defaultPortChangeable(defaultContainerProto)
transportProtoSelector.mouseArea.enabled = !ProtocolProps.defaultTransportProtoChangeable(defaultContainerProto)
var protocolSelectorVisible = ProtocolProps.defaultTransportProtoChangeable(defaultContainerProto)
transportProtoSelector.visible = protocolSelectorVisible
transportProtoHeader.visible = protocolSelectorVisible
}
}
}

View file

@ -260,12 +260,12 @@ PageType {
}
function fillConnectionTypeModel() {
connectionTypesModel = [amneziaConnectionFormat]
root.connectionTypesModel = [amneziaConnectionFormat]
if (currentIndex === ContainerProps.containerFromString("OpenVpn")) {
connectionTypesModel.push(openVpnConnectionFormat)
root.connectionTypesModel.push(openVpnConnectionFormat)
} else if (currentIndex === ContainerProps.containerFromString("wireGuardConnectionType")) {
connectionTypesModel.push(amneziaConnectionFormat)
root.connectionTypesModel.push(amneziaConnectionFormat)
}
}
}
@ -287,7 +287,7 @@ PageType {
drawerHeight: 0.4375
visible: accessTypeSelector.currentIndex === 0
enabled: connectionTypesModel.length > 1
enabled: root.connectionTypesModel.length > 1
descriptionText: qsTr("Connection format")
headerText: qsTr("Connection format")
@ -298,7 +298,7 @@ PageType {
imageSource: "qrc:/images/controls/chevron-right.svg"
model: connectionTypesModel
model: root.connectionTypesModel
currentIndex: 0
clickedFunction: function() {
@ -326,7 +326,7 @@ PageType {
onClicked: {
if (accessTypeSelector.currentIndex === 0) {
connectionTypesModel[connectionTypeSelector.currentIndex].func()
root.connectionTypesModel[accessTypeSelector.currentIndex].func()
} else {
ExportController.generateConfig(true)
}

View file

@ -77,8 +77,8 @@ PageType {
isSelected: tabBar.currentIndex === 0
image: "qrc:/images/controls/home.svg"
onClicked: {
ServersModel.currentlyProcessedIndex = ServersModel.defaultIndex
tabBarStackView.goToTabBarPage(PageEnum.PageHome)
ServersModel.currentlyProcessedIndex = ServersModel.defaultIndex
}
}
TabImageButtonType {
@ -94,7 +94,7 @@ PageType {
}
visible: ServersModel.isCurrentlyProcessedServerHasWriteAccess()
width: visible ? undefined : 0
width: ServersModel.isCurrentlyProcessedServerHasWriteAccess() ? undefined : 0
isSelected: tabBar.currentIndex === 1
image: "qrc:/images/controls/share-2.svg"