sbMetadataUtils.jsm
Go to the documentation of this file.
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 
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 
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 
const Cu
const Cc
var sbMetadataUtils
const Cr
const Ci
_getSelectedPageStyle s i
EXPORTED_SYMBOLS