1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
3
* Copyright (C) 2010 Intel, Inc
4
* Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* Authors: Thomas Wood <thomas.wood@intel.com>
21
* Rodrigo Moya <rodrigo@gnome.org>
28
#include <glib/gi18n-lib.h>
29
#include <gdesktop-enums.h>
30
#include "cc-ua-panel.h"
32
#include "zoom-options.h"
34
#define WID(b, w) (GtkWidget *) gtk_builder_get_object (b, w)
36
#define DPI_FACTOR_LARGE 1.25
37
#define DPI_FACTOR_NORMAL 1.0
39
#define HIGH_CONTRAST_THEME "HighContrast"
40
#define KEY_TEXT_SCALING_FACTOR "text-scaling-factor"
41
#define KEY_GTK_THEME "gtk-theme"
42
#define KEY_ICON_THEME "icon-theme"
43
#define KEY_WM_THEME "theme"
45
CC_PANEL_REGISTER (CcUaPanel, cc_ua_panel)
47
#define UA_PANEL_PRIVATE(o) \
48
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_UA_PANEL, CcUaPanelPrivate))
50
struct _CcUaPanelPrivate
53
GSettings *wm_settings;
54
GSettings *interface_settings;
55
GSettings *kb_settings;
56
GSettings *mouse_settings;
57
GSettings *application_settings;
58
GSettings *mediakeys_settings;
60
ZoomOptions *zoom_options;
66
cc_ua_panel_get_property (GObject *object,
74
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
79
cc_ua_panel_set_property (GObject *object,
87
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
92
cc_ua_panel_dispose (GObject *object)
94
CcUaPanelPrivate *priv = CC_UA_PANEL (object)->priv;
96
if (priv->shell_watch_id)
98
g_bus_unwatch_name (priv->shell_watch_id);
99
priv->shell_watch_id = 0;
104
g_object_unref (priv->builder);
105
priv->builder = NULL;
108
if (priv->wm_settings)
110
g_object_unref (priv->wm_settings);
111
priv->wm_settings = NULL;
114
if (priv->interface_settings)
116
g_object_unref (priv->interface_settings);
117
priv->interface_settings = NULL;
120
if (priv->kb_settings)
122
g_object_unref (priv->kb_settings);
123
priv->kb_settings = NULL;
126
if (priv->mouse_settings)
128
g_object_unref (priv->mouse_settings);
129
priv->mouse_settings = NULL;
132
if (priv->application_settings)
134
g_object_unref (priv->application_settings);
135
priv->application_settings = NULL;
138
if (priv->mediakeys_settings)
140
g_object_unref (priv->mediakeys_settings);
141
priv->mediakeys_settings = NULL;
144
if (priv->zoom_options)
146
g_object_unref (priv->zoom_options);
147
priv->zoom_options = NULL;
150
G_OBJECT_CLASS (cc_ua_panel_parent_class)->dispose (object);
154
cc_ua_panel_finalize (GObject *object)
156
G_OBJECT_CLASS (cc_ua_panel_parent_class)->finalize (object);
160
cc_ua_panel_get_help_uri (CcPanel *panel)
162
if (!g_strcmp0(g_getenv("XDG_CURRENT_DESKTOP"), "Unity"))
163
return "help:ubuntu-help/a11y";
165
return "help:gnome-help/a11y";
169
cc_ua_panel_class_init (CcUaPanelClass *klass)
171
GObjectClass *object_class = G_OBJECT_CLASS (klass);
172
CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
174
g_type_class_add_private (klass, sizeof (CcUaPanelPrivate));
176
panel_class->get_help_uri = cc_ua_panel_get_help_uri;
178
object_class->get_property = cc_ua_panel_get_property;
179
object_class->set_property = cc_ua_panel_set_property;
180
object_class->dispose = cc_ua_panel_dispose;
181
object_class->finalize = cc_ua_panel_finalize;
184
static gchar *sticky_keys_section[] = {
185
"typing_sticky_keys_disable_two_keys_checkbutton",
186
"typing_sticky_keys_beep_modifier_checkbutton",
190
static gchar *slow_keys_section[]= {
191
"typing_slowkeys_delay_box",
192
"typing_slow_keys_beeb_box",
196
static gchar *bounce_keys_section[] = {
197
"typing_bouncekeys_delay_box",
198
"typing_bounce_keys_beep_rejected_checkbutton",
202
static gchar *secondary_click_section[] = {
203
"pointing_secondary_click_scale_box",
207
static gchar *dwell_click_section[] = {
208
"pointing_hover_click_delay_scale_box",
209
"pointing_hover_click_threshold_scale_box",
213
static gchar *visual_alerts_section[] = {
214
"hearing_test_flash_button",
215
"hearing_flash_window_title_button",
216
"hearing_flash_screen_button",
220
/* zoom options dialog */
222
zoom_options_launch_cb (GtkWidget *options_button, CcUaPanel *self)
224
if (self->priv->zoom_options == NULL)
225
self->priv->zoom_options = zoom_options_new ();
227
if (self->priv->zoom_options != NULL)
228
zoom_options_set_parent (self->priv->zoom_options,
229
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
233
cc_ua_panel_section_switched (GObject *object,
239
gchar **widgets, **s;
241
widgets = g_object_get_data (object, "section-widgets");
243
g_object_get (object, "active", &enabled, NULL);
245
for (s = widgets; *s; s++)
247
w = WID (builder, *s);
248
gtk_widget_set_sensitive (w, enabled);
253
settings_on_off_editor_new (CcUaPanelPrivate *priv,
259
/* set data to enable/disable the section this on/off switch controls */
262
g_object_set_data (G_OBJECT (widget), "section-widgets", section);
263
g_signal_connect (widget, "notify::active",
264
G_CALLBACK (cc_ua_panel_section_switched),
268
/* set up the boolean editor */
269
g_settings_bind (settings, key, widget, "active", G_SETTINGS_BIND_DEFAULT);
275
cc_ua_panel_set_shortcut_label (CcUaPanel *self,
282
guint accel_key, *keycode;
283
GdkModifierType mods;
285
widget = WID (self->priv->builder, label);
286
value = g_settings_get_string (self->priv->mediakeys_settings, key);
288
if (value == NULL || *value == '\0') {
289
gtk_label_set_text (GTK_LABEL (widget), _("No shortcut set"));
293
gtk_accelerator_parse_with_keycode (value, &accel_key, &keycode, &mods);
294
if (accel_key == 0 && keycode == NULL && mods == 0) {
295
gtk_label_set_text (GTK_LABEL (widget), _("No shortcut set"));
297
g_warning ("Failed to parse keyboard shortcut: '%s'", value);
302
text = gtk_accelerator_get_label_with_keycode (gtk_widget_get_display (widget), accel_key, *keycode, mods);
304
gtk_label_set_text (GTK_LABEL (widget), text);
309
shell_vanished_cb (GDBusConnection *connection,
313
CcUaPanelPrivate *priv = self->priv;
315
gtk_widget_hide (WID (priv->builder, "zoom_label_box"));
316
gtk_widget_hide (WID (priv->builder, "zoom_value_box"));
320
shell_appeared_cb (GDBusConnection *connection,
322
const gchar *name_owner,
325
CcUaPanelPrivate *priv = self->priv;
327
gtk_widget_show (WID (priv->builder, "zoom_label_box"));
328
gtk_widget_show (WID (priv->builder, "zoom_value_box"));
332
get_large_text_mapping (GValue *value,
339
factor = g_variant_get_double (variant);
340
large = factor > DPI_FACTOR_NORMAL;
341
g_value_set_boolean (value, large);
347
set_large_text_mapping (const GValue *value,
348
const GVariantType *expected_type,
352
GSettings *settings = user_data;
353
GVariant *ret = NULL;
355
large = g_value_get_boolean (value);
357
ret = g_variant_new_double (DPI_FACTOR_LARGE);
359
g_settings_reset (settings, KEY_TEXT_SCALING_FACTOR);
365
get_contrast_mapping (GValue *value,
372
theme = g_variant_get_string (variant, NULL);
373
hc = (g_strcmp0 (theme, HIGH_CONTRAST_THEME) == 0);
374
g_value_set_boolean (value, hc);
380
set_contrast_mapping (const GValue *value,
381
const GVariantType *expected_type,
385
CcUaPanel *self = user_data;
386
CcUaPanelPrivate *priv = self->priv;
387
GVariant *ret = NULL;
389
hc = g_value_get_boolean (value);
392
ret = g_variant_new_string (HIGH_CONTRAST_THEME);
393
g_settings_set_string (priv->interface_settings, KEY_ICON_THEME, HIGH_CONTRAST_THEME);
395
g_settings_set_string (priv->wm_settings, KEY_WM_THEME, HIGH_CONTRAST_THEME);
399
g_settings_reset (priv->interface_settings, KEY_GTK_THEME);
400
g_settings_reset (priv->interface_settings, KEY_ICON_THEME);
402
g_settings_reset (priv->wm_settings, KEY_WM_THEME);
409
cc_ua_panel_init_seeing (CcUaPanel *self)
411
CcUaPanelPrivate *priv = self->priv;
413
g_settings_bind_with_mapping (priv->interface_settings, KEY_GTK_THEME,
414
WID (priv->builder, "seeing_contrast_switch"),
415
"active", G_SETTINGS_BIND_DEFAULT,
416
get_contrast_mapping,
417
set_contrast_mapping,
420
g_settings_bind_with_mapping (priv->interface_settings, KEY_TEXT_SCALING_FACTOR,
421
WID (priv->builder, "seeing_large_text_switch"),
422
"active", G_SETTINGS_BIND_DEFAULT,
423
get_large_text_mapping,
424
set_large_text_mapping,
425
priv->interface_settings,
428
g_settings_bind (priv->kb_settings, "togglekeys-enable",
429
WID (priv->builder, "seeing_toggle_keys_switch"), "active",
430
G_SETTINGS_BIND_DEFAULT);
432
if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity"))
434
priv->shell_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
436
G_BUS_NAME_WATCHER_FLAGS_NONE,
437
(GBusNameAppearedCallback) shell_appeared_cb,
438
(GBusNameVanishedCallback) shell_vanished_cb,
443
gtk_widget_hide (WID (priv->builder, "zoom_label_box"));
444
gtk_widget_hide (WID (priv->builder, "zoom_value_box"));
447
g_signal_connect (WID (priv->builder, "seeing_zoom_preferences_button"),
449
G_CALLBACK (zoom_options_launch_cb), self);
450
g_settings_bind (priv->application_settings, "screen-magnifier-enabled",
451
WID (priv->builder, "seeing_zoom_switch"), "active",
452
G_SETTINGS_BIND_DEFAULT);
454
settings_on_off_editor_new (priv, priv->application_settings,
455
"screen-reader-enabled",
456
WID (priv->builder, "seeing_reader_switch"),
459
cc_ua_panel_set_shortcut_label (self, "seeing_zoom_enable_keybinding_label", "magnifier");
460
cc_ua_panel_set_shortcut_label (self, "seeing_zoom_in_keybinding_label", "magnifier-zoom-in");
461
cc_ua_panel_set_shortcut_label (self, "seeing_zoom_out_keybinding_label", "magnifier-zoom-out");
462
cc_ua_panel_set_shortcut_label (self, "seeing_reader_enable_keybinding_label", "screenreader");
466
/* hearing/sound section */
468
visual_bell_type_notify_cb (GSettings *settings,
473
GDesktopVisualBellType type;
475
type = g_settings_get_enum (panel->priv->wm_settings, "visual-bell-type");
477
if (type == G_DESKTOP_VISUAL_BELL_FRAME_FLASH)
478
widget = WID (panel->priv->builder, "hearing_flash_window_title_button");
480
widget = WID (panel->priv->builder, "hearing_flash_screen_button");
482
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
486
visual_bell_type_toggle_cb (GtkWidget *button,
489
gboolean frame_flash;
490
GDesktopVisualBellType type;
492
frame_flash = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
495
type = G_DESKTOP_VISUAL_BELL_FRAME_FLASH;
497
type = G_DESKTOP_VISUAL_BELL_FULLSCREEN_FLASH;
498
g_settings_set_enum (panel->priv->wm_settings, "visual-bell-type", type);
502
hearing_sound_preferences_clicked (GtkButton *button,
507
shell = cc_panel_get_shell (CC_PANEL (panel));
508
cc_shell_set_active_panel_from_id (shell, "sound", NULL, NULL);
514
cc_ua_panel_init_hearing (CcUaPanel *self)
516
CcUaPanelPrivate *priv = self->priv;
519
/* set the initial visual bell values */
520
visual_bell_type_notify_cb (NULL, NULL, self);
523
w = WID (priv->builder, "hearing_visual_alerts_switch");
524
settings_on_off_editor_new (priv, priv->wm_settings, "visual-bell", w, visual_alerts_section);
526
g_signal_connect (priv->wm_settings, "changed::visual-bell-type",
527
G_CALLBACK (visual_bell_type_notify_cb), self);
528
g_signal_connect (WID (priv->builder, "hearing_flash_window_title_button"),
529
"toggled", G_CALLBACK (visual_bell_type_toggle_cb), self);
532
g_signal_connect (WID (priv->builder, "hearing_test_flash_button"),
533
"clicked", G_CALLBACK (gdk_beep), NULL);
535
g_signal_connect (WID (priv->builder, "hearing_sound_preferences_link"),
537
G_CALLBACK (hearing_sound_preferences_clicked), self);
540
/* typing/keyboard section */
543
cc_ua_panel_init_keyboard (CcUaPanel *self)
545
CcUaPanelPrivate *priv = self->priv;
548
/* Typing assistant (on-screen keyboard) */
549
w = WID (priv->builder, "typing_assistant_switch");
550
g_settings_bind (priv->application_settings, "screen-keyboard-enabled",
551
w, "active", G_SETTINGS_BIND_DEFAULT);
553
/* enable shortcuts */
554
w = WID (priv->builder, "typing_keyboard_toggle_switch");
555
g_settings_bind (priv->kb_settings, "enable", w, "active", G_SETTINGS_BIND_DEFAULT);
558
w = WID (priv->builder, "typing_sticky_keys_switch");
559
settings_on_off_editor_new (priv, priv->kb_settings, "stickykeys-enable", w, sticky_keys_section);
561
w = WID (priv->builder, "typing_sticky_keys_disable_two_keys_checkbutton");
562
g_settings_bind (priv->kb_settings, "stickykeys-two-key-off", w, "active", G_SETTINGS_BIND_NO_SENSITIVITY);
564
w = WID (priv->builder, "typing_sticky_keys_beep_modifier_checkbutton");
565
g_settings_bind (priv->kb_settings, "stickykeys-modifier-beep", w, "active", G_SETTINGS_BIND_NO_SENSITIVITY);
568
w = WID (priv->builder, "typing_slow_keys_switch");
569
settings_on_off_editor_new (priv, priv->kb_settings, "slowkeys-enable", w, slow_keys_section);
571
w = WID (priv->builder, "typing_slowkeys_delay_scale");
572
g_settings_bind (priv->kb_settings, "slowkeys-delay",
573
gtk_range_get_adjustment (GTK_RANGE (w)), "value",
574
G_SETTINGS_BIND_DEFAULT);
576
w = WID (priv->builder, "typing_slow_keys_beep_pressed_checkbutton");
577
g_settings_bind (priv->kb_settings, "slowkeys-beep-press", w, "active", G_SETTINGS_BIND_DEFAULT);
579
w = WID (priv->builder, "typing_slow_keys_beep_accepted_checkbutton");
580
g_settings_bind (priv->kb_settings, "slowkeys-beep-accept", w, "active", G_SETTINGS_BIND_DEFAULT);
582
w = WID (priv->builder, "typing_slow_keys_beep_rejected_checkbutton");
583
g_settings_bind (priv->kb_settings, "slowkeys-beep-reject", w, "active", G_SETTINGS_BIND_DEFAULT);
586
w = WID (priv->builder, "typing_bounce_keys_switch");
587
settings_on_off_editor_new (priv, priv->kb_settings, "bouncekeys-enable", w, bounce_keys_section);
589
w = WID (priv->builder, "typing_bouncekeys_delay_scale");
590
g_settings_bind (priv->kb_settings, "bouncekeys-delay",
591
gtk_range_get_adjustment (GTK_RANGE (w)), "value",
592
G_SETTINGS_BIND_DEFAULT);
594
w = WID (priv->builder, "typing_bounce_keys_beep_rejected_checkbutton");
595
g_settings_bind (priv->kb_settings, "bouncekeys-beep-reject", w, "active", G_SETTINGS_BIND_NO_SENSITIVITY);
598
/* mouse/pointing & clicking section */
600
pointing_mouse_preferences_clicked_cb (GtkButton *button,
605
shell = cc_panel_get_shell (CC_PANEL (panel));
606
cc_shell_set_active_panel_from_id (shell, "mouse", NULL, NULL);
612
cc_ua_panel_init_mouse (CcUaPanel *self)
614
CcUaPanelPrivate *priv = self->priv;
618
w = WID (priv->builder, "pointing_mouse_keys_switch");
619
settings_on_off_editor_new (priv, priv->kb_settings, "mousekeys-enable", w, NULL);
621
/* simulated secondary click */
622
w = WID (priv->builder, "pointing_second_click_switch");
623
settings_on_off_editor_new (priv, priv->mouse_settings, "secondary-click-enabled", w, secondary_click_section);
625
w = WID (priv->builder, "pointing_secondary_click_delay_scale");
626
g_settings_bind (priv->mouse_settings, "secondary-click-time",
627
gtk_range_get_adjustment (GTK_RANGE (w)), "value",
628
G_SETTINGS_BIND_DEFAULT);
631
w = WID (priv->builder, "pointing_hover_click_switch");
632
settings_on_off_editor_new (priv, priv->mouse_settings, "dwell-click-enabled", w, dwell_click_section);
634
w = WID (priv->builder, "pointing_dwell_delay_scale");
635
g_settings_bind (priv->mouse_settings, "dwell-time",
636
gtk_range_get_adjustment (GTK_RANGE (w)), "value",
637
G_SETTINGS_BIND_DEFAULT);
639
w = WID (priv->builder, "pointing_dwell_threshold_scale");
640
g_settings_bind (priv->mouse_settings, "dwell-threshold",
641
gtk_range_get_adjustment (GTK_RANGE (w)), "value",
642
G_SETTINGS_BIND_DEFAULT);
644
/* mouse preferences button */
645
g_signal_connect (WID (priv->builder, "pointing_mouse_preferences_link"),
647
G_CALLBACK (pointing_mouse_preferences_clicked_cb), self);
651
cc_ua_panel_init (CcUaPanel *self)
653
CcUaPanelPrivate *priv;
656
gchar *objects[] = { "universal_access_box", "contrast_model",
657
"text_size_model", "slowkeys_delay_adjustment",
658
"bouncekeys_delay_adjustment", "click_delay_adjustment",
659
"dwell_time_adjustment", "dwell_threshold_adjustment",
660
"seeing_sizegroup", "typing_sizegroup",
661
"pointing_sizegroup", "pointing_sizegroup2",
662
"pointing_scale_sizegroup", "sizegroup1",
666
priv = self->priv = UA_PANEL_PRIVATE (self);
668
priv->builder = gtk_builder_new ();
670
gtk_builder_add_objects_from_file (priv->builder,
671
GNOMECC_UI_DIR "/uap.ui",
677
g_warning ("Could not load interface file: %s", err->message);
680
g_object_unref (priv->builder);
681
priv->builder = NULL;
686
priv->interface_settings = g_settings_new ("org.gnome.desktop.interface");
687
priv->wm_settings = g_settings_new ("org.gnome.desktop.wm.preferences");
688
priv->kb_settings = g_settings_new ("org.gnome.desktop.a11y.keyboard");
689
priv->mouse_settings = g_settings_new ("org.gnome.desktop.a11y.mouse");
690
priv->application_settings = g_settings_new ("org.gnome.desktop.a11y.applications");
691
priv->mediakeys_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys");
693
cc_ua_panel_init_keyboard (self);
694
cc_ua_panel_init_mouse (self);
695
cc_ua_panel_init_hearing (self);
696
cc_ua_panel_init_seeing (self);
698
widget = (GtkWidget*) gtk_builder_get_object (priv->builder,
699
"universal_access_box");
701
gtk_container_add (GTK_CONTAINER (self), widget);
705
cc_ua_panel_register (GIOModule *module)
707
cc_ua_panel_register_type (G_TYPE_MODULE (module));
708
g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
710
"universal-access", 0);