Don't translate g_warning messages
[platform/upstream/at-spi2-core.git] / atspi / atspi-accessible.c
index aa31965..dfeed59 100644 (file)
@@ -4,6 +4,7 @@
  *
  * Copyright 2001, 2002 Sun Microsystems Inc.,
  * Copyright 2001, 2002 Ximian, Inc.
+ * Copyright 2010, 2011 Novell, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -44,6 +45,7 @@ atspi_document_interface_init (AtspiDocument *document)
 {
 }
 
+static void
 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
 {
 }
@@ -108,7 +110,6 @@ static void
 atspi_accessible_dispose (GObject *object)
 {
   AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
-  gboolean cached;
   AtspiEvent e;
   AtspiAccessible *parent;
 
@@ -311,7 +312,7 @@ atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
     if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
                                    "s", &obj->name))
       return g_strdup ("");
-    obj->cached_properties |= ATSPI_CACHE_NAME;
+    _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
   }
   return g_strdup (obj->name);
 }
@@ -336,7 +337,7 @@ atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
                                    "Description", error, "s",
                                    &obj->description))
       return g_strdup ("");
-    obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
+    _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
   }
   return g_strdup (obj->description);
 }
@@ -359,7 +360,7 @@ atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
 {
   g_return_val_if_fail (obj != NULL, NULL);
 
-  if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
+  if (obj->parent.app && !(obj->cached_properties & ATSPI_CACHE_PARENT))
   {
     DBusMessage *message, *reply;
     DBusMessageIter iter, iter_variant;
@@ -371,15 +372,19 @@ atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
     dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
                                DBUS_TYPE_STRING, &str_parent,
                               DBUS_TYPE_INVALID);
-    reply = _atspi_dbus_send_with_reply_and_block (message);
-    if (!reply ||
-       (strcmp (dbus_message_get_signature (reply), "v") != 0))
+    reply = _atspi_dbus_send_with_reply_and_block (message, error);
+    if (!reply)
+      return NULL;
+    if (strcmp (dbus_message_get_signature (reply), "v") != 0)
+    {
+      dbus_message_unref (reply);
       return NULL;
+    }
     dbus_message_iter_init (reply, &iter);
     dbus_message_iter_recurse (&iter, &iter_variant);
     obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
     dbus_message_unref (reply);
-    obj->cached_properties |= ATSPI_CACHE_PARENT;
+    _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
   }
   if (!obj->accessible_parent)
     return NULL;
@@ -526,6 +531,7 @@ atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
       ret = new_array;
     dbus_message_iter_next (&iter_array);
   }
+  dbus_message_unref (reply);
   return ret;
 }
 
@@ -548,10 +554,10 @@ atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
   {
     dbus_uint32_t role;
     /* TODO: Make this a property */
-    if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
+    if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
     {
-      obj->cached_properties |= ATSPI_CACHE_ROLE;
       obj->role = role;
+    _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
     }
   }
   return obj->role;
@@ -643,6 +649,7 @@ atspi_accessible_get_state_set (AtspiAccessible *obj)
     dbus_message_iter_init (reply, &iter);
     _atspi_dbus_set_state (obj, &iter);
     dbus_message_unref (reply);
+    _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
   }
 
   return g_object_ref (obj->states);
