[Xfce4-commits] <garcon:master> Use GFile in garcon_menu_item_new and add convenient functions.

Nick Schermer nick at xfce.org
Sun Aug 16 18:06:12 CEST 2009


Updating branch refs/heads/master
         to ce9762d78694cc3636d3fe934f8d5ccf5f17a8cc (commit)
       from 44be78065c4bdec5540dcd05eeff13d651a73990 (commit)

commit ce9762d78694cc3636d3fe934f8d5ccf5f17a8cc
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Aug 16 17:56:15 2009 +0200

    Use GFile in garcon_menu_item_new and add convenient functions.
    
    We use GIO for file loading internally. The two convenient
    functions allow creating a GarconMenuItem from a filename or uri.

 garcon/garcon-menu-item-cache.c |    2 +-
 garcon/garcon-menu-item.c       |   40 +++++++++++++++++++++++++++++++++++---
 garcon/garcon-menu-item.h       |    5 +++-
 3 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/garcon/garcon-menu-item-cache.c b/garcon/garcon-menu-item-cache.c
index e232b35..c8d4d24 100644
--- a/garcon/garcon-menu-item-cache.c
+++ b/garcon/garcon-menu-item-cache.c
@@ -194,7 +194,7 @@ garcon_menu_item_cache_lookup (GarconMenuItemCache *cache,
     }
 
   /* Last chance is to load it directly from the file */
-  item = garcon_menu_item_new (uri);
+  item = garcon_menu_item_new_for_uri (uri);
 
   if (G_LIKELY (item != NULL))
     {
diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c
index 34fc472..e1f3be3 100644
--- a/garcon/garcon-menu-item.c
+++ b/garcon/garcon-menu-item.c
@@ -527,14 +527,13 @@ garcon_menu_item_set_property (GObject      *object,
 
 
 GarconMenuItem *
-garcon_menu_item_new (const gchar *uri)
+garcon_menu_item_new (GFile *file)
 {
   GarconMenuItem *item = NULL;
   GKeyFile       *rc = NULL;
   gchar          *contents;
   gsize           length;
   gboolean        succeed;
-  GFile          *file;
   GList          *categories = NULL;
   gboolean        terminal;
   gboolean        no_display;
@@ -550,10 +549,9 @@ garcon_menu_item_new (const gchar *uri)
   gchar         **mt;
   gchar         **str_list;
 
-  g_return_val_if_fail (uri != NULL, NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
 
   /* Load the contents of the file */
-  file = g_file_new_for_uri (uri);
   if (!g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
     goto error;
 
@@ -652,6 +650,40 @@ error:
 
 
 
+GarconMenuItem *
+garcon_menu_item_new_for_path (const gchar *filename)
+{
+  GFile          *file;
+  GarconMenuItem *item;
+
+  g_return_val_if_fail (filename != NULL, NULL);
+
+  file = g_file_new_for_path (filename);
+  item = garcon_menu_item_new (file);
+  g_object_unref (G_OBJECT (file));
+
+  return item;
+}
+
+
+
+GarconMenuItem *
+garcon_menu_item_new_for_uri (const gchar *uri)
+{
+  GFile          *file;
+  GarconMenuItem *item;
+
+  g_return_val_if_fail (uri != NULL, NULL);
+
+  file = g_file_new_for_uri (uri);
+  item = garcon_menu_item_new (file);
+  g_object_unref (G_OBJECT (file));
+
+  return item;
+}
+
+
+
 const gchar *
 garcon_menu_item_get_desktop_id (GarconMenuItem *item)
 {
diff --git a/garcon/garcon-menu-item.h b/garcon/garcon-menu-item.h
index 779864b..5a82f92 100644
--- a/garcon/garcon-menu-item.h
+++ b/garcon/garcon-menu-item.h
@@ -28,6 +28,7 @@
 #define __GARCON_MENU_ITEM_H__
 
 #include <glib-object.h>
+#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
@@ -44,7 +45,9 @@ typedef struct _GarconMenuItem        GarconMenuItem;
 
 GType           garcon_menu_item_get_type                          (void) G_GNUC_CONST;
 
-GarconMenuItem *garcon_menu_item_new                               (const gchar  *filename) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+GarconMenuItem *garcon_menu_item_new                               (GFile          *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+GarconMenuItem *garcon_menu_item_new_for_path                      (const gchar    *filename) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+GarconMenuItem *garcon_menu_item_new_for_uri                       (const gchar    *uri) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 
 const gchar    *garcon_menu_item_get_desktop_id                    (GarconMenuItem *item);
 void            garcon_menu_item_set_desktop_id                    (GarconMenuItem *item,



More information about the Xfce4-commits mailing list