Skip to content
Snippets Groups Projects
Footer.qml 4.69 KiB
Newer Older
  • Learn to ignore specific revisions
  • Kali Kaneko's avatar
    Kali Kaneko committed
    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
    
    Kali Kaneko's avatar
    Kali Kaneko committed
    
    ToolBar {
    
    
        Material.background: Theme.bgColor
    
    Kali Kaneko's avatar
    Kali Kaneko committed
        Material.foreground: "black"
        Material.elevation: 0
        visible: stackView.depth > 1 && ctx !== undefined ? false : true
    
        Item {
    
            id: footerRow
            width: root.width
    
            ToolButton {
                id: gwButton
    
                visible: hasMultipleGateways()
                anchors {
                    verticalCenter: parent.verticalCenter
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                    leftMargin: 20
    
                    left: parent.left
                    verticalCenterOffset: 5
                }
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                /*
                background.implicitHeight: 32
                background.implicitWidth: 32
                */
                icon.width: 20
                icon.height: 20
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                icon.source: stackView.depth > 1 ? "" : "../resources/globe.svg"
                onClicked: stackView.push("Locations.qml")
            }
    
            Label {
                id: locationLabel
                anchors.left: gwButton.right
                anchors.verticalCenter: parent.verticalCenter
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                anchors.verticalCenterOffset: 7
    
                text: locationStr()
                color: getLocationColor()
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            }
    
            Item {
                Layout.fillWidth: true
                height: gwButton.implicitHeight
            }
    
            Image {
                id: bridge
    
                visible: isBridgeSelected()
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                height: 24
                width: 24
                source: "../resources/bridge.png"
                anchors.verticalCenter: parent.verticalCenter
                anchors.verticalCenterOffset: 5
                anchors.right: gwQuality.left
                anchors.rightMargin: 10
            }
    
            Image {
                id: gwQuality
                height: 24
                width: 24
                source: "../resources/reception-0.svg"
                anchors.right: parent.right
                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
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            }
        }
    }