2008-05-16 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / hyperlink.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include "accessible.h"
26
27 static AtkHyperlink *
28 get_hyperlink (DBusMessage * message)
29 {
30   AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
31   if (!obj)
32     return NULL;
33   return ATK_HYPERLINK (obj);
34 }
35
36 static AtkHyperlink *
37 get_hyperlink_from_path (const char *path, void *user_data)
38 {
39   AtkObject *obj = spi_dbus_get_object (path);
40   if (!obj || !ATK_IS_HYPERLINK(obj))
41     return NULL;
42   return ATK_HYPERLINK (obj);
43 }
44
45 static dbus_bool_t
46 impl_get_nAnchors (const char *path, DBusMessageIter * iter, void *user_data)
47 {
48   AtkHyperlink *link = get_hyperlink_from_path (path, user_data);
49   if (!link)
50     return FALSE;
51   return droute_return_v_int32 (iter, atk_hyperlink_get_n_anchors (link));
52 }
53
54
55 static dbus_bool_t
56 impl_get_startIndex (const char *path, DBusMessageIter * iter,
57                      void *user_data)
58 {
59   AtkHyperlink *link = get_hyperlink_from_path (path, user_data);
60   if (!link)
61     return FALSE;
62   return droute_return_v_int32 (iter, atk_hyperlink_get_start_index (link));
63 }
64
65 static dbus_bool_t
66 impl_get_endIndex (const char *path, DBusMessageIter * iter, void *user_data)
67 {
68   AtkHyperlink *link = get_hyperlink_from_path (path, user_data);
69   if (!link)
70     return FALSE;
71   return droute_return_v_int32 (iter, atk_hyperlink_get_end_index (link));
72 }
73
74 static DBusMessage *
75 impl_getObject (DBusConnection * bus, DBusMessage * message, void *user_data)
76 {
77   AtkHyperlink *link = get_hyperlink (message);
78   DBusError error;
79   dbus_int32_t i;
80   AtkObject *atk_object;
81
82   if (!link)
83     return spi_dbus_general_error (message);
84   dbus_error_init (&error);
85   if (!dbus_message_get_args
86       (message, &error, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID))
87     {
88       return SPI_DBUS_RETURN_ERROR (message, &error);
89     }
90   atk_object = atk_hyperlink_get_object (link, i);
91   return spi_dbus_return_object (message, atk_object, FALSE);
92 }
93
94 static DBusMessage *
95 impl_getURI (DBusConnection * bus, DBusMessage * message, void *user_data)
96 {
97   AtkHyperlink *link = get_hyperlink (message);
98   dbus_int32_t i;
99   DBusError error;
100   gchar *rv;
101   DBusMessage *reply;
102
103   if (!link)
104     return spi_dbus_general_error (message);
105   dbus_error_init (&error);
106   if (!dbus_message_get_args
107       (message, &error, DBUS_TYPE_INT32, &i, DBUS_TYPE_INT32, &i,
108        DBUS_TYPE_INVALID))
109     {
110       return SPI_DBUS_RETURN_ERROR (message, &error);
111     }
112
113   rv = atk_hyperlink_get_uri (link, i);
114   if (!rv)
115     rv = g_strdup ("");
116   reply = dbus_message_new_method_return (message);
117   if (reply)
118     {
119       dbus_message_append_args (reply, DBUS_TYPE_STRING, &rv,
120                                 DBUS_TYPE_INVALID);
121     }
122   g_free (rv);
123   return reply;
124 }
125
126 static DBusMessage *
127 impl_isValid (DBusConnection * bus, DBusMessage * message, void *user_data)
128 {
129   AtkHyperlink *link = get_hyperlink (message);
130   dbus_bool_t rv;
131   DBusMessage *reply;
132
133   if (!link)
134     return spi_dbus_general_error (message);
135
136   rv = atk_hyperlink_is_valid (link);
137   reply = dbus_message_new_method_return (message);
138   if (reply)
139     {
140       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
141                                 DBUS_TYPE_INVALID);
142     }
143   return reply;
144 }
145
146 static DRouteMethod methods[] = {
147   {impl_getObject, "getObject"},
148   {impl_getURI, "getURI"},
149   {impl_isValid, "isValid"},
150   {NULL, NULL}
151 };
152
153 static DRouteProperty properties[] = {
154   {impl_get_nAnchors, NULL, "nAnchors"},
155   {impl_get_startIndex, NULL, "startIndex"},
156   {impl_get_endIndex, NULL, "endIndex"},
157   {NULL, NULL, NULL}
158 };
159
160 void
161 spi_initialize_hyperlink (DRouteData * data)
162 {
163   droute_add_interface (data, "org.freedesktop.atspi.Hyperlink",
164                         methods, properties,
165                         (DRouteGetDatumFunction) get_hyperlink_from_path,
166                         NULL);
167 };