Fixed ugly little regression introduced by 'failsafe' fix
[platform/core/uifw/at-spi2-atk.git] / registryd / desktop.c
index e3ed7de..929a25e 100644 (file)
 #include <libbonobo.h>
 #include "desktop.h"
 
+/* SpiDesktop signals */
+enum {
+  APPLICATION_ADDED,
+  APPLICATION_REMOVED,  
+LAST_SIGNAL
+};
+static guint spi_desktop_signals[LAST_SIGNAL];
+
+
 /* Our parent Gtk object type */
 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
 
@@ -44,6 +53,7 @@ spi_desktop_init (SpiDesktop *desktop)
   spi_base_construct (SPI_BASE (desktop), g_object_new (ATK_TYPE_OBJECT, NULL));
 
   desktop->applications = NULL;
+  bonobo_object_set_immortal (BONOBO_OBJECT (desktop), TRUE);
 
   atk_object_set_name (ATK_OBJECT (SPI_BASE (desktop)->gobj), "main");
 }
@@ -55,7 +65,8 @@ spi_desktop_dispose (GObject *object)
 
   while (desktop->applications)
     {
-      Application *app = (Application *) desktop->applications;
+      Application *app = desktop->applications->data;
+      g_assert (app->ref != CORBA_OBJECT_NIL);
       spi_desktop_remove_application (desktop, app->ref);
     }
 
@@ -116,6 +127,24 @@ spi_desktop_class_init (SpiDesktopClass *klass)
   
   parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
 
+  spi_desktop_signals[APPLICATION_ADDED] =
+    g_signal_new ("application_added",
+                 G_TYPE_FROM_CLASS (klass),
+                 G_SIGNAL_RUN_LAST,
+                 G_STRUCT_OFFSET (SpiDesktopClass, application_added),
+                 NULL, NULL,
+                 g_cclosure_marshal_VOID__UINT,
+                 G_TYPE_NONE,
+                 1, G_TYPE_UINT);
+  spi_desktop_signals[APPLICATION_REMOVED] =
+    g_signal_new ("application_removed",
+                 G_TYPE_FROM_CLASS (klass),
+                 G_SIGNAL_RUN_LAST,
+                 G_STRUCT_OFFSET (SpiDesktopClass, application_removed),
+                 NULL, NULL,
+                 g_cclosure_marshal_VOID__UINT,
+                 G_TYPE_NONE,
+                 1, G_TYPE_UINT);
   epv->_get_childCount = impl_desktop_get_child_count;
   epv->getChildAtIndex = impl_desktop_get_child_at_index;
 }
@@ -165,8 +194,12 @@ spi_desktop_add_application (SpiDesktop *desktop,
 
       desktop->applications = g_list_append (desktop->applications, app);
 
-      ORBit_small_listen_for_broken (app->ref, G_CALLBACK (abnormal_application_termination), app);
-      g_signal_emit_by_name (SPI_BASE(desktop)->gobj, "children_changed::add", g_list_index (desktop->applications, app), NULL);
+      ORBit_small_listen_for_broken (
+             app->ref, G_CALLBACK (abnormal_application_termination), app);
+
+      g_signal_emit (G_OBJECT (desktop),
+                    spi_desktop_signals[APPLICATION_ADDED], 0,
+                    g_list_index (desktop->applications, app));
     }
 
   CORBA_exception_free (&ev);
@@ -176,13 +209,16 @@ void
 spi_desktop_remove_application (SpiDesktop *desktop,
                                const Accessibility_Application app_ref)
 {
+  guint idx;
   GList *l;
   CORBA_Environment ev;
 
+  g_return_if_fail (app_ref != CORBA_OBJECT_NIL);
   g_return_if_fail (SPI_IS_DESKTOP (desktop));
 
   CORBA_exception_init (&ev);
 
+  idx = 0;
   for (l = desktop->applications; l; l = l->next)
     {
       Application *app = (Application *) l->data;
@@ -191,6 +227,7 @@ spi_desktop_remove_application (SpiDesktop *desktop,
         {
          break;
        }
+      idx++;
     }
 
   CORBA_exception_free (&ev);
@@ -199,11 +236,12 @@ spi_desktop_remove_application (SpiDesktop *desktop,
     {
       Application *app = (Application *) l->data;
 
-      g_signal_emit_by_name (SPI_BASE(desktop)->gobj, "children_changed::remove", g_list_index (desktop->applications, l), NULL);
       desktop->applications = g_list_delete_link (desktop->applications, l);
 
       ORBit_small_unlisten_for_broken (app->ref, G_CALLBACK (abnormal_application_termination));
       bonobo_object_release_unref (app->ref, NULL);
       g_free (app);
+      
+      g_signal_emit (G_OBJECT (desktop), spi_desktop_signals[APPLICATION_REMOVED], 0, idx);
     }
 }