[Xfce4-commits] r29763 - in thunar/branches/migration-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Sat Apr 11 17:36:07 CEST 2009


Author: jannis
Date: 2009-04-11 15:36:06 +0000 (Sat, 11 Apr 2009)
New Revision: 29763

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/configure.in.in
   thunar/branches/migration-to-gio/thunar/Makefile.am
   thunar/branches/migration-to-gio/thunar/thunar-launcher.c
   thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c
Log:
	* configure.in.in, thunar/Makefile.am: Add optional dependency on
	  gio-unix-2.0.
	* thunar/thunar-launcher.c, thunar/thunar-sendto-model.c: Load sendto
	  handlers using GDesktopAppInfo (only supported on UNIX for whatever
	  reason). Update ThunarLauncher to use GAppInfo for handlers
	  retrieved from ThunarSendtoModel. Unfortunately, GIO doesn't support
	  checking whether a GAppInfo supports more than one file argument.
	  There's also no way to find out what MIME types a GAppInfo supports
	  which forces us to drop a few nice sanity checks in
	  thunar_sendto_model_get_matching().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-11 14:45:15 UTC (rev 29762)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-11 15:36:06 UTC (rev 29763)
@@ -1,5 +1,18 @@
 2009-04-11	Jannis Pohlmann <jannis at xfce.org>
 
+	* configure.in.in, thunar/Makefile.am: Add optional dependency on 
+	  gio-unix-2.0.
+	* thunar/thunar-launcher.c, thunar/thunar-sendto-model.c: Load sendto
+	  handlers using GDesktopAppInfo (only supported on UNIX for whatever
+	  reason). Update ThunarLauncher to use GAppInfo for handlers
+	  retrieved from ThunarSendtoModel. Unfortunately, GIO doesn't support
+	  checking whether a GAppInfo supports more than one file argument.
+	  There's also no way to find out what MIME types a GAppInfo supports
+	  which forces us to drop a few nice sanity checks in
+	  thunar_sendto_model_get_matching().
+
+2009-04-11	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-file.{c,h}: Add new macro
 	  thunar_file_get_default_handler() for querying the default GAppInfo
 	  to handle a ThunarFile. Use it in thunar_file_launch(). Fix pointer

Modified: thunar/branches/migration-to-gio/configure.in.in
===================================================================
--- thunar/branches/migration-to-gio/configure.in.in	2009-04-11 14:45:15 UTC (rev 29762)
+++ thunar/branches/migration-to-gio/configure.in.in	2009-04-11 15:36:06 UTC (rev 29763)
@@ -182,6 +182,14 @@
 XDT_CHECK_LIBSM()
 
 dnl **********************************
+dnl *** Optional GIO UNIX features ***
+dnl **********************************
+XDT_CHECK_OPTIONAL_PACKAGE([GIO_UNIX], [gio-unix-2.0],
+                           [2.16.0], [gio-unix], [GIO UNIX features])
+
+dnl *******************************************************
+dnl *** Optional support for gconf (GNOME thumbnailers) ***
+dnl **********************************
 dnl *** Optional support for D-BUS ***
 dnl **********************************
 XDT_CHECK_OPTIONAL_PACKAGE([DBUS], [dbus-glib-1],
@@ -507,6 +515,11 @@
 else
 echo "* D-BUS support:             no"
 fi
+if test x"$GIO_UNIX_FOUND" = x"yes"; then
+echo "* GIO UNIX features:         yes"
+else
+echo "* GIO UNIX features:         no"
+fi
 echo "* File System Monitor:       $ac_bm_thunar_vfs_monitor_impl"
 if test x"$GCONF_FOUND" = x"yes"; then
 echo "* GNOME Thumbnailers:        yes"

Modified: thunar/branches/migration-to-gio/thunar/Makefile.am
===================================================================
--- thunar/branches/migration-to-gio/thunar/Makefile.am	2009-04-11 14:45:15 UTC (rev 29762)
+++ thunar/branches/migration-to-gio/thunar/Makefile.am	2009-04-11 15:36:06 UTC (rev 29763)
@@ -240,6 +240,14 @@
 	$(DBUS_LIBS)
 endif
 
+if HAVE_GIO_UNIX
+Thunar_CFLAGS +=							\
+	$(GIO_UNIX_CFLAGS)
+
+Thunar_LDADD +=								\
+	$(GIO_UNIX_LIBS)
+endif
+
 desktopdir = $(datadir)/applications
 desktop_in_files = thunar-settings.desktop.in
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)

Modified: thunar/branches/migration-to-gio/thunar/thunar-launcher.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-launcher.c	2009-04-11 14:45:15 UTC (rev 29762)
+++ thunar/branches/migration-to-gio/thunar/thunar-launcher.c	2009-04-11 15:36:06 UTC (rev 29763)
@@ -1233,12 +1233,15 @@
   const gchar    *icon_name;
   const gchar    *label;
   GtkAction      *action;
