~unity-team/unity/trunk

« back to all changes in this revision

Viewing changes to services/panel-a11y.c

  • 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:
17
17
 */
18
18
 
19
19
#include <gio/gio.h>
 
20
#include <atk-bridge.h>
20
21
 
21
22
#include "panel-a11y.h"
22
23
#include "panel-util-accessible.h"
23
24
 
24
25
static gboolean a11y_initialized = FALSE;
25
26
 
26
 
#define INIT_METHOD "gnome_accessibility_module_init"
27
 
#define DESKTOP_SCHEMA "org.gnome.desktop.interface"
28
 
#define ACCESSIBILITY_ENABLED_KEY "toolkit-accessibility"
29
 
#define AT_SPI_SCHEMA "org.a11y.atspi"
30
 
#define ATK_BRIDGE_LOCATION_KEY "atk-bridge-location"
31
 
 
32
 
 
33
 
/* This method is required because g_setting_new abort if the schema
34
 
   is not present. */
35
 
static gboolean
36
 
has_gsettings_schema (const gchar *schema)
37
 
{
38
 
  const char * const *list_schemas = NULL;
39
 
  gboolean found = FALSE;
40
 
  int i = 0;
41
 
 
42
 
  list_schemas = g_settings_list_schemas ();
43
 
  for (i = 0; list_schemas [i]; i++)
44
 
    {
45
 
      if (!g_strcmp0 (list_schemas[i], schema))
46
 
        {
47
 
          found = TRUE;
48
 
          break;
49
 
        }
50
 
    }
51
 
 
52
 
  return found;
53
 
}
54
 
 
55
 
static gboolean
56
 
should_enable_a11y (void)
57
 
{
58
 
  GSettings *desktop_settings = NULL;
59
 
  gboolean value = FALSE;
60
 
 
61
 
  if (!has_gsettings_schema (DESKTOP_SCHEMA))
62
 
    return FALSE;
63
 
 
64
 
  desktop_settings = g_settings_new (DESKTOP_SCHEMA);
65
 
  value = g_settings_get_boolean (desktop_settings, ACCESSIBILITY_ENABLED_KEY);
66
 
 
67
 
  g_object_unref (desktop_settings);
68
 
 
69
 
  return value;
70
 
}
71
 
 
72
 
static gchar*
73
 
get_atk_bridge_path (void)
74
 
{
75
 
  GSettings *atspi_settings = NULL;
76
 
  GVariant *variant = NULL;
77
 
  char *value = NULL;
78
 
 
79
 
  if (!has_gsettings_schema (AT_SPI_SCHEMA))
80
 
    return NULL;
81
 
 
82
 
  atspi_settings = g_settings_new(AT_SPI_SCHEMA);
83
 
  variant = g_settings_get_value (atspi_settings, ATK_BRIDGE_LOCATION_KEY);
84
 
  value = g_variant_dup_bytestring (variant, NULL);
85
 
 
86
 
  g_variant_unref (variant);
87
 
  g_object_unref (atspi_settings);
88
 
 
89
 
  return value;
90
 
}
91
 
 
92
 
static gboolean
93
 
a11y_invoke_module (const char *module_path)
94
 
{
95
 
  GModule    *handle;
96
 
  void      (*invoke_fn) (void);
97
 
 
98
 
  if (!module_path)
99
 
    {
100
 
      g_warning ("Accessibility: invalid module path (NULL)");
101
 
 
102
 
      return FALSE;
103
 
    }
104
 
 
105
 
  if (!(handle = g_module_open (module_path, (GModuleFlags)0)))
106
 
    {
107
 
      g_warning ("Accessibility: failed to load module '%s': '%s'",
108
 
                 module_path, g_module_error ());
109
 
 
110
 
      return FALSE;
111
 
    }
112
 
 
113
 
  if (!g_module_symbol (handle, INIT_METHOD, (gpointer *)&invoke_fn))
114
 
    {
115
 
      g_warning ("Accessibility: error library '%s' does not include "
116
 
                 "method '%s' required for accessibility support",
117
 
                 module_path, INIT_METHOD);
118
 
      g_module_close (handle);
119
 
 
120
 
      return FALSE;
121
 
    }
122
 
 
123
 
  invoke_fn ();
124
 
 
125
 
  return TRUE;
126
 
}
127
 
 
128
27
void
129
28
panel_a11y_init (void)
130
29
{
131
 
  gchar *bridge_path = NULL;
132
 
 
133
30
  if (a11y_initialized)
134
31
    return;
135
32
 
137
34
  g_unsetenv ("NO_AT_BRIDGE");
138
35
  g_unsetenv ("NO_GAIL");
139
36
 
140
 
  if (!should_enable_a11y ())
141
 
    return;
142
 
 
143
37
  /* Load PanelUtilAccessible class */
144
38
  g_type_class_unref (g_type_class_ref (PANEL_TYPE_UTIL_ACCESSIBLE));
145
 
 
146
 
  bridge_path = get_atk_bridge_path ();
147
 
  if (a11y_invoke_module (bridge_path))
148
 
    {
149
 
      g_debug ("Unity accessibility started, using bridge on %s", bridge_path);
150
 
    }
151
 
 
152
 
  g_free (bridge_path);
153
 
  atk_get_root ();
 
39
  atk_bridge_adaptor_init(NULL, NULL);
154
40
 
155
41
  a11y_initialized = TRUE;
156
42
}