diff --git a/gio/gappinfo.c b/gio/gappinfo.c index dd2f75695..c54fc677b 100644 --- a/gio/gappinfo.c +++ b/gio/gappinfo.c @@ -116,6 +116,38 @@ g_app_info_default_init (GAppInfoInterface *iface) { } +/** + * g_app_info_create_from_commandline: + * @commandline: (type filename): the command line to use + * @application_name: (nullable): the application name, or `NULL` to use @commandline + * @flags: flags that can specify details of the created [iface@Gio.AppInfo] + * @error: a [type@GLib.Error] location to store the error occurring, + * `NULL` to ignore. + * + * Creates a new [iface@Gio.AppInfo] from the given information. + * + * Note that for @commandline, the quoting rules of the `Exec` key of the + * [freedesktop.org Desktop Entry Specification](http://freedesktop.org/Standards/desktop-entry-spec) + * are applied. For example, if the @commandline contains + * percent-encoded URIs, the percent-character must be doubled in order to prevent it from + * being swallowed by `Exec` key unquoting. See + * [the specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html) + * for exact quoting rules. + * + * Returns: (transfer full): new [iface@Gio.AppInfo] for given command. + **/ +GAppInfo * +g_app_info_create_from_commandline (const char *commandline, + const char *application_name, + GAppInfoCreateFlags flags, + GError **error) +{ + g_return_val_if_fail (commandline, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + return g_app_info_create_from_commandline_impl (commandline, application_name, + flags, error); +} /** * g_app_info_dup: @@ -374,6 +406,156 @@ g_app_info_set_as_last_used_for_type (GAppInfo *appinfo, return FALSE; } +/** + * g_app_info_get_all: + * + * Gets a list of all of the applications currently registered + * on this system. + * + * For desktop files, this includes applications that have + * [`NoDisplay=true`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-nodisplay) + * set or are excluded from display by means of + * [`OnlyShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-onlyshowin) + * or [`NotShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-notshowin). + * See [method@Gio.AppInfo.should_show]. + * + * The returned list does not include applications which have the + * [`Hidden` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-hidden) + * set. + * + * Returns: (element-type GAppInfo) (transfer full): a newly allocated + * list of references to [iface@Gio.AppInfo]s. + **/ +GList * +g_app_info_get_all (void) +{ + return g_app_info_get_all_impl (); +} + +/** + * g_app_info_get_recommended_for_type: + * @content_type: the content type to find a [iface@Gio.AppInfo] for + * + * Gets a list of recommended [iface@Gio.AppInfo]s for a given content type, + * i.e. those applications which claim to support the given content type + * exactly, and not by MIME type subclassing. + * + * Note that the first application of the list is the last used one, i.e. + * the last one for which [method@Gio.AppInfo.set_as_last_used_for_type] has + * been called. + * + * Returns: (element-type GAppInfo) (transfer full): list of + * [iface@Gio.AppInfo]s for given @content_type or `NULL` on error. + * + * Since: 2.28 + **/ +GList * +g_app_info_get_recommended_for_type (const gchar *content_type) +{ + g_return_val_if_fail (content_type != NULL, NULL); + + return g_app_info_get_recommended_for_type_impl (content_type); +} + +/** + * g_app_info_get_fallback_for_type: + * @content_type: the content type to find a [iface@Gio.AppInfo] for + * + * Gets a list of fallback [iface@Gio.AppInfo]s for a given content type, i.e. + * those applications which claim to support the given content type by MIME + * type subclassing and not directly. + * + * Returns: (element-type GAppInfo) (transfer full): list of [iface@Gio.AppInfo]s + * for given @content_type or `NULL` on error. + * + * Since: 2.28 + **/ +GList * +g_app_info_get_fallback_for_type (const gchar *content_type) +{ + g_return_val_if_fail (content_type != NULL, NULL); + + return g_app_info_get_fallback_for_type_impl (content_type); +} + +/** + * g_app_info_get_all_for_type: + * @content_type: the content type to find a [iface@Gio.AppInfo] for + * + * Gets a list of all [iface@Gio.AppInfo]s for a given content type, + * including the recommended and fallback [iface@Gio.AppInfo]s. See + * [func@Gio.AppInfo.get_recommended_for_type] and + * [func@Gio.AppInfo.get_fallback_for_type]. + * + * Returns: (element-type GAppInfo) (transfer full): list of + * [iface@Gio.AppInfo]s for given @content_type. + **/ +GList * +g_app_info_get_all_for_type (const char *content_type) +{ + g_return_val_if_fail (content_type != NULL, NULL); + + return g_app_info_get_all_for_type_impl (content_type); +} + +/** + * g_app_info_reset_type_associations: + * @content_type: a content type + * + * Removes all changes to the type associations done by + * [method@Gio.AppInfo.set_as_default_for_type], + * [method@Gio.AppInfo.set_as_default_for_extension], + * [method@Gio.AppInfo.add_supports_type] or + * [method@Gio.AppInfo.remove_supports_type]. + * + * Since: 2.20 + */ +void +g_app_info_reset_type_associations (const char *content_type) +{ + g_app_info_reset_type_associations_impl (content_type); +} + +/** + * g_app_info_get_default_for_type: + * @content_type: the content type to find a [iface@Gio.AppInfo] for + * @must_support_uris: if `TRUE`, the [iface@Gio.AppInfo] is expected to + * support URIs + * + * Gets the default [iface@Gio.AppInfo] for a given content type. + * + * Returns: (transfer full) (nullable): [iface@Gio.AppInfo] for given + * @content_type or `NULL` on error. + */ +GAppInfo * +g_app_info_get_default_for_type (const char *content_type, + gboolean must_support_uris) +{ + g_return_val_if_fail (content_type != NULL, NULL); + + return g_app_info_get_default_for_type_impl (content_type, must_support_uris); +} + +/** + * g_app_info_get_default_for_uri_scheme: + * @uri_scheme: a string containing a URI scheme. + * + * Gets the default application for handling URIs with the given URI scheme. + * + * A URI scheme is the initial part of the URI, up to but not including the `:`. + * For example, `http`, `ftp` or `sip`. + * + * Returns: (transfer full) (nullable): [iface@Gio.AppInfo] for given + * @uri_scheme or `NULL` on error. + */ +GAppInfo * +g_app_info_get_default_for_uri_scheme (const char *uri_scheme) +{ + g_return_val_if_fail (uri_scheme != NULL && *uri_scheme != '\0', NULL); + + return g_app_info_get_default_for_uri_scheme_impl (uri_scheme); +} + /** * g_app_info_set_as_default_for_extension: * @appinfo: the app info diff --git a/gio/gappinfoprivate.h b/gio/gappinfoprivate.h index dbf46c22a..df6a2d3bf 100644 --- a/gio/gappinfoprivate.h +++ b/gio/gappinfoprivate.h @@ -25,4 +25,17 @@ void g_app_info_monitor_fire (void); +GAppInfo *g_app_info_create_from_commandline_impl (const char *commandline, + const char *application_name, + GAppInfoCreateFlags flags, + GError **error); +GList *g_app_info_get_recommended_for_type_impl (const gchar *content_type); +GList *g_app_info_get_fallback_for_type_impl (const gchar *content_type); +GList *g_app_info_get_all_for_type_impl (const char *content_type); +void g_app_info_reset_type_associations_impl (const char *content_type); +GAppInfo *g_app_info_get_default_for_type_impl (const char *content_type, + gboolean must_support_uris); +GAppInfo *g_app_info_get_default_for_uri_scheme_impl (const char *uri_scheme); +GList *g_app_info_get_all_impl (void); + #endif /* __G_APP_INFO_PRIVATE_H__ */ diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index ffffa8ca8..343f30949 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -4324,31 +4324,12 @@ g_desktop_app_info_delete (GAppInfo *appinfo) } /* Create for commandline {{{2 */ -/** - * g_app_info_create_from_commandline: - * @commandline: (type filename): the command line to use - * @application_name: (nullable): the application name, or `NULL` to use @commandline - * @flags: flags that can specify details of the created [iface@Gio.AppInfo] - * @error: a [type@GLib.Error] location to store the error occurring, - * `NULL` to ignore. - * - * Creates a new [iface@Gio.AppInfo] from the given information. - * - * Note that for @commandline, the quoting rules of the `Exec` key of the - * [freedesktop.org Desktop Entry Specification](http://freedesktop.org/Standards/desktop-entry-spec) - * are applied. For example, if the @commandline contains - * percent-encoded URIs, the percent-character must be doubled in order to prevent it from - * being swallowed by `Exec` key unquoting. See - * [the specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html) - * for exact quoting rules. - * - * Returns: (transfer full): new [iface@Gio.AppInfo] for given command. - **/ + GAppInfo * -g_app_info_create_from_commandline (const char *commandline, - const char *application_name, - GAppInfoCreateFlags flags, - GError **error) +g_app_info_create_from_commandline_impl (const char *commandline, + const char *application_name, + GAppInfoCreateFlags flags, + GError **error) { char **split; char *basename; @@ -4497,25 +4478,8 @@ g_desktop_app_info_get_desktop_ids_for_content_type (const gchar *content_type, return (gchar **) g_ptr_array_free (hits, FALSE); } -/** - * g_app_info_get_recommended_for_type: - * @content_type: the content type to find a [iface@Gio.AppInfo] for - * - * Gets a list of recommended [iface@Gio.AppInfo]s for a given content type, - * i.e. those applications which claim to support the given content type - * exactly, and not by MIME type subclassing. - * - * Note that the first application of the list is the last used one, i.e. - * the last one for which [method@Gio.AppInfo.set_as_last_used_for_type] has - * been called. - * - * Returns: (element-type GAppInfo) (transfer full): list of - * [iface@Gio.AppInfo]s for given @content_type or `NULL` on error. - * - * Since: 2.28 - **/ GList * -g_app_info_get_recommended_for_type (const gchar *content_type) +g_app_info_get_recommended_for_type_impl (const gchar *content_type) { gchar **desktop_ids; GList *infos; @@ -4540,21 +4504,8 @@ g_app_info_get_recommended_for_type (const gchar *content_type) return g_list_reverse (infos); } -/** - * g_app_info_get_fallback_for_type: - * @content_type: the content type to find a [iface@Gio.AppInfo] for - * - * Gets a list of fallback [iface@Gio.AppInfo]s for a given content type, i.e. - * those applications which claim to support the given content type by MIME - * type subclassing and not directly. - * - * Returns: (element-type GAppInfo) (transfer full): list of [iface@Gio.AppInfo]s - * for given @content_type or `NULL` on error. - * - * Since: 2.28 - **/ GList * -g_app_info_get_fallback_for_type (const gchar *content_type) +g_app_info_get_fallback_for_type_impl (const gchar *content_type) { gchar **recommended_ids; gchar **all_ids; @@ -4592,20 +4543,8 @@ g_app_info_get_fallback_for_type (const gchar *content_type) return g_list_reverse (infos); } -/** - * g_app_info_get_all_for_type: - * @content_type: the content type to find a [iface@Gio.AppInfo] for - * - * Gets a list of all [iface@Gio.AppInfo]s for a given content type, - * including the recommended and fallback [iface@Gio.AppInfo]s. See - * [func@Gio.AppInfo.get_recommended_for_type] and - * [func@Gio.AppInfo.get_fallback_for_type]. - * - * Returns: (element-type GAppInfo) (transfer full): list of - * [iface@Gio.AppInfo]s for given @content_type. - **/ GList * -g_app_info_get_all_for_type (const char *content_type) +g_app_info_get_all_for_type_impl (const char *content_type) { gchar **desktop_ids; GList *infos; @@ -4630,40 +4569,17 @@ g_app_info_get_all_for_type (const char *content_type) return g_list_reverse (infos); } -/** - * g_app_info_reset_type_associations: - * @content_type: a content type - * - * Removes all changes to the type associations done by - * [method@Gio.AppInfo.set_as_default_for_type], - * [method@Gio.AppInfo.set_as_default_for_extension], - * [method@Gio.AppInfo.add_supports_type] or - * [method@Gio.AppInfo.remove_supports_type]. - * - * Since: 2.20 - */ void -g_app_info_reset_type_associations (const char *content_type) +g_app_info_reset_type_associations_impl (const char *content_type) { update_mimeapps_list (NULL, content_type, UPDATE_MIME_NONE, NULL); } -/** - * g_app_info_get_default_for_type: - * @content_type: the content type to find a [iface@Gio.AppInfo] for - * @must_support_uris: if `TRUE`, the [iface@Gio.AppInfo] is expected to - * support URIs - * - * Gets the default [iface@Gio.AppInfo] for a given content type. - * - * Returns: (transfer full) (nullable): [iface@Gio.AppInfo] for given - * @content_type or `NULL` on error. - */ GAppInfo * -g_app_info_get_default_for_type (const char *content_type, - gboolean must_support_uris) +g_app_info_get_default_for_type_impl (const char *content_type, + gboolean must_support_uris) { GPtrArray *blocklist; GPtrArray *results; @@ -4726,20 +4642,8 @@ out: return info; } -/** - * g_app_info_get_default_for_uri_scheme: - * @uri_scheme: a string containing a URI scheme. - * - * Gets the default application for handling URIs with the given URI scheme. - * - * A URI scheme is the initial part of the URI, up to but not including the `:`. - * For example, `http`, `ftp` or `sip`. - * - * Returns: (transfer full) (nullable): [iface@Gio.AppInfo] for given - * @uri_scheme or `NULL` on error. - */ GAppInfo * -g_app_info_get_default_for_uri_scheme (const char *uri_scheme) +g_app_info_get_default_for_uri_scheme_impl (const char *uri_scheme) { GAppInfo *app_info; char *content_type, *scheme_down; @@ -4905,28 +4809,8 @@ g_desktop_app_info_search (const gchar *search_string) return results; } -/** - * g_app_info_get_all: - * - * Gets a list of all of the applications currently registered - * on this system. - * - * For desktop files, this includes applications that have - * [`NoDisplay=true`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-nodisplay) - * set or are excluded from display by means of - * [`OnlyShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-onlyshowin) - * or [`NotShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-notshowin). - * See [method@Gio.AppInfo.should_show]. - * - * The returned list does not include applications which have the - * [`Hidden` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-hidden) - * set. - * - * Returns: (element-type GAppInfo) (transfer full): a newly allocated - * list of references to [iface@Gio.AppInfo]s. - **/ GList * -g_app_info_get_all (void) +g_app_info_get_all_impl (void) { GHashTable *apps; GHashTableIter iter; diff --git a/gio/gosxappinfo.m b/gio/gosxappinfo.m index 50b08e0be..6de647d6b 100644 --- a/gio/gosxappinfo.m +++ b/gio/gosxappinfo.m @@ -22,6 +22,7 @@ #include "config.h" #include "gappinfo.h" +#include "gappinfoprivate.h" #include "gosxappinfo.h" #include "gcontenttype.h" #include "gfile.h" @@ -577,10 +578,10 @@ g_osx_app_info_iface_init (GAppInfoIface *iface) } GAppInfo * -g_app_info_create_from_commandline (const char *commandline, - const char *application_name, - GAppInfoCreateFlags flags, - GError **error) +g_app_info_create_from_commandline_impl (const char *commandline, + const char *application_name, + GAppInfoCreateFlags flags, + GError **error) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Creating an app info from a command line not currently supported"); @@ -622,7 +623,7 @@ g_osx_app_info_get_all_for_scheme (const char *cscheme) } GList * -g_app_info_get_all_for_type (const char *content_type) +g_app_info_get_all_for_type_impl (const char *content_type) { gchar *mime_type; CFArrayRef bundle_list; @@ -667,20 +668,20 @@ g_app_info_get_all_for_type (const char *content_type) } GList * -g_app_info_get_recommended_for_type (const char *content_type) +g_app_info_get_recommended_for_type_impl (const char *content_type) { return g_app_info_get_all_for_type (content_type); } GList * -g_app_info_get_fallback_for_type (const char *content_type) +g_app_info_get_fallback_for_type_impl (const char *content_type) { return g_app_info_get_all_for_type (content_type); } GAppInfo * -g_app_info_get_default_for_type (const char *content_type, - gboolean must_support_uris) +g_app_info_get_default_for_type_impl (const char *content_type, + gboolean must_support_uris) { gchar *mime_type; CFStringRef type; @@ -731,7 +732,7 @@ g_app_info_get_default_for_type (const char *content_type, } GAppInfo * -g_app_info_get_default_for_uri_scheme (const char *uri_scheme) +g_app_info_get_default_for_uri_scheme_impl (const char *uri_scheme) { CFStringRef scheme, bundle_id; NSBundle *bundle; @@ -756,7 +757,7 @@ g_app_info_get_default_for_uri_scheme (const char *uri_scheme) } GList * -g_app_info_get_all (void) +g_app_info_get_all_impl (void) { /* There is no API for this afaict * could manually do it... @@ -765,6 +766,6 @@ g_app_info_get_all (void) } void -g_app_info_reset_type_associations (const char *content_type) +g_app_info_reset_type_associations_impl (const char *content_type) { } diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c index 0b179d877..f2b9cf346 100644 --- a/gio/gwin32appinfo.c +++ b/gio/gwin32appinfo.c @@ -29,6 +29,7 @@ #include #include "gcontenttype.h" +#include "gappinfoprivate.h" #include "gwin32appinfo.h" #include "gappinfo.h" #include "gioerror.h" @@ -5671,10 +5672,10 @@ g_win32_app_info_get_supported_types (GAppInfo *appinfo) } GAppInfo * -g_app_info_create_from_commandline (const char *commandline, - const char *application_name, - GAppInfoCreateFlags flags, - GError **error) +g_app_info_create_from_commandline_impl (const char *commandline, + const char *application_name, + GAppInfoCreateFlags flags, + GError **error) { GWin32AppInfo *info; GWin32AppInfoApplication *app; @@ -5754,7 +5755,7 @@ g_win32_app_info_iface_init (GAppInfoIface *iface) } GAppInfo * -g_app_info_get_default_for_uri_scheme (const char *uri_scheme) +g_app_info_get_default_for_uri_scheme_impl (const char *uri_scheme) { GWin32AppInfoURLSchema *scheme = NULL; char *scheme_down; @@ -5796,8 +5797,8 @@ g_app_info_get_default_for_uri_scheme (const char *uri_scheme) } GAppInfo * -g_app_info_get_default_for_type (const char *content_type, - gboolean must_support_uris) +g_app_info_get_default_for_type_impl (const char *content_type, + gboolean must_support_uris) { GWin32AppInfoFileExtension *ext = NULL; char *ext_down; @@ -5858,7 +5859,7 @@ g_app_info_get_default_for_type (const char *content_type, } GList * -g_app_info_get_all (void) +g_app_info_get_all_impl (void) { GHashTableIter iter; gpointer value; @@ -5887,7 +5888,7 @@ g_app_info_get_all (void) } GList * -g_app_info_get_all_for_type (const char *content_type) +g_app_info_get_all_for_type_impl (const char *content_type) { GWin32AppInfoFileExtension *ext = NULL; char *ext_down; @@ -5957,21 +5958,21 @@ g_app_info_get_all_for_type (const char *content_type) } GList * -g_app_info_get_fallback_for_type (const gchar *content_type) +g_app_info_get_fallback_for_type_impl (const gchar *content_type) { /* TODO: fix this once gcontenttype support is improved */ return g_app_info_get_all_for_type (content_type); } GList * -g_app_info_get_recommended_for_type (const gchar *content_type) +g_app_info_get_recommended_for_type_impl (const gchar *content_type) { /* TODO: fix this once gcontenttype support is improved */ return g_app_info_get_all_for_type (content_type); } void -g_app_info_reset_type_associations (const char *content_type) +g_app_info_reset_type_associations_impl (const char *content_type) { /* nothing to do */ }