[nautilus/gnome-2-32: 63/283] Remove a pile of hacks used to initialize bookmarks.



commit e16db78c621f29a34091033644ba10519f113b69
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu May 6 18:07:56 2010 +0200

    Remove a pile of hacks used to initialize bookmarks.
    
    - Make nautilus_window_constructed a real GObject implementation and
      move bookmark initialization code there.
    - Don't replicate a singleton logic in nautilus-window-bookmarks now
      that NautilusBookmarkList is a real singleton
    - Remove get_bookmark_list() method from NautilusWindowInfo, as it's
      not any useful anymore.

 libnautilus-private/nautilus-window-info.c |    9 ---
 libnautilus-private/nautilus-window-info.h |    3 -
 src/nautilus-application.c                 |    2 -
 src/nautilus-window-bookmarks.c            |  107 ++++++++--------------------
 src/nautilus-window-bookmarks.h            |    2 -
 src/nautilus-window-menus.c                |    1 -
 src/nautilus-window-private.h              |    3 +-
 src/nautilus-window.c                      |   23 +++---
 8 files changed, 42 insertions(+), 108 deletions(-)
---
diff --git a/libnautilus-private/nautilus-window-info.c b/libnautilus-private/nautilus-window-info.c
index 7639775..0b5ba2e 100644
--- a/libnautilus-private/nautilus-window-info.c
+++ b/libnautilus-private/nautilus-window-info.c
@@ -202,15 +202,6 @@ nautilus_window_info_get_history (NautilusWindowInfo *window)
 	return (* NAUTILUS_WINDOW_INFO_GET_IFACE (window)->get_history) (window);
 }
 
-NautilusBookmarkList *
-nautilus_window_info_get_bookmark_list (NautilusWindowInfo *window)
-{
-	g_return_val_if_fail (NAUTILUS_IS_WINDOW_INFO (window), NULL);
-	
-	return (* NAUTILUS_WINDOW_INFO_GET_IFACE (window)->get_bookmark_list) (window);
-}
-
-
 char *
 nautilus_window_info_get_current_location (NautilusWindowInfo *window)
 {
diff --git a/libnautilus-private/nautilus-window-info.h b/libnautilus-private/nautilus-window-info.h
index 1c71d58..737094a 100644
--- a/libnautilus-private/nautilus-window-info.h
+++ b/libnautilus-private/nautilus-window-info.h
@@ -127,8 +127,6 @@ struct _NautilusWindowInfoIface
 					  const char *status);
 	char * (* get_title)             (NautilusWindowInfo *window);
 	GList *(* get_history)           (NautilusWindowInfo *window);
-	NautilusBookmarkList *  
-	       (* get_bookmark_list)     (NautilusWindowInfo *window);
 	NautilusWindowType
 	       (* get_window_type)       (NautilusWindowInfo *window);
 	NautilusWindowShowHiddenFilesMode
@@ -167,7 +165,6 @@ void                              nautilus_window_info_push_status
 NautilusWindowType                nautilus_window_info_get_window_type          (NautilusWindowInfo                *window);
 char *                            nautilus_window_info_get_title                (NautilusWindowInfo                *window);
 GList *                           nautilus_window_info_get_history              (NautilusWindowInfo                *window);
-NautilusBookmarkList *		  nautilus_window_info_get_bookmark_list        (NautilusWindowInfo                *window);
 char *                            nautilus_window_info_get_current_location     (NautilusWindowInfo                *window);
 int                               nautilus_window_info_get_selection_count      (NautilusWindowInfo                *window);
 GList *                           nautilus_window_info_get_selection            (NautilusWindowInfo                *window);
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 81beb48..544a4ec 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1236,8 +1236,6 @@ create_window (NautilusApplication *application,
 						  "app", application,
 						  "screen", screen,
 						  NULL));
