[connections] notifications: Dismiss notifications when closing the app
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [connections] notifications: Dismiss notifications when closing the app
- Date: Tue, 1 Dec 2020 09:56:14 +0000 (UTC)
commit 8db1e01d4a1831c7fbbf8edacfacc605b1cab8a0
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date: Tue Dec 1 09:56:13 2020 +0000
notifications: Dismiss notifications when closing the app
- Any pending deletions upon exit are now processed
- A timeout is added for non-auth notifications
Fixes #30
src/notifications.vala | 40 ++++++++++++++++++++++++++++++++++++++--
src/ui/window.ui | 1 +
src/window.vala | 7 +++++++
3 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/src/notifications.vala b/src/notifications.vala
index fd1e803..a1654d6 100644
--- a/src/notifications.vala
+++ b/src/notifications.vala
@@ -22,6 +22,9 @@
namespace Connections {
private class NotificationsBar : Gtk.Bin {
public const int DEFAULT_TIMEOUT = 6;
+ private const int MAX_NOTIFICATIONS = 5;
+
+ private Gtk.Widget? active_notification;
construct {
valign = Gtk.Align.START;
@@ -41,10 +44,10 @@ namespace Connections {
if (child is Notification)
(child as Notification).dismiss ();
-
}
add (notification);
+ active_notification = notification;
}
public AuthNotification display_for_auth (string auth_string,
@@ -59,13 +62,25 @@ namespace Connections {
remove (get_child ());
add (notification);
+ active_notification = notification;
return notification;
}
+
+ public void dismiss_any_notification () {
+ if (active_notification != null) {
+ Notification? child = active_notification as Notification;
+ if (child != null) {
+ child.dismiss ();
+ }
+ }
+ }
}
[GtkTemplate (ui = "/org/gnome/Connections/ui/notification.ui")]
private class Notification : Gtk.Revealer {
+ public signal void dismissed ();
+
public delegate void OKFunc ();
public delegate void DismissFunc ();
@@ -76,15 +91,24 @@ namespace Connections {
[GtkChild]
private Gtk.Button ok_button;
+ private uint notification_timeout_id = 0;
+
public Notification (string message,
string? ok_label,
owned OKFunc? ok_func,
- owned DismissFunc? dismiss_func) {
+ owned DismissFunc? dismiss_func,
+ int timeout = NotificationsBar.DEFAULT_TIMEOUT) {
this.dismiss_func = (owned)dismiss_func;
set_reveal_child (true);
message_label.label = message;
+ notification_timeout_id = Timeout.add_seconds (timeout, () => {
+ notification_timeout_id = 0;
+ dismissed ();
+ return Source.REMOVE;
+ });
+
if (ok_label != null) {
ok_button.label = ok_label;
@@ -93,10 +117,17 @@ namespace Connections {
ok_func ();
set_reveal_child (false);
+
+ if (notification_timeout_id != 0) {
+ Source.remove (notification_timeout_id);
+ notification_timeout_id = 0;
+ }
});
ok_button.show_all ();
}
+
+ dismissed.connect (dismiss);
}
[GtkCallback]
@@ -104,6 +135,11 @@ namespace Connections {
set_reveal_child (false);
if (dismiss_func != null)
dismiss_func ();
+
+ if (notification_timeout_id != 0) {
+ Source.remove (notification_timeout_id);
+ notification_timeout_id = 0;
+ }
}
}
diff --git a/src/ui/window.ui b/src/ui/window.ui
index 3acdeed..a8fcca1 100644
--- a/src/ui/window.ui
+++ b/src/ui/window.ui
@@ -5,6 +5,7 @@
<property name="width-request">1024</property>
<property name="height-request">768</property>
<signal name="key-press-event" after="yes" handler="on_key_pressed"/>
+ <signal name="delete-event" handler="on_delete_event"/>
<child type="titlebar">
<object class="ConnectionsTopbar" id="topbar">
<property name="visible">True</property>
diff --git a/src/window.vala b/src/window.vala
index 342deae..eadd50d 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -104,5 +104,12 @@ namespace Connections {
return false;
}
+
+ [GtkCallback]
+ private bool on_delete_event () {
+ notifications_bar.dismiss_any_notification ();
+
+ return false;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]