lame view cache hack



Hi,

So I wrote the following ugly hack which keeps a most recently used list
of views around and tries to reuse them when loading a new location. 
Views are destroyed after 4 minutes of inactivity.  

This has two effects, first, browsing around is pretty speedy (though a
little flickery), and secondly, the view remains scrolled to the correct
location between location changes.

There are some bugs, but I wanted to see if this would be considered raw
crack-smokery before I spend any more time on it :)

-Alex

-- 
 on the canvass of life, incompetence is my paintbrush.

? src/nautilus-sidebar.c.flc
? src/nautilus-window.c.flc
Index: src/nautilus-view-frame.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-view-frame.c,v
retrieving revision 1.159
diff -u -r1.159 nautilus-view-frame.c
--- src/nautilus-view-frame.c	26 Apr 2002 19:45:21 -0000	1.159
+++ src/nautilus-view-frame.c	25 Aug 2002 08:44:27 -0000
@@ -89,6 +89,7 @@
 	char *title;
 	char *label;
         char *view_iid;
+        char *location;
 
         /* The view frame Bonobo objects. */
         BonoboObject *view_frame;
@@ -137,11 +138,13 @@
 		return;
 	}
 
-	nautilus_idle_queue_add (view->details->idle_queue,
-				 (GFunc) call,
-				 view,
-				 callback_data,
-				 destroy_callback_data);
+	if (view->details->idle_queue != NULL) {
+		nautilus_idle_queue_add (view->details->idle_queue,
+					 (GFunc) call,
+					 view,
+					 callback_data,
+					 destroy_callback_data);
+	}
 }
 
 static void
@@ -182,6 +185,9 @@
 	g_free (view->details->view_iid);
 	view->details->view_iid = NULL;
 
+	g_free (view->details->location);
+	view->details->location = NULL;
+
 	CORBA_Object_release (view->details->view, NULL);
 	view->details->view = CORBA_OBJECT_NIL;
 
@@ -228,7 +234,7 @@
 static void
 nautilus_view_frame_unrealize (GtkWidget *widget)
 {
-	shut_down (NAUTILUS_VIEW_FRAME (widget));
+	stop_activation (NAUTILUS_VIEW_FRAME (widget));
 	EEL_CALL_PARENT (GTK_WIDGET_CLASS, unrealize, (widget));
 }
 
@@ -815,8 +821,14 @@
 	
 	CORBA_exception_init (&ev);
 	Nautilus_View_load_location (view->details->view, location, &ev);
+	g_free (view->details->location);
+
 	if (BONOBO_EX (&ev)) {
 		view_frame_failed (view);
+		view->details->location = NULL;
+	} else {
+		view->details->location = g_strdup (location);
+		g_print ("*** SETTING VIEW LOCATION: %p, %s\n", view, location);
 	}
 	CORBA_exception_free (&ev);
 }
@@ -1060,6 +1072,14 @@
 	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);
 
 	return view->details->view_iid;
+}
+
+const char *
+nautilus_view_frame_get_location (NautilusViewFrame *view)
+{
+	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);
+
+	return view->details->location;
 }
 
 void
Index: src/nautilus-view-frame.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-view-frame.h,v
retrieving revision 1.69
diff -u -r1.69 nautilus-view-frame.h
--- src/nautilus-view-frame.h	26 Apr 2002 19:45:21 -0000	1.69
+++ src/nautilus-view-frame.h	25 Aug 2002 08:44:27 -0000
@@ -131,6 +131,7 @@
 /* Other. */
 gboolean           nautilus_view_frame_get_is_view_loaded        (NautilusViewFrame   *view);
 const char *       nautilus_view_frame_get_view_iid              (NautilusViewFrame   *view);
+const char *       nautilus_view_frame_get_location              (NautilusViewFrame   *view);
 gboolean           nautilus_view_frame_get_is_zoomable           (NautilusViewFrame   *view);
 char *             nautilus_view_frame_get_title                 (NautilusViewFrame   *view);
 char *             nautilus_view_frame_get_label                 (NautilusViewFrame   *view);
