Author: jannis
Date: 2007-02-05 17:23:53 +0000 (Mon, 05 Feb 2007)
New Revision: 24857
Added:
libfrap/trunk/libfrap/menu/tests/test-menu-spec.c
Modified:
libfrap/trunk/libfrap/menu/ChangeLog
libfrap/trunk/libfrap/menu/Makefile.am
libfrap/trunk/libfrap/menu/frap-menu-item-pool.c
libfrap/trunk/libfrap/menu/frap-menu-item-pool.h
libfrap/trunk/libfrap/menu/frap-menu-item.c
libfrap/trunk/libfrap/menu/frap-menu-item.h
libfrap/trunk/libfrap/menu/frap-menu.c
libfrap/trunk/libfrap/menu/tests/Makefile.am
libfrap/trunk/libfrap/menu/tests/test-menu-item.c
Log:
* tests/Makefile.am, tests/test-menu-spec.c: Test program for
the fd.o menu spec test suite added.
* frap-menu-item.{c,h}: Replce "hidden" property with "no-display" as
hidden desktop entries won't even be parsed. Also replace all
accessor functions with _get_no_display(), _set_no_display()
equivalents. Ignore hidden desktop entries. Don't check TryExec for
now (as this causes errors when testing with the fd.o menu spec
test suite). Let frap_menu_item_get_allocated() return gint instead
of gboolean as we need to check at least two states (allocation
counter > 1 and > 2) in FrapMenu and FrapMenuItemPool.
* frap-menu-item-pool.{c,h}: Implement functions for removing already
allocated items (for menus with <OnlyUnallocated/>). Fix several
issues related to <Include>/<Exclude> rules, which did not work
properly until now.
* frap-menu.c: Cleanup app dir related code. Remove allocated items
from menus with <OnlyUnallocated/> in the second pass of
frap_menu_resolve_items(). Only set the menu directory if there is
one. Don't try to load item files not ending with .desktop.
* tests/test-menu-item.c: Use frap_menu_item_get_no_display() instead
of _is_hidden().
Modified: libfrap/trunk/libfrap/menu/ChangeLog
===================================================================
--- libfrap/trunk/libfrap/menu/ChangeLog 2007-02-05 12:12:53 UTC (rev
24856)
+++ libfrap/trunk/libfrap/menu/ChangeLog 2007-02-05 17:23:53 UTC (rev
24857)
@@ -1,3 +1,26 @@
+2007-02-05 Jannis Pohlmann <[EMAIL PROTECTED]>
+
+ * tests/Makefile.am, tests/test-menu-spec.c: Test program for
+ the fd.o menu spec test suite added.
+ * frap-menu-item.{c,h}: Replce "hidden" property with "no-display" as
+ hidden desktop entries won't even be parsed. Also replace all
+ accessor functions with _get_no_display(), _set_no_display()
+ equivalents. Ignore hidden desktop entries. Don't check TryExec for
+ now (as this causes errors when testing with the fd.o menu spec
+ test suite). Let frap_menu_item_get_allocated() return gint instead
+ of gboolean as we need to check at least two states (allocation
+ counter > 1 and > 2) in FrapMenu and FrapMenuItemPool.
+ * frap-menu-item-pool.{c,h}: Implement functions for removing already
+ allocated items (for menus with <OnlyUnallocated/>). Fix several
+ issues related to <Include>/<Exclude> rules, which did not work
+ properly until now.
+ * frap-menu.c: Cleanup app dir related code. Remove allocated items
+ from menus with <OnlyUnallocated/> in the second pass of
+ frap_menu_resolve_items(). Only set the menu directory if there is
+ one. Don't try to load item files not ending with .desktop.
+ * tests/test-menu-item.c: Use frap_menu_item_get_no_display() instead
+ of _is_hidden().
+
2007-01-16 Jannis Pohlmann <[EMAIL PROTECTED]>
* frap-menu.c: Update documentation.
Modified: libfrap/trunk/libfrap/menu/Makefile.am
===================================================================
--- libfrap/trunk/libfrap/menu/Makefile.am 2007-02-05 12:12:53 UTC (rev
24856)
+++ libfrap/trunk/libfrap/menu/Makefile.am 2007-02-05 17:23:53 UTC (rev
24857)
@@ -60,7 +60,6 @@
$(LIBXFCE4UTIL_LIBS) \
$(top_builddir)/libfrap/menu/tdb/libtdb.la
-
EXTRA_DIST = \
README \
STATUS
Modified: libfrap/trunk/libfrap/menu/frap-menu-item-pool.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item-pool.c 2007-02-05 12:12:53 UTC
(rev 24856)
+++ libfrap/trunk/libfrap/menu/frap-menu-item-pool.c 2007-02-05 17:23:53 UTC
(rev 24857)
@@ -34,14 +34,17 @@
-static void frap_menu_item_pool_class_init (FrapMenuItemPoolClass *klass);
-static void frap_menu_item_pool_init (FrapMenuItemPool *pool);
-static void frap_menu_item_pool_finalize (GObject
*object);
-static gboolean frap_menu_item_pool_filter_item (const gchar
*desktop_id,
- FrapMenuItem *item,
- GSList *rules);
-static gboolean frap_menu_item_pool_remove (const gchar
*desktop_id,
- FrapMenuItem *item);
+static void frap_menu_item_pool_class_init (FrapMenuItemPoolClass
*klass);
+static void frap_menu_item_pool_init (FrapMenuItemPool
*pool);
+static void frap_menu_item_pool_finalize (GObject
*object);
+static gboolean frap_menu_item_pool_filter_item (const gchar
*desktop_id,
+ FrapMenuItem
*item,
+ GSList
*rules);
+static gboolean frap_menu_item_pool_remove (const gchar
*desktop_id,
+ FrapMenuItem
*item);
+static gboolean frap_menu_item_pool_filter_allocated (const gchar
*desktop_id,
+ FrapMenuItem
*item,
+ gpointer
data);
@@ -218,7 +221,8 @@
{
FrapMenuStandardRules *rule;
GSList *iter;
- gboolean included = FALSE;
+ gboolean remove = TRUE;
+ gboolean matches;
g_return_val_if_fail (FRAP_IS_MENU_ITEM (item), FALSE);
@@ -228,16 +232,35 @@
rule = FRAP_MENU_STANDARD_RULES (iter->data);
if (frap_menu_standard_rules_get_include (rule))
- included = frap_menu_rules_match (FRAP_MENU_RULES (rule), item);
+ {
+ matches = frap_menu_rules_match (FRAP_MENU_RULES (rule), item);
+
+ if (matches)
+ remove = FALSE;
+ }
else
- included = !frap_menu_rules_match (FRAP_MENU_RULES (rule), item);
+ {
+ matches = frap_menu_rules_match (FRAP_MENU_RULES (rule), item);
+
+ if (matches)
+ remove = TRUE;
+ }
}
- return !included;
+ return remove;
}
+void
+frap_menu_item_pool_remove_allocated (FrapMenuItemPool *pool)
+{
+ g_return_if_fail (FRAP_IS_MENU_ITEM_POOL (pool));
+ g_hash_table_foreach_remove (pool->priv->items, (GHRFunc)
frap_menu_item_pool_filter_allocated, NULL);
+}
+
+
+
gboolean
frap_menu_item_pool_get_empty (FrapMenuItemPool *pool)
{
@@ -253,3 +276,13 @@
{
return TRUE;
}
+
+
+
+static gboolean
+frap_menu_item_pool_filter_allocated (const gchar *desktop_id,
+ FrapMenuItem *item,
+ gpointer data)
+{
+ return frap_menu_item_get_allocated (item) > 1;
+}
Modified: libfrap/trunk/libfrap/menu/frap-menu-item-pool.h
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item-pool.h 2007-02-05 12:12:53 UTC
(rev 24856)
+++ libfrap/trunk/libfrap/menu/frap-menu-item-pool.h 2007-02-05 17:23:53 UTC
(rev 24857)
@@ -41,20 +41,21 @@
#define FRAP_IS_MENU_ITEM_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
FRAP_TYPE_MENU_ITEM_POOL))
#define FRAP_MENU_ITEM_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
FRAP_TYPE_MENU_ITEM_POOL, FrapMenuItemPoolClass))
-GType frap_menu_item_pool_get_type (void) G_GNUC_CONST;
+GType frap_menu_item_pool_get_type (void) G_GNUC_CONST;
-FrapMenuItemPool *frap_menu_item_pool_new (void);
+FrapMenuItemPool *frap_menu_item_pool_new (void);
-void frap_menu_item_pool_insert (FrapMenuItemPool *pool,
- FrapMenuItem *item);
-FrapMenuItem *frap_menu_item_pool_lookup (FrapMenuItemPool *pool,
- const gchar
*desktop_id);
-void frap_menu_item_pool_foreach (FrapMenuItemPool *pool,
- GHFunc func,
- gpointer
user_data);
-void frap_menu_item_pool_apply_rules (FrapMenuItemPool *pool,
- GSList *rules);
-gboolean frap_menu_item_pool_get_empty (FrapMenuItemPool *pool);
+void frap_menu_item_pool_insert (FrapMenuItemPool *pool,
+ FrapMenuItem
*item);
+FrapMenuItem *frap_menu_item_pool_lookup (FrapMenuItemPool *pool,
+ const gchar
*desktop_id);
+void frap_menu_item_pool_foreach (FrapMenuItemPool *pool,
+ GHFunc
func,
+ gpointer
user_data);
+void frap_menu_item_pool_apply_rules (FrapMenuItemPool *pool,
+ GSList
*rules);
+void frap_menu_item_pool_remove_allocated (FrapMenuItemPool
*pool);
+gboolean frap_menu_item_pool_get_empty (FrapMenuItemPool
*pool);
G_END_DECLS;
Modified: libfrap/trunk/libfrap/menu/frap-menu-item.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item.c 2007-02-05 12:12:53 UTC (rev
24856)
+++ libfrap/trunk/libfrap/menu/frap-menu-item.c 2007-02-05 17:23:53 UTC (rev
24857)
@@ -42,7 +42,7 @@
PROP_DESKTOP_ID,
PROP_FILENAME,
PROP_REQUIRES_TERMINAL,
- PROP_HIDDEN,
+ PROP_NO_DISPLAY,
PROP_STARTUP_NOTIFICATION,
PROP_NAME,
PROP_ICON_NAME,
@@ -88,7 +88,7 @@
guint requires_terminal : 1;
/* Whether this menu item should be hidden */
- guint hidden : 1;
+ guint no_display : 1;
/* Whether this application supports startup notification */
guint supports_startup_notification : 1;
@@ -207,14 +207,14 @@
G_PARAM_READWRITE));
/**
- * FrapMenuItem:hidden:
+ * FrapMenuItem:no-display:
*
- * Whether this menu item is hidden.
+ * Whether this menu item is displayed in menus.
**/
g_object_class_install_property (gobject_class,
- PROP_HIDDEN,
- g_param_spec_boolean ("hidden",
- _("Hidden"),
+ PROP_NO_DISPLAY,
+ g_param_spec_boolean ("no-display",
+ _("No Display"),
_("Visibility state
of the menu item"),
FALSE,
G_PARAM_READWRITE));
@@ -337,7 +337,7 @@
break;
case PROP_REQUIRES_TERMINAL:
- case PROP_HIDDEN:
+ case PROP_NO_DISPLAY:
case PROP_STARTUP_NOTIFICATION:
case PROP_NAME:
case PROP_COMMAND:
@@ -374,8 +374,8 @@
frap_menu_item_set_requires_terminal (item, g_value_get_boolean (value));
break;
- case PROP_HIDDEN:
- frap_menu_item_set_hidden (item, g_value_get_boolean (value));
+ case PROP_NO_DISPLAY:
+ frap_menu_item_set_no_display (item, g_value_get_boolean (value));
break;
case PROP_STARTUP_NOTIFICATION:
@@ -418,7 +418,7 @@
GList *categories = NULL;
gboolean present;
gboolean terminal;
- gboolean hidden;
+ gboolean no_display;
gboolean startup_notify;
gboolean show;
@@ -438,8 +438,17 @@
return NULL;
}
- /* Parse the file */
+ /* Use the Desktop Entry section of the desktop file */
xfce_rc_set_group (rc, "Desktop Entry");
+
+ /* Abort if the file has been marked as "deleted"/hidden */
+ if (G_UNLIKELY (xfce_rc_read_bool_entry (rc, "Hidden", FALSE)))
+ {
+ xfce_rc_close (rc);
+ return NULL;
+ }
+
+ /* Parse name, exec command and icon name */
name = xfce_rc_read_entry (rc, "Name", NULL);
exec = xfce_rc_read_entry (rc, "Exec", NULL);
icon = xfce_rc_read_entry (rc, "Icon", NULL);
@@ -451,6 +460,7 @@
/* Perform checks in order to ignore non-existend programs */
if (G_LIKELY (tryexec != NULL && g_shell_parse_argv (tryexec, NULL, &mt,
NULL)))
{
+#if 0
/* Check if the path is absolute */
present = g_file_test (mt[0], G_FILE_TEST_EXISTS);
@@ -471,6 +481,9 @@
xfce_rc_close (rc);
return NULL;
}
+#endif
+ g_strfreev (mt);
+ present = TRUE;
}
/* Validate Name and Exec fields */
@@ -478,7 +491,7 @@
{
/* Determine other application properties */
terminal = xfce_rc_read_bool_entry (rc, "Terminal", FALSE);
- hidden = xfce_rc_read_bool_entry (rc, "Hidden", FALSE) ||
xfce_rc_read_bool_entry (rc, "NoDisplay", FALSE);
+ no_display = xfce_rc_read_bool_entry (rc, "NoDisplay", FALSE);
startup_notify = xfce_rc_read_bool_entry (rc, "StartupNotify", FALSE) ||
xfce_rc_read_bool_entry (rc, "X-KDE-StartupNotify", FALSE);
/* Allocate a new menu item instance */
@@ -488,7 +501,7 @@
"name", name,
"icon-name", icon,
"requires-terminal", terminal,
- "hidden", hidden,
+ "no-display", no_display,
"supports-startup-notification", startup_notify,
NULL);
@@ -811,29 +824,29 @@
gboolean
-frap_menu_item_is_hidden (FrapMenuItem *item)
+frap_menu_item_get_no_display (FrapMenuItem *item)
{
g_return_val_if_fail (FRAP_IS_MENU_ITEM (item), FALSE);
- return item->priv->hidden;
+ return item->priv->no_display;
}
void
-frap_menu_item_set_hidden (FrapMenuItem *item,
- gboolean hidden)
+frap_menu_item_set_no_display (FrapMenuItem *item,
+ gboolean no_display)
{
g_return_if_fail (FRAP_IS_MENU_ITEM (item));
/* Abort if old and new value are equal */
- if (item->priv->hidden == hidden)
+ if (item->priv->no_display == no_display)
return;
/* Assign new value */
- item->priv->hidden = hidden;
+ item->priv->no_display = no_display;
/* Notify listeners */
- g_object_notify (G_OBJECT (item), "hidden");
+ g_object_notify (G_OBJECT (item), "no-display");
}
@@ -894,11 +907,11 @@
-gboolean
+gint
frap_menu_item_get_allocated (FrapMenuItem *item)
{
g_return_val_if_fail (FRAP_IS_MENU_ITEM (item), FALSE);
- return item->priv->num_allocated > 0;
+ return item->priv->num_allocated;
}
Modified: libfrap/trunk/libfrap/menu/frap-menu-item.h
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item.h 2007-02-05 12:12:53 UTC (rev
24856)
+++ libfrap/trunk/libfrap/menu/frap-menu-item.h 2007-02-05 17:23:53 UTC (rev
24857)
@@ -64,9 +64,9 @@
gboolean frap_menu_item_requires_terminal (FrapMenuItem
*item);
void frap_menu_item_set_requires_terminal (FrapMenuItem
*item,
gboolean
requires_terminal);
-gboolean frap_menu_item_is_hidden (FrapMenuItem
*item);
-void frap_menu_item_set_hidden (FrapMenuItem
*item,
- gboolean
hidden);
+gboolean frap_menu_item_get_no_display (FrapMenuItem
*item);
+void frap_menu_item_set_no_display (FrapMenuItem
*item,
+ gboolean
no_display);
gboolean frap_menu_item_supports_startup_notification (FrapMenuItem
*item);
void frap_menu_item_set_supports_startup_notification (FrapMenuItem
*item,
gboolean
supports_startup_notification);
@@ -75,7 +75,7 @@
GList
*categories);
void frap_menu_item_ref (FrapMenuItem
*item);
void frap_menu_item_unref (FrapMenuItem
*item);
-gboolean frap_menu_item_get_allocated (FrapMenuItem
*item);
+gint frap_menu_item_get_allocated (FrapMenuItem
*item);
void frap_menu_item_increment_allocated (FrapMenuItem
*item);
void frap_menu_item_decrement_allocated (FrapMenuItem
*item);
Modified: libfrap/trunk/libfrap/menu/frap-menu.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu.c 2007-02-05 12:12:53 UTC (rev
24856)
+++ libfrap/trunk/libfrap/menu/frap-menu.c 2007-02-05 17:23:53 UTC (rev
24857)
@@ -2089,11 +2089,11 @@
g_return_if_fail (FRAP_IS_MENU (menu));
/* Iterate over app dirs in reverse order */
- for (iter = g_slist_reverse (menu->priv->app_dirs); iter != NULL; iter =
g_slist_next (iter))
+ for (iter = menu->priv->app_dirs; iter != NULL; iter = g_slist_next (iter))
{
- /* Prepend app dir to the new list unless it already exists */
+ /* Append app dir to the new list unless it already exists */
if (G_LIKELY (g_slist_find_custom (dirs, iter->data, (GCompareFunc)
g_utf8_collate) == NULL))
- dirs = g_slist_prepend (dirs, g_strdup (iter->data));
+ dirs = g_slist_append (dirs, g_strdup (iter->data));
}
/* Free old list */
@@ -2128,8 +2128,11 @@
break;
}
- /* Set the directory (assuming that we found at least one valid name) */
- frap_menu_set_directory (menu, directory);
+ if (G_LIKELY (directory != NULL))
+ {
+ /* Set the directory (assuming that we found at least one valid name) */
+ frap_menu_set_directory (menu, directory);
+ }
/* Free reverse list copy */
g_slist_free (directory_names);
@@ -2235,6 +2238,10 @@
frap_menu_resolve_items_from_path (menu, iter->data, NULL);
}
+ /* Filter already allocated items if the menu has <OnlyUnallocated/> */
+ if (G_UNLIKELY (menu->priv->only_unallocated))
+ frap_menu_item_pool_remove_allocated (menu->priv->pool);
+
/* Filter items according to the include/exclude rules */
frap_menu_item_pool_apply_rules (menu->priv->pool, menu->priv->rules);
}
@@ -2299,28 +2306,32 @@
}
else
{
- /* Create desktop file id */
- if (G_LIKELY (id_prefix == NULL))
- desktop_id = g_strdup (filename);
- else
- desktop_id = g_strjoin ("-", id_prefix, filename, NULL);
+ /* Skip all filenames which do not end with .desktop */
+ if (G_LIKELY (g_str_has_suffix (filename, ".desktop")))
+ {
+ /* Create desktop file id */
+ if (G_LIKELY (id_prefix == NULL))
+ desktop_id = g_strdup (filename);
+ else
+ desktop_id = g_strjoin ("-", id_prefix, filename, NULL);
- /* Try to load the menu item from the cache */
- item = frap_menu_item_cache_lookup (menu->priv->cache,
absolute_path, desktop_id);
+ /* Try to load the menu item from the cache */
+ item = frap_menu_item_cache_lookup (menu->priv->cache,
absolute_path, desktop_id);
- if (G_LIKELY (item != NULL))
- {
- /* Only include item if menu not only includes unallocated items
- * or if the item is not allocated yet */
- if (!menu->priv->only_unallocated ||
!frap_menu_item_get_allocated (item))
+ if (G_LIKELY (item != NULL))
{
- /* Add the new item to the pool (replace the old one if
needed) */
- frap_menu_item_pool_insert (menu->priv->pool, item);
+ /* Only include item if menu not only includes unallocated
items
+ * or if the item is not allocated yet */
+ if (!menu->priv->only_unallocated ||
(frap_menu_item_get_allocated (item) < 1))
+ {
+ /* Add the new item to the pool (replace the old one if
needed) */
+ frap_menu_item_pool_insert (menu->priv->pool, item);
+ }
}
+
+ /* Free desktop id */
+ g_free (desktop_id);
}
-
- /* Free desktop id */
- g_free (desktop_id);
}
/* Free the absolute path */
Modified: libfrap/trunk/libfrap/menu/tests/Makefile.am
===================================================================
--- libfrap/trunk/libfrap/menu/tests/Makefile.am 2007-02-05 12:12:53 UTC
(rev 24856)
+++ libfrap/trunk/libfrap/menu/tests/Makefile.am 2007-02-05 17:23:53 UTC
(rev 24857)
@@ -26,7 +26,8 @@
test-and-rules \
test-not-rules \
test-root-menu \
- test-display-root-menu
+ test-display-root-menu \
+ test-menu-spec
check_PROGRAMS = \
test-menu-item \
@@ -34,7 +35,8 @@
test-and-rules \
test-not-rules \
test-root-menu \
- test-display-root-menu
+ test-display-root-menu \
+ test-menu-spec
test_menu_item_SOURCES = \
test-menu-item.c
@@ -72,6 +74,12 @@
test_display_root_menu_DEPENDENCIES = \
$(top_builddir)/libfrap/menu/libfrapmenu.la
+test_menu_spec_SOURCES = \
+ test-menu-spec.c
+
+test_menu_spec_DEPENDENCIES = \
+ $(top_builddir)/libfrap/menu/libfrapmenu.la
+
EXTRA_DIST = \
README \
STATUS
Modified: libfrap/trunk/libfrap/menu/tests/test-menu-item.c
===================================================================
--- libfrap/trunk/libfrap/menu/tests/test-menu-item.c 2007-02-05 12:12:53 UTC
(rev 24856)
+++ libfrap/trunk/libfrap/menu/tests/test-menu-item.c 2007-02-05 17:23:53 UTC
(rev 24857)
@@ -51,7 +51,7 @@
g_assert (g_utf8_collate (frap_menu_item_get_command (item), "xfmedia %F")
== 0);
g_assert (frap_menu_item_requires_terminal (item) == FALSE);
g_assert (frap_menu_item_supports_startup_notification (item) == TRUE);
- g_assert (frap_menu_item_is_hidden (item) == FALSE);
+ g_assert (frap_menu_item_get_no_display (item) == FALSE);
/* Free desktop file */
g_object_unref (G_OBJECT (item));
Added: libfrap/trunk/libfrap/menu/tests/test-menu-spec.c
===================================================================
--- libfrap/trunk/libfrap/menu/tests/test-menu-spec.c
(rev 0)
+++ libfrap/trunk/libfrap/menu/tests/test-menu-spec.c 2007-02-05 17:23:53 UTC
(rev 24857)
@@ -0,0 +1,118 @@
+/* $Id$ */
+/* vi:set expandtab sw=2 sts=2: */
+/*-
+ * Copyright (c) 2007 Jannis Pohlmann <[EMAIL PROTECTED]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <libxfce4util/libxfce4util.h>
+#include <libfrapmenu.h>
+
+
+
+gint
+compare_menus (FrapMenu *menu1, FrapMenu *menu2)
+{
+ return g_utf8_collate (frap_menu_get_name (menu1), frap_menu_get_name
(menu2));
+}
+
+
+
+gint
+compare_menu_items (FrapMenuItem *item1, FrapMenuItem *item2)
+{
+ return g_utf8_collate (frap_menu_item_get_filename (item1),
frap_menu_item_get_filename (item2));
+}
+
+
+
+void
+print_menu (FrapMenu *menu, gboolean is_root)
+{
+ FrapMenuDirectory *directory;
+ GSList *iter;
+ const gchar *name;
+
+ /* Determine menu name */
+ directory = frap_menu_get_directory (menu);
+ name = is_root ? "" : (directory == NULL ? frap_menu_get_name (menu) :
frap_menu_directory_get_name (directory));
+
+ /* Print child menus */
+ for (iter = g_slist_sort (frap_menu_get_menus (menu), (GCompareFunc)
compare_menus); iter != NULL; iter = g_slist_next (iter))
+ print_menu (FRAP_MENU (iter->data), FALSE);
+
+ /* Print menu items */
+ for (iter = g_slist_sort (frap_menu_get_items (menu), (GCompareFunc)
compare_menu_items); iter != NULL; iter = g_slist_next (iter))
+ {
+ FrapMenuItem *item = iter->data;
+
+ if (G_UNLIKELY (frap_menu_item_get_no_display (item)))
+ continue;
+
+ g_printf ("%s/\t%s\t%s\n", name, frap_menu_item_get_desktop_id (item),
frap_menu_item_get_filename (item));
+ }
+}
+
+
+
+int
+main (int argc,
+ char **argv)
+{
+ FrapMenu *menu;
+ GError *error = NULL;
+#ifdef HAVE_STDLIB_H
+ int exit_code = EXIT_SUCCESS;
+#else
+ int exit_code = 0;
+#endif
+
+ /* Initialize menu library */
+ frap_menu_init (NULL);
+
+ /* Try to get the root menu */
+ menu = frap_menu_get_root (&error);
+
+ if (G_LIKELY (menu != NULL))
+ {
+ /* Print menu contents according to the test suite criteria */
+ print_menu (menu, TRUE);
+ }
+ else
+ {
+ g_error (error->message);
+ g_error_free (error);
+#ifdef HAVE_STDLIB_H
+ exit_code = EXIT_FAILURE;
+#else
+ exit_code = -1;
+#endif
+ }
+
+ /* Shut down the menu library */
+ frap_menu_shutdown ();
+
+ return exit_code;
+}
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits