sbBaseDeviceHelper.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 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 
29 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
30 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
31 Components.utils.import("resource://app/jsmodules/StringUtils.jsm");
32 
33 const Ci = Components.interfaces;
34 const Cc = Components.classes;
35 
36 function BaseDeviceHelper() {}
37 
38 BaseDeviceHelper.prototype = {
39 
40 /*
41  boolean hasSpaceForWrite(in unsigned long long aSpaceNeeded,
42  in sbIDeviceLibrary aLibrary,
43  [optional] in sbIDevice aDevice,
44  [optional] out unsigned long long aSpaceRemaining);
45  */
46  hasSpaceForWrite: function BaseDeviceHelper_hasSpaceForWrite(
47  aSpaceNeeded, aLibrary, aDevice, aSpaceRemaining)
48  {
49  var device = aDevice;
50  if (!device) {
51  // no device supplied, need to find it
52  const deviceMgr = Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
53  .getService(Ci.sbIDeviceRegistrar);
54  var foundLib = false;
55  for (device in ArrayConverter.JSArray(deviceMgr.devices)) {
56  for (var library in ArrayConverter.JSArray(device.content.libraries)) {
57  if (library.equals(aLibrary)) {
58  foundLib = true;
59  break;
60  }
61  }
62  if (foundLib)
63  break;
64  }
65  if (!foundLib) {
66  throw Components.Exception("Failed to find device for library");
67  }
68  }
69 
70  // figure out the space remaining
71  var spaceRemaining =
72  device.properties
73  .properties
74  .getPropertyAsInt64("http://songbirdnest.com/device/1.0#freeSpace");
75  if (aSpaceRemaining) {
76  aSpaceRemaining.value = spaceRemaining;
77  }
78 
79  // if we have enough space, no need to look at anything else
80  if (aSpaceNeeded < spaceRemaining)
81  return true;
82 
83  // need to ask the user
84  var messageKeyPrefix = this._getMessageKeyPrefix(aLibrary);
85 
86  storageConverter =
87  Cc["@songbirdnest.com/Songbird/Properties/UnitConverter/Storage;1"]
88  .createInstance(Ci.sbIPropertyUnitConverter);
89  var messageParams = [
90  device.name,
91  storageConverter.autoFormat(aSpaceNeeded, -1, 1),
92  storageConverter.autoFormat(spaceRemaining, -1, 1)
93  ];
94  var message = SBFormattedString(messageKeyPrefix + ".message",
95  messageParams);
96 
97  const prompter = Cc["@songbirdnest.com/Songbird/Prompter;1"]
98  .getService(Ci.sbIPrompter);
99  var neverPromptAgain = { value: false };
100  var abortRequest = prompter.confirmEx(null, /* parent */
101  SBString(messageKeyPrefix + ".title"),
102  message,
103  Ci.nsIPromptService.STD_YES_NO_BUTTONS,
104  null, null, null, /* button text */
105  null, /* checkbox message TODO */
106  neverPromptAgain);
107  return (!abortRequest);
108  },
109 
110 /*
111  boolean queryUserSpaceExceeded(in nsIDOMWindow aParent,
112  in sbIDevice aDevice,
113  in sbIDeviceLibrary aLibrary,
114  in unsigned long long aSpaceNeeded,
115  in unsigned long long aSpaceAvailable);
116  */
117  queryUserSpaceExceeded: function BaseDeviceHelper_queryUserSpaceExceeded
118  (aParent,
119  aDevice,
120  aLibrary,
121  aSpaceNeeded,
122  aSpaceAvailable,
123  aAbort)
124  {
125  var messageKeyPrefix = this._getMessageKeyPrefix(aLibrary);
126 
127  storageConverter =
128  Cc["@songbirdnest.com/Songbird/Properties/UnitConverter/Storage;1"]
129  .createInstance(Ci.sbIPropertyUnitConverter);
131  (messageKeyPrefix + ".message",
132  [ aDevice.name,
133  storageConverter.autoFormat(aSpaceNeeded, -1, 1),
134  storageConverter.autoFormat(aSpaceAvailable, -1, 1) ]);
135 
136  var buttonFlags = (Ci.nsIPromptService.BUTTON_POS_0 *
137  Ci.nsIPromptService.BUTTON_TITLE_IS_STRING) +
138  (Ci.nsIPromptService.BUTTON_POS_1 *
139  Ci.nsIPromptService.BUTTON_TITLE_IS_STRING);
140  var prompter = Cc["@songbirdnest.com/Songbird/Prompter;1"]
141  .getService(Ci.sbIPrompter);
142  var neverPromptAgain = { value: false };
143  var abortRequest = prompter.confirmEx
144  (aParent,
145  SBString(messageKeyPrefix + ".title"),
146  message,
147  buttonFlags,
148  SBString(messageKeyPrefix + ".confirm_button"),
149  SBString(messageKeyPrefix + ".cancel_button"),
150  null,
151  null,
152  neverPromptAgain);
153 
154  return !abortRequest;
155  },
156 
157  _getMessageKeyPrefix:
158  function BaseDeviceHelper__getMessageKeyPrefix(aLibrary) {
159  var messageKeyPrefix = "device.error.not_enough_freespace.prompt.";
160  messageKeyPrefix += "manual";
161 
162  return messageKeyPrefix;
163  },
164 
165  contractID: "@songbirdnest.com/Songbird/Device/Base/Helper;1",
166  classDescription: "Helper component for device implementations",
167  classID: Components.ID("{ebe6e08a-0604-44fd-a3d7-2be556b96b24}"),
168  QueryInterface: XPCOMUtils.generateQI([
169  Components.interfaces.sbIDeviceHelper
170  ])
171 };
172 
173 NSGetModule = XPCOMUtils.generateNSGetModule([BaseDeviceHelper], null, null);
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function SBString(aKey, aDefault, aStringBundle)
Definition: StringUtils.jsm:93
GstMessage * message
return null
Definition: FeedWriter.js:1143
const Ci
const Cc
countRef value
Definition: FeedWriter.js:1423
sbDeviceFirmwareAutoCheckForUpdate prototype classID
function BaseDeviceHelper()