status/keyboard: Store IBus engine properties per InputSource object

Instead of storing them globally and having an hardcoded list of
engines which are allowed to change their indicator symbol when the
InputMode property changes.

https://bugzilla.gnome.org/show_bug.cgi?id=682318
This commit is contained in:
Rui Matos 2012-12-13 20:48:13 +01:00
parent c41424b57b
commit 2008feb7da

View File

@ -47,6 +47,7 @@ const IBusManager = new Lang.Class({
this._engines = {}; this._engines = {};
this._ready = false; this._ready = false;
this._registerPropertiesId = 0; this._registerPropertiesId = 0;
this._currentEngineName = null;
this._nameWatcherId = Gio.DBus.session.watch_name(IBus.SERVICE_IBUS, this._nameWatcherId = Gio.DBus.session.watch_name(IBus.SERVICE_IBUS,
Gio.BusNameWatcherFlags.NONE, Gio.BusNameWatcherFlags.NONE,
@ -66,6 +67,7 @@ const IBusManager = new Lang.Class({
this._engines = {}; this._engines = {};
this._ready = false; this._ready = false;
this._registerPropertiesId = 0; this._registerPropertiesId = 0;
this._currentEngineName = null;
}, },
_onNameAppeared: function() { _onNameAppeared: function() {
@ -105,9 +107,15 @@ const IBusManager = new Lang.Class({
this._candidatePopup.setPanelService(this._panelService); this._candidatePopup.setPanelService(this._panelService);
// Need to set this to get 'global-engine-changed' emitions // Need to set this to get 'global-engine-changed' emitions
this._ibus.set_watch_ibus_signal(true); this._ibus.set_watch_ibus_signal(true);
this._ibus.connect('global-engine-changed', Lang.bind(this, this._resetProperties)); this._ibus.connect('global-engine-changed', Lang.bind(this, this._engineChanged));
this._panelService.connect('update-property', Lang.bind(this, this._updateProperty)); this._panelService.connect('update-property', Lang.bind(this, this._updateProperty));
this._resetProperties(); // If an engine is already active we need to get its properties
this._ibus.get_global_engine_async(-1, null, Lang.bind(this, function(i, result) {
let engine = this._ibus.get_global_engine_async_finish(result);
if (!engine)
return;
this._engineChanged(this._ibus, engine.get_name());
}));
} else { } else {
this._clear(); this._clear();
return; return;
@ -124,8 +132,8 @@ const IBusManager = new Lang.Class({
this._readyCallback(); this._readyCallback();
}, },
_resetProperties: function() { _engineChanged: function(bus, engineName) {
this.emit('properties-registered', null); this._currentEngineName = engineName;
if (this._registerPropertiesId != 0) if (this._registerPropertiesId != 0)
return; return;
@ -138,25 +146,18 @@ const IBusManager = new Lang.Class({
this._panelService.disconnect(this._registerPropertiesId); this._panelService.disconnect(this._registerPropertiesId);
this._registerPropertiesId = 0; this._registerPropertiesId = 0;
this.emit('properties-registered', props); this.emit('properties-registered', this._currentEngineName, props);
})); }));
}, },
_updateProperty: function(panel, prop) { _updateProperty: function(panel, prop) {
this.emit('property-updated', prop); this.emit('property-updated', this._currentEngineName, prop);
}, },
activateProperty: function(key, state) { activateProperty: function(key, state) {
this._panelService.property_activate(key, state); this._panelService.property_activate(key, state);
}, },
hasProperties: function(id) {
if (id == 'anthy')
return true;
return false;
},
getEngineDesc: function(id) { getEngineDesc: function(id) {
if (!IBus || !this._ready) if (!IBus || !this._ready)
return null; return null;
@ -194,6 +195,8 @@ const InputSource = new Lang.Class({
this._menuItem = new LayoutMenuItem(this.displayName, this._shortName); this._menuItem = new LayoutMenuItem(this.displayName, this._shortName);
this._menuItem.connect('activate', Lang.bind(this, this.activate)); this._menuItem.connect('activate', Lang.bind(this, this.activate));
this._indicatorLabel = new St.Label({ text: this._shortName }); this._indicatorLabel = new St.Label({ text: this._shortName });
this.properties = null;
}, },
destroy: function() { destroy: function() {
@ -242,6 +245,10 @@ const InputSourceIndicator = new Lang.Class({
// All valid input sources currently in the gsettings // All valid input sources currently in the gsettings
// KEY_INPUT_SOURCES list indexed by their index there // KEY_INPUT_SOURCES list indexed by their index there
this._inputSources = {}; this._inputSources = {};
// All valid input sources currently in the gsettings
// KEY_INPUT_SOURCES list of type INPUT_SOURCE_TYPE_IBUS
// indexed by the IBus ID
this._ibusSources = {};
this._currentSource = null; this._currentSource = null;
@ -257,8 +264,6 @@ const InputSourceIndicator = new Lang.Class({
this.menu.addMenuItem(this._propSection); this.menu.addMenuItem(this._propSection);
this._propSection.actor.hide(); this._propSection.actor.hide();
this._properties = null;
this._ibusManager = new IBusManager(Lang.bind(this, this._inputSourcesChanged)); this._ibusManager = new IBusManager(Lang.bind(this, this._inputSourcesChanged));
this._ibusManager.connect('properties-registered', Lang.bind(this, this._ibusPropertiesRegistered)); this._ibusManager.connect('properties-registered', Lang.bind(this, this._ibusPropertiesRegistered));
this._ibusManager.connect('property-updated', Lang.bind(this, this._ibusPropertyUpdated)); this._ibusManager.connect('property-updated', Lang.bind(this, this._ibusPropertyUpdated));
@ -285,14 +290,8 @@ const InputSourceIndicator = new Lang.Class({
let nVisibleSources = Object.keys(this._inputSources).length; let nVisibleSources = Object.keys(this._inputSources).length;
let newSourceIndex = this._settings.get_uint(KEY_CURRENT_INPUT_SOURCE); let newSourceIndex = this._settings.get_uint(KEY_CURRENT_INPUT_SOURCE);
let newSource = this._inputSources[newSourceIndex]; let newSource = this._inputSources[newSourceIndex];
let hasProperties;
if (newSource) if (!newSource || (nVisibleSources < 2 && !newSource.properties)) {
hasProperties = this._ibusManager.hasProperties(newSource.id);
else
hasProperties = false;
if (!newSource || (nVisibleSources < 2 && !hasProperties)) {
// This source index might be invalid if we weren't able // This source index might be invalid if we weren't able
// to build a menu item for it, so we hide ourselves since // to build a menu item for it, so we hide ourselves since
// we can't fix it here. *shrug* // we can't fix it here. *shrug*
@ -314,10 +313,10 @@ const InputSourceIndicator = new Lang.Class({
this._container.set_skip_paint(oldSource.indicatorLabel, true); this._container.set_skip_paint(oldSource.indicatorLabel, true);
} }
if (hasProperties)
newSource.indicatorLabel.set_text(newSource.shortName);
newSource.menuItem.setShowDot(true); newSource.menuItem.setShowDot(true);
this._container.set_skip_paint(newSource.indicatorLabel, false); this._container.set_skip_paint(newSource.indicatorLabel, false);
this._buildPropSection(newSource.properties);
}, },
_inputSourcesChanged: function() { _inputSourcesChanged: function() {
@ -328,6 +327,7 @@ const InputSourceIndicator = new Lang.Class({
this._inputSources[i].destroy(); this._inputSources[i].destroy();
this._inputSources = {}; this._inputSources = {};
this._ibusSources = {};
let inputSourcesByShortName = {}; let inputSourcesByShortName = {};
@ -365,6 +365,9 @@ const InputSourceIndicator = new Lang.Class({
inputSourcesByShortName[is.shortName].push(is); inputSourcesByShortName[is.shortName].push(is);
this._inputSources[is.index] = is; this._inputSources[is.index] = is;
if (is.type == INPUT_SOURCE_TYPE_IBUS)
this._ibusSources[is.id] = is;
} }
let menuIndex = 0; let menuIndex = 0;
@ -423,14 +426,25 @@ const InputSourceIndicator = new Lang.Class({
return String.fromCharCode(0x2328); // keyboard glyph return String.fromCharCode(0x2328); // keyboard glyph
}, },
_ibusPropertiesRegistered: function(im, props) { _ibusPropertiesRegistered: function(im, engineName, props) {
this._properties = props; let source = this._ibusSources[engineName];
this._buildPropSection(); if (!source)
return;
source.properties = props;
if (source == this._currentSource)
this._currentInputSourceChanged();
}, },
_ibusPropertyUpdated: function(im, prop) { _ibusPropertyUpdated: function(im, engineName, prop) {
if (this._updateSubProperty(this._properties, prop)) let source = this._ibusSources[engineName];
this._buildPropSection(); if (!source)
return;
if (this._updateSubProperty(source.properties, prop) &&
source == this._currentSource)
this._currentInputSourceChanged();
}, },
_updateSubProperty: function(props, prop) { _updateSubProperty: function(props, prop) {
@ -450,18 +464,12 @@ const InputSourceIndicator = new Lang.Class({
return false; return false;
}, },
_updateIndicatorLabel: function(text) { _buildPropSection: function(properties) {
let hasProperties = this._ibusManager.hasProperties(this._currentSource.id);
if (hasProperties)
this._currentSource.indicatorLabel.set_text(text);
},
_buildPropSection: function() {
this._propSeparator.actor.hide(); this._propSeparator.actor.hide();
this._propSection.actor.hide(); this._propSection.actor.hide();
this._propSection.removeAll(); this._propSection.removeAll();
this._buildPropSubMenu(this._propSection, this._properties); this._buildPropSubMenu(this._propSection, properties);
if (!this._propSection.isEmpty()) { if (!this._propSection.isEmpty()) {
this._propSection.actor.show(); this._propSection.actor.show();
@ -489,7 +497,7 @@ const InputSourceIndicator = new Lang.Class({
text = prop.get_label().get_text(); text = prop.get_label().get_text();
if (text && text.length > 0 && text.length < 3) if (text && text.length > 0 && text.length < 3)
this._updateIndicatorLabel(text); this._currentSource.indicatorLabel.set_text(text);
} }
let item; let item;