[nautilus] mime-application-chooser: always take a list of NautilusFiles



commit 395bc3b42ed3e07bbdb5203033beeda07d979138
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Aug 23 12:24:49 2012 +0200

    mime-application-chooser: always take a list of NautilusFiles
    
    This has the following consequences:
    - fixes the build after commit 58b704ad8b473600d7f7ad57aa5535e5be5dbd24
    - take a ref to the NautilusFiles when the list is passed-in
    - simplifies the code calling the dialog from NautilusPropertiesWindow
    - simplifies the code in NautilusMimeApplicationChooser, since we don't
      have to special case the files != NULL case and build a GFile manually
      from the URI

 .../nautilus-mime-application-chooser.c            |   66 +++++++-------------
 .../nautilus-mime-application-chooser.h            |    3 +-
 src/nautilus-properties-window.c                   |   19 +++---
 3 files changed, 33 insertions(+), 55 deletions(-)
---
diff --git a/libnautilus-private/nautilus-mime-application-chooser.c b/libnautilus-private/nautilus-mime-application-chooser.c
index b78bae2..53f736c 100644
--- a/libnautilus-private/nautilus-mime-application-chooser.c
+++ b/libnautilus-private/nautilus-mime-application-chooser.c
@@ -41,7 +41,6 @@
 
 struct _NautilusMimeApplicationChooserDetails {
 	GList *files;
-	char *uri;
 
 	char *content_type;
 
@@ -54,7 +53,6 @@ struct _NautilusMimeApplicationChooserDetails {
 
 enum {
 	PROP_CONTENT_TYPE = 1,
-	PROP_URI,
 	PROP_FILES,
 	NUM_PROPERTIES
 };
@@ -241,42 +239,35 @@ static void
 nautilus_mime_application_chooser_apply_labels (NautilusMimeApplicationChooser *chooser)
 {
 	gchar *label, *extension = NULL, *description = NULL;
+	gint num_files;
+	NautilusFile *file;
 
-	if (chooser->details->files != NULL) {
-		/* here we assume all files are of the same content type */
-		if (g_content_type_is_unknown (chooser->details->content_type)) {
-			extension = nautilus_file_get_extension (NAUTILUS_FILE (chooser->details->files->data));
+	num_files = g_list_length (chooser->details->files);
+	file = chooser->details->files->data;
 
-			/* the %s here is a file extension */
-			description = g_strdup_printf (_("%s document"), extension);
-		} else {
-			description = g_content_type_get_description (chooser->details->content_type);
-		}
+	/* here we assume all files are of the same content type */
+	if (g_content_type_is_unknown (chooser->details->content_type)) {
+		extension = nautilus_file_get_extension (file);
 
+		/* Translators: the %s here is a file extension */
+		description = g_strdup_printf (_("%s document"), extension);
+	} else {
+		description = g_content_type_get_description (chooser->details->content_type);
+	}
+
+	if (num_files > 1) {
+		/* Translators; %s here is a mime-type description */
 		label = g_strdup_printf (_("Open all files of type â%sâ with"),
 					 description);
 	} else {
-		GFile *file;
-		gchar *basename;
-
-		file = g_file_new_for_uri (chooser->details->uri);
-		basename = g_file_get_basename (file);
+		gchar *display_name;
+		display_name = nautilus_file_get_display_name (file);
 
-		if (g_content_type_is_unknown (chooser->details->content_type)) {
-			extension = nautilus_file_get_extension (file);
-
-			/* the %s here is a file extension */
-			description = g_strdup_printf (_("%s document"), extension);
-		} else {
-			description = g_content_type_get_description (chooser->details->content_type);
-		}
-
-		/* first %s is filename, second %s is mime-type description */
+		/* Translators: first %s is filename, second %s is mime-type description */
 		label = g_strdup_printf (_("Select an application to open â%sâ and other files of type â%sâ"),
-					 basename, description);
+					 display_name, description);
 
-		g_free (basename);
-		g_object_unref (file);
+		g_free (display_name);
 	}
 
 	gtk_label_set_markup (GTK_LABEL (chooser->details->label), label);
@@ -395,8 +386,8 @@ nautilus_mime_application_chooser_finalize (GObject *object)
 
 	chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
 
-	g_free (chooser->details->uri);
 	g_free (chooser->details->content_type);
+	nautilus_file_list_free (chooser->details->files);
 
 	G_OBJECT_CLASS (nautilus_mime_application_chooser_parent_class)->finalize (object);
 }
@@ -432,10 +423,7 @@ nautilus_mime_application_chooser_set_property (GObject *object,
 		chooser->details->content_type = g_value_dup_string (value);
 		break;
 	case PROP_FILES:
-		chooser->details->files = g_value_get_pointer (value);
-		break;
-	case PROP_URI:
-		chooser->details->uri = g_value_dup_string (value);
+		chooser->details->files = nautilus_file_list_copy (g_value_get_pointer (value));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -460,12 +448,6 @@ nautilus_mime_application_chooser_class_init (NautilusMimeApplicationChooserClas
 							     NULL,
 							     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
 							     G_PARAM_STATIC_STRINGS);
-	properties[PROP_URI] = g_param_spec_string ("uri",
-						    "URI",
-						    "URI for this widget",
-						    NULL,
-						    G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
-						    G_PARAM_STATIC_STRINGS);
 	properties[PROP_FILES] = g_param_spec_pointer ("files",
 						       "Files",
 						       "Files for this widget",
@@ -478,14 +460,12 @@ nautilus_mime_application_chooser_class_init (NautilusMimeApplicationChooserClas
 }
 
 GtkWidget *
-nautilus_mime_application_chooser_new (const char *uri,
-				       GList *files,
+nautilus_mime_application_chooser_new (GList *files,
 				       const char *mime_type)
 {
 	GtkWidget *chooser;
 
 	chooser = g_object_new (NAUTILUS_TYPE_MIME_APPLICATION_CHOOSER,
-				"uri", uri,
 				"files", files,
 				"content-type", mime_type,
 				NULL);
diff --git a/libnautilus-private/nautilus-mime-application-chooser.h b/libnautilus-private/nautilus-mime-application-chooser.h
index 795ec06..8b7eaae 100644
--- a/libnautilus-private/nautilus-mime-application-chooser.h
+++ b/libnautilus-private/nautilus-mime-application-chooser.h
@@ -47,8 +47,7 @@ struct _NautilusMimeApplicationChooserClass {
 };
 
 GType      nautilus_mime_application_chooser_get_type (void);
-GtkWidget * nautilus_mime_application_chooser_new (const char *uri,
-						   GList *files,
+GtkWidget * nautilus_mime_application_chooser_new (GList *files,
 						   const char *mime_type);
 
 #endif /* NAUTILUS_MIME_APPLICATION_CHOOSER_H */
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 20f1628..8d5de2f 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -4628,27 +4628,26 @@ create_open_with_page (NautilusPropertiesWindow *window)
 {
 	GtkWidget *vbox;
 	char *mime_type;
-	char *uri = NULL;
-	GList *uris = NULL;
+	GList *files = NULL;
+	NautilusFile *target_file;
 
-	mime_type = nautilus_file_get_mime_type (get_target_file (window));
+	target_file = get_target_file (window);
+	mime_type = nautilus_file_get_mime_type (target_file);
 
 	if (!is_multi_file_window (window)) {
-		uri = nautilus_file_get_uri (get_target_file (window));
-		if (uri == NULL) {
-			return;
-		}
+		files = g_list_prepend (NULL, target_file);
 	} else {
-		uris = window->details->original_files;
-		if (uris == NULL) {
+		files = g_list_copy (window->details->original_files);
+		if (files == NULL) {
 			return;
 		}
 	}
 
-	vbox = nautilus_mime_application_chooser_new (uri, uris, mime_type);
+	vbox = nautilus_mime_application_chooser_new (files, mime_type);
 
 	gtk_widget_show (vbox);
 	g_free (mime_type);
+	g_list_free (files);
 
 	g_object_set_data_full (G_OBJECT (vbox), "help-uri", g_strdup ("help:gnome-help/files-open"), g_free);
 	gtk_notebook_append_page (window->details->notebook, 



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