summaryrefslogtreecommitdiff
path: root/src/contacts-in-app-notification.vala
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2017-06-24 13:52:24 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2017-06-24 13:57:40 +0200
commita483ccf5a68fc044af126246809369e314afa7a8 (patch)
tree20fd46a08ceee01597fa9f8a4baad6d0eb9a8f10 /src/contacts-in-app-notification.vala
parent7f47e0574dd402ac53e845a41ddb504ce253d8cd (diff)
downloadgnome-contacts-a483ccf5a68fc044af126246809369e314afa7a8.tar.gz
Create InAppNotification class and remove libgd.
Libgd is bound to remove Gd.Notification, and removing it also means it gets easier to port our build system to Meson. Furthermore, we can now use some more sane defaults for our application w.r.t. notifications.
Diffstat (limited to 'src/contacts-in-app-notification.vala')
-rw-r--r--src/contacts-in-app-notification.vala78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/contacts-in-app-notification.vala b/src/contacts-in-app-notification.vala
new file mode 100644
index 0000000..b3f9aea
--- /dev/null
+++ b/src/contacts-in-app-notification.vala
@@ -0,0 +1,78 @@
+/*
+ * 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) {
+ 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();
+ }
+}