[gnome-menus/wip/gobject-review] libmenu: Correctly deal with OnlyShowIn/NotShowIn



commit ad286574d38555ad42de386fa139f57196c00349
Author: Vincent Untz <vuntz gnome org>
Date:   Thu Jul 21 15:26:11 2011 +0200

    libmenu: Correctly deal with OnlyShowIn/NotShowIn
    
    We're using new glib API for this.
    
    Also, we do not remove entries because of OnlyShowIn/NotShowIn before
    processing the layout, as we might want to add a GMenuTreeFlags value in
    the future, to include .desktop files that are excluded because of
    OnlyShowIn/NotShowIn.

 configure.ac              |    2 +-
 libmenu/desktop-entries.c |   16 ++++++++++++----
 libmenu/desktop-entries.h |    1 +
 libmenu/gmenu-tree.c      |   16 ++++++++++++++++
 4 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 022fdc7..8adfbae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,7 +38,7 @@ AC_ARG_PROGRAM
 AC_LIBTOOL_WIN32_DLL
 AM_PROG_LIBTOOL
 
-PKG_CHECK_MODULES(GIO_UNIX, gio-unix-2.0 >= 2.29.9)
+PKG_CHECK_MODULES(GIO_UNIX, gio-unix-2.0 >= 2.29.13)
 AC_SUBST(GIO_UNIX_CFLAGS)
 AC_SUBST(GIO_UNIX_LIBS)
 
diff --git a/libmenu/desktop-entries.c b/libmenu/desktop-entries.c
index da09455..a441f65 100644
--- a/libmenu/desktop-entries.c
+++ b/libmenu/desktop-entries.c
@@ -58,6 +58,7 @@ typedef struct
 
   guint     nodisplay   : 1;
   guint     hidden      : 1;
+  guint     showin      : 1;
 } DesktopEntryDirectory;
 
 struct DesktopEntrySet
@@ -158,10 +159,6 @@ desktop_entry_load_directory (DesktopEntry  *entry,
 
   g_free (type_str);
 
-  /* Just skip stuff that's not GNOME */
-  if (!key_file_get_show_in_gnome (key_file))
-    return FALSE;
-
   entry_directory->name = g_key_file_get_locale_string (key_file, DESKTOP_ENTRY_GROUP, "Name", NULL, error);
   if (entry_directory->name == NULL)
     return FALSE;
@@ -177,6 +174,8 @@ desktop_entry_load_directory (DesktopEntry  *entry,
                                                           DESKTOP_ENTRY_GROUP,
                                                           "Hidden",
                                                           NULL);
+  entry_directory->showin       = key_file_get_show_in_gnome (key_file);
+
   return TRUE;
 }
 
@@ -394,6 +393,7 @@ desktop_entry_copy (DesktopEntry *entry)
       retval_directory->icon         = g_strdup (entry_directory->icon);
       retval_directory->nodisplay    = entry_directory->nodisplay;
       retval_directory->hidden       = entry_directory->hidden;
+      retval_directory->showin       = entry_directory->showin;
     }
 
   return retval;
@@ -503,6 +503,14 @@ desktop_entry_get_hidden (DesktopEntry *entry)
   return ((DesktopEntryDirectory*)entry)->hidden;
 }
 
+gboolean
+desktop_entry_get_show_in (DesktopEntry *entry)
+{
+  if (entry->type == DESKTOP_ENTRY_DESKTOP)
+    return g_desktop_app_info_get_show_in (((DesktopEntryDesktop*)entry)->appinfo, "GNOME");
+  return ((DesktopEntryDirectory*)entry)->showin;
+}
+
 
 GDesktopAppInfo  *
 desktop_entry_get_app_info (DesktopEntry *entry)
diff --git a/libmenu/desktop-entries.h b/libmenu/desktop-entries.h
index 6ca4855..5ef9b63 100644
--- a/libmenu/desktop-entries.h
+++ b/libmenu/desktop-entries.h
@@ -48,6 +48,7 @@ const char       *desktop_entry_get_generic_name (DesktopEntry *entry);
 const char       *desktop_entry_get_comment  (DesktopEntry *entry);
 gboolean          desktop_entry_get_hidden   (DesktopEntry *entry);
 gboolean          desktop_entry_get_no_display (DesktopEntry *entry);
+gboolean          desktop_entry_get_show_in  (DesktopEntry *entry);
 
 /* Only valid for DESKTOP_ENTRY_DIRECTORY */
 const char       *desktop_entry_get_icon     (DesktopEntry *entry);
diff --git a/libmenu/gmenu-tree.c b/libmenu/gmenu-tree.c
index cdad440..a7f9cdb 100644
--- a/libmenu/gmenu-tree.c
+++ b/libmenu/gmenu-tree.c
@@ -3311,6 +3311,12 @@ process_layout (GMenuTree          *tree,
             }
         }
 
+      if (!desktop_entry_get_show_in (directory->directory_entry))
+        {
+          menu_verbose ("Not showing menu %s because OnlyShowIn!=$DESKTOP or NotShowIn=$DESKTOP (with $DESKTOP=${XDG_CURRENT_DESKTOP:-GNOME})\n",
+                        desktop_entry_get_name (directory->directory_entry));
+          deleted = TRUE;
+        }
     }
 
   if (deleted)
@@ -3367,6 +3373,16 @@ process_layout (GMenuTree          *tree,
           delete = TRUE;
         }
 
+      if (!desktop_entry_get_show_in (entry->desktop_entry))
+        {
+          menu_verbose ("Deleting %s because OnlyShowIn!=$DESKTOP or NotShowIn=$DESKTOP (with $DESKTOP=${XDG_CURRENT_DESKTOP:-GNOME})\n",
+                        desktop_entry_get_name (entry->desktop_entry));
+          delete = TRUE;
+        }
+
+      /* No need to filter out based on TryExec since GDesktopAppInfo cannot
+       * deal with .desktop files with a failed TryExec. */
+
       if (delete)
         {
           directory->entries = g_slist_delete_link (directory->entries,



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