[gnome-menus] Rebase DesktopEntry on GDesktopAppInfo



commit 4d00dcf9ce31b248c61dc66430b881ba32e2d611
Author: Colin Walters <walters verbum org>
Date:   Sat Apr 16 14:09:57 2011 -0400

    Rebase DesktopEntry on GDesktopAppInfo
    
    The main motivation for this work is to avoid gnome-shell having
    to read all .desktop files *twice* - once from gnome-menus, and
    once from gio (when doing MIME assocation etc.)
    
    This patch replaces almost all of the accessors for GMenuTreeEntry
    with the simple gmenu_tree_entry_get_app_info().
    
    Note this patch depends on patches from (see bug 647967).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=647968

 configure.ac              |    8 +-
 libmenu/Makefile.am       |    6 +-
 libmenu/desktop-entries.c |  387 ++++++++++++++++-----------------------------
 libmenu/desktop-entries.h |   22 +--
 libmenu/gmenu-tree.c      |   92 +----------
 libmenu/gmenu-tree.h      |   10 +-
 python/Makefile.am        |    4 +-
 python/gmenu.c            |   25 ++-
 util/Makefile.am          |    4 +-
 9 files changed, 179 insertions(+), 379 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2417d7f..e9361aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ GNOME_MAINTAINER_MODE_DEFINES
 #   change to C+1:0:0
 # - If the interface is the same as the previous version, change to C:R+1:A
 
-LIB_MENU_LT_VERSION=6:13:4
+LIB_MENU_LT_VERSION=7:0:0
 AC_SUBST(LIB_MENU_LT_VERSION)
 
 GETTEXT_PACKAGE=gnome-menus
@@ -38,9 +38,9 @@ AC_ARG_PROGRAM
 AC_LIBTOOL_WIN32_DLL
 AM_PROG_LIBTOOL
 
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.6.0 gio-2.0 >= 2.15.2)
-AC_SUBST(GLIB_CFLAGS)
-AC_SUBST(GLIB_LIBS)
+PKG_CHECK_MODULES(GIO_UNIX, gio-unix-2.0 >= 2.28.5)
+AC_SUBST(GIO_UNIX_CFLAGS)
+AC_SUBST(GIO_UNIX_LIBS)
 
 GNOME_COMPILE_WARNINGS(yes)
 
diff --git a/libmenu/Makefile.am b/libmenu/Makefile.am
index a015e05..33721a7 100644
--- a/libmenu/Makefile.am
+++ b/libmenu/Makefile.am
@@ -1,7 +1,7 @@
 lib_LTLIBRARIES = libgnome-menu.la
 
 AM_CPPFLAGS =				\
-	$(GLIB_CFLAGS)			\
+	$(GIO_UNIX_CFLAGS)		\
 	-DGMENU_I_KNOW_THIS_IS_UNSTABLE	\
 	$(DISABLE_DEPRECATED_CFLAGS)	\
 	$(DEBUG_CFLAGS)
@@ -32,7 +32,7 @@ libgnome_menu_la_SOURCES =		\
 	menu-util.h
 
 libgnome_menu_la_LIBADD = 		\
-	$(GLIB_LIBS)
+	$(GIO_UNIX_LIBS)
 
 libgnome_menu_la_LDFLAGS =			\
 	-version-info $(LIB_MENU_LT_VERSION)	\
@@ -59,7 +59,7 @@ if HAVE_INTROSPECTION
 introspection_sources = $(libgnome_menu_include_HEADERS)
 
 GMenu-2.0.gir: libgnome-menu.la
-GMenu_2_0_gir_INCLUDES = GObject-2.0
+GMenu_2_0_gir_INCLUDES = Gio-2.0
 GMenu_2_0_gir_CFLAGS = $(AM_CPPFLAGS)
 GMenu_2_0_gir_LIBS = libgnome-menu.la
 GMenu_2_0_gir_SCANNERFLAGS = --identifier-prefix=GMenu --symbol-prefix=gmenu --pkg-export=libgnome-menu
diff --git a/libmenu/desktop-entries.c b/libmenu/desktop-entries.c
index 85005c3..a32caab 100644
--- a/libmenu/desktop-entries.c
+++ b/libmenu/desktop-entries.c
@@ -20,6 +20,7 @@
 #include <config.h>
 
 #include "desktop-entries.h"
+#include <gio/gdesktopappinfo.h>
 
 #include <string.h>
 
@@ -35,37 +36,28 @@ struct DesktopEntry
   char *path;
   const char *basename;
 
-  char     *name;
-  char     *comment;
-  char     *icon;
-
   guint    type              : 2;
