~elementary-os/elementaryos/os-patch-gnome-control-center-precise

« back to all changes in this revision

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

  • Committer: Sergey "Shnatsel" Davidoff
  • Date: 2012-05-18 13:02:50 UTC
  • Revision ID: shnatsel@gmail.com-20120518130250-2u99ldq61a42rbt7
Initial import, version 1:3.4.1-0ubuntu2

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
 
 
37
G_DEFINE_DYNAMIC_TYPE (CcUaPanel, cc_ua_panel, CC_TYPE_PANEL)
 
38
 
 
39
#define UA_PANEL_PRIVATE(o) \
 
40
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_UA_PANEL, CcUaPanelPrivate))
 
41
 
 
42
struct _CcUaPanelPrivate
 
43
{
 
44
  GtkBuilder *builder;
 
45
  GSettings *wm_settings;
 
46
  GSettings *interface_settings;
 
47
  GSettings *kb_settings;
 
48
  GSettings *mouse_settings;
 
49
  GSettings *application_settings;
 
50
  GSettings *mediakeys_settings;
 
51
 
 
52
  ZoomOptions *zoom_options;
 
53
  guint shell_watch_id;
 
54
};
 
55
 
 
56
 
 
57
static void
 
58
cc_ua_panel_get_property (GObject    *object,
 
59
                               guint       property_id,
 
60
                               GValue     *value,
 
61
                               GParamSpec *pspec)
 
62
{
 
63
  switch (property_id)
 
64
    {
 
65
    default:
 
66
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
67
    }
 
68
}
 
69
 
 
70
static void
 
71
cc_ua_panel_set_property (GObject      *object,
 
72
                               guint         property_id,
 
73
                               const GValue *value,
 
74
                               GParamSpec   *pspec)
 
75
{
 
76
  switch (property_id)
 
77
    {
 
78
    default:
 
79
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
80
    }
 
81
}
 
82
 
 
83
static void
 
84
cc_ua_panel_dispose (GObject *object)
 
85
{
 
86
  CcUaPanelPrivate *priv = CC_UA_PANEL (object)->priv;
 
87
 
 
88
  if (priv->shell_watch_id)
 
89
    {
 
90
      g_bus_unwatch_name (priv->shell_watch_id);
 
91
      priv->shell_watch_id = 0;
 
92
    }
 
93
 
 
94
  if (priv->builder)
 
95
    {
 
96
      g_object_unref (priv->builder);
 
97
      priv->builder = NULL;
 
98
    }
 
99
 
 
100
  if (priv->wm_settings)
 
101
    {
 
102
      g_object_unref (priv->wm_settings);
 
103
      priv->wm_settings = NULL;
 
104
    }
 
105
 
 
106
  if (priv->interface_settings)
 
107
    {
 
108
      g_object_unref (priv->interface_settings);
 
109
      priv->interface_settings = NULL;
 
110
    }
 
111
 
 
112
  if (priv->kb_settings)
 
113
    {
 
114
      g_object_unref (priv->kb_settings);
 
115
      priv->kb_settings = NULL;
 
116
    }
 
117
 
 
118
  if (priv->mouse_settings)
 
119
    {
 
120
      g_object_unref (priv->mouse_settings);
 
121
      priv->mouse_settings = NULL;
 
122
    }
 
123
 
 
124
  if (priv->application_settings)
 
125
    {
 
126
      g_object_unref (priv->application_settings);
 
127
      priv->application_settings = NULL;
 
128
    }
 
129
 
 
130
  if (priv->mediakeys_settings)
 
131
    {
 
132
      g_object_unref (priv->mediakeys_settings);
 
133
      priv->mediakeys_settings = NULL;
 
134
    }
 
135
 
 
136
  if (priv->zoom_options)
 
137
    {
 
138
      g_object_unref (priv->zoom_options);
 
139
      priv->zoom_options = NULL;
 
140
    }
 
141
 
 
142
  G_OBJECT_CLASS (cc_ua_panel_parent_class)->dispose (object);
 
143
}
 
144
 
 
145
static void
 
146
cc_ua_panel_finalize (GObject *object)
 
147
{
 
148
  G_OBJECT_CLASS (cc_ua_panel_parent_class)->finalize (object);
 
149
}
 
150
 
 
151
static void
 
152
cc_ua_panel_class_init (CcUaPanelClass *klass)
 
