[Xfce4-commits] <garcon:master> Add API and a property to get the menu item's GFile.

Nick Schermer nick at xfce.org
Sun Aug 16 18:40:05 CEST 2009


Updating branch refs/heads/master
         to 9d9b8994c5ffb0628b673a1c69ecd8af68c04062 (commit)
       from fbc06663a8c2f7e942fd064320d4f99d6648469f (commit)

commit 9d9b8994c5ffb0628b673a1c69ecd8af68c04062
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Aug 16 18:37:00 2009 +0200

    Add API and a property to get the menu item's GFile.
    
    Also drop the {set,get}_filename API since it's not really
    safe for remote files. Setting the filename had no function
    anyways.

 garcon/garcon-menu-item.c |  116 ++++++++++++++++-----------------------------
 garcon/garcon-menu-item.h |    5 +-
 2 files changed, 43 insertions(+), 78 deletions(-)

diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c
index e1f3be3..ee9d15e 100644
--- a/garcon/garcon-menu-item.c
+++ b/garcon/garcon-menu-item.c
@@ -38,8 +38,8 @@
 enum
 {
   PROP_0,
+  PROP_FILE,
   PROP_DESKTOP_ID,
-  PROP_FILENAME,
   PROP_REQUIRES_TERMINAL,
   PROP_NO_DISPLAY,
   PROP_STARTUP_NOTIFICATION,
@@ -79,12 +79,12 @@ struct _GarconMenuItemClass
 
 struct _GarconMenuItemPrivate
 {
+  /* Source file of the menu item */
+  GFile    *file;
+
   /* Desktop file id */
   gchar    *desktop_id;
 
-  /* Absolute filename */
-  gchar    *filename;
-
   /* List of categories */
   GList    *categories;
 
@@ -161,30 +161,30 @@ garcon_menu_item_class_init (GarconMenuItemClass *klass)
   gobject_class->set_property = garcon_menu_item_set_property;
 
   /**
-   * GarconMenuItem:desktop-id:
+   * GarconMenu:file:
    *
-   * The desktop-file id of this application.
+   * The #GFile from which the %GarconMenuItem was loaded. 
    **/
   g_object_class_install_property (gobject_class,
-                                   PROP_DESKTOP_ID,
-                                   g_param_spec_string ("desktop-id",
-                                                        "Desktop-File Id",
-                                                        "Desktop-File Id of the application",
-                                                        NULL,
+                                   PROP_FILE,
+                                   g_param_spec_object ("file",
+                                                        "file",
+                                                        "file",
+                                                        G_TYPE_FILE,
                                                         G_PARAM_READWRITE |
-                                                        G_PARAM_STATIC_STRINGS));
+                                                        G_PARAM_STATIC_STRINGS |
+                                                        G_PARAM_CONSTRUCT_ONLY));
 
   /**
-   * GarconMenuItem:filename:
+   * GarconMenuItem:desktop-id:
    *
-   * The (absolute) filename of the %GarconMenuItem. Whenever this changes, the
-   * complete file is reloaded. 
+   * The desktop-file id of this application.
    **/
   g_object_class_install_property (gobject_class,
-                                   PROP_FILENAME,
-                                   g_param_spec_string ("filename",
-                                                        "Filename",
-                                                        "Absolute filename",
+                                   PROP_DESKTOP_ID,
+                                   g_param_spec_string ("desktop-id",
+                                                        "Desktop-File Id",
+                                                        "Desktop-File Id of the application",
                                                         NULL,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_STATIC_STRINGS));
@@ -350,11 +350,11 @@ static void
 garcon_menu_item_init (GarconMenuItem *item)
 {
   item->priv = GARCON_MENU_ITEM_GET_PRIVATE (item);
+  item->priv->file = NULL;
   item->priv->desktop_id = NULL;
   item->priv->name = NULL;
   item->priv->generic_name = NULL;
   item->priv->comment = NULL;
-  item->priv->filename = NULL;
   item->priv->command = NULL;
   item->priv->try_exec = NULL;
   item->priv->categories = NULL;
@@ -376,7 +376,6 @@ garcon_menu_item_finalize (GObject *object)
   g_free (item->priv->name);
   g_free (item->priv->generic_name);
   g_free (item->priv->comment);
-  g_free (item->priv->filename);
   g_free (item->priv->command);
   g_free (item->priv->try_exec);
   g_free (item->priv->icon_name);
@@ -389,6 +388,9 @@ garcon_menu_item_finalize (GObject *object)
   g_list_foreach (item->priv->categories, (GFunc) g_free, NULL);
   g_list_free (item->priv->categories);
 
+  if (item->priv->file != NULL)
+    g_object_unref (G_OBJECT (item->priv->file));
+
   (*G_OBJECT_CLASS (garcon_menu_item_parent_class)->finalize) (object);
 }
 
@@ -404,12 +406,12 @@ garcon_menu_item_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_DESKTOP_ID:
-      g_value_set_string (value, garcon_menu_item_get_desktop_id (item));
+    case PROP_FILE:
+      g_value_set_object (value, garcon_menu_item_get_file (item));
       break;
 
-    case PROP_FILENAME:
-      g_value_set_string (value, garcon_menu_item_get_filename (item));
+    case PROP_DESKTOP_ID:
+      g_value_set_string (value, garcon_menu_item_get_desktop_id (item));
       break;
 
     case PROP_COMMENT:
@@ -470,12 +472,12 @@ garcon_menu_item_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_DESKTOP_ID:
-      garcon_menu_item_set_desktop_id (item, g_value_get_string (value));
+    case PROP_FILE:
+      item->priv->file = g_object_ref (g_value_get_object (value));
       break;
 
-    case PROP_FILENAME:
-      garcon_menu_item_set_filename (item, g_value_get_string (value));
+    case PROP_DESKTOP_ID:
+      garcon_menu_item_set_desktop_id (item, g_value_get_string (value));
       break;
 
     case PROP_REQUIRES_TERMINAL:
@@ -545,7 +547,6 @@ garcon_menu_item_new (GFile *file)
   gchar          *exec;
   gchar          *try_exec;
   gchar          *icon;
-  gchar          *filename;
   gchar         **mt;
   gchar         **str_list;
 
@@ -584,12 +585,9 @@ garcon_menu_item_new (GFile *file)
       startup_notify = g_key_file_get_boolean (rc, "Desktop Entry", "StartupNotify", NULL) ||
                        g_key_file_get_boolean (rc, "Desktop Entry", "X-KDE-StartupNotify", NULL);
 
-      /* Get the filename */
-      filename = g_file_get_path (file);
-
       /* Allocate a new menu item instance */
       item = g_object_new (GARCON_TYPE_MENU_ITEM, 
-                           "filename", filename,
+                           "file", file,
                            "command", exec, 
                            "try-exec", try_exec,
                            "name", name, 
@@ -602,9 +600,6 @@ garcon_menu_item_new (GFile *file)
                            "path", path,
                            NULL);
 
-      /* Cleanup */
-      g_free (filename);
-
       /* Determine the categories this application should be shown in */
       str_list = g_key_file_get_string_list (rc, "Desktop Entry", "Categories", NULL, NULL);
       if (G_LIKELY (str_list != NULL))
@@ -684,6 +679,15 @@ garcon_menu_item_new_for_uri (const gchar *uri)
 
 
 
+GFile *
+garcon_menu_item_get_file (GarconMenuItem *item)
+{
+  g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), NULL);
+  return item->priv->file;
+}
+
+
+
 const gchar *
 garcon_menu_item_get_desktop_id (GarconMenuItem *item)
 {
@@ -720,44 +724,6 @@ garcon_menu_item_set_desktop_id (GarconMenuItem *item,
 
 
 
-const gchar *
-garcon_menu_item_get_filename (GarconMenuItem *item)
-{
-  g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), NULL);
-  return item->priv->filename;
-}
-
-
-
-void
-garcon_menu_item_set_filename (GarconMenuItem *item,
-                               const gchar    *filename)
-{
-  g_return_if_fail (GARCON_IS_MENU_ITEM (item));
-  g_return_if_fail (filename != NULL);
-  g_return_if_fail (g_path_is_absolute (filename));
-
-  /* Check if there is an old filename */
-  if (G_UNLIKELY (item->priv->filename != NULL))
-    {
-      /* Abort if old and new filename are equal */
-      if (G_UNLIKELY (g_utf8_collate (item->priv->filename, filename) == 0))
-        return;
-
-      /* Otherwise free the old filename */
-      g_free (item->priv->filename);
-    }
-
-  /* Assign the new filename */
-  item->priv->filename = g_strdup (filename);
-
-  /* Notify listeners */
-  g_object_notify (G_OBJECT (item), "filename");
-}
-
-
-
-
 GList*
 garcon_menu_item_get_categories (GarconMenuItem *item)
 {
diff --git a/garcon/garcon-menu-item.h b/garcon/garcon-menu-item.h
index 5a82f92..2df197e 100644
--- a/garcon/garcon-menu-item.h
+++ b/garcon/garcon-menu-item.h
@@ -49,13 +49,12 @@ GarconMenuItem *garcon_menu_item_new                               (GFile
 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;
 
+GFile          *garcon_menu_item_get_file                          (GarconMenuItem *item);
+
 const gchar    *garcon_menu_item_get_desktop_id                    (GarconMenuItem *item);
 void            garcon_menu_item_set_desktop_id                    (GarconMenuItem *item,
                                                                     const gchar    *desktop_id);
 
-const gchar    *garcon_menu_item_get_filename                      (GarconMenuItem *item);
-void            garcon_menu_item_set_filename                      (GarconMenuItem *item,
-                                                                    const gchar    *filename);
 const gchar    *garcon_menu_item_get_command                       (GarconMenuItem *item);
 void            garcon_menu_item_set_command                       (GarconMenuItem *item,
                                                                     const gchar    *command);



More information about the Xfce4-commits mailing list