[Xfce4-commits] <garcon:master> Reload Categories/OnlyShowIn/NotShowIn. Add garcon_menu_element_equal().

Jannis Pohlmann noreply at xfce.org
Sun Sep 5 21:42:02 CEST 2010


Updating branch refs/heads/master
         to 2d35906e4287a17a35386d1fe01799348e3e6c22 (commit)
       from 7d42e955c11060646e17d3e1f67a601ba3d6a503 (commit)

commit 2d35906e4287a17a35386d1fe01799348e3e6c22
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sun Sep 5 15:01:23 2010 +0200

    Reload Categories/OnlyShowIn/NotShowIn. Add garcon_menu_element_equal().

 garcon/garcon-menu-element.c   |   15 ++++++++++
 garcon/garcon-menu-element.h   |    4 +++
 garcon/garcon-menu-item.c      |   56 +++++++++++++++++++++++++++++++++++++---
 garcon/garcon-menu-separator.c |   13 +++++++++
 garcon/garcon-menu.c           |   17 +++++++++++-
 5 files changed, 100 insertions(+), 5 deletions(-)

diff --git a/garcon/garcon-menu-element.c b/garcon/garcon-menu-element.c
index 5978120..5f6a5d6 100644
--- a/garcon/garcon-menu-element.c
+++ b/garcon/garcon-menu-element.c
@@ -116,3 +116,18 @@ garcon_menu_element_get_no_display (GarconMenuElement *element)
   return (*GARCON_MENU_ELEMENT_GET_IFACE (element)->get_no_display) (element);
 }
 
+
+
+gboolean
+garcon_menu_element_equal (GarconMenuElement *a,
+                           GarconMenuElement *b)
+{
+  g_return_val_if_fail (GARCON_IS_MENU_ELEMENT (a), FALSE);
+  g_return_val_if_fail (GARCON_IS_MENU_ELEMENT (b), FALSE);
+
+  if (G_TYPE_FROM_INSTANCE (a) != G_TYPE_FROM_INSTANCE (b))
+    return FALSE;
+
+  return (*GARCON_MENU_ELEMENT_GET_IFACE (a)->equal) (a, b);
+}
+
diff --git a/garcon/garcon-menu-element.h b/garcon/garcon-menu-element.h
index 8aacdd8..4c30547 100644
--- a/garcon/garcon-menu-element.h
+++ b/garcon/garcon-menu-element.h
@@ -48,6 +48,8 @@ struct _GarconMenuElementIface
   gboolean     (*get_visible)             (GarconMenuElement *element);
   gboolean     (*get_show_in_environment) (GarconMenuElement *element);
   gboolean     (*get_no_display)          (GarconMenuElement *element);
+  gboolean     (*equal)                   (GarconMenuElement *element,
+                                           GarconMenuElement *other);
 };
 
 GType        garcon_menu_element_get_type                (void) G_GNUC_CONST;
@@ -58,6 +60,8 @@ const gchar *garcon_menu_element_get_icon_name           (GarconMenuElement *ele
 gboolean     garcon_menu_element_get_visible             (GarconMenuElement *element);
 gboolean     garcon_menu_element_get_show_in_environment (GarconMenuElement *element);
 gboolean     garcon_menu_element_get_no_display          (GarconMenuElement *element);
+gboolean     garcon_menu_element_equal                   (GarconMenuElement *a,
+                                                          GarconMenuElement *b);
 
 G_END_DECLS
 
diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c
index 461ed02..f490f16 100644
--- a/garcon/garcon-menu-item.c
+++ b/garcon/garcon-menu-item.c
@@ -85,6 +85,8 @@ static const gchar *garcon_menu_item_get_element_icon_name           (GarconMenu
 static gboolean     garcon_menu_item_get_element_visible             (GarconMenuElement      *element);
 static gboolean     garcon_menu_item_get_element_show_in_environment (GarconMenuElement      *element);
 static gboolean     garcon_menu_item_get_element_no_display          (GarconMenuElement      *element);
+static gboolean     garcon_menu_item_get_element_equal               (GarconMenuElement      *element,
+                                                                      GarconMenuElement      *other);
 
 
 
@@ -384,6 +386,7 @@ garcon_menu_item_element_init (GarconMenuElementIface *iface)
   iface->get_visible = garcon_menu_item_get_element_visible;
   iface->get_show_in_environment = garcon_menu_item_get_element_show_in_environment;
   iface->get_no_display = garcon_menu_item_get_element_no_display;
+  iface->equal = garcon_menu_item_get_element_equal;
 }
 
 
@@ -622,6 +625,21 @@ garcon_menu_item_get_element_no_display (GarconMenuElement *element)
   return garcon_menu_item_get_no_display (GARCON_MENU_ITEM (element));
 }
 
+
+
+static gboolean
+garcon_menu_item_get_element_equal (GarconMenuElement *element,
+                                    GarconMenuElement *other)
+{
+  g_return_val_if_fail (GARCON_IS_MENU_ITEM (element), FALSE);
+  g_return_val_if_fail (GARCON_IS_MENU_ITEM (other), FALSE);
+
+  return g_file_equal (GARCON_MENU_ITEM (element)->priv->file, 
+                       GARCON_MENU_ITEM (other)->priv->file);
+}
+
+
+
 static const gchar*
 garcon_menu_item_get_element_name (GarconMenuElement *element)
 {
@@ -816,12 +834,16 @@ garcon_menu_item_reload_from_file (GarconMenuItem  *item,
                                    GError         **error)
 {
   GKeyFile *rc;
-  gchar    *contents;
-  gsize     length = 0;
+  gboolean  boolean;
   gboolean  succeed;
+  GList    *categories = NULL;
+  gchar   **mt;
+  gchar   **str_list;
+  gchar    *contents;
   gchar    *string;
-  gboolean  boolean;
-  gchar    *name, *exec;
+  gchar    *name;
+  gchar    *exec;
+  gsize     length = 0;
 
   g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), FALSE);
   g_return_val_if_fail (G_IS_FILE (file), FALSE);
@@ -912,6 +934,32 @@ garcon_menu_item_reload_from_file (GarconMenuItem  *item,
   boolean = GET_KEY (boolean, G_KEY_FILE_DESKTOP_KEY_HIDDEN);
   garcon_menu_item_set_hidden (item, boolean);
 
+  /* Determine the categories this application should be shown in */
+  str_list = GET_STRING_LIST (G_KEY_FILE_DESKTOP_KEY_CATEGORIES);
+  if (G_LIKELY (str_list != NULL))
+    {
+      for (mt = str_list; *mt != NULL; ++mt)
+        {
+          if (**mt != '\0')
+            categories = g_list_prepend (categories, g_strdup (*mt));
+        }
+
+      /* Free list */
+      g_strfreev (str_list);
+
+      /* Assign categories list to the menu item */
+      garcon_menu_item_set_categories (item, categories);
+    }
+  else
+    {
+      /* Assign empty categories list to the menu item */
+      garcon_menu_item_set_categories (item, NULL);
+    }
+
+  /* Set the rest of the private data directly */
+  item->priv->only_show_in = GET_STRING_LIST (G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN);
+  item->priv->not_show_in = GET_STRING_LIST (G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN);
+
   /* Flush property notifications */
   g_object_thaw_notify (G_OBJECT (item));
 
diff --git a/garcon/garcon-menu-separator.c b/garcon/garcon-menu-separator.c
index fcfe900..e7e22e5 100644
--- a/garcon/garcon-menu-separator.c
+++ b/garcon/garcon-menu-separator.c
@@ -36,6 +36,8 @@ static const gchar *garcon_menu_separator_get_element_icon_name           (Garco
 static gboolean     garcon_menu_separator_get_element_visible             (GarconMenuElement        *element);
 static gboolean     garcon_menu_separator_get_element_show_in_environment (GarconMenuElement        *element);
 static gboolean     garcon_menu_separator_get_element_no_display          (GarconMenuElement        *element);
+static gboolean     garcon_menu_separator_get_element_equal               (GarconMenuElement        *element,
+                                                                           GarconMenuElement        *other);
 
 
 
@@ -64,6 +66,7 @@ garcon_menu_separator_element_init (GarconMenuElementIface *iface)
   iface->get_visible = garcon_menu_separator_get_element_visible;
   iface->get_show_in_environment = garcon_menu_separator_get_element_show_in_environment;
   iface->get_no_display = garcon_menu_separator_get_element_no_display;
+  iface->equal = garcon_menu_separator_get_element_equal;
 }
 
 
@@ -158,3 +161,13 @@ garcon_menu_separator_get_element_no_display (GarconMenuElement *element)
 {
   return FALSE;
 }
+
+
+
+static gboolean
+garcon_menu_separator_get_element_equal (GarconMenuElement *element,
+                                         GarconMenuElement *other)
+{
+  /* FIXME this is inherently broken as the separator is a singleton class */
+  return FALSE;
+}
diff --git a/garcon/garcon-menu.c b/garcon/garcon-menu.c
index 6634a33..879c3ef 100644
--- a/garcon/garcon-menu.c
+++ b/garcon/garcon-menu.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2007-2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2007-2010 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -137,6 +137,8 @@ static const gchar         *garcon_menu_get_element_icon_name           (GarconM
 static gboolean             garcon_menu_get_element_visible             (GarconMenuElement       *element);
 static gboolean             garcon_menu_get_element_show_in_environment (GarconMenuElement       *element);
 static gboolean             garcon_menu_get_element_no_display          (GarconMenuElement       *element);
+static gboolean             garcon_menu_get_element_equal               (GarconMenuElement       *element,
+                                                                         GarconMenuElement       *other);
 
 
 
@@ -224,6 +226,7 @@ garcon_menu_element_init (GarconMenuElementIface *iface)
   iface->get_visible = garcon_menu_get_element_visible;
   iface->get_show_in_environment = garcon_menu_get_element_show_in_environment;
   iface->get_no_display = garcon_menu_get_element_no_display;
+  iface->equal = garcon_menu_get_element_equal;
 }
 
 
@@ -1552,3 +1555,15 @@ garcon_menu_get_element_no_display (GarconMenuElement *element)
   else
     return garcon_menu_directory_get_no_display (menu->priv->directory);
 }
+
+
+
+static gboolean
+garcon_menu_get_element_equal (GarconMenuElement *element,
+                               GarconMenuElement *other)
+{
+  g_return_val_if_fail (GARCON_IS_MENU (element), FALSE);
+  g_return_val_if_fail (GARCON_IS_MENU (other), FALSE);
+
+  return GARCON_MENU (element) == GARCON_MENU (other);
+}



More information about the Xfce4-commits mailing list