-  guint    show_in_gnome     : 1;
-  guint    nodisplay         : 1;
-  guint    hidden            : 1;
-  guint    reserved          : 27;
+  guint    reserved          : 30;
 };
 
 typedef struct 
 {
   DesktopEntry base;
 
+  GDesktopAppInfo *appinfo;
   GQuark   *categories;
-
-  char     *generic_name;
-  char     *full_name;
-  char     *exec;
-  char     *try_exec;
-
-  guint    terminal          : 1;
-  guint    tryexec_evaluated : 1;
-  guint    tryexec_failed    : 1;
-  guint    reserved          : 29;
 } DesktopEntryDesktop;
 
 typedef struct
 {
   DesktopEntry base;
+
+  char     *name;
+  char     *comment;
+  char     *icon;
+
+  guint    nodisplay         : 1;
+  guint    hidden            : 1;
 } DesktopEntryDirectory;
 
 struct DesktopEntrySet
@@ -143,53 +135,20 @@ key_file_get_show_in_gnome (GKeyFile  *key_file,
   return show_in_gnome;
 }
 
-static GQuark *
-get_categories_from_key_file (GKeyFile     *key_file,
-                              const char   *desktop_entry_group)
-{
-  GQuark  *retval;
-  char   **strv;
-  gsize    len;
-  int      i;
-
-  strv = g_key_file_get_string_list (key_file,
-                                     desktop_entry_group,
-                                     "Categories",
-                                     &len,
-                                     NULL);
-  if (!strv)
-    return NULL;
-
-  retval = g_new0 (GQuark, len + 1);
-
-  for (i = 0; strv[i]; i++)
-    retval[i] = g_quark_from_string (strv[i]);
-
-  g_strfreev (strv);
-
-  return retval;
-}
-
 static gboolean
