[epiphany/wip/exalm/cleanups: 6/14] notification: Use a signal for closing




commit e66d7edf2c8972ae150b83589888839a2593b04b
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Nov 29 14:01:15 2021 +0500

    notification: Use a signal for closing
    
    Don't access its parent for this.
    
    Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1034>

 lib/ephy-notification-container.c | 14 ++++++++++++++
 lib/ephy-notification.c           | 24 +++++++++++++++---------
 2 files changed, 29 insertions(+), 9 deletions(-)
---
diff --git a/lib/ephy-notification-container.c b/lib/ephy-notification-container.c
index 2c31bbb9f..376513ce0 100644
--- a/lib/ephy-notification-container.c
+++ b/lib/ephy-notification-container.c
@@ -69,6 +69,18 @@ ephy_notification_container_get_default (void)
                        NULL);
 }
 
+static void
+notification_close_cb (EphyNotification          *notification,
+                       EphyNotificationContainer *self)
+{
+  gtk_container_remove (GTK_CONTAINER (self->grid), GTK_WIDGET (notification));
+
+  if (ephy_notification_container_get_num_children (self) == 0) {
+    gtk_widget_hide (GTK_WIDGET (self));
+    gtk_revealer_set_reveal_child (GTK_REVEALER (self), FALSE);
+  }
+}
+
 void
 ephy_notification_container_add_notification (EphyNotificationContainer *self,
                                               GtkWidget                 *notification)
@@ -92,6 +104,8 @@ ephy_notification_container_add_notification (EphyNotificationContainer *self,
   gtk_container_add (GTK_CONTAINER (self->grid), notification);
   gtk_widget_show_all (GTK_WIDGET (self));
   gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
+
+  g_signal_connect (notification, "close", G_CALLBACK (notification_close_cb), self);
 }
 
 guint
diff --git a/lib/ephy-notification.c b/lib/ephy-notification.c
index da4f42ebe..38ccc8829 100644
--- a/lib/ephy-notification.c
+++ b/lib/ephy-notification.c
@@ -42,6 +42,13 @@ enum {
   PROP_BODY
 };
 
+enum {
+  CLOSE,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
 G_DEFINE_TYPE (EphyNotification, ephy_notification, GTK_TYPE_BIN);
 
 static void
@@ -112,15 +119,7 @@ static void
 close_button_clicked_cb (GtkButton        *button,
                          EphyNotification *self)
 {
-  EphyNotificationContainer *container = ephy_notification_container_get_default ();
-
-  /* gtk_widget_destroy() removes the widget from its parent container. */
-  gtk_widget_destroy (GTK_WIDGET (self));
-
-  if (ephy_notification_container_get_num_children (container) == 0) {
-    gtk_widget_hide (GTK_WIDGET (container));
-    gtk_revealer_set_reveal_child (GTK_REVEALER (container), FALSE);
-  }
+  g_signal_emit (self, signals[CLOSE], 0);
 }
 
 static void
@@ -187,6 +186,13 @@ ephy_notification_class_init (EphyNotificationClass *klass)
                                                         "The notification body",
                                                         "",
                                                         G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY | 
G_PARAM_READWRITE));
+
+  signals[CLOSE] =
+    g_signal_new ("close",
+                  G_OBJECT_CLASS_TYPE (object_class),
+                  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                  0, NULL, NULL, NULL,
+                  G_TYPE_NONE, 0);
 }
 
 EphyNotification *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]