From 0373d6fcb3f7b62028db4978ba215c403b43fed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 25 Jan 2012 11:55:37 +0100 Subject: IndicatorObject: correctly initialize the parent object. --- libindicator/indicator-object.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 849fb9f..6e25387 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -348,6 +348,7 @@ indicator_object_dispose (GObject *object) if (entry_get_private(io, entry)->visibility == ENTRY_INVISIBLE) { g_signal_emit(io, signals[ENTRY_ADDED], detail, entry); } + entry->parent_object = NULL; } g_list_free (entries); @@ -507,6 +508,8 @@ get_entries_default (IndicatorObject * io) if (!priv->gotten_entries) { IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); + priv->entry.parent_object = io; + if (class->get_label) { priv->entry.label = class->get_label(io); } @@ -551,7 +554,7 @@ get_entries_default (IndicatorObject * io) static GList* get_all_entries (IndicatorObject * io) { - GList * all_entries = NULL; + GList * all_entries = NULL, *l; g_return_val_if_fail(INDICATOR_IS_OBJECT(io), NULL); IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); @@ -559,8 +562,16 @@ get_all_entries (IndicatorObject * io) if (class->get_entries == NULL) g_error("No get_entries function on object. It must have been deleted?!?!"); else + { all_entries = class->get_entries(io); + for (l = all_entries; l; l = l->next) + { + IndicatorObjectEntry *entry = l->data; + entry->parent_object = io; + } + } + return all_entries; } @@ -757,6 +768,7 @@ indicator_object_entry_being_removed (IndicatorObject * io, IndicatorObjectEntry IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); entry_get_private (io, entry)->visibility = ENTRY_INVISIBLE; + entry->parent_object = NULL; if (class->entry_being_removed != NULL) class->entry_being_removed (io, entry); @@ -769,6 +781,7 @@ indicator_object_entry_was_added (IndicatorObject * io, IndicatorObjectEntry * e IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); entry_get_private (io, entry)->visibility = ENTRY_VISIBLE; + entry->parent_object = io; if (class->entry_was_added != NULL) class->entry_was_added (io, entry); -- cgit v1.2.3 From c9df18becfc38ab3e3a833d0095c26f5140800e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 25 Jan 2012 12:21:51 +0100 Subject: Indicator-Object: update the parent_object value only if the entry is valid. --- libindicator/indicator-object.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 6e25387..91f45ff 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -348,7 +348,9 @@ indicator_object_dispose (GObject *object) if (entry_get_private(io, entry)->visibility == ENTRY_INVISIBLE) { g_signal_emit(io, signals[ENTRY_ADDED], detail, entry); } - entry->parent_object = NULL; + + if (entry) + entry->parent_object = NULL; } g_list_free (entries); @@ -568,7 +570,9 @@ get_all_entries (IndicatorObject * io) for (l = all_entries; l; l = l->next) { IndicatorObjectEntry *entry = l->data; - entry->parent_object = io; + + if (entry) + entry->parent_object = io; } } @@ -768,10 +772,14 @@ indicator_object_entry_being_removed (IndicatorObject * io, IndicatorObjectEntry IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); entry_get_private (io, entry)->visibility = ENTRY_INVISIBLE; - entry->parent_object = NULL; if (class->entry_being_removed != NULL) + { + if (entry) + entry->parent_object = NULL; + class->entry_being_removed (io, entry); + } } static void @@ -781,10 +789,14 @@ indicator_object_entry_was_added (IndicatorObject * io, IndicatorObjectEntry * e IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); entry_get_private (io, entry)->visibility = ENTRY_VISIBLE; - entry->parent_object = io; if (class->entry_was_added != NULL) + { + if (entry) + entry->parent_object = io; + class->entry_was_added (io, entry); + } } /** -- cgit v1.2.3 From c26baddf8b8f8a290557f1a51d4e957bc95e45c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 25 Jan 2012 12:22:12 +0100 Subject: Added better parent_object tests. --- tests/test-loader.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test-loader.c b/tests/test-loader.c index 6f9d25b..b567733 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -190,6 +190,8 @@ test_loader_filename_dummy_visible (void) g_assert(entry != NULL); g_list_free(list); g_assert(GTK_IS_LABEL(entry->label)); + g_assert(entry->parent_object == object); + g_assert(INDICATOR_IS_OBJECT(entry->parent_object)); GtkWidget * label = GTK_WIDGET(entry->label); g_assert(g_object_get_qdata(G_OBJECT(label), is_hidden_quark) == NULL); @@ -239,9 +241,11 @@ test_loader_filename_dummy_simple_location (void) g_assert(entries != NULL); g_assert(g_list_length(entries) == 1); - g_assert(indicator_object_get_location(object, (IndicatorObjectEntry *)entries->data) == 0); + IndicatorObjectEntry *entry = entries->data; + + g_assert(indicator_object_get_location(object, entry) == 0); g_assert(indicator_object_get_location(object, NULL) == 0); - g_assert(((IndicatorObjectEntry *)entries->data)->parent_object != NULL); + g_assert(entry->parent_object == object); g_object_unref(object); -- cgit v1.2.3 From 1baaf2880f44fea4519f323e3da425318af6c688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 25 Jan 2012 18:10:29 +0100 Subject: IndicatorObject: update object parent in any case. --- libindicator/indicator-object.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 91f45ff..d0b3ecf 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -773,11 +773,11 @@ indicator_object_entry_being_removed (IndicatorObject * io, IndicatorObjectEntry entry_get_private (io, entry)->visibility = ENTRY_INVISIBLE; + if (entry) + entry->parent_object = NULL; + if (class->entry_being_removed != NULL) { - if (entry) - entry->parent_object = NULL; - class->entry_being_removed (io, entry); } } @@ -790,11 +790,11 @@ indicator_object_entry_was_added (IndicatorObject * io, IndicatorObjectEntry * e entry_get_private (io, entry)->visibility = ENTRY_VISIBLE; + if (entry) + entry->parent_object = io; + if (class->entry_was_added != NULL) { - if (entry) - entry->parent_object = io; - class->entry_was_added (io, entry); } } -- cgit v1.2.3 From 39cf870292e40bd72a16fc10b20135e294d4e269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 25 Jan 2012 18:11:07 +0100 Subject: Tests: update dummy signaler to work with real IndicatorObjectEntry This fixes a crash due to the parent/unparent. --- tests/dummy-indicator-signaler.c | 17 ++++++++++++++--- tests/test-loader.c | 23 ++++++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/tests/dummy-indicator-signaler.c b/tests/dummy-indicator-signaler.c index c7a5c1f..9908d3d 100644 --- a/tests/dummy-indicator-signaler.c +++ b/tests/dummy-indicator-signaler.c @@ -110,9 +110,20 @@ idle_signal (gpointer data) { DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(data); - g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, GUINT_TO_POINTER(5), TRUE); - g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, GUINT_TO_POINTER(5), TRUE); - g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED_ID, 0, GUINT_TO_POINTER(5), 0, 1, TRUE); + IndicatorObjectEntry *added_entry, *removed_entry, *moved_entry; + IndicatorObjectEntry *entries = g_new0(IndicatorObjectEntry, 3); + + added_entry = &entries[0]; + moved_entry = &entries[1]; + removed_entry = &entries[2]; + + added_entry->name_hint = "added"; + moved_entry->name_hint = "moved"; + removed_entry->name_hint = "removed"; + + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, added_entry); + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED_ID, 0, moved_entry, 0, 1); + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, removed_entry); return FALSE; /* Don't queue again */ } diff --git a/tests/test-loader.c b/tests/test-loader.c index b567733..2140294 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -100,8 +100,8 @@ void destroy_cb (gpointer data, GObject * object); void entry_change_cb (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer data) { - gpointer * valuestore = (gpointer *)data; - *valuestore = entry; + IndicatorObjectEntry *other_entry = data; + other_entry->name_hint = entry->name_hint; return; } @@ -117,11 +117,16 @@ test_loader_filename_dummy_signaler (void) IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-signaler.so"); g_assert(object != NULL); - gpointer added_value = NULL, removed_value = NULL, moved_value = NULL; + IndicatorObjectEntry *added_entry, *moved_entry, *removed_entry; + IndicatorObjectEntry entries[3]; - g_signal_connect(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_change_cb), &added_value); - g_signal_connect(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_change_cb), &removed_value); - g_signal_connect(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED, G_CALLBACK(entry_move_cb), &moved_value); + added_entry = &entries[0]; + moved_entry = &entries[1]; + removed_entry = &entries[2]; + + g_signal_connect_after(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_change_cb), added_entry); + g_signal_connect_after(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED, G_CALLBACK(entry_move_cb), moved_entry); + g_signal_connect_after(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_change_cb), removed_entry); GList * list = indicator_object_get_entries(object); g_assert(list != NULL); @@ -131,9 +136,9 @@ test_loader_filename_dummy_signaler (void) g_main_context_iteration(NULL, TRUE); } - g_assert(GPOINTER_TO_UINT(added_value) == 5); - g_assert(GPOINTER_TO_UINT(removed_value) == 5); - g_assert(GPOINTER_TO_UINT(moved_value) == 5); + g_assert(g_strcmp0(added_entry->name_hint, "added") == 0); + g_assert(g_strcmp0(removed_entry->name_hint, "removed") == 0); + g_assert(g_strcmp0(moved_entry->name_hint, "moved") == 0); g_object_unref(object); -- cgit v1.2.3 From c87aff749b07f228e3fa69c1155d9128ef07620c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 25 Jan 2012 18:11:43 +0100 Subject: Test loader: check also for parent changes --- tests/test-loader.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test-loader.c b/tests/test-loader.c index 2140294..28c56aa 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -102,6 +102,7 @@ entry_change_cb (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer da { IndicatorObjectEntry *other_entry = data; other_entry->name_hint = entry->name_hint; + other_entry->parent_object = entry->parent_object; return; } @@ -140,6 +141,9 @@ test_loader_filename_dummy_signaler (void) g_assert(g_strcmp0(removed_entry->name_hint, "removed") == 0); g_assert(g_strcmp0(moved_entry->name_hint, "moved") == 0); + g_assert(added_entry->parent_object == object); + g_assert(removed_entry->parent_object == NULL); + g_object_unref(object); return; -- cgit v1.2.3 From 7ae413b583259eb8c312511c4da5f0558d2daab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 3 Feb 2012 15:34:07 +0100 Subject: tests, DummyIndicatorSignaler: free the allocated memory. --- tests/dummy-indicator-signaler.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/dummy-indicator-signaler.c b/tests/dummy-indicator-signaler.c index 9908d3d..a4206d0 100644 --- a/tests/dummy-indicator-signaler.c +++ b/tests/dummy-indicator-signaler.c @@ -42,6 +42,7 @@ struct _DummyIndicatorSignalerClass { struct _DummyIndicatorSignaler { IndicatorObject parent; + IndicatorObjectEntry *entries; }; GType dummy_indicator_signaler_get_type (void); @@ -111,11 +112,10 @@ idle_signal (gpointer data) DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(data); IndicatorObjectEntry *added_entry, *removed_entry, *moved_entry; - IndicatorObjectEntry *entries = g_new0(IndicatorObjectEntry, 3); - added_entry = &entries[0]; - moved_entry = &entries[1]; - removed_entry = &entries[2]; + added_entry = &self->entries[0]; + moved_entry = &self->entries[1]; + removed_entry = &self->entries[2]; added_entry->name_hint = "added"; moved_entry->name_hint = "moved"; @@ -131,6 +131,7 @@ idle_signal (gpointer data) static void dummy_indicator_signaler_init (DummyIndicatorSignaler *self) { + self->entries = g_new0(IndicatorObjectEntry, 3); g_idle_add(idle_signal, self); return; } @@ -146,7 +147,8 @@ dummy_indicator_signaler_dispose (GObject *object) static void dummy_indicator_signaler_finalize (GObject *object) { - + DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(object); + g_free (self->entries); G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->finalize (object); return; } -- cgit v1.2.3