From dc2468b27b7b41b5c2922611d3b6b676a53a0db8 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 2 Nov 2013 18:03:52 -0400 Subject: [PATCH] remoteSearch: Do filtering here of providers here We already do ordering at load time, so why not filtering? --- js/ui/remoteSearch.js | 17 ++++++++++++++--- js/ui/search.js | 21 +++------------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/js/ui/remoteSearch.js b/js/ui/remoteSearch.js index dd2928fc4..520d109ab 100644 --- a/js/ui/remoteSearch.js +++ b/js/ui/remoteSearch.js @@ -62,7 +62,7 @@ const SearchProvider2Iface = ' \ var SearchProviderProxyInfo = Gio.DBusInterfaceInfo.new_for_xml(SearchProviderIface); var SearchProvider2ProxyInfo = Gio.DBusInterfaceInfo.new_for_xml(SearchProvider2Iface); -function loadRemoteSearchProviders(addProviderCallback) { +function loadRemoteSearchProviders(callback) { let objectPaths = {}; let loadedProviders = []; @@ -116,6 +116,12 @@ function loadRemoteSearchProviders(addProviderCallback) { } } + let searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA }); + if (searchSettings.get_boolean('disable-external')) { + callback([]); + return; + } + let dataDirs = GLib.get_system_data_dirs(); dataDirs.forEach(function(dataDir) { let path = GLib.build_filenamev([dataDir, 'gnome-shell', 'search-providers']); @@ -134,12 +140,17 @@ function loadRemoteSearchProviders(addProviderCallback) { } }); - let searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA }); let sortOrder = searchSettings.get_strv('sort-order'); // Special case gnome-control-center to be always active and always first sortOrder.unshift('gnome-control-center.desktop'); + loadedProviders = loadedProviders.filter(function(provider) { + let appId = provider.appInfo.get_id(); + let disabled = searchSettings.get_strv('disabled'); + return disabled.indexOf(appId) == -1; + }); + loadedProviders.sort(function(providerA, providerB) { let idxA, idxB; let appIdA, appIdB; @@ -170,7 +181,7 @@ function loadRemoteSearchProviders(addProviderCallback) { return (idxA - idxB); }); - loadedProviders.forEach(addProviderCallback); + callback(loadedProviders); } const RemoteSearchProvider = new Lang.Class({ diff --git a/js/ui/search.js b/js/ui/search.js index dcaef41ed..b55b76a94 100644 --- a/js/ui/search.js +++ b/js/ui/search.js @@ -39,19 +39,6 @@ const SearchSystem = new Lang.Class({ this._reloadRemoteProviders(); }, - _shouldUseSearchProvider: function(provider) { - // the disable-external GSetting only affects remote providers - if (!provider.isRemoteProvider) - return true; - - if (this._searchSettings.get_boolean('disable-external')) - return false; - - let appId = provider.appInfo.get_id(); - let disable = this._searchSettings.get_strv('disabled'); - return disable.indexOf(appId) == -1; - }, - addProvider: function(provider) { this._providers.push(provider); this.emit('providers-changed'); @@ -65,12 +52,10 @@ const SearchSystem = new Lang.Class({ this._unregisterProvider(provider); })); - RemoteSearch.loadRemoteSearchProviders(Lang.bind(this, function(provider) { - if (!this._shouldUseSearchProvider(provider)) - return; - - this._registerProvider(provider); + RemoteSearch.loadRemoteSearchProviders(Lang.bind(this, function(providers) { + providers.forEach(Lang.bind(this, this._registerProvider)); })); + this.emit('providers-changed'); },