25 if (typeof(
Cc) ==
"undefined")
26 var
Cc = Components.classes;
27 if (typeof(
Ci) ==
"undefined")
28 var
Ci = Components.interfaces;
29 if (typeof(
Cr) ==
"undefined")
30 var
Cr = Components.results;
31 if (typeof(
Cu) ==
"undefined")
32 var
Cu = Components.utils;
34 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
35 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
36 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
55 this.library =
window.arguments[0].QueryInterface(Ci.sbIDeviceLibrary);
56 this._device = this.library.device;
57 this._metadataResults = ArrayConverter.JSArray(
58 window.arguments[1].QueryInterface(
59 Ci.nsISimpleEnumerator));
61 this._infolist = document.getElementById(
"infolist");
62 this._other = document.getElementById(
"other");
64 this._jobTracksMap = [];
65 this._jobResultIndexMap =
66 Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
67 .createInstance(Ci.nsIMutableArray);
69 for (
i in this._metadataResults)
71 var result = this._metadataResults[
i];
72 result.QueryInterface(Ci.sbIMetadataAlbumDetail);
73 var props = SBProperties.arrayToJSObject(result.properties);
76 this._infolist.insertItemAt(
77 this._infolist.getIndexOfItem(
this._other),
79 [props[SBProperties.artistName],
80 props[SBProperties.albumName]]),
83 var tracks = document.createElementNS(
84 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
87 tracks.setAttribute(
"first-sb-cdtracks",
"true");
89 this._infolist.insertBefore(tracks, this._other);
92 var mlm = Cc[
"@songbirdnest.com/Songbird/MetadataLookup/manager;1"]
93 .getService(Ci.sbIMetadataLookupManager);
94 var job = mlm.defaultProvider.getAlbumDetail(result);
97 this._jobResultIndexMap.appendElement(job,
false);
99 this._jobTracksMap[
i] = tracks;
100 if (job.status == Ci.sbIJobProgress.STATUS_RUNNING) {
101 job.addJobProgressListener(
this);
103 this.onJobProgress(job);
107 this._infolist.selectedIndex = 0;
110 var deviceManager = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
111 .getService(Ci.sbIDeviceManager2);
112 deviceManager.addEventListener(
this);
118 onunload:
function onunload()
121 var deviceManager = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
122 .getService(Ci.sbIDeviceManager2);
123 deviceManager.removeEventListener(
this);
129 onJobProgress:
function onJobProgress(job)
131 job.QueryInterface(Ci.sbIMetadataLookupJob);
132 if (job.status != Ci.sbIJobProgress.STATUS_SUCCEEDED)
135 if (job.mlJobType != Ci.sbIMetadataLookupJob.JOB_ALBUM_DETAIL_LOOKUP)
138 function getname(props) {
139 return SBProperties.arrayToJSObject(props)[SBProperties.trackName];
142 var index = this._jobResultIndexMap.indexOf(0, job);
143 var tracks = this._jobTracksMap[index];
145 var enumDetails = job.getMetadataResults();
146 var result = enumDetails.getNext().QueryInterface(Ci.sbIMetadataAlbumDetail);
147 tracks.setTrackTitles(ArrayConverter.JSArray(result.tracks).map(getname));
148 this._metadataResults[index] = result;
154 onSelectionChange:
function onSelectionChange()
160 document.getElementById(
"artist-textbox").disabled =
161 (this._infolist.value !=
"other");
162 document.getElementById(
"album-textbox").disabled =
163 (this._infolist.value !=
"other");
169 onaccept:
function onaccept()
171 if (this._infolist.value ==
"other")
173 this._artistValue = document.getElementById(
"artist-textbox").value ||
174 SBString(
"cdrip.lookup.default_artistname");
175 this._albumValue = document.getElementById(
"album-textbox").value ||
176 SBString(
"cdrip.lookup.default_albumname");
179 if (document.getElementById(
"album-textbox").value)
180 this.library.setProperty(SBProperties.albumName,
this._albumValue);
182 this._setEmptyOnly =
false;
183 this.library.enumerateAllItems(
this);
187 var result = this._metadataResults[parseInt(this._infolist.value)];
188 var tracks = ArrayConverter.JSArray(result.tracks);
190 if (tracks.length > 0) {
192 this.library.setProperty
193 (SBProperties.albumName,
194 result.properties.getPropertyValue(SBProperties.albumName));
197 for (var
i=0;
i < tracks.length;
i++) {
200 var trackArr = this.library.getItemsByProperty(SBProperties.trackNumber,
202 var item = trackArr.queryElementAt(0, Ci.sbIMediaItem);
203 item.setProperties(tracks[
i]);
210 onDeviceEvent:
function onDeviceEvent(aEvent) {
211 switch(aEvent.type) {
212 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED :
214 if (aEvent.data ==
this._device)
226 oncancel:
function oncancel()
229 this._artistValue =
SBString(
"cdrip.lookup.default_artistname");
230 this._albumValue =
SBString(
"cdrip.lookup.default_albumname");
232 this._setEmptyOnly =
true;
233 this.library.enumerateAllItems(
this);
239 onEnumerationBegin:
function (aList) {},
240 onEnumeratedItem:
function (aList, aItem)
242 if (!this._setEmptyOnly || !aItem.getProperty(SBProperties.albumArtistName))
243 aItem.setProperty(SBProperties.albumArtistName,
this._artistValue);
244 if (!this._setEmptyOnly || !aItem.getProperty(SBProperties.artistName))
245 aItem.setProperty(SBProperties.artistName,
this._artistValue);
246 if (!this._setEmptyOnly || !aItem.getProperty(SBProperties.albumName))
247 aItem.setProperty(SBProperties.albumName,
this._albumValue);
249 if (!aItem.getProperty(SBProperties.trackName)) {
252 var curTrackNum = this._curTrackIndex++;
253 if (curTrackNum < 10 && this.library.length >= 10) {
254 curTrackNum =
"0" + curTrackNum;
256 aItem.setProperty(SBProperties.trackName,
261 onEnumerationEnd:
function (aList, aStatus) {}
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
function SBString(aKey, aDefault, aStringBundle)
_getSelectedPageStyle s i