49 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
50 Components.utils.import(
"resource://app/jsmodules/SBJobUtils.jsm");
51 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
52 Components.utils.import(
"resource://app/jsmodules/WindowUtils.jsm");
53 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
63 if (typeof(
Cc) ==
"undefined")
64 var
Cc = Components.classes;
65 if (typeof(
Ci) ==
"undefined")
66 var
Ci = Components.interfaces;
67 if (typeof(
Cr) ==
"undefined")
68 var
Cr = Components.results;
69 if (typeof(
Cu) ==
"undefined")
70 var
Cu = Components.utils;
88 className:
"Songbird Library Importer Manager Service",
89 cid: Components.ID(
"{0ed2a7e0-78ac-4574-8554-b1e422b02642}"),
90 contractID:
"@songbirdnest.com/Songbird/LibraryImporterManager;1",
91 ifList: [ Ci.nsIObserver,
92 Ci.sbILibraryImporterManager,
93 Ci.sbILibraryImporterListener ]
96 sbLibraryImporterManagerCfg.categoryList = [
98 category:
"app-startup",
99 entry: sbLibraryImporterManagerCfg.className,
100 value:
"service," + sbLibraryImporterManagerCfg.contractID
140 classID: sbLibraryImporterManagerCfg.cid,
141 contractID: sbLibraryImporterManagerCfg.contractID,
145 _isInitialized:
false,
146 _libraryImporterList:
null,
147 _prefsAvailable:
false,
161 defaultLibraryImporter:
null,
180 function sbLibraryImporterManager_onLibraryChanged(aLibFilePath, aGUID) {
183 var
Application = Cc[
"@mozilla.org/fuel/application;1"]
184 .getService(Ci.fuelIApplication);
189 var
importer = this.defaultLibraryImporter;
190 var libraryFilePath = Application.prefs.getValue
191 (
"songbird.library_importer.library_file_path",
193 var libraryPreviousImportPath = importer.libraryPreviousImportPath;
196 var job = importer.import(libraryFilePath,
"songbird",
false);
199 var libraryFile = Cc[
"@mozilla.org/file/local;1"]
200 .createInstance(Ci.nsILocalFile);
201 try { libraryFile.initWithPath(libraryFilePath); }
202 catch (ex) { libaryFile =
null; }
205 var previousLibraryFile = Cc[
"@mozilla.org/file/local;1"]
206 .createInstance(Ci.nsILocalFile);
207 try { previousLibraryFile.initWithPath(libraryPreviousImportPath); }
208 catch (ex) { previousLibraryFile =
null; }
212 !previousLibraryFile ||
213 !libraryFile.equals(previousLibraryFile)) {
214 SBJobUtils.showProgressDialog(job,
null, 0,
true);
224 onImportError:
function sbLibraryImporterManager_onImportError() {
227 WindowUtils.openModalDialog
229 "chrome://songbird/content/xul/importLibrary.xul",
231 "chrome,centerscreen",
234 doImport = (doImport.value ==
"true");
239 var Application = Cc[
"@mozilla.org/fuel/application;1"]
240 .getService(Ci.fuelIApplication);
241 var libraryFilePath = Application.prefs.getValue
242 (
"songbird.library_importer.library_file_path",
244 this.defaultLibraryImporter.import(libraryFilePath,
"songbird",
false);
259 function sbLibraryImporterManager_onNonExistentMedia(aNonExistentMediaCount,
262 var prompter = Cc[
"@songbirdnest.com/Songbird/Prompter;1"]
263 .createInstance(Ci.sbIPrompter);
265 (
"import_library.nonexistent_media_alert.title");
268 [ aNonExistentMediaCount, aTrackCount ]);
269 var songWin = Cc[
"@mozilla.org/appshell/window-mediator;1"]
270 .getService(Ci.nsIWindowMediator)
271 .getMostRecentWindow(
"Songbird:Main");
273 prompter.alert(songWin, alertTitle, alertMsg);
282 onUnsupportedMedia:
function sbLibraryImporterManager_onUnsupportedMedia() {
284 var Application = Cc[
"@mozilla.org/fuel/application;1"]
285 .getService(Ci.fuelIApplication);
286 var alertEnabledPref =
287 "songbird.library_importer.unsupported_media_alert.enabled";
288 var alertEnabled = Application.prefs.getValue(alertEnabledPref,
false);
295 var prompter = Cc[
"@songbirdnest.com/Songbird/Prompter;1"]
296 .createInstance(Ci.sbIPrompter);
298 (
"import_library.unsupported_media_alert.title");
299 var alertMsg =
SBString(
"import_library.unsupported_media_alert.msg");
301 SBString(
"import_library.unsupported_media_alert.enable_label");
302 var checkState = {
value: alertEnabled };
304 var songWin = Cc[
"@mozilla.org/appshell/window-mediator;1"]
305 .getService(Ci.nsIWindowMediator)
306 .getMostRecentWindow(
"Songbird:Main");
308 prompter.alertCheck(songWin,
313 checkState = checkState.value;
316 Application.prefs.setValue(alertEnabledPref, checkState);
335 function sbLibraryImporterManager_onDirtyPlaylist(aPlaylistName,
340 WindowUtils.openModalDialog
342 "chrome://songbird/content/xul/dirtyPlaylistDialog.xul",
344 "chrome,centerscreen",
346 [ action, applyAll ]);
347 action = action.value;
348 applyAll = (applyAll.value ==
"true");
351 aApplyAll.value = applyAll;
371 observe:
function sbLibraryImporterManager_observe(aSubject, aTopic,
aData) {
375 this._handleAppStartup();
378 case "profile-after-change" :
379 this._handleProfileAfterChange();
382 case "songbird-library-manager-ready" :
383 this._handleLibraryManagerReady();
386 case "songbird-library-manager-before-shutdown" :
387 this._handleAppQuit();
402 QueryInterface: XPCOMUtils.generateQI(sbLibraryImporterManagerCfg.ifList),
415 _handleAppStartup:
function sbLibraryImporterManager__handleAppStartup() {
425 _handleProfileAfterChange:
426 function sbLibraryImporterManager__handleProfileAfterChange() {
428 this._prefsAvailable =
true;
439 _handleLibraryManagerReady:
440 function sbLibraryImporterManager__handleLibraryManagerReady() {
450 _handleAppQuit:
function sbLibraryImporterManager__handleAppQuit() {
466 _initialize:
function sbLibraryImporterManager__initialize() {
468 if (this._isInitialized)
472 if (!this._observerSvc) {
473 this._observerSvc = Cc[
"@mozilla.org/observer-service;1"]
474 .getService(Ci.nsIObserverService);
475 this._observerSvc.addObserver(
this,
"songbird-library-manager-before-shutdown",
false);
476 this._observerSvc.addObserver(
this,
"profile-after-change",
false);
477 this._observerSvc.addObserver(
this,
478 "songbird-library-manager-ready",
483 if (!this._prefsAvailable)
488 var
libraryManager = Cc[
"@songbirdnest.com/Songbird/library/Manager;1"]
489 .getService(Ci.sbILibraryManager);
490 if (!libraryManager.mainLibrary)
497 this._libraryImporterList = [];
500 this._addAllLibraryImporters();
503 var Application = Cc[
"@mozilla.org/fuel/application;1"]
504 .getService(Ci.fuelIApplication);
505 var hasLibraryFilePath =
506 Application.prefs.has(
"songbird.library_importer.library_file_path");
507 if (!hasLibraryFilePath && this.defaultLibraryImporter) {
508 var libraryDefaultFilePath =
509 this.defaultLibraryImporter.libraryDefaultFilePath;
510 if (libraryDefaultFilePath) {
511 Application.prefs.setValue
512 (
"songbird.library_importer.library_file_path",
513 libraryDefaultFilePath);
518 this._isInitialized =
true;
529 _finalize:
function sbLibraryImporterManager__finalize() {
531 this._observerSvc.removeObserver(
this,
"songbird-library-manager-before-shutdown");
532 this._observerSvc.removeObserver(
this,
"profile-after-change");
533 this._observerSvc.removeObserver(
this,
"songbird-library-manager-ready");
536 this._removeAllLibraryImporters();
539 this._libraryImporterList =
null;
540 this.defaultLibraryImporter =
null;
548 _addAllLibraryImporters:
549 function sbLibraryImporterManager__addAllLibraryImporters() {
551 var categoryManager = Cc[
"@mozilla.org/categorymanager;1"]
552 .getService(Ci.nsICategoryManager);
553 var libraryImporterEnum = categoryManager.enumerateCategory
554 (
"library-importer");
555 while (libraryImporterEnum.hasMoreElements()) {
557 var
entry = libraryImporterEnum.getNext()
558 .QueryInterface(Ci.nsISupportsCString);
561 var
contractID = categoryManager.getCategoryEntry(
"library-importer",
565 this._addLibraryImporter(contractID);
577 function sbLibraryImporterManager__addLibraryImporter(aContractID) {
579 var libraryImporter = Cc[aContractID].getService(Ci.sbILibraryImporter);
582 libraryImporter.initialize();
585 libraryImporter.setListener(
this);
588 this._libraryImporterList.push(libraryImporter);
591 this._updateDefaultLibraryImporter();
599 _removeAllLibraryImporters:
600 function sbLibraryImporterManager__removeAllLibraryImporters() {
601 for (var
i = this._libraryImporterList.length - 1;
i >= 0;
i--) {
603 var libraryImporter = this._libraryImporterList.pop();
606 libraryImporter.setListener(
null);
609 libraryImporter.finalize();
610 libraryImporter =
null;
619 _updateDefaultLibraryImporter:
620 function sbLibraryImporterManager__updateDefaultLibraryImporter() {
622 if (!this.defaultLibraryImporter) {
623 if (this._libraryImporterList.length > 0)
624 this.defaultLibraryImporter = this._libraryImporterList[0];
633 _autoImport:
function sbLibraryImporterManager_autoImport() {
635 var Application = Cc[
"@mozilla.org/fuel/application;1"]
636 .getService(Ci.fuelIApplication);
637 var firstRunDoImportLibrary =
638 Application.prefs.getValue(
"songbird.firstrun.do_import_library",
640 var importTracks = Application.prefs.getValue(
641 "songbird.library_importer.import_tracks",
false);
642 var importPlaylists = Application.prefs.getValue(
643 "songbird.library_importer.import_playlists",
false);
646 if (!this.defaultLibraryImporter || firstRunDoImportLibrary ||
647 (!importTracks && !importPlaylists))
652 var windowWatcher = Cc[
"@songbirdnest.com/Songbird/window-watcher;1"]
653 .getService(Ci.sbIWindowWatcher);
655 var func =
function(aWindow) { _this._autoImportWithWindow(aWindow); };
656 windowWatcher.callWithWindow(
"Songbird:Main", func,
false);
659 _autoImportWithWindow:
660 function sbLibraryImporterManager_autoImportWithWindow(aWindow) {
662 var Application = Cc[
"@mozilla.org/fuel/application;1"]
663 .getService(Ci.fuelIApplication);
664 var libraryFilePath = Application.prefs.getValue
665 (
"songbird.library_importer.library_file_path",
668 this.defaultLibraryImporter.import(libraryFilePath,
"songbird",
true);
function SBBrandedString(aKey, aDefault, aStringBundle)
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
sbOSDControlService prototype className
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function SBString(aKey, aDefault, aStringBundle)
DataRemote prototype constructor
function sbLibraryImporterManager()
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe
var sbLibraryImporterManagerCfg