[glib] GAppInfo: add a mechanism to query supported content types
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GAppInfo: add a mechanism to query supported content types
- Date: Wed, 16 May 2012 10:44:18 +0000 (UTC)
commit 0417ddab6fbd2f1cddbb9218e0e300e04da2eda5
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sat Apr 14 19:34:00 2012 +0200
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
docs/reference/gio/gio-sections.txt | 1 +
gio/gappinfo.c | 31 +++++++++++++++++++++++++++++++
gio/gappinfo.h | 4 ++++
gio/gdesktopappinfo.c | 13 +++++++++++++
gio/gio.symbols | 1 +
gio/tests/appinfo-test.desktop | 1 +
gio/tests/appinfo.c | 16 ++++++++++++++++
7 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 584a3f5..7c5636d 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -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
diff --git a/gio/gappinfo.c b/gio/gappinfo.c
index 666d2b0..53d3c39 100644
--- a/gio/gappinfo.c
+++ b/gio/gappinfo.c
@@ -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:
diff --git a/gio/gappinfo.h b/gio/gappinfo.h
index b6786d6..17d2f76 100644
--- a/gio/gappinfo.h
+++ b/gio/gappinfo.h
@@ -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);
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 4044679..fafea1c 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -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
diff --git a/gio/gio.symbols b/gio/gio.symbols
index f4dff35..3f6f773 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -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
diff --git a/gio/tests/appinfo-test.desktop b/gio/tests/appinfo-test.desktop
index f2b873a..e4d8396 100644
--- a/gio/tests/appinfo-test.desktop
+++ b/gio/tests/appinfo-test.desktop
@@ -10,3 +10,4 @@ Exec=./appinfo-test --option
Icon=testicon
StartupNotify=true
StartupWMClass=appinfo-class
+MimeType=image/png;image/jpeg;
diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c
index bb24669..e8e511a 100644
--- a/gio/tests/appinfo.c
+++ b/gio/tests/appinfo.c
@@ -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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]