[Xfce4-commits] r29109 - in thunar/branches/port-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Tue Jan 6 15:18:29 CET 2009


Author: jannis
Date: 2009-01-06 14:18:29 +0000 (Tue, 06 Jan 2009)
New Revision: 29109

Modified:
   thunar/branches/port-to-gio/ChangeLog
   thunar/branches/port-to-gio/TODO-GIO
   thunar/branches/port-to-gio/thunar/thunar-file.c
   thunar/branches/port-to-gio/thunar/thunar-launcher.c
Log:
	* TODO-GIO: Add desktop actions, icon infos and a few other things to
	  the TODO list.
	* thunar/thunar-file.c: Implement thunar_file_list_get_applications()
	  based on GIO. It now returns a list of GAppInfos which can handle
	  all files in the list.
	* thunar/thunar-launcher.c: Update thunar_launcher_update() to handle
	  GAppInfo lists. Unfortunately, due to GIO, there is no support for
	  desktop actions anymore (TODO item for that added though). Add
	  workaround for icons in context/file menu, because GtkAction has no
	  API for GIcon yet (bug report against GTK+ filed, will probably be
	  part of GTK+ 2.16).

Modified: thunar/branches/port-to-gio/ChangeLog
===================================================================
--- thunar/branches/port-to-gio/ChangeLog	2009-01-06 11:53:03 UTC (rev 29108)
+++ thunar/branches/port-to-gio/ChangeLog	2009-01-06 14:18:29 UTC (rev 29109)
@@ -1,3 +1,17 @@
+2009-01-06	Jannis Pohlmann <jannis at xfce.org>
+
+	* TODO-GIO: Add desktop actions, icon infos and a few other things to
+	  the TODO list.
+	* thunar/thunar-file.c: Implement thunar_file_list_get_applications()
+	  based on GIO. It now returns a list of GAppInfos which can handle
+	  all files in the list. 
+	* thunar/thunar-launcher.c: Update thunar_launcher_update() to handle
+	  GAppInfo lists. Unfortunately, due to GIO, there is no support for 
+	  desktop actions anymore (TODO item for that added though). Add
+	  workaround for icons in context/file menu, because GtkAction has no
+	  API for GIcon yet (bug report against GTK+ filed, will probably be
+	  part of GTK+ 2.16). 
+
 2008-12-23	Jannis Pohlmann <jannis at xfce.org>
 
 	* thunar/thunar-file.c: Implement more methods using GIO:
@@ -7,6 +21,7 @@
 	  thunar_file_get_icon_name().
 	* thunar/thunar-standard-view.c: Use thunar_file_cache_lookup_path()
 	  in thunar_standard_view_new_files() to fix a crash.
+
 2008-12-22	Jannis Pohlmann <jannis at xfce.org>
 
 	* AUTHORS: Add Nick and myself.

Modified: thunar/branches/port-to-gio/TODO-GIO
===================================================================
--- thunar/branches/port-to-gio/TODO-GIO	2009-01-06 11:53:03 UTC (rev 29108)
+++ thunar/branches/port-to-gio/TODO-GIO	2009-01-06 14:18:29 UTC (rev 29109)
@@ -4,3 +4,11 @@
 * Remove Thunar's own trash:// implementation and just use GIO/GVfs 
   for that. No special treatment needed. Right now browsing the trash
   makes Thunar crash.
