search: Port all search providers over to the async API

https://bugzilla.gnome.org/show_bug.cgi?id=675328
This commit is contained in:
Jasper St. Pierre 2012-05-02 15:45:37 -04:00
parent f2d883dab2
commit 58f77a19ed
4 changed files with 53 additions and 47 deletions

View File

@ -313,10 +313,11 @@ const AppSearchProvider = new Lang.Class({
_init: function() { _init: function() {
this.parent(_("APPLICATIONS")); this.parent(_("APPLICATIONS"));
this.async = true;
this._appSys = Shell.AppSystem.get_default(); this._appSys = Shell.AppSystem.get_default();
}, },
getResultMetas: function(apps) { getResultMetasAsync: function(apps, callback) {
let metas = []; let metas = [];
for (let i = 0; i < apps.length; i++) { for (let i = 0; i < apps.length; i++) {
let app = apps[i]; let app = apps[i];
@ -327,15 +328,15 @@ const AppSearchProvider = new Lang.Class({
} }
}); });
} }
return metas; callback(metas);
}, },
getInitialResultSet: function(terms) { getInitialResultSetAsync: function(terms) {
return this._appSys.initial_search(terms); this.searchSystem.pushResults(this, this._appSys.initial_search(terms));
}, },
getSubsearchResultSet: function(previousResults, terms) { getSubsearchResultSetAsync: function(previousResults, terms) {
return this._appSys.subsearch(previousResults, terms); this.searchSystem.pushResults(this, this._appSys.subsearch(previousResults, terms));
}, },
activateResult: function(app, params) { activateResult: function(app, params) {
@ -374,11 +375,12 @@ const SettingsSearchProvider = new Lang.Class({
_init: function() { _init: function() {
this.parent(_("SETTINGS")); this.parent(_("SETTINGS"));
this.async = true;
this._appSys = Shell.AppSystem.get_default(); this._appSys = Shell.AppSystem.get_default();
this._gnomecc = this._appSys.lookup_app('gnome-control-center.desktop'); this._gnomecc = this._appSys.lookup_app('gnome-control-center.desktop');
}, },
getResultMetas: function(prefs) { getResultMetasAsync: function(prefs, callback) {
let metas = []; let metas = [];
for (let i = 0; i < prefs.length; i++) { for (let i = 0; i < prefs.length; i++) {
let pref = prefs[i]; let pref = prefs[i];
@ -389,15 +391,15 @@ const SettingsSearchProvider = new Lang.Class({
} }
}); });
} }
return metas; callback(metas);
}, },
getInitialResultSet: function(terms) { getInitialResultSetAsync: function(terms) {
return this._appSys.search_settings(terms); this.searchSystem.pushResults(this, this._appSys.search_settings(terms));
}, },
getSubsearchResultSet: function(previousResults, terms) { getSubsearchResultSetAsync: function(previousResults, terms) {
return this._appSys.search_settings(terms); this.searchSystem.pushResults(this, this._appSys.search_settings(terms));
}, },
activateResult: function(pref, params) { activateResult: function(pref, params) {

View File

@ -151,10 +151,11 @@ const ContactSearchProvider = new Lang.Class({
_init: function() { _init: function() {
this.parent(_("CONTACTS")); this.parent(_("CONTACTS"));
this.async = true;
this._contactSys = Shell.ContactSystem.get_default(); this._contactSys = Shell.ContactSystem.get_default();
}, },
getResultMetas: function(ids) { getResultMetasAsync: function(ids, callback) {
let metas = []; let metas = [];
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
let contact = new Contact(ids[i]); let contact = new Contact(ids[i]);
@ -165,15 +166,15 @@ const ContactSearchProvider = new Lang.Class({
} }
}); });
} }
return metas; callback(metas);
}, },
getInitialResultSet: function(terms) { getInitialResultSetAsync: function(terms) {
return this._contactSys.initial_search(terms); this.searchSystem.pushResults(this, this._contactSys.initial_search(terms));
}, },
getSubsearchResultSet: function(previousResults, terms) { getSubsearchResultSetAsync: function(previousResults, terms) {
return this._contactSys.subsearch(previousResults, terms); this.searchSystem.pushResults(this, this._contactSys.subsearch(previousResults, terms));
}, },
createResultActor: function(resultMeta, terms) { createResultActor: function(resultMeta, terms) {

View File

@ -365,10 +365,11 @@ const PlaceSearchProvider = new Lang.Class({
_init: function() { _init: function() {
this.parent(_("PLACES & DEVICES")); this.parent(_("PLACES & DEVICES"));
this.async = true;
this.placesManager = new PlacesManager(); this.placesManager = new PlacesManager();
}, },
getResultMetas: function(resultIds) { getResultMetasAsync: function(resultIds, callback) {
let metas = []; let metas = [];
for (let i = 0; i < resultIds.length; i++) { for (let i = 0; i < resultIds.length; i++) {
let placeInfo = this.placesManager.lookupPlaceById(resultIds[i]); let placeInfo = this.placesManager.lookupPlaceById(resultIds[i]);
@ -382,7 +383,7 @@ const PlaceSearchProvider = new Lang.Class({
} }
}); });
} }
return metas; callback(metas);
}, },
activateResult: function(id, params) { activateResult: function(id, params) {
@ -413,18 +414,18 @@ const PlaceSearchProvider = new Lang.Class({
prefixResults.sort(Lang.bind(this, this._compareResultMeta)); prefixResults.sort(Lang.bind(this, this._compareResultMeta));
substringResults.sort(Lang.bind(this, this._compareResultMeta)); substringResults.sort(Lang.bind(this, this._compareResultMeta));
return prefixResults.concat(substringResults); this.searchSystem.pushResults(this, prefixResults.concat(substringResults));
}, },
getInitialResultSet: function(terms) { getInitialResultSetAsync: function(terms) {
let places = this.placesManager.getAllPlaces(); let places = this.placesManager.getAllPlaces();
return this._searchPlaces(places, terms); this._searchPlaces(places, terms);
}, },
getSubsearchResultSet: function(previousResults, terms) { getSubsearchResultSetAsync: function(previousResults, terms) {
let places = previousResults.map(Lang.bind(this, function(id) { let places = previousResults.map(Lang.bind(this, function(id) {
return this.placesManager.lookupPlaceById(id); return this.placesManager.lookupPlaceById(id);
})); }));
return this._searchPlaces(places, terms); this._searchPlaces(places, terms);
} }
}); });

