mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 06:56:14 +01:00
GAppInfo: add a mechanism to query supported content types
This essentially adds an accessor for the MimeType field in desktop files, to retrieve the list of all mime types supported by an application. The interface though is part of GAppInfo, so it could be implemented in the future by other backends. https://bugzilla.gnome.org/show_bug.cgi?id=674111
This commit is contained in:
parent
e011d2c921
commit
0417ddab6f
@ -1313,6 +1313,7 @@ g_app_info_set_as_last_used_for_type
|
||||
g_app_info_add_supports_type
|
||||
g_app_info_can_remove_supports_type
|
||||
g_app_info_remove_supports_type
|
||||
g_app_info_get_supported_types
|
||||
g_app_info_get_all
|
||||
g_app_info_get_all_for_type
|
||||
g_app_info_get_default_for_type
|
||||
|
@ -458,6 +458,37 @@ g_app_info_remove_supports_type (GAppInfo *appinfo,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_app_info_get_supported_types:
|
||||
* @info: a #GAppInfo that can handle files
|
||||
*
|
||||
* Retrieves the list of content types that @app_info claims to support.
|
||||
* If this information is not provided by the environment, this function
|
||||
* will return %NULL.
|
||||
* This function does not take in consideration associations added with
|
||||
* g_app_info_add_supports_type(), but only those exported directly by
|
||||
* the application.
|
||||
*
|
||||
* Returns: (transfer none) (array zero-terminated=1) (element-type utf8):
|
||||
* a list of content types.
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
const char **
|
||||
g_app_info_get_supported_types (GAppInfo *appinfo)
|
||||
{
|
||||
GAppInfoIface *iface;
|
||||
|
||||
g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
|
||||
|
||||
iface = G_APP_INFO_GET_IFACE (appinfo);
|
||||
|
||||
if (iface->get_supported_types)
|
||||
return iface->get_supported_types (appinfo);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_app_info_get_icon:
|
||||
|
@ -132,6 +132,7 @@ struct _GAppInfoIface
|
||||
gboolean (* set_as_last_used_for_type) (GAppInfo *appinfo,
|
||||
const char *content_type,
|
||||
GError **error);
|
||||
const char ** (* get_supported_types) (GAppInfo *appinfo);
|
||||
};
|
||||
|
||||
GType g_app_info_get_type (void) G_GNUC_CONST;
|
||||
@ -174,6 +175,9 @@ gboolean g_app_info_can_remove_supports_type (GAppInfo *appin
|
||||
gboolean g_app_info_remove_supports_type (GAppInfo *appinfo,
|
||||
const char *content_type,
|
||||
GError **error);
|
||||
GLIB_AVAILABLE_IN_2_34
|
||||
const char **g_app_info_get_supported_types (GAppInfo *appinfo);
|
||||
|
||||
gboolean g_app_info_can_delete (GAppInfo *appinfo);
|
||||
gboolean g_app_info_delete (GAppInfo *appinfo);
|
||||
|
||||
|
@ -108,6 +108,7 @@ struct _GDesktopAppInfo
|
||||
char *path;
|
||||
char *categories;
|
||||
char *startup_wm_class;
|
||||
char **mime_types;
|
||||
|
||||
guint nodisplay : 1;
|
||||
guint hidden : 1;
|
||||
@ -187,6 +188,7 @@ g_desktop_app_info_finalize (GObject *object)
|
||||
g_free (info->path);
|
||||
g_free (info->categories);
|
||||
g_free (info->startup_wm_class);
|
||||
g_strfreev (info->mime_types);
|
||||
|
||||
G_OBJECT_CLASS (g_desktop_app_info_parent_class)->finalize (object);
|
||||
}
|
||||
@ -333,6 +335,7 @@ g_desktop_app_info_load_from_keyfile (GDesktopAppInfo *info,
|
||||
info->hidden = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL) != FALSE;
|
||||
info->categories = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_CATEGORIES, NULL);
|
||||
info->startup_wm_class = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, STARTUP_WM_CLASS_KEY, NULL);
|
||||
info->mime_types = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, NULL, NULL);
|
||||
|
||||
info->icon = NULL;
|
||||
if (info->icon_name)
|
||||
@ -1981,6 +1984,15 @@ g_desktop_app_info_remove_supports_type (GAppInfo *appinfo,
|
||||
error);
|
||||
}
|
||||
|
||||
static const char **
|
||||
g_desktop_app_info_get_supported_types (GAppInfo *appinfo)
|
||||
{
|
||||
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
|
||||
|
||||
return (const char**) info->mime_types;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
|
||||
GError **error)
|
||||
@ -2202,6 +2214,7 @@ g_desktop_app_info_iface_init (GAppInfoIface *iface)
|
||||
iface->get_commandline = g_desktop_app_info_get_commandline;
|
||||
iface->get_display_name = g_desktop_app_info_get_display_name;
|
||||
iface->set_as_last_used_for_type = g_desktop_app_info_set_as_last_used_for_type;
|
||||
iface->get_supported_types = g_desktop_app_info_get_supported_types;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -56,6 +56,7 @@ g_app_info_get_description
|
||||
g_app_info_get_executable
|
||||
g_app_info_get_commandline
|
||||
g_app_info_get_icon
|
||||
g_app_info_get_supported_types
|
||||
g_app_info_launch
|
||||
g_app_info_supports_uris
|
||||
g_app_info_supports_files
|
||||
|
@ -10,3 +10,4 @@ Exec=./appinfo-test --option
|
||||
Icon=testicon
|
||||
StartupNotify=true
|
||||
StartupWMClass=appinfo-class
|
||||
MimeType=image/png;image/jpeg;
|
||||
|
@ -287,6 +287,21 @@ test_startup_wm_class (void)
|
||||
g_object_unref (appinfo);
|
||||
}
|
||||
|
||||
static void
|
||||
test_supported_types (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
const char * const *content_types;
|
||||
|
||||
appinfo = G_APP_INFO (g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop"));
|
||||
content_types = g_app_info_get_supported_types (appinfo);
|
||||
|
||||
g_assert_cmpint (g_strv_length ((char**)content_types), ==, 2);
|
||||
g_assert_cmpstr (content_types[0], ==, "image/png");
|
||||
|
||||
g_object_unref (appinfo);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -303,6 +318,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/appinfo/associations", test_associations);
|
||||
g_test_add_func ("/appinfo/environment", test_environment);
|
||||
g_test_add_func ("/appinfo/startup-wm-class", test_startup_wm_class);
|
||||
g_test_add_func ("/appinfo/supported-types", test_supported_types);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user