2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-07-21 08:44:59 +00:00
|
|
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2010-11-30 17:58:05 +00:00
|
|
|
const A11Y_SCHEMA = 'org.gnome.desktop.a11y.keyboard';
|
|
|
|
const KEY_STICKY_KEYS_ENABLED = 'stickykeys-enable';
|
|
|
|
const KEY_BOUNCE_KEYS_ENABLED = 'bouncekeys-enable';
|
|
|
|
const KEY_SLOW_KEYS_ENABLED = 'slowkeys-enable';
|
|
|
|
const KEY_MOUSE_KEYS_ENABLED = 'mousekeys-enable';
|
2010-07-21 08:44:59 +00:00
|
|
|
|
2011-02-17 15:05:22 +00:00
|
|
|
const APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
|
2010-07-21 08:44:59 +00:00
|
|
|
|
|
|
|
const DPI_LOW_REASONABLE_VALUE = 50;
|
|
|
|
const DPI_HIGH_REASONABLE_VALUE = 500;
|
|
|
|
|
|
|
|
const DPI_FACTOR_LARGE = 1.25;
|
|
|
|
const DPI_FACTOR_LARGER = 1.5;
|
|
|
|
const DPI_FACTOR_LARGEST = 2.0;
|
|
|
|
|
2011-06-27 01:54:26 +00:00
|
|
|
const WM_SCHEMA = 'org.gnome.desktop.wm.preferences';
|
2011-11-14 14:34:42 +00:00
|
|
|
const KEY_VISUAL_BELL = 'visual-bell';
|
2010-07-21 08:44:59 +00:00
|
|
|
|
2010-11-30 17:58:05 +00:00
|
|
|
const DESKTOP_INTERFACE_SCHEMA = 'org.gnome.desktop.interface';
|
|
|
|
const KEY_GTK_THEME = 'gtk-theme';
|
|
|
|
const KEY_ICON_THEME = 'icon-theme';
|
2011-03-03 16:01:19 +00:00
|
|
|
const KEY_TEXT_SCALING_FACTOR = 'text-scaling-factor';
|
2010-07-21 08:44:59 +00:00
|
|
|
|
2010-11-30 17:58:05 +00:00
|
|
|
const HIGH_CONTRAST_THEME = 'HighContrast';
|
2010-07-21 08:44:59 +00:00
|
|
|
|
2011-11-20 14:38:48 +00:00
|
|
|
const ATIndicator = new Lang.Class({
|
|
|
|
Name: 'ATIndicator',
|
|
|
|
Extends: PanelMenu.SystemStatusButton,
|
2010-07-21 08:44:59 +00:00
|
|
|
|
|
|
|
_init: function() {
|
2012-05-30 13:58:37 +00:00
|
|
|
this.parent('preferences-desktop-accessibility-symbolic', _("Accessibility"));
|
2010-07-21 08:44:59 +00:00
|
|
|
|
|
|
|
let highContrast = this._buildHCItem();
|
|
|
|
this.menu.addMenuItem(highContrast);
|
|
|
|
|
2011-02-17 15:05:22 +00:00
|
|
|
let magnifier = this._buildItem(_("Zoom"), APPLICATIONS_SCHEMA,
|
|
|
|
'screen-magnifier-enabled');
|
2010-07-21 08:44:59 +00:00
|
|
|
this.menu.addMenuItem(magnifier);
|
|
|
|
|
2010-11-12 18:37:51 +00:00
|
|
|
let textZoom = this._buildFontItem();
|
2010-07-21 08:44:59 +00:00
|
|
|
this.menu.addMenuItem(textZoom);
|
|
|
|
|
2012-06-15 21:54:04 +00:00
|
|
|
let screenReader = this._buildItem(_("Screen Reader"), APPLICATIONS_SCHEMA,
|
|
|
|
'screen-reader-enabled');
|
|
|
|
this.menu.addMenuItem(screenReader);
|
2010-07-21 08:44:59 +00:00
|
|
|
|
2011-08-29 17:02:42 +00:00
|
|
|
let screenKeyboard = this._buildItem(_("Screen Keyboard"), APPLICATIONS_SCHEMA,
|
|
|
|
'screen-keyboard-enabled');
|
|
|
|
this.menu.addMenuItem(screenKeyboard);
|
2010-07-21 08:44:59 +00:00
|
|
|
|
2011-11-14 14:34:42 +00:00
|
|
|
let visualBell = this._buildItem(_("Visual Alerts"), WM_SCHEMA, KEY_VISUAL_BELL);
|
2010-07-21 08:44:59 +00:00
|
|
|
this.menu.addMenuItem(visualBell);
|
|
|
|
|
2010-11-12 16:36:41 +00:00
|
|
|
let stickyKeys = this._buildItem(_("Sticky Keys"), A11Y_SCHEMA, KEY_STICKY_KEYS_ENABLED);
|
2010-07-21 08:44:59 +00:00
|
|
|
this.menu.addMenuItem(stickyKeys);
|
|
|
|
|
2010-11-12 16:36:41 +00:00
|
|
|
let slowKeys = this._buildItem(_("Slow Keys"), A11Y_SCHEMA, KEY_SLOW_KEYS_ENABLED);
|
2010-07-21 08:44:59 +00:00
|
|
|
this.menu.addMenuItem(slowKeys);
|
|
|
|
|
2010-11-12 16:36:41 +00:00
|
|
|
let bounceKeys = this._buildItem(_("Bounce Keys"), A11Y_SCHEMA, KEY_BOUNCE_KEYS_ENABLED);
|
2010-07-21 08:44:59 +00:00
|
|
|
this.menu.addMenuItem(bounceKeys);
|
|
|
|
|
2010-11-12 16:36:41 +00:00
|
|
|
let mouseKeys = this._buildItem(_("Mouse Keys"), A11Y_SCHEMA, KEY_MOUSE_KEYS_ENABLED);
|
2010-07-21 08:44:59 +00:00
|
|
|
this.menu.addMenuItem(mouseKeys);
|
|
|
|
|
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2011-08-23 14:14:55 +00:00
|
|
|
this.menu.addSettingsAction(_("Universal Access Settings"), 'gnome-universal-access-panel.desktop');
|
2010-07-21 08:44:59 +00:00
|
|
|
},
|
|
|
|
|
2012-05-22 22:27:06 +00:00
|
|
|
setLockedState: function(locked) {
|
2012-08-16 17:02:31 +00:00
|
|
|
this.actor.visible = !locked;
|
2012-05-22 22:27:06 +00:00
|
|
|
},
|
|
|
|
|
2010-07-21 08:44:59 +00:00
|
|
|
_buildItemExtended: function(string, initial_value, writable, on_set) {
|
|
|
|
let widget = new PopupMenu.PopupSwitchMenuItem(string, initial_value);
|
|
|
|
if (!writable)
|
|
|
|
widget.actor.reactive = false;
|
|
|
|
else
|
|
|
|
widget.connect('toggled', function(item) {
|
|
|
|
on_set(item.state);
|
|
|
|
});
|
|
|
|
return widget;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildItem: function(string, schema, key) {
|
|
|
|
let settings = new Gio.Settings({ schema: schema });
|
|
|
|
let widget = this._buildItemExtended(string,
|
|
|
|
settings.get_boolean(key),
|
|
|
|
settings.is_writable(key),
|
|
|
|
function(enabled) {
|
|
|
|
return settings.set_boolean(key, enabled);
|
|
|
|
});
|
|
|
|
settings.connect('changed::'+key, function() {
|
|
|
|
widget.setToggleState(settings.get_boolean(key));
|
|
|
|
});
|
|
|
|
return widget;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildHCItem: function() {
|
|
|
|
let settings = new Gio.Settings({ schema: DESKTOP_INTERFACE_SCHEMA });
|
|
|
|
let gtkTheme = settings.get_string(KEY_GTK_THEME);
|
|
|
|
let iconTheme = settings.get_string(KEY_ICON_THEME);
|
|
|
|
let hasHC = (gtkTheme == HIGH_CONTRAST_THEME);
|
|
|
|
let highContrast = this._buildItemExtended(
|
|
|
|
_("High Contrast"),
|
|
|
|
hasHC,
|
|
|
|
settings.is_writable(KEY_GTK_THEME) && settings.is_writable(KEY_ICON_THEME),
|
|
|
|
function (enabled) {
|
|
|
|
if (enabled) {
|
|
|
|
settings.set_string(KEY_GTK_THEME, HIGH_CONTRAST_THEME);
|
|
|
|
settings.set_string(KEY_ICON_THEME, HIGH_CONTRAST_THEME);
|
2011-02-18 15:15:35 +00:00
|
|
|
} else if(!hasHC) {
|
2010-07-21 08:44:59 +00:00
|
|
|
settings.set_string(KEY_GTK_THEME, gtkTheme);
|
|
|
|
settings.set_string(KEY_ICON_THEME, iconTheme);
|
2011-02-18 15:15:35 +00:00
|
|
|
} else {
|
|
|
|
settings.reset(KEY_GTK_THEME);
|
|
|
|
settings.reset(KEY_ICON_THEME);
|
2010-07-21 08:44:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
settings.connect('changed::' + KEY_GTK_THEME, function() {
|
|
|
|
let value = settings.get_string(KEY_GTK_THEME);
|
|
|
|
if (value == HIGH_CONTRAST_THEME) {
|
|
|
|
highContrast.setToggleState(true);
|
|
|
|
} else {
|
|
|
|
highContrast.setToggleState(false);
|
|
|
|
gtkTheme = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
settings.connect('changed::' + KEY_ICON_THEME, function() {
|
|
|
|
let value = settings.get_string(KEY_ICON_THEME);
|
|
|
|
if (value != HIGH_CONTRAST_THEME)
|
|
|
|
iconTheme = value;
|
|
|
|
});
|
|
|
|
return highContrast;
|
|
|
|
},
|
|
|
|
|
2010-11-12 18:37:51 +00:00
|
|
|
_buildFontItem: function() {
|
2011-03-03 16:01:19 +00:00
|
|
|
let settings = new Gio.Settings({ schema: DESKTOP_INTERFACE_SCHEMA });
|
2010-11-12 16:36:41 +00:00
|
|
|
|
2011-03-03 16:01:19 +00:00
|
|
|
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
|
|
|
|
let initial_setting = (factor > 1.0);
|
2010-09-18 15:29:05 +00:00
|
|
|
let widget = this._buildItemExtended(_("Large Text"),
|
2010-07-21 08:44:59 +00:00
|
|
|
initial_setting,
|
2011-03-03 16:01:19 +00:00
|
|
|
settings.is_writable(KEY_TEXT_SCALING_FACTOR),
|
2010-07-21 08:44:59 +00:00
|
|
|
function (enabled) {
|
|
|
|
if (enabled)
|
2011-03-03 16:01:19 +00:00
|
|
|
settings.set_double(KEY_TEXT_SCALING_FACTOR,
|
|
|
|
DPI_FACTOR_LARGE);
|
2010-07-21 08:44:59 +00:00
|
|
|
else
|
2011-03-03 16:01:19 +00:00
|
|
|
settings.reset(KEY_TEXT_SCALING_FACTOR);
|
2010-07-21 08:44:59 +00:00
|
|
|
});
|
2011-03-03 16:01:19 +00:00
|
|
|
settings.connect('changed::' + KEY_TEXT_SCALING_FACTOR, function() {
|
|
|
|
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
|
|
|
|
let active = (factor > 1.0);
|
2010-11-12 16:36:41 +00:00
|
|
|
widget.setToggleState(active);
|
2010-07-21 08:44:59 +00:00
|
|
|
});
|
|
|
|
return widget;
|
|
|
|
}
|
2011-11-20 14:38:48 +00:00
|
|
|
});
|