153
{
 
154
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
155
 
 
156
  g_type_class_add_private (klass, sizeof (CcUaPanelPrivate));
 
157
 
 
158
  object_class->get_property = cc_ua_panel_get_property;
 
159
  object_class->set_property = cc_ua_panel_set_property;
 
160
  object_class->dispose = cc_ua_panel_dispose;
 
161
  object_class->finalize = cc_ua_panel_finalize;
 
162
}
 
163
 
 
164
static void
 
165
cc_ua_panel_class_finalize (CcUaPanelClass *klass)
 
166
{
 
167
}
 
168
 
 
169
static gchar *typing_assistant_section[] = {
 
170
    "typing_assistant_preferences_button",
 
171
    NULL
 
172
};
 
173
 
 
174
static gchar *sticky_keys_section[] = {
 
175
    "typing_sticky_keys_disable_two_keys_checkbutton",
 
176
    "typing_sticky_keys_beep_modifier_checkbutton",
 
177
    NULL
 
178
};
 
179
 
 
180
static gchar *slow_keys_section[]= {
 
181
    "typing_slowkeys_delay_box",
 
182
    "typing_slow_keys_beeb_box",
 
183
    NULL
 
184
};
 
185
 
 
186
static gchar *bounce_keys_section[] = {
 
187
    "typing_bouncekeys_delay_box",
 
188
    "typing_bounce_keys_beep_rejected_checkbutton",
 
189
    NULL
 
190
};
 
191
 
 
192
static gchar *secondary_click_section[] = {
 
193
    "pointing_secondary_click_scale_box",
 
194
    NULL
 
195
};
 
196
 
 
197
static gchar *dwell_click_section[] = {
 
198
    "pointing_hover_click_delay_scale_box",
 
199
    "pointing_hover_click_threshold_scale_box",
 
200
    NULL
 
201
};
 
202
 
 
203
static gchar *visual_alerts_section[] = {
 
204
    "hearing_test_flash_button",
 
205
    "hearing_flash_window_title_button",
 
206
    "hearing_flash_screen_button",
 
207
    NULL
 
208
};
 
209
 
 
210
/* zoom options dialog */
 
211
static void
 
212
zoom_options_launch_cb (GtkWidget *options_button, CcUaPanel *self)
 
