]> err.no Git - libchamplain/commitdiff
Fix Bug 584368 for ChamplainMapSourceFactory
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 31 May 2009 22:20:01 +0000 (18:20 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 31 May 2009 22:20:01 +0000 (18:20 -0400)
champlain/champlain-cache.c
champlain/champlain-map-source-factory.c
champlain/champlain-map-source-factory.h
champlain/champlain-view.c
demos/launcher-gtk.c

index c342526fecfe8af80ec7780d6479eebc42b4286a..77b5481e8c5279c5f4e3a5153bd7ad4a5cc3853f 100644 (file)
@@ -278,9 +278,11 @@ cleanup:
 }
 
 /**
- * champlain_cache_get_default:
+ * champlain_cache_dup_default:
+ *
+ * Returns the #ChamplainCache singleton, use #g_object_unref when not neeeded
+ * anymore.
  *
- * Returns the #ChamplainCache singleton
  *
  * Since: 0.4
  */
index 2bd84a34a36a8e184fb4a841accc1e21f3f4f437..6c583835f4345500afce30b79bc3e565b3ca0185 100644 (file)
@@ -62,6 +62,7 @@ enum
 };
 
 /* static guint champlain_map_source_factory_signals[LAST_SIGNAL] = { 0, }; */
+static ChamplainMapSourceFactory *instance = NULL;
 
 G_DEFINE_TYPE (ChamplainMapSourceFactory, champlain_map_source_factory, G_TYPE_OBJECT);
 
@@ -121,12 +122,37 @@ champlain_map_source_factory_finalize (GObject *object)
   G_OBJECT_CLASS (champlain_map_source_factory_parent_class)->finalize (object);
 }
 
+static GObject *
+champlain_map_source_factory_constructor (GType type,
+    guint n_construct_params,
+    GObjectConstructParam *construct_params)
+{
+  GObject *retval;
+
+  if (instance == NULL)
+    {
+      retval = G_OBJECT_CLASS (champlain_map_source_factory_parent_class)->constructor
+          (type, n_construct_params, construct_params);
+
+      instance = CHAMPLAIN_MAP_SOURCE_FACTORY (retval);
+      g_object_add_weak_pointer (retval, (gpointer) &instance);
+    }
+  else
+    {
+      retval = g_object_ref (instance);
+    }
+
+  return retval;
+}
+
 static void
 champlain_map_source_factory_class_init (ChamplainMapSourceFactoryClass *klass)
 {
   g_type_class_add_private (klass, sizeof (ChamplainMapSourceFactoryPrivate));
 
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructor = champlain_map_source_factory_constructor;
   object_class->finalize = champlain_map_source_factory_finalize;
   object_class->get_property = champlain_map_source_factory_get_property;
   object_class->set_property = champlain_map_source_factory_set_property;
@@ -214,25 +240,17 @@ champlain_map_source_factory_init (ChamplainMapSourceFactory *factory)
 }
 
 /**
- * champlain_map_source_factory_get_default:
+ * champlain_map_source_factory_dup_default:
  *
- * Returns the singleton #ChamplainMapSourceFactory
+ * Returns the singleton #ChamplainMapSourceFactory, it should be freed
+ * using #g_object_unref when not needed.
  *
  * Since: 0.4
  */
 ChamplainMapSourceFactory *
-champlain_map_source_factory_get_default (void)
+champlain_map_source_factory_dup_default (void)
 {
-  static ChamplainMapSourceFactory *instance = NULL;
-
-  if (G_UNLIKELY (instance == NULL))
-    {
-      instance = g_object_new (CHAMPLAIN_TYPE_MAP_SOURCE_FACTORY, NULL);
-      g_object_add_weak_pointer (G_OBJECT (instance), (gpointer*)&instance);
-      return instance;
-    }
-
-  return g_object_ref (instance);
+  return g_object_new (CHAMPLAIN_TYPE_MAP_SOURCE_FACTORY, NULL);
 }
 
 /**
index 191d1417f44b07ae19764e932040dc8e6fea7afb..c2c441e4f38dc7424fe1579e74ffcf31f11b85b8 100644 (file)
@@ -55,7 +55,7 @@ struct _ChamplainMapSourceFactoryClass
 
 GType champlain_map_source_factory_get_type (void);
 
-ChamplainMapSourceFactory * champlain_map_source_factory_get_default (void);
+ChamplainMapSourceFactory * champlain_map_source_factory_dup_default (void);
 
 GSList * champlain_map_source_factory_get_list (ChamplainMapSourceFactory *factory);
 
index 474edbecabb67403ca05aa7b42cf24734a870d33..7bcf6fe4c7dfb8c8e0238b54822083175991cc28 100644 (file)
@@ -791,7 +791,7 @@ champlain_view_init (ChamplainView *view)
 
   view->priv = priv;
 
-  priv->factory = champlain_map_source_factory_get_default ();
+  priv->factory = champlain_map_source_factory_dup_default ();
   priv->map_source = champlain_map_source_factory_create (priv->factory, CHAMPLAIN_MAP_SOURCE_OSM_MAPNIK);
   priv->zoom_level = 0;
   priv->min_zoom_level = champlain_map_source_get_min_zoom_level (priv->map_source);
index 3e05184c8f4ed9c9bcce93176e5019a84aeaa058..194d9fde32c1ef842f0736f24fe45ea157c63590 100644 (file)
@@ -63,7 +63,7 @@ map_source_changed (GtkWidget *widget,
 
   gtk_tree_model_get (model, &iter, COL_ID, &id, -1);
 
-  ChamplainMapSourceFactory *factory = champlain_map_source_factory_get_default ();
+  ChamplainMapSourceFactory *factory = champlain_map_source_factory_dup_default ();
   source = champlain_map_source_factory_create (factory, id);
 
   if (source != NULL)
@@ -141,9 +141,9 @@ build_combo_box (GtkComboBox *box)
       G_TYPE_STRING, /* name */
       -1);
 
-  factory = champlain_map_source_factory_get_default ();
+  factory = champlain_map_source_factory_dup_default ();
   sources = champlain_map_source_factory_get_list (factory);
-  
+
   iter = sources;
   while (iter != NULL)
   {