home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / jsmodules / sbCDDeviceUtils.jsm < prev    next >
Text File  |  2012-06-08  |  3KB  |  102 lines

  1. /*
  2.  *=BEGIN SONGBIRD GPL
  3.  *
  4.  * This file is part of the Songbird web player.
  5.  *
  6.  * Copyright(c) 2005-2009 POTI, Inc.
  7.  * http://www.songbirdnest.com
  8.  *
  9.  * This file may be licensed under the terms of of the
  10.  * GNU General Public License Version 2 (the ``GPL'').
  11.  *
  12.  * Software distributed under the License is distributed
  13.  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
  14.  * express or implied. See the GPL for the specific language
  15.  * governing rights and limitations.
  16.  *
  17.  * You should have received a copy of the GPL along with this
  18.  * program. If not, go to http://www.gnu.org/licenses/gpl.html
  19.  * or write to the Free Software Foundation, Inc.,
  20.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21.  *
  22.  *=END SONGBIRD GPL
  23.  */
  24.  
  25. EXPORTED_SYMBOLS = [ "sbCDDeviceUtils" ];
  26.  
  27. Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
  28. Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
  29.  
  30. const Cc = Components.classes;
  31. const Ci = Components.interfaces;
  32. const Cr = Components.results;
  33. const Cu = Components.utils;
  34.  
  35. var sbCDDeviceUtils = {
  36.   
  37.   /**
  38.    * Start a CD Lookup Process for the device.
  39.    * \param aDevice - device to perform lookup on.
  40.    */
  41.   doCDLookUp: function(aDevice) {
  42.     // Invoke the CD Lookup again
  43.     var bag = Cc["@mozilla.org/hash-property-bag;1"]
  44.                 .createInstance(Ci.nsIPropertyBag2);
  45.     aDevice.submitRequest(Ci.sbICDDeviceEvent.REQUEST_CDLOOKUP, bag);
  46.   },
  47.   
  48.   /**
  49.    * Rip any selected tracks from the cd device to the main library.
  50.    * \param aDevice - device to rip tracks from.
  51.    */
  52.   doCDRip: function(aDevice) {
  53.     var deviceLibrary = this._getDeviceLibrary(aDevice);
  54.     try {
  55.       // Get all the selected tracks from the device library
  56.       var addItems = deviceLibrary.getItemsByProperty(SBProperties.shouldRip,
  57.                                                       "1");
  58.   
  59.       //reset the rip status of the items to be ripped
  60.       var ripItemsEnum = addItems.enumerate();
  61.       while (ripItemsEnum.hasMoreElements()) {
  62.         var ripItem = ripItemsEnum.getNext();
  63.         ripItem.setProperty(SBProperties.cdRipStatus, null);
  64.       }
  65.  
  66.       // Then add them to the main library using addSome(enumerator)
  67.       LibraryUtils.mainLibrary.addSome(addItems.enumerate());
  68.     } catch (err) {
  69.       Cu.reportError("Error occurred when trying to rip tracks from CD: " + err);
  70.     }
  71.   },
  72.   
  73.   /**
  74.    * Get the devices library (defaults to first library)
  75.    * \param aDevice - device to get library from
  76.    * \param aIndex - Library index to retrieve
  77.    */
  78.   _getDeviceLibrary: function _getDeviceLibrary(aDevice, aIndex) {
  79.     if (typeof(aIndex) == "undefined") {
  80.       aIndex = 0;
  81.     }
  82.     
  83.     // Get the libraries for device
  84.     var libraries = aDevice.content.libraries;
  85.     if (libraries.length < 1) {
  86.       // Oh no, we have no libraries
  87.       Cu.reportError("Device " + aDevice.id + " has no libraries!");
  88.       return null;
  89.     }
  90.  
  91.     // Get the requested library
  92.     var deviceLibrary = libraries.queryElementAt(aIndex, Ci.sbIMediaList);
  93.     if (!deviceLibrary) {
  94.       Cu.reportError("Unable to get library " + aIndex + " for device: " +
  95.                      aDevice.id);
  96.       return null;
  97.     }
  98.     
  99.     return deviceLibrary;
  100.   }
  101. };
  102.