213
{
 
214
  if (self->priv->zoom_options == NULL)
 
215
    self->priv->zoom_options = zoom_options_new ();
 
216
 
 
217
  if (self->priv->zoom_options != NULL)
 
218
    zoom_options_set_parent (self->priv->zoom_options,
 
219
                             GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
 
220
}
 
221
 
 
222
static void
 
223
cc_ua_panel_section_switched (GObject    *object,
 
224
                              GParamSpec *pspec,
 
225
                              GtkBuilder *builder)
 
226
{
 
227
  GtkWidget *w;
 
228
  gboolean enabled;
 
229
  gchar **widgets, **s;
 
230
 
 
231
  widgets = g_object_get_data (object, "section-widgets");
 
232
 
 
233
  g_object_get (object, "active", &enabled, NULL);
 
234
 
 
235
  for (s = widgets; *s; s++)
 
236
    {
 
237
      w = WID (builder, *s);
 
238
      gtk_widget_set_sensitive (w, enabled);
 
239
    }
 
240
}
 
241
 
 
242
static void
 
243
settings_on_off_editor_new (CcUaPanelPrivate  *priv,
 
244
                            GSettings         *settings,
 
245
                            const gchar       *key,
 
246
                            GtkWidget         *widget,
 
247
                            gchar            **section)
 
248
{
 
249
  /* set data to enable/disable the section this on/off switch controls */
 
250
  if (section)
 
251
    {
 
252
      g_object_set_data (G_OBJECT (widget), "section-widgets", section);
 
253
      g_signal_connect (widget, "notify::active",
 
254
                        G_CALLBACK (cc_ua_panel_section_switched),
 
255
                        priv->builder);
 
256
    }
 
257
 
 
258
  /* set up the boolean editor */
 
259
  g_settings_bind (settings, key, widget, "active", G_SETTINGS_BIND_DEFAULT);
 
260
}
 
261
 
 
262
/* seeing section */
 
263
#define GTK_THEME_KEY "gtk-theme"
 
264
#define ICON_THEME_KEY "icon-theme"
 
265
#define CONTRAST_MODEL_THEME_COLUMN 2
 
266
#define DPI_MODEL_FACTOR_COLUMN 2
 
267
#define DPI_MODEL_FACTOR_CALC_COLUMN 3
 
268
 
 
269
static void text_scaling_factor_combo_box_changed (GtkComboBox *box, CcUaPanel *panel);
 
270
 
 
271
static void
 
272
text_scaling_factor_notify_cb (GSettings   *settings,
 
273
                               const gchar *key,
 
274
                               CcUaPanel   *panel)
 
275
{
 
276
  CcUaPanelPrivate *priv = panel->priv;
 
277
  GtkTreeIter iter;
 
278
  GtkTreeModel *model;
 
279
  GtkWidget *combo;
 
280
  gboolean valid;
 
281
  gdouble conf_value;
 
282
  GtkTreeIter best;
 
283
  gdouble distance;
 
284
 
 
285
  if (!g_str_equal (key, "text-scaling-factor"))
 
286
    return;
 
287
 
 
288
  conf_value = g_settings_get_double (settings, key);
 
289
 
 
290
  combo = WID (priv->builder, "seeing_text_size_combobox");
 
291
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
 
292
 
 
293
  /* Recalculate the font sizes so that
 
294
   * their size is about constant when changing text size */
 
295
  valid = gtk_tree_model_get_iter_first (model, &iter);
 
296
  while (valid)
 
297
    {
 
298
      gfloat factor;
 
299
 
 
300
      gtk_tree_model_get (model, &iter,
 
301
                          DPI_MODEL_FACTOR_COLUMN, &factor,
 
302
                          -1);
 
303
 
 
304
      factor /= conf_value;
 
305
 
 
306
      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
307
                          DPI_MODEL_FACTOR_CALC_COLUMN, factor,
 
308
                          -1);
 
309
 
 
310
      valid = gtk_tree_model_iter_next (model, &iter);
 
311
    }
 
312
 
 
313
  /* find the closest match in the combobox model */
 
314
  distance = 1e6;
 
315
  valid = gtk_tree_model_get_iter_first (model, &iter);
 
316
  while (valid)
 
317
    {
 
318
      gfloat factor;
 
319
      gdouble d;
 
320
 
 
321
      gtk_tree_model_get (model, &iter,
 
322
                          DPI_MODEL_FACTOR_COLUMN, &factor,
 
323
                          -1);
 
324
 
 
325
      d = fabs (conf_value - factor);
 
326
      if (d < distance)
 
327
        {
 
328
          best = iter;
 
329
          distance = d;
 
330
        }
 
331
 
 
332
      valid = gtk_tree_model_iter_next (model, &iter);
 
333
    }
 
334
 
 
335
  g_signal_handlers_block_by_func (combo, text_scaling_factor_combo_box_changed, panel);
 
336
  gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &best);
 
337
  g_signal_handlers_unblock_by_func (combo, text_scaling_factor_combo_box_changed, panel);
 
338
}
 
339
 
 
340
static void
 
341
text_scaling_factor_combo_box_changed (GtkComboBox *box,
 
342
                                       CcUaPanel *panel)
 
343
{
 
344
  CcUaPanelPrivate *priv = panel->priv;
 
345
  GtkTreeIter iter;
 
346
  gfloat factor;
 
347
 
 
348
  gtk_combo_box_get_active_iter (box, &iter);
 
349
 
 
350
  gtk_tree_model_get (gtk_combo_box_get_model (box), &iter,
 
351
                      DPI_MODEL_FACTOR_COLUMN, &factor,
 
352
                      -1);
 
353
 
 
354
  if (factor == 1.0)
 
355
    g_settings_reset (priv->interface_settings, "text-scaling-factor");
 
356
  else
 
357
    g_settings_set_double (priv->interface_settings, "text-scaling-factor", factor);
 
358
}
 
359
 
 
360
 
 
361
static void
 
362
interface_settings_changed_cb (GSettings   *settings,
 
363
                               const gchar *key,
 
364
                               CcUaPanel   *panel)
 
