4e630cdb334e065a4f398e158bd38695f9be1c91
[lxde/lxpanel.git] / src / menu-policy.c
1 /**
2 * Copyright (c) 2009 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <menu-cache.h>
20 #include <glib.h>
21
22 #include "menu-policy.h"
23 #include "panel.h"
24
25 guint32 visibility_flags = 0;
26
27 /* Allocate a menu cache. */
28 MenuCache * panel_menu_cache_new(guint32* visibility_flags)
29 {
30 MenuCache* cache;
31 if (g_getenv("XDG_MENU_PREFIX") == NULL)
32 g_setenv("XDG_MENU_PREFIX", "lxde-", TRUE);
33 cache = menu_cache_lookup("applications.menu");
34 if(visibility_flags)
35 {
36 if(is_in_lxde)
37 *visibility_flags = SHOW_IN_LXDE;
38 else
39 {
40 const char* de_name = g_getenv("XDG_CURRENT_DESKTOP");
41 if(de_name)
42 *visibility_flags = menu_cache_get_desktop_env_flag(cache, de_name);
43 else
44 *visibility_flags = SHOW_IN_LXDE|SHOW_IN_GNOME|SHOW_IN_KDE|SHOW_IN_XFCE;
45 }
46 }
47 return cache;
48 }
49
50 /* Evaluate the visibility of a menu item. */
51 gboolean panel_menu_item_evaluate_visibility(MenuCacheItem * item, guint32 visibility_flags)
52 {
53 return menu_cache_app_get_is_visible(MENU_CACHE_APP(item), visibility_flags);
54 }