Fixed ugly little regression introduced by 'failsafe' fix
[platform/core/uifw/at-spi2-atk.git] / registryd / desktop.c
index 9258398..929a25e 100644 (file)
 #include <config.h>
 #include <stdio.h>
 #include <libbonobo.h>
-#include <libspi/desktop.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
@@ -41,11 +50,12 @@ static SpiAccessibleClass *parent_class;
 static void
 spi_desktop_init (SpiDesktop *desktop)
 {
-  spi_base_construct_default (SPI_BASE (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 (SPI_BASE (desktop)->atko, "main");
+  atk_object_set_name (ATK_OBJECT (SPI_BASE (desktop)->gobj), "main");
 }
 
 static void
@@ -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);
     }
 
@@ -94,9 +105,6 @@ impl_desktop_get_child_at_index (PortableServer_Servant servant,
       retval = bonobo_object_dup_ref (app->ref, ev);
       if (BONOBO_EX (ev))
         {
-          CORBA_exception_free (ev);
-         CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
-                              ex_Accessibility_ChildGone, NULL);
          retval = CORBA_OBJECT_NIL;
        }
     }
@@ -119,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;
 }
@@ -168,7 +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);
+      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);
@@ -178,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;
@@ -193,6 +227,7 @@ spi_desktop_remove_application (SpiDesktop *desktop,
         {
          break;
        }
+      idx++;
     }
 
   CORBA_exception_free (&ev);
@@ -206,5 +241,7 @@ spi_desktop_remove_application (SpiDesktop *desktop,
       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);
     }
 }