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

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set sw=2 :miv */
  3. /*
  4.  *=BEGIN SONGBIRD GPL
  5.  *
  6.  * This file is part of the Songbird web player.
  7.  *
  8.  * Copyright(c) 2005-2009 POTI, Inc.
  9.  * http://www.songbirdnest.com
  10.  *
  11.  * This file may be licensed under the terms of of the
  12.  * GNU General Public License Version 2 (the ``GPL'').
  13.  *
  14.  * Software distributed under the License is distributed
  15.  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
  16.  * express or implied. See the GPL for the specific language
  17.  * governing rights and limitations.
  18.  *
  19.  * You should have received a copy of the GPL along with this
  20.  * program. If not, go to http://www.gnu.org/licenses/gpl.html
  21.  * or write to the Free Software Foundation, Inc.,
  22.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  23.  *
  24.  *=END SONGBIRD GPL
  25.  */
  26.  
  27. /**
  28.  * \file  sbMetadataUtils.jsm
  29.  * \brief Javascript source for the metadata utilities.
  30.  */
  31.  
  32. //------------------------------------------------------------------------------
  33. //
  34. // Metadata utilities JSM configuration.
  35. //
  36. //------------------------------------------------------------------------------
  37.  
  38. EXPORTED_SYMBOLS = ["sbMetadataUtils"];
  39.  
  40.  
  41. //------------------------------------------------------------------------------
  42. //
  43. // Metadata utilities imported services.
  44. //
  45. //------------------------------------------------------------------------------
  46.  
  47. // Component manager defs.
  48. if (typeof(Cc) == "undefined")
  49.   var Cc = Components.classes;
  50. if (typeof(Ci) == "undefined")
  51.   var Ci = Components.interfaces;
  52. if (typeof(Cr) == "undefined")
  53.   var Cr = Components.results;
  54. if (typeof(Cu) == "undefined")
  55.   var Cu = Components.utils;
  56.  
  57. // Songbird imports.
  58. Cu.import("resource://app/jsmodules/ArrayConverter.jsm");
  59. Cu.import("resource://app/jsmodules/SBJobUtils.jsm");
  60. Cu.import("resource://app/jsmodules/sbProperties.jsm");
  61.  
  62.  
  63. //------------------------------------------------------------------------------
  64. //
  65. // Metadata utilities.
  66. //
  67. //------------------------------------------------------------------------------
  68.  
  69. var sbMetadataUtils = {
  70.   /**
  71.    *   Write the metadata specified by aPropertyList for the set of media items
  72.    * specified by aMediaItemList.  The metadata is read from each media item's
  73.    * properties; aPropertyList simply specifies which properties to write, not
  74.    * their values.  As with sbIFileMetadataService.write, all media items must
  75.    * be from the same library.
  76.    *   If aSuppressProgressDialog is false, display a metadata write job
  77.    * progress dialog using the parent window specified by aParentWindow;
  78.    * aParentWindow may be null.
  79.    *   Check conditions for writing metadata such as the dontWriteMetadata
  80.    * property of the items' library.  If aMediaList is specified, also check
  81.    * its dontWriteMetadata property.  Do nothing if the dontWriteMetadata
  82.    * property is true.
  83.    *
  84.    * \param aMediaItemList      List of media items for which to write metadata.
  85.    * \param aPropertyList       List of properties to write.
  86.    * \param aParentWindow       Optional parent window for job progress dialog.
  87.    * \param aMediaList          Optional media list providing context for
  88.    *                            writing.
  89.    * \param aSuppressProgressDialog
  90.    *                            If true, don't open job progress dialog.
  91.    */
  92.   writeMetadata: function sbMetadataUtils_writeMetadata
  93.                             (aMediaItemList,
  94.                              aPropertyList,
  95.                              aParentWindow,
  96.                              aMediaList,
  97.                              aSuppressProgressDialog) {
  98.     // Get the item library.
  99.     var library = aMediaItemList[0].library;
  100.  
  101.     // Do nothing if the item library or the provided media list don't allow
  102.     // writing metadata.
  103.     if ((library.getProperty(SBProperties.dontWriteMetadata) == "1") ||
  104.         (aMediaList &&
  105.          (aMediaList.getProperty(SBProperties.dontWriteMetadata) == "1"))) {
  106.       return;
  107.     }
  108.  
  109.     // Create an array for the media item list.
  110.     var mediaItemArray = Cc["@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
  111.                            .createInstance(Ci.nsIMutableArray);
  112.     for (var i = 0; i < aMediaItemList.length; i++) {
  113.       mediaItemArray.appendElement(aMediaItemList[i], false);
  114.     }
  115.  
  116.     // Create an array for the property list.
  117.     var propertyArray = ArrayConverter.stringEnumerator(aPropertyList);
  118.  
  119.     try {
  120.       // Initiate writing of the metadata.
  121.       var metadataService = Cc["@songbirdnest.com/Songbird/FileMetadataService;1"]
  122.                               .getService(Ci.sbIFileMetadataService);
  123.       var job = metadataService.write(mediaItemArray, propertyArray);
  124.  
  125.       // Show a progress dialog.
  126.       if (!aSuppressProgressDialog) {
  127.         SBJobUtils.showProgressDialog(job, aParentWindow);
  128.       }
  129.     } catch (ex) {
  130.       // Job will fail if writing is disabled by the pref.
  131.       Cu.reportError(ex);
  132.     }
  133.   }
  134. };
  135.  
  136.  
  137.