From cd055cff628cabc56efbf9bd893b8078d2e8fc3d Mon Sep 17 00:00:00 2001 From: Nethius Date: Thu, 29 Feb 2024 17:22:17 +0700 Subject: [PATCH] removed the display of servers without containers on PageShare (#609) * removed the display of servers without containers on PageShare * removed unused isAnyContainerInstalled() from containers model * added tab navigation to the share connection drawer * fixed display of default server without containers on PageShare --- .../ui/controllers/connectionController.cpp | 5 ++-- client/ui/controllers/pageController.cpp | 2 +- client/ui/controllers/pageController.h | 2 +- client/ui/models/containers_model.cpp | 14 ---------- client/ui/models/containers_model.h | 2 -- client/ui/models/servers_model.cpp | 27 ++++++++++++------- client/ui/models/servers_model.h | 6 +++-- .../qml/Components/ShareConnectionDrawer.qml | 21 +++++++++++++++ client/ui/qml/Controls2/BasicButtonType.qml | 17 ++++++------ client/ui/qml/Pages2/PageHome.qml | 2 +- client/ui/qml/Pages2/PageSetupWizardEasy.qml | 5 ++-- client/ui/qml/Pages2/PageShare.qml | 13 +++++++-- client/ui/qml/Pages2/PageStart.qml | 6 ++--- 13 files changed, 73 insertions(+), 49 deletions(-) diff --git a/client/ui/controllers/connectionController.cpp b/client/ui/controllers/connectionController.cpp index 7b59c901..686ddf6b 100644 --- a/client/ui/controllers/connectionController.cpp +++ b/client/ui/controllers/connectionController.cpp @@ -25,12 +25,13 @@ ConnectionController::ConnectionController(const QSharedPointer &s void ConnectionController::openConnection() { - if (!m_containersModel->isAnyContainerInstalled()) { + int serverIndex = m_serversModel->getDefaultServerIndex(); + + if (!m_serversModel->data(serverIndex, ServersModel::Roles::HasInstalledContainers).toBool()) { emit noInstalledContainers(); return; } - int serverIndex = m_serversModel->getDefaultServerIndex(); ServerCredentials credentials = m_serversModel->getServerCredentials(serverIndex); DockerContainer container = qvariant_cast(m_serversModel->data(serverIndex, ServersModel::Roles::DefaultContainerRole)); diff --git a/client/ui/controllers/pageController.cpp b/client/ui/controllers/pageController.cpp index 1a73a1b1..a799c52f 100644 --- a/client/ui/controllers/pageController.cpp +++ b/client/ui/controllers/pageController.cpp @@ -132,7 +132,7 @@ bool PageController::isTriggeredByConnectButton() return m_isTriggeredByConnectButton; } -void PageController::setTriggeredBtConnectButton(bool trigger) +void PageController::setTriggeredByConnectButton(bool trigger) { m_isTriggeredByConnectButton = trigger; } diff --git a/client/ui/controllers/pageController.h b/client/ui/controllers/pageController.h index cfaabebd..b802be47 100644 --- a/client/ui/controllers/pageController.h +++ b/client/ui/controllers/pageController.h @@ -83,7 +83,7 @@ public slots: void showOnStartup(); bool isTriggeredByConnectButton(); - void setTriggeredBtConnectButton(bool trigger); + void setTriggeredByConnectButton(bool trigger); void closeApplication(); diff --git a/client/ui/models/containers_model.cpp b/client/ui/models/containers_model.cpp index c060343f..38e547df 100644 --- a/client/ui/models/containers_model.cpp +++ b/client/ui/models/containers_model.cpp @@ -83,20 +83,6 @@ QJsonObject ContainersModel::getContainerConfig(const int containerIndex) return qvariant_cast(data(index(containerIndex), ConfigRole)); } -bool ContainersModel::isAnyContainerInstalled() -{ - for (int row=0; row < rowCount(); row++) { - QModelIndex idx = this->index(row, 0); - - if (this->data(idx, IsInstalledRole).toBool() && - this->data(idx, ServiceTypeRole).toInt() == ServiceType::Vpn) { - return true; - } - } - - return false; -} - QHash ContainersModel::roleNames() const { QHash roles; diff --git a/client/ui/models/containers_model.h b/client/ui/models/containers_model.h index 320a762a..385adf57 100644 --- a/client/ui/models/containers_model.h +++ b/client/ui/models/containers_model.h @@ -49,8 +49,6 @@ public slots: QJsonObject getContainerConfig(const int containerIndex); - bool isAnyContainerInstalled(); - protected: QHash roleNames() const override; diff --git a/client/ui/models/servers_model.cpp b/client/ui/models/servers_model.cpp index 3c72ee49..8a6c5a38 100644 --- a/client/ui/models/servers_model.cpp +++ b/client/ui/models/servers_model.cpp @@ -87,6 +87,9 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const case DefaultContainerRole: { return ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString()); } + case HasInstalledContainers: { + return serverHasInstalledContainers(index.row()); + } case IsServerFromApiRole: { return server.value(config_key::configVersion).toInt(); } @@ -302,6 +305,7 @@ QHash ServersModel::roleNames() const roles[ContainsAmneziaDnsRole] = "containsAmneziaDns"; roles[DefaultContainerRole] = "defaultContainer"; + roles[HasInstalledContainers] = "hasInstalledContainers"; roles[IsServerFromApiRole] = "isServerFromApi"; return roles; @@ -548,6 +552,19 @@ bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc) return false; } +bool ServersModel::serverHasInstalledContainers(const int serverIndex) const +{ + QJsonObject server = m_servers.at(serverIndex).toObject(); + const auto containers = server.value(config_key::containers).toArray(); + for (auto it = containers.begin(); it != containers.end(); it++) { + auto container = ContainerProps::containerFromString(it->toObject().value(config_key::container).toString()); + if (ContainerProps::containerService(container) == ServiceType::Vpn) { + return true; + } + } + return false; +} + QVariant ServersModel::getDefaultServerData(const QString roleString) { auto roles = roleNames(); @@ -560,11 +577,6 @@ QVariant ServersModel::getDefaultServerData(const QString roleString) return {}; } -void ServersModel::setDefaultServerData(const QString roleString, const QVariant &value) -{ - -} - QVariant ServersModel::getProcessedServerData(const QString roleString) { auto roles = roleNames(); @@ -577,11 +589,6 @@ QVariant ServersModel::getProcessedServerData(const QString roleString) return {}; } -void ServersModel::setProcessedServerData(const QString roleString, const QVariant &value) -{ - -} - bool ServersModel::isDefaultServerDefaultContainerHasSplitTunneling() { auto server = m_servers.at(m_defaultServerIndex).toObject(); diff --git a/client/ui/models/servers_model.h b/client/ui/models/servers_model.h index 3e24e46c..00d8d06c 100644 --- a/client/ui/models/servers_model.h +++ b/client/ui/models/servers_model.h @@ -28,6 +28,7 @@ public: DefaultContainerRole, + HasInstalledContainers, IsServerFromApiRole, HasAmneziaDns @@ -101,10 +102,8 @@ public slots: bool isServerFromApiAlreadyExists(const quint16 crc); QVariant getDefaultServerData(const QString roleString); - void setDefaultServerData(const QString roleString, const QVariant &value); QVariant getProcessedServerData(const QString roleString); - void setProcessedServerData(const QString roleString, const QVariant &value); bool isDefaultServerDefaultContainerHasSplitTunneling(); @@ -123,6 +122,7 @@ signals: private: ServerCredentials serverCredentials(int index) const; + void updateContainersModel(); void updateDefaultServerContainersModel(); @@ -130,6 +130,8 @@ private: bool isAmneziaDnsContainerInstalled(const int serverIndex) const; + bool serverHasInstalledContainers(const int serverIndex) const; + QJsonArray m_servers; std::shared_ptr m_settings; diff --git a/client/ui/qml/Components/ShareConnectionDrawer.qml b/client/ui/qml/Components/ShareConnectionDrawer.qml index d816cd41..46206703 100644 --- a/client/ui/qml/Components/ShareConnectionDrawer.qml +++ b/client/ui/qml/Components/ShareConnectionDrawer.qml @@ -38,6 +38,14 @@ DrawerType2 { expandedContent: Item { implicitHeight: root.expandedHeight + Connections { + target: root + + function onOpened() { + header.forceActiveFocus() + } + } + Header2Type { id: header anchors.top: parent.top @@ -48,6 +56,8 @@ DrawerType2 { anchors.rightMargin: 16 headerText: root.headerText + + KeyNavigation.tab: shareButton } FlickableType { @@ -68,12 +78,15 @@ DrawerType2 { visible: root.contentVisible BasicButtonType { + id: shareButton Layout.fillWidth: true Layout.topMargin: 16 text: qsTr("Share") imageSource: "qrc:/images/controls/share-2.svg" + KeyNavigation.tab: copyConfigTextButton + clickedFunc: function() { var fileName = "" if (GC.isMobile()) { @@ -107,6 +120,8 @@ DrawerType2 { text: qsTr("Copy") imageSource: "qrc:/images/controls/copy.svg" + + KeyNavigation.tab: copyNativeConfigStringButton.visible ? copyNativeConfigStringButton : showSettingsButton } BasicButtonType { @@ -125,9 +140,13 @@ DrawerType2 { text: qsTr("Copy config string") imageSource: "qrc:/images/controls/copy.svg" + + KeyNavigation.tab: showSettingsButton } BasicButtonType { + id: showSettingsButton + Layout.fillWidth: true Layout.topMargin: 24 @@ -143,6 +162,8 @@ DrawerType2 { clickedFunc: function() { configContentDrawer.open() } + + KeyNavigation.tab: header } DrawerType2 { diff --git a/client/ui/qml/Controls2/BasicButtonType.qml b/client/ui/qml/Controls2/BasicButtonType.qml index 257486d6..9a0011e4 100644 --- a/client/ui/qml/Controls2/BasicButtonType.qml +++ b/client/ui/qml/Controls2/BasicButtonType.qml @@ -33,22 +33,23 @@ Button { hoverEnabled: true background: Rectangle { - id: background_border + id: focusBorder color: "transparent" border.color: root.activeFocus ? root.borderFocusedColor : "transparent" border.width: root.activeFocus ? root.borderFocusedWidth : "transparent" anchors.fill: parent + radius: 16 Rectangle { id: background - anchors.fill: background_border - anchors.margins: root.activeFocus ? 2: 0 + anchors.fill: focusBorder + anchors.margins: root.activeFocus ? 2 : 0 - radius: 16 + radius: root.activeFocus ? 14 : 16 color: { if (root.enabled) { if (root.pressed) { @@ -59,8 +60,8 @@ Button { return disabledColor } } - border.color: root.activeFocus ? "transparent" : borderColor - border.width: root.activeFocus ? 0 : borderWidth + border.color: borderColor + border.width: borderWidth Behavior on color { PropertyAnimation { duration: 200 } @@ -95,13 +96,13 @@ Button { } MouseArea { - anchors.fill: background_border + anchors.fill: focusBorder enabled: false cursorShape: Qt.PointingHandCursor } contentItem: Item { - anchors.fill: background_border + anchors.fill: focusBorder implicitWidth: content.implicitWidth implicitHeight: content.implicitHeight diff --git a/client/ui/qml/Pages2/PageHome.qml b/client/ui/qml/Pages2/PageHome.qml index 536fc951..1ca74f47 100644 --- a/client/ui/qml/Pages2/PageHome.qml +++ b/client/ui/qml/Pages2/PageHome.qml @@ -162,7 +162,7 @@ PageType { } } - expandedContent: Item { + expandedContent: Item { id: serverMenuContainer implicitHeight: root.height * 0.9 diff --git a/client/ui/qml/Pages2/PageSetupWizardEasy.qml b/client/ui/qml/Pages2/PageSetupWizardEasy.qml index 69109a85..794a0a53 100644 --- a/client/ui/qml/Pages2/PageSetupWizardEasy.qml +++ b/client/ui/qml/Pages2/PageSetupWizardEasy.qml @@ -187,9 +187,8 @@ PageType { visible: { if (PageController.isTriggeredByConnectButton()) { - PageController.setTriggeredBtConnectButton(false) - - return ContainersModel.isAnyContainerInstalled() + PageController.setTriggeredByConnectButton(false) + return false } return true diff --git a/client/ui/qml/Pages2/PageShare.qml b/client/ui/qml/Pages2/PageShare.qml index cd7e7958..44fe145f 100644 --- a/client/ui/qml/Pages2/PageShare.qml +++ b/client/ui/qml/Pages2/PageShare.qml @@ -308,6 +308,10 @@ PageType { ValueFilter { roleName: "hasWriteAccess" value: true + }, + ValueFilter { + roleName: "hasInstalledContainers" + value: true } ] } @@ -324,8 +328,12 @@ PageType { } Component.onCompleted: { - serverSelectorListView.currentIndex = ServersModel.isDefaultServerHasWriteAccess() ? - proxyServersModel.mapFromSource(ServersModel.defaultIndex) : 0 + if (ServersModel.isDefaultServerHasWriteAccess() && ServersModel.getDefaultServerData("hasInstalledContainers")) { + serverSelectorListView.currentIndex = proxyServersModel.mapFromSource(ServersModel.defaultIndex) + } else { + serverSelectorListView.currentIndex = 0 + } + serverSelectorListView.triggerCurrentItem() } @@ -480,6 +488,7 @@ PageType { Layout.fillWidth: true Layout.topMargin: 40 + Layout.bottomMargin: 32 enabled: shareButtonEnabled visible: accessTypeSelector.currentIndex === 0 diff --git a/client/ui/qml/Pages2/PageStart.qml b/client/ui/qml/Pages2/PageStart.qml index eed08194..0bedb010 100644 --- a/client/ui/qml/Pages2/PageStart.qml +++ b/client/ui/qml/Pages2/PageStart.qml @@ -60,8 +60,8 @@ PageType { } else { tabBarStackView.push(pagePath, { "objectName" : pagePath }, StackView.Immediate) } - - tabBar.isServerInfoShow = page === PageEnum.PageSettingsServerInfo || PageEnum.PageSettingsSplitTunneling || tabBar.isServerInfoShow + + tabBar.isServerInfoShow = (page === PageEnum.PageSettingsServerInfo) || (page === PageEnum.PageSettingsSplitTunneling) || tabBar.isServerInfoShow } function onGoToStartPage() { @@ -122,7 +122,7 @@ PageType { } function onNoInstalledContainers() { - PageController.setTriggeredBtConnectButton(true) + PageController.setTriggeredByConnectButton(true) ServersModel.processedIndex = ServersModel.getDefaultServerIndex() InstallController.setShouldCreateServer(false)