aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/notifications/NotificationsPage.qml
blob: 612fb83cf9f07b5e50be38bbb1bf32d7654ede53 (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// 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
import Quickshell.Io
import QtQuick
import Qt.labs.platform as P
import "../.."
import "../appearance"
import "../qtmaildir"

// The rows of the notifications settings page. Everything edits mod.draft.
Column {
    id: pg
    // Not "nm": a property named like the injecting id binds to itself.
    required property QtObject mod
    readonly property var d: mod.draft
    spacing: 8

    function setTimeout(key, v) {
        pg.mod.edit({ timeouts: Object.assign({}, pg.d.timeouts, { [key]: v }) });
    }

    Heading { text: "Timeouts" }
    Text {
        width: pg.width; wrapMode: Text.Wrap
        text: "Seconds a balloon stays when the app leaves it to the daemon. An app's own timeout still wins."
        color: Theme.overlay
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
    }
    Repeater {
        model: [["low", "Low"], ["normal", "Normal"], ["critical", "Critical"]]
        Row {
            required property var modelData
            spacing: 10
            Text {
                width: 90; anchors.verticalCenter: parent.verticalCenter
                text: modelData[1]; color: Theme.text
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
            }
            Field {
                anchors.verticalCenter: parent.verticalCenter
                visible: pg.d.timeouts[modelData[0]] !== 0
                value: String(pg.d.timeouts[modelData[0]])
                placeholder: "seconds"
                // Typing drops the value binding too: put it back so Discard
                // shows the draft, and a rejected entry reverts at once.
                onEdited: {
                    const n = parseInt(value, 10);
                    value = Qt.binding(() => String(pg.d.timeouts[modelData[0]]));
                    if (n > 0 && n <= 86400) pg.setTimeout(modelData[0], n);
                }
            }
            Toggle {
                anchors.verticalCenter: parent.verticalCenter
                label: "never"
                checked: pg.d.timeouts[modelData[0]] === 0
                // Toggle flips itself on click, which drops the binding; put
                // it back so Discard shows the draft again.
                onToggled: {
                    const on = checked;
                    checked = Qt.binding(() => pg.d.timeouts[modelData[0]] === 0);
                    pg.setTimeout(modelData[0], on ? 0 : 10);
                }
            }
        }
    }

    Heading { text: "Sounds" }
    Text {
        width: pg.width; wrapMode: Text.Wrap
        text: "Played when a balloon pops, never for one muted, held by Do Not Disturb or snoozed. An app's own sound, or its request for silence, wins."
        color: Theme.overlay
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
    }
    Repeater {
        model: [["low", "Low"], ["normal", "Normal"], ["critical", "Critical"]]
        Row {
            required property var modelData
            spacing: 10
            readonly property string file: pg.d.sounds[modelData[0]]
            Text {
                width: 90; anchors.verticalCenter: parent.verticalCenter
                text: modelData[1]; color: Theme.text
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
            }
            Text {
                width: 180; anchors.verticalCenter: parent.verticalCenter
                elide: Text.ElideMiddle
                text: parent.file ? parent.file.split("/").pop() : "none"
                color: parent.file ? Theme.text : Theme.overlay
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
            }
            Button {
                text: "Choose\u2026"
                onClicked: { picker.key = modelData[0]; picker.open(); }
            }
            Button {
                icon: "\uf04b"
                enabled: parent.file !== ""
                onClicked: { preview.command = ["pw-play", parent.file]; preview.running = false; preview.running = true; }
            }
            Button {
                icon: "\uf00d"
                enabled: parent.file !== ""
                onClicked: pg.mod.edit({ sounds: Object.assign({}, pg.d.sounds, { [modelData[0]]: "" }) })
            }
        }
    }
    Text {
        topPadding: 6
        text: "Theme for sounds apps ask for by name, also set as the system sound theme"
        color: Theme.subtext
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4; bold: true }
    }
    Flow {
        width: pg.width; spacing: 6
        Repeater {
            model: pg.mod.themes
            Button {
                required property string modelData
                text: modelData
                border.color: pg.d.soundTheme === modelData ? Theme.accent : Qt.alpha(Theme.text, 0.2)
                onClicked: pg.mod.edit({ soundTheme: modelData })
            }
        }
    }
    Row {
        spacing: 10
        visible: pg.mod.systemTheme !== "" && pg.mod.systemTheme !== pg.d.soundTheme
        Text {
            anchors.verticalCenter: parent.verticalCenter
            text: "System sound theme is " + pg.mod.systemTheme + ", changed outside this page"
            color: Theme.yellow
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
        }
        Button {
            text: "Use " + pg.mod.systemTheme
            onClicked: pg.mod.edit({ soundTheme: pg.mod.systemTheme })
        }
    }

    Process { id: preview }
    // Qt.labs.platform, not QtQuick.Dialogs: the Quick dialog opens light on
    // this desktop (AGENTS.md); this one takes the widget style.
    P.FileDialog {
        id: picker
        property string key: ""
        folder: "file://" + Quickshell.env("HOME") + "/.local/share/sounds"
        nameFilters: ["Sounds (*.oga *.ogg *.wav)"]
        onAccepted: pg.mod.edit({ sounds: Object.assign({}, pg.d.sounds,
            { [picker.key]: decodeURIComponent(file.toString().replace(/^file:\/\//, "")) }) })
    }

    Heading { text: "Limits" }
    Text {
        width: pg.width; wrapMode: Text.Wrap
        text: "How many notifications are kept live and in history, 1 to 100 each. Past the live limit the oldest moves to history; past the history limit it is dropped."
        color: Theme.overlay
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
    }
    Repeater {
        model: [["liveCap", "On screen"], ["historyCap", "History"]]
        Row {
            required property var modelData
            spacing: 10
            Text {
                width: 90; anchors.verticalCenter: parent.verticalCenter
                text: modelData[1]; color: Theme.text
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
            }
            Field {
                anchors.verticalCenter: parent.verticalCenter
                value: String(pg.d[modelData[0]])
                border.color: pg.d[modelData[0]] >= 1 && pg.d[modelData[0]] <= 100 ? Qt.alpha(Theme.text, 0.12) : Theme.red
                onEdited: {
                    const n = parseInt(value, 10) || 0;
                    value = Qt.binding(() => String(pg.d[modelData[0]]));
                    pg.mod.edit({ [modelData[0]]: n });
                }
            }
        }
    }

    Heading { text: "Placement" }
    Flow {
        width: pg.width; spacing: 6
        Repeater {
            model: Quickshell.screens.map(s => s.name)
            Button {
                required property string modelData
                text: modelData
                border.color: pg.d.balloons.screen === modelData ? Theme.accent : Qt.alpha(Theme.text, 0.2)
                onClicked: pg.mod.edit({ balloons: Object.assign({}, pg.d.balloons, { screen: modelData }) })
            }
        }
    }
    // The four corners as a miniature screen: click the one balloons go to.
    Grid {
        columns: 2; spacing: 4
        Repeater {
            model: ["top-left", "top-right", "bottom-left", "bottom-right"]
            Rectangle {
                required property string modelData
                width: 60; height: 34; radius: 5
                color: pg.d.balloons.corner === modelData ? Qt.alpha(Theme.accent, 0.6) : Qt.alpha(Theme.surface, 0.6)
                border.width: 1; border.color: Qt.alpha(Theme.text, 0.15)
                MouseArea {
                    anchors.fill: parent; cursorShape: Qt.PointingHandCursor
                    onClicked: pg.mod.edit({ balloons: Object.assign({}, pg.d.balloons, { corner: modelData }) })
                }
            }
        }
    }

    Heading { text: "Suppression" }
    Toggle {
        label: "Critical notifications still pop up under Do Not Disturb"
        checked: pg.d.dndPassCritical
        onToggled: {
            const on = checked;
            checked = Qt.binding(() => pg.d.dndPassCritical);
            pg.mod.edit({ dndPassCritical: on });
        }
    }
    Text {
        width: pg.width; wrapMode: Text.Wrap
        text: "Muted apps get no balloon. They still appear in the drawer and in history."
        color: Theme.overlay
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
    }
    // Two rows told apart by a caption and by look: muted apps in red, a
    // click unmutes; recent apps dimmed, a click mutes.
    Text {
        text: pg.d.muted.length ? "Muted, click to unmute" : "No muted apps"
        color: Theme.subtext
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4; bold: true }
    }
    Flow {
        width: pg.width; spacing: 6
        Repeater {
            model: pg.d.muted
            Button {
                required property string modelData
                text: modelData; icon: "\uf00d"; danger: true
                onClicked: pg.mod.edit({ muted: pg.d.muted.filter(a => a !== modelData) })
            }
        }
    }
    // Apps seen in the queue and history, newest first (both lists are), not
    // yet muted. Bounded by the two caps already; the slice keeps the row short.
    Text {
        visible: recent.count > 0
        topPadding: 6
        text: "Recently seen, click to mute"
        color: Theme.subtext
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4; bold: true }
    }
    Flow {
        width: pg.width; spacing: 6
        Repeater {
            id: recent
            model: [...new Set(Notify.queue.concat(Notify.history).map(n => n.app))]
                .filter(a => a && pg.d.muted.indexOf(a) < 0).slice(0, 8)
            Button {
                required property string modelData
                text: modelData; icon: "\uf067"
                opacity: 0.7
                onClicked: pg.mod.edit({ muted: pg.d.muted.concat([modelData]) })
            }
        }
    }
    Field {
        width: 200
        placeholder: "mute another app by name"
        onEdited: {
            const a = value.trim();
            if (a !== "" && pg.d.muted.indexOf(a) < 0) pg.mod.edit({ muted: pg.d.muted.concat([a]) });
            value = "";
        }
    }
}