[nautilus] slot: consolidate code for showing/hiding the loading floating bar



commit 0b22ba642ceb38593eeae781fdc83d534967bd50
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Sep 18 23:48:31 2012 -0400

    slot: consolidate code for showing/hiding the loading floating bar
    
    Move all the code relative to it in NautilusWindowSlot, and make the
    relative object members private.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684218

 src/nautilus-window-manage-views.c |   72 ------------------
 src/nautilus-window-slot.c         |  142 ++++++++++++++++++++++++++++--------
 src/nautilus-window-slot.h         |    6 --
 3 files changed, 110 insertions(+), 110 deletions(-)
---
diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c
index 407a27e..90d67fc 100644
--- a/src/nautilus-window-manage-views.c
+++ b/src/nautilus-window-manage-views.c
@@ -30,7 +30,6 @@
 
 #include "nautilus-actions.h"
 #include "nautilus-application.h"
-#include "nautilus-floating-bar.h"
 #include "nautilus-pathbar.h"
 #include "nautilus-window-private.h"
 #include "nautilus-window-slot.h"
@@ -1181,62 +1180,6 @@ nautilus_window_report_location_change (NautilusWindow *window)
 	}
 }
 
-static void
-real_setup_loading_floating_bar (NautilusWindowSlot *slot)
-{
-	gboolean disable_chrome;
-
-	g_object_get (nautilus_window_slot_get_window (slot),
-		      "disable-chrome", &disable_chrome,
-		      NULL);
-
-	if (disable_chrome) {
-		gtk_widget_hide (slot->floating_bar);
-		return;
-	}
-
-	nautilus_floating_bar_set_primary_label (NAUTILUS_FLOATING_BAR (slot->floating_bar),
-						 NAUTILUS_IS_SEARCH_DIRECTORY (nautilus_view_get_model (slot->content_view)) ?
-						 _("Searching...") : _("Loading..."));
-	nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (slot->floating_bar),
-						TRUE);
-	nautilus_floating_bar_add_action (NAUTILUS_FLOATING_BAR (slot->floating_bar),
-					  GTK_STOCK_STOP,
-					  NAUTILUS_FLOATING_BAR_ACTION_ID_STOP);
-
-	gtk_widget_set_halign (slot->floating_bar, GTK_ALIGN_END);
-	gtk_widget_show (slot->floating_bar);
-}
-
-static gboolean
-setup_loading_floating_bar_timeout_cb (gpointer user_data)
-{
-	NautilusWindowSlot *slot = user_data;
-
-	slot->loading_timeout_id = 0;
-	real_setup_loading_floating_bar (slot);
-
-	return FALSE;
-}
-
-static void
-setup_loading_floating_bar (NautilusWindowSlot *slot)
-{
-	/* setup loading overlay */
-	if (slot->set_status_timeout_id != 0) {
-		g_source_remove (slot->set_status_timeout_id);
-		slot->set_status_timeout_id = 0;
-	}
-
-	if (slot->loading_timeout_id != 0) {
-		g_source_remove (slot->loading_timeout_id);
-		slot->loading_timeout_id = 0;
-	}
-
-	slot->loading_timeout_id =
-		g_timeout_add (500, setup_loading_floating_bar_timeout_cb, slot);
-}
-
 /* This is called when we have decided we can actually change to the new view/location situation. */
 static void
 location_has_really_changed (NautilusWindowSlot *slot)
@@ -1276,8 +1219,6 @@ location_has_really_changed (NautilusWindowSlot *slot)
 
 		g_object_unref (location_copy);
 	}
-
-	setup_loading_floating_bar (slot);
 }
 
 static void
@@ -1543,18 +1484,6 @@ nautilus_window_report_load_complete (NautilusWindow *window,
 }
 
 static void