-	/* Must be called after construction finished */
-	nautilus_window_constructed (window);
 
 	if (startup_id) {
 		gtk_window_set_startup_id (GTK_WINDOW (window), startup_id);
diff --git a/src/nautilus-window-bookmarks.c b/src/nautilus-window-bookmarks.c
index e1b6574..0d25e35 100644
--- a/src/nautilus-window-bookmarks.c
+++ b/src/nautilus-window-bookmarks.c
@@ -43,39 +43,23 @@
 #define MENU_ITEM_MAX_WIDTH_CHARS 32
 
 static GtkWindow *bookmarks_window = NULL;
-static NautilusBookmarkList *bookmarks = NULL;
-
-static void schedule_refresh_bookmarks_menu (NautilusWindow *window);
-
-static void
-free_bookmark_list (void)
-{
-	g_object_unref (bookmarks);
-}
-
-NautilusBookmarkList *
-nautilus_get_bookmark_list (void)
-{
-        if (bookmarks == NULL) {
-                bookmarks = nautilus_bookmark_list_new ();
-                eel_debug_call_at_shutdown (free_bookmark_list);
-        }
-	
-        return bookmarks;
-}
 
+static void refresh_bookmarks_menu (NautilusWindow *window);
 
 static void
 remove_bookmarks_for_uri_if_yes (GtkDialog *dialog, int response, gpointer callback_data)
 {
 	const char *uri;
+	NautilusWindow *window;
 
 	g_assert (GTK_IS_DIALOG (dialog));
 	g_assert (callback_data != NULL);
 
+	window = callback_data;
+
 	if (response == GTK_RESPONSE_YES) {
-		uri = callback_data;
-		nautilus_bookmark_list_delete_items_with_uri (nautilus_get_bookmark_list (), uri);
+		uri = g_object_get_data (G_OBJECT (dialog), "uri");
+		nautilus_bookmark_list_delete_items_with_uri (window->details->bookmark_list, uri);
 	}
 
 	gtk_object_destroy (GTK_OBJECT (dialog));
@@ -103,12 +87,9 @@ show_bogus_bookmark_window (NautilusWindow *window,
 					 GTK_STOCK_CANCEL,
 					 GTK_WINDOW (window));
 
-	g_signal_connect_data (dialog,
-			       "response",
-			       G_CALLBACK (remove_bookmarks_for_uri_if_yes),
-			       g_file_get_uri (location),
-			       (GClosureNotify)g_free,
-			       0);
+	g_signal_connect (dialog, "response",
+	                  G_CALLBACK (remove_bookmarks_for_uri_if_yes), window);
+	g_object_set_data_full (G_OBJECT (dialog), "uri", g_file_get_uri (location), g_free);
 
 	gtk_dialog_set_default_response (dialog, GTK_RESPONSE_NO);
 
@@ -118,10 +99,15 @@ show_bogus_bookmark_window (NautilusWindow *window,
 }
 
 static GtkWindow *
-get_or_create_bookmarks_window (GObject *undo_manager_source)
+get_or_create_bookmarks_window (NautilusWindow *window)
 {
+	GObject *undo_manager_source;
+
+	undo_manager_source = G_OBJECT (window);
+
 	if (bookmarks_window == NULL) {
-		bookmarks_window = create_bookmarks_window (nautilus_get_bookmark_list(), undo_manager_source);
+		bookmarks_window = create_bookmarks_window (window->details->bookmark_list,
+		                                            undo_manager_source);
 	} else {
 		edit_bookmarks_dialog_set_signals (undo_manager_source);
 	}
@@ -155,14 +141,16 @@ nautilus_window_add_bookmark_for_current_location (NautilusWindow *window)
 {
 	NautilusBookmark *bookmark;
 	NautilusWindowSlot *slot;
+	NautilusBookmarkList *list;
 
 	g_assert (NAUTILUS_IS_WINDOW (window));
 
 	slot = window->details->active_pane->active_slot;
 	bookmark = slot->current_location_bookmark;
+	list = window->details->bookmark_list;
 
-	if (!nautilus_bookmark_list_contains (nautilus_get_bookmark_list (), bookmark)) {
-		nautilus_bookmark_list_append (nautilus_get_bookmark_list (), bookmark); 
+	if (!nautilus_bookmark_list_contains (list, bookmark)) {
+		nautilus_bookmark_list_append (list, bookmark); 
 	}
 }
 
@@ -171,22 +159,13 @@ nautilus_window_edit_bookmarks (NautilusWindow *window)
 {
 	GtkWindow *dialog;
 
-	dialog = get_or_create_bookmarks_window (G_OBJECT (window));
+	dialog = get_or_create_bookmarks_window (window);
 
 	gtk_window_set_screen (
 		dialog, gtk_window_get_screen (GTK_WINDOW (window)));
         gtk_window_present (dialog);
 }
 
-void
-nautilus_window_remove_bookmarks_menu_callback (NautilusWindow *window)
-{
-        if (window->details->refresh_bookmarks_menu_idle_id != 0) {
-                g_source_remove (window->details->refresh_bookmarks_menu_idle_id);
-		window->details->refresh_bookmarks_menu_idle_id = 0;
-        }
-}
-
 static void
 remove_bookmarks_menu_items (NautilusWindow *window)
 {
@@ -236,7 +215,11 @@ update_bookmarks (NautilusWindow *window)
 	g_assert (window->details->bookmarks_merge_id == 0);
 	g_assert (window->details->bookmarks_action_group == NULL);
 
-	bookmarks = nautilus_get_bookmark_list ();
+	if (window->details->bookmark_list == NULL) {
+		window->details->bookmark_list = nautilus_bookmark_list_new ();
+	}
+
+	bookmarks = window->details->bookmark_list;
 
 	ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));
 	
@@ -267,7 +250,7 @@ update_bookmarks (NautilusWindow *window)
 			 index,
 			 window->details->bookmarks_action_group,
 			 window->details->bookmarks_merge_id,
-			 G_CALLBACK (schedule_refresh_bookmarks_menu), 
+			 G_CALLBACK (refresh_bookmarks_menu), 
 			 show_bogus_bookmark_window);
 	}
 }
