diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index 29f10c1b3..879f521c3 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -1402,6 +1402,7 @@ g_desktop_app_info_new g_desktop_app_info_get_filename g_desktop_app_info_get_is_hidden g_desktop_app_info_get_nodisplay +g_desktop_app_info_get_show_in g_desktop_app_info_get_generic_name g_desktop_app_info_get_categories g_desktop_app_info_set_desktop_env diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 97618952a..996acdfcf 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -127,6 +127,9 @@ G_DEFINE_TYPE_WITH_CODE (GDesktopAppInfo, g_desktop_app_info, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_APP_INFO, g_desktop_app_info_iface_init)) +G_LOCK_DEFINE_STATIC (g_desktop_env); +static gchar *g_desktop_env = NULL; + static gpointer search_path_init (gpointer data) { @@ -691,6 +694,72 @@ g_desktop_app_info_get_nodisplay (GDesktopAppInfo *info) return info->nodisplay; } +/** + * g_desktop_app_info_get_show_in: + * @info: a #GDesktopAppInfo + * @desktop_env: a string specifying a desktop name + * + * Checks if the application info should be shown in menus that list available + * applications for a specific name of the desktop, based on the + * OnlyShowIn and NotShowIn keys. + * + * If @desktop_env is %NULL, then the name of the desktop set with + * g_desktop_app_info_set_desktop_env() is used. + * + * Note that g_app_info_should_show() for @info will include this check (with + * %NULL for @desktop_env) as well as additional checks. + * + * Returns: %TRUE if the @info should be shown in @desktop_env according to the + * OnlyShowIn and NotShowIn keys, %FALSE + * otherwise. + * + * Since: 2.30 + */ +gboolean +g_desktop_app_info_get_show_in (GDesktopAppInfo *info, + const gchar *desktop_env) +{ + gboolean found; + int i; + + g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE); + + if (!desktop_env) { + G_LOCK (g_desktop_env); + desktop_env = g_desktop_env; + G_UNLOCK (g_desktop_env); + } + + if (info->only_show_in) + { + if (desktop_env == NULL) + return FALSE; + + found = FALSE; + for (i = 0; info->only_show_in[i] != NULL; i++) + { + if (strcmp (info->only_show_in[i], desktop_env) == 0) + { + found = TRUE; + break; + } + } + if (!found) + return FALSE; + } + + if (info->not_show_in && desktop_env) + { + for (i = 0; info->not_show_in[i] != NULL; i++) + { + if (strcmp (info->not_show_in[i], desktop_env) == 0) + return FALSE; + } + } + + return TRUE; +} + static char * expand_macro_single (char macro, char *uri) { @@ -1376,15 +1445,13 @@ g_desktop_app_info_launch_uris_as_manager (GDesktopAppInfo *appinfo, error); } -G_LOCK_DEFINE_STATIC (g_desktop_env); -static gchar *g_desktop_env = NULL; - /** * g_desktop_app_info_set_desktop_env: * @desktop_env: a string specifying what desktop this is * * Sets the name of the desktop that the application is running in. - * This is used by g_app_info_should_show() to evaluate the + * This is used by g_app_info_should_show() and + * g_desktop_app_info_get_show_in() to evaluate the * OnlyShowIn and NotShowIn * desktop entry fields. * @@ -1413,45 +1480,11 @@ static gboolean g_desktop_app_info_should_show (GAppInfo *appinfo) { GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo); - gboolean found; - const gchar *desktop_env; - int i; if (info->nodisplay) return FALSE; - G_LOCK (g_desktop_env); - desktop_env = g_desktop_env; - G_UNLOCK (g_desktop_env); - - if (info->only_show_in) - { - if (desktop_env == NULL) - return FALSE; - - found = FALSE; - for (i = 0; info->only_show_in[i] != NULL; i++) - { - if (strcmp (info->only_show_in[i], desktop_env) == 0) - { - found = TRUE; - break; - } - } - if (!found) - return FALSE; - } - - if (info->not_show_in && desktop_env) - { - for (i = 0; info->not_show_in[i] != NULL; i++) - { - if (strcmp (info->not_show_in[i], desktop_env) == 0) - return FALSE; - } - } - - return TRUE; + return g_desktop_app_info_get_show_in (info, NULL); } typedef enum { diff --git a/gio/gdesktopappinfo.h b/gio/gdesktopappinfo.h index 89391898e..9e45a254b 100644 --- a/gio/gdesktopappinfo.h +++ b/gio/gdesktopappinfo.h @@ -53,6 +53,8 @@ const char * g_desktop_app_info_get_filename (GDesktopAppInfo *info); const char * g_desktop_app_info_get_generic_name (GDesktopAppInfo *info); const char * g_desktop_app_info_get_categories (GDesktopAppInfo *info); gboolean g_desktop_app_info_get_nodisplay (GDesktopAppInfo *info); +gboolean g_desktop_app_info_get_show_in (GDesktopAppInfo *info, + const gchar *desktop_env); GDesktopAppInfo *g_desktop_app_info_new (const char *desktop_id); gboolean g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info); diff --git a/gio/gio.symbols b/gio/gio.symbols index e5f96e92b..5189d560a 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -98,6 +98,7 @@ g_desktop_app_info_get_filename g_desktop_app_info_get_generic_name g_desktop_app_info_get_is_hidden g_desktop_app_info_get_nodisplay +g_desktop_app_info_get_show_in g_desktop_app_info_get_type g_desktop_app_info_launch_uris_as_manager g_desktop_app_info_lookup_get_type