Index: src/nautilus-window-manage-views.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-manage-views.c,v
retrieving revision 1.306
diff -u -r1.306 nautilus-window-manage-views.c
--- src/nautilus-window-manage-views.c	24 Jul 2002 16:26:19 -0000	1.306
+++ src/nautilus-window-manage-views.c	25 Aug 2002 08:44:28 -0000
@@ -934,6 +934,8 @@
 {
         const char *iid;
         NautilusViewFrame *view;
+        GList *iter;
+        gboolean reuse_existing = FALSE;
 
  	/* FIXME bugzilla.gnome.org 41243: 
 	 * We should use inheritance instead of these special cases
@@ -964,14 +966,31 @@
 				       FALSE);
         
         bonobo_ui_component_thaw (window->details->shell_ui, NULL);
-        
-        if (nautilus_window_content_view_matches_iid (window, iid)) {
-                /* reuse existing content view */
-                view = window->content_view;
-                window->new_content_view = view;
-        	g_object_ref (view);
-                set_to_pending_location_and_selection (window);
-        } else {
+
+        for (iter = window->recent_views; iter; iter = iter->next) {
+                view = iter->data;
+
+                if (eel_uris_match (window->details->pending_location,
+                                    nautilus_view_frame_get_location (view))) {
+                        g_print ("*** REUSING EXISTING VIEW: %p\n", view);
+
+                        window->new_content_view = view;
+                        g_object_ref (view);
+
+                        connect_view (window, view);
+                        load_new_location_in_all_views (
+                                window,
+                                window->details->pending_location,
+                                window->details->pending_selection,
+                                window->new_content_view);
+                        location_has_really_changed (window);
+                        
+                        reuse_existing = TRUE;
+                        break;
+                }
+        }
+
+        if (!reuse_existing) {
                 /* create a new content view */
                 view = nautilus_view_frame_new (window->details->ui_container,
                                                 window->application->undo_manager);
Index: src/nautilus-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.c,v
retrieving revision 1.393
diff -u -r1.393 nautilus-window.c
--- src/nautilus-window.c	24 Jul 2002 07:45:10 -0000	1.393
+++ src/nautilus-window.c	25 Aug 2002 08:44:28 -0000
@@ -783,6 +783,8 @@
 nautilus_window_destroy (GtkObject *object)
 {
 	NautilusWindow *window;
+	NautilusViewFrame *recent_frame;
+	GList *iter;
 	
 	window = NAUTILUS_WINDOW (object);
 
@@ -802,6 +804,16 @@
 		window->content_view = NULL;
 	}
 
+	for (iter = window->recent_views; iter; iter = iter->next) {
+		recent_frame = iter->data;
+
+		if (recent_frame != window->content_view) {
+			g_object_unref (recent_frame);
+		}
+	}
+	g_list_free (window->recent_views);
+	window->recent_views = NULL;
+
 	if (window->details->tooltips) {
 		g_object_unref (G_OBJECT (window->details->tooltips));
 		window->details->tooltips = NULL;
@@ -1745,10 +1757,49 @@
 	gtk_widget_show (dialog);
 }
 
+static void
+view_on_destroy_callback (gpointer user_data, GObject *dead_object)
+{
+	NautilusWindow *window;
+
+	g_print ("*** VIEW BEING DESTROYED: %p\n", dead_object);
+
+	window = NAUTILUS_WINDOW (user_data);
+	window->recent_views = g_list_remove (window->recent_views, 
+					      dead_object);
+}
+
+static void 
+cancel_view_destroy_callback (gpointer user_data) 
+{
+	guint timeout_id;
+
+	g_print ("*** REMOVING DESTROY TIMEOUT ID: %d\n", (int) user_data);
+
+	timeout_id = GPOINTER_TO_INT (user_data);
+	if (timeout_id) {
+		g_source_remove (timeout_id);
+	}
+}
+
+static gboolean
+kill_view_callback (gpointer user_data)
+{
+	NautilusViewFrame *view;
+
+	g_print ("*** DESTROYING VIEW: %p\n", user_data);
+
+	view = NAUTILUS_VIEW_FRAME (user_data);
+	gtk_object_destroy (GTK_OBJECT (view));
+	return FALSE;
+}
+
 void
 nautilus_window_set_content_view_widget (NautilusWindow *window,
 					 NautilusViewFrame *new_view)
 {
+	guint destroy_timeout;
+
 	g_return_if_fail (NAUTILUS_IS_WINDOW (window));
 	g_return_if_fail (new_view == NULL || NAUTILUS_IS_VIEW_FRAME (new_view));
 	
@@ -1757,7 +1808,25 @@
 	}
 	
 	if (window->content_view != NULL) {
-		gtk_object_destroy (GTK_OBJECT (window->content_view));
+		window->recent_views = g_list_prepend (window->recent_views, 
+						       window->content_view);
+		g_object_ref (window->content_view);
+
+		g_object_weak_ref (G_OBJECT (window->content_view),
+				   view_on_destroy_callback,
+				   window);
+
+		destroy_timeout = g_timeout_add (60 * 4000, 
+						 kill_view_callback, 
+						 window->content_view);
+
+		g_object_set_data_full (G_OBJECT (window->content_view),
+					"destroy-timeout-id",
+					GINT_TO_POINTER (destroy_timeout),
+					cancel_view_destroy_callback);
+
+		gtk_container_remove (GTK_CONTAINER (window->content_hbox),
+				      GTK_WIDGET (window->content_view));
 		window->content_view = NULL;
 	}
 
Index: src/nautilus-window.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.h,v
retrieving revision 1.103
diff -u -r1.103 nautilus-window.h
--- src/nautilus-window.h	18 Jul 2002 05:58:23 -0000	1.103
+++ src/nautilus-window.h	25 Aug 2002 08:44:28 -0000
@@ -103,6 +103,7 @@
         
         /* Current views stuff */
         NautilusViewFrame *content_view;
+        GList *recent_views;
         GList *sidebar_panels;
         
         /* Widgets to keep track of (for state changes, etc) */      


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