47 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
48 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
50 const Cc = Components.classes;
51 const Ci = Components.interfaces;
52 const Cr = Components.results;
54 const CONTRACTID =
"@mozilla.org/autocomplete/search;1?name=library-distinct-properties";
56 const CID = Components.ID(
"{1ed101bc-a11c-4e03-83af-514672bd3a70}");
65 gDefaultValues[
"audio"] = [
66 "Alternative",
"Blues/R&B",
"Books&Spoken",
"Children's Music",
67 "Classical",
"Comedy",
"Country",
"Dance",
"Easy Listening",
"World",
68 "Electronic",
"Folk",
"Hip Hop/Rap",
"Holiday",
"House",
"Industrial",
69 "Jazz",
"New Age",
"Nerdcore",
"Podcast",
"Pop",
"Reggae",
"Religious",
70 "Rock",
"Science",
"Soundtrack",
"Techno",
"Trance",
"Unclassifiable",
73 gDefaultValues[
"video"] = [
74 "Children's",
"Comedy",
"Drama",
"Entertainment",
"Healthcare & Fitness",
75 "Travel",
"Unclassifiable",
88 this._searchString = searchString;
89 this._defaultIndex = defaultIndex;
90 this._errorDescription = errorDescription;
91 this._results = results;
110 _errorDescription:
"",
122 return this._searchString;
133 if (this._results.length > 0) {
134 return Ci.nsIAutoCompleteResult.RESULT_SUCCESS;
136 return Ci.nsIAutoCompleteResult.RESULT_NOMATCH;
144 return this._defaultIndex;
150 get errorDescription() {
151 return this._errorDescription;
158 return this._results.length;
166 getValueAt:
function(index) {
167 return this._results[index];
175 getCommentAt:
function(index) {
184 getStyleAt:
function(index) {
185 if (!this._results[index])
189 return "suggestfirst";
191 return "suggesthint";
199 getImageAt:
function(index) {
207 removeValueAt:
function(index, removeFromDatabase) {
208 this._results.splice(index, 1);
218 if (!iid.equals(
Ci.nsIAutoCompleteResult) &&
219 !iid.equals(
Ci.nsISupports))
220 throw Cr.NS_ERROR_NO_INTERFACE;
240 var
os =
Cc[
"@mozilla.org/observer-service;1"]
241 .getService(
Ci.nsIObserverService);
259 _distinctValues:
null,
269 onSearchResult:
function(searchString, results) {
270 if (this._listener) {
277 this._listener.onSearchResult(
this, result);
281 this._listener =
null;
297 startSearch:
function(searchString, searchParam, previousResult,
listener) {
303 this.onSearchResult(searchString, []);
315 if (!this._distinctValues ||
316 this._cacheParam != searchParam) {
319 this._cacheParam = searchParam;
323 previousResult =
null;
326 this._distinctValues = {};
331 Cc[
"@songbirdnest.com/Songbird/library/Manager;1"]
332 .getService(
Ci.sbILibraryManager);
336 var params = searchParam.split(
";");
338 var properties = params[0].split(
"$");
339 this._prop = properties[0];
340 this._type = properties[1] ||
"audio";
342 var guid = params[1];
343 var additionalValues = params[2];
344 this._conversionUnit = params[3];
346 if (this._type !=
"video") {
348 function getDistinctValues(aLibrary, prop, obj) {
351 var values = aLibrary.getDistinctValuesForProperty(prop);
352 while (values.hasMore()) {
354 obj._distinctValues[values.getNext()] =
true;
361 if (guid && guid.length > 0) {
366 while (libs.hasMoreElements()) {
367 getDistinctValues(libs.getNext(), this._prop,
this);
374 if (additionalValues && additionalValues.length > 0) {
375 var values = additionalValues.split(
",");
376 for each (var
value in values) {
377 this._distinctValues[
value] =
true;
382 this._addDefaultDistinctValues();
387 this.
_timer =
Cc[
"@mozilla.org/timer;1"].createInstance(
Ci.nsITimer);
390 this.
_timer.initWithCallback(
this, 5000, this.
_timer.TYPE_ONE_SHOT);
394 var
search = searchString.toLowerCase();
397 function startsWith(aString, aPartial) {
400 aString.toLowerCase().slice(0, aPartial.length) == aPartial);
409 if (previousResult &&
410 startsWith(search, this._lastSearch)) {
411 for (var
i = 0 ;
i < previousResult.matchCount ;
i++) {
412 var value = previousResult.getValueAt(
i);
413 if (startsWith(value, search))
419 if (this._conversionUnit && this._conversionUnit !=
"") {
420 var propertyManager =
421 Cc[
"@songbirdnest.com/Songbird/Properties/PropertyManager;1"]
422 .getService(
Ci.sbIPropertyManager);
423 var info = propertyManager.getPropertyInfo(this._prop);
424 converter = info.unitConverter;
427 for (var value in this._distinctValues) {
429 value = converter.convert(value,
430 converter.nativeUnitId,
431 this._conversionUnit,
434 if (startsWith(value, search))
441 this._lastSearch =
search;
444 this.onSearchResult(searchString, results);
449 this._lastSearch =
null;
450 this._distinctValues =
null;
457 stopSearch:
function() {
464 _addDefaultDistinctValues:
function() {
465 var
defaults = gDefaultValues[this._type];
467 for each (var value
in defaults) {
468 this._distinctValues[
value] =
true;
476 observe:
function SAC_observe(aSubject, aTopic,
aData) {
485 var
os =
Cc[
"@mozilla.org/observer-service;1"]
486 .getService(
Ci.nsIObserverService);
499 XPCOMUtils.generateQI([
Ci.nsIAutoCompleteSearch,
const XPCOM_SHUTDOWN_TOPIC
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function NSGetModule(compMgr, fileSpec)
sbDeviceFirmwareAutoCheckForUpdate prototype _timer
TimerLoop prototype notify
function search(aFolderId, aSearchStr, aExpectedScopeButtonId)
function AutoCompleteResult(searchString, defaultIndex, errorDescription, results)
sbAutoDownloader prototype _libraryManager
sbDeviceFirmwareAutoCheckForUpdate prototype classID
function LibrarySearchSuggester()
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe