mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-10-01 05:23:56 +00:00
bookmark: Simplify get_native_icon() and get_xdg_type()
The usage of goto's makes get_native_icon() unnecessarily complex and
error-prone.
Indeed, the goto's may be the reason why the commit[0] which introduced
the `nautilus_bookmark_get_xdg_type()` function as a replacement for
`nautilus_file_is_user_special_directory()` didn't remove the obsolete
checks `bookmark->file == NULL` and `xdg_type < G_USER_N_DIRECTORIES`.
Simplify and modernize `nautilus_bookmark_get_xdg_type()` as well, to
make it clear it the passed `GUserDirectory` value is always lower than
G_USER_N_DIRECTORIES, because it's the for loop condition.
[0] commit 1dcd2d816a
This commit is contained in:
parent
7e427c0ba7
commit
a011010567
|
@ -190,37 +190,28 @@ gboolean
|
||||||
nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark,
|
nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark,
|
||||||
GUserDirectory *directory)
|
GUserDirectory *directory)
|
||||||
{
|
{
|
||||||
gboolean match;
|
for (GUserDirectory dir = 0; dir < G_USER_N_DIRECTORIES; dir++)
|
||||||
GFile *location;
|
|
||||||
const gchar *path;
|
|
||||||
GUserDirectory dir;
|
|
||||||
|
|
||||||
match = FALSE;
|
|
||||||
|
|
||||||
for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++)
|
|
||||||
{
|
{
|
||||||
path = g_get_user_special_dir (dir);
|
const gchar *path = g_get_user_special_dir (dir);
|
||||||
if (!path)
|
|
||||||
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = g_file_new_for_path (path);
|
g_autoptr (GFile) location = g_file_new_for_path (path);
|
||||||
match = g_file_equal (location, bookmark->location);
|
|
||||||
g_object_unref (location);
|
|
||||||
|
|
||||||
if (match)
|
if (g_file_equal (location, bookmark->location))
|
||||||
{
|
{
|
||||||
break;
|
if (directory != NULL)
|
||||||
|
{
|
||||||
|
*directory = dir;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match && directory != NULL)
|
return FALSE;
|
||||||
{
|
|
||||||
*directory = dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
return match;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GIcon *
|
static GIcon *
|
||||||
|
@ -228,44 +219,20 @@ get_native_icon (NautilusBookmark *bookmark,
|
||||||
gboolean symbolic)
|
gboolean symbolic)
|
||||||
{
|
{
|
||||||
GUserDirectory xdg_type;
|
GUserDirectory xdg_type;
|
||||||
GIcon *icon = NULL;
|
|
||||||
|
|
||||||
if (bookmark->file == NULL)
|
if (nautilus_bookmark_get_xdg_type (bookmark, &xdg_type))
|
||||||
{
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type))
|
|
||||||
{
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xdg_type < G_USER_N_DIRECTORIES)
|
|
||||||
{
|
{
|
||||||
if (symbolic)
|
if (symbolic)
|
||||||
{
|
{
|
||||||
icon = nautilus_special_directory_get_symbolic_icon (xdg_type);
|
return nautilus_special_directory_get_symbolic_icon (xdg_type);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
icon = nautilus_special_directory_get_icon (xdg_type);
|
return nautilus_special_directory_get_icon (xdg_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
return g_themed_icon_new (symbolic ? NAUTILUS_ICON_FOLDER : NAUTILUS_ICON_FULLCOLOR_FOLDER);
|
||||||
if (icon == NULL)
|
|
||||||
{
|
|
||||||
if (symbolic)
|
|
||||||
{
|
|
||||||
icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue