aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/network/NetworkPage.qml
blob: 3749688bcb8a747dc04b5ace8812ff1e75aa66ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

import Quickshell.Networking
import QtQuick
import "../.."

Column {
    id: page

    required property var net
    signal back

    spacing: 14

    function stateLabel(s) {
        return s === ConnectionState.Connected ? "connected"
             : s === ConnectionState.Connecting ? "connecting"
             : s === ConnectionState.Disconnecting ? "disconnecting"
             : "disconnected";
    }

    // --- Wired ---

    Row {
        visible: page.net.wiredDevices.length > 0
        spacing: 6

        Text {
            anchors.verticalCenter: parent.verticalCenter
            text: "\uef44"
            font { family: Theme.iconFamily; pixelSize: Theme.fontSize - 2 }
            color: Theme.subtext
        }

        Text {
            anchors.verticalCenter: parent.verticalCenter
            text: "Wired"
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
            color: Theme.subtext
        }
    }

    Repeater {
        model: page.net.wiredDevices

        Rectangle {
            required property var modelData

            width: page.width
            implicitHeight: wiredText.implicitHeight + 16
            radius: 8
            color: Qt.alpha(Theme.surface, 0.35)

            Text {
                id: wiredText
                anchors { left: parent.left; leftMargin: 10; verticalCenter: parent.verticalCenter }
                text: modelData.name + "  " + page.stateLabel(modelData.state)
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
                color: modelData.connected ? Theme.text : Theme.subtext
            }

            Button {
                anchors { right: parent.right; rightMargin: 8; verticalCenter: parent.verticalCenter }
                visible: modelData.connected
                text: "Disconnect"
                onClicked: page.net.disconnectNetwork(modelData)
            }
        }
    }

    Rectangle { width: page.width; height: 1; visible: page.net.wiredDevices.length > 0; color: Qt.alpha(Theme.text, 0.12) }

    // --- Wifi ---

    Item {
        width: page.width
        implicitHeight: Math.max(wifiLabel.implicitHeight, wifiSwitch.implicitHeight)

        Text {
            id: wifiLabel
            anchors { left: wifiGlyph.right; leftMargin: 6; verticalCenter: parent.verticalCenter }
            text: "Wi-Fi"
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 1; bold: true }
            color: Theme.text
        }

        Text {
            id: wifiGlyph
            anchors.verticalCenter: parent.verticalCenter
            text: "\uf1eb"
            font { family: Theme.iconFamily; pixelSize: Theme.fontSize - 2 }
            color: Theme.subtext
        }

        Switch {
            id: wifiSwitch
            anchors { right: parent.right; verticalCenter: parent.verticalCenter }
            enabled: Networking.wifiHardwareEnabled
            checked: page.net.wifiOn
            onToggled: Networking.wifiEnabled = checked
        }
    }

    Text {
        width: page.width
        visible: !page.net.wifiOn
        text: "Wi-Fi off"
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
        color: Theme.subtext
    }

    Row {
        width: page.width
        visible: page.net.wifiOn
        spacing: 8

        Button {
            text: page.net.wifiDevice && page.net.wifiDevice.scannerEnabled ? "Scanning…" : "Scan"
            onClicked: if (page.net.wifiDevice) page.net.wifiDevice.scannerEnabled = !page.net.wifiDevice.scannerEnabled
        }

        // The scanner repeats until disabled, and closing the drawer does not
        // disable it. A continuous scan also costs throughput on the connected
        // link. See the matching timer in BluetoothPage.
        Timer {
            interval: 60000
            running: page.net.wifiDevice ? page.net.wifiDevice.scannerEnabled : false
            onTriggered: if (page.net.wifiDevice) page.net.wifiDevice.scannerEnabled = false
        }
    }

    Repeater {
        model: page.net.wifiOn ? page.net.wifiNetworksSorted : []

        NetworkRow {
            required property var modelData
            net: page.net
            entry: modelData
            width: page.width
        }
    }

    Text {
        width: page.width
        visible: page.net.error !== ""
        wrapMode: Text.Wrap
        text: page.net.error
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
        color: Theme.red
    }
}