365
{
 
366
  CcUaPanelPrivate *priv = panel->priv;
 
367
 
 
368
  if (g_str_equal (key, "gtk-theme")) {
 
369
    GtkTreeIter iter;
 
370
    GtkTreeModel *model;
 
371
    GtkWidget *combo;
 
372
    gboolean valid;
 
373
    gchar *theme_value;
 
374
 
 
375
    theme_value = g_settings_get_string (settings, GTK_THEME_KEY);
 
376
 
 
377
    combo = WID (priv->builder, "seeing_contrast_combobox");
 
378
    model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
 
379
 
 
380
    /* see if there is a matching theme name in the combobox model */
 
381
    valid = gtk_tree_model_get_iter_first (model, &iter);
 
382
    while (valid)
 
383
      {
 
384
        gchar *value;
 
385
 
 
386
        gtk_tree_model_get (model, &iter,
 
387
                            CONTRAST_MODEL_THEME_COLUMN, &value,
 
388
                            -1);
 
389
 
 
390
        if (!g_strcmp0 (value, theme_value))
 
391
          {
 
392
            gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
 
393
            g_free (value);
 
394
            break;
 
395
          }
 
396
 
 
397
        g_free (value);
 
398
        valid = gtk_tree_model_iter_next (model, &iter);
 
399
      }
 
400
 
 
401
    /* if a value for the current theme was not found in the combobox, set to the
 
402
     * "normal" option */
 
403
    if (!valid)
 
404
      {
 
405
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
 
406
      }
 
407
  }
 
408
}
 
409
 
 
410
static void
 
411
contrast_combobox_changed_cb (GtkComboBox *box,
 
412
                              CcUaPanel   *panel)
 
413
{
 
414
  CcUaPanelPrivate *priv = panel->priv;
 
415
  gchar *theme_name = NULL;
 
416
  GtkTreeIter iter;
 
417
 
 
418
  gtk_combo_box_get_active_iter (box, &iter);
 
419
 
 
420
  gtk_tree_model_get (gtk_combo_box_get_model (box), &iter,
 
421
                      CONTRAST_MODEL_THEME_COLUMN, &theme_name,
 
422
                      -1);
 
423
 
 
424
  if (g_strcmp0 (theme_name, ""))
 
425
    {
 
426
      /* disable overlay scrollbars for a11y */
 
427
      if (g_strcmp0 (theme_name, "HighContrast") == 0 ||
 
428
          g_strcmp0 (theme_name, "HighContrastInverse") == 0)
 
429
        g_settings_set_boolean (priv->interface_settings, "ubuntu-overlay-scrollbars", FALSE);
 
430
      else
 
431
        g_settings_reset (priv->interface_settings, "ubuntu-overlay-scrollbars");
 
432
 
 
433
      g_settings_set_string (priv->interface_settings, GTK_THEME_KEY, theme_name);
 
434
      g_settings_set_string (priv->interface_settings, ICON_THEME_KEY, theme_name);
 
435
    }
 
436
  else
 
437
    {
 
438
      /* reset overlay scrollbars key */
 
439
      g_settings_reset (priv->interface_settings, "ubuntu-overlay-scrollbars");
 
440
 
 
441
      g_settings_reset (priv->interface_settings, GTK_THEME_KEY);
 
442
      g_settings_reset (priv->interface_settings, ICON_THEME_KEY);
 
443
    }
 
444
 
 
445
  g_free (theme_name);
 
446
}
 
447
 
 
448
static void
 
449
cc_ua_panel_set_shortcut_label (CcUaPanel  *self,
 
450
                                const char *label,
 
451
                                const char *key)
 
452
{
 
453
        GtkWidget *widget;
 
454
        char *value;
 
455
        char *text;
 
456
        guint accel_key, *keycode;
 
457
        GdkModifierType mods;
 
458
 
 
459
        widget = WID (self->priv->builder, label);
 
460
        value = g_settings_get_string (self->priv->mediakeys_settings, key);
 
461
 
 
462
        if (value == NULL || *value == '\0') {
 
463
                gtk_label_set_text (GTK_LABEL (widget), _("No shortcut set"));
 
464
                g_free (value);
 
465
                return;
 
466
        }
 
467
        gtk_accelerator_parse_with_keycode (value, &accel_key, &keycode, &mods);
 
468
        if (accel_key == 0 && keycode == NULL && mods == 0) {
 
469
                gtk_label_set_text (GTK_LABEL (widget), _("No shortcut set"));
 
470
                g_free (value);
 
471
                g_warning ("Failed to parse keyboard shortcut: '%s'", value);
 
472
                return;
 
473
        }
 
474
        g_free (value);
 
475
 
 
476
        text = gtk_accelerator_get_label_with_keycode (gtk_widget_get_display (widget), accel_key, *keycode, mods);
 
477
        g_free (keycode);
 
478
        gtk_label_set_text (GTK_LABEL (widget), text);
 
479
        g_free (text);
 
480
}
 
481
 
 
482
static void
 
483
shell_vanished_cb (GDBusConnection *connection,
 
484
                   const gchar *name,
 
485
                   CcUaPanel   *self)
 
