[Xfce4-commits] <garcon:master> Add reload functions to GarconMenuItem.

Nick Schermer nick at xfce.org
Sat Aug 29 19:02:05 CEST 2009


Updating branch refs/heads/master
         to 9ff22e379d31bac748a04a9b896a9b1e93b57a01 (commit)
       from 9d1777980c832796696b0d21ca7e34b13723f44e (commit)

commit 9ff22e379d31bac748a04a9b896a9b1e93b57a01
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Aug 29 18:06:05 2009 +0200

    Add reload functions to GarconMenuItem.
    
    Not entirly finished because we need a global changed
    signal for the menu item too, but it's a start.

 garcon/garcon-menu-item.c |  100 +++++++++++++++++++++++++++++++++++++++++++++
 garcon/garcon-menu-item.h |    7 +++
 2 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c
index a4ad9fa..5440a1a 100644
--- a/garcon/garcon-menu-item.c
+++ b/garcon/garcon-menu-item.c
@@ -32,6 +32,8 @@
 
 
 #define GARCON_MENU_ITEM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GARCON_TYPE_MENU_ITEM, GarconMenuItemPrivate))
+#define GET_LOCALE_KEY(type, key) g_key_file_get_locale_##type (rc, G_KEY_FILE_DESKTOP_GROUP, key, NULL, NULL)
+#define GET_KEY(type, key) g_key_file_get_##type (rc, G_KEY_FILE_DESKTOP_GROUP, key, NULL)
 
 
 
@@ -687,6 +689,104 @@ garcon_menu_item_new_for_uri (const gchar *uri)
 
 
 
+gboolean
+garcon_menu_item_reload (GarconMenuItem  *item,
+                         GError         **error)
+{
+  g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  return garcon_menu_item_reload_from_file (item, item->priv->file, error);
+}
+
+
+
+gboolean
+garcon_menu_item_reload_from_file (GarconMenuItem  *item,
+                                   GFile           *file,
+                                   GError         **error)
+{
+  GKeyFile       *rc;
+  gchar          *contents;
+  gsize           length = 0;
+  gboolean        succeed;
+  gchar          *string;
+  gboolean        boolean;
+
+  g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), FALSE);
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  /* Load the contents of the file */
+  if (!g_file_load_contents (file, NULL, &contents, &length, NULL, error))
+    return FALSE;
+
+  /* Leave when the file is empty */
+  if (G_UNLIKELY (length == 0))
+    {
+      g_set_error_literal (error, 0, 0, "The desktop file if empty.");
+      return FALSE;
+    }
+
+  /* Open the keyfile */
+  rc = g_key_file_new ();
+  succeed = g_key_file_load_from_data (rc, contents, length, G_KEY_FILE_NONE, error);
+  g_free (contents);
+  if (G_UNLIKELY (!succeed))
+    return FALSE;
+
+  /* Queue property notifications */
+  g_object_freeze_notify (G_OBJECT (item));
+
+  /* Update properties */
+  string = GET_LOCALE_KEY (string, G_KEY_FILE_DESKTOP_KEY_NAME);
+  garcon_menu_item_set_name (item, string);
+  g_free (string);
+
+  string = GET_KEY (string, G_KEY_FILE_DESKTOP_KEY_EXEC);
+  garcon_menu_item_set_command (item, string);
+  g_free (string);
+
+  string = GET_LOCALE_KEY (string, G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME);
+  garcon_menu_item_set_generic_name (item, string);
+  g_free (string);
+
+  string = GET_LOCALE_KEY (string, G_KEY_FILE_DESKTOP_KEY_COMMENT);
+  garcon_menu_item_set_comment (item, string);
+  g_free (string);
+
+  string = GET_KEY (string, G_KEY_FILE_DESKTOP_KEY_TRY_EXEC);
+  garcon_menu_item_set_try_exec (item, string);
+  g_free (string);
+
+  string = GET_KEY (string, G_KEY_FILE_DESKTOP_KEY_ICON);
+  garcon_menu_item_set_icon_name (item, string);
+  g_free (string);
+
+  string = GET_KEY (string, G_KEY_FILE_DESKTOP_KEY_PATH);
+  garcon_menu_item_set_path (item, string);
+  g_free (string);
+
+  boolean = GET_KEY (boolean, G_KEY_FILE_DESKTOP_KEY_TERMINAL);
+  garcon_menu_item_set_requires_terminal (item, boolean);
+
+  boolean = GET_KEY (boolean, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY);
+  garcon_menu_item_set_no_display (item, boolean);
+
+  boolean = GET_KEY (boolean, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY)
+            || GET_KEY (boolean, "X-KDE-StartupNotify");
+  garcon_menu_item_set_supports_startup_notification (item, boolean);
+
+  /* Flush property notifications */
+  g_object_thaw_notify (G_OBJECT (item));
+
+  g_key_file_free (rc);
+
+  return TRUE;
+}
+
+
+
 /**
  * garcon_menu_item_get_file:
  *
diff --git a/garcon/garcon-menu-item.h b/garcon/garcon-menu-item.h
index 7dec619..d305e63 100644
--- a/garcon/garcon-menu-item.h
+++ b/garcon/garcon-menu-item.h
@@ -49,6 +49,13 @@ 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;
 
+gboolean        garcon_menu_item_reload                            (GarconMenuItem *item,
+                                                                    GError        **error);
+
+gboolean        garcon_menu_item_reload_from_file                  (GarconMenuItem *item,
+                                                                    GFile          *file,
+                                                                    GError        **error);
+
 GFile          *garcon_menu_item_get_file                          (GarconMenuItem *item);
 
 gchar          *garcon_menu_item_get_uri                           (GarconMenuItem *item) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;



More information about the Xfce4-commits mailing list