Merging upstream version 0.8.2 (Closes: #786485, #784725, #801319).
[debian/lxpanel.git] / src / menu-policy.c
1 /*
2 * Copyright (C) 2009-2010 martyj19 <martyj19@comcast.net>
3 * 2009 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4 * 2014 Andriy Grytsenko <andrej@rep.kiev.ua>
5 *
6 * This file is a part of LXPanel project.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <glib.h>
28
29 #include "menu-policy.h"
30 #include "private.h"
31
32 /* support for libmenu-cache 0.4.x */
33 #ifndef MENU_CACHE_CHECK_VERSION
34 # ifdef HAVE_MENU_CACHE_DIR_LIST_CHILDREN
35 # define MENU_CACHE_CHECK_VERSION(_a,_b,_c) (_a == 0 && _b < 5) /* < 0.5.0 */
36 # else
37 # define MENU_CACHE_CHECK_VERSION(_a,_b,_c) 0 /* not even 0.4.0 */
38 # endif
39 #endif
40
41 /* Allocate a menu cache. */
42 MenuCache * panel_menu_cache_new(guint32* visibility_flags)
43 {
44 MenuCache* cache;
45 gboolean need_prefix = (g_getenv("XDG_MENU_PREFIX") == NULL);
46
47 #if MENU_CACHE_CHECK_VERSION(0, 5, 0)
48 /* do it the same way menu:// VFS plugin in libfm does */
49 cache = menu_cache_lookup(need_prefix ? "lxde-applications.menu+hidden" : "applications.menu+hidden");
50 #else
51 cache = menu_cache_lookup(need_prefix ? "lxde-applications.menu" : "applications.menu");
52 #endif
53 if(visibility_flags)
54 {
55 if(is_in_lxde)
56 *visibility_flags = SHOW_IN_LXDE;
57 else
58 {
59 const char* de_name = g_getenv("XDG_CURRENT_DESKTOP");
60 if(de_name)
61 *visibility_flags = menu_cache_get_desktop_env_flag(cache, de_name);
62 else
63 *visibility_flags = SHOW_IN_LXDE|SHOW_IN_GNOME|SHOW_IN_KDE|SHOW_IN_XFCE;
64 }
65 }
66 return cache;
67 }
68
69 /* Evaluate the visibility of a menu item. */
70 gboolean panel_menu_item_evaluate_visibility(MenuCacheItem * item, guint32 visibility_flags)
71 {
72 return menu_cache_app_get_is_visible(MENU_CACHE_APP(item), visibility_flags);
73 }