summaryrefslogtreecommitdiff
path: root/gio/gicon.c
diff options
context:
space:
mode:
authorJehan <jehan@girinstud.io>2018-09-05 14:51:18 +0200
committerJehan <jehan@girinstud.io>2018-09-13 13:16:40 +0200
commit8519368c0eb26ce353e5e1ffd4d23fe8353848dc (patch)
tree6ea965b9ad9850c435c11a3f26bfcfc34204d6bb /gio/gicon.c
parentd2f412590e088ada916aef18dcf051916b140c6e (diff)
downloadglib-8519368c0eb26ce353e5e1ffd4d23fe8353848dc.tar.gz
Fix g_icon_to_string() regression (doc inconsistency).
g_icon_new_for_string() docs states that it should return a single name when created with a single name. I add a second condition to this case: the themed icon must not include default fallbacks (i.e. it must not have been created with `g_themed_icon_new_with_default_fallbacks()`). Otherwise the return value of `g_icon_new_for_string()` would not recreate the same icon list when passed to `g_icon_new_for_string()` (which would be another documentation inconsistency). g_icon_new_for_string() is now back to old behavior for this specific case. I also revert the unit test for this case, and add a new unit test when using g_themed_icon_new_with_default_fallbacks() with a single name as well. Closes #1513.
Diffstat (limited to 'gio/gicon.c')
-rw-r--r--gio/gicon.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/gio/gicon.c b/gio/gicon.c
index 5f943f559..4f73d7568 100644
--- a/gio/gicon.c
+++ b/gio/gicon.c
@@ -199,8 +199,8 @@ g_icon_to_string_tokenized (GIcon *icon, GString *s)
* native, the returned string is the result of g_file_get_uri()
* (such as `sftp://path/to/my%20icon.png`).
*
- * - If @icon is a #GThemedIcon with exactly one name, the encoding is
- * simply the name (such as `network-server`).
+ * - If @icon is a #GThemedIcon with exactly one name and no fallbacks,
+ * the encoding is simply the name (such as `network-server`).
*
* Virtual: to_tokens
* Returns: (nullable): An allocated NUL-terminated UTF8 string or
@@ -237,15 +237,23 @@ g_icon_to_string (GIcon *icon)
}
else if (G_IS_THEMED_ICON (icon))
{
- const char * const *names;
-
- names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+ char **names = NULL;
+ gboolean use_default_fallbacks = FALSE;
+
+ g_object_get (G_OBJECT (icon),
+ "names", &names,
+ "use-default-fallbacks", &use_default_fallbacks,
+ NULL);
+ /* Themed icon initialized with a single name and no fallbacks. */
if (names != NULL &&
names[0] != NULL &&
names[0][0] != '.' && /* Allowing icons starting with dot would break G_ICON_SERIALIZATION_MAGIC0 */
g_utf8_validate (names[0], -1, NULL) && /* Only return utf8 strings */
- names[1] == NULL)
+ names[1] == NULL &&
+ ! use_default_fallbacks)
ret = g_strdup (names[0]);
+
+ g_strfreev (names);
}
if (ret == NULL)