~ubuntu-branches/ubuntu/trusty/unity-control-center/trusty

« back to all changes in this revision

Viewing changes to panels/universal-access/cc-ua-panel.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-01-08 16:29:18 UTC
  • Revision ID: package-import@ubuntu.com-20140108162918-g29dd08tr913y2qh
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 
2
 *
 
3
 * Copyright (C) 2010 Intel, Inc
 
4
 * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * Authors: Thomas Wood <thomas.wood@intel.com>
 
21
 *          Rodrigo Moya <rodrigo@gnome.org>
 
22
 *
 
23
 */
 
24
 
 
25
#include <config.h>
 
26
 
 
27
#include <math.h>
 
28
#include <glib/gi18n-lib.h>
 
29
#include <gdesktop-enums.h>
 
30
#include "cc-ua-panel.h"
 
31
 
 
32
#include "zoom-options.h"
 
33
 
 
34
#define WID(b, w) (GtkWidget *) gtk_builder_get_object (b, w)
 
35
 
 
36
#define DPI_FACTOR_LARGE 1.25
 
37
#define DPI_FACTOR_NORMAL 1.0
 
38
 
 
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"
 
44
 
 
45
CC_PANEL_REGISTER (CcUaPanel, cc_ua_panel)
 
46
 
 
47
#define UA_PANEL_PRIVATE(o) \
 
48
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_UA_PANEL, CcUaPanelPrivate))
 
49
 
 
50
struct _CcUaPanelPrivate
 
51
{
 
52
  GtkBuilder *builder;
 
53
  GSettings *wm_settings;
 
54
  GSettings *interface_settings;
 
55
  GSettings *kb_settings;
 
56
  GSettings *mouse_settings;
 
57
  GSettings *application_settings;
 
58
  GSettings *mediakeys_settings;
 
59
 
 
60
  ZoomOptions *zoom_options;
 
61
  guint shell_watch_id;
 
62
};
 
63
 
 
64
 
 
65
static void
 
66
cc_ua_panel_get_property (GObject    *object,
 
67
                          guint       property_id,
 
68
                          GValue     *value,
 
69
                          GParamSpec *pspec)
 
70
{
 
71
  switch (property_id)
 
72
    {
 
73
    default:
 
74
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
75
    }
 
76
}
 
77
 
 
78
static void
 
79
cc_ua_panel_set_property (GObject      *object,
 
80
                          guint         property_id,
 
81
                          const GValue *value,
 
82
                          GParamSpec   *pspec)
 
83
{
 
84
  switch (property_id)
 
85
    {
 
86
    default:
 
87
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
88
    }
 
89
}
 
90
 
 
91
static void
 
92
cc_ua_panel_dispose (GObject *object)
 
93
{
 
94
  CcUaPanelPrivate *priv = CC_UA_PANEL (object)->priv;
 
95
 
 
96
  if (priv->shell_watch_id)
 
97
    {
 
98
      g_bus_unwatch_name (priv->shell_watch_id);
 
99
      priv->shell_watch_id = 0;
 
100
    }
 
101
 
 
102
  if (priv->builder)
 
103
    {
 
104
      g_object_unref (priv->builder);
 
105
      priv->builder = NULL;
 
106
    }
 
107
 
 
108
  if (priv->wm_settings)
 
109
    {
 
110
      g_object_unref (priv->wm_settings);
 
111
      priv->wm_settings = NULL;
 
112
    }
 
113
 
 
114
  if (priv->interface_settings)
 
115
    {
 
116
      g_object_unref (priv->interface_settings);
 
117
      priv->interface_settings = NULL;
 
118
    }
 
119
 
 
120
  if (priv->kb_settings)
 
121
    {
 
122
      g_object_unref (priv->kb_settings);
 
123
      priv->kb_settings = NULL;
 
124
    }
 
125
 
 
126
  if (priv->mouse_settings)
 
127
    {
 
128
      g_object_unref (priv->mouse_settings);
 
129
      priv->mouse_settings = NULL;
 
130
    }
 
131
 
 
132
  if (priv->application_settings)
 
133
    {
 
134
      g_object_unref (priv->application_settings);
 
135
      priv->application_settings = NULL;
 
136
    }
 
137
 
 
138
  if (priv->mediakeys_settings)
 
139
    {
 
140
      g_object_unref (priv->mediakeys_settings);
 
141
      priv->mediakeys_settings = NULL;
 
142
    }
 
143
 
 
144
  if (priv->zoom_options)
 
145
    {
 
146
      g_object_unref (priv->zoom_options);
 
147
      priv->zoom_options = NULL;
 
148
    }
 
149
 
 
150
  G_OBJECT_CLASS (cc_ua_panel_parent_class)->dispose (object);
 
151
}
 
152
 
 
153
static void
 
154
cc_ua_panel_finalize (GObject *object)
 
155
{
 
156
  G_OBJECT_CLASS (cc_ua_panel_parent_class)->finalize (object);
 
157
}
 
158
 
 
159
static const char *
 
160
cc_ua_panel_get_help_uri (CcPanel *panel)
 
161
{
 
162
  if (!g_strcmp0(g_getenv("XDG_CURRENT_DESKTOP"), "Unity"))
 
163
    return "help:ubuntu-help/a11y";
 
164
  else
 
165
    return "help:gnome-help/a11y";
 
166
}
 
167
 
 
168
static void
 
169
cc_ua_panel_class_init (CcUaPanelClass *klass)
 
170
{
 
171
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
172
  CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
 
173
 
 
174
  g_type_class_add_private (klass, sizeof (CcUaPanelPrivate));
 
175
 
 
176
  panel_class->get_help_uri = cc_ua_panel_get_help_uri;
 
177
 
 
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;
 
182
}
 
183
 
 
184
static gchar *sticky_keys_section[] = {
 
185
    "typing_sticky_keys_disable_two_keys_checkbutton",
 
186
    "typing_sticky_keys_beep_modifier_checkbutton",
 
187
    NULL
 
188
};
 
189
 
 
190
static gchar *slow_keys_section[]= {
 
191
    "typing_slowkeys_delay_box",
 
192
    "typing_slow_keys_beeb_box",
 
193
    NULL
 
194
};
 
195
 
 
196
static gchar *bounce_keys_section[] = {
 
197
    "typing_bouncekeys_delay_box",
 
198
    "typing_bounce_keys_beep_rejected_checkbutton",
 
199
    NULL
 
200
};
 
201
 
 
202
static gchar *secondary_click_section[] = {
 
203
    "pointing_secondary_click_scale_box",
 
204
    NULL
 
205
};
 
206
 
 
207
static gchar *dwell_click_section[] = {
 
208
    "pointing_hover_click_delay_scale_box",
 
209
    "pointing_hover_click_threshold_scale_box",
 
210
    NULL
 
211
};
 
212
 
 
213
static gchar *visual_alerts_section[] = {
 
214
    "hearing_test_flash_button",
 
215
    "hearing_flash_window_title_button",
 
216
    "hearing_flash_screen_button",
 
217
    NULL
 
218
};
 
219
 
 
220
/* zoom options dialog */
 
221
static void
 
222
zoom_options_launch_cb (GtkWidget *options_button, CcUaPanel *self)
 
223
{
 
224
  if (self->priv->zoom_options == NULL)
 
225
    self->priv->zoom_options = zoom_options_new ();
 
226
 
 
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))));
 
230
}
 
231
 
 
232
static void
 
233
cc_ua_panel_section_switched (GObject    *object,
 
234
                              GParamSpec *pspec,
 
235
                              GtkBuilder *builder)
 
236
{
 
237
  GtkWidget *w;
 
238
  gboolean enabled;
 
239
  gchar **widgets, **s;
 
240
 
 
241
  widgets = g_object_get_data (object, "section-widgets");
 
242
 
 
243
  g_object_get (object, "active", &enabled, NULL);
 
244
 
 
245
  for (s = widgets; *s; s++)
 
246
    {
 
247
      w = WID (builder, *s);
 
248
      gtk_widget_set_sensitive (w, enabled);
 
249
    }
 
250
}
 
251
 
 
252
static void
 
253
settings_on_off_editor_new (CcUaPanelPrivate  *priv,
 
254
                            GSettings         *settings,
 
255
                            const gchar       *key,
 
256
                            GtkWidget         *widget,
 
257
                            gchar            **section)
 
258
{
 
259
  /* set data to enable/disable the section this on/off switch controls */
 
260
  if (section)
 
261
    {
 
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),
 
265
                        priv->builder);
 
266
    }
 
267
 
 
268
  /* set up the boolean editor */
 
269
  g_settings_bind (settings, key, widget, "active", G_SETTINGS_BIND_DEFAULT);
 
270
}
 
271
 
 
272
/* seeing section */
 
273
 
 
274
static void
 
275
cc_ua_panel_set_shortcut_label (CcUaPanel  *self,
 
276
                                const char *label,
 
277
                                const char *key)
 
