marlin r1305 - in trunk/src: . dialogs



Author: iain
Date: Sat Oct 11 13:21:09 2008
New Revision: 1305
URL: http://svn.gnome.org/viewvc/marlin?rev=1305&view=rev

Log:
Replace GNOME-vfs in the information dialog


Modified:
   trunk/src/ChangeLog
   trunk/src/dialogs/marlin-information-dialog.c

Modified: trunk/src/dialogs/marlin-information-dialog.c
==============================================================================
--- trunk/src/dialogs/marlin-information-dialog.c	(original)
+++ trunk/src/dialogs/marlin-information-dialog.c	Sat Oct 11 13:21:09 2008
@@ -19,8 +19,6 @@
  *
  */
 
-/* FIXME: This needs to handle remote files: Should use GnomeVFS functions
-   rather than simple stat calls. */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -31,6 +29,8 @@
 
 #include <glib/gi18n.h>
 
+#include <gio/gio.h>
+
 #include <gtk/gtklabel.h>
 #include <gtk/gtkdialog.h>
 #include <gtk/gtktable.h>
@@ -45,12 +45,6 @@
 #include <gtk/gtkimage.h>
 #include <gtk/gtkicontheme.h>
 
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-file-info.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-
 #include <marlin/marlin-x-utils.h>
 #include <marlin/marlin-gst-extras.h>
 #include <marlin/marlin-utils.h>
@@ -96,7 +90,7 @@
 	name = get_string_from_taglist (idd->taglist, GST_TAG_TITLE);
 	gtk_entry_set_text (GTK_ENTRY (idd->name), name);
 	g_free (name);
-	
+
 	name = get_string_from_taglist (idd->taglist, GST_TAG_ARTIST);
 	gtk_entry_set_text (GTK_ENTRY (idd->artist), name);
 	g_free (name);
@@ -158,7 +152,7 @@
 			  MARLIN_TAG_BPM, c->nbpm,
 			  NULL);
 }
-	
+
 static void
 set_info_destroy (gpointer data)
 {
@@ -201,14 +195,14 @@
 		name = gtk_entry_get_text (GTK_ENTRY (idd->name));
 		artist = gtk_entry_get_text (GTK_ENTRY (idd->artist));
 		album = gtk_entry_get_text (GTK_ENTRY (idd->album));
-		
+
 		gtk_text_buffer_get_bounds (idd->buffer, &start, &end);
 		comments = gtk_text_buffer_get_text (idd->buffer, &start, &end, FALSE);
 
 		track_no = (guint) idd->track_no->value;
 		bpm = (guint) idd->bpm->value;
 
-		ctxt = marlin_undo_manager_context_begin (idd->undo, 
+		ctxt = marlin_undo_manager_context_begin (idd->undo,
 							  _("Change Information"));
 		c = g_new (struct _set_info_closure, 1);
 		c->nname = g_strdup (name);
@@ -261,75 +255,28 @@
 	g_free (idd);
 }
 
-#if 0
-static GdkPixbuf *
-load_icon_file (char *filename,
-		guint nominal_size)
+GdkPixbuf *
+get_pixbuf_from_icon (GIcon *icon)
 {
-	GdkPixbuf *pixbuf, *scaled_pixbuf;
-	guint width, height;
-
-	pixbuf = gdk_pixbuf_new_from_file_at_size (filename, nominal_size, nominal_size, NULL);
-
-	if (pixbuf == NULL) {
-		return NULL;
-	}
-
-	width = gdk_pixbuf_get_width (pixbuf);
-	height = gdk_pixbuf_get_height (pixbuf);
-
-	if (MAX (width, height) > nominal_size) {
-		if (width > height) {
-			height = height * nominal_size / width;
-			width = nominal_size;
-		} else {
-			width = width * nominal_size / height;
-			height = nominal_size;
-		}
-
-		scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
-				  			 width, height,
-							 GDK_INTERP_BILINEAR);
-		g_object_unref (pixbuf);
-		pixbuf = scaled_pixbuf;
-	}
-
-	return pixbuf;
-}
-#endif
-static GdkPixbuf *
-get_icon_for_mime_type (const char *mime_type,
-			int         pixel_size)
-{
-	const char *separator;
-	GString *icon_name;
-	GdkPixbuf *pixbuf;
+	GtkIconTheme *theme;
+	GtkIconInfo *icon_info;
+	GdkPixbuf *pixbuf = NULL;
 	GError *error = NULL;
 
-	separator = strchr (mime_type, '/');
-	if (separator == NULL) {
+	theme = gtk_icon_theme_get_default ();
+	icon_info = gtk_icon_theme_lookup_by_gicon
+		(theme, icon, 48, GTK_ICON_LOOKUP_USE_BUILTIN);
+	if (icon_info == NULL) {
 		return NULL;
 	}
 
-	icon_name = g_string_new ("gnome-mime-");
-	g_string_append_len (icon_name, mime_type, separator - mime_type);
-	g_string_append_c (icon_name, '-');
-	g_string_append (icon_name, separator + 1);
-
-	pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), 
-					   icon_name->str,
-					   pixel_size, 0, &error);
-	if (pixbuf == NULL) {
-		g_warning ("Error loading pixbuf %s: %s", icon_name->str, 
-			   error->message);
+	pixbuf = gtk_icon_info_load_icon (icon_info, &error);
+	if (error != NULL) {
+		g_warning ("Error loading icon: %s", error->message);
 		g_error_free (error);
-
-		return NULL;
 	}
 
-	g_print ("loading: %s - %p\n", icon_name->str, pixbuf);
-	g_string_free (icon_name, TRUE);
-
+	gtk_icon_info_free (icon_info);
 	return pixbuf;
 }
 
