Commit e66d7edf authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko
Browse files

notification: Use a signal for closing

Don't access its parent for this.

Part-of: <!1034>
parent 1adf4af3
......@@ -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
......
......@@ -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 *
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment