aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/status/SnoozeRow.qml
blob: 046d7cbb8ad67f8aab05ad48e9a05bfcd90bf24d (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
// 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 QtQuick.Controls
import "../.."

// A switch plus a minutes field. On snoozes for the typed minutes through
// notify-snooze.sh; off clears. The last used value is persisted by the
// script, so the field prefills from it.
Item {
    id: row

    // A tick so the switch reflects the snooze ending on its own.
    property double now: Date.now()
    Timer {
        interval: 1000
        running: true
        repeat: true
        onTriggered: row.now = Date.now()
    }

    readonly property bool active: Notify.snoozeUntil > row.now

    implicitHeight: Math.max(texts.implicitHeight, sw.implicitHeight) + 16

    function apply(on) {
        if (on) {
            const n = parseInt(minutes.text, 10);
            snooze.command = ["notify-snooze.sh", String(isNaN(n) || n < 1 ? 30 : n)];
        } else {
            snooze.command = ["notify-snooze.sh", "off"];
        }
        snooze.running = false;
        snooze.running = true;
    }

    Process { id: snooze }

    FileView {
        id: lastUsed
        path: `${Quickshell.env("HOME")}/.local/state/notify-snooze.minutes`
        printErrors: false
        onLoaded: minutes.text = text().trim()
        onLoadFailed: minutes.text = "30"
    }

    Column {
        id: texts
        anchors {
            left: parent.left
            right: controls.left
            rightMargin: 12
            verticalCenter: parent.verticalCenter
        }
        spacing: 2

        Text {
            text: "Snooze"
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
            color: Theme.text
        }

        Text {
            width: parent.width
            wrapMode: Text.WordWrap
            text: row.active ? "All notification balloons are held until snooze ends."
                             : "Hold every notification balloon for a number of minutes."
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
            color: Theme.subtext
        }
    }

    Row {
        id: controls
        anchors { right: parent.right; verticalCenter: parent.verticalCenter }
        spacing: 8

        TextField {
            id: minutes
            width: 48
            height: 28
            text: "30"
            horizontalAlignment: TextInput.AlignHCenter
            color: Theme.text
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
            background: Rectangle {
                radius: 6
                color: Qt.alpha(Theme.surface, 0.9)
                border.width: 1
                border.color: Qt.alpha(Theme.text, 0.15)
            }
            validator: IntValidator { bottom: 1; top: 1440 }
        }

        Switch {
            id: sw
            checked: row.active
            onToggled: row.apply(!row.active)
        }
    }

    onNowChanged: sw.checked = row.active
}