+* Implement something like NautilusIconInfo or at least a function to
+  load GdPixbufs from GIcons.
+* Re-add support for desktop actions (Actions= key and "Desktop 
+  Action %s" sections in desktop entries) which is not part of the
+  desktop entry standard anymore but still very useful.
+* Properly detect desktop entries with [Desktop Entry] section and
+  either Exec or Link key as executable.
+* Update the API documentation.

Modified: thunar/branches/port-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-file.c	2009-01-06 11:53:03 UTC (rev 29108)
+++ thunar/branches/port-to-gio/thunar/thunar-file.c	2009-01-06 14:18:29 UTC (rev 29109)
@@ -2484,31 +2484,35 @@
  * g_list_free (list);
  * </programlisting></informalexample>
  *
- * Return value: the list of #ThunarVfsMimeApplication<!---->s that
- *               can be used to open all items in the @file_list.
+ * Return value: the list of #GAppInfo<!---->s that can be used 
+ *               to open all items in the @file_list.
  **/
 GList*
 thunar_file_list_get_applications (GList *file_list)
 {
-  ThunarVfsMimeDatabase *database;
-  GList                 *applications = NULL;
-  GList                 *list;
-  GList                 *next;
-  GList                 *ap;
-  GList                 *lp;
+  GList       *applications = NULL;
+  GList       *list;
+  GList       *next;
+  GList       *ap;
+  GList       *lp;
+  const gchar *previous_type;
+  const gchar *current_type;
 
-  /* grab a reference on the mime database */
-  database = thunar_vfs_mime_database_get_default ();
-
   /* determine the set of applications that can open all files */
   for (lp = file_list; lp != NULL; lp = lp->next)
     {
+      current_type = g_file_info_get_content_type (THUNAR_FILE (lp->data)->ginfo);
+
       /* no need to check anything if this file has the same mime type as the previous file */
-      if (lp->prev != NULL && thunar_file_get_mime_info (lp->prev->data) == thunar_file_get_mime_info (lp->data))
-        continue;
+      if (lp->prev != NULL)
+        {
+          previous_type = g_file_info_get_content_type (THUNAR_FILE (lp->prev->data)->ginfo);
+          if (G_LIKELY (g_content_type_equals (previous_type, current_type)))
+            continue;
+        }
 
       /* determine the list of applications that can open this file */
-      list = thunar_vfs_mime_database_get_applications (database, thunar_file_get_mime_info (lp->data));
+      list = g_app_info_get_all_for_type (current_type);
       if (G_UNLIKELY (applications == NULL))
         {
           /* first file, so just use the applications list */
@@ -2543,9 +2547,6 @@
         break;
     }
 
-  /* release the mime database */
-  g_object_unref (G_OBJECT (database));
-
   return applications;
 }
 

Modified: thunar/branches/port-to-gio/thunar/thunar-launcher.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-launcher.c	2009-01-06 11:53:03 UTC (rev 29108)
+++ thunar/branches/port-to-gio/thunar/thunar-launcher.c	2009-01-06 14:18:29 UTC (rev 29109)
@@ -724,9 +724,10 @@
 thunar_launcher_update (ThunarLauncher *launcher)
 {
   GtkIconTheme *icon_theme;
-  const gchar  *icon_name;
   const gchar  *context_menu_path;
   const gchar  *file_menu_path;
+  GtkWidget    *menu_item;
+  GtkWidget    *image;
   GtkAction    *action;
   gboolean      default_is_open_with_other = FALSE;
   GList        *applications;
@@ -735,6 +736,7 @@
   gchar        *tooltip;
   gchar        *label;
   gchar        *name;
+  gchar        *ui_path;
   gint          n_directories = 0;
   gint          n_executables = 0;
   gint          n_regulars = 0;
@@ -848,9 +850,6 @@
       /* determine the set of applications that work for all selected files */
       applications = thunar_file_list_get_applications (launcher->selected_files);
 
-      /* reset the desktop actions list */
-      actions = NULL;
-
       /* check if we have only executable files in the selection */
       if (G_UNLIKELY (n_executables == n_selected_files))
         {
@@ -863,10 +862,10 @@
       else if (G_LIKELY (applications != NULL))
         {
           /* turn the "Open" action into "Open With DEFAULT" */
-          label = g_strdup_printf (_("_Open With \"%s\""), thunar_vfs_mime_application_get_name (applications->data));
+          label = g_strdup_printf (_("_Open With \"%s\""), g_app_info_get_name (applications->data));
           tooltip = g_strdup_printf (ngettext ("Use \"%s\" to open the selected file",
                                                "Use \"%s\" to open the selected files",
-                                               n_selected_files), thunar_vfs_mime_application_get_name (applications->data));
+                                               n_selected_files), g_app_info_get_name (applications->data));
           g_object_set (G_OBJECT (launcher->action_open),
                         "label", label,
                         "tooltip", tooltip,
@@ -877,9 +876,6 @@
           /* remember the default application for the "Open" action */
           g_object_set_qdata_full (G_OBJECT (launcher->action_open), thunar_launcher_handler_quark, applications->data, g_object_unref);
 
-          /* add the desktop actions for this application */
-          actions = g_list_concat (actions, thunar_vfs_mime_application_get_actions (applications->data));
-
           /* drop the default application from the list */
           applications = g_list_remove (applications, applications->data);
         }
@@ -947,23 +943,15 @@
           /* process all applications and determine the desktop actions */
           for (lp = applications, n = 0; lp != NULL; lp = lp->next, ++n)
             {
-              /* determine the desktop actions for this application */
-              actions = g_list_concat (actions, thunar_vfs_mime_application_get_actions (lp->data));
-
               /* generate a unique label, unique id and tooltip for the application's action */
               name = g_strdup_printf ("thunar-launcher-addon-application%d-%p", n, launcher);
-              label = g_strdup_printf (_("Open With \"%s\""), thunar_vfs_mime_application_get_name (lp->data));
+              label = g_strdup_printf (_("Open With \"%s\""), g_app_info_get_name (lp->data));
               tooltip = g_strdup_printf (ngettext ("Use \"%s\" to open the selected file",
                                                    "Use \"%s\" to open the selected files",
-                                                   n_selected_files), thunar_vfs_mime_application_get_name (lp->data));
+                                                   n_selected_files), g_app_info_get_name (lp->data));
 
-              /* check if we have an icon for this application */
-              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 application */
-              action = gtk_action_new (name, label, tooltip, (icon_name != NULL) ? name : NULL);
+              action = gtk_action_new (name, label, tooltip, NULL);
               gtk_action_group_add_action (launcher->action_group, action);
               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);
@@ -975,57 +963,31 @@
                                      GTK_UI_MANAGER_MENUITEM, FALSE);
               g_object_unref (G_OBJECT (action));
 