-desktop_entry_load_base (DesktopEntry *entry,
-			 GKeyFile     *key_file,
-			 const char   *desktop_entry_group,
-			 GError      **error)
+desktop_entry_load_directory (DesktopEntry *entry,
+			      GKeyFile     *key_file,
+			      const char   *desktop_entry_group,
+			      GError      **error)
 {
+  DesktopEntryDirectory *entry_directory = (DesktopEntryDirectory*)entry;
   char *type_str;
 
-  type_str = g_key_file_get_string (key_file, desktop_entry_group, "Type", NULL);
+  type_str = g_key_file_get_string (key_file, desktop_entry_group, "Type", error);
   if (!type_str)
-    {
-      g_set_error (error,
-		   G_KEY_FILE_ERROR,
-		   G_KEY_FILE_ERROR_INVALID_VALUE,
-		   "\"%s\" contains no \"Type\" key\n", entry->path);
-      return FALSE;
-    }
+    return FALSE;
 
-  if ((entry->type == DESKTOP_ENTRY_DESKTOP && strcmp (type_str, "Application") != 0) ||
-      (entry->type == DESKTOP_ENTRY_DIRECTORY && strcmp (type_str, "Directory") != 0))
+  if (strcmp (type_str, "Directory") != 0)
     {
       g_set_error (error,
 		   G_KEY_FILE_ERROR,
@@ -201,52 +160,24 @@ desktop_entry_load_base (DesktopEntry *entry,
 
   g_free (type_str);
 
-  entry->name         = g_key_file_get_locale_string (key_file, desktop_entry_group, "Name", NULL, error);
-  if (entry->name == NULL)
+  /* Just skip stuff that's not GNOME */
+  if (!key_file_get_show_in_gnome (key_file, desktop_entry_group))
     return FALSE;
 
-  entry->comment      = g_key_file_get_locale_string (key_file, desktop_entry_group, "Comment", NULL, NULL);
-  entry->icon         = g_key_file_get_locale_string (key_file, desktop_entry_group, "Icon", NULL, NULL);
-  entry->nodisplay    = g_key_file_get_boolean (key_file,
-						 desktop_entry_group,
-						 "NoDisplay",
-						 NULL);
-  entry->hidden       = g_key_file_get_boolean (key_file,
-						 desktop_entry_group,
-						 "Hidden",
-						 NULL);
-  entry->show_in_gnome = key_file_get_show_in_gnome (key_file, desktop_entry_group);
-
-  return TRUE;
-}
-
-static gboolean
-desktop_entry_load_desktop (DesktopEntry  *entry,
-			    GKeyFile      *key_file,
-			    const char    *desktop_entry_group,
-			    GError       **error)
-{
-  DesktopEntryDesktop *desktop_entry;
-
-  desktop_entry = (DesktopEntryDesktop*)entry;
-
-  desktop_entry->exec = g_key_file_get_string (key_file, desktop_entry_group, "Exec", error);
-
-  if (desktop_entry->exec == NULL)
+  entry_directory->name = g_key_file_get_locale_string (key_file, desktop_entry_group, "Name", NULL, error);
+  if (entry_directory->name == NULL)
     return FALSE;
 
-  desktop_entry->categories   = get_categories_from_key_file (key_file, desktop_entry_group);
-  desktop_entry->generic_name = g_key_file_get_locale_string (key_file, desktop_entry_group, "GenericName", NULL, NULL);
-  desktop_entry->full_name    = g_key_file_get_locale_string (key_file, desktop_entry_group, "X-GNOME-FullName", NULL, NULL);
-  desktop_entry->try_exec     = g_key_file_get_string (key_file,
-						       desktop_entry_group,
-						       "TryExec",
-						       NULL);
-  /* why are we stripping tryexec but not exec? */
-  if (desktop_entry->try_exec != NULL)
-    desktop_entry->try_exec = g_strstrip (desktop_entry->try_exec);
-  desktop_entry->terminal = g_key_file_get_boolean (key_file, desktop_entry_group, "Terminal", NULL);
-
+  entry_directory->comment      = g_key_file_get_locale_string (key_file, desktop_entry_group, "Comment", NULL, NULL);
+  entry_directory->icon         = g_key_file_get_locale_string (key_file, desktop_entry_group, "Icon", NULL, NULL);
+  entry_directory->nodisplay    = g_key_file_get_boolean (key_file,
+							  desktop_entry_group,
+							  "NoDisplay",
+							  NULL);
+  entry_directory->hidden       = g_key_file_get_boolean (key_file,
+							  desktop_entry_group,
+							  "Hidden",
+							  NULL);
   return TRUE;
 }
 
@@ -258,50 +189,67 @@ desktop_entry_load (DesktopEntry *entry)
   gboolean          retval = FALSE;
   const char       *desktop_entry_group;
 
-  key_file = g_key_file_new ();
-
-  if (!g_key_file_load_from_file (key_file, entry->path, 0, &error))
-    goto out;
-
-  if (g_key_file_has_group (key_file, DESKTOP_ENTRY_GROUP))
-    desktop_entry_group = DESKTOP_ENTRY_GROUP;
-  else
+  if (entry->type == DESKTOP_ENTRY_DESKTOP)
     {
-      if (g_key_file_has_group (key_file, KDE_DESKTOP_ENTRY_GROUP))
-	desktop_entry_group = KDE_DESKTOP_ENTRY_GROUP;
-      else
+      DesktopEntryDesktop *entry_desktop = (DesktopEntryDesktop*)entry;
+      const char *categories_str;
+
+      entry_desktop->appinfo = g_desktop_app_info_new_from_filename (entry->path);
+      if (!entry_desktop->appinfo)
 	{
-	  g_set_error (&error,
-		       G_KEY_FILE_ERROR,
-		       G_KEY_FILE_ERROR_INVALID_VALUE,
-		       "Desktop file does not have Desktop group");
-	  goto out;
+	  menu_verbose ("Failed to load \"%s\"\n", entry->path);
+	  return FALSE;
 	}
-    }
 
-  if (!desktop_entry_load_base (entry, key_file, desktop_entry_group, &error))
-    goto out;
+      categories_str = g_desktop_app_info_get_categories (entry_desktop->appinfo);
+      if (categories_str)
+	{
+	  char **categories;
+	  int i;
 
-  if (entry->type == DESKTOP_ENTRY_DESKTOP)
-    {
-      if (!desktop_entry_load_desktop (entry, key_file, desktop_entry_group, &error))
-	goto out;
+	  categories = g_strsplit (categories_str, ";", -1);
+	  entry_desktop->categories = g_new0 (GQuark, g_strv_length (categories) + 1);
+      
+	  for (i = 0; categories[i]; i++)
+	    entry_desktop->categories[i] = g_quark_from_string (categories[i]);
+	  
+	  g_strfreev (categories);
+	}
+
+      return TRUE;
     }
   else if (entry->type == DESKTOP_ENTRY_DIRECTORY)
     {
+      key_file = g_key_file_new ();
+      
+      if (!g_key_file_load_from_file (key_file, entry->path, 0, &error))
+	goto out;
+      
+      if (g_key_file_has_group (key_file, DESKTOP_ENTRY_GROUP))
+	desktop_entry_group = DESKTOP_ENTRY_GROUP;
+      else
+	{
+	  if (g_key_file_has_group (key_file, KDE_DESKTOP_ENTRY_GROUP))
+	    desktop_entry_group = KDE_DESKTOP_ENTRY_GROUP;
+	  else
+	    {
+	      g_set_error (&error,
+			   G_KEY_FILE_ERROR,
+			   G_KEY_FILE_ERROR_INVALID_VALUE,
+			   "Desktop file does not have Desktop group");
+	      goto out;
+	    }
+	}
+
+      if (!desktop_entry_load_directory (entry, key_file, desktop_entry_group, &error))
+	goto out;
+
+      g_key_file_free (key_file);
     }
   else
     g_assert_not_reached ();
   
-  retval = TRUE;
  out:
-  if (!retval)
-    {
-      menu_verbose ("Failed to load \"%s\": %s\n",
-		    entry->path, error->message);
-      g_clear_error (&error);
-    }
-  g_key_file_free (key_file);
   return retval;
 }
 
@@ -351,36 +299,28 @@ desktop_entry_reload (DesktopEntry *entry)
 
   menu_verbose ("Re-loading desktop entry \"%s\"\n", entry->path);
 
-  g_free (entry->name);
-  entry->name = NULL;
-
-  g_free (entry->comment);
-  entry->comment = NULL;
-
-  g_free (entry->icon);
-  entry->icon = NULL;
-
   if (entry->type == DESKTOP_ENTRY_DESKTOP)
     {
       DesktopEntryDesktop *entry_desktop = (DesktopEntryDesktop *) entry;
 
+      g_object_unref (entry_desktop->appinfo);
+      entry_desktop->appinfo = NULL;
+
       g_free (entry_desktop->categories);
       entry_desktop->categories = NULL;
-
-      g_free (entry_desktop->generic_name);
-      entry_desktop->generic_name = NULL;
-
-      g_free (entry_desktop->full_name);
-      entry_desktop->full_name = NULL;
-
-      g_free (entry_desktop->exec);
-      entry_desktop->exec = NULL;
-
-      g_free (entry_desktop->try_exec);
-      entry_desktop->try_exec = NULL;
     }
   else if (entry->type == DESKTOP_ENTRY_DIRECTORY)
     {
+      DesktopEntryDirectory *entry_directory = (DesktopEntryDirectory*) entry;
+
+      g_free (entry_directory->name);
+      entry_directory->name = NULL;
+      
+      g_free (entry_directory->comment);
+      entry_directory->comment = NULL;
+      
+      g_free (entry_directory->icon);
+      entry_directory->icon = NULL;
     }
   else
     g_assert_not_reached ();
@@ -424,27 +364,12 @@ desktop_entry_copy (DesktopEntry *entry)
   retval->type         = entry->type;
   retval->path         = g_strdup (entry->path);
   retval->basename     = unix_basename_from_path (retval->path);
-  retval->name         = g_strdup (entry->name);
-  retval->comment      = g_strdup (entry->comment);
-  retval->icon         = g_strdup (entry->icon);
-
-  retval->show_in_gnome     = entry->show_in_gnome; 
-  retval->nodisplay         = entry->nodisplay;
-  retval->hidden            = entry->hidden;
 
   if (retval->type == DESKTOP_ENTRY_DESKTOP)
     {
       DesktopEntryDesktop *desktop_entry = (DesktopEntryDesktop*) entry;
       DesktopEntryDesktop *retval_desktop_entry = (DesktopEntryDesktop*) retval;
 
-      retval_desktop_entry->generic_name = g_strdup (desktop_entry->generic_name);
-      retval_desktop_entry->full_name    = g_strdup (desktop_entry->full_name);
-      retval_desktop_entry->exec         = g_strdup (desktop_entry->exec);
-      retval_desktop_entry->try_exec     = g_strdup (desktop_entry->try_exec);
-      retval_desktop_entry->terminal          = desktop_entry->terminal;
-      retval_desktop_entry->tryexec_evaluated = desktop_entry->tryexec_evaluated;
-      retval_desktop_entry->tryexec_failed    = desktop_entry->tryexec_failed;
-      
       i = 0;
       if (desktop_entry->categories != NULL)
 	{
@@ -460,6 +385,17 @@ desktop_entry_copy (DesktopEntry *entry)
 	    retval_desktop_entry->categories[i] = desktop_entry->categories[i];
 	}
     }
+  else if (entry->type == DESKTOP_ENTRY_DIRECTORY)
+    {
+      DesktopEntryDirectory *entry_directory = (DesktopEntryDirectory*)entry;
+      DesktopEntryDirectory *retval_directory = (DesktopEntryDirectory*)retval;
+
+      retval_directory->name         = g_strdup (entry_directory->name);
+      retval_directory->comment      = g_strdup (entry_directory->comment);
+      retval_directory->icon         = g_strdup (entry_directory->icon);
+      retval_directory->nodisplay         = entry_directory->nodisplay;
+      retval_directory->hidden            = entry_directory->hidden;
+    }
 
   return retval;
 }
@@ -476,28 +412,26 @@ desktop_entry_unref (DesktopEntry *entry)
 
   g_free (entry->path);
   entry->path = NULL;
-  
-  g_free (entry->name);
-  entry->name = NULL;
-
-  g_free (entry->comment);
-  entry->comment = NULL;
-
-  g_free (entry->icon);
-  entry->icon = NULL;
-
 
   if (entry->type == DESKTOP_ENTRY_DESKTOP)
     {
       DesktopEntryDesktop *desktop_entry = (DesktopEntryDesktop*) entry;
       g_free (desktop_entry->categories);
-      g_free (desktop_entry->generic_name);
-      g_free (desktop_entry->full_name);
-      g_free (desktop_entry->exec);
-      g_free (desktop_entry->try_exec);
+      if (desktop_entry->appinfo)
+	g_object_unref (desktop_entry->appinfo);
     }
   else if (entry->type == DESKTOP_ENTRY_DIRECTORY)
     {
+      DesktopEntryDirectory *entry_directory = (DesktopEntryDirectory*) entry;
+
+      g_free (entry_directory->name);
+      entry_directory->name = NULL;
+      
+      g_free (entry_directory->comment);
+      entry_directory->comment = NULL;
+
+      g_free (entry_directory->icon);
+      entry_directory->icon = NULL;
     }
   else
     g_assert_not_reached ();
@@ -526,97 +460,48 @@ desktop_entry_get_basename (DesktopEntry *entry)
 const char *
 desktop_entry_get_name (DesktopEntry *entry)
 {
-  return entry->name;
-}
-
-const char *
-desktop_entry_get_generic_name (DesktopEntry *entry)
-{
-  if (entry->type != DESKTOP_ENTRY_DESKTOP)
-    return NULL;
-  return ((DesktopEntryDesktop*)entry)->generic_name;
-}
-
-const char *
-desktop_entry_get_full_name (DesktopEntry *entry)
-{
-  if (entry->type != DESKTOP_ENTRY_DESKTOP)
-    return NULL;
-  return ((DesktopEntryDesktop*)entry)->full_name;
+  if (entry->type == DESKTOP_ENTRY_DESKTOP)
+    return g_app_info_get_name (G_APP_INFO (((DesktopEntryDesktop*)entry)->appinfo));
+  return ((DesktopEntryDirectory*)entry)->name;
 }
 
 const char *
 desktop_entry_get_comment (DesktopEntry *entry)
 {
-  return entry->comment;
+  if (entry->type == DESKTOP_ENTRY_DESKTOP)
+    return g_app_info_get_description (G_APP_INFO (((DesktopEntryDesktop*)entry)->appinfo));
+  return ((DesktopEntryDirectory*)entry)->comment;
 }
 
 const char *
-desktop_entry_get_icon (DesktopEntry *entry)
+desktop_entry_desktop_get_icon (DesktopEntry *entry)
 {
-  return entry->icon;
-}
-
-const char *
-desktop_entry_get_exec (DesktopEntry *entry)
-{
-  if (entry->type != DESKTOP_ENTRY_DESKTOP)
-    return NULL;
-  return ((DesktopEntryDesktop*)entry)->exec;
+  g_return_val_if_fail (entry->type == DESKTOP_ENTRY_DIRECTORY, NULL);
+  return ((DesktopEntryDirectory*)entry)->icon;
 }
 
 gboolean
-desktop_entry_get_launch_in_terminal (DesktopEntry *entry)
+desktop_entry_get_no_display (DesktopEntry *entry)
 {
-  if (entry->type != DESKTOP_ENTRY_DESKTOP)
-    return FALSE;
-  return ((DesktopEntryDesktop*)entry)->terminal;
+  if (entry->type == DESKTOP_ENTRY_DESKTOP)
+    return g_desktop_app_info_get_is_hidden (((DesktopEntryDesktop*)entry)->appinfo);
+  return ((DesktopEntryDirectory*)entry)->nodisplay;
 }
 
 gboolean
 desktop_entry_get_hidden (DesktopEntry *entry)
 {
-  return entry->hidden;
-}
-
-gboolean
-desktop_entry_get_no_display (DesktopEntry *entry)
-{
-  return entry->nodisplay;
+  if (entry->type == DESKTOP_ENTRY_DESKTOP)
+    return g_desktop_app_info_get_is_hidden (((DesktopEntryDesktop*)entry)->appinfo);
+  return ((DesktopEntryDirectory*)entry)->hidden;
 }
 
-gboolean
-desktop_entry_get_show_in_gnome (DesktopEntry *entry)
-{
-  return entry->show_in_gnome;
-}
 
-gboolean
-desktop_entry_get_tryexec_failed (DesktopEntry *entry)
+GDesktopAppInfo  *
+desktop_entry_get_app_info (DesktopEntry *entry)
 {
-  DesktopEntryDesktop *desktop_entry;
-
-  if (entry->type != DESKTOP_ENTRY_DESKTOP)
-    return FALSE;
-  desktop_entry = (DesktopEntryDesktop*) entry;
-
-  if (desktop_entry->try_exec == NULL)
-    return FALSE;
-
-  if (!desktop_entry->tryexec_evaluated)
-    {
-      char *path;
-
-      desktop_entry->tryexec_evaluated = TRUE;
-
-      path = g_find_program_in_path (desktop_entry->try_exec);
-
-      desktop_entry->tryexec_failed = (path == NULL);
-
-      g_free (path);
-    }
-
-  return desktop_entry->tryexec_failed;
+  g_return_val_if_fail (entry->type == DESKTOP_ENTRY_DESKTOP, NULL);
+  return ((DesktopEntryDesktop*)entry)->appinfo;
 }
 
 gboolean
diff --git a/libmenu/desktop-entries.h b/libmenu/desktop-entries.h
index f3b4b7a..f05369c 100644
--- a/libmenu/desktop-entries.h
+++ b/libmenu/desktop-entries.h
@@ -20,7 +20,7 @@
 #ifndef __DESKTOP_ENTRIES_H__
 #define __DESKTOP_ENTRIES_H__
 
-#include <glib.h>
+#include <gio/gdesktopappinfo.h>
 
 G_BEGIN_DECLS
 
@@ -43,20 +43,16 @@ void          desktop_entry_unref  (DesktopEntry *entry);
 DesktopEntryType  desktop_entry_get_type     (DesktopEntry *entry);
 const char       *desktop_entry_get_path     (DesktopEntry *entry);
 const char       *desktop_entry_get_basename (DesktopEntry *entry);
+const char       *desktop_entry_get_name  (DesktopEntry *entry);
+const char       *desktop_entry_get_comment  (DesktopEntry *entry);
+gboolean          desktop_entry_get_no_display (DesktopEntry *entry);
+gboolean          desktop_entry_get_hidden (DesktopEntry *entry);
 
-const char *desktop_entry_get_name               (DesktopEntry *entry);
-const char *desktop_entry_get_generic_name       (DesktopEntry *entry);
-const char *desktop_entry_get_full_name          (DesktopEntry *entry);
-const char *desktop_entry_get_comment            (DesktopEntry *entry);
-const char *desktop_entry_get_icon               (DesktopEntry *entry);
-const char *desktop_entry_get_exec               (DesktopEntry *entry);
-gboolean    desktop_entry_get_launch_in_terminal (DesktopEntry *entry);
-
-gboolean desktop_entry_get_hidden         (DesktopEntry *entry);
-gboolean desktop_entry_get_no_display     (DesktopEntry *entry);
-gboolean desktop_entry_get_show_in_gnome  (DesktopEntry *entry);
-gboolean desktop_entry_get_tryexec_failed (DesktopEntry *entry);
+/* Only valid for DESKTOP_ENTRY_DIRECTORY */
+const char * desktop_entry_desktop_get_icon (DesktopEntry *entry);
 
+/* Only valid for DESKTOP_ENTRY_DESKTOP */
+GDesktopAppInfo  *desktop_entry_get_app_info (DesktopEntry *entry);
 gboolean desktop_entry_has_categories (DesktopEntry *entry);
 gboolean desktop_entry_has_category   (DesktopEntry *entry,
                                        const char   *category);
diff --git a/libmenu/gmenu-tree.c b/libmenu/gmenu-tree.c
index 0cb9645..1abefa0 100644
--- a/libmenu/gmenu-tree.c
+++ b/libmenu/gmenu-tree.c
@@ -1047,7 +1047,7 @@ gmenu_tree_directory_get_icon (GMenuTreeDirectory *directory)
   if (!directory->directory_entry)
     return NULL;
 
-  return desktop_entry_get_icon (directory->directory_entry);
+  return desktop_entry_desktop_get_icon (directory->directory_entry);
 }
 
 const char *
