Remove erroneous debug print introduced in last commit
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / accessible-cache.c
index f282d55..afaedb0 100644 (file)
@@ -125,8 +125,8 @@ spi_cache_init (SpiCache * cache)
 
   add_subtree (cache, spi_global_app_data->root);
 
-  atk_add_global_event_listener (child_added_listener,
-                                 "Gtk:AtkObject:children-changed");
+  cache->child_added_listener = atk_add_global_event_listener (child_added_listener,
+                                                               "Gtk:AtkObject:children-changed"); 
 
   g_signal_connect (G_OBJECT (spi_global_app_data->root),
                     "children-changed::add",
@@ -141,7 +141,15 @@ spi_cache_finalize (GObject * object)
   while (!g_queue_is_empty (cache->add_traversal))
     g_object_unref (G_OBJECT (g_queue_pop_head (cache->add_traversal)));
   g_queue_free (cache->add_traversal);
-  g_free (cache->objects);
+  g_hash_table_unref (cache->objects);
+
+  g_signal_handlers_disconnect_by_func (spi_global_register,
+                                        (GCallback) remove_object, cache);
+
+  g_signal_handlers_disconnect_by_func (G_OBJECT (spi_global_app_data->root),
+                                        (GCallback) toplevel_added_listener, NULL);
+
+  atk_remove_global_event_listener (cache->child_added_listener);
 
   G_OBJECT_CLASS (spi_cache_parent_class)->finalize (object);
 }
@@ -171,6 +179,8 @@ remove_object (GObject * source, GObject * gobj, gpointer data)
       g_signal_emit (cache, cache_signals [OBJECT_REMOVED], 0, gobj);
       g_hash_table_remove (cache->objects, gobj);
     }
+  else
+    g_queue_remove (cache->add_traversal, gobj);
 }
 
 static void
@@ -271,17 +281,19 @@ add_pending_items (gpointer data)
       current = g_queue_pop_head (cache->add_traversal);
       set = atk_object_ref_state_set (current);
 
-      if (!atk_state_set_contains_state (set, ATK_STATE_TRANSIENT))
+      if (set && !atk_state_set_contains_state (set, ATK_STATE_TRANSIENT))
         {
          g_queue_push_tail (to_add, current);
           if (!spi_cache_in (cache, G_OBJECT (current)) &&
-              !atk_state_set_contains_state  (set, ATK_STATE_MANAGES_DESCENDANTS))
+              !atk_state_set_contains_state  (set, ATK_STATE_MANAGES_DESCENDANTS) &&
+              !atk_state_set_contains_state  (set, ATK_STATE_DEFUNCT))
             {
               append_children (current, cache->add_traversal);
             }
         }
 
-      g_object_unref (set);
+      if (set)
+        g_object_unref (set);
     }
 
   while (!g_queue_is_empty (to_add))
@@ -309,9 +321,7 @@ child_added_listener (GSignalInvocationHint * signal_hint,
                       const GValue * param_values, gpointer data)
 {
   SpiCache *cache = spi_global_cache;
-
   AtkObject *accessible;
-  AtkObject *child;
 
   const gchar *detail = NULL;
 
@@ -335,16 +345,17 @@ child_added_listener (GSignalInvocationHint * signal_hint,
       if (signal_hint->detail)
         detail = g_quark_to_string (signal_hint->detail);
 
-      if (!strncmp (detail, "add", 3))
+      if (detail && !strncmp (detail, "add", 3))
         {
           gpointer child;
           int index = g_value_get_uint (param_values + 1);
           child = g_value_get_pointer (param_values + 2);
+          if (!child)
+            {
+              g_static_rec_mutex_unlock (&cache_mutex);
+              return;
+            }
 
-          if (!ATK_IS_OBJECT (child))
-           {
-             child = atk_object_ref_accessible_child (accessible, index);
-           }
           g_object_ref (child);
           g_queue_push_tail (cache->add_traversal, child);
 
@@ -411,6 +422,9 @@ spi_cache_foreach (SpiCache * cache, GHFunc func, gpointer data)
 gboolean
 spi_cache_in (SpiCache * cache, GObject * object)
 {
+  if (!cache)
+    return FALSE;
+
   if (g_hash_table_lookup_extended (cache->objects,
                                     object,
                                     NULL,