aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFelix Riemann <friemann@src.gnome.org>2007-11-04 06:20:59 +0800
committerFelix Riemann <friemann@src.gnome.org>2007-11-04 06:20:59 +0800
commitdef60a9cefca3430326f2e529bd32273aa54b786 (patch)
treef2081de5e7b0ea99bb9a126e0f4d609441a6aa8b /lib
parent7e2c73fd2eb91e2f66d90daaacc3d57c8011f7ef (diff)
downloadgsoc2013-epiphany-def60a9cefca3430326f2e529bd32273aa54b786.tar
gsoc2013-epiphany-def60a9cefca3430326f2e529bd32273aa54b786.tar.gz
gsoc2013-epiphany-def60a9cefca3430326f2e529bd32273aa54b786.tar.bz2
gsoc2013-epiphany-def60a9cefca3430326f2e529bd32273aa54b786.tar.lz
gsoc2013-epiphany-def60a9cefca3430326f2e529bd32273aa54b786.tar.xz
gsoc2013-epiphany-def60a9cefca3430326f2e529bd32273aa54b786.tar.zst
gsoc2013-epiphany-def60a9cefca3430326f2e529bd32273aa54b786.zip
Update to latest EggToolbarEditor code.
This supports changing the editor's model during runtime and tries to avoid some possibly leaking signal handlers. Fixes bug #493149. svn path=/trunk/; revision=7619
Diffstat (limited to 'lib')
-rw-r--r--lib/egg/egg-toolbar-editor.c70
-rw-r--r--lib/egg/egg-toolbar-editor.h2
2 files changed, 62 insertions, 10 deletions
diff --git a/lib/egg/egg-toolbar-editor.c b/lib/egg/egg-toolbar-editor.c
index 8671cd4c3..ff48ccba5 100644
--- a/lib/egg/egg-toolbar-editor.c
+++ b/lib/egg/egg-toolbar-editor.c
@@ -55,6 +55,14 @@ enum
PROP_TOOLBARS_MODEL
};
+enum
+{
+ SIGNAL_HANDLER_ITEM_ADDED,
+ SIGNAL_HANDLER_ITEM_REMOVED,
+ SIGNAL_HANDLER_TOOLBAR_REMOVED,
+ SIGNAL_HANDLER_LIST_SIZE /* Array size */
+};
+
#define EGG_TOOLBAR_EDITOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_TOOLBAR_EDITOR, EggToolbarEditorPrivate))
struct EggToolbarEditorPrivate
@@ -66,6 +74,9 @@ struct EggToolbarEditorPrivate
GtkWidget *scrolled_window;
GList *actions_list;
GList *factory_list;
+
+ /* These handlers need to be sanely disconnected when switching models */
+ gulong sig_handlers[SIGNAL_HANDLER_LIST_SIZE];
};
G_DEFINE_TYPE (EggToolbarEditor, egg_toolbar_editor, GTK_TYPE_VBOX);
@@ -136,21 +147,59 @@ toolbar_removed_cb (EggToolbarsModel *model,
}
static void
+egg_toolbar_editor_disconnect_model (EggToolbarEditor *t)
+{
+ EggToolbarEditorPrivate *priv = t->priv;
+ EggToolbarsModel *model = priv->model;
+ gulong handler;
+ int i;
+
+ for (i = 0; i < SIGNAL_HANDLER_LIST_SIZE; i++)
+ {
+ handler = priv->sig_handlers[i];
+
+ if (handler != 0)
+ {
+ if (g_signal_handler_is_connected (model, handler))
+ {
+ g_signal_handler_disconnect (model, handler);
+ }
+
+ priv->sig_handlers[i] = 0;
+ }
+ }
+}
+
+void
egg_toolbar_editor_set_model (EggToolbarEditor *t,
EggToolbarsModel *model)
{
g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (t));
+ g_return_if_fail (model != NULL);
- t->priv->model = g_object_ref (model);
-
- update_editor_sheet (t);
+ EggToolbarEditorPrivate *priv = t->priv;
+
+ if (priv->model)
+ {
+ if (G_UNLIKELY (priv->model == model)) return;
+
+ egg_toolbar_editor_disconnect_model (t);
+ g_object_unref (priv->model);
+ }
- g_signal_connect_object (model, "item_added",
- G_CALLBACK (item_added_or_removed_cb), t, 0);
- g_signal_connect_object (model, "item_removed",
- G_CALLBACK (item_added_or_removed_cb), t, 0);
- g_signal_connect_object (model, "toolbar_removed",
- G_CALLBACK (toolbar_removed_cb), t, 0);
+ priv->model = g_object_ref (model);
+
+ update_editor_sheet (t);
+
+ priv->sig_handlers[SIGNAL_HANDLER_ITEM_ADDED] =
+ g_signal_connect_object (model, "item_added",
+ G_CALLBACK (item_added_or_removed_cb), t, 0);
+ priv->sig_handlers[SIGNAL_HANDLER_ITEM_REMOVED] =
+ g_signal_connect_object (model, "item_removed",
+ G_CALLBACK (item_added_or_removed_cb), t, 0);
+ priv->sig_handlers[SIGNAL_HANDLER_TOOLBAR_REMOVED] =
+ g_signal_connect_object (model, "toolbar_removed",
+ G_CALLBACK (toolbar_removed_cb), t, 0);
}
static void
@@ -215,7 +264,7 @@ egg_toolbar_editor_class_init (EggToolbarEditorClass *klass)
"Toolbars Model",
EGG_TYPE_TOOLBARS_MODEL,
G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB |
- G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_CONSTRUCT));
g_type_class_add_private (object_class, sizeof (EggToolbarEditorPrivate));
}
@@ -232,6 +281,7 @@ egg_toolbar_editor_finalize (GObject *object)
if (editor->priv->model)
{
+ egg_toolbar_editor_disconnect_model (editor);
g_object_unref (editor->priv->model);
}
diff --git a/lib/egg/egg-toolbar-editor.h b/lib/egg/egg-toolbar-editor.h
index e29e5482b..46ce2b87a 100644
--- a/lib/egg/egg-toolbar-editor.h
+++ b/lib/egg/egg-toolbar-editor.h
@@ -56,6 +56,8 @@ struct EggToolbarEditorClass
GType egg_toolbar_editor_get_type (void);
GtkWidget *egg_toolbar_editor_new (GtkUIManager *manager,
EggToolbarsModel *model);
+void egg_toolbar_editor_set_model (EggToolbarEditor *t,
+ EggToolbarsModel *model);
G_END_DECLS