View File

@ -166,36 +166,38 @@ const WandaSearchProvider = new Lang.Class({
_init: function() { _init: function() {
this.parent(_("Your favorite Easter Egg")); this.parent(_("Your favorite Easter Egg"));
this.async = true;
}, },
getResultMetas: function(fish) { getResultMetasAsync: function(fish, callback) {
return [{ 'id': fish[0], // there may be many fish in the sea, but callback([{ 'id': fish[0], // there may be many fish in the sea, but
// only one which speaks the truth! // only one which speaks the truth!
'name': capitalize(fish[0]), 'name': capitalize(fish[0]),
'createIcon': function(iconSize) { 'createIcon': function(iconSize) {
// for DND only (maybe could be improved) // for DND only (maybe could be improved)
// DON'T use St.Icon here, it crashes the shell // DON'T use St.Icon here, it crashes the shell
// (dnd.js code assumes it can query the actor size // (dnd.js code assumes it can query the actor size
// without parenting it, while StWidget accesses // without parenting it, while StWidget accesses
// StThemeNode in get_preferred_width/height, which // StThemeNode in get_preferred_width/height, which
// triggers an assertion failure) // triggers an assertion failure)
return St.TextureCache.get_default().load_icon_name(null, return St.TextureCache.get_default().load_icon_name(null,
'face-smile', 'face-smile',
St.IconType.FULLCOLOR, St.IconType.FULLCOLOR,
iconSize); iconSize);
} }
}]; }]);
}, },
getInitialResultSet: function(terms) { getInitialResultSetAsync: function(terms) {
if (terms.join(' ') == MAGIC_FISH_KEY) { if (terms.join(' ') == MAGIC_FISH_KEY) {
return [ FISH_NAME ]; this.searchSystem.pushResults(this, [ FISH_NAME ]);
} else {
this.searchSystem.pushResults(this, []);
} }
return [];
}, },
getSubsearchResultSet: function(previousResults, terms) { getSubsearchResultSetAsync: function(previousResults, terms) {
return this.getInitialResultSet(terms); this.getInitialResultSetAsync(terms);
}, },
activateResult: function(fish, params) { activateResult: function(fish, params) {