-remove_loading_floating_bar (NautilusWindowSlot *slot)
-{
-	if (slot->loading_timeout_id != 0) {
-		g_source_remove (slot->loading_timeout_id);
-		slot->loading_timeout_id = 0;
-	}
-
-	gtk_widget_hide (slot->floating_bar);
-	nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (slot->floating_bar));
-}
-
-static void
 end_location_change (NautilusWindowSlot *slot)
 {
 	char *uri;
@@ -1566,7 +1495,6 @@ end_location_change (NautilusWindowSlot *slot)
 	}
 
 	nautilus_window_slot_set_allow_stop (slot, FALSE);
-	remove_loading_floating_bar (slot);
 
         /* Now we can free pending_scroll_to, since the load_complete
          * callback already has been emitted.
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 0ed23bd..bdf3a3e 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -57,6 +57,12 @@ enum {
 
 struct NautilusWindowSlotDetails {
 	NautilusWindow *window;
+
+	/* floating bar */
+	guint set_status_timeout_id;
+	guint loading_timeout_id;
+	GtkWidget *floating_bar;
+	GtkWidget *view_overlay;
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -346,20 +352,20 @@ nautilus_window_slot_constructed (GObject *object)
 	g_object_add_weak_pointer (G_OBJECT (slot->query_editor),
 				   (gpointer *) &slot->query_editor);
 
-	slot->view_overlay = gtk_overlay_new ();
-	gtk_widget_add_events (slot->view_overlay,
+	slot->details->view_overlay = gtk_overlay_new ();
+	gtk_widget_add_events (slot->details->view_overlay,
 			       GDK_ENTER_NOTIFY_MASK |
 			       GDK_LEAVE_NOTIFY_MASK);
-	gtk_box_pack_start (GTK_BOX (slot), slot->view_overlay, TRUE, TRUE, 0);
-	gtk_widget_show (slot->view_overlay);
+	gtk_box_pack_start (GTK_BOX (slot), slot->details->view_overlay, TRUE, TRUE, 0);
+	gtk_widget_show (slot->details->view_overlay);
 
-	slot->floating_bar = nautilus_floating_bar_new (NULL, NULL, FALSE);
-	gtk_widget_set_halign (slot->floating_bar, GTK_ALIGN_END);
-	gtk_widget_set_valign (slot->floating_bar, GTK_ALIGN_END);
-	gtk_overlay_add_overlay (GTK_OVERLAY (slot->view_overlay),
-				 slot->floating_bar);
+	slot->details->floating_bar = nautilus_floating_bar_new (NULL, NULL, FALSE);
+	gtk_widget_set_halign (slot->details->floating_bar, GTK_ALIGN_END);
+	gtk_widget_set_valign (slot->details->floating_bar, GTK_ALIGN_END);
+	gtk_overlay_add_overlay (GTK_OVERLAY (slot->details->view_overlay),
+				 slot->details->floating_bar);
 
-	g_signal_connect (slot->floating_bar, "action",
+	g_signal_connect (slot->details->floating_bar, "action",
 			  G_CALLBACK (floating_bar_action_cb), slot);
 
 	slot->title = g_strdup (_("Loading..."));
@@ -373,6 +379,18 @@ nautilus_window_slot_init (NautilusWindowSlot *slot)
 }
 
 static void
+remove_loading_floating_bar (NautilusWindowSlot *slot)
+{
+	if (slot->details->loading_timeout_id != 0) {
+		g_source_remove (slot->details->loading_timeout_id);
+		slot->details->loading_timeout_id = 0;
+	}
+
+	gtk_widget_hide (slot->details->floating_bar);
+	nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (slot->details->floating_bar));
+}
+
+static void
 view_end_loading_cb (NautilusView       *view,
 		     gboolean            all_files_seen,
 		     NautilusWindowSlot *slot)
@@ -382,13 +400,71 @@ view_end_loading_cb (NautilusView       *view,
 		slot->needs_reload = FALSE;
 	}
 
