From 8af463f939730be9236460977878912b856dbb9d Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 4 Jan 2008 10:51:56 +0000 Subject: [PATCH] Add g_app_info_supports_files() Remove desktop arg from 2008-01-04 Alexander Larsson * gappinfo.[ch]: * gwin32appinfo.c: * gio.symbols: Add g_app_info_supports_files() Remove desktop arg from g_app_info_should_show(). * gdesktopappinfo.[ch]: Implement g_app_info_supports_files() and new should_show() Add g_desktop_app_info_set_desktop_env() to set the desktop for should_show(). (This will be set by gtk+ later) svn path=/trunk/; revision=6242 --- gio/ChangeLog | 13 +++++++++ gio/gappinfo.c | 35 +++++++++++++++++------- gio/gappinfo.h | 9 ++++--- gio/gdesktopappinfo.c | 73 ++++++++++++++++++++++++++++++++++++++++++--------- gio/gdesktopappinfo.h | 2 ++ gio/gio.symbols | 1 + gio/gwin32appinfo.c | 10 +++++-- 7 files changed, 115 insertions(+), 28 deletions(-) diff --git a/gio/ChangeLog b/gio/ChangeLog index dac46af..e4fbbac 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,5 +1,18 @@ 2008-01-04 Alexander Larsson + * gappinfo.[ch]: + * gwin32appinfo.c: + * gio.symbols: + Add g_app_info_supports_files() + Remove desktop arg from g_app_info_should_show(). + + * gdesktopappinfo.[ch]: + Implement g_app_info_supports_files() and new should_show() + Add g_desktop_app_info_set_desktop_env() to set the desktop + for should_show(). (This will be set by gtk+ later) + +2008-01-04 Alexander Larsson + * gio.symbols: * gmemoryinputstream.[ch]: Improve API so that you can use multile chunks diff --git a/gio/gappinfo.c b/gio/gappinfo.c index aad0306..5136048 100644 --- a/gio/gappinfo.c +++ b/gio/gappinfo.c @@ -446,6 +446,27 @@ g_app_info_supports_uris (GAppInfo *appinfo) /** + * g_app_info_supports_files: + * @appinfo: a #GAppInfo. + * + * Checks if the application accepts files as arguments. + * + * Returns: %TRUE if the @appinfo supports files. + **/ +gboolean +g_app_info_supports_files (GAppInfo *appinfo) +{ + GAppInfoIface *iface; + + g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE); + + iface = G_APP_INFO_GET_IFACE (appinfo); + + return (* iface->supports_files) (appinfo); +} + + +/** * g_app_info_launch_uris: * @appinfo: a #GAppInfo. * @uris: a #GList containing URIs to launch. @@ -484,20 +505,14 @@ g_app_info_launch_uris (GAppInfo *appinfo, /** * g_app_info_should_show: * @appinfo: a #GAppInfo. - * @desktop_env: A string specifying what desktop this is, or %NULL. - * - * Checks if the application info should be shown when listing - * applications available. * - * @destkop_env is used to hide applications that are specified to - * just show up in specific desktops. For instance, passing in "GNOME" - * would show all applications specific to the Gnome desktop. + * Checks if the application info should be shown in menus that + * list available applications. * * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise. **/ gboolean -g_app_info_should_show (GAppInfo *appinfo, - const char *desktop_env) +g_app_info_should_show (GAppInfo *appinfo) { GAppInfoIface *iface; @@ -505,7 +520,7 @@ g_app_info_should_show (GAppInfo *appinfo, iface = G_APP_INFO_GET_IFACE (appinfo); - return (* iface->should_show) (appinfo, desktop_env); + return (* iface->should_show) (appinfo); } G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT); diff --git a/gio/gappinfo.h b/gio/gappinfo.h index af39b86..da5d34d 100644 --- a/gio/gappinfo.h +++ b/gio/gappinfo.h @@ -80,6 +80,7 @@ typedef struct _GAppInfo GAppInfo; /* Dummy typedef */ * @get_icon: Gets the #GIcon for the #GAppInfo. * @launch: Launches an application specified by the #GAppInfo. * @supports_uris: Indicates whether the application specified supports launching URIs. + * @supports_files: Indicates whether the application specified accepts filename arguments. * @launch_uris: Launches an application with a list of URIs. * @should_show: Returns whether an application should be shown (e.g. when getting a list of installed applications). * @@ -113,12 +114,12 @@ struct _GAppInfoIface GAppLaunchContext *launch_context, GError **error); gboolean (*supports_uris) (GAppInfo *appinfo); + gboolean (*supports_files) (GAppInfo *appinfo); gboolean (*launch_uris) (GAppInfo *appinfo, GList *uris, GAppLaunchContext *launch_context, GError **error); - gboolean (*should_show) (GAppInfo *appinfo, - const char *desktop_env); + gboolean (*should_show) (GAppInfo *appinfo); /* For changing associations */ gboolean (*set_as_default_for_type) (GAppInfo *appinfo, @@ -156,12 +157,12 @@ gboolean g_app_info_launch (GAppInfo *appin GAppLaunchContext *launch_context, GError **error); gboolean g_app_info_supports_uris (GAppInfo *appinfo); +gboolean g_app_info_supports_files (GAppInfo *appinfo); gboolean g_app_info_launch_uris (GAppInfo *appinfo, GList *uris, GAppLaunchContext *launch_context, GError **error); -gboolean g_app_info_should_show (GAppInfo *appinfo, - const char *desktop_env); +gboolean g_app_info_should_show (GAppInfo *appinfo); gboolean g_app_info_set_as_default_for_type (GAppInfo *appinfo, const char *content_type, diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 4433b1c..33bfa91 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -951,6 +951,16 @@ g_desktop_app_info_supports_uris (GAppInfo *appinfo) } static gboolean +g_desktop_app_info_supports_files (GAppInfo *appinfo) +{ + GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo); + + return info->exec && + ((strstr (info->exec, "%f") != NULL) || + (strstr (info->exec, "%F") != NULL)); +} + +static gboolean g_desktop_app_info_launch_uris (GAppInfo *appinfo, GList *uris, GAppLaunchContext *launch_context, @@ -981,17 +991,54 @@ g_desktop_app_info_launch_uris (GAppInfo *appinfo, return res; } +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 + * OnlyShowIn and NotShowIn + * desktop entry fields. + * + * The Desktop + * Menu specification recognizes the following: + * + * GNOME + * KDE + * ROX + * XFCE + * Old + * + * + * Should be called only once; subsequent calls are ignored. + */ +void +g_desktop_app_info_set_desktop_env (const gchar *desktop_env) +{ + G_LOCK (g_desktop_env); + if (!g_desktop_env) + g_desktop_env = g_strdup (desktop_env); + G_UNLOCK (g_desktop_env); +} + static gboolean -g_desktop_app_info_should_show (GAppInfo *appinfo, - const char *desktop_env) +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) @@ -1495,6 +1542,7 @@ g_desktop_app_info_iface_init (GAppInfoIface *iface) iface->get_icon = g_desktop_app_info_get_icon; iface->launch = g_desktop_app_info_launch; iface->supports_uris = g_desktop_app_info_supports_uris; + iface->supports_files = g_desktop_app_info_supports_files; iface->launch_uris = g_desktop_app_info_launch_uris; iface->should_show = g_desktop_app_info_should_show; iface->set_as_default_for_type = g_desktop_app_info_set_as_default_for_type; @@ -1648,21 +1696,14 @@ get_apps_from_dir (GHashTable *apps, { appinfo = g_desktop_app_info_new_from_filename (filename); - /* Don't return apps that don't take arguments */ - if (appinfo && - (g_desktop_app_info_get_is_hidden (appinfo) || - (appinfo->exec && - strstr (appinfo->exec,"%U") == NULL && - strstr (appinfo->exec,"%u") == NULL && - strstr (appinfo->exec,"%f") == NULL && - strstr (appinfo->exec,"%F") == NULL))) + if (appinfo && g_desktop_app_info_get_is_hidden (appinfo)) { g_object_unref (appinfo); appinfo = NULL; hidden = TRUE; } - if (appinfo != NULL || hidden) + if (appinfo || hidden) { g_hash_table_insert (apps, g_strdup (desktop_id), appinfo); @@ -1695,7 +1736,15 @@ get_apps_from_dir (GHashTable *apps, /** * g_app_info_get_all: * - * Gets a list of all of the applications currently registered on this system. + * Gets a list of all of the applications currently registered + * on this system. + * + * For desktop files, this includes applications that have + * NoDisplay=true set or are excluded from + * display by means of OnlyShowIn or + * NotShowIn. See g_app_info_should_show(). + * The returned list does not include applications which have + * the Hidden key set. * * Returns: a newly allocated #GList of references to #GAppInfos. **/ diff --git a/gio/gdesktopappinfo.h b/gio/gdesktopappinfo.h index 6ed5853..e7fed43 100644 --- a/gio/gdesktopappinfo.h +++ b/gio/gdesktopappinfo.h @@ -48,6 +48,8 @@ GDesktopAppInfo *g_desktop_app_info_new_from_filename (const char *filename GDesktopAppInfo *g_desktop_app_info_new (const char *desktop_id); gboolean g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info); +void g_desktop_app_info_set_desktop_env (const char *desktop_env); + G_END_DECLS diff --git a/gio/gio.symbols b/gio/gio.symbols index 79030c6..7c93e8d 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -38,6 +38,7 @@ g_app_info_get_executable g_app_info_get_icon g_app_info_launch g_app_info_supports_uris +g_app_info_supports_files g_app_info_launch_uris g_app_info_should_show g_app_info_set_as_default_for_type diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c index 0db39e9..d9ec404 100644 --- a/gio/gwin32appinfo.c +++ b/gio/gwin32appinfo.c @@ -333,6 +333,12 @@ g_win32_app_info_supports_uris (GAppInfo *appinfo) } static gboolean +g_win32_app_info_supports_files (GAppInfo *appinfo) +{ + return TRUE; +} + +static gboolean g_win32_app_info_launch_uris (GAppInfo *appinfo, GList *uris, GAppLaunchContext *launch_context, @@ -345,8 +351,7 @@ g_win32_app_info_launch_uris (GAppInfo *appinfo, } static gboolean -g_win32_app_info_should_show (GAppInfo *appinfo, - const char *win32_env) +g_win32_app_info_should_show (GAppInfo *appinfo) { GWin32AppInfo *info = G_WIN32_APP_INFO (appinfo); @@ -392,6 +397,7 @@ g_win32_app_info_iface_init (GAppInfoIface *iface) iface->get_icon = g_win32_app_info_get_icon; iface->launch = g_win32_app_info_launch; iface->supports_uris = g_win32_app_info_supports_uris; + iface->supports_files = g_win32_app_info_supports_files; iface->launch_uris = g_win32_app_info_launch_uris; iface->should_show = g_win32_app_info_should_show; iface->set_as_default_for_type = g_win32_app_info_set_as_default_for_type; -- 2.7.4