From 9791d15f3918a549914cc470d8e58c94bc260e66 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 1 Nov 2012 10:33:40 -0400 Subject: [PATCH] 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 --- js/ui/search.js | 2 ++ js/ui/viewSelector.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/js/ui/search.js b/js/ui/search.js index bc50cb0a4..2e746d8ca 100644 --- a/js/ui/search.js +++ b/js/ui/search.js @@ -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. diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js index 4d096ba49..d2edfcbed 100644 --- a/js/ui/viewSelector.js +++ b/js/ui/viewSelector.js @@ -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); },