gtk+ r20003 - in trunk: . gtk



Author: ebassi
Date: Tue Apr 15 23:00:17 2008
New Revision: 20003
URL: http://svn.gnome.org/viewvc/gtk+?rev=20003&view=rev

Log:
2008-04-15  Emmanuele Bassi  <ebassi gnome org>

	Bug 506062 â gtk_recent_manager_add_item does not detect mime
	type on Windows

	* configure.in: Depend on gio-2.0

	* gtk/gtkrecentmanager.c:
	(gtk_recent_manager_add_item_query_info_cb),
	(gtk_recent_manager_add_item): Use GIO to (asynchronously) query
	the MIME type of the passed URI.

Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/gtk/gtkrecentmanager.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Apr 15 23:00:17 2008
@@ -1674,7 +1674,7 @@
         LIBS="$gtk_save_LIBS"
 fi
 
-GTK_PACKAGES="atk cairo"
+GTK_PACKAGES="atk cairo gio-2.0"
 GTK_EXTRA_LIBS=
 GTK_EXTRA_CFLAGS= 
 GTK_DEP_LIBS="$GDK_EXTRA_LIBS $GTK_DEP_LIBS_FOR_X `$PKG_CONFIG --libs $GDK_PIXBUF_PACKAGES $PANGO_PACKAGES $GTK_PACKAGES_FOR_X $GTK_PACKAGES` $GTK_EXTRA_LIBS $GDK_PIXBUF_EXTRA_LIBS"

Modified: trunk/gtk/gtkrecentmanager.c
==============================================================================
--- trunk/gtk/gtkrecentmanager.c	(original)
+++ trunk/gtk/gtkrecentmanager.c	Tue Apr 15 23:00:17 2008
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <gio/gio.h>
 
 #include "gtkrecentmanager.h"
 #include "gtkintl.h"
@@ -136,6 +137,9 @@
 						       guint                  prop_id,
 						       GValue                *value,
 						       GParamSpec            *pspec);
+static void gtk_recent_manager_add_item_query_info_cb (GObject              *source_object,
+                                                       GAsyncResult         *res,
+                                                       gpointer             user_data);
 static void           gtk_recent_manager_changed      (GtkRecentManager      *manager);
 
 static void           gtk_recent_manager_real_changed (GtkRecentManager      *manager);
@@ -797,6 +801,60 @@
   return priv->limit;
 }
 
+static void
+gtk_recent_manager_add_item_query_info_cb (GObject      *source_object,
+                                           GAsyncResult *res,
+                                           gpointer      user_data)
+{
+  GFile *file = G_FILE (source_object);
+  GtkRecentManager *manager = user_data;
+  GtkRecentData recent_data;
+  GFileInfo *file_info;
+  gchar *uri;
+  GError *error;
+
+  uri = g_file_get_uri (file);
+
+  error = NULL;
+  file_info = g_file_query_info_finish (file, res, &error);
+  if (error)
+    {
+      g_warning ("Unable to retrieve the file info for `%s': %s",
+                 uri,
+                 error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  recent_data.display_name = NULL;
+  recent_data.description = NULL;
+
+  if (file_info)
+    {
+      recent_data.mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (file_info));
+      g_object_unref (file_info);
+    }
+  else
+    recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
+
+  recent_data.app_name = g_strdup (g_get_application_name ());
+  recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
+  recent_data.groups = NULL;
+  recent_data.is_private = FALSE;
+
+  /* Ignore return value, this can't fail anyway since all required
+   * fields are set */
+  gtk_recent_manager_add_full (manager, uri, &recent_data);
+
+  g_free (recent_data.mime_type);
+  g_free (recent_data.app_name);
+  g_free (recent_data.app_exec);
+
+out:
+  g_object_unref (manager);
+  g_free (uri);
+}
+
 /**
  * gtk_recent_manager_add_item:
  * @manager: a #GtkRecentManager
@@ -808,7 +866,7 @@
  * This function automatically retrieves some of the needed
  * metadata and setting other metadata to common default values; it
  * then feeds the data to gtk_recent_manager_add_full().
- *
+ * 
  * See gtk_recent_manager_add_full() if you want to explicitly
  * define the metadata for the resource pointed by @uri.
  *
@@ -821,51 +879,24 @@
 gtk_recent_manager_add_item (GtkRecentManager  *manager,
 			     const gchar       *uri)
 {
-  GtkRecentData recent_data;
-  gboolean retval;
+  GFile* file;
   
   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
   g_return_val_if_fail (uri != NULL, FALSE);
 
-  recent_data.display_name = NULL;
-  recent_data.description = NULL;
-  recent_data.mime_type = NULL;
+  file = g_file_new_for_uri (uri);
 
-#ifdef G_OS_UNIX
-  if (has_case_prefix (uri, "file:/"))
-    {
-      gchar *filename;
-      const gchar *mime_type;
-      
-      filename = g_filename_from_uri (uri, NULL, NULL);
-      if (filename)
-        {
-          mime_type = xdg_mime_get_mime_type_for_file (filename, NULL);
-          if (mime_type)
-            recent_data.mime_type = g_strdup (mime_type);
-      
-          g_free (filename);
-        }
+  g_file_query_info_async (file,
+                           G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
+                           G_PRIORITY_DEFAULT,
+                           G_FILE_QUERY_INFO_NONE,
+                           NULL,
+                           gtk_recent_manager_add_item_query_info_cb,
+                           g_object_ref (manager));
 
-      if (!recent_data.mime_type)
-        recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
-    }
-  else
-#endif
-    recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
-  
-  recent_data.app_name = g_strdup (g_get_application_name ());
-  recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
-  recent_data.groups = NULL;
-  recent_data.is_private = FALSE;
-  
-  retval = gtk_recent_manager_add_full (manager, uri, &recent_data);
-  
-  g_free (recent_data.mime_type);
-  g_free (recent_data.app_name);
-  g_free (recent_data.app_exec);
+  g_object_unref (file);
 
-  return retval;
+  return TRUE;
 }
 
 /**



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