GIcon: pure re-factor of _from_string()

Split out the 'simple string format' cases of URIs, file paths and
themed icons to a separate function.

This function will be shared by g_icon_deserialize().

https://bugzilla.gnome.org/show_bug.cgi?id=688820
This commit is contained in:
Ryan Lortie 2013-04-20 16:41:09 -04:00
parent c0af442909
commit 519e989ea8

View File

@ -381,6 +381,33 @@ ensure_builtin_icon_types (void)
g_type_ensure (G_TYPE_EMBLEM);
}
/* handles the 'simple' cases: GFileIcon and GThemedIcon */
static GIcon *
g_icon_new_for_string_simple (const gchar *str)
{
gchar *scheme;
GIcon *icon;
if (str[0] == '.')
return NULL;
/* handle special GFileIcon and GThemedIcon cases */
scheme = g_uri_parse_scheme (str);
if (scheme != NULL || str[0] == '/' || str[0] == G_DIR_SEPARATOR)
{
GFile *location;
location = g_file_new_for_commandline_arg (str);
icon = g_file_icon_new (location);
g_object_unref (location);
}
else
icon = g_themed_icon_new (str);
g_free (scheme);
return icon;
}
/**
* g_icon_new_for_string:
* @str: A string obtained via g_icon_to_string().
@ -402,16 +429,16 @@ GIcon *
g_icon_new_for_string (const gchar *str,
GError **error)
{
GIcon *icon;
GIcon *icon = NULL;
g_return_val_if_fail (str != NULL, NULL);
icon = g_icon_new_for_string_simple (str);
if (icon)
return icon;
ensure_builtin_icon_types ();
icon = NULL;
if (*str == '.')
{
if (g_str_has_prefix (str, G_ICON_SERIALIZATION_MAGIC0))
{
gchar **tokens;
@ -426,24 +453,6 @@ g_icon_new_for_string (const gchar *str,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Can't handle the supplied version of the icon encoding"));
}
else
{
gchar *scheme;
/* handle special GFileIcon and GThemedIcon cases */
scheme = g_uri_parse_scheme (str);
if (scheme != NULL || str[0] == '/' || str[0] == G_DIR_SEPARATOR)
{
GFile *location;
location = g_file_new_for_commandline_arg (str);
icon = g_file_icon_new (location);
g_object_unref (location);
}
else
icon = g_themed_icon_new (str);
g_free (scheme);
}
return icon;
}