| 1 |
/* CALLY - The Clutter Accessibility Implementation Library |
| 2 |
* |
| 3 |
* Copyright (C) 2009 Igalia, S.L. |
| 4 |
* |
| 5 |
* Author: Alejandro Piñeiro Iglesias <[email protected]> |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the |
| 19 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 |
* Boston, MA 02111-1307, USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#include <gmodule.h> |
| 25 |
#include <stdlib.h> |
| 26 |
|
| 27 |
#include <clutter/clutter.h> |
| 28 |
|
| 29 |
#include "cally-examples-util.h" |
| 30 |
|
| 31 |
/* Checking the at-spi sources, the module directory is |
| 32 |
* $(libdir)/gtk-2.0/modules |
| 33 |
* |
| 34 |
* It is supposed cally would be installed on the same libdir. |
| 35 |
* |
| 36 |
* You could use the option atk-bridge-dir to use other directory. |
| 37 |
*/ |
| 38 |
#define ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY PREFIXDIR"/gtk-2.0/modules" |
| 39 |
|
| 40 |
static gchar * |
| 41 |
_search_for_bridge_module (const gchar *module_name) |
| 42 |
{ |
| 43 |
/* We simplify the search for the atk bridge, see see the definition |
| 44 |
* of the macro for more information*/ |
| 45 |
return g_strdup (ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY); |
| 46 |
} |
| 47 |
|
| 48 |
static gchar* |
| 49 |
_a11y_check_custom_bridge (int *argc, |
| 50 |
char ***argv) |
| 51 |
{ |
| 52 |
GError *error = NULL; |
| 53 |
GOptionContext *context; |
| 54 |
static gchar *bridge_dir = NULL; |
| 55 |
static GOptionEntry entries [] = |
| 56 |
{ |
| 57 |
{"atk-bridge-dir", 'd', 0, G_OPTION_ARG_STRING, &bridge_dir, "atk-bridge module directory", NULL} |
| 58 |
}; |
| 59 |
|
| 60 |
context = g_option_context_new ("- cally examples"); |
| 61 |
g_option_context_add_main_entries (context, entries, NULL); |
| 62 |
if (!g_option_context_parse (context, argc, argv, &error)) |
| 63 |
{ |
| 64 |
g_print ("%s\n", error->message); |
| 65 |
g_print ("Use --help for more information.\n"); |
| 66 |
exit (0); |
| 67 |
} |
| 68 |
|
| 69 |
return bridge_dir; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
static gboolean |
| 74 |
_a11y_invoke_module (const gchar *module_path, |
| 75 |
gboolean init) |
| 76 |
{ |
| 77 |
GModule *handle; |
| 78 |
void (*invoke_fn) (void); |
| 79 |
const char *method; |
| 80 |
|
| 81 |
if (init) |
| 82 |
method = "gnome_accessibility_module_init"; |
| 83 |
else |
| 84 |
method = "gnome_accessibility_module_shutdown"; |
| 85 |
|
| 86 |
if (!module_path) |
| 87 |
return FALSE; |
| 88 |
|
| 89 |
if (!(handle = g_module_open (module_path, G_MODULE_BIND_LAZY))) |
| 90 |
{ |
| 91 |
g_warning ("Accessibility: failed to load module '%s': '%s'", |
| 92 |
module_path, g_module_error ()); |
| 93 |
|
| 94 |
return FALSE; |
| 95 |
} |
| 96 |
|
| 97 |
if (!g_module_symbol (handle, method, (gpointer *)&invoke_fn)) |
| 98 |
{ |
| 99 |
g_warning ("Accessibility: error library '%s' does not include " |
| 100 |
"method '%s' required for accessibility support", |
| 101 |
module_path, method); |
| 102 |
g_module_close (handle); |
| 103 |
|
| 104 |
return FALSE; |
| 105 |
} |
| 106 |
|
| 107 |
g_debug ("Module %s loaded successfully", module_path); |
| 108 |
invoke_fn (); |
| 109 |
|
| 110 |
return TRUE; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* This method will initialize the accessibility support provided by cally. |
| 115 |
* |
| 116 |
* Basically it will load the cally module using gmodule functions. |
| 117 |
* |
| 118 |
* Returns if it was able to init the a11y support or not. |
| 119 |
*/ |
| 120 |
gboolean |
| 121 |
cally_util_a11y_init (int *argc, char ***argv) |
| 122 |
{ |
| 123 |
gchar *bridge_dir = NULL; |
| 124 |
gchar *bridge_path = NULL; |
| 125 |
gboolean result = FALSE; |
| 126 |
|
| 127 |
if (clutter_get_accessibility_enabled () == FALSE) |
| 128 |
{ |
| 129 |
g_warning ("Accessibility: clutter has no accessibility enabled" |
| 130 |
" skipping the atk-bridge load"); |
| 131 |
return FALSE; |
| 132 |
} |
| 133 |
|
| 134 |
bridge_dir = _a11y_check_custom_bridge (argc, argv); |
| 135 |
if (bridge_dir == NULL) |
| 136 |
bridge_dir = _search_for_bridge_module ("atk-bridge"); |
| 137 |
|
| 138 |
bridge_path = g_module_build_path (bridge_dir, "libatk-bridge"); |
| 139 |
|
| 140 |
result = _a11y_invoke_module (bridge_path, TRUE); |
| 141 |
|
| 142 |
g_free (bridge_dir); |
| 143 |
g_free (bridge_path); |
| 144 |
|
| 145 |
return result; |
| 146 |
} |