view-selector: filter out disabled search providers

If the added search provider has an appId in the list of the disabled
search providers settings, ignore it.

https://bugzilla.gnome.org/show_bug.cgi?id=687491
This commit is contained in:
Cosimo Cecchi 2012-11-01 10:33:40 -04:00
parent 80e7f5832b
commit 9791d15f39
2 changed files with 26 additions and 0 deletions

View File

@ -10,6 +10,8 @@ const Util = imports.misc.util;
const FileUtils = imports.misc.fileUtils;
const Main = imports.ui.main;
const SEARCH_PROVIDERS_SCHEMA = 'org.gnome.desktop.search-providers';
// Not currently referenced by the search API, but
// this enumeration can be useful for provider
// implementations.

View File

@ -94,6 +94,9 @@ const ViewSelector = new Lang.Class({
this._searchPage = this._addPage(this._searchResults.actor, this._entry,
_("Search"), 'edit-find-symbolic');
this._searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
this._searchSettings.connect('changed::disabled', Lang.bind(this, this._reloadRemoteProviders));
// Default search providers
// Wanda comes obviously first
this.addSearchProvider(new Wanda.WandaSearchProvider());
@ -435,7 +438,28 @@ const ViewSelector = new Lang.Class({
this._showPage(this._searchPage);
},
_shouldUseSearchProvider: function(provider) {
if (!provider.isRemoteProvider)
return true;
let appId = provider.appInfo.get_id();
let disable = this._searchSettings.get_strv('disabled');
return disable.indexOf(appId) == -1;
},
_reloadRemoteProviders: function() {
// removeSearchProvider() modifies the provider list we iterate on,
// so make a copy first
let remoteProviders = this._searchSystem.getRemoteProviders().slice(0);
remoteProviders.forEach(Lang.bind(this, this.removeSearchProvider));
RemoteSearch.loadRemoteSearchProviders(Lang.bind(this, this.addSearchProvider));
},
addSearchProvider: function(provider) {
if (!this._shouldUseSearchProvider(provider))
return;
this._searchSystem.registerProvider(provider);
this._searchResults.createProviderMeta(provider);
},