+  GtkWidget      *image;
+  GtkWidget      *menu_item;
   gboolean        linkable = TRUE;
   GList          *handlers;
   GList          *volumes;
   GList          *lp;
   gchar          *name;
   gchar          *tooltip;
+  gchar          *ui_path;
   gint            n_selected_files;
   gint            n = 0;
 
@@ -1335,19 +1338,14 @@
           for (lp = handlers; lp != NULL; lp = lp->next, ++n)
             {
               /* generate a unique name and tooltip for the handler */
-              label = thunar_vfs_mime_handler_get_name (lp->data);
+              label = g_app_info_get_name (lp->data);
               name = g_strdup_printf ("thunar-launcher-sendto%d-%p", n, launcher);
               tooltip = g_strdup_printf (ngettext ("Send the selected file to \"%s\"",
                                                    "Send the selected files to \"%s\"",
                                                    n_selected_files), label);
 
-              /* check if we have an icon for this handler */
-              icon_name = thunar_vfs_mime_handler_lookup_icon_name (lp->data, icon_theme);
-              if (G_LIKELY (icon_name != NULL))
-                thunar_gtk_icon_factory_insert_icon (launcher->icon_factory, name, icon_name);
-
               /* allocate a new action for the handler */
-              action = gtk_action_new (name, label, tooltip, (icon_name != NULL) ? name : NULL);
+              action = gtk_action_new (name, label, tooltip, NULL);
               g_object_set_qdata_full (G_OBJECT (action), thunar_launcher_handler_quark, lp->data, g_object_unref);
               g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (thunar_launcher_action_open), launcher);
               gtk_action_group_add_action (launcher->action_group, action);
@@ -1359,6 +1357,25 @@
                                      name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
               g_object_unref (G_OBJECT (action));
 
+              /* FIXME There's no API for creating GtkActions using GIcon in GTK+ 2.14. A "gicon" property
+               * has been added to GtkAction in GTK+ 2.16 though. For now, this hack will have to do: */
+
+              ui_path = g_strconcat ("/main-menu/file-menu/sendto-menu/placeholder-sendto-actions/", name, NULL);
+              g_debug ("name = %s, ui_path = %s", name, ui_path);
+              menu_item = gtk_ui_manager_get_widget (launcher->ui_manager, ui_path);
+              image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menu_item));
+              gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (lp->data), GTK_ICON_SIZE_MENU);
+              g_free (ui_path);
+              	
+              ui_path = g_strconcat ("/file-context-menu/sendto-menu/placeholder-sendto-actions/", name, NULL);
+              g_debug ("name = %s, ui_path = %s", name, ui_path);
+              menu_item = gtk_ui_manager_get_widget (launcher->ui_manager, ui_path);
+              image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menu_item));
+              gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (lp->data), GTK_ICON_SIZE_MENU);
+              g_free (ui_path);
+
+              /* FIXME End of the hack */
+
               /* cleanup */
               g_free (tooltip);
               g_free (name);

Modified: thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c	2009-04-11 14:45:15 UTC (rev 29762)
+++ thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c	2009-04-11 15:36:06 UTC (rev 29763)
@@ -1,6 +1,7 @@
 /* $Id$ */
 /*-
  * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -28,6 +29,10 @@
 #include <string.h>
 #endif
 
+#ifdef HAVE_GIO_UNIX
+#include <gio/gdesktopappinfo.h>
+#endif
+
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-sendto-model.h>
 
@@ -134,11 +139,12 @@
 
 
 static gint
-tvma_compare (gconstpointer a,
-              gconstpointer b)
+g_app_info_compare (gpointer a,
+                    gpointer b)
 {
-  return strcmp (thunar_vfs_mime_application_get_desktop_id (b),
-                 thunar_vfs_mime_application_get_desktop_id (a));
+  g_debug ("a = %s, b = %s", g_app_info_get_name (a), g_app_info_get_name (b));
+  return g_utf8_collate (g_app_info_get_name (b),
+                         g_app_info_get_name (a));
 }
 
 
@@ -146,11 +152,10 @@
 static void
 thunar_sendto_model_load (ThunarSendtoModel *sendto_model)
 {
-  ThunarVfsMimeApplication *handler;
-  const gchar              *id;
-  gchar                   **specs;
-  gchar                    *path;
-  guint                     n;
+  GDesktopAppInfo *app_info = NULL;
+  gchar          **specs;
+  gchar           *path;
+  guint            n;
 
   /* lookup all sendto .desktop files */
   specs = xfce_resource_match (XFCE_RESOURCE_DATA, "Thunar/sendto/*.desktop", TRUE);
