1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/* $Id$ */
/*-
* vi:set et ai sts=2 sw=2 cindent:
*
* Copyright (c) 2007-2011 Jannis Pohlmann <jannis@xfce.org>
*
* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "garcon/garcon.h"
#include <glib/gprintf.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
static void
print_menu (GarconMenu *menu,
const gchar *path)
{
GarconMenuDirectory *directory;
GFile *file;
GList *menus;
GList *items;
GList *iter;
gchar *name;
gchar *file_path;
if (!garcon_menu_element_get_visible (GARCON_MENU_ELEMENT (menu)))
return;
/* Determine menu name */
directory = garcon_menu_get_directory (menu);
if (G_UNLIKELY (path == NULL))
name = g_strdup ("");
else
{
name = g_strdup_printf ("%s%s/", path,
(directory == NULL
? garcon_menu_element_get_name (GARCON_MENU_ELEMENT (menu))
: garcon_menu_directory_get_name (directory)));
}
/* Fetch submenus */
menus = garcon_menu_get_menus (menu);
/* Print child menus */
for (iter = menus; iter != NULL; iter = g_list_next (iter))
{
/* Only display menus which are not hidden or excluded from this environment */
if (G_LIKELY (garcon_menu_element_get_visible (iter->data)))
print_menu (GARCON_MENU (iter->data), name);
}
/* Free submenu list */
g_list_free (menus);
/* Fetch menu items */
items = garcon_menu_get_elements (menu);
/* Print menu items */
for (iter = items; iter != NULL; iter = g_list_next (iter))
{
if (GARCON_IS_MENU_ITEM (iter->data)
&& garcon_menu_element_get_visible (iter->data))
{
file = garcon_menu_item_get_file (iter->data);
file_path = g_file_get_path (file);
g_printf ("%s\t%s\t%s\n", name, garcon_menu_item_get_desktop_id (iter->data),
file_path);
g_free (file_path);
g_object_unref (file);
}
}
/* Free menu item list */
g_list_free (items);
/* Free name */
g_free (name);
}
int
main (int argc,
char **argv)
{
GarconMenu *menu;
GError *error = NULL;
#ifdef HAVE_STDLIB_H
int exit_code = EXIT_SUCCESS;
#else
int exit_code = 0;
#endif
g_set_prgname ("test-menu-spec");
/* Try to get the root menu */
menu = garcon_menu_new_applications ();
if (G_LIKELY (garcon_menu_load (menu, NULL, &error)))
{
/* Print menu contents according to the test suite criteria */
print_menu (menu, NULL);
}
else
{
gchar *uri;
uri = g_file_get_uri (garcon_menu_get_file (menu));
g_error ("Could not load menu from %s: %s", uri, error->message);
g_free (uri);
g_error_free (error);
#ifdef HAVE_STDLIB_H
exit_code = EXIT_FAILURE;
#else
exit_code = -1;
#endif
}
return exit_code;
}
|