[Xfce4-commits] <garcon:master> Make GarconMenuSeparator a singleton.

Nick Schermer nick at xfce.org
Mon Aug 17 18:16:07 CEST 2009


Updating branch refs/heads/master
         to f22335e8808dcc6a1f5ecb08b9fde2550aad1299 (commit)
       from 415fd0ea800c21546b5fa170a560beaa36e18fa3 (commit)

commit f22335e8808dcc6a1f5ecb08b9fde2550aad1299
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Aug 17 17:46:37 2009 +0200

    Make GarconMenuSeparator a singleton.

 garcon/garcon-menu-separator.c |   64 ++++++++++++++-------------------------
 garcon/garcon-menu-separator.h |   17 +++++++---
 garcon/garcon.c                |    8 -----
 3 files changed, 35 insertions(+), 54 deletions(-)

diff --git a/garcon/garcon-menu-separator.c b/garcon/garcon-menu-separator.c
index c2c2f88..0a8bebd 100644
--- a/garcon/garcon-menu-separator.c
+++ b/garcon/garcon-menu-separator.c
@@ -38,45 +38,6 @@ static gboolean     garcon_menu_separator_get_element_show_in_environment (Garco
 static gboolean     garcon_menu_separator_get_element_no_display          (GarconMenuElement        *element);
 
 
-static GarconMenuSeparator *_garcon_menu_separator = NULL;
-
-
-
-void
-_garcon_menu_separator_init (void)
-{
-  if (G_LIKELY (_garcon_menu_separator == NULL))
-    {
-      _garcon_menu_separator = g_object_new (GARCON_TYPE_MENU_SEPARATOR, NULL);
-      g_object_add_weak_pointer (G_OBJECT (_garcon_menu_separator),
-                                 (gpointer) &_garcon_menu_separator);
-    }
-}
-
-
-
-void
-_garcon_menu_separator_shutdown (void)
-{
-  if (G_LIKELY (_garcon_menu_separator != NULL))
-    g_object_unref (G_OBJECT (_garcon_menu_separator));
-}
-
-
-
-struct _GarconMenuSeparatorClass
-{
-  GObjectClass __parent__;
-};
-
-struct _GarconMenuSeparator
-{
-  GObject __parent__;
-
-
-};
-
-
 
 G_DEFINE_TYPE_WITH_CODE (GarconMenuSeparator, garcon_menu_separator, G_TYPE_OBJECT,
     G_IMPLEMENT_INTERFACE (GARCON_TYPE_MENU_ELEMENT, garcon_menu_separator_element_init))
@@ -125,10 +86,32 @@ garcon_menu_separator_finalize (GObject *object)
 
 
 
+/**
+ * garcon_menu_separator_get_default:
+ *
+ * Returns the default #GarconMenuSeparator.
+ *
+ * Return value: the default #GarconMenuSeparator. The returned object
+ * should be unreffed with g_object_unref() when no longer needed.
+ */
 GarconMenuSeparator*
 garcon_menu_separator_get_default (void)
 {
-  return _garcon_menu_separator;
+  static GarconMenuSeparator *separator = NULL;
+
+  if (G_UNLIKELY (separator == NULL))
+    {
+      /* create a new cache */
+      separator = g_object_new (GARCON_TYPE_MENU_SEPARATOR, NULL);
+      g_object_add_weak_pointer (G_OBJECT (separator), (gpointer) &separator);
+    }
+  else
+    {
+      /* set and extra reference */
+      g_object_ref (G_OBJECT (separator));
+    }
+
+  return separator;
 }
 
 
@@ -178,4 +161,3 @@ garcon_menu_separator_get_element_no_display (GarconMenuElement *element)
 {
   return FALSE;
 }
-
diff --git a/garcon/garcon-menu-separator.h b/garcon/garcon-menu-separator.h
index ccc920b..40fdbd8 100644
--- a/garcon/garcon-menu-separator.h
+++ b/garcon/garcon-menu-separator.h
@@ -40,15 +40,22 @@ G_BEGIN_DECLS
 typedef struct _GarconMenuSeparatorClass GarconMenuSeparatorClass;
 typedef struct _GarconMenuSeparator      GarconMenuSeparator;
 
+struct _GarconMenuSeparatorClass
+{
+  GObjectClass __parent__;
+};
+
+struct _GarconMenuSeparator
+{
+  GObject __parent__;
+};
+
+
+
 GType                garcon_menu_separator_get_type    (void) G_GNUC_CONST;
 
 GarconMenuSeparator *garcon_menu_separator_get_default (void);
 
-#if defined(GARCON_COMPILATION)
-void                 _garcon_menu_separator_init       (void) G_GNUC_INTERNAL;
-void                 _garcon_menu_separator_shutdown   (void) G_GNUC_INTERNAL;
-#endif
-
 G_END_DECLS
 
 #endif /* !__GARCON_MENU_SEPARATOR_H__ */
diff --git a/garcon/garcon.c b/garcon/garcon.c
index 43a0cb1..c44421e 100644
--- a/garcon/garcon.c
+++ b/garcon/garcon.c
@@ -26,8 +26,6 @@
 
 #include <garcon/garcon.h>
 #include <garcon/garcon-environment.h>
-#include <garcon/garcon-menu-item-cache.h>
-#include <garcon/garcon-menu-separator.h>
 
 
 
@@ -68,9 +66,6 @@ garcon_init (const gchar *env)
 
       /* Set desktop environment */
       garcon_set_environment (env);
-
-      /* Creates the menu separator */
-      _garcon_menu_separator_init ();
    }
 }
 
@@ -88,9 +83,6 @@ garcon_shutdown (void)
     {
       /* Unset desktop environment */
       garcon_set_environment (NULL);
-
-      /* Destroys the menu separator */
-      _garcon_menu_separator_shutdown ();
     }
 }
 



More information about the Xfce4-commits mailing list