@@ -160,15 +165,18 @@
       path = xfce_resource_lookup (XFCE_RESOURCE_DATA, specs[n]);
       if (G_LIKELY (path != NULL))
         {
-          /* we use the filename as desktop-id */
-          id = specs[n] + (sizeof ("Thunar/sendto/") - 1);
-
+#ifdef HAVE_GIO_UNIX
           /* try to load the .desktop file */
-          handler = thunar_vfs_mime_application_new_from_file (path, id);
-          if (G_LIKELY (handler != NULL))
+          app_info = g_desktop_app_info_new_from_filename (path);
+#else
+          /* FIXME try to create the app info ourselves in a platform independent way */
+#endif
+          if (G_LIKELY (app_info != NULL))
             {
               /* add to our handler list, sorted by their desktop-ids (reverse order) */
-              sendto_model->handlers = g_list_insert_sorted (sendto_model->handlers, handler, tvma_compare);
+              sendto_model->handlers = g_list_insert_sorted (sendto_model->handlers, 
+                                                             G_APP_INFO (app_info),
+                                                             (GCompareFunc) g_app_info_compare);
             }
         }
 
@@ -239,8 +247,8 @@
  * @sendto_model : a #ThunarSendtoModel.
  * @files        : a #GList of #ThunarFile<!---->s.
  * 
- * Returns the list of #ThunarVfsMimeHandler<!---->s for the "Send To"
- * targets that support the specified @files.
+ * Returns the list of #GAppInfo<!---->s for the "Send To" targets that 
+ * support the specified @files.
  *
  * The returned list is owned by the caller and must be freed when no
  * longer needed, using:
@@ -249,23 +257,21 @@
  * g_list_free (list);
  * </programlisting></informalexample>
  *
- * Return value: a #GList of supported #ThunarVfsMimeHandler<!---->s as
+ * Return value: a #GList of supported #GAppInfo<!---->s as
  *               "Send To" targets for the specified @files.
  **/
 GList*
 thunar_sendto_model_get_matching (ThunarSendtoModel *sendto_model,
                                   GList             *files)
 {
-  ThunarVfsMimeHandlerFlags flags;
-  ThunarVfsMonitorHandle   *handle;
-  const gchar * const      *mime_types;
-  ThunarVfsPath            *path;
-  gchar                   **datadirs;
-  gchar                    *dir;
-  GList                    *handlers = NULL;
-  GList                    *hp;
-  GList                    *fp;
-  guint                     n;
+  ThunarVfsMonitorHandle *handle;
+  ThunarVfsPath          *path;
+  gchar                 **datadirs;
+  gchar                  *dir;
+  GList                  *handlers = NULL;
+  GList                  *hp;
+  GList                  *fp;
+  guint                   n;
 
   _thunar_return_val_if_fail (THUNAR_IS_SENDTO_MODEL (sendto_model), NULL);
 
@@ -304,13 +310,10 @@
   /* test all handlers */
   for (hp = sendto_model->handlers; hp != NULL; hp = hp->next)
     {
-      /* ignore the handler if it doesn't support multiple files, but we have more than one file */
-      flags = thunar_vfs_mime_handler_get_flags (THUNAR_VFS_MIME_HANDLER (hp->data));
-      if ((flags & THUNAR_VFS_MIME_HANDLER_SUPPORTS_MULTI) == 0 && files->next != NULL)
-        continue;
+      /* FIXME Ignore GAppInfos which don't support multiple file arguments */
 
       /* ignore the handler if it doesn't support URIs, but we don't have a local file */
-      if ((flags & THUNAR_VFS_MIME_HANDLER_SUPPORTS_URIS) == 0)
+      if (!g_app_info_supports_uris (hp->data))
         {
           /* check if we have any non-local files */
           for (fp = files; fp != NULL; fp = fp->next)
@@ -322,31 +325,8 @@
             continue;
         }
 
-      /* check if we need to test mime types for this handler */
-      mime_types = thunar_vfs_mime_application_get_mime_types (hp->data);
-      if (G_LIKELY (mime_types != NULL && *mime_types != NULL))
-        {
-          /* each file must match atleast one of the specified mime types */
-          for (fp = files; fp != NULL; fp = fp->next)
-            {
-              /* each file must be supported by one of the mime types */
-              for (n = 0; mime_types[n] != NULL; ++n)
-                if (thunarx_file_info_has_mime_type (fp->data, mime_types[n]))
-                  break;
+      /* FIXME Check if the GAppInfo supports all files */
 
-              /* check if all mime types failed */
-              if (mime_types[n] == NULL)
-                break;
-            }
-
-          /* check if atleast one file failed */
-          if (G_UNLIKELY (fp != NULL))
-            {
-              /* skip this handler */
-              continue;
-            }
-        }
-
       /* the handler is supported */
       handlers = g_list_prepend (handlers, g_object_ref (G_OBJECT (hp->data)));
     }




More information about the Xfce4-commits mailing list