~unity-team/unity/trunk

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/unitya11y.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-09-13 10:56:42 UTC
  • mfrom: (2684 unity)
  • mto: This revision was merged to the branch mainline in revision 2698.
  • Revision ID: daniel.van.vugt@canonical.com-20120913105642-9on2ald55h54j1zn
Merge latest lp:unity and fix conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <gio/gio.h>
21
21
#include <gmodule.h>
22
22
#include <stdio.h>
 
23
#include <atk-bridge.h>
23
24
 
24
25
#include "unitya11y.h"
25
26
#include "unitya11ytests.h"
62
63
 
63
64
static gboolean a11y_initialized = FALSE;
64
65
 
65
 
#define INIT_METHOD "gnome_accessibility_module_init"
66
 
#define DESKTOP_SCHEMA "org.gnome.desktop.interface"
67
 
#define ACCESSIBILITY_ENABLED_KEY "toolkit-accessibility"
68
 
#define AT_SPI_SCHEMA "org.a11y.atspi"
69
 
#define ATK_BRIDGE_LOCATION_KEY "atk-bridge-location"
70
 
 
71
66
static void
72
67
unity_a11y_restore_environment(void)
73
68
{
82
77
  g_type_class_unref(g_type_class_ref(UNITY_TYPE_UTIL_ACCESSIBLE));
83
78
}
84
79
 
85
 
/* This method is required because g_setting_new aborts if the schema
86
 
   is not present. */
87
 
static gboolean
88
 
has_gsettings_schema(const gchar* schema)
89
 
{
90
 
  const char* const* list_schemas = NULL;
91
 
  gboolean found = FALSE;
92
 
  int i = 0;
93
 
 
94
 
  list_schemas = g_settings_list_schemas();
95
 
  for (i = 0; list_schemas [i]; i++)
96
 
  {
97
 
    if (!g_strcmp0(list_schemas[i], schema))
98
 
    {
99
 
      found = TRUE;
100
 
      break;
101
 
    }
102
 
  }
103
 
 
104
 
  return found;
105
 
}
106
 
 
107
 
static gboolean
108
 
should_enable_a11y(void)
109
 
{
110
 
  GSettings* desktop_settings = NULL;
111
 
  gboolean value = FALSE;
112
 
 
113
 
  if (!has_gsettings_schema(DESKTOP_SCHEMA))
114
 
    return FALSE;
115
 
 
116
 
  desktop_settings = g_settings_new(DESKTOP_SCHEMA);
117
 
  value = g_settings_get_boolean(desktop_settings, ACCESSIBILITY_ENABLED_KEY);
118
 
 
119
 
  g_object_unref(desktop_settings);
120
 
 
121
 
  return value;
122
 
}
123
 
 
124
 
static gchar*
125
 
get_atk_bridge_path(void)
126
 
{
127
 
  GSettings* atspi_settings = NULL;
128
 
  GVariant *variant = NULL;
129
 
  char* value = NULL;
130
 
 
131
 
  if (!has_gsettings_schema(AT_SPI_SCHEMA))
132
 
    return NULL;
133
 
 
134
 
  atspi_settings = g_settings_new(AT_SPI_SCHEMA);
135
 
  variant = g_settings_get_value (atspi_settings, ATK_BRIDGE_LOCATION_KEY);
136
 
  value = g_variant_dup_bytestring (variant, NULL);
137
 
 
138
 
  g_variant_unref (variant);
139
 
  g_object_unref(atspi_settings);
140
 
 
141
 
  return value;
142
 
}
143
 
 
144
 
static gboolean
145
 
a11y_invoke_module(const char* module_path)
146
 
{
147
 
  GModule*    handle;
148
 
  void (*invoke_fn)(void);
149
 
 
150
 
  if (!module_path)
151
 
  {
152
 
    g_warning("Accessibility: invalid module path (NULL)");
153
 
 
154
 
    return FALSE;
155
 
  }
156
 
 
157
 
  if (!(handle = g_module_open(module_path, (GModuleFlags)0)))
158
 
  {
159
 
    g_warning("Accessibility: failed to load module '%s': '%s'",
160
 
              module_path, g_module_error());
161
 
 
162
 
    return FALSE;
163
 
  }
164
 
 
165
 
  if (!g_module_symbol(handle, INIT_METHOD, (gpointer*)&invoke_fn))
166
 
  {
167
 
    g_warning("Accessibility: error library '%s' does not include "
168
 
              "method '%s' required for accessibility support",
169
 
              module_path, INIT_METHOD);
170
 
    g_module_close(handle);
171
 
 
172
 
    return FALSE;
173
 
  }
174
 
 
175
 
  invoke_fn();
176
 
 
177
 
  return TRUE;
178
 
}
179
 
 
180
 
/********************************************************************************/
181
80
/*
182
81
 * In order to avoid the atk-bridge loading and the GAIL
183
82
 * initialization during the gtk_init, it is required to set some
194
93
/*
195
94
 * Initializes the accessibility (ATK) support on Unity
196
95
 *
197
 
 * It loads the atk-bridge if required. It checks:
198
 
 *  * If the proper gsettings keys are set
199
 
 *  * Loads the proper AtkUtil implementation
200
96
 */
201
97
void
202
98
unity_a11y_init(nux::WindowThread* wt)
203
99
{
204
 
  gchar* bridge_path = NULL;
 
100
  if (a11y_initialized)
 
101
    return;
205
102
 
206
103
  unity_a11y_restore_environment();
207
 
 
208
 
  if (!should_enable_a11y())
209
 
    return;
210
 
 
211
104
  load_unity_atk_util(wt);
212
 
 
213
 
  bridge_path = get_atk_bridge_path();
214
 
 
215
 
  if (a11y_invoke_module(bridge_path))
216
 
  {
217
 
    g_debug("Unity Oneiric accessibility started, using bridge on %s",
218
 
            bridge_path);
219
 
 
220
 
    atk_get_root();
221
 
 
222
 
    a11y_initialized = TRUE;
223
 
  }
224
 
 
225
 
  g_free(bridge_path);
 
105
  atk_bridge_adaptor_init(NULL, NULL);
 
106
  atk_get_root();
 
107
 
 
108
  a11y_initialized = TRUE;
226
109
 
227
110
// NOTE: we run the unit tests manually while developing by
228
111
// uncommenting this. Take a look at the explanation in the