deviceCapacityPanel.js
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 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2009 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
34 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 //
37 // Device capacity widget.
38 //
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
41 
42 //------------------------------------------------------------------------------
43 //
44 // Device capacity imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 // Component manager defs.
49 if (typeof(Cc) == "undefined")
50  var Cc = Components.classes;
51 if (typeof(Ci) == "undefined")
52  var Ci = Components.interfaces;
53 if (typeof(Cr) == "undefined")
54  var Cr = Components.results;
55 if (typeof(Cu) == "undefined")
56  var Cu = Components.utils;
57 
58 // Songbird imports.
59 Cu.import("resource://app/jsmodules/sbTimeFormatter.jsm");
60 
61 
62 //------------------------------------------------------------------------------
63 //
64 // Device capacity services.
65 //
66 //------------------------------------------------------------------------------
67 
68 var DCW = {
69  //
70  // Device capacity object.
71  //
72  // _cfg Configuration.
73  // _widget Device capacity widget.
74  // _deviceLibrary Device library we are working with.
75  // _panel The XUL panel itself
76  // _label The label within the panel
77  //
78 
79  _widget: null,
80  _devLib: null,
81  _panel: null,
82  _label: null,
83 
84 
92  initialize: function DCW__initialize(aWidget) {
93  // Get the device capacity widget.
94  this._widget = aWidget;
95 
96  // Initialize object fields.
97  this._deviceLibrary = this._widget.devLib;
98 
99  this._panel = this._getElement("capacity-panel");
100  this._label = this._getElement("panel-label");
101  },
102 
103 
108  finalize: function DCW_finalize() {
109  // Clear object fields.
110  this._widget = null;
111  this._deviceLibrary = null;
112  },
113 
118  openPopup: function DCW_openPopup(anchor) {
119  var type = anchor.getAttribute("type");
120  DCW._update(type);
121  DCW._panel.openPopup(anchor, "after_start");
122  },
123 
124 
125  //----------------------------------------------------------------------------
126  //
127  // Device capacity XUL services.
128  //
129  //----------------------------------------------------------------------------
130 
140  _getElement: function DCW__getElement(aElementID) {
141  return document.getAnonymousElementByAttribute(this._widget,
142  "sbid",
143  aElementID);
144  },
145 
146 
147  //----------------------------------------------------------------------------
148  //
149  // Internal device capacity services.
150  //
151  //----------------------------------------------------------------------------
152 
158  _update: function DCW__update(type) {
159  // Sanity check
160  if (type != "music" && type != "video")
161  return;
162 
163  var playTimeProperty = "http://songbirdnest.com/device/1.0#" +
164  type + "TotalPlayTime";
165  var itemCountProperty = "http://songbirdnest.com/device/1.0#" +
166  type + "ItemCount";
167  var playTime = parseInt(this._getDevLibProperty(playTimeProperty, -1));
168  var itemCount = parseInt(this._getDevLibProperty(itemCountProperty, -1));
169  if (playTime < 0 || itemCount < 0) {
170  this._label.value = SBString("device.capacity.panel." + type + ".error");
171  } else {
172  var key = "device.capacity.panel." + type;
173  playTime = TimeFormatter.formatSingle(playTime/1000000);
174 
175  this._label.value = SBFormattedCountString(key, itemCount,
176  [ playTime, itemCount ], "");
177  }
178 
179  },
180 
181 
182 
183  //----------------------------------------------------------------------------
184  //
185  // Device capacity device services.
186  //
187  //----------------------------------------------------------------------------
188 
200  _getDevLibProperty: function DCW__getDevLibProperty(aPropertyName, aDefault) {
201  try {
202  if (this._deviceLibrary)
203  return this._deviceLibrary.getProperty(aPropertyName);
204  } catch (ex) { }
205  return aDefault;
206  },
207 };
const Cu
function Fx prototype initialize
var DCW
const Cc
function SBString(aKey, aDefault, aStringBundle)
Definition: StringUtils.jsm:93
function SBFormattedCountString(aKeyBase, aCount, aParams, aDefault, aStringBundle)
return null
Definition: FeedWriter.js:1143
const Cr
const Ci