@@ -277,37 +260,10 @@ refresh_bookmarks_menu (NautilusWindow *window)
 {
 	g_assert (NAUTILUS_IS_WINDOW (window));
 
-	/* Unregister any pending call to this function. */
-	nautilus_window_remove_bookmarks_menu_callback (window);
-
 	remove_bookmarks_menu_items (window);
 	update_bookmarks (window);
 }
 
-
-static gboolean
-refresh_bookmarks_menu_idle_callback (gpointer data)
-{
-	g_assert (NAUTILUS_IS_WINDOW (data));
-
-	refresh_bookmarks_menu (NAUTILUS_WINDOW (data));
-
-        /* Don't call this again (unless rescheduled) */
-        return FALSE;
-}
-
-static void
-schedule_refresh_bookmarks_menu (NautilusWindow *window)
-{
-	g_assert (NAUTILUS_IS_WINDOW (window));
-
-	if (window->details->refresh_bookmarks_menu_idle_id == 0) {
-                window->details->refresh_bookmarks_menu_idle_id
-                        = g_idle_add (refresh_bookmarks_menu_idle_callback,
-				      window);
-	}	
-}
-
 /**
  * nautilus_window_initialize_bookmarks_menu
  * 
@@ -319,13 +275,10 @@ nautilus_window_initialize_bookmarks_menu (NautilusWindow *window)
 {
 	g_assert (NAUTILUS_IS_WINDOW (window));
 
-	/* Construct the initial set of bookmarks. */
-	/* We do this in an idle, since this is called in the constructor
-	 * where we don't know the real type of the window */
-	schedule_refresh_bookmarks_menu (window);
+	refresh_bookmarks_menu (window);
 
 	/* Recreate dynamic part of menu if bookmark list changes */
-	g_signal_connect_object (nautilus_get_bookmark_list (), "contents_changed",
-				 G_CALLBACK (schedule_refresh_bookmarks_menu),
+	g_signal_connect_object (window->details->bookmark_list, "contents_changed",
+				 G_CALLBACK (refresh_bookmarks_menu),
 				 window, G_CONNECT_SWAPPED);
 }
diff --git a/src/nautilus-window-bookmarks.h b/src/nautilus-window-bookmarks.h
index 0fbb604..ba051c1 100644
--- a/src/nautilus-window-bookmarks.h
+++ b/src/nautilus-window-bookmarks.h
@@ -29,11 +29,9 @@
 #include <nautilus-window.h>
 #include "nautilus-bookmark-list.h"
 
-NautilusBookmarkList *nautilus_get_bookmark_list                        (void);
 void                  nautilus_bookmarks_exiting                        (void);
 void                  nautilus_window_add_bookmark_for_current_location (NautilusWindow *window);
 void                  nautilus_window_edit_bookmarks                    (NautilusWindow *window);
 void                  nautilus_window_initialize_bookmarks_menu         (NautilusWindow *window);
-void                  nautilus_window_remove_bookmarks_menu_callback    (NautilusWindow *window);
 
 #endif
diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c
index 372c396..1cdab99 100644
--- a/src/nautilus-window-menus.c
+++ b/src/nautilus-window-menus.c
@@ -938,7 +938,6 @@ nautilus_window_initialize_menus (NautilusWindow *window)
 	gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, NULL);
 
 	nautilus_window_initialize_trash_icon_monitor (window);
-	nautilus_window_initialize_bookmarks_menu (window);
 }
 
 static GList *
diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h
index d9ed0e4..b796b07 100644
--- a/src/nautilus-window-private.h
+++ b/src/nautilus-window-private.h
@@ -54,8 +54,8 @@ struct NautilusWindowDetails
         GtkActionGroup *extensions_menu_action_group;
 
         GtkActionGroup *bookmarks_action_group;
-        guint refresh_bookmarks_menu_idle_id;
         guint bookmarks_merge_id;
+        NautilusBookmarkList *bookmark_list;
 
 	NautilusWindowShowHiddenFilesMode show_hidden_files_mode;
 
@@ -212,7 +212,6 @@ gboolean           nautilus_add_to_history_list_no_notify                (GFile
 									  GIcon            *icon);
 GList *            nautilus_get_history_list                             (void);
 void               nautilus_window_bookmarks_preference_changed_callback (gpointer           user_data);
-void               nautilus_window_constructed                           (NautilusWindow    *window);
 
 
 /* sync window GUI with current slot. Used when changing slots,
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 854fcf2..2bc2c73 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -515,11 +515,14 @@ nautilus_window_set_initial_window_geometry (NautilusWindow *window)
 				          max_height_for_screen));
 }
 
-void
-nautilus_window_constructed (NautilusWindow *window)
+static void
+nautilus_window_constructed (GObject *self)
 {
-	g_return_if_fail (NAUTILUS_IS_WINDOW (window));
+	NautilusWindow *window;
+
+	window = NAUTILUS_WINDOW (self);
 
+	nautilus_window_initialize_bookmarks_menu (window);
 	nautilus_window_set_initial_window_geometry (window);
 	nautilus_undo_manager_attach (window->application->undo_manager, G_OBJECT (window));
 }
@@ -592,11 +595,13 @@ nautilus_window_finalize (GObject *object)
 
 	window = NAUTILUS_WINDOW (object);
 
-	nautilus_window_remove_bookmarks_menu_callback (window);
 	nautilus_window_remove_trash_monitor_callback (window);
-
 	free_stored_viewers (window);
 
+	if (window->details->bookmark_list != NULL) {
+		g_object_unref (window->details->bookmark_list);
+	}
+
 	/* nautilus_window_close() should have run */
 	g_assert (window->details->panes == NULL);
 
@@ -1853,12 +1858,6 @@ nautilus_window_set_initiated_unmount (NautilusWindowInfo *window,
 	window->details->initiated_unmount = initiated_unmount;
 }
 
-static NautilusBookmarkList *
-nautilus_window_get_bookmark_list (NautilusWindowInfo *window)
-{
-  return nautilus_get_bookmark_list ();
-}
-
 static char *
 nautilus_window_get_cached_title (NautilusWindow *window)
 {
@@ -1937,7 +1936,6 @@ nautilus_window_info_iface_init (NautilusWindowInfoIface *iface)
 	iface->get_window_type = nautilus_window_get_window_type;
 	iface->get_title = nautilus_window_get_cached_title;
 	iface->get_history = nautilus_window_get_history;
-	iface->get_bookmark_list = nautilus_window_get_bookmark_list;
 	iface->get_current_location = nautilus_window_get_location_uri;
 	iface->get_ui_manager = nautilus_window_get_ui_manager;
 	iface->get_selection_count = nautilus_window_get_selection_count;
@@ -1957,6 +1955,7 @@ nautilus_window_class_init (NautilusWindowClass *class)
 
 	G_OBJECT_CLASS (class)->finalize = nautilus_window_finalize;
 	G_OBJECT_CLASS (class)->constructor = nautilus_window_constructor;
+	G_OBJECT_CLASS (class)->constructed = nautilus_window_constructed;
 	G_OBJECT_CLASS (class)->get_property = nautilus_window_get_property;
 	G_OBJECT_CLASS (class)->set_property = nautilus_window_set_property;
 	GTK_OBJECT_CLASS (class)->destroy = nautilus_window_destroy;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]