-	if (slot->loading_timeout_id != 0) {
-		g_source_remove (slot->loading_timeout_id);
-		slot->loading_timeout_id = 0;
+	remove_loading_floating_bar (slot);
+}
+
+
+static void
+real_setup_loading_floating_bar (NautilusWindowSlot *slot)
+{
+	gboolean disable_chrome;
+
+	g_object_get (nautilus_window_slot_get_window (slot),
+		      "disable-chrome", &disable_chrome,
+		      NULL);
+
+	if (disable_chrome) {
+		gtk_widget_hide (slot->details->floating_bar);
+		return;
 	}
 
-	gtk_widget_hide (slot->floating_bar);
-	nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (slot->floating_bar));
+	nautilus_floating_bar_set_primary_label (NAUTILUS_FLOATING_BAR (slot->details->floating_bar),
+						 NAUTILUS_IS_SEARCH_DIRECTORY (nautilus_view_get_model (slot->content_view)) ?
+						 _("Searching...") : _("Loading..."));
+	nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (slot->details->floating_bar),
+						TRUE);
+	nautilus_floating_bar_add_action (NAUTILUS_FLOATING_BAR (slot->details->floating_bar),
+					  GTK_STOCK_STOP,
+					  NAUTILUS_FLOATING_BAR_ACTION_ID_STOP);
+
+	gtk_widget_set_halign (slot->details->floating_bar, GTK_ALIGN_END);
+	gtk_widget_show (slot->details->floating_bar);
+}
+
+static gboolean
+setup_loading_floating_bar_timeout_cb (gpointer user_data)
+{
+	NautilusWindowSlot *slot = user_data;
+
+	slot->details->loading_timeout_id = 0;
+	real_setup_loading_floating_bar (slot);
+
+	return FALSE;
+}
+
+static void
+setup_loading_floating_bar (NautilusWindowSlot *slot)
+{
+	/* setup loading overlay */
+	if (slot->details->set_status_timeout_id != 0) {
+		g_source_remove (slot->details->set_status_timeout_id);
+		slot->details->set_status_timeout_id = 0;
+	}
+
+	if (slot->details->loading_timeout_id != 0) {
+		g_source_remove (slot->details->loading_timeout_id);
+		slot->details->loading_timeout_id = 0;
+	}
+
+	slot->details->loading_timeout_id =
+		g_timeout_add (500, setup_loading_floating_bar_timeout_cb, slot);
+}
+
+static void
+view_begin_loading_cb (NautilusView       *view,
+		       NautilusWindowSlot *slot)
+{
+	setup_loading_floating_bar (slot);
 }
 
 static void
@@ -416,14 +492,14 @@ nautilus_window_slot_dispose (GObject *object)
 		slot->new_content_view = NULL;
 	}
 
