aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/sonix/SonixDevice.qml
blob: bc1ffc558666582b5c23de12ad6b94312f4dc266 (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
// 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 QtQuick
import "../.."

Column {
    id: dev
    signal go(string name)
    readonly property var p: Sonix.player
    spacing: 10

    component Line: Row {
        id: line
        property string k: ""
        property string v: ""
        spacing: 10
        Text {
            width: 110
            text: line.k
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
            color: Theme.subtext
        }
        Text {
            textFormat: Text.PlainText
            text: line.v
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
            color: Theme.text
        }
    }

    Line { k: "Name"; v: Sonix.name }
    Line { k: "Address"; v: `${Sonix.host}:${Sonix.port}` }
    Line {
        k: "Battery"
        v: dev.p.battery === undefined ? "\u2026" : dev.p.battery + "%" + (dev.p.charging ? ", charging" : "")
    }
    Row {
        spacing: 10
        Text {
            width: 110
            text: "Accent"
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
            color: Theme.subtext
        }
        Rectangle {
            width: 18; height: 18; radius: 4
            color: dev.p.accent || "transparent"
            border.width: 1
            border.color: Qt.alpha(Theme.text, 0.2)
        }
        Text {
            textFormat: Text.PlainText
            text: dev.p.accent || ""
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
            color: Theme.text
        }
    }
    Line {
        k: "Library"
        v: dev.p.scanning ? `scanning\u2026 ${dev.p.scan_count ?? 0} found`
         : dev.p.tracks === undefined ? "\u2026" : dev.p.tracks + " tracks"
    }
    Line {
        k: "Now"
        v: (["stopped", "playing", "paused"][dev.p.state || 0] ?? "stopped") + (dev.p.title ? " \u00b7 " + dev.p.title : "")
    }

    Row {
        spacing: 8
        Button {
            text: "Rescan"
            enabled: !dev.p.scanning
            onClicked: Sonix.command({ do: "scan" }, null, (ok, d, err) => msg.text = ok ? "" : err)
        }
        Button {
            text: "Open Wi-Fi transfer"
            onClicked: Qt.openUrlExternally(`http://${Sonix.host}/`)
        }
        Button {
            text: "Boot logo\u2026"
            onClicked: dev.go("bootlogo")
        }
    }

    Text {
        width: dev.width
        wrapMode: Text.Wrap
        text: "Wi-Fi transfer answers only while its page is open on the player."
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 5 }
        color: Theme.subtext
    }

    Text {
        id: msg
        visible: text !== ""
        width: dev.width
        wrapMode: Text.Wrap
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
        color: Theme.red
    }
}