More fixing.

* Fix a resource leak in LdLibrary.
* Add missing property change notifiers
  to ld_diagram_object_{get,set}_storage().
* Don't unref the parameter in ld_symbol_category_remove_{symbol,subcategory}
  if it wasn't actually removed from the internal list.
* Fix a cyclic dependency problem in LdDiagram.
This commit is contained in:
Přemysl Eric Janouch 2012-08-11 21:00:38 +02:00
parent f55afb6542
commit bb224bafd0
4 changed files with 36 additions and 8 deletions

View File

@ -221,8 +221,12 @@ JsonObject *
ld_diagram_object_get_storage (LdDiagramObject *self) ld_diagram_object_get_storage (LdDiagramObject *self)
{ {
g_return_val_if_fail (LD_IS_DIAGRAM_OBJECT (self), NULL); g_return_val_if_fail (LD_IS_DIAGRAM_OBJECT (self), NULL);
if (!self->priv->storage) if (!self->priv->storage)
{
self->priv->storage = json_object_new (); self->priv->storage = json_object_new ();
g_object_notify (G_OBJECT (self), "storage");
}
return self->priv->storage; return self->priv->storage;
} }
@ -245,6 +249,8 @@ ld_diagram_object_set_storage (LdDiagramObject *self, JsonObject *storage)
self->priv->storage = json_object_ref (storage); self->priv->storage = json_object_ref (storage);
else else
self->priv->storage = NULL; self->priv->storage = NULL;
g_object_notify (G_OBJECT (self), "storage");
} }
/** /**

View File

@ -803,12 +803,19 @@ ld_diagram_end_user_action (LdDiagram *self)
(self->priv->undo_stack, self->priv->undo_stack); (self->priv->undo_stack, self->priv->undo_stack);
} }
static void
action_finalize_notify_cb (ObjectActionData *data, LdDiagram *self)
{
data->self = NULL;
}
static void static void
on_object_action_remove (gpointer user_data) on_object_action_remove (gpointer user_data)
{ {
ObjectActionData *data; ObjectActionData *data;
data = user_data; data = user_data;
g_return_if_fail (data->self != NULL);
ld_diagram_remove_object (data->self, data->object); ld_diagram_remove_object (data->self, data->object);
} }
@ -818,6 +825,7 @@ on_object_action_insert (gpointer user_data)
ObjectActionData *data; ObjectActionData *data;
data = user_data; data = user_data;
g_return_if_fail (data->self != NULL);
ld_diagram_insert_object (data->self, data->object, data->pos); ld_diagram_insert_object (data->self, data->object, data->pos);
} }
@ -827,7 +835,8 @@ on_object_action_destroy (gpointer user_data)
ObjectActionData *data; ObjectActionData *data;
data = user_data; data = user_data;
g_object_unref (data->self); g_object_weak_unref (G_OBJECT (data->self),
(GWeakNotify) action_finalize_notify_cb, data);
g_object_unref (data->object); g_object_unref (data->object);
g_slice_free (ObjectActionData, data); g_slice_free (ObjectActionData, data);
} }
@ -891,7 +900,9 @@ ld_diagram_insert_object (LdDiagram *self, LdDiagramObject *object, gint pos)
install_object (object, self); install_object (object, self);
action_data = g_slice_new (ObjectActionData); action_data = g_slice_new (ObjectActionData);
action_data->self = g_object_ref (self); action_data->self = self;
g_object_weak_ref (G_OBJECT (self),
(GWeakNotify) action_finalize_notify_cb, action_data);
action_data->object = g_object_ref (object); action_data->object = g_object_ref (object);
action_data->pos = pos; action_data->pos = pos;
@ -938,7 +949,9 @@ ld_diagram_remove_object (LdDiagram *self, LdDiagramObject *object)
uninstall_object (object, self); uninstall_object (object, self);
action_data = g_slice_new (ObjectActionData); action_data = g_slice_new (ObjectActionData);
action_data->self = g_object_ref (self); action_data->self = self;
g_object_weak_ref (G_OBJECT (self),
(GWeakNotify) action_finalize_notify_cb, action_data);
action_data->object = g_object_ref (object); action_data->object = g_object_ref (object);
action_data->pos = pos; action_data->pos = pos;

View File

@ -378,7 +378,10 @@ ld_library_load_cb (const gchar *base, const gchar *filename, gpointer userdata)
cat = load_category (data->self, filename, base); cat = load_category (data->self, filename, base);
if (cat) if (cat)
{
ld_library_insert_category (data->self, cat, -1); ld_library_insert_category (data->self, cat, -1);
g_object_unref (cat);
}
data->changed = TRUE; data->changed = TRUE;
return TRUE; return TRUE;

View File

@ -325,8 +325,11 @@ ld_symbol_category_remove_symbol (LdSymbolCategory *self,
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self)); g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
g_return_if_fail (LD_IS_SYMBOL (symbol)); g_return_if_fail (LD_IS_SYMBOL (symbol));
g_object_unref (symbol); if (g_slist_find (self->priv->symbols, symbol))
{
self->priv->symbols = g_slist_remove (self->priv->symbols, symbol); self->priv->symbols = g_slist_remove (self->priv->symbols, symbol);
g_object_unref (symbol);
}
} }
/** /**
@ -378,9 +381,12 @@ ld_symbol_category_remove_subcategory (LdSymbolCategory *self,
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self)); g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (category)); g_return_if_fail (LD_IS_SYMBOL_CATEGORY (category));
g_object_unref (category); if (g_slist_find (self->priv->subcategories, category))
{
self->priv->subcategories self->priv->subcategories
= g_slist_remove (self->priv->subcategories, category); = g_slist_remove (self->priv->subcategories, category);
g_object_unref (category);
}
} }
/** /**