Skip to content
Snippets Groups Projects
Footer.qml 6.17 KiB
Newer Older
  • Learn to ignore specific revisions
  • import QtQuick
    import QtQuick.Controls
    import QtQuick.Controls.Material
    import QtQuick.Layouts
    import QtQuick.Effects
    
    import "../themes/themes.js" as Theme
    
    Kali Kaneko's avatar
    Kali Kaneko committed
    
    ToolBar {
    
        Material.foreground: "black"
        Material.elevation: 10
        background: Rectangle {
            implicitHeight: 48
            color: "transparent"
    
    Kali Kaneko's avatar
    Kali Kaneko committed
    
    
            Rectangle {
                width: parent.width
                height: 1
                anchors.bottom: parent.bottom
                color: "transparent"
            }
        }
    
    Kali Kaneko's avatar
    Kali Kaneko committed
    
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            id: footerRow
    
            width: root.width - 18
            height: 48
            radius: 8
            color: "white"
            opacity: 0.9
    
    Kali Kaneko's avatar
    Kali Kaneko committed
    
            ToolButton {
                id: gwButton
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                visible: true
    
    Kali Kaneko's avatar
    Kali Kaneko committed
    
    
                anchors {
                    verticalCenter: parent.verticalCenter
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                    leftMargin: 10
    
                    left: parent.left
                }
    
                icon {
                    width: 20
                    height: 20
                    source: stackView.depth > 1 ? "" : "../resources/globe.svg"
                }
    
                HoverHandler {
                    cursorShape: Qt.PointingHandCursor
                }
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                onClicked: stackView.push("Locations.qml")
            }
    
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            Image {
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                smooth: true
                visible: ctx != undefined & root.selectedGateway == "auto"
                width: 16
                source: "../resources/lightning.svg"
                fillMode: Image.PreserveAspectFit
                anchors {
                    left: gwButton.right
                    leftMargin: -10
    
                    verticalCenter: gwButton.verticalCenter
    
            }
            MultiEffect {
                anchors.fill: lightning
                source: lightning
                colorizationColor: getLocationColor()
                colorization: 1.0
                antialiasing: true
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            Label {
                id: locationLabel
    
                text: locationStr()
                color: getLocationColor()
    
                anchors {
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                    left: lightning.right
    
                    verticalCenter: gwButton.verticalCenter
    
                MouseArea {
                    cursorShape: Qt.PointingHandCursor
                    anchors.fill: parent
                    onClicked: stackView.push("Locations.qml")
                }
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            }
    
            Item {
                Layout.fillWidth: true
                height: gwButton.implicitHeight
            }
    
            Image {
                id: bridge
    
                smooth: true
    
                visible: isBridgeSelected()
    
                width: 40
                source: "../resources/bridge.svg"
                fillMode: Image.PreserveAspectFit
                anchors {
                    verticalCenter: parent.verticalCenter
    
                    verticalCenterOffset: -2
    
                    right: gwQuality.left
                    rightMargin: 10
                }
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            }
    
    
            // TODO refactor with SignalIcon
            // This signal image renders particularly bad at this size.
            // https://stackoverflow.com/a/23449205/1157664
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            Image {
                id: gwQuality
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                source: "../resources/reception-0@24.svg"
    
                width: 24
                sourceSize.width: 24
                smooth: false
                mipmap: true
                antialiasing: false
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                anchors {
                    right: parent.right
                    verticalCenter: parent.verticalCenter
    
                    verticalCenterOffset: -5
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                    topMargin: 5
                    rightMargin: 20
    
            }
            MultiEffect {
                anchors.fill: gwQuality
                source: gwQuality
                colorizationColor: getSignalColor()
                colorization: 1.0
                antialiasing: false
    
            }
        }
    
        function getSignalColor() {
            if (ctx && ctx.status == "on") {
    
            } else {
    
            }
        }
    
        StateGroup {
            state: ctx ? ctx.status : "off"
            states: [
                State {
                    name: "on"
                    PropertyChanges {
                        target: gwQuality
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                        source: "../resources/reception-4@24.svg"
    
                    }
                },
                State {
                    name: "off"
                    PropertyChanges {
                        target: gwQuality
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                        source: "../resources/reception-0@24.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
                    }
    
                }
            }
            if (root.selectedGateway == "auto") {
                if (ctx && ctx.locations && ctx.bestLocation) {
    
    Kali Kaneko's avatar
    Kali Kaneko committed
                    //return "🗲 " + getCanonicalLocation(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") {
    
            } else {
                // TODO darker gray
    
            }
        }
    
        function hasMultipleGateways() {
    
            let provider = getSelectedProvider(providers);
    
            if (provider == "riseup") {
    
            } else {
                if (!ctx) {
    
                return ctx.locations.length > 0;
    
            }
        }
    
        function getSelectedProvider(providers) {
    
            let obj = JSON.parse(providers.getJson());
            return obj['default'];
    
        }
    
        function isBridgeSelected() {
            if (ctx && ctx.transport == "obfs4") {
    
    Kali Kaneko's avatar
    Kali Kaneko committed
            }
    
            if (ctx && ctx.transport == "kcp") {
                return true;
            }
            return false;
    
    Kali Kaneko's avatar
    Kali Kaneko committed
        }
    }