summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRazvan Chitu <razvan.ch95@gmail.com>2016-03-04 19:33:56 +0200
committerCarlos Soriano <csoriano@gnome.org>2016-03-07 21:13:02 +0100
commitaa54b178028ea4091a7e5c8fa09fd5bf03d2a2b0 (patch)
tree22d0bb6f892e6fc4e114861792b57a7d0b2264ea
parent11fdde78eb2957fe297b9e2a77c521d64649a6f5 (diff)
downloadnautilus-aa54b178028ea4091a7e5c8fa09fd5bf03d2a2b0.tar.gz
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
-rw-r--r--src/nautilus-application.c61
-rw-r--r--src/nautilus-application.h7
2 files changed, 68 insertions, 0 deletions
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 0547c298d..803d181f6 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 a57da53a8..2af610a0a 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,