49 Components.utils.import(
"resource://app/jsmodules/DOMUtils.jsm");
50 Components.utils.import(
"resource://app/jsmodules/SBJobUtils.jsm");
51 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
61 if (typeof(
Cc) ==
"undefined")
62 var
Cc = Components.classes;
63 if (typeof(
Ci) ==
"undefined")
64 var
Ci = Components.interfaces;
65 if (typeof(
Cr) ==
"undefined")
66 var
Cr = Components.results;
67 if (typeof(
Cu) ==
"undefined")
68 var
Cu = Components.utils;
93 var importLibraryPrefsUI = {
103 _userReadableLibraryType:
null,
104 _defaultLibraryFileName:
null,
105 _libraryFileExtFilter:
null,
119 initialize:
function importLibraryPrefsUI_initialize() {
122 this._userReadableLibraryType =
"iTunes";
123 this._defaultLibraryFileName =
"iTunes Music Library.xml";
124 this._libraryFileExtFilter =
"*.xml";
127 this.
_prefBranch = Cc[
"@mozilla.org/preferences-service;1"]
128 .getService(Ci.nsIPrefBranch);
139 readPrefs:
function importLibraryPrefsUI_readPrefs() {
141 var prefElemList = DOMUtils.getElementsByAttribute(document,
"prefname");
142 for (var
i = 0;
i < prefElemList.length;
i++) {
144 var prefElem = prefElemList[
i];
147 if (prefElem.localName ==
"preference")
151 var prefValue = this._readPrefValue(prefElem);
152 this._setPrefElemValue(prefElem, prefValue);
164 writePrefs:
function importLibraryPrefsUI_writePrefs() {
166 var prefElemList = DOMUtils.getElementsByAttribute(document,
"prefname");
167 for (var
i = 0;
i < prefElemList.length;
i++) {
169 var prefElem = prefElemList[
i];
172 if (prefElem.localName ==
"preference")
176 var prefValue = this._getPrefElemValue(prefElem);
177 this._writePrefValue(prefElem, prefValue);
194 doBrowseCommand:
function importLibraryPrefsUI_doBrowseCommand(aEvent) {
196 var importLibraryPathPrefElem = this._getPrefElem(
"library_file_path_pref");
197 var importLibraryFile = Cc[
"@mozilla.org/file/local;1"]
198 .createInstance(Ci.nsILocalFile);
199 var importLibraryDir =
null;
201 importLibraryFile.initWithPath(importLibraryPathPrefElem.value);
202 importLibraryDir = importLibraryFile.parent;
204 importLibraryFile =
null;
205 importLibraryDir =
null;
209 var filePicker = Cc[
"@mozilla.org/filepicker;1"]
210 .createInstance(Ci.nsIFilePicker);
212 [ this._userReadableLibraryType ]);
213 filePicker.init(
window, filePickerMsg, Ci.nsIFilePicker.modeOpen);
216 filePicker.defaultString = this._defaultLibraryFileName;
219 if (importLibraryDir && importLibraryDir.exists())
220 filePicker.displayDirectory = importLibraryDir;
223 var filePickerFilterMsg =
225 [ this._userReadableLibraryType ]);
226 filePicker.appendFilter (filePickerFilterMsg, this._libraryFileExtFilter);
229 var result = filePicker.show();
232 if (result == Ci.nsIFilePicker.returnOK)
233 importLibraryPathPrefElem.value = filePicker.file.path;
242 doImportCommand:
function importLibraryPrefsUI_doIMportCommand(aEvent) {
243 document.getElementById(
"import_playlists_itunes_pref")
244 .valueFromPreferences =
245 document.getElementById(
"import_playlists_itunes_checkbox").checked;
248 var libraryImporterManager =
249 Cc[
"@songbirdnest.com/Songbird/LibraryImporterManager;1"]
250 .getService(Ci.sbILibraryImporterManager);
251 var libraryImporter = libraryImporterManager.defaultLibraryImporter;
254 var libraryFilePath = this._getPrefElem(
"library_file_path_pref").value;
256 var job = libraryImporter.import(libraryFilePath,
"songbird",
false);
260 SBJobUtils.showProgressDialog(job,
window, 0,
true);
269 doOptionsChange:
function libraryPrefsUI_doOptionsChange(aEvent, aElement) {
272 var prefid = aElement.getAttribute(
"id");
273 var prefValue = aElement.value;
274 if (!prefValue && prefid ==
"import_tracks_itunes_pref") {
275 document.getElementById(
"import_playlists_itunes_pref").value =
false;
277 else if (!prefValue && prefid ==
"export_tracks_itunes_pref") {
278 document.getElementById(
"export_playlists_itunes_pref").value =
false;
279 document.getElementById(
"export_smartplaylists_itunes_pref").value =
false;
296 _update:
function importLibrary__update() {
298 var importLibraryButton = document.getElementById
299 (
"import_library_button");
300 var libraryPath = this._getPrefElem(
"library_file_path_pref").value;
301 var choseLibrary = (libraryPath !=
"");
302 importLibraryButton.setAttribute(
"disabled", choseLibrary ?
"false" :
"true");
305 this._updateCheckboxBroadcaster(
"import_tracks_itunes");
306 this._updateCheckboxBroadcaster(
"export_tracks_itunes");
319 _updateCheckboxBroadcaster:
function(aIdBaseString) {
320 var broadcasterElem =
321 document.getElementById(aIdBaseString +
"_broadcaster");
323 document.getElementById(aIdBaseString +
"_checkbox");
326 if (checkboxElem.checked) {
327 broadcasterElem.removeAttribute(
"disabled");
330 broadcasterElem.setAttribute(
"disabled",
"true");
343 _getPrefElem:
function importLibrary__getPrefElem(aPrefID) {
345 var prefElemList = DOMUtils.getElementsByAttribute(document,
348 if (!prefElemList || (prefElemList.length == 0))
351 return prefElemList[0];
363 _getPrefElemValue:
function importLibrary__getPrefElemValue(aElement) {
365 if (aElement.localName ==
"checkbox")
366 return aElement.checked;
368 return aElement.value;
380 _setPrefElemValue:
function importLibrary__setPrefElemValue(aElement,
383 if (aElement.localName ==
"checkbox") {
384 aElement.checked =
aValue;
401 _readPrefValue:
function importLibraryPrefsUI__readPrefValue(aElement) {
403 var prefName = aElement.getAttribute(
"prefname");
404 var prefType = aElement.getAttribute(
"preftype");
407 var prefValue =
null;
415 prefValue = this.
_prefBranch.getBoolPref(prefName);
416 if (aElement.getAttribute(
"prefinverted") ==
"true")
417 prefValue = !prefValue;
422 prefValue = this.
_prefBranch.getComplexValue(prefName,
423 Ci.nsISupportsString);
444 _writePrefValue:
function importLibraryPrefsUI__writePrefValue(aElement,
447 var prefName = aElement.getAttribute(
"prefname");
448 var prefType = aElement.getAttribute(
"preftype");
457 if (aElement.getAttribute(
"prefinverted") ==
"true")
465 var
value = Cc[
"@mozilla.org/supports-string;1"]
466 .createInstance(Ci.nsISupportsString);
468 this.
_prefBranch.setComplexValue(prefName, Ci.nsISupportsString, value);
486 var importLibraryPrefsPane = {
497 doPaneLoad:
function importLibraryPrefs_doPaneLoad() {
499 importLibraryPrefsUI.initialize();
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
_getSelectedPageStyle s i