@@ -1148,66 +1148,12 @@ gmenu_tree_directory_make_path (GMenuTreeDirectory *directory,
   return g_string_free (path, FALSE);
 }
 
-const char *
-gmenu_tree_entry_get_name (GMenuTreeEntry *entry)
-{
-  g_return_val_if_fail (entry != NULL, NULL);
-
-  return desktop_entry_get_name (entry->desktop_entry);
-}
-
-const char *
-gmenu_tree_entry_get_generic_name (GMenuTreeEntry *entry)
-{
-  g_return_val_if_fail (entry != NULL, NULL);
-
-  return desktop_entry_get_generic_name (entry->desktop_entry);
-}
-
-const char *
-gmenu_tree_entry_get_display_name (GMenuTreeEntry *entry)
-{
-  const char *display_name;
-
-  g_return_val_if_fail (entry != NULL, NULL);
-
-  display_name = desktop_entry_get_full_name (entry->desktop_entry);
-  if (!display_name || display_name[0] == '\0')
-    display_name = desktop_entry_get_name (entry->desktop_entry);
-
-  return display_name;
-}
-
-const char *
-gmenu_tree_entry_get_comment (GMenuTreeEntry *entry)
+GDesktopAppInfo *
+gmenu_tree_entry_get_app_info (GMenuTreeEntry *entry)
 {
   g_return_val_if_fail (entry != NULL, NULL);
 
-  return desktop_entry_get_comment (entry->desktop_entry);
-}
-
-const char *
-gmenu_tree_entry_get_icon (GMenuTreeEntry *entry)
-{
-  g_return_val_if_fail (entry != NULL, NULL);
-
-  return desktop_entry_get_icon (entry->desktop_entry);
-}
-
-const char *
-gmenu_tree_entry_get_exec (GMenuTreeEntry *entry)
-{
-  g_return_val_if_fail (entry != NULL, NULL);
-
-  return desktop_entry_get_exec (entry->desktop_entry);
-}
-
-gboolean
-gmenu_tree_entry_get_launch_in_terminal (GMenuTreeEntry *entry)
-{
-  g_return_val_if_fail (entry != NULL, FALSE);
-
-  return desktop_entry_get_launch_in_terminal (entry->desktop_entry);
+  return desktop_entry_get_app_info (entry->desktop_entry);
 }
 
 const char *
@@ -1234,14 +1180,6 @@ gmenu_tree_entry_get_is_excluded (GMenuTreeEntry *entry)
   return entry->is_excluded;
 }
 
-gboolean
-gmenu_tree_entry_get_is_nodisplay (GMenuTreeEntry *entry)
-{
-  g_return_val_if_fail (entry != NULL, FALSE);
-
-  return entry->is_nodisplay;
-}
-
 GMenuTreeDirectory *
 gmenu_tree_header_get_directory (GMenuTreeHeader *header)
 {
@@ -1614,7 +1552,7 @@ gmenu_tree_item_compare_get_name_helper (GMenuTreeItem    *item,
 	  name = desktop_entry_get_name (GMENU_TREE_ENTRY (item)->desktop_entry);
 	  break;
 	case GMENU_TREE_SORT_DISPLAY_NAME:
-	  name = gmenu_tree_entry_get_display_name (GMENU_TREE_ENTRY (item));
+	  name = g_app_info_get_display_name (G_APP_INFO (gmenu_tree_entry_get_app_info (GMENU_TREE_ENTRY (item))));
 	  break;
 	default:
 	  g_assert_not_reached ();
@@ -3465,12 +3403,6 @@ process_layout (GMenuTree          *tree,
             }
         }
 
-      if (!desktop_entry_get_show_in_gnome (directory->directory_entry))
-        {
-          menu_verbose ("Not showing menu %s because OnlyShowIn!=GNOME or NotShowIn=GNOME\n",
-                        desktop_entry_get_name (directory->directory_entry));
-          deleted = TRUE;
-        }
     }
 
   if (deleted)