486
{
 
487
  CcUaPanelPrivate *priv = self->priv;
 
488
 
 
489
  gtk_widget_hide (WID (priv->builder, "zoom_frame"));
 
490
}
 
491
 
 
492
static void
 
493
shell_appeared_cb (GDBusConnection *connection,
 
494
                   const gchar *name,
 
495
                   const gchar *name_owner,
 
496
                   CcUaPanel   *self)
 
497
{
 
498
  CcUaPanelPrivate *priv = self->priv;
 
499
 
 
500
  gtk_widget_show (WID (priv->builder, "zoom_frame"));
 
501
}
 
502
 
 
503
static void
 
504
cc_ua_panel_init_seeing (CcUaPanel *self)
 
505
{
 
506
  CcUaPanelPrivate *priv = self->priv;
 
507
 
 
508
  text_scaling_factor_notify_cb (priv->interface_settings, "text-scaling-factor", self);
 
509
  g_signal_connect (priv->interface_settings, "changed::text-scaling-factor", G_CALLBACK (text_scaling_factor_notify_cb), self);
 
510
 
 
511
  g_signal_connect (WID (priv->builder, "seeing_contrast_combobox"), "changed",
 
512
                    G_CALLBACK (contrast_combobox_changed_cb), self);
 
513
 
 
514
  g_signal_connect (WID (priv->builder, "seeing_text_size_combobox"), "changed",
 
515
                    G_CALLBACK (text_scaling_factor_combo_box_changed), self);
 
516
 
 
517
  g_settings_bind (priv->kb_settings, "togglekeys-enable",
 
518
                   WID (priv->builder, "seeing_enable_toggle_keys_checkbutton"), "active",
 
519
                   G_SETTINGS_BIND_DEFAULT);
 
520
 
 
521
  priv->shell_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
 
522
                                           "org.gnome.Shell",
 
523
                                           G_BUS_NAME_WATCHER_FLAGS_NONE,
 
524
                                           (GBusNameAppearedCallback) shell_appeared_cb,
 
525
                                           (GBusNameVanishedCallback) shell_vanished_cb,
 
526
                                           self,
 
527
                                           NULL);
 
528
  g_signal_connect (WID (priv->builder, "seeing_zoom_preferences_button"),
 
529
                    "clicked",
 
530
                    G_CALLBACK (zoom_options_launch_cb), self);
 
531
  g_settings_bind (priv->application_settings, "screen-magnifier-enabled",
 
532
                   WID (priv->builder, "seeing_zoom_switch"), "active",
 
533
                   G_SETTINGS_BIND_DEFAULT);
 
534
 
 
535
  settings_on_off_editor_new (priv, priv->application_settings,
 
536
                              "screen-reader-enabled",
 
537
                              WID (priv->builder, "seeing_reader_switch"),
 
538
                              NULL);
 
539
 
 
540
  cc_ua_panel_set_shortcut_label (self, "seeing_contrast_toggle_keybinding_label", "toggle-contrast");
 
541
  cc_ua_panel_set_shortcut_label (self, "seeing_increase_size_keybinding_label", "increase-text-size");
 
542
  cc_ua_panel_set_shortcut_label (self, "seeing_decrease_size_keybinding_label", "decrease-text-size");
 
543
  cc_ua_panel_set_shortcut_label (self, "seeing_zoom_enable_keybinding_label", "magnifier");
 
544
  cc_ua_panel_set_shortcut_label (self, "seeing_zoom_in_keybinding_label", "magnifier-zoom-in");
 
545
  cc_ua_panel_set_shortcut_label (self, "seeing_zoom_out_keybinding_label", "magnifier-zoom-out");
 
546
  cc_ua_panel_set_shortcut_label (self, "seeing_reader_enable_keybinding_label", "screenreader");
 
547
}
 
548
 
 
549
 
 
550
/* hearing/sound section */
 
551
static void
 
552
visual_bell_type_notify_cb (GSettings   *settings,
 
553
                            const gchar *key,
 
554
                            CcUaPanel   *panel)
 
555
{
 
556
  GtkWidget *widget;
 
557
  GDesktopVisualBellType type;
 
558
 
 
559
  type = g_settings_get_enum (panel->priv->wm_settings, "visual-bell-type");
 
560
 
 
561
  if (type == G_DESKTOP_VISUAL_BELL_FRAME_FLASH)
 
562
    widget = WID (panel->priv->builder, "hearing_flash_window_title_button");
 
563
  else
 
564
    widget = WID (panel->priv->builder, "hearing_flash_screen_button");
 
565
 
 
566
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
 
567
}
 
