[Xfce4-commits] <garcon:master> Fix garcon_config_lookup.
Nick Schermer
nick at xfce.org
Sun Aug 16 21:00:01 CEST 2009
Updating branch refs/heads/master
to ef110722a651a7ede4d2739eeb6716459b7b85f2 (commit)
from 461f62df39bd4009b0cc4dfd5ca5623f8be6ada9 (commit)
commit ef110722a651a7ede4d2739eeb6716459b7b85f2
Author: Nick Schermer <nick at xfce.org>
Date: Sun Aug 16 20:50:35 2009 +0200
Fix garcon_config_lookup.
Make the funtion easier to read and test for regular files
in the user's directory too.
garcon/garcon-menu-item-cache.h | 2 +-
garcon/garcon.c | 40 +++++++++++++++++---------------------
2 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/garcon/garcon-menu-item-cache.h b/garcon/garcon-menu-item-cache.h
index 49bbd0e..a6198dc 100644
--- a/garcon/garcon-menu-item-cache.h
+++ b/garcon/garcon-menu-item-cache.h
@@ -46,7 +46,7 @@ GType garcon_menu_item_cache_get_type (void) G_GNUC_CONST;
GarconMenuItemCache *garcon_menu_item_cache_get_default (void);
GarconMenuItem *garcon_menu_item_cache_lookup (GarconMenuItemCache *cache,
- const gchar *filename,
+ const gchar *uri,
const gchar *desktop_id);
void garcon_menu_item_cache_foreach (GarconMenuItemCache *cache,
GHFunc func,
diff --git a/garcon/garcon.c b/garcon/garcon.c
index af39027..1ac73a4 100644
--- a/garcon/garcon.c
+++ b/garcon/garcon.c
@@ -114,33 +114,29 @@ garcon_config_lookup (const gchar *filename)
{
const gchar * const *dirs;
gchar *path;
- gint i;
+ guint i;
- g_return_val_if_fail (filename != NULL && g_utf8_strlen (filename, -1) > 0, NULL);
+ g_return_val_if_fail (filename != NULL && *filename != '\0', NULL);
- path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_config_dir (), filename, NULL);
+ /* Look for the file in the user's config directory */
+ path = g_build_filename (g_get_user_config_dir (), filename, NULL);
+ if (g_path_is_absolute (path)
+ && g_file_test (path, G_FILE_TEST_IS_REGULAR))
+ return path;
+ g_free (path);
- if (!g_file_test (path, G_FILE_TEST_EXISTS))
+ /* Look for the file in the system config directories */
+ dirs = g_get_system_config_dirs ();
+ for (i = 0; dirs[i] != NULL; ++i)
{
+ /* Build the filename, if the file exists return the path */
+ path = g_build_filename (dirs[i], filename, NULL);
+ if (g_path_is_absolute (path)
+ && g_file_test (path, G_FILE_TEST_IS_REGULAR))
+ return path;
g_free (path);
- path = NULL;
-
- dirs = g_get_system_config_dirs ();
-
- for (i = 0; path == NULL && dirs[i] != NULL; ++i)
- {
- if (g_path_is_absolute (dirs[i]))
- {
- path = g_build_path (G_DIR_SEPARATOR_S, dirs[i], filename, NULL);
-
- if (!g_file_test (path, G_FILE_TEST_IS_REGULAR))
- {
- g_free (path);
- path = NULL;
- }
- }
- }
}
- return path;
+ /* Nothing found */
+ return NULL;
}
More information about the Xfce4-commits
mailing list