Re: PATCH: use timeouts for progress dialogs



Hi Dave,

> And I meant to ask earlier, but forgot:  did you test the performance
> boost of just delaying mapping/realizing vs. delaying creation?

Indeed it turns out that this doesn't cause a noticeable performance
boost. The main delay seems to be caused by drawing the dialog on screen
and also because the dialog stays visible for a minimum amount of time.

Another performance problem is copying vs. moving files. Copying a small
file is noticably faster than moving it. That's because when you move it
the IconContainer lays out all the icons once the icon is removed from
the folder. This happens even when I move the icon in the bottom right
corner of the folder. In that case no re-layout is needed but the
IconContainer does it anyway. It might be worthwhile to try and optimize
the layout code some more.

Even if there is no relayout when you view a folder in manual layout,
moving a file still seems to take longer. I'm not sure if that's just me
or if there really is a delay even in that case...

Anyway, a new patch is attached. Removing the realize handler makes it a
bit simpler.

- Frank


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5466
diff -u -p -r1.5466 ChangeLog
--- ChangeLog	31 Jul 2002 20:16:31 -0000	1.5466
+++ ChangeLog	1 Aug 2002 06:08:51 -0000
@@ -1,3 +1,24 @@
+2002-07-31  Frank Worsley  <fworsley shaw ca>
+
+	* libnautilus-private/nautilus-file-operations-progress.h:
+	* libnautilus-private/nautilus-file-operations-progress.c:
+	(nautilus_file_operations_progress_update),
+	(nautilus_file_operations_progress_destroy), (map_callback),
+	(nautilus_file_operations_progress_init), (delayed_show_callback),
+	(nautilus_file_operations_progress_new),
+	(nautilus_file_operations_progress_new_file),
+	(nautilus_file_operations_progress_done),
+	(nautilus_file_operations_progress_pause_timeout),
+	(nautilus_file_operations_progress_resume_timeout):
+	use a timeout for displaying the progress dialog
+
+	* libnautilus-private/nautilus-file-operations.c:
+	(create_transfer_dialog), (handle_transfer_vfs_error),
+	(handle_transfer_overwrite), (nautilus_file_operations_copy_move),
+	(nautilus_file_operations_delete), (do_empty_trash):
+	use a timeout and also suspend the timeout while waiting
+	for user response
+
 2002-07-31  Dave Camp  <dave ximian com>
 
 	* libnautilus-private/nautilus-icon-container.c:
Index: libnautilus-private/nautilus-file-operations.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.c,v
retrieving revision 1.153
diff -u -p -r1.153 nautilus-file-operations.c
--- libnautilus-private/nautilus-file-operations.c	12 Jul 2002 18:36:13 -0000	1.153
+++ libnautilus-private/nautilus-file-operations.c	1 Aug 2002 06:08:52 -0000
@@ -73,7 +73,6 @@ typedef struct {
 	GnomeVFSXferOverwriteMode overwrite_mode;
 	GtkWidget *parent_view;
 	TransferKind kind;
-	gboolean show_progress_dialog;
 	void (* done_callback) (GHashTable *debuting_uris, gpointer data);
 	gpointer done_callback_data;
 	GHashTable *debuting_uris;
@@ -280,14 +279,10 @@ static void
 create_transfer_dialog (const GnomeVFSXferProgressInfo *progress_info,
 			TransferInfo *transfer_info)
 {
-	if (!transfer_info->show_progress_dialog) {
-		return;
-	}
-
 	g_return_if_fail (transfer_info->progress_dialog == NULL);
 
 	transfer_info->progress_dialog = nautilus_file_operations_progress_new 
-		(transfer_info->operation_title, "", "", "", 0, 0);
+		(transfer_info->operation_title, "", "", "", 0, 0, TRUE);
 
 	/* Treat clicking on the close box or use of the escape key
 	 * the same as clicking cancel.
@@ -307,8 +302,6 @@ create_transfer_dialog (const GnomeVFSXf
 			GTK_WINDOW (transfer_info->progress_dialog), 
 			GTK_WINDOW (gtk_widget_get_toplevel (transfer_info->parent_view)));
 	}
-
-	gtk_widget_show (GTK_WIDGET (transfer_info->progress_dialog));
 }
 
 static void
@@ -800,6 +793,9 @@ handle_transfer_vfs_error (const GnomeVF
 
 		/* transfer error, prompt the user to continue or stop */
 
+		/* stop timeout while waiting for user */
+		nautilus_file_operations_progress_pause_timeout (transfer_info->progress_dialog);
+
 		formatted_source_name = NULL;
 		formatted_target_name = NULL;
 
@@ -958,6 +954,8 @@ handle_transfer_vfs_error (const GnomeVF
 		g_free (formatted_source_name);
 		g_free (formatted_target_name);
 
+		nautilus_file_operations_progress_resume_timeout (transfer_info->progress_dialog);
+
 		return error_dialog_result;
 
 	case GNOME_VFS_XFER_ERROR_MODE_ABORT:
@@ -999,6 +997,8 @@ handle_transfer_overwrite (const GnomeVF
 	int result;
 	char *text, *formatted_name;
 
+	nautilus_file_operations_progress_pause_timeout (transfer_info->progress_dialog);	
+
 	/* Handle special case files such as Trash, mount links and home directory */	
 	if (is_special_link (progress_info->target_name)) {
 		formatted_name = extract_and_ellipsize_file_name_for_dialog
@@ -1025,6 +1025,8 @@ handle_transfer_overwrite (const GnomeVF
 		g_free (text);
 		g_free (formatted_name);
 
+		nautilus_file_operations_progress_resume_timeout (transfer_info->progress_dialog);
+
 		return GNOME_VFS_XFER_OVERWRITE_ACTION_SKIP;
 	}
 	
@@ -1044,6 +1046,9 @@ handle_transfer_overwrite (const GnomeVF
 			(parent_for_error_dialog (transfer_info), TRUE, text, 
 			 _("Conflict while copying"),
 			 _("Replace"), _("Skip"), NULL);
+			 
+		nautilus_file_operations_progress_resume_timeout (transfer_info->progress_dialog);
+					 
 		switch (result) {
 		case 0:
 			return GNOME_VFS_XFER_OVERWRITE_ACTION_REPLACE;
@@ -1059,6 +1064,8 @@ handle_transfer_overwrite (const GnomeVF
 			 _("Conflict while copying"),
 			 _("Replace All"), _("Replace"), _("Skip"), NULL);
 
+		nautilus_file_operations_progress_resume_timeout (transfer_info->progress_dialog);
+
 		switch (result) {
 		case 0:
 			return GNOME_VFS_XFER_OVERWRITE_ACTION_REPLACE_ALL;
@@ -1688,7 +1695,6 @@ nautilus_file_operations_copy_move (cons
 	gboolean target_is_trash;
 	gboolean is_desktop_trash_link;
 	gboolean duplicate;
-	gboolean all_local;
 	
 	IconPositionIterator *icon_position_iterator;
 
@@ -1712,7 +1718,6 @@ nautilus_file_operations_copy_move (cons
 	 */
 	source_uri_list = NULL;
 	target_uri_list = NULL;
-	all_local = TRUE;
 	duplicate = copy_action != GDK_ACTION_MOVE;
 	for (p = item_uris; p != NULL; p = p->next) {
 		/* Filter out special Nautilus link files */
@@ -1750,11 +1755,6 @@ nautilus_file_operations_copy_move (cons
 			target_uri_list = g_list_prepend (target_uri_list, target_uri);
 			source_uri_list = g_list_prepend (source_uri_list, source_uri);
 
-			if (all_local && (!gnome_vfs_uri_is_local (source_uri)
-					  || !gnome_vfs_uri_is_local (target_uri))) {
-				all_local = FALSE;
-			}
-
 			if (duplicate
 			    && !gnome_vfs_uri_equal (source_dir_uri, target_dir_uri)) {
 				duplicate = FALSE;
@@ -1823,11 +1823,6 @@ nautilus_file_operations_copy_move (cons
 
 		transfer_info->kind = TRANSFER_MOVE_TO_TRASH;
 
-		/* Do an arbitrary guess that an operation will take very little
-		 * time and the progress shouldn't be shown.
-		 */
-		transfer_info->show_progress_dialog = 
-			!all_local || g_list_length ((GList *) item_uris) > 20;
 	} else if ((move_options & GNOME_VFS_XFER_REMOVESOURCE) != 0) {
 		/* localizers: progress dialog title */
 		transfer_info->operation_title = _("Moving files");
@@ -1840,11 +1835,6 @@ nautilus_file_operations_copy_move (cons
 
 		transfer_info->kind = TRANSFER_MOVE;
 
-		/* Do an arbitrary guess that an operation will take very little
-		 * time and the progress shouldn't be shown.
-		 */
-		transfer_info->show_progress_dialog = 
-			!all_local || g_list_length ((GList *) item_uris) > 20;
 	} else if ((move_options & GNOME_VFS_XFER_LINK_ITEMS) != 0) {
 		/* when creating links, handle name conflicts automatically */
 		move_options |= GNOME_VFS_XFER_USE_UNIQUE_NAMES;
@@ -1858,8 +1848,7 @@ nautilus_file_operations_copy_move (cons
 		transfer_info->cleanup_name = _("Finishing Creating Links...");
 
 		transfer_info->kind = TRANSFER_LINK;
-		transfer_info->show_progress_dialog =
-			g_list_length ((GList *)item_uris) > 20;
+
 	} else {
 		/* localizers: progress dialog title */
 		transfer_info->operation_title = _("Copying files");
@@ -1871,8 +1860,6 @@ nautilus_file_operations_copy_move (cons
 		transfer_info->cleanup_name = "";
 
 		transfer_info->kind = TRANSFER_COPY;
-		/* always show progress during copy */
-		transfer_info->show_progress_dialog = TRUE;
 	}
 
 	/* we'll need to check for copy into Trash and for moving/copying the Trash itself */
@@ -2140,7 +2127,6 @@ nautilus_file_operations_delete (const G
 	uri_list = g_list_reverse (uri_list);
 
 	transfer_info = transfer_info_new (parent_view);
-	transfer_info->show_progress_dialog = TRUE;
 
 	/* localizers: progress dialog title */
 	transfer_info->operation_title = _("Deleting files");
@@ -2176,7 +2162,6 @@ do_empty_trash (GtkWidget *parent_view)
 	if (trash_dir_list != NULL) {
 		/* set up the move parameters */
 		transfer_info = transfer_info_new (parent_view);
-		transfer_info->show_progress_dialog = TRUE;
 
 		/* localizers: progress dialog title */
 		transfer_info->operation_title = _("Emptying the Trash");
Index: libnautilus-private/nautilus-file-operations-progress.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations-progress.c,v
retrieving revision 1.36
diff -u -p -r1.36 nautilus-file-operations-progress.c
--- libnautilus-private/nautilus-file-operations-progress.c	17 Apr 2002 12:29:10 -0000	1.36
+++ libnautilus-private/nautilus-file-operations-progress.c	1 Aug 2002 06:08:52 -0000
@@ -55,6 +55,8 @@
 
 #define MINIMUM_TIME_UP    1000
 
+#define SHOW_TIMEOUT	   1200
+
 static GdkPixbuf *empty_jar_pixbuf, *full_jar_pixbuf;
 
 static void nautilus_file_operations_progress_class_init (NautilusFileOperationsProgressClass *klass);
@@ -83,10 +85,17 @@ struct NautilusFileOperationsProgressDet
 	gulong files_total;
 	gulong bytes_total;
 
-	/* system time (microseconds) when dialog was mapped */
+	/* system time (microseconds) when dialog was created */
 	gint64 start_time;
 
+	/* system time (microseconds) when dialog was mapped */
+	gint64 show_time;
+	
+	/* time remaining in show timeout if it's paused and resumed */
+	guint remaining_time;
+
 	guint delayed_close_timeout_id;
+	guint delayed_show_timeout_id;
 
 	int progress_jar_position;
 };
@@ -124,7 +133,7 @@ static void
 nautilus_file_operations_progress_update (NautilusFileOperationsProgress *progress)
 {
 	double fraction;
-	
+
 	if (progress->details->bytes_total == 0) {
 		/* We haven't set up the file count yet, do not update
 		 * the progress bar until we do.
@@ -191,6 +200,11 @@ nautilus_file_operations_progress_destro
 		progress->details->delayed_close_timeout_id = 0;
 	}
 	
+	if (progress->details->delayed_show_timeout_id != 0) {
+		g_source_remove (progress->details->delayed_show_timeout_id);
+		progress->details->delayed_show_timeout_id = 0;
+	}
+	
 	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
 }
 
@@ -228,7 +242,7 @@ map_callback (GtkWidget *widget)
 
 	EEL_CALL_PARENT (GTK_WIDGET_CLASS, map, (widget));
 
-	progress->details->start_time = eel_get_system_time ();
+	progress->details->show_time = eel_get_system_time ();
 }
 
 static gboolean
@@ -249,6 +263,8 @@ nautilus_file_operations_progress_init (
 
 	progress->details = g_new0 (NautilusFileOperationsProgressDetails, 1);
 
+	progress->details->start_time = eel_get_system_time ();
+	
 	vbox = gtk_vbox_new (FALSE, VERTICAL_SPACING);
 	gtk_container_set_border_width (GTK_CONTAINER (vbox), OUTER_BORDER);
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (progress)->vbox), vbox, TRUE, TRUE, VERTICAL_SPACING);
@@ -335,13 +351,28 @@ nautilus_file_operations_progress_class_
 	
 }
 
+static gboolean
+delayed_show_callback (gpointer callback_data)
+{
+	NautilusFileOperationsProgress *progress;
+	
+	progress = NAUTILUS_FILE_OPERATIONS_PROGRESS (callback_data);
+	
+	progress->details->delayed_show_timeout_id = 0;
+	
+	gtk_widget_show (GTK_WIDGET (progress));
+	
+	return FALSE;
+}
+
 NautilusFileOperationsProgress *
 nautilus_file_operations_progress_new (const char *title,
 				       const char *operation_string,
 				       const char *from_prefix,
 				       const char *to_prefix,
 				       gulong total_files,
-				       gulong total_bytes)
+				       gulong total_bytes,
+				       gboolean use_timeout)
 {
 	GtkWidget *widget;
 	NautilusFileOperationsProgress *progress;
@@ -359,6 +390,11 @@ nautilus_file_operations_progress_new (c
 
 	progress->details->from_prefix = from_prefix;
 	progress->details->to_prefix = to_prefix;
+
+	if (use_timeout) {
+		progress->details->delayed_show_timeout_id =
+			g_timeout_add (SHOW_TIMEOUT, delayed_show_callback, progress);
+	}
 	
 	return progress;
 }
@@ -400,7 +436,10 @@ nautilus_file_operations_progress_new_fi
 	char *progress_count;
 
 	g_return_if_fail (NAUTILUS_IS_FILE_OPERATIONS_PROGRESS (progress));
-	g_return_if_fail (GTK_WIDGET_REALIZED (progress));
+
+	if (!GTK_WIDGET_REALIZED (progress)) {
+		return;
+	}
 
 	progress->details->from_prefix = from_prefix;
 	progress->details->to_prefix = to_prefix;
@@ -485,7 +524,7 @@ nautilus_file_operations_progress_done (
 	g_assert (progress->details->start_time != 0);
 
 	/* compute time up in milliseconds */
-	time_up = (eel_get_system_time () - progress->details->start_time) / 1000;
+	time_up = (eel_get_system_time () - progress->details->show_time) / 1000;
 	if (time_up >= MINIMUM_TIME_UP) {
 		gtk_object_destroy (GTK_OBJECT (progress));
 		return;
@@ -498,4 +537,45 @@ nautilus_file_operations_progress_done (
 		(MINIMUM_TIME_UP - time_up,
 		 delayed_close_callback,
 		 progress);
+}
+
+void
+nautilus_file_operations_progress_pause_timeout (NautilusFileOperationsProgress *progress)
+{
+	guint time_up;
+
+	if (progress->details->delayed_show_timeout_id == 0) {
+		progress->details->remaining_time = 0;
+		return;
+	}
+	
+	time_up = (eel_get_system_time () - progress->details->start_time) / 1000;
+	
+	if (time_up >= SHOW_TIMEOUT) {
+		progress->details->remaining_time = 0;
+		return;
+	}
+	
+	g_source_remove (progress->details->delayed_show_timeout_id);
+	progress->details->delayed_show_timeout_id = 0;
+	progress->details->remaining_time = SHOW_TIMEOUT - time_up;
+}
+
+void
+nautilus_file_operations_progress_resume_timeout (NautilusFileOperationsProgress *progress)
+{
+	if (progress->details->delayed_show_timeout_id != 0) {
+		return;
+	}
+	
+	if (progress->details->remaining_time <= 0) {
+		return;
+	}
+	
+	progress->details->delayed_show_timeout_id =
+		g_timeout_add (progress->details->remaining_time,
+			       delayed_show_callback,
+			       progress);
+			       
+	progress->details->remaining_time = 0;		       
 }
Index: libnautilus-private/nautilus-file-operations-progress.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations-progress.h,v
retrieving revision 1.10
diff -u -p -r1.10 nautilus-file-operations-progress.h
--- libnautilus-private/nautilus-file-operations-progress.h	27 Nov 2001 01:46:16 -0000	1.10
+++ libnautilus-private/nautilus-file-operations-progress.h	1 Aug 2002 06:08:52 -0000
@@ -55,7 +55,8 @@ NautilusFileOperationsProgress *nautilus
 											const char                     *from_prefix,
 											const char                     *to_prefix,
 											gulong                          files_total,
-											gulong                          bytes_total);
+											gulong                          bytes_total,
+											gboolean			use_timeout);
 void                            nautilus_file_operations_progress_done                 (NautilusFileOperationsProgress *dialog);
 void                            nautilus_file_operations_progress_set_progress_title   (NautilusFileOperationsProgress *dialog,
 											const char                     *progress_title);
@@ -77,5 +78,7 @@ void                            nautilus
 void                            nautilus_file_operations_progress_update_sizes         (NautilusFileOperationsProgress *dialog,
 											gulong                          bytes_done_in_file,
 											gulong                          bytes_done);
+void				nautilus_file_operations_progress_pause_timeout	       (NautilusFileOperationsProgress *progress);
+void				nautilus_file_operations_progress_resume_timeout       (NautilusFileOperationsProgress *progress);
 
 #endif /* NAUTILUS_FILE_OPERATIONS_PROGRESS_H */


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