-              /* cleanup */
-              g_free (tooltip);
-              g_free (label);
-              g_free (name);
-            }
+              /* FIXME: There's no API for create GtkActions using GIcon in GTK+ at the moment. 
+               * This will hopefully be added in GTK+ 2.16. For now this hack will have to do: */
 
-          /* cleanup */
-          g_list_free (applications);
-        }
+              ui_path = g_strconcat (file_menu_path, "/", name, NULL);
+              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);
 
-      /* check if we have any desktop actions */
-      if (G_UNLIKELY (actions != NULL))
-        {
-          /* add separator before the desktop actions */
-          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
-                                 "/main-menu/file-menu/placeholder-launcher/placeholder-actions",
-                                 "separator", NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
-          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
-                                 "/file-context-menu/placeholder-launcher/placeholder-actions",
-                                 "separator", NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
+              ui_path = g_strconcat (context_menu_path, "/", name, NULL);
+              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);
 
-          /* process all actions and add them to the UI manager */
-          for (lp = actions, n = 0; lp != NULL; lp = lp->next, ++n)
-            {
-              /* generate a unique name for the mime action */
-              name = g_strdup_printf ("thunar-launcher-addon-action%d-%p", n, launcher);
+              /* FIXME: End of the hack */
 
-              /* check if we have an icon for this action */
-              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 ui action for the mime action */
-              action = gtk_action_new (name, thunar_vfs_mime_handler_get_name (lp->data), NULL, (icon_name != NULL) ? name : NULL);
-              gtk_action_group_add_action (launcher->action_group, action);
-              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_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
-                                     "/main-menu/file-menu/placeholder-launcher/placeholder-actions",
-                                     name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
-              gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
-                                     "/file-context-menu/placeholder-launcher/placeholder-actions",
-                                     name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
-              g_object_unref (G_OBJECT (action));
-
               /* cleanup */
+              g_free (tooltip);
+              g_free (label);
               g_free (name);
             }
 
           /* cleanup */
-          g_list_free (actions);
+          g_list_free (applications);
         }
     }
 




More information about the Xfce4-commits mailing list