Re: patch for bug #165442 - Icons needed in the corner popup menu



Hey Alex,

On 6/7/05, Alexander Larsson <alexl redhat com> wrote:
> Ah, this is more problematic. We need to do some async i/o to actually
> get the information from not-yet-read files. That makes things a lot
> more complicated...
I have attached a new patch that actually does this.

> > On 6/2/05, Alexander Larsson <alexl redhat com> wrote:
> Do we really need to show it as opened?
In the patch the regular icon for the visited folder is used (so it's
the "computer" icon when visiting computer:///, etc)

> Maybe nautilus_icon_factory_get_pixbuf_for_file is the easiest one to
> use in this case.
I kept using nautilus_icon_factory_get_icon_for_file, as I couldn't
pass GTK_ICON_SIZE_MENU to nautilus_icon_factory_get_pixbuf_for_file
(it's a GtkIconSize and not a int).

Thanks for all the pointers !
Cheers
Vincent
Index: src/nautilus-spatial-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.c,v
retrieving revision 1.443
diff -u -r1.443 nautilus-spatial-window.c
--- src/nautilus-spatial-window.c	2 Jun 2005 16:16:55 -0000	1.443
+++ src/nautilus-spatial-window.c	7 Jun 2005 15:59:45 -0000
@@ -94,6 +94,7 @@
 	GtkWidget *content_box;
 	GtkWidget *location_button;
 	GtkWidget *location_label;
+	GtkWidget *location_icon;
 
 	GnomeVFSURI *location;
 };
@@ -471,6 +472,33 @@
 }
 
 static void
+got_file_info_for_location_menu_callback (NautilusFile *file,
+					  gpointer callback_data)
+{	
+	GtkWidget *icon;
+	GtkWidget *menu_item = callback_data;
+	GnomeVFSResult vfs_result_code;
+	char *icon_name;
+
+	g_return_if_fail (NAUTILUS_IS_FILE (file));
+
+	vfs_result_code = nautilus_file_get_file_info_result (file);
+	if (vfs_result_code == GNOME_VFS_OK) {
+		icon_name = nautilus_icon_factory_get_icon_for_file (file, FALSE);
+		if (icon_name) {
+			icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+		} else {
+			icon = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
+		}
+		
+		if (icon) {
+			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), icon);
+		}
+	}
+	g_object_unref (file);
+}
+
+static void
 menu_deactivate_callback (GtkWidget *menu,
 			  gpointer   data)
 {
@@ -537,17 +565,24 @@
 	uri = gnome_vfs_uri_ref (window->details->location);
 	child_uri = NULL;
 	while (uri != NULL) {
+		NautilusFile *file;
+		NautilusDirectory *directory;
+		char *uri_string;
+
 		name = nautilus_get_uri_shortname_for_display (uri);
 		menu_item = gtk_image_menu_item_new_with_label (name);
-		if (first_item == NULL) {
-			GtkWidget *open_icon = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
-
-			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), open_icon);
-
-			first_item = menu_item;
-		}
-		
 		g_free (name);
+		
+		uri_string = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
+		directory = nautilus_directory_get (uri_string);
+		file = nautilus_directory_get_corresponding_file (directory);
+		nautilus_file_call_when_ready (file,
+					       NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY,
+					       got_file_info_for_location_menu_callback,
+					       menu_item);
+		g_object_unref (directory);
+		g_free (uri_string);		
+
 		gtk_widget_show (menu_item);
 		g_signal_connect (menu_item, "activate",
 				  G_CALLBACK (location_menu_item_activated_callback),
@@ -663,11 +698,33 @@
 		uri = gnome_vfs_uri_new (location);
 	}
 	if (uri != NULL) {
+		NautilusDirectory *directory;
+		NautilusFile *file;
+		GnomeVFSResult vfs_result_code;
+		
 		name = nautilus_get_uri_shortname_for_display (uri);
 		gtk_label_set_label (GTK_LABEL (window->details->location_label),
 				     name);
 		g_free (name);
 		gtk_widget_set_sensitive (window->details->location_button, TRUE);
+
+		directory = nautilus_directory_get (location);
+		file = nautilus_directory_get_corresponding_file (directory);
+		vfs_result_code = nautilus_file_get_file_info_result (file);
+		if (vfs_result_code == GNOME_VFS_OK) {
+			char *icon_name;
+
+			icon_name = nautilus_icon_factory_get_icon_for_file (file, FALSE);		
+			if (icon_name) {
+				gtk_image_set_from_icon_name (GTK_IMAGE (window->details->location_icon), 
+							      icon_name, GTK_ICON_SIZE_MENU);
+			} else {
+				gtk_image_set_from_stock (GTK_IMAGE (window->details->location_icon),
+							  GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
+			}
+		}
+		g_object_unref (directory);
+
 	} else {
 		gtk_label_set_label (GTK_LABEL (window->details->location_label),
 				     "");
@@ -713,7 +770,6 @@
 	GtkActionGroup *action_group;
 	GtkUIManager *ui_manager;
 	const char *ui;
-	GtkWidget *folder_icon;
 	
 	window->details = g_new0 (NautilusSpatialWindowDetails, 1);
 	window->affect_spatial_window_on_next_location_change = TRUE;
@@ -747,9 +803,9 @@
 			   hbox);
 	gtk_widget_show (hbox);
 
-	folder_icon = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
-	gtk_box_pack_start (GTK_BOX (hbox), folder_icon, FALSE, FALSE, 0);
-	gtk_widget_show (folder_icon);
+	window->details->location_icon = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
+	gtk_box_pack_start (GTK_BOX (hbox), window->details->location_icon, FALSE, FALSE, 0);
+	gtk_widget_show (window->details->location_icon);
 	
 	window->details->location_label = gtk_label_new ("");
 	gtk_box_pack_start (GTK_BOX (hbox), window->details->location_label,


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