2008-01-04 Alexander Larsson <alexl@redhat.com>
+ * 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 <alexl@redhat.com>
+
* gio.symbols:
* gmemoryinputstream.[ch]:
Improve API so that you can use multile chunks
/**
+ * 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.
/**
* 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;
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);
* @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).
* <ulink url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">
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,
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,
}
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,
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
+ * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal>
+ * desktop entry fields.
+ *
+ * The <ulink url="http://standards.freedesktop.org/menu-spec/latest/">Desktop
+ * Menu specification</ulink> recognizes the following:
+ * <simplelist>
+ * <member>GNOME</member>
+ * <member>KDE</member>
+ * <member>ROX</member>
+ * <member>XFCE</member>
+ * <member>Old</member>
+ * </simplelist>
+ *
+ * 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)
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;
{
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);
/**
* 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
+ * <literal>NoDisplay=true</liberal> set or are excluded from
+ * display by means of <literal>OnlyShowIn</literal> or
+ * <literal>NotShowIn</literal>. See g_app_info_should_show().
+ * The returned list does not include applications which have
+ * the <literal>Hidden</literal> key set.
*
* Returns: a newly allocated #GList of references to #GAppInfo<!---->s.
**/
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
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
}
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,
}
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);
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;