diff options
Diffstat (limited to 'calendar/gui/e-comp-editor-registry.c')
-rw-r--r-- | calendar/gui/e-comp-editor-registry.c | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/calendar/gui/e-comp-editor-registry.c b/calendar/gui/e-comp-editor-registry.c index 9e2a63bd48..c576ea7465 100644 --- a/calendar/gui/e-comp-editor-registry.c +++ b/calendar/gui/e-comp-editor-registry.c @@ -34,6 +34,7 @@ struct _ECompEditorRegistryPrivate { struct _ECompEditorRegistryData { + ECompEditorRegistry *registry; CompEditor *editor; char *uid; }; @@ -41,42 +42,63 @@ struct _ECompEditorRegistryData typedef struct _ECompEditorRegistryData ECompEditorRegistryData; typedef struct _ECompEditorRegistryForeachData ECompEditorRegistryForeachData; -static GtkObjectClass *parent_class = NULL; +static GObjectClass *parent_class = NULL; -static void editor_destroy_cb (GtkWidget *widget, gpointer data); +static void editor_destroy_cb (gpointer data, GObject *where_object_was); static void -destroy (GtkObject *obj) +registry_data_free (gpointer data) +{ + ECompEditorRegistryData *rdata = data; + + if (rdata->editor) + g_object_weak_unref (G_OBJECT (rdata->editor), editor_destroy_cb, rdata); + g_free (rdata->uid); + g_free (rdata); +} + +static void +dispose (GObject *obj) { ECompEditorRegistry *reg; ECompEditorRegistryPrivate *priv; reg = E_COMP_EDITOR_REGISTRY (obj); priv = reg->priv; + + if (priv->editors) { + g_hash_table_destroy (priv->editors); + priv->editors = NULL; + } - if (priv) { - if (priv->editors) { - g_hash_table_destroy (priv->editors); - priv->editors = NULL; - } + (* G_OBJECT_CLASS (parent_class)->dispose) (obj); +} - g_free (priv); - reg->priv = NULL; - } +static void +finalize (GObject *obj) +{ + ECompEditorRegistry *reg; + ECompEditorRegistryPrivate *priv; + + reg = E_COMP_EDITOR_REGISTRY (obj); + priv = reg->priv; - (* GTK_OBJECT_CLASS (parent_class)->destroy) (obj); + g_free (priv); + + (* G_OBJECT_CLASS (parent_class)->finalize) (obj); } static void class_init (ECompEditorRegistryClass *klass) { - GtkObjectClass *object_class; + GObjectClass *object_class; - object_class = GTK_OBJECT_CLASS (klass); + object_class = G_OBJECT_CLASS (klass); parent_class = g_type_class_peek_parent (klass); - object_class->destroy = destroy; + object_class->dispose = dispose; + object_class->finalize = finalize; } static void @@ -87,16 +109,15 @@ init (ECompEditorRegistry *reg) priv = g_new0 (ECompEditorRegistryPrivate, 1); reg->priv = priv; - - priv->editors = g_hash_table_new (g_str_hash, g_str_equal); + priv->editors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, registry_data_free); } E_MAKE_TYPE (e_comp_editor_registry, "ECompEditorRegistry", ECompEditorRegistry, - class_init, init, gtk_object_get_type ()); + class_init, init, G_TYPE_OBJECT); -GtkObject * +GObject * e_comp_editor_registry_new (void) { return g_object_new (E_TYPE_COMP_EDITOR_REGISTRY, NULL); @@ -122,12 +143,14 @@ e_comp_editor_registry_add (ECompEditorRegistry *reg, CompEditor *editor, gboole rdata = g_new0 (ECompEditorRegistryData, 1); + rdata->registry = reg; rdata->editor = editor; rdata->uid = g_strdup (uid); - g_hash_table_insert (priv->editors, rdata->uid, rdata); - g_signal_connect (editor, "destroy", G_CALLBACK (editor_destroy_cb), reg); + g_hash_table_insert (priv->editors, g_strdup (uid), rdata); + /* FIXME Need to know when uid on the editor changes (if the component changes locations) */ + g_object_weak_ref (G_OBJECT (editor), editor_destroy_cb, rdata); } CompEditor * @@ -188,25 +211,12 @@ e_comp_editor_registry_close_all (ECompEditorRegistry *reg) } static void -editor_destroy_cb (GtkWidget *widget, gpointer data) +editor_destroy_cb (gpointer data, GObject *where_object_was) { - ECompEditorRegistry *reg; - ECompEditorRegistryPrivate *priv; - ECompEditorRegistryData *rdata; - ECalComponent *comp; - const char *uid; - - reg = E_COMP_EDITOR_REGISTRY (data); - priv = reg->priv; - - comp = comp_editor_get_comp (COMP_EDITOR (widget)); - e_cal_component_get_uid (comp, &uid); - - rdata = g_hash_table_lookup (priv->editors, uid); + ECompEditorRegistryData *rdata = data; - if (rdata != NULL) { - g_hash_table_remove (priv->editors, rdata->uid); - g_free (rdata->uid); - g_free (rdata); - } + /* We null it out because its dead, so we won't try to weak + * unref it in the hash destroyer */ + rdata->editor = NULL; + g_hash_table_remove (rdata->registry->priv->editors, rdata->uid); } |