278
{
 
279
        GtkWidget *widget;
 
280
        char *value;
 
281
        char *text;
 
282
        guint accel_key, *keycode;
 
283
        GdkModifierType mods;
 
284
 
 
285
        widget = WID (self->priv->builder, label);
 
286
        value = g_settings_get_string (self->priv->mediakeys_settings, key);
 
287
 
 
288
        if (value == NULL || *value == '\0') {
 
289
                gtk_label_set_text (GTK_LABEL (widget), _("No shortcut set"));
 
290
                g_free (value);
 
291
                return;
 
292
        }
 
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"));
 
296
                g_free (value);
 
297
                g_warning ("Failed to parse keyboard shortcut: '%s'", value);
 
298
                return;
 
299
        }
 
300
        g_free (value);
 
301
 
 
302
        text = gtk_accelerator_get_label_with_keycode (gtk_widget_get_display (widget), accel_key, *keycode, mods);
 
303
        g_free (keycode);
 
304
        gtk_label_set_text (GTK_LABEL (widget), text);
 
305
        g_free (text);
 
306
}
 
307
 
 
308
static void
 
309
shell_vanished_cb (GDBusConnection *connection,
 
310
                   const gchar *name,
 
311
                   CcUaPanel   *self)
 
312
{
 
313
  CcUaPanelPrivate *priv = self->priv;
 
314
 
 
315
  gtk_widget_hide (WID (priv->builder, "zoom_label_box"));
 
316
  gtk_widget_hide (WID (priv->builder, "zoom_value_box"));
 
317
}
 
318
 
 
319
static void
 
320
shell_appeared_cb (GDBusConnection *connection,
 
321
                   const gchar *name,
 
322
                   const gchar *name_owner,
 
323
                   CcUaPanel   *self)
 
324
{
 
325
  CcUaPanelPrivate *priv = self->priv;
 
326
 
 
327
  gtk_widget_show (WID (priv->builder, "zoom_label_box"));
 
328
  gtk_widget_show (WID (priv->builder, "zoom_value_box"));
 
329
}
 
330
 
 
331
static gboolean
 
332
get_large_text_mapping (GValue   *value,
 
333
                        GVariant *variant,
 
334
                        gpointer  user_data)
 
335
{
 
336
  gdouble factor;
 
337
  gboolean large;
 
338
 
 
339
  factor = g_variant_get_double (variant);
 
340
  large = factor > DPI_FACTOR_NORMAL;
 
341
  g_value_set_boolean (value, large);
 
342
 
 
343
  return TRUE;
 
344
}
 
345
 
 
346
static GVariant *
 
347
set_large_text_mapping (const GValue       *value,
 
348
                        const GVariantType *expected_type,
 
349
                        gpointer            user_data)
 
350
{
 
351
  gboolean large;
 
352
  GSettings *settings = user_data;
 
353
  GVariant *ret = NULL;
 
354
 
 
355
  large = g_value_get_boolean (value);
 
356
  if (large)
 
357
    ret = g_variant_new_double (DPI_FACTOR_LARGE);
 
358
  else
 
359
    g_settings_reset (settings, KEY_TEXT_SCALING_FACTOR);
 
360
 
 
361
  return ret;
 
362
}
 
363
 
 
364
static gboolean
 
365
get_contrast_mapping (GValue   *value,
 
366
                      GVariant *variant,
 
367
                      gpointer  user_data)
 
368
{
 
369
  const char *theme;
 
370
  gboolean hc;
 
371
 
 
372
  theme = g_variant_get_string (variant, NULL);
 
373
  hc = (g_strcmp0 (theme, HIGH_CONTRAST_THEME) == 0);
 
374
  g_value_set_boolean (value, hc);
 
375
 
 
376
  return TRUE;
 
377
}
 
378
 
 
379
static GVariant *
 
380
set_contrast_mapping (const GValue       *value,
 
381
                      const GVariantType *expected_type,
 
382
                      gpointer            user_data)
 
