blob: dc5d035741b93e135e349aeedb1dab252c8a709e (
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
|
/*
* Copyright (C) 2017 Niels De Graef <nielsdegraef@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Gtk;
[GtkTemplate (ui = "/org/gnome/Contacts/ui/contacts-in-app-notification.ui")]
public class Contacts.InAppNotification : Revealer {
// Close the in-app notification after 5 seconds by default.
private const uint DEFAULT_KEEPALIVE = 5;
[GtkChild]
private Grid grid;
[GtkChild]
private Label label;
public Label message_label {
get { return this.label; }
}
/**
* Fired when the notification is completely dismissed (i.e. gone).
*/
public signal void dismissed ();
/**
* Creates an in-app notification with the given message, and an accompanying button if not null.
*/
public InAppNotification (string message, Button? button = null) {
this.label.label = message;
if (button != null) {
button.valign = Gtk.Align.CENTER;
this.grid.attach (button, 1, 0);
button.show();
}
this.notify["child-revealed"].connect (on_child_revealed_changed);
}
public new void show () {
base.show ();
this.reveal_child = true;
Timeout.add_seconds (DEFAULT_KEEPALIVE, () => {
dismiss ();
return false;
});
}
public void dismiss () {
this.reveal_child = false;
}
private void on_child_revealed_changed (Object o, ParamSpec p) {
if (!this.child_revealed) {
dismissed ();
destroy ();
}
}
[GtkCallback]
private void on_close_button_clicked(Button close_button) {
dismiss();
}
}
|