-desktop_class_init (DesktopClass *klass)
-{
- AccessibleClass * accessible_class = (AccessibleClass *) klass;
- POA_Accessibility_Accessible__epv *epv = &accessible_class->epv;
-
- parent_class = g_type_class_ref (ACCESSIBLE_TYPE);
-
- epv->_get_childCount = impl_desktop_get_child_count;
- epv->getChildAtIndex = impl_desktop_get_child_at_index;
-}
-
-GType
-desktop_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo tinfo = {
- sizeof (DesktopClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) desktop_class_init,
- (GClassFinalizeFunc) NULL,
- NULL, /* class data */
- sizeof (Desktop),
- 0, /* n preallocs */
- (GInstanceInitFunc) desktop_init,
- NULL /* value table */
- };
- /*
- * Here we use bonobo_type_unique instead of
- * gtk_type_unique, this auto-generates a load of
- * CORBA structures for us. All derived types must
- * use bonobo_type_unique.
- */
- type = bonobo_type_unique (
- PARENT_TYPE,
- POA_Accessibility_Desktop__init,
- NULL,
- G_STRUCT_OFFSET (DesktopClass, epv),
- &tinfo,
- "Desktop");
- }
-
- return type;
-}
-
-Desktop *
-desktop_new (void)
-{
- Desktop *retval =
- DESKTOP (g_object_new (desktop_get_type (), NULL));
- return retval;
+spi_desktop_class_init (SpiDesktopClass *klass)
+{
+ GObjectClass * object_class = (GObjectClass *) klass;
+
+ object_class->dispose = spi_desktop_dispose;
+
+ parent_class = g_type_class_ref (G_TYPE_OBJECT);
+
+ 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);
+ g_atexit (spi_desktop_exiting);
+}
+
+SpiDesktop *
+spi_desktop_new (void)
+{
+ return g_object_new (SPI_DESKTOP_TYPE, NULL);
+}
+
+static void
+abnormal_application_termination (gpointer object, SpiDesktopApplication *app)
+{
+ g_return_if_fail (SPI_IS_DESKTOP (app->desktop));
+
+ if (!exiting)
+ spi_desktop_remove_application (app->desktop, app->bus_name);
+}
+
+void
+spi_desktop_add_application (SpiDesktop *desktop,
+ const char *application)
+{
+ SpiDesktopApplication *app;
+
+ g_return_if_fail (SPI_IS_DESKTOP (desktop));
+
+ app = g_new (SpiDesktopApplication, 1);
+ app->desktop = desktop;
+ app->bus_name = g_strdup (application);
+
+ desktop->applications = g_list_append (desktop->applications, app);
+
+ // TODO: Listen for termination, and call abnormal_application_termination
+
+ g_signal_emit (G_OBJECT (desktop),
+ spi_desktop_signals[APPLICATION_ADDED], 0,
+ g_list_index (desktop->applications, app));
+}
+
+void
+spi_desktop_remove_application (SpiDesktop *desktop,
+ const char *bus_name)
+{
+ guint idx;
+ GList *l;
+ SpiDesktopApplication *app;
+
+ g_return_if_fail ( bus_name != NULL);
+ g_return_if_fail (SPI_IS_DESKTOP (desktop));
+
+ idx = 0;
+ for (l = desktop->applications; l; l = l->next)
+ {
+ app = (SpiDesktopApplication *) l->data;
+
+ if (!strcmp(app->bus_name, bus_name))
+ {
+ break;
+ }
+ idx++;
+ }
+
+ if (!l) return;
+
+ g_signal_emit (G_OBJECT (desktop), spi_desktop_signals[APPLICATION_REMOVED], 0, idx);
+
+ desktop->applications = g_list_delete_link (desktop->applications, l);
+
+ g_free (app->bus_name);
+ g_free (app);