aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/Snack.qml
blob: b955ad2b33b6ea62d9b384b1ca385fadf16fdedd (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
// 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.

pragma Singleton

import Quickshell
import QtQuick

// The settings window's one message, shown by Snackbar.qml at the foot of the
// window: what a save, an apply or an upload said. A page calls ok(), wait()
// or error(); a new message replaces the last. ok() fades by itself, wait()
// and error() stay until dismissed or replaced. SaveBar forwards its notice
// and error here, so a page using it needs nothing more.
Singleton {
    id: root

    property string text: ""
    property color color: Theme.green
    property bool sticky: false
    // Bumped on every show, so the same text twice restarts the fade.
    property int serial: 0

    function show(text, color, sticky) {
        root.text = text;
        root.color = color;
        root.sticky = !!sticky;
        root.serial++;
    }
    function ok(text) { root.show(text, Theme.green, false); }
    function wait(text) { root.show(text, Theme.yellow, true); }
    function error(text) { root.show(text, Theme.red, true); }
    function clear() { root.text = ""; }
}