-	if (slot->set_status_timeout_id != 0) {
-		g_source_remove (slot->set_status_timeout_id);
-		slot->set_status_timeout_id = 0;
+	if (slot->details->set_status_timeout_id != 0) {
+		g_source_remove (slot->details->set_status_timeout_id);
+		slot->details->set_status_timeout_id = 0;
 	}
 
-	if (slot->loading_timeout_id != 0) {
-		g_source_remove (slot->loading_timeout_id);
-		slot->loading_timeout_id = 0;
+	if (slot->details->loading_timeout_id != 0) {
+		g_source_remove (slot->details->loading_timeout_id);
+		slot->details->loading_timeout_id = 0;
 	}
 
 	nautilus_window_slot_set_viewed_file (slot, NULL);
@@ -601,6 +677,7 @@ nautilus_window_slot_set_content_view_widget (NautilusWindowSlot *slot,
 	if (slot->content_view != NULL) {
 		/* disconnect old view */
 		g_signal_handlers_disconnect_by_func (slot->content_view, G_CALLBACK (view_end_loading_cb), slot);
+		g_signal_handlers_disconnect_by_func (slot->content_view, G_CALLBACK (view_begin_loading_cb), slot);
 
 		nautilus_window_disconnect_content_view (window, slot->content_view);
 
@@ -612,12 +689,13 @@ nautilus_window_slot_set_content_view_widget (NautilusWindowSlot *slot,
 
 	if (new_view != NULL) {
 		widget = GTK_WIDGET (new_view);
-		gtk_container_add (GTK_CONTAINER (slot->view_overlay), widget);
+		gtk_container_add (GTK_CONTAINER (slot->details->view_overlay), widget);
 		gtk_widget_show (widget);
 
 		slot->content_view = new_view;
 		g_object_ref (slot->content_view);
 
+		g_signal_connect (new_view, "begin_loading", G_CALLBACK (view_begin_loading_cb), slot);
 		g_signal_connect (new_view, "end_loading", G_CALLBACK (view_end_loading_cb), slot);
 
 		/* connect new view */
@@ -646,8 +724,8 @@ real_slot_set_short_status (NautilusWindowSlot *slot,
 {
 	gboolean disable_chrome;
 
-	nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (slot->floating_bar));
-	nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (slot->floating_bar),
+	nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (slot->details->floating_bar));
+	nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (slot->details->floating_bar),
 						FALSE);
 
 	g_object_get (nautilus_window_slot_get_window (slot),
@@ -655,13 +733,13 @@ real_slot_set_short_status (NautilusWindowSlot *slot,
 		      NULL);
 
 	if ((primary_status == NULL && detail_status == NULL) || disable_chrome) {
-		gtk_widget_hide (slot->floating_bar);
+		gtk_widget_hide (slot->details->floating_bar);
 		return;
 	}
 
-	nautilus_floating_bar_set_labels (NAUTILUS_FLOATING_BAR (slot->floating_bar),
+	nautilus_floating_bar_set_labels (NAUTILUS_FLOATING_BAR (slot->details->floating_bar),
 					  primary_status, detail_status);
-	gtk_widget_show (slot->floating_bar);
+	gtk_widget_show (slot->details->floating_bar);
 }
 
 typedef struct {
@@ -686,7 +764,7 @@ set_status_timeout_cb (gpointer data)
 {
 	SetStatusData *status_data = data;
 
-	status_data->slot->set_status_timeout_id = 0;
+	status_data->slot->details->set_status_timeout_id = 0;
 	real_slot_set_short_status (status_data->slot,
 				    status_data->primary_status,
 				    status_data->detail_status);
@@ -703,9 +781,9 @@ set_floating_bar_status (NautilusWindowSlot *slot,
 	gint double_click_time;
 	SetStatusData *status_data;
 
-	if (slot->set_status_timeout_id != 0) {
-		g_source_remove (slot->set_status_timeout_id);
-		slot->set_status_timeout_id = 0;
+	if (slot->details->set_status_timeout_id != 0) {
+		g_source_remove (slot->details->set_status_timeout_id);
+		slot->details->set_status_timeout_id = 0;
 	}
 
 	settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (slot->content_view)));
@@ -722,7 +800,7 @@ set_floating_bar_status (NautilusWindowSlot *slot,
 	 * the status seems to be a good approximation of not setting it
 	 * too often and not delaying the statusbar too much.
 	 */
-	slot->set_status_timeout_id =
+	slot->details->set_status_timeout_id =
 		g_timeout_add_full (G_PRIORITY_DEFAULT,
 				    (guint) (double_click_time / 2),
 				    set_status_timeout_cb,
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index f4a7e90..cd9c4ea 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -67,12 +67,6 @@ struct NautilusWindowSlot {
  	 */
 	GtkWidget *extra_location_widgets;
 
-	GtkWidget *view_overlay;
-	GtkWidget *floating_bar;
-
-	guint set_status_timeout_id;
-	guint loading_timeout_id;
-
 	NautilusView *content_view;
 	NautilusView *new_content_view;
 



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