568
 
 
569
static void
 
570
visual_bell_type_toggle_cb (GtkWidget *button,
 
571
                            CcUaPanel *panel)
 
572
{
 
573
  gboolean frame_flash;
 
574
  GDesktopVisualBellType type;
 
575
 
 
576
  frame_flash = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
 
577
 
 
578
  if (frame_flash)
 
579
    type = G_DESKTOP_VISUAL_BELL_FRAME_FLASH;
 
580
  else
 
581
    type = G_DESKTOP_VISUAL_BELL_FULLSCREEN_FLASH;
 
582
  g_settings_set_enum (panel->priv->wm_settings, "visual-bell-type", type);
 
583
}
 
584
 
 
585
static gboolean
 
586
hearing_sound_preferences_clicked (GtkButton  *button,
 
587
                                   CcUaPanel  *panel)
 
588
{
 
589
  CcShell *shell;
 
590
 
 
591
  shell = cc_panel_get_shell (CC_PANEL (panel));
 
592
  if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)
 
593
    cc_shell_set_active_panel_from_id (shell, "sound-nua", NULL, NULL);
 
594
  else
 
595
    cc_shell_set_active_panel_from_id (shell, "sound", NULL, NULL);
 
596
 
 
597
  return TRUE;
 
598
}
 
599
 
 
600
static void
 
601
cc_ua_panel_init_hearing (CcUaPanel *self)
 
602
{
 
603
  CcUaPanelPrivate *priv = self->priv;
 
604
  GtkWidget *w;
 
605
 
 
606
  /* set the initial visual bell values */
 
607
  visual_bell_type_notify_cb (NULL, NULL, self);
 
608
 
 
609
  /* and listen */
 
610
  w = WID (priv->builder, "hearing_visual_alerts_switch");
 
611
  settings_on_off_editor_new (priv, priv->wm_settings, "visual-bell", w, visual_alerts_section);
 
612
 
 
613
  g_signal_connect (priv->wm_settings, "changed::visual-bell-type",
 
614
                    G_CALLBACK (visual_bell_type_notify_cb), self);
 
615
  g_signal_connect (WID (priv->builder, "hearing_flash_window_title_button"),
 
616
                    "toggled", G_CALLBACK (visual_bell_type_toggle_cb), self);
 
617
 
 
618
  /* test flash */
 
619
  g_signal_connect (WID (priv->builder, "hearing_test_flash_button"),
 
620
                    "clicked", G_CALLBACK (gdk_beep), NULL);
 
621
 
 
622
  g_signal_connect (WID (priv->builder, "hearing_sound_preferences_link"),
 
623
                    "activate-link",
 
624
                    G_CALLBACK (hearing_sound_preferences_clicked), self);
 
625
}
 
626
 
 
627
/* typing/keyboard section */
 
628
static gboolean
 
629
typing_keyboard_preferences_clicked (GtkButton  *button,
 
630
                                     CcUaPanel  *panel)
 
631
{
 
632
  CcShell *shell;
 
633
 
 
634
  shell = cc_panel_get_shell (CC_PANEL (panel));
 
635
  cc_shell_set_active_panel_from_id (shell, "keyboard", NULL, NULL);
 
636
 
 
637
  return TRUE;
 
638
}
 
639
 
 
640
static void
 
641
cc_ua_panel_init_keyboard (CcUaPanel *self)
 