383
{
 
384
  gboolean hc;
 
385
  CcUaPanel *self = user_data;
 
386
  CcUaPanelPrivate *priv = self->priv;
 
387
  GVariant *ret = NULL;
 
388
 
 
389
  hc = g_value_get_boolean (value);
 
390
  if (hc)
 
391
    {
 
392
      ret = g_variant_new_string (HIGH_CONTRAST_THEME);
 
393
      g_settings_set_string (priv->interface_settings, KEY_ICON_THEME, HIGH_CONTRAST_THEME);
 
394
 
 
395
      g_settings_set_string (priv->wm_settings, KEY_WM_THEME, HIGH_CONTRAST_THEME);
 
396
    }
 
397
  else
 
398
    {
 
399
      g_settings_reset (priv->interface_settings, KEY_GTK_THEME);
 
400
      g_settings_reset (priv->interface_settings, KEY_ICON_THEME);
 
401
 
 
402
      g_settings_reset (priv->wm_settings, KEY_WM_THEME);
 
403
    }
 
404
 
 
405
  return ret;
 
406
}
 
407
 
 
408
static void
 
409
cc_ua_panel_init_seeing (CcUaPanel *self)
 
410
{
 
411
  CcUaPanelPrivate *priv = self->priv;
 
412
 
 
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,
 
418
                                self,
 
419
                                NULL);
 
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,
 
426
                                NULL);
 
427
 
 
428
  g_settings_bind (priv->kb_settings, "togglekeys-enable",
 
429
                   WID (priv->builder, "seeing_toggle_keys_switch"), "active",
 
430
                   G_SETTINGS_BIND_DEFAULT);
 
431
 
 
432
  if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity")) 
 
433
  {
 
434
    priv->shell_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
 
435
                                           "org.gnome.Shell",
 
436
                                           G_BUS_NAME_WATCHER_FLAGS_NONE,
 
437
                                           (GBusNameAppearedCallback) shell_appeared_cb,
 
438
                                           (GBusNameVanishedCallback) shell_vanished_cb,
 
439
                                           self,
 
440
                                           NULL);
 
441
  } else
 
442
  {
 
443
    gtk_widget_hide (WID (priv->builder, "zoom_label_box"));
 
444
    gtk_widget_hide (WID (priv->builder, "zoom_value_box"));
 
445
  }
 
446
 
 
447
  g_signal_connect (WID (priv->builder, "seeing_zoom_preferences_button"),
 
448
                    "clicked",
 
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);
 
453
 
 
454
  settings_on_off_editor_new (priv, priv->application_settings,
 
455
                              "screen-reader-enabled",
 
456
                              WID (priv->builder, "seeing_reader_switch"),
 
457
                              NULL);
 
458
 
 
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");
 
463
}
 
464
 
 
465
 
 
466
/* hearing/sound section */
 
467
static void
 
468
visual_bell_type_notify_cb (GSettings   *settings,
 
469
                            const gchar *key,
 
470
                            CcUaPanel   *panel)
 
471
{
 
472
  GtkWidget *widget;
 
473
  GDesktopVisualBellType type;
 
474
 
 
475
  type = g_settings_get_enum (panel->priv->wm_settings, "visual-bell-type");
 
476
 
 
477
  if (type == G_DESKTOP_VISUAL_BELL_FRAME_FLASH)
 
478
    widget = WID (panel->priv->builder, "hearing_flash_window_title_button");
 
479
  else
 
480
    widget = WID (panel->priv->builder, "hearing_flash_screen_button");
 
481
 
 
482
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
 
483
}
 
484
 
 
485
static void
 
486
visual_bell_type_toggle_cb (GtkWidget *button,
 
487
                            CcUaPanel *panel)
 
488
{
 
489
  gboolean frame_flash;
 
490
  GDesktopVisualBellType type;
 
491
 
 
492
  frame_flash = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
 
493
 
 
494
  if (frame_flash)
 
495
    type = G_DESKTOP_VISUAL_BELL_FRAME_FLASH;
 
496
  else
 
497
    type = G_DESKTOP_VISUAL_BELL_FULLSCREEN_FLASH;
 
498
  g_settings_set_enum (panel->priv->wm_settings, "visual-bell-type", type);
 
499
}
 
500
 
 
501
static gboolean
 
502
hearing_sound_preferences_clicked (GtkButton  *button,
 
503
                                   CcUaPanel  *panel)
 
504
{
 
505
  CcShell *shell;
 
506
 
 
507
  shell = cc_panel_get_shell (CC_PANEL (panel));
 
508
  cc_shell_set_active_panel_from_id (shell, "sound", NULL, NULL);
 
509
 
 
510
  return TRUE;
 
511
}
 
512
 
 
513
static void
 
514
cc_ua_panel_init_hearing (CcUaPanel *self)
 
515
{
 
516
  CcUaPanelPrivate *priv = self->priv;
 
517
  GtkWidget *w;
 
518
 
 
519
  /* set the initial visual bell values */
 
520
  visual_bell_type_notify_cb (NULL, NULL, self);
 
521
 
 
522
  /* and listen */
 
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);
 
