home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February / PCWorld_2008-02_cd.bin / temacd / songbird / Songbird_0.4_windows-i686.exe / components / sbDownloadDeviceServicePaneModule.js < prev    next >
Text File  |  2007-12-21  |  7KB  |  203 lines

  1. /*
  2. //
  3. // BEGIN SONGBIRD GPL
  4. //
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2008 POTI, Inc.
  8. // http://songbirdnest.com
  9. //
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. //
  13. // Software distributed under the License is distributed
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
  15. // express or implied. See the GPL for the specific language
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc.,
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. //
  23. // END SONGBIRD GPL
  24. //
  25. */
  26.  
  27. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  28. Components.utils.import("resource://app/components/sbProperties.jsm");
  29.  
  30. const Ci = Components.interfaces;
  31. const Cc = Components.classes;
  32. const Cr = Components.results;
  33.  
  34. function sbDownloadDeviceServicePaneModule()
  35. {
  36.   this._servicePaneNode = null;
  37.   this._downloadDevice = null;
  38.   this._currentState = Ci.sbIDeviceBase.STATE_IDLE;
  39. }
  40.  
  41. sbDownloadDeviceServicePaneModule.prototype =
  42. {
  43.   classDescription: "Songbird Download Device Service Pane Module",
  44.   classID:          Components.ID("{ee93796b-090e-4703-982a-1d27bea552c3}"),
  45.   contractID:       "@songbirdnest.com/Songbird/DownloadDeviceServicePaneModule;1",
  46.   QueryInterface:   XPCOMUtils.generateQI([Ci.sbIServicePaneModule,
  47.                                            Ci.sbIDeviceBaseCallback])
  48. }
  49.  
  50. // sbIServicePaneModule
  51. sbDownloadDeviceServicePaneModule.prototype.servicePaneInit =
  52. function sbDownloadDeviceServicePaneModule_servicePaneInit(aServicePaneModule)
  53. {
  54.   var devMgr = Cc["@songbirdnest.com/Songbird/DeviceManager;1"]
  55.                  .getService(Ci.sbIDeviceManager);
  56.   var downloadCat = "Songbird Download Device";
  57.   if (devMgr.hasDeviceForCategory(downloadCat)) {
  58.     this._downloadDevice = devMgr.getDeviceByCategory(downloadCat)
  59.                                  .QueryInterface(Ci.sbIDownloadDevice);
  60.   }
  61.   this._downloadDevice.addCallback(this);
  62.   this._currentState = this._downloadDevice.getDeviceState("download");
  63.   this._updateState();
  64. }
  65.  
  66. sbDownloadDeviceServicePaneModule.prototype.fillContextMenu =
  67. function sbDownloadDeviceServicePaneModule_fillContextMenu(aNode,
  68.                                                            aContextMenu,
  69.                                                            aParentWindow)
  70. {
  71. }
  72.  
  73. sbDownloadDeviceServicePaneModule.prototype.fillNewItemMenu =
  74. function sbDownloadDeviceServicePaneModule_fillNewItemMenu(aNode,
  75.                                                            aContextMenu,
  76.                                                            aParentWindow)
  77. {
  78. }
  79.  
  80. sbDownloadDeviceServicePaneModule.prototype.onSelectionChanged =
  81. function sbDownloadDeviceServicePaneModule_onSelectionChanged(aNode,
  82.                                                               aContainer,
  83.                                                               aParentWindow)
  84. {
  85. }
  86.  
  87. sbDownloadDeviceServicePaneModule.prototype.canDrop =
  88. function sbDownloadDeviceServicePaneModule_canDrop(aNode,
  89.                                                    aDragSession,
  90.                                                    aOrientation)
  91. {
  92. }
  93.  
  94. sbDownloadDeviceServicePaneModule.prototype.onDrop =
  95. function sbDownloadDeviceServicePaneModule_onDrop(aNode,
  96.                                                   aDragSession,
  97.                                                   aOrientation)
  98. {
  99. }
  100.  
  101. sbDownloadDeviceServicePaneModule.prototype.onDragGesture =
  102. function sbDownloadDeviceServicePaneModule_onDragGesture(aNode,
  103.                                                          aTransferable)
  104. {
  105. }
  106.  
  107. sbDownloadDeviceServicePaneModule.prototype.onRename =
  108. function sbDownloadDeviceServicePaneModule_onRename(aNode,
  109.                                                     aNewName)
  110. {
  111. }
  112.  
  113. sbDownloadDeviceServicePaneModule.prototype.__defineGetter__("stringBundle",
  114. function sbDownloadDeviceServicePaneModule_get_stringBundle()
  115. {
  116. });
  117.  
  118. sbDownloadDeviceServicePaneModule.prototype.shutdown =
  119. function sbDownloadDeviceServicePaneModule_shutdown()
  120. {
  121.   if (this._downloadDevice) {
  122.     this._downloadDevice.removeCallback(this);
  123.   }
  124. }
  125.  
  126. // sbIDeviceBaseCallback
  127. sbDownloadDeviceServicePaneModule.prototype.onDeviceConnect =
  128. function sbDownloadDeviceServicePaneModule_onDeviceConnect(aDeviceIdentifier)
  129. {
  130. }
  131.  
  132. sbDownloadDeviceServicePaneModule.prototype.onDeviceDisconnect =
  133. function sbDownloadDeviceServicePaneModule_onDeviceDisconnect(aDeviceIdentifier)
  134. {
  135. }
  136.  
  137. sbDownloadDeviceServicePaneModule.prototype.onTransferStart =
  138. function sbDownloadDeviceServicePaneModule_onTransferStart(aSourceURL,
  139.                                                            aDestinationURL)
  140. {
  141. }
  142.  
  143. sbDownloadDeviceServicePaneModule.prototype.onTransferComplete =
  144. function sbDownloadDeviceServicePaneModule_onTransferComplete(aSourceURL,
  145.                                                               aDestinationURL)
  146. {
  147. }
  148.  
  149. sbDownloadDeviceServicePaneModule.prototype.onStateChanged =
  150. function sbDownloadDeviceServicePaneModule_onStateChanged(aDeviceIdentifier,
  151.                                                           aState)
  152. {
  153.   this._currentState = aState;
  154.   this._updateState();
  155. }
  156.  
  157. sbDownloadDeviceServicePaneModule.prototype.__defineGetter__("_node",
  158. function sbDownloadDeviceServicePaneModule_get_node()
  159. {
  160.   if (!this._servicePaneNode) {
  161.     var lsps = Cc["@songbirdnest.com/servicepane/library;1"]
  162.                  .getService(Ci.sbILibraryServicePaneService);
  163.     this._servicePaneNode =
  164.       lsps.getNodeForLibraryResource(this._downloadDevice.downloadMediaList);
  165.   }
  166.   return this._servicePaneNode;
  167. });
  168.  
  169. sbDownloadDeviceServicePaneModule.prototype._updateState =
  170. function sbDownloadDeviceServicePaneModule_onStateChanged()
  171. {
  172.   if (this._node) {
  173.     var a = this._node.properties.split(" ");
  174.  
  175.     // Remove the "progress" property from the array, if any
  176.     a = a.filter(function(property) {
  177.       return property != "downloading";
  178.     });
  179.  
  180.     if (this._currentState == Ci.sbIDeviceBase.STATE_DOWNLOADING) {
  181.       a.push("downloading");
  182.     }
  183.  
  184.     this._node.properties = a.join(" ");
  185.   }
  186. }
  187.  
  188. function NSGetModule(compMgr, fileSpec) {
  189.   var module = XPCOMUtils.generateModule(
  190.     [sbDownloadDeviceServicePaneModule],
  191.       function(aCompMgr, aFileSpec, aLocation) {
  192.       XPCOMUtils.categoryManager.addCategoryEntry(
  193.         "service-pane",
  194.         "z-download-device-service-pane-module",
  195.         sbDownloadDeviceServicePaneModule.prototype.contractID,
  196.         true,
  197.         true);
  198.       }
  199.     );
  200.   return module;
  201. }
  202.  
  203.