diff options
Diffstat (limited to 'gui/components/Footer.qml')
-rw-r--r-- | gui/components/Footer.qml | 121 |
1 files changed, 115 insertions, 6 deletions
diff --git a/gui/components/Footer.qml b/gui/components/Footer.qml index 2c7c875..7658fa1 100644 --- a/gui/components/Footer.qml +++ b/gui/components/Footer.qml @@ -2,10 +2,13 @@ import QtQuick 2.0 import QtQuick.Controls 2.4 import QtQuick.Controls.Material 2.1 import QtQuick.Layouts 1.14 +import QtGraphicalEffects 1.0 + +import "../themes/themes.js" as Theme ToolBar { - Material.background: Material.backgroundColor + Material.background: Theme.bgColor Material.foreground: "black" Material.elevation: 0 visible: stackView.depth > 1 && ctx !== undefined ? false : true @@ -17,10 +20,13 @@ ToolBar { ToolButton { id: gwButton - anchors.verticalCenter: parent.verticalCenter - anchors.leftMargin: 10 - anchors.left: parent.left - anchors.verticalCenterOffset: 5 + visible: hasMultipleGateways() + anchors { + verticalCenter: parent.verticalCenter + leftMargin: 10 + left: parent.left + verticalCenterOffset: 5 + } icon.source: stackView.depth > 1 ? "" : "../resources/globe.svg" onClicked: stackView.push("Locations.qml") } @@ -30,7 +36,8 @@ ToolBar { anchors.left: gwButton.right anchors.verticalCenter: parent.verticalCenter anchors.verticalCenterOffset: 5 - text: "Seattle" + text: locationStr() + color: getLocationColor() } Item { @@ -40,6 +47,7 @@ ToolBar { Image { id: bridge + visible: isBridgeSelected() height: 24 width: 24 source: "../resources/bridge.png" @@ -58,6 +66,107 @@ ToolBar { anchors.rightMargin: 20 anchors.verticalCenter: parent.verticalCenter anchors.verticalCenterOffset: 5 + // TODO refactor with SignalIcon + ColorOverlay{ + anchors.fill: gwQuality + source: gwQuality + color: getSignalColor() + antialiasing: true + } + } + } + + function getSignalColor() { + if (ctx && ctx.status == "on") { + return "green" + } else { + return "black" + } + } + + StateGroup { + state: ctx ? ctx.status : "off" + states: [ + State { + name: "on" + PropertyChanges { + target: gwQuality + source: "../resources/reception-4.svg" + } + }, + State { + name: "off" + PropertyChanges { + target: gwQuality + source: "../resources/reception-0.svg" + } + } + ] + } + + function locationStr() { + if (ctx && ctx.status == "on") { + if (ctx.currentLocation && ctx.currentCountry) { + let s = ctx.currentLocation + ", " + ctx.currentCountry + if (root.selectedGateway == "auto") { + s = "🗲 " + s + } + return s + } + } + if (root.selectedGateway == "auto") { + if (ctx && ctx.locations && ctx.bestLocation) { + return "🗲 " + getCanonicalLocation(ctx.bestLocation) + } else { + return qsTr("Recommended") + } + } + if (ctx && ctx.locations && ctx.locationLabels) { + return getCanonicalLocation(root.selectedGateway) + } + } + + // returns the composite of Location, CC + function getCanonicalLocation(label) { + try { + let loc = ctx.locationLabels[label] + return loc[0] + ", " + loc[1] + } catch(e) { + return "unknown" + } + } + + function getLocationColor() { + if (ctx && ctx.status == "on") { + return "black" + } else { + // TODO darker gray + return "gray" + } + } + + function hasMultipleGateways() { + let provider = getSelectedProvider(providers) + if (provider == "riseup") { + return true + } else { + if (!ctx) { + return false + } + return ctx.locations.length > 0 + } + } + + function getSelectedProvider(providers) { + let obj = JSON.parse(providers.getJson()) + return obj['default'] + } + + function isBridgeSelected() { + if (ctx && ctx.transport == "obfs4") { + return true + } else { + return false } } } |