@@ -3527,20 +3459,6 @@ process_layout (GMenuTree          *tree,
           delete = TRUE;
         }
 
-      if (!desktop_entry_get_show_in_gnome (entry->desktop_entry))
-        {
-          menu_verbose ("Deleting %s because OnlyShowIn!=GNOME or NotShowIn=GNOME\n",
-                        desktop_entry_get_name (entry->desktop_entry));
-          delete = TRUE;
-        }
-
-      if (desktop_entry_get_tryexec_failed (entry->desktop_entry))
-        {
-          menu_verbose ("Deleting %s because TryExec failed\n",
-                        desktop_entry_get_name (entry->desktop_entry));
-          delete = TRUE;
-        }
-
       if (delete)
         {
           directory->entries = g_slist_delete_link (directory->entries,
diff --git a/libmenu/gmenu-tree.h b/libmenu/gmenu-tree.h
index 3a05eb2..a3990ae 100644
--- a/libmenu/gmenu-tree.h
+++ b/libmenu/gmenu-tree.h
@@ -24,7 +24,7 @@
 #error "libgnome-menu should only be used if you understand that it's subject to frequent change, and is not supported as a fixed API/ABI or as part of the platform"
 #endif
 
-#include <glib.h>
+#include <gio/gdesktopappinfo.h>
 
 G_BEGIN_DECLS
 
@@ -122,13 +122,7 @@ char *gmenu_tree_directory_make_path (GMenuTreeDirectory *directory,
 				      GMenuTreeEntry     *entry);
 
 
-const char *gmenu_tree_entry_get_name               (GMenuTreeEntry *entry);
-const char *gmenu_tree_entry_get_generic_name       (GMenuTreeEntry *entry);
-const char *gmenu_tree_entry_get_display_name       (GMenuTreeEntry *entry);
-const char *gmenu_tree_entry_get_comment            (GMenuTreeEntry *entry);
-const char *gmenu_tree_entry_get_icon               (GMenuTreeEntry *entry);
-const char *gmenu_tree_entry_get_exec               (GMenuTreeEntry *entry);
-gboolean    gmenu_tree_entry_get_launch_in_terminal (GMenuTreeEntry *entry);
+GDesktopAppInfo *gmenu_tree_entry_get_app_info       (GMenuTreeEntry *entry);
 
 const char *gmenu_tree_entry_get_desktop_file_path (GMenuTreeEntry *entry);
 const char *gmenu_tree_entry_get_desktop_file_id   (GMenuTreeEntry *entry);
diff --git a/python/Makefile.am b/python/Makefile.am
index fc2fc55..2a92afb 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -1,5 +1,5 @@
 AM_CPPFLAGS =				\
-	$(GLIB_CFLAGS)			\
+	$(GIO_UNIX_CFLAGS)		\
 	$(PYTHON_INCLUDES)		\
 	-I$(srcdir)/../libmenu		\
 	-DGMENU_I_KNOW_THIS_IS_UNSTABLE	\
@@ -15,6 +15,6 @@ gmenu_LTLIBRARIES = gmenu.la
 
 gmenu_la_SOURCES = gmenu.c
 gmenu_la_LDFLAGS = -module -avoid-version -fPIC -export-symbols-regex initgmenu
-gmenu_la_LIBADD = $(GLIB_LIBS) $(PYTHON_LIBS) $(top_builddir)/libmenu/libgnome-menu.la
+gmenu_la_LIBADD = $(GIO_UNIX_LIBS) $(PYTHON_LIBS) $(top_builddir)/libmenu/libgnome-menu.la
 
 -include $(top_srcdir)/git.mk
diff --git a/python/gmenu.c b/python/gmenu.c
index 71e4e38..d66e63e 100644
--- a/python/gmenu.c
+++ b/python/gmenu.c
@@ -619,7 +619,7 @@ pygmenu_tree_entry_get_name (PyObject *self,
 
   entry = (PyGMenuTreeEntry *) self;
 
-  name = gmenu_tree_entry_get_name (GMENU_TREE_ENTRY (entry->item));
+  name = g_app_info_get_name (G_APP_INFO (gmenu_tree_entry_get_app_info (GMENU_TREE_ENTRY (entry->item))));
   if (name == NULL)
     {
       Py_INCREF (Py_None);
@@ -644,7 +644,7 @@ pygmenu_tree_entry_get_generic_name (PyObject *self,
 
   entry = (PyGMenuTreeEntry *) self;
 
-  generic_name = gmenu_tree_entry_get_generic_name (GMENU_TREE_ENTRY (entry->item));
+  generic_name = g_desktop_app_info_get_generic_name (gmenu_tree_entry_get_app_info (GMENU_TREE_ENTRY (entry->item)));
   if (generic_name == NULL)
     {
       Py_INCREF (Py_None);
@@ -669,7 +669,7 @@ pygmenu_tree_entry_get_display_name (PyObject *self,
 
   entry = (PyGMenuTreeEntry *) self;
 
-  display_name = gmenu_tree_entry_get_display_name (GMENU_TREE_ENTRY (entry->item));
+  display_name = g_app_info_get_display_name (G_APP_INFO (gmenu_tree_entry_get_app_info (GMENU_TREE_ENTRY (entry->item))));
   if (display_name == NULL)
     {
       Py_INCREF (Py_None);
@@ -694,7 +694,7 @@ pygmenu_tree_entry_get_comment (PyObject *self,
 
   entry = (PyGMenuTreeEntry *) self;
 
-  comment = gmenu_tree_entry_get_comment (GMENU_TREE_ENTRY (entry->item));
+  comment = g_app_info_get_description (G_APP_INFO (gmenu_tree_entry_get_app_info (GMENU_TREE_ENTRY (entry->item))));
   if (comment == NULL)
     {
       Py_INCREF (Py_None);
@@ -709,7 +709,8 @@ pygmenu_tree_entry_get_icon (PyObject *self,
 			     PyObject *args)
 {
   PyGMenuTreeEntry *entry;
-  const char       *icon;
+  GIcon *icon;
+  const char *const *names;
 
   if (args != NULL)
     {
@@ -719,14 +720,20 @@ pygmenu_tree_entry_get_icon (PyObject *self,
 
   entry = (PyGMenuTreeEntry *) self;
 
-  icon = gmenu_tree_entry_get_icon (GMENU_TREE_ENTRY (entry->item));
-  if (icon == NULL)
+  icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (GMENU_TREE_ENTRY (entry->item))));
+  if (icon == NULL || !G_IS_THEMED_ICON (icon))
+    {
+      Py_INCREF (Py_None);
+      return Py_None;
+    }
+  names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+  if (names == NULL || names[0] == NULL)
     {
       Py_INCREF (Py_None);
       return Py_None;
     }
 
-  return PyString_FromString (icon);
+  return PyString_FromString (names[0]);
 }
 
 static PyObject *
@@ -744,7 +751,7 @@ pygmenu_tree_entry_get_exec (PyObject *self,
 
   entry = (PyGMenuTreeEntry *) self;
 
-  exec = gmenu_tree_entry_get_exec (GMENU_TREE_ENTRY (entry->item));
+  exec = g_app_info_get_executable (G_APP_INFO (gmenu_tree_entry_get_app_info (GMENU_TREE_ENTRY (entry->item))));
   if (exec == NULL)
     {
       Py_INCREF (Py_None);
diff --git a/util/Makefile.am b/util/Makefile.am
index d76a9db..a8ab28e 100644
--- a/util/Makefile.am
+++ b/util/Makefile.am
@@ -1,7 +1,7 @@
 noinst_PROGRAMS = gnome-menu-spec-test
 
 AM_CPPFLAGS =							\
-	$(GLIB_CFLAGS)						\
+	$(GIO_UNIX_CFLAGS)					\
 	-I$(srcdir)/../libmenu					\
 	-DGMENU_I_KNOW_THIS_IS_UNSTABLE				\
 	-DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"	\
@@ -14,7 +14,7 @@ gnome_menu_spec_test_SOURCES =		\
 	test-menu-spec.c
 
 gnome_menu_spec_test_LDADD =		\
-	$(GLIB_LIBS)			\
+	$(GIO_UNIX_LIBS)		\
 	../libmenu/libgnome-menu.la
 
 if HAVE_PYTHON



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