[nautilus/gnome-3-20] application: handle notifications internally
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gnome-3-20] application: handle notifications internally
- Date: Mon, 7 Mar 2016 20:08:35 +0000 (UTC)
commit 1ba5e6206fe0b4bcc40aee5e5432741b0ba08ce1
Author: Razvan Chitu <razvan ch95 gmail com>
Date: Fri Mar 4 19:33:56 2016 +0200
application: handle notifications internally
In Nautilus, operations such as unmounts create notifications that are not
withdrawn on application closing. This leads to issues such as notifications
that persist even after reboot. In order to fix this, the application should
keep track of the notifications sent in order to withdraw them when it is
closed.
Add helper functions for sending and withdrawing notifications. Add "shutdown"
signal handler for removing notifications on application closing.
https://bugzilla.gnome.org/show_bug.cgi?id=763129
src/nautilus-application.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
src/nautilus-application.h | 7 +++++
2 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 0547c29..803d181 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -80,6 +80,8 @@ struct _NautilusApplicationPriv {
NautilusShellSearchProvider *search_provider;
GList *windows;
+
+ GHashTable *notifications;
};
void
@@ -532,6 +534,8 @@ nautilus_application_finalize (GObject *object)
g_list_free (application->priv->windows);
+ g_hash_table_destroy (application->priv->notifications);
+
G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
}
@@ -991,6 +995,11 @@ nautilus_application_init (NautilusApplication *application)
G_TYPE_INSTANCE_GET_PRIVATE (application, NAUTILUS_TYPE_APPLICATION,
NautilusApplicationPriv);
+ application->priv->notifications = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ NULL);
+
g_application_add_main_option_entries (G_APPLICATION (application), options);
}
@@ -1106,6 +1115,56 @@ setup_theme_extensions (void)
theme_changed (settings);
}
+NautilusApplication *
+nautilus_application_get_default (void)
+{
+ NautilusApplication *self;
+
+ self = NAUTILUS_APPLICATION (g_application_get_default ());
+
+ return self;
+}
+
+void
+nautilus_application_send_notification (NautilusApplication *self,
+ const gchar *notification_id,
+ GNotification *notification)
+{
+ g_hash_table_add (self->priv->notifications, g_strdup (notification_id));
+ g_application_send_notification (G_APPLICATION (self), notification_id, notification);
+}
+
+void
+nautilus_application_withdraw_notification (NautilusApplication *self,
+ const gchar *notification_id)
+{
+ if (!g_hash_table_contains (self->priv->notifications, notification_id)) {
+ return;
+ }
+
+ g_hash_table_remove (self->priv->notifications, notification_id);
+ g_application_withdraw_notification (G_APPLICATION (self), notification_id);
+}
+
+static void
+on_application_shutdown (GApplication *application,
+ gpointer user_data)
+{
+ NautilusApplication *self = NAUTILUS_APPLICATION (application);
+ GList *notification_ids;
+ GList *l;
+ gchar *notification_id;
+
+ notification_ids = g_hash_table_get_keys (self->priv->notifications);
+ for (l = notification_ids; l != NULL; l = l->next) {
+ notification_id = l->data;
+
+ g_application_withdraw_notification (application, notification_id);
+ }
+
+ g_list_free (notification_ids);
+}
+
static void
nautilus_application_startup (GApplication *app)
{
@@ -1153,6 +1212,8 @@ nautilus_application_startup (GApplication *app)
init_desktop (self);
nautilus_profile_end (NULL);
+
+ g_signal_connect (self, "shutdown", G_CALLBACK (on_application_shutdown), NULL);
}
static gboolean
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index a57da53..2af610a 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -78,6 +78,13 @@ void nautilus_application_open_location_full (NautilusApplication *applicati
NautilusWindow *target_window,
NautilusWindowSlot *target_slot);
+NautilusApplication *nautilus_application_get_default (void);
+void nautilus_application_send_notification (NautilusApplication *self,
+ const gchar *notification_id,
+ GNotification *notification);
+void nautilus_application_withdraw_notification (NautilusApplication *self,
+ const gchar *notification_id);
+
NautilusBookmarkList *
nautilus_application_get_bookmarks (NautilusApplication *application);
void nautilus_application_edit_bookmarks (NautilusApplication *application,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]