[Nautilus-list] Simple optimization



Currently every nautilus view implementation that runs as external program
quits immediately after destroying the last object it provides. It slows
things down, for example, if we're previewing many text files in a row.
The attached (simple) patch causes the process to wait for some time before
quitting.

There's no changelog entry yet, because the patch is not ready - timeout
value should be read from configuration or set individually for every
component (in this case we'd need to add an extra argument to
nautilus_view_standard_main_multi).
I'd like to know your opinion before going further.

BTW, why doesn't image view use nautilus_view_standard_main? Does it need
anything special?


Zbigniew
--- /home/cyba/gcvs/nautilus/libnautilus/nautilus-view-standard-main.c	Thu Apr 26 12:24:03 2001
+++ nautilus/libnautilus/nautilus-view-standard-main.c	Mon Jul  2 20:47:33 2001
@@ -41,13 +41,25 @@
 #include <liboaf/liboaf.h>
 #include <stdlib.h>
 
+#define N_IDLE_SECONDS_BEFORE_QUIT  5
+
 typedef struct {
 	int                          object_count;
 	GList                       *view_iids;
 	NautilusViewCreateFunction   create_function;
 	void                        *user_data;
+	guint                        timeout_id;
 } CallbackData;
 
+static gboolean
+timeout_callback (gpointer data)
+{
+	CallbackData *callback_data = data;
+
+	callback_data->timeout_id = 0;
+	gtk_main_quit ();
+	return FALSE;
+}
 
 static void
 object_destroyed (GtkObject     *object,
@@ -56,8 +68,9 @@ object_destroyed (GtkObject     *object,
 	g_assert (GTK_IS_OBJECT (object));
 
 	callback_data->object_count--;
-	if (callback_data->object_count <= 0) {
-		gtk_main_quit ();
+	if (callback_data->object_count <= 0 && callback_data->timeout_id == 0) {
+		callback_data->timeout_id = g_timeout_add (N_IDLE_SECONDS_BEFORE_QUIT * 1000,
+		                                           timeout_callback, callback_data);
 	}
 }
 
@@ -90,6 +103,10 @@ make_object (BonoboGenericFactory *facto
          * when there are no more objects outstanding.
 	 */
 	callback_data->object_count++;
+	if (callback_data->timeout_id != 0) {
+		g_source_remove (callback_data->timeout_id);
+		callback_data->timeout_id = 0;
+	}
 	gtk_signal_connect (GTK_OBJECT (view), "destroy",
 			    object_destroyed, callback_data);
 
@@ -188,6 +205,7 @@ nautilus_view_standard_main_multi (const
 	callback_data.view_iids = view_iids;
 	callback_data.create_function = create_function;
 	callback_data.user_data = user_data;
+	callback_data.timeout_id = 0;
 
 	/* Create the factory. */
         registration_id = oaf_make_registration_id (factory_iid, g_getenv ("DISPLAY"));
@@ -199,7 +217,7 @@ nautilus_view_standard_main_multi (const
 	/* Loop until we have no more objects. */
 	do {
 		bonobo_main ();
-	} while (callback_data.object_count > 0);
+	} while (callback_data.object_count > 0 || callback_data.timeout_id != 0);
 
 	/* Let the factory go. */
 	bonobo_object_unref (BONOBO_OBJECT (factory));


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