642
{
 
643
  CcUaPanelPrivate *priv = self->priv;
 
644
  GtkWidget *w;
 
645
 
 
646
  /* Typing assistant (on-screen keyboard) */
 
647
  w = WID (priv->builder, "typing_assistant_switch");
 
648
  settings_on_off_editor_new (priv, priv->application_settings, "screen-keyboard-enabled", w, typing_assistant_section);
 
649
 
 
650
  /* enable shortcuts */
 
651
  w = WID (priv->builder, "typing_keyboard_toggle_checkbox");
 
652
  g_settings_bind (priv->kb_settings, "enable", w, "active", G_SETTINGS_BIND_DEFAULT);
 
653
 
 
654
  /* sticky keys */
 
655
  w = WID (priv->builder, "typing_sticky_keys_switch");
 
656
  settings_on_off_editor_new (priv, priv->kb_settings, "stickykeys-enable", w, sticky_keys_section);
 
657
 
 
658
  w = WID (priv->builder, "typing_sticky_keys_disable_two_keys_checkbutton");
 
659
  g_settings_bind (priv->kb_settings, "stickykeys-two-key-off", w, "active", G_SETTINGS_BIND_NO_SENSITIVITY);
 
660
 
 
661
  w = WID (priv->builder, "typing_sticky_keys_beep_modifier_checkbutton");
 
662
  g_settings_bind (priv->kb_settings, "stickykeys-modifier-beep", w, "active", G_SETTINGS_BIND_NO_SENSITIVITY);
 
663
 
 
664
  /* slow keys */
 
665
  w = WID (priv->builder, "typing_slow_keys_switch");
 
666
  settings_on_off_editor_new (priv, priv->kb_settings, "slowkeys-enable", w, slow_keys_section);
 
667
 
 
668
  w = WID (priv->builder, "typing_slowkeys_delay_scale");
 
669
  g_settings_bind (priv->kb_settings, "slowkeys-delay",
 
670
                   gtk_range_get_adjustment (GTK_RANGE (w)), "value",
 
671
                   G_SETTINGS_BIND_DEFAULT);
 
672
 
 
673
  w = WID (priv->builder, "typing_slow_keys_beep_pressed_checkbutton");
 
674
  g_settings_bind (priv->kb_settings, "slowkeys-beep-press", w, "active", G_SETTINGS_BIND_DEFAULT);
 
675
 
 
676
  w = WID (priv->builder, "typing_slow_keys_beep_accepted_checkbutton");
 
677
  g_settings_bind (priv->kb_settings, "slowkeys-beep-accept", w, "active", G_SETTINGS_BIND_DEFAULT);
 
678
 
 
679
  w = WID (priv->builder, "typing_slow_keys_beep_rejected_checkbutton");
 
680
  g_settings_bind (priv->kb_settings, "slowkeys-beep-reject", w, "active", G_SETTINGS_BIND_DEFAULT);
 
681
 
 
682
  /* bounce keys */
 
683
  w = WID (priv->builder, "typing_bounce_keys_switch");
 
684
  settings_on_off_editor_new (priv, priv->kb_settings, "bouncekeys-enable", w, bounce_keys_section);
 
685
 
 
686
  w = WID (priv->builder, "typing_bouncekeys_delay_scale");
 
687
  g_settings_bind (priv->kb_settings, "bouncekeys-delay",
 
688
                   gtk_range_get_adjustment (GTK_RANGE (w)), "value",
 
689
                   G_SETTINGS_BIND_DEFAULT);
 
690
 
 
691
  w = WID (priv->builder, "typing_bounce_keys_beep_rejected_checkbutton");
 
692
  g_settings_bind (priv->kb_settings, "bouncekeys-beep-reject", w, "active", G_SETTINGS_BIND_NO_SENSITIVITY);
 
693
 
 
694
  g_signal_connect (WID (priv->builder, "typing_keyboard_preferences_link"),
 
695
                    "activate-link",
 
696
                    G_CALLBACK (typing_keyboard_preferences_clicked), self);
 
697
}
 
698
 
 
699
/* mouse/pointing & clicking section */
 
700
static gboolean
 
701
pointing_mouse_preferences_clicked_cb (GtkButton  *button,
 
702
                                       CcUaPanel  *panel)
 
703
{
 
704
  CcShell *shell;
 
705
 
 
706
  shell = cc_panel_get_shell (CC_PANEL (panel));
 
707
  cc_shell_set_active_panel_from_id (shell, "mouse", NULL, NULL);
 
708
 
 
709
  return TRUE;
 
710
}
 
711
 
 
712
static void
 
713
cc_ua_panel_init_mouse (CcUaPanel *self)
 