@@ -337,13 +284,13 @@
 make_general_page (struct _InformationDialog *idd)
 {
 	GtkWidget *table, *label, *sep, *icon;
-	char *filename, *name, *mime_type, *str;
-	char date_str[256];
-	GdkPixbuf *icon_pb;
-	GDate *date;
-	GnomeVFSFileInfo *info;
+	char *filename, *name, *str;
+	const char *mimetype;
+	GFile *file;
+	GFileInfo *info;
 	int height, channels;
 	guint64 frames, size;
+	GError *error = NULL;
 
 	g_object_get (G_OBJECT (idd->sample),
 		      "total_frames", &frames,
@@ -351,36 +298,47 @@
 		      "channels", &channels,
 		      NULL);
 
-	info = gnome_vfs_file_info_new ();
-	gnome_vfs_get_file_info (filename, info,
-				 GNOME_VFS_FILE_INFO_DEFAULT | 
-				 GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
-
+	file = g_file_new_for_uri (filename);
+	info = g_file_query_info (file, "*", G_FILE_QUERY_INFO_NONE,
+				  NULL, &error);
+	if (error != NULL) {
+		g_warning ("Error getting %s details: %s", filename,
+			   error->message);
+		g_error_free (error);
+	}
 
 	table = marlin_make_table (8, 2, FALSE);
 	gtk_container_set_border_width (GTK_CONTAINER (table), 6);
 	gtk_widget_show (table);
 
-	mime_type = (char *) gnome_vfs_file_info_get_mime_type (info);
-	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (idd->dialog),
-					   GTK_ICON_SIZE_MENU,
-					   NULL, &height);
-
-	icon_pb = get_icon_for_mime_type (mime_type, height);
+	if (info) {
+		GtkWidget *image;
+		GdkPixbuf *icon_pb;
+		GIcon *icon;
+
+		icon = g_file_info_get_icon (info);
+		icon_pb = get_pixbuf_from_icon (icon);
+		if (icon_pb) {
+			image = gtk_image_new_from_pixbuf (icon_pb);
+			gtk_misc_set_alignment (GTK_MISC (image), 1.0, 0.5);
+			g_object_unref (G_OBJECT (icon_pb));
 
-	icon = gtk_image_new_from_pixbuf (icon_pb);
-	gtk_misc_set_alignment (GTK_MISC (icon), 1.0, 0.5);
-	g_object_unref (G_OBJECT (icon_pb));
-
-	PACK (table, icon, 0, 0, GTK_FILL);
-	gtk_widget_show (icon);
+			PACK (table, image, 0, 0, GTK_FILL);
+			gtk_widget_show (image);
+		}
+	}
 
-	name = g_path_get_basename (filename);
+	if (info) {
+		name = g_path_get_basename (g_file_info_get_display_name (info));
+	} else {
+		name = g_path_get_basename (filename);
+	}
 	label = marlin_make_info_label (name);
+	g_free (name);
+
 	PACK (table, label, 1, 0, GTK_FILL);
 	gtk_widget_show (label);
-	g_free (name);
-	
+
 	sep = gtk_label_new ("");
 	gtk_table_attach (GTK_TABLE (table), sep,
 			  0, 2, 1, 2,
@@ -392,13 +350,25 @@
 	PACK (table, label, 0, 2, GTK_FILL);
 	gtk_widget_show (label);
 
-	if (mime_type) {
-		label = marlin_make_info_label (gnome_vfs_mime_get_description (mime_type));
+	if (info) {
+		mimetype = g_file_info_get_content_type (info);
+	} else {
+		mimetype = NULL;
+	}
+
+	if (mimetype) {
+		char *type;
 
-		PACK (table, label, 1, 2, GTK_FILL);
-		gtk_widget_show (label);
+		type = g_content_type_get_description (mimetype);
+		label = marlin_make_info_label (type);
+		g_free (type);
+	} else {
+		label = marlin_make_info_label (_("Unknown"));
 	}
 
+	PACK (table, label, 1, 2, GTK_FILL);
+	gtk_widget_show (label);
+
 	label = marlin_make_title_label (_("Location:"));
 	gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
 	PACK (table, label, 0, 3, GTK_FILL);
@@ -415,11 +385,15 @@
 	PACK (table, label, 0, 4, GTK_FILL);
 	gtk_widget_show (label);
 
-	str = gnome_vfs_format_file_size_for_display (info->size);
-	label = marlin_make_info_label (str);
+	if (info) {
+		str = g_format_size_for_display (g_file_info_get_size (info));
+		label = marlin_make_info_label (str);
+		g_free (str);
+	} else {
+		label = marlin_make_info_label (_("Unknown"));
+	}
 	PACK (table, label, 1, 4, GTK_FILL);
 	gtk_widget_show (label);
-	g_free (str);
 
 	label = marlin_make_title_label (_("Size in Memory:"));
 	gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
@@ -428,7 +402,7 @@
 
 	/* FIXME: This will be a bad estimate when we are editing */
 	size = frames * channels * sizeof (float);
-	str = gnome_vfs_format_file_size_for_display (size);
+	str = g_format_size_for_display (size);
 	label = marlin_make_info_label (str);
 	PACK (table, label, 1, 5, GTK_FILL);
 	gtk_widget_show (label);
@@ -445,16 +419,28 @@
 	PACK (table, label, 0, 7, GTK_FILL);
 	gtk_widget_show (label);
 
-	date = g_date_new ();
-	g_date_set_time_t (date, info->mtime);
-	g_date_strftime (date_str, 256, "%c", date);
-	g_date_free (date);
+	if (info) {
+		GTimeVal modified_time;
+		GDate *date;
+		char date_str[256];
+
+		g_file_info_get_modification_time (info, &modified_time);
+
+		date = g_date_new ();
+		g_date_set_time_val (date, &modified_time);
+		g_date_strftime (date_str, 256, "%c", date);
+		g_date_free (date);
 
-	label = marlin_make_info_label (date_str);
+		label = marlin_make_info_label (date_str);
+	} else {
+		label = marlin_make_info_label (_("Unknown"));
+	}
 	PACK (table, label, 1, 7, GTK_FILL);
 	gtk_widget_show (label);
 
-	gnome_vfs_file_info_unref (info);
+	g_free (filename);
+	g_object_unref (file);
+	g_object_unref (info);
 
 	return table;
 }



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