[gnome-photos] application: Add API to prevent the main window from getting destroyed
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] application: Add API to prevent the main window from getting destroyed
- Date: Sat, 18 Jun 2016 08:03:56 +0000 (UTC)
commit 45cca03a9d3ab08973d0062b2166d4db8414935c
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Apr 22 20:00:21 2016 +0200
application: Add API to prevent the main window from getting destroyed
We don't want the application to shut down while certain critical
asynchronous operations are in flight. eg., saving the pipeline or
deleting an item.
The problem with g_application_hold is that it doesn't prevent the
main window from getting destroyed, and some of the callbacks of
these operations expect the widget hierarchy to be in place. While we
can try to make things more robust on a case by case basis, it will be
hard to ensure that all corner cases have been covered.
It is much safer to temporarily override the default
GtkWidget::delete-event handler to only hide the PhotosMainWindow
instead of destroying it.
https://bugzilla.gnome.org/show_bug.cgi?id=764076
src/photos-application.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/photos-application.h | 4 ++++
2 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 68d3eae..4b1368c 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -104,7 +104,9 @@ struct _PhotosApplication
PhotosSearchProvider *search_provider;
PhotosSelectionController *sel_cntrlr;
TrackerExtractPriority *extract_priority;
+ gboolean main_window_deleted;
guint create_miners_count;
+ guint use_count;
guint32 activation_timestamp;
gulong source_added_id;
gulong source_removed_id;
@@ -420,6 +422,20 @@ photos_application_tracker_clear_rdf_types (GObject *source_object, GAsyncResult
}
+static gboolean
+photos_application_delete_event (PhotosApplication *self)
+{
+ gboolean ret_val = GDK_EVENT_PROPAGATE;
+
+ self->main_window_deleted = TRUE;
+
+ if (self->use_count > 0)
+ ret_val = gtk_widget_hide_on_delete (self->main_window);
+
+ return ret_val;
+}
+
+
static void
photos_application_destroy (PhotosApplication *self)
{
@@ -615,8 +631,15 @@ photos_application_create_window (PhotosApplication *self)
g_return_val_if_fail (photos_application_sanity_check_gegl (self), FALSE);
self->main_window = photos_main_window_new (GTK_APPLICATION (self));
+ g_signal_connect_object (self->main_window,
+ "delete-event",
+ G_CALLBACK (photos_application_delete_event),
+ self,
+ G_CONNECT_AFTER | G_CONNECT_SWAPPED);
g_signal_connect_swapped (self->main_window, "destroy", G_CALLBACK (photos_application_destroy), self);
+ self->main_window_deleted = FALSE;
+
g_application_hold (G_APPLICATION (self));
tracker_extract_priority_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
@@ -1767,3 +1790,23 @@ photos_application_get_scale_factor (PhotosApplication *self)
out:
return ret_val;
}
+
+
+void
+photos_application_hold (PhotosApplication *self)
+{
+ g_return_if_fail (PHOTOS_IS_APPLICATION (self));
+ self->use_count++;
+}
+
+
+void
+photos_application_release (PhotosApplication *self)
+{
+ g_return_if_fail (PHOTOS_IS_APPLICATION (self));
+ g_return_if_fail (self->use_count > 0);
+
+ self->use_count--;
+ if (self->main_window_deleted && self->use_count == 0)
+ gtk_widget_destroy (self->main_window);
+}
diff --git a/src/photos-application.h b/src/photos-application.h
index caaa28e..f77a147 100644
--- a/src/photos-application.h
+++ b/src/photos-application.h
@@ -50,6 +50,10 @@ GList *photos_application_get_miners_running (PhotosApplicat
gint photos_application_get_scale_factor (PhotosApplication *self);
+void photos_application_hold (PhotosApplication *self);
+
+void photos_application_release (PhotosApplication *self);
+
G_END_DECLS
#endif /* PHOTOS_APPLICATION_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]