From 492613abba3299d0215e02aa2083374e26e561dd Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 29 Nov 2014 23:59:59 -0800 Subject: application: cleanup use of gtk_application_get_windows() We're really only interested in the NautilusWindows that we create - so keep track of them explicitly instead of checking for NAUTILUS_IS_WINDOW() every time. --- src/nautilus-application-actions.c | 10 ++--- src/nautilus-application.c | 81 ++++++++++++++++++++------------------ src/nautilus-application.h | 2 + src/nautilus-view.c | 13 +++--- src/nautilus-window-slot.c | 6 +-- 5 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/nautilus-application-actions.c b/src/nautilus-application-actions.c index aee66ef4b..a69de747d 100644 --- a/src/nautilus-application-actions.c +++ b/src/nautilus-application-actions.c @@ -173,13 +173,13 @@ action_quit (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - GtkApplication *application = user_data; - GList *l; + NautilusApplication *application = user_data; + GList *windows, *l; /* nautilus_window_close() doesn't do anything for desktop windows */ - for (l = gtk_application_get_windows (GTK_APPLICATION (application)); l; l = l->next) { - if (NAUTILUS_IS_WINDOW (l->data)) - nautilus_window_close (NAUTILUS_WINDOW (l->data)); + windows = nautilus_application_get_windows (application); + for (l = windows; l != NULL; l = l->next) { + nautilus_window_close (l->data); } } diff --git a/src/nautilus-application.c b/src/nautilus-application.c index 64425d280..391d04182 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -82,8 +82,17 @@ struct _NautilusApplicationPriv { GtkWidget *connect_server_window; NautilusShellSearchProvider *search_provider; + + GList *windows; }; +GList * +nautilus_application_get_windows (NautilusApplication *application) +{ + return application->priv->windows; +} + + NautilusProgressUIHandler * nautilus_application_get_progress_ui_handler (NautilusApplication *application) { @@ -317,21 +326,6 @@ do_upgrades_once (NautilusApplication *self) g_free (xdg_dir); } -static gboolean -another_navigation_window_already_showing (NautilusApplication *application, - NautilusWindow *the_window) -{ - GList *l; - - for (l = gtk_application_get_windows (GTK_APPLICATION (application)); l; l = l->next) { - if (NAUTILUS_IS_WINDOW (l->data) && l->data != the_window) { - return TRUE; - } - } - - return FALSE; -} - NautilusWindow * nautilus_application_create_window (NautilusApplication *application, GdkScreen *screen) @@ -339,10 +333,12 @@ nautilus_application_create_window (NautilusApplication *application, NautilusWindow *window; char *geometry_string; gboolean maximized; + gint n_windows; g_return_val_if_fail (NAUTILUS_IS_APPLICATION (application), NULL); nautilus_profile_start (NULL); + n_windows = g_list_length (application->priv->windows); window = nautilus_window_new (screen); maximized = g_settings_get_boolean @@ -357,16 +353,16 @@ nautilus_application_create_window (NautilusApplication *application, (nautilus_window_state, NAUTILUS_WINDOW_STATE_GEOMETRY); if (geometry_string != NULL && geometry_string[0] != 0) { - /* Ignore saved window position if a window with the same - * location is already showing. That way the two windows - * wont appear at the exact same location on the screen. + /* Ignore saved window position if another window is already showing. + * That way the two windows wont appear at the exact same + * location on the screen. */ eel_gtk_window_set_initial_geometry_from_string (GTK_WINDOW (window), geometry_string, NAUTILUS_WINDOW_MIN_WIDTH, NAUTILUS_WINDOW_MIN_HEIGHT, - another_navigation_window_already_showing (application, window)); + n_windows > 0); } g_free (geometry_string); @@ -380,6 +376,7 @@ static NautilusWindowSlot * get_window_slot_for_location (NautilusApplication *application, GFile *location) { NautilusWindowSlot *slot; + NautilusWindow *window; GList *l, *sl; slot = NULL; @@ -390,12 +387,11 @@ get_window_slot_for_location (NautilusApplication *application, GFile *location) g_object_ref (location); } - for (l = gtk_application_get_windows (GTK_APPLICATION (application)); l; l = l->next) { - if (!NAUTILUS_IS_WINDOW (l->data) || NAUTILUS_IS_DESKTOP_WINDOW (l->data)) - continue; + for (l = application->priv->windows; l != NULL; l = l->next) { + window = l->data; - for (sl = nautilus_window_get_slots (NAUTILUS_WINDOW (l->data)); sl; sl = sl->next) { - NautilusWindowSlot *current = NAUTILUS_WINDOW_SLOT (sl->data); + for (sl = nautilus_window_get_slots (window); sl; sl = sl->next) { + NautilusWindowSlot *current = sl->data; GFile *slot_location = nautilus_window_slot_get_location (current); if (slot_location && g_file_equal (slot_location, location)) { @@ -626,6 +622,8 @@ nautilus_application_finalize (GObject *object) g_clear_object (&application->priv->fdb_manager); g_clear_object (&application->priv->search_provider); + g_list_free (application->priv->windows); + G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object); } @@ -1100,15 +1098,15 @@ update_dbus_opened_locations (NautilusApplication *app) GList *locations = NULL; gsize locations_size = 0; gchar **locations_array; + NautilusWindow *window; g_return_if_fail (NAUTILUS_IS_APPLICATION (app)); - for (l = gtk_application_get_windows (GTK_APPLICATION (app)); l; l = l->next) { - if (!NAUTILUS_IS_WINDOW (l->data) || NAUTILUS_IS_DESKTOP_WINDOW (l->data)) - continue; + for (l = app->priv->windows; l != NULL; l = l->next) { + window = l->data; - for (sl = nautilus_window_get_slots (NAUTILUS_WINDOW (l->data)); sl; sl = sl->next) { - NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (sl->data); + for (sl = nautilus_window_get_slots (window); sl; sl = sl->next) { + NautilusWindowSlot *slot = sl->data; gchar *uri = nautilus_window_slot_get_location_uri (slot); if (uri) { @@ -1175,30 +1173,35 @@ static void nautilus_application_window_added (GtkApplication *app, GtkWindow *window) { - /* chain to parent */ + NautilusApplication *self = NAUTILUS_APPLICATION (app); + GTK_APPLICATION_CLASS (nautilus_application_parent_class)->window_added (app, window); - g_signal_connect (window, "slot-added", G_CALLBACK (on_slot_added), app); - g_signal_connect (window, "slot-removed", G_CALLBACK (on_slot_removed), app); + if (NAUTILUS_IS_WINDOW (window)) { + self->priv->windows = g_list_prepend (self->priv->windows, window); + g_signal_connect (window, "slot-added", G_CALLBACK (on_slot_added), app); + g_signal_connect (window, "slot-removed", G_CALLBACK (on_slot_removed), app); + } } static void nautilus_application_window_removed (GtkApplication *app, GtkWindow *window) { - GList *l; + NautilusApplication *self = NAUTILUS_APPLICATION (app); - /* chain to parent */ GTK_APPLICATION_CLASS (nautilus_application_parent_class)->window_removed (app, window); + if (NAUTILUS_IS_WINDOW (window)) { + self->priv->windows = g_list_remove_all (self->priv->windows, window); + g_signal_handlers_disconnect_by_func (window, on_slot_added, app); + g_signal_handlers_disconnect_by_func (window, on_slot_removed, app); + } + /* if this was the last window, close the previewer */ - for (l = gtk_application_get_windows (GTK_APPLICATION (app)); l && !NAUTILUS_IS_WINDOW (l->data); l = l->next); - if (!l) { + if (g_list_length (self->priv->windows) == 0) { nautilus_previewer_call_close (); } - - g_signal_handlers_disconnect_by_func (window, on_slot_added, app); - g_signal_handlers_disconnect_by_func (window, on_slot_removed, app); } static void diff --git a/src/nautilus-application.h b/src/nautilus-application.h index 991b14333..540d8b48b 100644 --- a/src/nautilus-application.h +++ b/src/nautilus-application.h @@ -63,6 +63,8 @@ NautilusApplication * nautilus_application_new (void); NautilusWindow * nautilus_application_create_window (NautilusApplication *application, GdkScreen *screen); +GList * nautilus_application_get_windows (NautilusApplication *application); + void nautilus_application_open_location (NautilusApplication *application, GFile *location, GFile *selection, diff --git a/src/nautilus-view.c b/src/nautilus-view.c index 17d5d4982..16df48170 100644 --- a/src/nautilus-view.c +++ b/src/nautilus-view.c @@ -30,6 +30,7 @@ #include "nautilus-view.h" #include "nautilus-actions.h" +#include "nautilus-application.h" #include "nautilus-desktop-canvas-view.h" #include "nautilus-error-reporting.h" #include "nautilus-list-view.h" @@ -5753,11 +5754,11 @@ on_app_window_removed (GtkApplication *application, static void copy_data_free (CopyCallbackData *data) { - GtkApplication *application; + NautilusApplication *application; GList *windows; GList *w; - application = GTK_APPLICATION (g_application_get_default ()); + application = NAUTILUS_APPLICATION (g_application_get_default ()); g_signal_handlers_disconnect_by_func (application, G_CALLBACK (on_app_window_added), data); @@ -5765,7 +5766,7 @@ copy_data_free (CopyCallbackData *data) G_CALLBACK (on_app_window_removed), data); - windows = gtk_application_get_windows (application); + windows = nautilus_application_get_windows (application); for (w = windows; w != NULL; w = w->next) { NautilusWindow *window = w->data; GList *slots; @@ -5889,12 +5890,12 @@ get_selected_folders (GList *selection) static void add_window_location_bookmarks (CopyCallbackData *data) { - GtkApplication *application; + NautilusApplication *application; GList *windows; GList *w; - application = GTK_APPLICATION (g_application_get_default ()); - windows = gtk_application_get_windows (application); + application = NAUTILUS_APPLICATION (g_application_get_default ()); + windows = nautilus_application_get_windows (application); g_signal_connect (application, "window-added", G_CALLBACK (on_app_window_added), data); g_signal_connect (application, "window-removed", G_CALLBACK (on_app_window_removed), data); diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index ea2ff71a8..875995dab 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -1161,7 +1161,7 @@ got_file_info_for_view_selection_callback (NautilusFile *file, GFile *location, *default_location; GMountOperation *mount_op; MountNotMountedData *data; - GtkApplication *app; + NautilusApplication *app; GMount *mount; slot = callback_data; @@ -1298,9 +1298,9 @@ got_file_info_for_view_selection_callback (NautilusFile *file, */ /* if this is the only window, we don't want to quit, so we redirect it to home */ - app = GTK_APPLICATION (g_application_get_default ()); + app = NAUTILUS_APPLICATION (g_application_get_default ()); - if (g_list_length (gtk_application_get_windows (app)) == 1) { + if (g_list_length (nautilus_application_get_windows (app)) == 1) { /* the user could have typed in a home directory that doesn't exist, in which case going home would cause an infinite loop, so we better test for that */ -- cgit v1.2.1