@@ -712,6 +719,21 @@ atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
   for (;;)
   {
     parent = atspi_accessible_get_parent (obj, NULL);
+    if (!parent && obj->parent.app &&
+        atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
+    {
+      AtspiAccessible *root = g_object_ref (obj->parent.app->root);
+      if (root)
+      {
+        g_object_unref (obj);
+        if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
+        {
+          g_object_unref (root);
+          return NULL;
+        }
+        return root;
+      }
+    }
     if (!parent || parent == obj ||
         atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
     return obj;
@@ -765,8 +787,60 @@ atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
       return NULL;
   return g_strdup (ret);
 }
+/**
+ * atspi_accessible_get_toolkit_version:
+ * @obj: a pointer to the #AtspiAccessible object on which to operate.
+ *
+ * Get the application id for a #AtspiAccessible object.
+ * Only works on application root objects.
+ *
+ * Returns: a gint indicating the id for the #AtspiAccessible object.
+ * or -1 on exception
+ **/
+gint
+atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
+{
+  gint ret = -1;
+
+  g_return_val_if_fail (obj != NULL, -1);
+
+  if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
+      return -1;
+  return ret;
+}
+
+
 /* Interface query methods */
 
+static gboolean
+_atspi_accessible_is_a (AtspiAccessible *accessible,
+                     const char *interface_name)
+{
+  int n;
+
+  if (accessible == NULL)
+    {
+      return FALSE;
+    }
+
+  if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
+  {
+    DBusMessage *reply;
+    DBusMessageIter iter;
+    reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
+                                      "GetInterfaces", NULL, "");
+    _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
+    dbus_message_iter_init (reply, &iter);
+    _atspi_dbus_set_interfaces (accessible, &iter);
+    dbus_message_unref (reply);
+    _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
+  }
+
+  n = _atspi_get_iface_num (interface_name);
+  if (n == -1) return FALSE;
+  return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
+}
+
 /**
  * atspi_accessible_is_action:
  * @obj: a pointer to the #AtspiAccessible instance to query.
@@ -878,6 +952,22 @@ atspi_accessible_is_hypertext (AtspiAccessible *obj)
 }
 
 /**
+ * atspi_accessible_is_hyperlink:
+ * @obj: a pointer to the #AtspiAccessible instance to query.
+ *
+ * Query whether the specified #AtspiAccessible implements #AtspiHyperlink.
+ *
+ * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
+ *          #FALSE otherwise.
+ **/
+gboolean
+atspi_accessible_is_hyperlink (AtspiAccessible *obj)
+{
+  return _atspi_accessible_is_a (obj,
+                             atspi_interface_hyperlink);
+}
+
+/**
  * atspi_accessible_is_image:
  * @obj: a pointer to the #AtspiAccessible instance to query.
  *
@@ -942,7 +1032,7 @@ atspi_accessible_is_streamable_content (AtspiAccessible *obj)
   return _atspi_accessible_is_a (obj,
                              atspi_interface_streamable_content);
 #else
-  g_warning (_("Streamable content not implemented"));
+  g_warning ("Streamable content not implemented");
   return FALSE;
 #endif
 }
@@ -1190,34 +1280,6 @@ atspi_accessible_get_value (AtspiAccessible *accessible)
           g_object_ref (ATSPI_VALUE (accessible)) : NULL);  
 }
 
-gboolean
-_atspi_accessible_is_a (AtspiAccessible *accessible,
-                     const char *interface_name)
-{
-  int n;
-
-  if (accessible == NULL)
-    {
-      return FALSE;
-    }
-
-  if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
-  {
-    DBusMessage *reply;
-    DBusMessageIter iter;
-    reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
-                                      "GetInterfaces", NULL, "");
-    _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
-    dbus_message_iter_init (reply, &iter);
-    _atspi_dbus_set_interfaces (accessible, &iter);
-    dbus_message_unref (reply);
-  }
-
-  n = _atspi_get_iface_num (interface_name);
-  if (n == -1) return FALSE;
-  return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
-}
-
 static void
 append_const_val (GArray *array, const gchar *val)
 {
@@ -1246,6 +1308,7 @@ atspi_accessible_get_interfaces (AtspiAccessible *obj)
 
   g_return_val_if_fail (obj != NULL, NULL);
 
+  append_const_val (ret, "Accessible");
   if (atspi_accessible_is_action (obj))
     append_const_val (ret, "Action");
   if (atspi_accessible_is_collection (obj))
@@ -1258,6 +1321,8 @@ atspi_accessible_get_interfaces (AtspiAccessible *obj)
     append_const_val (ret, "EditableText");
   if (atspi_accessible_is_hypertext (obj))
     append_const_val (ret, "Hypertext");
+  if (atspi_accessible_is_hyperlink (obj))
+    append_const_val (ret, "Hyperlink");
   if (atspi_accessible_is_image (obj))
     append_const_val (ret, "Image");
   if (atspi_accessible_is_selection (obj))
@@ -1285,3 +1350,49 @@ atspi_accessible_new (AtspiApplication *app, const gchar *path)
 
   return accessible;
 }
+
+/**
+ * atspi_accessible_set_cache_mask:
+ *
+ * @accessible: The #AtspiAccessible to operate on.  Must be the desktop or
+ *             the root of an application.
+ * @mask: An #AtspiCache specifying a bit mask of the types of data to cache.
+ *
+ * Sets the type of data to cache for accessibles.
+ * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
+ * then the desktop's cache flag will be used.
+ * If the desktop's cache flag is also undefined, then all possible data will
+ * be cached.
+ * This function is intended to work around bugs in toolkits where the proper
+ * events are not raised / to aid in testing for such bugs.
+ *
+ * Note: This function has no effect on data that has already been cached.
+ **/
+void
+atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
+{
+  g_return_if_fail (accessible != NULL);
+  g_return_if_fail (accessible->parent.app != NULL);
+  g_return_if_fail (accessible == accessible->parent.app->root);
+  accessible->parent.app->cache = mask;
+}
+
+void
+_atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
+{
+  AtspiCache mask = accessible->parent.app->cache;
+
+  if (mask == ATSPI_CACHE_UNDEFINED &&
+      accessible->parent.app->root &&
+      accessible->parent.app->root->accessible_parent)
+  {
+    AtspiAccessible *desktop = atspi_get_desktop (0);
+    mask = desktop->parent.app->cache;
+    g_object_unref (desktop);
+  }
+
+  if (mask == ATSPI_CACHE_UNDEFINED)
+    mask = ATSPI_CACHE_ALL;
+
+  accessible->cached_properties |= flag & mask;
+}