27 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
28 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
30 var
Ci = Components.interfaces;
31 var
Cc = Components.classes;
32 var
Cr = Components.results;
41 }
else if (x ==
null) {
43 }
else if (typeof x ==
'function') {
44 return x.name+
'(...)';
45 }
else if (typeof x ==
'string') {
46 return x.toSource().match(/^\(
new String\((.*)\)\)$/)[1];
47 }
else if (typeof x ==
'number') {
48 return x.toSource().match(/^\(
new Number\((.*)\)\)$/)[1];
49 }
else if (typeof x ==
'object' && x instanceof
Array) {
51 for (var
i=0;
i<x.length;
i++) {
52 if (
i) value = value +
', ';
53 value = value + repr(x[
i]);
56 }
else if (x instanceof Ci.nsISupports) {
62 dump(
'DEBUG '+
DEBUG.caller.name);
63 if (
msg == undefined) {
66 for (var
i=0;
i<
DEBUG.caller.length;
i++) {
68 dump(repr(
DEBUG.caller.arguments[
i]));
73 if (typeof
msg !=
'object' ||
msg instanceof
Array) {
89 var obs = Cc[
"@mozilla.org/observer-service;1"]
90 .getService(Ci.nsIObserverService);
91 obs.addObserver(
this,
'songbird-library-manager-ready',
false);
103 'Songbird Auto Downloader Service';
105 Components.ID(
"{a3d7426b-0b22-4f07-b72c-e44bab0759f7}");
109 [Ci.nsISupports, Ci.nsIClassInfo, Ci.nsIObserver, Ci.sbIMediaListListener];
112 function sbAutoDownloader_getInterfaces(
count,
array) {
124 function sbAutoDownloader_observe(subject,
topic,
data) {
127 var obs = Cc[
"@mozilla.org/observer-service;1"]
128 .getService(Ci.nsIObserverService);
130 if (
topic ==
"songbird-library-manager-ready") {
131 obs.removeObserver(
this,
"songbird-library-manager-ready");
132 obs.addObserver(
this,
"songbird-library-manager-before-shutdown",
false);
135 this.
_libraryManager = Cc[
'@songbirdnest.com/Songbird/library/Manager;1']
136 .getService(Ci.sbILibraryManager);
142 this.
_library.addListener(
this,
false,
143 Ci.sbIMediaList.LISTENER_FLAGS_ITEMADDED);
145 this.
_helper = Cc[
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1"]
146 .getService(Ci.sbIDownloadDeviceHelper);
148 }
else if (
topic ==
"songbird-library-manager-before-shutdown") {
149 obs.removeObserver(
this,
"songbird-library-manager-before-shutdown");
158 }
else if (
topic ==
'timer-callback') {
159 while (this.
_queue.length) {
160 var item = this.
_queue.shift();
161 var playlist = this.
_helper.getDownloadMediaList();
162 if (!this.
_library.contains(item)) {
166 if (playlist.contains(item)) {
170 if (item.getProperty(SBProperties.destination)) {
174 if (item.getProperty(SBProperties.disableDownload) ==
'1') {
178 this.
_helper.downloadItem(item);
189 function sbAutoDownloader_onItemAdded(aMediaList, aMediaItem, aIndex) {
191 if ((aMediaItem.getProperty(SBProperties.enableAutoDownload) ==
"1") &&
192 aMediaItem.contentSrc.scheme.match(/^http/)) {
194 if (!this.
_helper.getDownloadMediaList().contains(aMediaItem)) {
195 this.
_queue.push(aMediaItem);
203 function sbAutoDownloader_onBeforeItemRemoved(aMediaList, aMediaItem, aIndex) {
208 function sbAutoDownloader_onAfterItemRemoved(aMediaList, aMediaItem, aIndex) {
213 function sbAutoDownloader_onItemUpdated(aMediaList, aMediaItem, aProperties) {
218 function sbAutoDownloader_onItemMoved(aMediaList, aFromIndex, aToIndex) {
223 function sbAutoDownloader_onBeforeListCleared(aMediaList, aExcludeLists) {
228 function sbAutoDownloader_onListCleared(aMediaList, aExcludeLists) {
233 function sbAutoDownloader_onBatchBegin(aMediaList) {
237 function sbAutoDownloader_onBatchEnd(aMediaList) {
246 function sbAutoDownloader__setUpTimer() {
250 this.
_timer = Cc[
'@mozilla.org/timer;1'].createInstance(Ci.nsITimer);
251 this.
_timer.init(
this, 500, Ci.nsITimer.TYPE_REPEATING_SLACK);
255 function sbAutoDownloader__clearTimer() {
269 function(aCompMgr, aFileSpec, aLocation) {
270 XPCOMUtils.categoryManager.addCategoryEntry(
sbAutoDownloader prototype interfaces
sbAutoDownloader prototype _helper
function sbAutoDownloader()
sbAutoDownloader prototype _queue
sbAutoDownloader prototype _libraryManager
_getSelectedPageStyle s i
sbAutoDownloader prototype _library
sbAutoDownloader prototype _timer