From 0d1d4116eb283a684b93bd432cb1f3b8331b2d4d Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Fri, 9 Jul 2021 20:21:08 +0200
Subject: [PATCH] [ui] avoid blank location item

- Resolves: #522
---
 gui/qml/main.qml | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/gui/qml/main.qml b/gui/qml/main.qml
index cc5b17eb..1d679242 100644
--- a/gui/qml/main.qml
+++ b/gui/qml/main.qml
@@ -252,6 +252,16 @@ ApplicationWindow {
         return ctx.manualLocation == "true"
     }
 
+    function hasMultipleGateways() {
+        // could also count the gateways
+        let provider = Logic.getSelectedProvider(providers);
+        if (provider == "riseup") {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
     function setGwSelection() {
 
         if (!isManualLocation()) {
@@ -341,7 +351,7 @@ ApplicationWindow {
             MenuItem {
                 id: manualSelectionItem
                 text: {
-                    if (isManualLocation()) {
+                    if (isManualLocation() != "") {
                         locationStr()
                     } else {
                         qsTr("Pick location…")
@@ -350,6 +360,12 @@ ApplicationWindow {
                 checkable: true
                 checked: isManualLocation()
                 onTriggered: setGwSelection()
+                visible: hasMultipleGateways()
+            }
+
+            MenuItem {
+                text: qsTr("Preferences…")
+                visible: !hasMultipleGateways()
             }
 
             MenuSeparator {}
@@ -490,7 +506,11 @@ ApplicationWindow {
     }
 
     function locationStr() {
-        return ctx.currentLocation + ", " + ctx.currentCountry
+        if (ctx.currentLocation && ctx.currentCountry) {
+            return ctx.currentLocation + ", " + ctx.currentCountry
+        } else {
+            return ""
+        }
     }
 
     function useBridges(value) {
-- 
GitLab