714
{
 
715
  CcUaPanelPrivate *priv = self->priv;
 
716
  GtkWidget *w;
 
717
 
 
718
  /* mouse keys */
 
719
  w = WID (priv->builder, "pointing_mouse_keys_switch");
 
720
  settings_on_off_editor_new (priv, priv->kb_settings, "mousekeys-enable", w, NULL);
 
721
 
 
722
  /* simulated secondary click */
 
723
  w = WID (priv->builder, "pointing_second_click_switch");
 
724
  settings_on_off_editor_new (priv, priv->mouse_settings, "secondary-click-enabled", w, secondary_click_section);
 
725
 
 
726
  w = WID (priv->builder, "pointing_secondary_click_delay_scale");
 
727
  g_settings_bind (priv->mouse_settings, "secondary-click-time",
 
728
                   gtk_range_get_adjustment (GTK_RANGE (w)), "value",
 
729
                   G_SETTINGS_BIND_DEFAULT);
 
730
 
 
731
  /* dwell click */
 
732
  w = WID (priv->builder, "pointing_hover_click_switch");
 
733
  settings_on_off_editor_new (priv, priv->mouse_settings, "dwell-click-enabled", w, dwell_click_section);
 
734
 
 
735
  w = WID (priv->builder, "pointing_dwell_delay_scale");
 
736
  g_settings_bind (priv->mouse_settings, "dwell-time",
 
737
                   gtk_range_get_adjustment (GTK_RANGE (w)), "value",
 
738
                   G_SETTINGS_BIND_DEFAULT);
 
739
 
 
740
  w = WID (priv->builder, "pointing_dwell_threshold_scale");
 
741
  g_settings_bind (priv->mouse_settings, "dwell-threshold",
 
742
                   gtk_range_get_adjustment (GTK_RANGE (w)), "value",
 
743
                   G_SETTINGS_BIND_DEFAULT);
 
744
 
 
745
  /* mouse preferences button */
 
746
  g_signal_connect (WID (priv->builder, "pointing_mouse_preferences_link"),
 
747
                    "activate-link",
 
748
                    G_CALLBACK (pointing_mouse_preferences_clicked_cb), self);
 
749
}
 
750
 
 
751
static void
 
752
cc_ua_panel_init (CcUaPanel *self)
 
753
{
 
754
  CcUaPanelPrivate *priv;
 
755
  GtkWidget *widget;
 
756
  GError *err = NULL;
 
757
  gchar *objects[] = { "universal_access_box", "contrast_model",
 
758
                       "text_size_model", "slowkeys_delay_adjustment",
 
759
                       "bouncekeys_delay_adjustment", "click_delay_adjustment",
 
760
                       "dwell_time_adjustment", "dwell_threshold_adjustment",
 
761
                       "seeing_sizegroup", "typing_sizegroup",
 
762
                       "pointing_sizegroup", "pointing_sizegroup2",
 
763
                       "pointing_scale_sizegroup", "sizegroup1",
 
764
                       "hearing_sizegroup",
 
765
                       NULL };
 
766
 
 
767
  priv = self->priv = UA_PANEL_PRIVATE (self);
 
768
 
 
769
  priv->builder = gtk_builder_new ();
 
770
 
 
771
  gtk_builder_add_objects_from_file (priv->builder,
 
772
                                     GNOMECC_UI_DIR "/uap.ui",
 
773
                                     objects,
 
774
                                     &err);
 
775
 
 
776
  if (err)
 
777
    {
 
778
      g_warning ("Could not load interface file: %s", err->message);
 
779
      g_error_free (err);
 
780
 
 
781
      g_object_unref (priv->builder);
 
782
      priv->builder = NULL;
 
783
 
 
784
      return;
 
785
    }
 
786
 
 
787
  priv->interface_settings = g_settings_new ("org.gnome.desktop.interface");
 
788
  g_signal_connect (priv->interface_settings, "changed",
 
789
                    G_CALLBACK (interface_settings_changed_cb), self);
 
790
  interface_settings_changed_cb (priv->interface_settings, "gtk-theme", self);
 
791
 
 
792
  priv->wm_settings = g_settings_new ("org.gnome.desktop.wm.preferences");
 
793
  priv->kb_settings = g_settings_new ("org.gnome.desktop.a11y.keyboard");
 
794
  priv->mouse_settings = g_settings_new ("org.gnome.desktop.a11y.mouse");
 
795
  priv->application_settings = g_settings_new ("org.gnome.desktop.a11y.applications");
 
796
  priv->mediakeys_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys");
 
797
 
 
798
  cc_ua_panel_init_keyboard (self);
 
799
  cc_ua_panel_init_mouse (self);
 
800
  cc_ua_panel_init_hearing (self);
 
801
  cc_ua_panel_init_seeing (self);
 
802
 
 
803
  widget = (GtkWidget*) gtk_builder_get_object (priv->builder,
 
804
                                                "universal_access_box");
 
805
 
 
806
  gtk_container_add (GTK_CONTAINER (self), widget);
 
807
}
 
808
 
 
809
void
 
810
cc_ua_panel_register (GIOModule *module)
 
811
{
 
812
  cc_ua_panel_register_type (G_TYPE_MODULE (module));
 
813
  g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
 
814
                                  CC_TYPE_UA_PANEL,
 
815
                                  "universal-access", 0);
 
816
}
 
817