525
 
 
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);
 
530
 
 
531
  /* test flash */
 
532
  g_signal_connect (WID (priv->builder, "hearing_test_flash_button"),
 
533
                    "clicked", G_CALLBACK (gdk_beep), NULL);
 
534
 
 
535
  g_signal_connect (WID (priv->builder, "hearing_sound_preferences_link"),
 
536
                    "activate-link",
 
537
                    G_CALLBACK (hearing_sound_preferences_clicked), self);
 
538
}
 
539
 
 
540
/* typing/keyboard section */
 
541
 
 
542
static void
 
543
cc_ua_panel_init_keyboard (CcUaPanel *self)
 
544
{
 
545
  CcUaPanelPrivate *priv = self->priv;
 
546
  GtkWidget *w;
 
547
 
 
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);
 
552
 
 
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);
 
556
 
 
557
  /* sticky keys */
 
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);
 
560
 
 
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);
 
563
 
 
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);
 
566
 
 
567
  /* slow keys */
 
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);
 
570
 
 
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);
 
575
 
 
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);
 
578
 
 
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);
 
581
 
 
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);
 
584
 
 
585
  /* bounce keys */
 
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);
 
588
 
 
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);
 
593
 
 
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);
 
596
}
 
597
 
 
598
/* mouse/pointing & clicking section */
 
599
static gboolean
 
600
pointing_mouse_preferences_clicked_cb (GtkButton  *button,
 
601
                                       CcUaPanel  *panel)
 
602
{
 
603
  CcShell *shell;
 
604
 
 
605
  shell = cc_panel_get_shell (CC_PANEL (panel));
 
606
  cc_shell_set_active_panel_from_id (shell, "mouse", NULL, NULL);
 
607
 
 
608
  return TRUE;
 
609
}
 
610
 
 
611
static void
 
612
cc_ua_panel_init_mouse (CcUaPanel *self)
 
613
{
 
614
  CcUaPanelPrivate *priv = self->priv;
 
615
  GtkWidget *w;
 
616
 
 
617
  /* mouse keys */
 
618
  w = WID (priv->builder, "pointing_mouse_keys_switch");
 
619
  settings_on_off_editor_new (priv, priv->kb_settings, "mousekeys-enable", w, NULL);
 
620
 
 
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);
 
624
 
 
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);
 
629
 
 
630
  /* dwell click */
 
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);
 
633
 
 
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);
 
638
 
 
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);
 
643
 
 
644
  /* mouse preferences button */
 
645
  g_signal_connect (WID (priv->builder, "pointing_mouse_preferences_link"),
 
646
                    "activate-link",
 
647
                    G_CALLBACK (pointing_mouse_preferences_clicked_cb), self);
 
648
}
 
649
 
 
650
static void
 
651
cc_ua_panel_init (CcUaPanel *self)
 
652
{
 
653
  CcUaPanelPrivate *priv;
 
654
  GtkWidget *widget;
 
655
  GError *err = NULL;
 
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",
 
663
                       "hearing_sizegroup",
 
664
                       NULL };
 
665
 
 
666
  priv = self->priv = UA_PANEL_PRIVATE (self);
 
667
 
 
668
  priv->builder = gtk_builder_new ();
 
669
 
 
670
  gtk_builder_add_objects_from_file (priv->builder,
 
671
                                     GNOMECC_UI_DIR "/uap.ui",
 
672
                                     objects,
 
673
                                     &err);
 
674
 
 
675
  if (err)
 
676
    {
 
677
      g_warning ("Could not load interface file: %s", err->message);
 
678
      g_error_free (err);
 
679
 
 
680
      g_object_unref (priv->builder);
 
681
      priv->builder = NULL;
 
682
 
 
683
      return;
 
684
    }
 
685
 
 
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");
 
692
 
 
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);
 
697
 
 
698
  widget = (GtkWidget*) gtk_builder_get_object (priv->builder,
 
699
                                                "universal_access_box");
 
700
 
 
701
  gtk_container_add (GTK_CONTAINER (self), widget);
 
702
}
 
703
 
 
704
void
 
705
cc_ua_panel_register (GIOModule *module)
 
706
{
 
707
  cc_ua_panel_register_type (G_TYPE_MODULE (module));
 
708
  g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
 
709
                                  CC_TYPE_UA_PANEL,
 
710
                                  "universal-access", 0);
 
711
}
 
712