Re: [patch] size field for multi window property dialogs



So, another revision of the patch included as an attachment. All the
things you suggested in the review were changed.

Changes:

* Iterating over target_files (instead of original_files) in 
  directory_contents_value_field_update
* We're now saving total_size and total_count in window->details
* Only do nautilus_file_get_deep_counts if it's a directory, same
  with unreadable_dir_count.
* Use two status variables, one for each file and a global, to make sure
  deep_count_finished isn't modified until all files are deep counted.

-- 
Johan Dahlin <jdahlin async com br>
Async Open Source
--- /home/jdahlin/fm-properties-window.c	2003-07-03 23:47:39.000000000 +0200
+++ src/file-manager/fm-properties-window.c	2003-07-04 02:51:48.000000000 +0200
@@ -85,7 +85,7 @@
 struct FMPropertiesWindowDetails {	
 	GList *original_files;
 	GList *target_files;
-
+	
 	GtkNotebook *notebook;
 	GtkWidget *remove_image_button;
 	
@@ -119,6 +119,9 @@
 	GList *mime_list;
 
 	gboolean deep_count_finished;
+
+	guint total_count;
+	GnomeVFSFileSize total_size;
 };
 
 enum {
@@ -291,8 +294,6 @@
 static NautilusFile *
 get_target_file (FMPropertiesWindow *window)
 {
-	g_return_val_if_fail (!is_multi_file_window (window), NULL);
-
 	return NAUTILUS_FILE (window->details->target_files->data);
 }
 
@@ -1661,82 +1662,107 @@
 static void
 directory_contents_value_field_update (FMPropertiesWindow *window)
 {
-	NautilusRequestStatus status;
+	NautilusRequestStatus file_status, status;
 	char *text, *temp;
-	guint directory_count;
+	guint dir_count;
 	guint file_count;
 	guint total_count;
-	guint unreadable_directory_count;
+	guint unreadable_dir_count;
 	GnomeVFSFileSize total_size;
-	char *size_string;
 	gboolean used_two_lines;
 	NautilusFile *file;
+	GList *l;
+	guint file_unreadable;
+	GnomeVFSFileSize file_size;
 
 	g_assert (FM_IS_PROPERTIES_WINDOW (window));
 
-	/* For right now this will only work on single-file property
-	 * dialogs */
-	if (is_multi_file_window (window)) {
-		return ;
-	}
-
-	file = get_target_file (window);
-	g_assert (nautilus_file_is_directory (file) || nautilus_file_is_gone (file));
-
-	status = nautilus_file_get_deep_counts (file, 
-						&directory_count, 
-						&file_count, 
-						&unreadable_directory_count, 
-						&total_size);
+	status = NAUTILUS_REQUEST_DONE;
+	file_status = NAUTILUS_REQUEST_NOT_STARTED;
+	total_count = window->details->total_count;
+	total_size = window->details->total_size;
+	unreadable_dir_count = FALSE;
 
+	for (l = window->details->target_files; l; l = l->next) {
+		file = NAUTILUS_FILE (l->data);
+		if (nautilus_file_is_directory (file)) {
+			file_status = nautilus_file_get_deep_counts (file, 
+					 &dir_count,
+					 &file_count, 
+					 &file_unreadable,
+					 &file_size);
+			total_count += (file_count + dir_count);
+			total_size += file_size;
+			
+			if (file_unreadable) {
+				unreadable_dir_count = TRUE;
+			}
+			
+			if (file_status != NAUTILUS_REQUEST_DONE) {
+				status = file_status;
+			}
+		} else {
+			++total_count;
+			total_size += nautilus_file_get_size (file);
+		}
+	}
+	
 	/* If we've already displayed the total once, don't do another visible
-	 * count-up if the deep_count happens to get invalidated. But still display
-	 * the new total, since it might have changed.
+	 * count-up if the deep_count happens to get invalidated.
+	 * But still display the new total, since it might have changed.
 	 */
-	if (window->details->deep_count_finished && status != NAUTILUS_REQUEST_DONE) {
+	if (window->details->deep_count_finished &&
+	    status != NAUTILUS_REQUEST_DONE) {
 		return;
 	}
 
 	text = NULL;
-	total_count = file_count + directory_count;
 	used_two_lines = FALSE;
-
+	
 	if (total_count == 0) {
 		switch (status) {
 		case NAUTILUS_REQUEST_DONE:
-			if (unreadable_directory_count == 0) {
+			if (unreadable_dir_count == 0) {
 				text = g_strdup (_("nothing"));
 			} else {
 				text = g_strdup (_("unreadable"));
 			}
+			
 			break;
 		default:
 			text = g_strdup ("...");
 		}
 	} else {
-		size_string = gnome_vfs_format_file_size_for_display (total_size);
+		char *size_str;
+		size_str = gnome_vfs_format_file_size_for_display (total_size);
 		if (total_count == 1) {
-				text = g_strdup_printf (_("1 item, with size %s"), size_string);
+			text = g_strdup_printf (_("1 item, with size %s"),
+						size_str);
 		} else {
-			text = g_strdup_printf (_("%d items, totalling %s"), total_count, size_string);
+			text = g_strdup_printf (_("%d items, totalling %s"),
+						total_count, size_str);
 		}
-		g_free (size_string);
+		g_free (size_str);
 
-		if (unreadable_directory_count != 0) {
+		if (unreadable_dir_count != 0) {
 			temp = text;
-			text = g_strconcat (temp, "\n", _("(some contents unreadable)"), NULL);
+			text = g_strconcat (temp, "\n",
+					    _("(some contents unreadable)"),
+					    NULL);
 			g_free (temp);
 			used_two_lines = TRUE;
 		}
 	}
 
-	gtk_label_set_text (window->details->directory_contents_value_field, text);
+	gtk_label_set_text (window->details->directory_contents_value_field,
+			    text);
 	g_free (text);
 
-	/* Also set the title field here, with a trailing carriage return & space
-	 * if the value field has two lines. This is a hack to get the
-	 * "Contents:" title to line up with the first line of the 2-line value.
-	 * Maybe there's a better way to do this, but I couldn't think of one.
+	/* Also set the title field here, with a trailing carriage return &
+	 * space if the value field has two lines. This is a hack to get the
+	 * "Contents:" title to line up with the first line of the
+	 * 2-line value. Maybe there's a better way to do this, but I
+	 * couldn't think of one.
 	 */
 	text = g_strdup (_("Contents:"));
 	if (used_two_lines) {
@@ -1744,7 +1770,8 @@
 		text = g_strconcat (temp, "\n ", NULL);
 		g_free (temp);
 	}
-	gtk_label_set_text (window->details->directory_contents_title_field, text);
+	gtk_label_set_text (window->details->directory_contents_title_field,
+			    text);
 	g_free (text);
 
 	if (status == NAUTILUS_REQUEST_DONE) {
@@ -1791,14 +1818,16 @@
 	window->details->directory_contents_value_field = value_field;
 
 	gtk_label_set_line_wrap (value_field, TRUE);
-
-       /* Fill in the initial value. */
-       directory_contents_value_field_update (window);
+	
+	/* Fill in the initial value. */
+	directory_contents_value_field_update (window);
  
         /* Always recompute from scratch when the window is shown. */
-       if (is_multi_file_window (window)) {
+	if (is_multi_file_window (window)) {
                GList *l;
-               for (l = window->details->original_files; l; l = l->next) {
+	       NautilusFile *file;
+	       
+	       for (l = window->details->original_files; l; l = l->next) {
                        file = NAUTILUS_FILE (l->data);
                        nautilus_file_recompute_deep_counts (file);
                        
@@ -1807,8 +1836,7 @@
                                G_CALLBACK (schedule_directory_contents_update),
                               window, G_CONNECT_SWAPPED);
                }
-       }
-
+	}
 	
 	return value_field;	
 }
@@ -1902,12 +1930,15 @@
 update_visibility_of_item_count_fields (FMPropertiesWindow *window)
 {
 	gboolean should_show_count;
-	
-	if (is_multi_file_window (window)) {
-		should_show_count = FALSE;
-	} else {
-		should_show_count = nautilus_file_should_show_directory_item_count (get_target_file (window));
+	GList *l;
+	guint count = 0;
+	NautilusFile *file;
+               
+	for (l = window->details->original_files; l; l = l->next) {
+		file = NAUTILUS_FILE (l->data);
+		count += nautilus_file_should_show_directory_item_count (file);
 	}
+	should_show_count = count;
 
 	update_visibility_of_table_rows
 		(window->details->basic_table,
@@ -2212,12 +2243,8 @@
 					 FALSE);
 	}
 
-	if (is_multi_file_window (window)) {
-		/* FIXME: append a total size field here */
-#if 0
-		append_total_size_field (window, table);
-#endif
-	} else if (nautilus_file_is_directory (get_target_file (window))) {
+	if (is_multi_file_window (window) ||
+	    nautilus_file_is_directory (get_target_file (window))) {
 		append_directory_contents_fields (window, table);
 	} else {
 		append_title_value_pair (window, table, _("Size:"), 


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