27 const Cc = Components.classes;
28 const Ci = Components.interfaces;
29 const Cu = Components.utils;
31 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
32 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
33 Cu.import(
"resource://app/jsmodules/SBJobUtils.jsm");
34 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
48 _importInProgress:
false,
53 _firstMediaItem:
null,
65 importURIArray:
function(aMutableURIArray,
72 this._targetList = aTargetMediaList;
73 this._targetPosition = aTargetPosition;
74 this._listener = aImportListener;
77 if (!this._scanList) {
78 this._scanList =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
79 .createInstance(
Ci.nsIMutableArray);
83 this._firstMediaItem =
null;
84 this._totalImported = 0;
85 this._totalInserted = 0;
87 this._mainLibrary =
Cc[
"@songbirdnest.com/Songbird/library/Manager;1"]
88 .getService(
Ci.sbILibraryManager)
91 this._uriArray = aMutableURIArray;
95 if (!this._importInProgress) {
99 this._importInProgress =
true;
104 this._importDropFrame();
110 _nextImportDropFrame:
function()
112 this.
_timer =
Cc[
"@mozilla.org/timer;1"]
113 .createInstance(
Ci.nsITimer);
114 this.
_timer.initWithCallback(
this, 10,
Ci.nsITimer.TYPE_ONE_SHOT);
121 this._importDropFrame();
125 _importDropFrame:
function()
129 if (this._uriArray.length > 0) {
132 var
uri = this._uriArray.queryElementAt(0,
Ci.nsIURI);
135 this._uriArray.removeElementAt(0);
143 fileUrl = uri.QueryInterface(
Ci.nsIFileURL);
150 if (fileUrl.file.isDirectory()) {
152 this._directoryList.push(fileUrl.file);
154 this._nextImportDropFrame();
160 this._importDropFile(uri);
164 this._nextImportDropFrame();
169 if (this._scanList && this._scanList.length > 0) {
170 var metadataService =
171 Cc[
"@songbirdnest.com/Songbird/FileMetadataService;1"]
172 .getService(
Ci.sbIFileMetadataService);
174 metadataService.read(this._scanList);
175 this._scanList =
null;
179 if (this._directoryList.length > 0) {
182 this._importDropDirectories();
188 this._nextImportDropFrame();
192 this._dropComplete();
200 Components.utils.reportError(e);
201 this._nextImportDropFrame();
208 _importDropFile:
function(aURI) {
212 Cc[
"@songbirdnest.com/Songbird/Mediacore/TypeSniffer;1"]
213 .createInstance(
Ci.sbIMediacoreTypeSniffer);
215 .getService(
Ci.fuelIApplication);
217 let isValidMediaURL = typeSniffer.isValidMediaURL(aURI);
218 if (!Application.prefs.getValue(
"songbird.mediascan.enableVideoImporting",
true)
219 && typeSniffer.isValidVideoURL(aURI)) {
220 isValidMediaURL =
false;
223 if (isValidMediaURL) {
227 this._getFirstItemByProperty(this._targetList.library,
228 SBProperties.contentURL,
233 this._getFirstItemByProperty(this._targetList.library,
234 SBProperties.originURL,
237 let mainLibraryItem =
false;
240 if (!this._targetList.library.equals(
this._mainLibrary)) {
242 item = this._getFirstItemByProperty(this._mainLibrary,
243 SBProperties.contentURL,
249 this._getFirstItemByProperty(this._mainLibrary,
250 SBProperties.originURL,
253 mainLibraryItem = item !=
null;
256 let itemAdded =
false;
257 if (mainLibraryItem || !item) {
259 if (!mainLibraryItem) {
262 this._targetList.library.createMediaItemIfNotExist(aURI,
271 let newItem = this._targetList.library.addItem(item);
272 itemAdded = newItem && !newItem.equals(item);
278 this._scanList.appendElement(item,
false);
279 this._totalImported++;
291 if ((this._targetList instanceof
Ci.sbIOrderableMediaList) &&
292 (
this._targetPosition >= 0) &&
293 (
this._targetPosition <
this._targetList.length))
295 this._targetList.insertBefore(this._targetPosition, item);
296 this._targetPosition++;
299 this._targetList.add(item);
301 this._totalInserted++;
304 if (!this._firstMediaItem) {
305 this._firstMediaItem = item;
306 if (this._listener) {
307 this._listener.onFirstMediaItem(this._targetList, item);
313 Components.utils.reportError(e);
320 _getFirstItemByProperty:
function(aMediaList, aProperty,
aValue)
324 onEnumerationBegin:
function() {
326 onEnumeratedItem:
function(list, item) {
328 return Components.interfaces.sbIMediaListEnumerationListener.CANCEL;
330 onEnumerationEnd:
function() {
334 aMediaList.enumerateItemsByProperty(aProperty,
337 return listener.item;
342 _importDropDirectories:
function()
345 Cc[
'@songbirdnest.com/Songbird/DirectoryImportService;1']
346 .getService(
Ci.sbIDirectoryImportService);
348 var job = importService.import(ArrayConverter.nsIArray(
this._directoryList),
349 this._targetList, this._targetPosition);
352 this._directoryList = [];
354 SBJobUtils.showProgressDialog(job, this.
_window, 0);
357 if (!this._firstMediaItem) {
358 var allItems = job.enumerateAllItems();
359 if (allItems.hasMoreElements()) {
360 this._firstMediaItem =
361 allItems.getNext().QueryInterface(
Ci.sbIMediaItem);
363 if (this._listener) {
365 onFirstMediaItem(this._targetList, this._firstMediaItem);
370 this._totalImported += job.totalAddedToLibrary;
371 this._totalInserted += job.totalAddedToMediaList;
372 this._totalDups += job.totalDuplicates;
377 _dropComplete:
function()
379 if (this._listener) {
380 this._listener.onImportComplete(this._targetList,
389 this._importInProgress =
false;
390 this._targetList =
null;
391 this._scanList =
null;
393 this._listener =
null;
394 this._mainLibrary =
null;
404 "Songbird URI Import Service";
406 Components.ID(
"{CC435D34-F76A-458F-B786-FAF897CA69BD}");
408 "@songbirdnest.com/uri-import-service;1";
function NSGetModule(compMgr, fileSpec)
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype _timer
TimerLoop prototype notify
function sbURIImportService()