Author: jannis
Date: 2007-12-22 23:38:52 +0000 (Sat, 22 Dec 2007)
New Revision: 26500

Modified:
   libxfce4menu/trunk/ChangeLog
   libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.c
   libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.h
   libxfce4menu/trunk/libxfce4menu/xfce-menu-item.c
   libxfce4menu/trunk/libxfce4menu/xfce-menu-item.h
   libxfce4menu/trunk/libxfce4menu/xfce-menu.c
Log:
        * libxfce4menu/xfce-menu-item.{c,h}: Add support for "GenericName" as
          requested by Brian. Also add a convenience function 
                xfce_menu_item_has_category (XfceMenuItem *, const char *).
        * libxfce4menu/xfce-menu-item-cache.c: Re-add caching features, but now
          also allow the cache to be invalidated using _item_cache_invalidate().
                This can be used in combination with file monitoring: Once 
something
                has changed a) destroy the current menu, b) invalidate the 
cache and
                c) create the menu again.

Modified: libxfce4menu/trunk/ChangeLog
===================================================================
--- libxfce4menu/trunk/ChangeLog        2007-12-21 13:31:41 UTC (rev 26499)
+++ libxfce4menu/trunk/ChangeLog        2007-12-22 23:38:52 UTC (rev 26500)
@@ -1,3 +1,14 @@
+2007-12-23     Jannis Pohlmann <[EMAIL PROTECTED]>
+
+       * libxfce4menu/xfce-menu-item.{c,h}: Add support for "GenericName" as
+         requested by Brian. Also add a convenience function 
+               xfce_menu_item_has_category (XfceMenuItem *, const char *).
+       * libxfce4menu/xfce-menu-item-cache.c: Re-add caching features, but now
+         also allow the cache to be invalidated using _item_cache_invalidate().
+               This can be used in combination with file monitoring: Once 
something
+               has changed a) destroy the current menu, b) invalidate the 
cache and
+               c) create the menu again.
+
 2007-10-21     Jannis Pohlmann <[EMAIL PROTECTED]>
 
        * libxfce4menu/xfce-menu-item.{c,h}: Add support for the "Path" 

Modified: libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.c
===================================================================
--- libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.c      2007-12-21 
13:31:41 UTC (rev 26499)
+++ libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.c      2007-12-22 
23:38:52 UTC (rev 26500)
@@ -61,7 +61,7 @@
 static void          xfce_menu_item_cache_class_init (XfceMenuItemCacheClass 
*klass);
 static void          xfce_menu_item_cache_init       (XfceMenuItemCache      
*cache);
 static void          xfce_menu_item_cache_finalize   (GObject                
*object);
-#if 0 /* ITEM CACHE DEACTIVATED FOR NOW */
+#if 1 /* ITEM CACHE DEACTIVATED FOR NOW */
 static XfceMenuItem *xfce_menu_item_cache_fetch_item (XfceMenuItemCache      
*cache,
                                                       const gchar            
*filename);
 static void          xfce_menu_item_cache_store_item (XfceMenuItemCache      
*cache,
@@ -257,7 +257,7 @@
    * item cache */
   g_mutex_lock (cache->priv->lock);
 
-#if 0
+#if 1
   /* Search filename in the hash table */
   item = g_hash_table_lookup (cache->priv->items, filename);
 
@@ -299,7 +299,7 @@
 
           /* Grab a reference on the item, but don't increase the allocation
            * counter */
-#if 0
+#if 1
           g_object_ref (G_OBJECT (item));
 #endif
 
@@ -319,7 +319,7 @@
       /* Update desktop id */
       xfce_menu_item_set_desktop_id (item, desktop_id);
 
-#if 0 /* ITEM CACHE DEACTIVATED FOR NOW */
+#if 1 /* ITEM CACHE DEACTIVATED FOR NOW */
       /* Store updated item in cache */
       xfce_menu_item_cache_store_item (cache, filename, item);
 
@@ -328,7 +328,7 @@
 #endif
 
       /* Grab a reference on it but don't increase the allocation counter */
-#if 0
+#if 1
       g_object_ref (G_OBJECT (item)); 
 #endif
     }
@@ -359,7 +359,7 @@
 
 
 
-#if 0 /* ITEM CACHE DEACTIVATED FOR NOW */
+#if 1 /* ITEM CACHE DEACTIVATED FOR NOW */
 static XfceMenuItem*
 xfce_menu_item_cache_fetch_item (XfceMenuItemCache *cache,
                                  const gchar       *filename)
@@ -422,3 +422,21 @@
    */
 }
 #endif
+
+
+
+void
+xfce_menu_item_cache_invalidate (XfceMenuItemCache *cache)
+{
+  g_return_if_fail (XFCE_IS_MENU_ITEM_CACHE (cache));
+
+  /* Destroy the hash table */
+#if GLIB_CHECK_VERSION(2,10,0)
+  g_hash_table_unref (cache->priv->items);
+#else
+  g_hash_table_destroy (cache->priv->items);
+#endif
+  
+  /* Create a new, empty hash table */
+  cache->priv->items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, 
(GDestroyNotify) xfce_menu_item_unref);
+}

Modified: libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.h
===================================================================
--- libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.h      2007-12-21 
13:31:41 UTC (rev 26499)
+++ libxfce4menu/trunk/libxfce4menu/xfce-menu-item-cache.h      2007-12-22 
23:38:52 UTC (rev 26500)
@@ -51,6 +51,7 @@
 void               xfce_menu_item_cache_foreach     (XfceMenuItemCache *cache,
                                                      GHFunc             func, 
                                                      gpointer           
user_data);
+void               xfce_menu_item_cache_invalidate  (XfceMenuItemCache *cache);
 
 #if defined(LIBXFCE4MENU_COMPILATION)
 void               _xfce_menu_item_cache_init       (void) G_GNUC_INTERNAL;

Modified: libxfce4menu/trunk/libxfce4menu/xfce-menu-item.c
===================================================================
--- libxfce4menu/trunk/libxfce4menu/xfce-menu-item.c    2007-12-21 13:31:41 UTC 
(rev 26499)
+++ libxfce4menu/trunk/libxfce4menu/xfce-menu-item.c    2007-12-22 23:38:52 UTC 
(rev 26500)
@@ -46,6 +46,7 @@
   PROP_NO_DISPLAY,
   PROP_STARTUP_NOTIFICATION,
   PROP_NAME,
+  PROP_GENERIC_NAME,
   PROP_ICON_NAME,
   PROP_COMMAND,
   PROP_TRY_EXEC,
@@ -99,6 +100,9 @@
   /* Name to be displayed for the menu item */
   gchar    *name;
 
+  /* Generic name of the menu item */
+  gchar    *generic_name;
+
   /* Command to be executed when the menu item is clicked */
   gchar    *command;
 
@@ -269,6 +273,19 @@
                                                         G_PARAM_READWRITE));
 
   /**
+   * XfceMenuItem:generic-name:
+   *
+   * GenericName of the application (will be displayed in menus etc.).
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_GENERIC_NAME,
+                                   g_param_spec_string ("generic-name",
+                                                        "Generic name",
+                                                        "Generic name of the 
application",
+                                                        NULL,
+                                                        G_PARAM_READWRITE));
+
+  /**
    * XfceMenuItem:command:
    *
    * Command to be executed when the menu item is clicked.
@@ -338,6 +355,7 @@
   item->priv = XFCE_MENU_ITEM_GET_PRIVATE (item);
   item->priv->desktop_id = NULL;
   item->priv->name = NULL;
+  item->priv->generic_name = NULL;
   item->priv->filename = NULL;
   item->priv->command = NULL;
   item->priv->try_exec = NULL;
@@ -358,6 +376,7 @@
 
   g_free (item->priv->desktop_id);
   g_free (item->priv->name);
+  g_free (item->priv->generic_name);
   g_free (item->priv->filename);
   g_free (item->priv->command);
   g_free (item->priv->try_exec);
@@ -398,6 +417,7 @@
     case PROP_NO_DISPLAY:
     case PROP_STARTUP_NOTIFICATION:
     case PROP_NAME:
+    case PROP_GENERIC_NAME:
     case PROP_COMMAND:
     case PROP_ICON_NAME:
     case PROP_TRY_EXEC:
@@ -449,6 +469,10 @@
       xfce_menu_item_set_name (item, g_value_get_string (value));
       break;
 
+    case PROP_GENERIC_NAME:
+      xfce_menu_item_set_generic_name (item, g_value_get_string (value));
+      break;
+
     case PROP_COMMAND:
       xfce_menu_item_set_command (item, g_value_get_string (value));
       break;
@@ -480,6 +504,7 @@
   XfceRc       *rc;
   const gchar  *path;
   const gchar  *name;
+  const gchar  *generic_name;
   const gchar  *exec;
   const gchar  *try_exec;
   const gchar  *icon;
@@ -511,6 +536,7 @@
 
   /* Parse name, exec command and icon name */
   name = xfce_rc_read_entry (rc, "Name", NULL);
+  generic_name = xfce_rc_read_entry (rc, "GenericName", NULL);
   exec = xfce_rc_read_entry (rc, "Exec", NULL);
   try_exec = xfce_rc_read_entry (rc, "TryExec", NULL);
   icon = xfce_rc_read_entry (rc, "Icon", NULL);
@@ -530,6 +556,7 @@
                            "command", exec, 
                            "try-exec", try_exec,
                            "name", name, 
+                           "generic-name", generic_name,
                            "icon-name", icon, 
                            "requires-terminal", terminal, 
                            "no-display", no_display, 
@@ -776,6 +803,40 @@
 
 
 const gchar*
+xfce_menu_item_get_generic_name (XfceMenuItem *item)
+{
+  g_return_val_if_fail (XFCE_IS_MENU_ITEM (item), NULL);
+  return item->priv->generic_name;
+}
+
+
+
+void
+xfce_menu_item_set_generic_name (XfceMenuItem *item,
+                                 const gchar  *generic_name)
+{
+  g_return_if_fail (XFCE_IS_MENU_ITEM (item));
+
+  if (G_UNLIKELY (item->priv->generic_name != NULL))
+    {
+      /* Abort if old and new generic name are equal */
+      if (G_UNLIKELY (g_utf8_collate (item->priv->generic_name, generic_name) 
== 0))
+        return;
+
+      /* Otherwise free old generic name */
+      g_free (item->priv->generic_name);
+    }
+
+  /* Assign new generic_name */
+  item->priv->generic_name = g_strdup (generic_name);
+
+  /* Notify listeners */
+  g_object_notify (G_OBJECT (item), "generic-name");
+}
+
+
+
+const gchar*
 xfce_menu_item_get_icon_name (XfceMenuItem *item)
 {
   g_return_val_if_fail (XFCE_IS_MENU_ITEM (item), NULL);
@@ -928,6 +989,28 @@
 
 
 gboolean
+xfce_menu_item_has_category (XfceMenuItem *item,
+                             const gchar  *category)
+{
+  GList   *iter;
+  gboolean found = FALSE;
+
+  g_return_val_if_fail (XFCE_IS_MENU_ITEM (item), FALSE);
+  g_return_val_if_fail (category != NULL, FALSE);
+
+  for (iter = item->priv->categories; iter != NULL; iter = g_list_next (iter))
+    if (G_UNLIKELY (g_utf8_collate (iter->data, category) == 0))
+      {
+        found = TRUE;
+        break;
+      }
+
+  return found;
+}
+
+
+
+gboolean
 xfce_menu_item_show_in_environment (XfceMenuItem *item)
 {
   const gchar *env;

Modified: libxfce4menu/trunk/libxfce4menu/xfce-menu-item.h
===================================================================
--- libxfce4menu/trunk/libxfce4menu/xfce-menu-item.h    2007-12-21 13:31:41 UTC 
(rev 26499)
+++ libxfce4menu/trunk/libxfce4menu/xfce-menu-item.h    2007-12-22 23:38:52 UTC 
(rev 26500)
@@ -62,6 +62,9 @@
 const gchar  *xfce_menu_item_get_name                          (XfceMenuItem 
*item);
 void          xfce_menu_item_set_name                          (XfceMenuItem 
*item,
                                                                 const gchar  
*name);
+const gchar  *xfce_menu_item_get_generic_name                  (XfceMenuItem 
*item);
+void          xfce_menu_item_set_generic_name                  (XfceMenuItem 
*item,
+                                                                const gchar  
*generic_name);
 const gchar  *xfce_menu_item_get_icon_name                     (XfceMenuItem 
*item);
 void          xfce_menu_item_set_icon_name                     (XfceMenuItem 
*item,
                                                                 const gchar  
*icon_name);
@@ -80,6 +83,8 @@
 GList        *xfce_menu_item_get_categories                    (XfceMenuItem 
*item);
 void          xfce_menu_item_set_categories                    (XfceMenuItem 
*item,
                                                                 GList        
*categories);
+gboolean      xfce_menu_item_has_category                      (XfceMenuItem 
*item,
+                                                                const gchar  
*category);
 gboolean      xfce_menu_item_show_in_environment               (XfceMenuItem 
*item);
 void          xfce_menu_item_ref                               (XfceMenuItem 
*item);
 void          xfce_menu_item_unref                             (XfceMenuItem 
*item);

Modified: libxfce4menu/trunk/libxfce4menu/xfce-menu.c
===================================================================
--- libxfce4menu/trunk/libxfce4menu/xfce-menu.c 2007-12-21 13:31:41 UTC (rev 
26499)
+++ libxfce4menu/trunk/libxfce4menu/xfce-menu.c 2007-12-22 23:38:52 UTC (rev 
26500)
@@ -2684,11 +2684,17 @@
     {
       /* Only include item if menu not only includes unallocated items
        * or if the item is not allocated yet */
-      if (!menu->priv->only_unallocated || (xfce_menu_item_get_allocated 
(item) < 1))
+      if (!menu->priv->only_unallocated || xfce_menu_item_get_allocated (item) 
== 0)
         {
           /* Add item to the pool if it matches the include rule */
           if (G_LIKELY (xfce_menu_standard_rules_get_include (rule) && 
xfce_menu_rules_match (XFCE_MENU_RULES (rule), item)))
-            xfce_menu_item_pool_insert (menu->priv->pool, item);
+            {
+#if 0
+              if (menu->priv->directory != NULL && g_str_equal 
(xfce_menu_directory_get_name (menu->priv->directory), "Other"))
+                g_debug ("Adding item %s to Other (allocated: %d)", 
xfce_menu_item_get_name (item), xfce_menu_item_get_allocated (item));
+#endif
+              xfce_menu_item_pool_insert (menu->priv->pool, item);
+            }
         }
     }
 }

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to