[gnome-menus] Rename gmenu_tree_get_menu_file() to gmenu_tree_get_menu_path()



commit 4f47a654d91cc3b08d46ef518a42c7f484f01be3
Author: Colin Walters <walters verbum org>
Date:   Sun Apr 17 09:57:47 2011 -0400

    Rename gmenu_tree_get_menu_file() to gmenu_tree_get_menu_path()
    
    Document it and clean it up.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=647968

 libmenu/gmenu-tree.c  |   33 +++++++++++++--------------------
 libmenu/gmenu-tree.h  |    2 +-
 util/test-menu-spec.c |    2 ++
 3 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/libmenu/gmenu-tree.c b/libmenu/gmenu-tree.c
index 0cfe6e0..bfd1e1d 100644
--- a/libmenu/gmenu-tree.c
+++ b/libmenu/gmenu-tree.c
@@ -562,29 +562,22 @@ gmenu_tree_class_init (GMenuTreeClass *klass)
 }
 
 
+/**
+ * gmenu_tree_get_menu_path:
+ * @tree: a #GMenuTree
+ *
+ * This function is only available if the tree has been loaded via
+ * gmenu_tree_load_sync() or a variant thereof.
+ * 
+ * Returns: The absolute path to the loaded menu file
+ */
 const char *
-gmenu_tree_get_menu_file (GMenuTree *tree)
+gmenu_tree_get_menu_path (GMenuTree *tree)
 {
-  /* FIXME: this is horribly ugly. But it's done to keep the API. Would be bad
-   * to break the API only for a "const char *" => "char *" change. The other
-   * alternative is to leak the memory, which is bad too. */
-  static char *ugly_result_cache = NULL;
-
-  g_return_val_if_fail (tree != NULL, NULL);
-
-  /* we need to canonicalize the path so we actually find out the real menu
-   * file that is being used -- and take into account XDG_MENU_PREFIX */
-  if (!gmenu_tree_canonicalize_path (tree, NULL))
-    return NULL;
-
-  if (ugly_result_cache != NULL)
-    {
-      g_free (ugly_result_cache);
-      ugly_result_cache = NULL;
-    }
+  g_return_val_if_fail (GMENU_IS_TREE (tree), NULL);
+  g_return_val_if_fail (tree->loaded, NULL);
 
-  ugly_result_cache = g_path_get_basename (tree->canonical_path);
-  return ugly_result_cache;
+  return tree->canonical_path;
 }
 
 /**
diff --git a/libmenu/gmenu-tree.h b/libmenu/gmenu-tree.h
index 19e4784..51a75de 100644
--- a/libmenu/gmenu-tree.h
+++ b/libmenu/gmenu-tree.h
@@ -94,7 +94,7 @@ GMenuTree *gmenu_tree_new (const char     *menu_file,
 gboolean   gmenu_tree_load_sync (GMenuTree   *tree,
 				 GError     **error);
 
-const char         *gmenu_tree_get_menu_file           (GMenuTree  *tree);
+const char         *gmenu_tree_get_menu_path           (GMenuTree  *tree);
 GMenuTreeDirectory *gmenu_tree_get_root_directory      (GMenuTree  *tree);
 GMenuTreeDirectory *gmenu_tree_get_directory_from_path (GMenuTree  *tree,
 							const char *path);
diff --git a/util/test-menu-spec.c b/util/test-menu-spec.c
index 9748a13..cb0d032 100644
--- a/util/test-menu-spec.c
+++ b/util/test-menu-spec.c
@@ -227,6 +227,8 @@ main (int argc, char **argv)
       exit (1);
     }
 
+  g_print ("Loaded menu from %s\n", gmenu_tree_get_menu_path (tree));
+
   root = gmenu_tree_get_root_directory (tree);
   if (root != NULL)
     {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]