From a011010567d006966b143b6e91bef8f23bf9c0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Wed, 22 May 2024 12:34:46 +0100 Subject: [PATCH] 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 1dcd2d816a1278f7eec1d074ec5d9134af34a803 --- src/nautilus-bookmark.c | 65 ++++++++++------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/src/nautilus-bookmark.c b/src/nautilus-bookmark.c index 4d2fd325d..fb71f0f3f 100644 --- a/src/nautilus-bookmark.c +++ b/src/nautilus-bookmark.c @@ -190,37 +190,28 @@ gboolean nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark, GUserDirectory *directory) { - gboolean match; - GFile *location; - const gchar *path; - GUserDirectory dir; - - match = FALSE; - - for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++) + for (GUserDirectory dir = 0; dir < G_USER_N_DIRECTORIES; dir++) { - path = g_get_user_special_dir (dir); - if (!path) + const gchar *path = g_get_user_special_dir (dir); + + if (path == NULL) { continue; } - location = g_file_new_for_path (path); - match = g_file_equal (location, bookmark->location); - g_object_unref (location); + g_autoptr (GFile) location = g_file_new_for_path (path); - if (match) + if (g_file_equal (location, bookmark->location)) { - break; + if (directory != NULL) + { + *directory = dir; + } + return TRUE; } } - if (match && directory != NULL) - { - *directory = dir; - } - - return match; + return FALSE; } static GIcon * @@ -228,44 +219,20 @@ get_native_icon (NautilusBookmark *bookmark, gboolean symbolic) { GUserDirectory xdg_type; - GIcon *icon = NULL; - if (bookmark->file == NULL) - { - goto out; - } - - if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type)) - { - goto out; - } - - if (xdg_type < G_USER_N_DIRECTORIES) + if (nautilus_bookmark_get_xdg_type (bookmark, &xdg_type)) { if (symbolic) { - icon = nautilus_special_directory_get_symbolic_icon (xdg_type); + return nautilus_special_directory_get_symbolic_icon (xdg_type); } else { - icon = nautilus_special_directory_get_icon (xdg_type); + return nautilus_special_directory_get_icon (xdg_type); } } -out: - 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; + return g_themed_icon_new (symbolic ? NAUTILUS_ICON_FOLDER : NAUTILUS_ICON_FULLCOLOR_FOLDER); } static void