sbIPDProperties.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; 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 // iPod device properties imported services.
35 //
36 //------------------------------------------------------------------------------
37 
38 // Self import.
39 #include "sbIPDProperties.h"
40 
41 // Local imports.
42 #include "sbIPDDevice.h"
43 
44 // Songbird imports.
45 #include <sbIDeviceEvent.h>
47 
48 
49 //------------------------------------------------------------------------------
50 //
51 // iPod device properties nsISupports implementation.
52 //
53 //------------------------------------------------------------------------------
54 
57 NS_INTERFACE_MAP_BEGIN(sbIPDProperties)
58  NS_INTERFACE_MAP_ENTRY(sbIDeviceProperties)
59  NS_INTERFACE_MAP_ENTRY(nsIWritablePropertyBag)
60  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIPropertyBag, nsIWritablePropertyBag)
61  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWritablePropertyBag)
62  NS_INTERFACE_MAP_ENTRY(nsIPropertyBag2)
63  NS_INTERFACE_MAP_ENTRY(nsIWritablePropertyBag2)
64 NS_INTERFACE_MAP_END
65 
66 
67 //------------------------------------------------------------------------------
68 //
69 // iPod device properties sbIDeviceProperties implementation.
70 //
71 //------------------------------------------------------------------------------
72 
77 NS_IMETHODIMP
78 sbIPDProperties::InitFriendlyName(const nsAString& aFriendlyName)
79 {
80  return NS_ERROR_NOT_IMPLEMENTED;
81 }
82 
87 NS_IMETHODIMP
88 sbIPDProperties::InitDefaultName(const nsAString& aDefaultName)
89 {
90  return NS_ERROR_NOT_IMPLEMENTED;
91 }
92 
93 
98 NS_IMETHODIMP
99 sbIPDProperties::InitVendorName(const nsAString& aVendorName)
100 {
101  return NS_ERROR_NOT_IMPLEMENTED;
102 }
103 
104 
109 NS_IMETHODIMP
110 sbIPDProperties::InitModelNumber(nsIVariant* aModelNumber)
111 {
112  return NS_ERROR_NOT_IMPLEMENTED;
113 }
114 
115 
120 NS_IMETHODIMP
121 sbIPDProperties::InitSerialNumber(nsIVariant* aSerialNumber)
122 {
123  return NS_ERROR_NOT_IMPLEMENTED;
124 }
125 
130 NS_IMETHODIMP
131 sbIPDProperties::InitFirmwareVersion(const nsAString &aFirmwareVersion)
132 {
133  return NS_ERROR_NOT_IMPLEMENTED;
134 }
135 
140 NS_IMETHODIMP
141 sbIPDProperties::InitDeviceLocation(nsIURI* aDeviceLocationUri)
142 {
143  return NS_ERROR_NOT_IMPLEMENTED;
144 }
145 
146 
151 NS_IMETHODIMP
152 sbIPDProperties::InitDeviceIcon(nsIURI* aDeviceIconUri)
153 {
154  return NS_ERROR_NOT_IMPLEMENTED;
155 }
156 
157 
162 NS_IMETHODIMP
163 sbIPDProperties::InitDeviceProperties(nsIPropertyBag2* aProperties)
164 {
165  return NS_ERROR_NOT_IMPLEMENTED;
166 }
167 
168 
174 NS_IMETHODIMP
175 sbIPDProperties::InitDone()
176 {
177  return NS_ERROR_NOT_IMPLEMENTED;
178 }
179 
180 
181 //
182 // Getters/setters.
183 //
184 
191 NS_IMETHODIMP
192 sbIPDProperties::GetFriendlyName(nsAString& aFriendlyName)
193 {
194  return GetPropertyAsAString(NS_LITERAL_STRING("FriendlyName"), aFriendlyName);
195 }
196 
197 NS_IMETHODIMP
198 sbIPDProperties::SetFriendlyName(const nsAString& aFriendlyName)
199 {
200  return SetPropertyAsAString(NS_LITERAL_STRING("FriendlyName"), aFriendlyName);
201 }
202 
203 
209 NS_IMETHODIMP
210 sbIPDProperties::GetDefaultName(nsAString& aDefaultName)
211 {
212  return GetPropertyAsAString(
213  NS_LITERAL_STRING(SB_DEVICE_PROPERTY_DEFAULT_NAME),
214  aDefaultName);
215 }
216 
217 
222 NS_IMETHODIMP
223 sbIPDProperties::GetVendorName(nsAString& aVendorName)
224 {
225  return GetPropertyAsAString(NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MANUFACTURER),
226  aVendorName);
227 }
228 
229 
235 NS_IMETHODIMP
236 sbIPDProperties::GetModelNumber(nsIVariant** aModelNumber)
237 {
238  return GetProperty(NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MODEL), aModelNumber);
239 }
240 
241 
247 NS_IMETHODIMP
248 sbIPDProperties::GetSerialNumber(nsIVariant** aSerialNumber)
249 {
250  return GetProperty(NS_LITERAL_STRING(SB_DEVICE_PROPERTY_SERIAL_NUMBER),
251  aSerialNumber);
252 }
253 
254 NS_IMETHODIMP
255 sbIPDProperties::GetFirmwareVersion(nsAString &aFirmwareVersion)
256 {
257  aFirmwareVersion.Truncate();
258  return NS_OK;
259 }
260 
266 NS_IMETHODIMP
267 sbIPDProperties::GetUri(nsIURI** aUri)
268 {
269  return NS_ERROR_FAILURE;
270 }
271 
272 
278 NS_IMETHODIMP
279 sbIPDProperties::GetIconUri(nsIURI** aIconUri)
280 {
281  return GetPropertyAsInterface(NS_LITERAL_STRING("DeviceIcon"),
282  NS_GET_IID(nsIURI),
283  (void**) aIconUri);
284 }
285 
286 
287 NS_IMETHODIMP
288 sbIPDProperties::SetHidden(PRBool aHidden)
289 {
290  nsresult rv =
291  mProperties2->SetPropertyAsBool(NS_LITERAL_STRING(SB_DEVICE_PROPERTY_HIDDEN),
292  aHidden);
293  NS_ENSURE_SUCCESS(rv, rv);
294 
295  rv = mDevice->CreateAndDispatchEvent(
297  NS_ENSURE_SUCCESS(rv, rv);
298 
299  return NS_OK;
300 }
301 
302 
303 NS_IMETHODIMP
304 sbIPDProperties::GetHidden(PRBool *aHidden)
305 {
306  NS_ENSURE_ARG_POINTER(aHidden);
307 
308  nsresult rv = mProperties2->GetPropertyAsBool(
309  NS_LITERAL_STRING(SB_DEVICE_PROPERTY_HIDDEN),
310  aHidden);
311  NS_ENSURE_SUCCESS(rv, rv);
312 
313  return NS_OK;
314 }
315 
316 
322 NS_IMETHODIMP
323 sbIPDProperties::GetProperties(nsIPropertyBag2** aProperties)
324 {
325  // Validate arguments.
326  NS_ENSURE_ARG_POINTER(aProperties);
327 
328  // Return results.
329  NS_ADDREF(*aProperties = this);
330 
331  return NS_OK;
332 }
333 
334 
335 //------------------------------------------------------------------------------
336 //
337 // iPod device properties nsIWritablePropertyBag implementation.
338 //
339 //------------------------------------------------------------------------------
340 
347 NS_IMETHODIMP
348 sbIPDProperties::SetProperty(const nsAString& name,
349  nsIVariant* value)
350 {
351  // Validate arguments.
352  NS_ENSURE_ARG_POINTER(value);
353 
354  // Function variables.
355  nsresult rv;
356 
357  // If a property needs to be set under the request lock, enqueue a set
358  // property request. The internal property in the properties object is still
359  // set here to provide immediate feedback.
360  if (name.EqualsLiteral("FriendlyName")) {
361  rv = mDevice->ReqPushSetNamedValue(sbIPDDevice::REQUEST_SET_PROPERTY,
362  name,
363  value);
364  NS_ENSURE_SUCCESS(rv, rv);
365 
366  // once the name is set, mark the device as set up
367  rv = mDevice->SetIsSetUp(PR_TRUE);
368  NS_ENSURE_SUCCESS(rv, rv);
369  }
370 
371  // Set the property internally.
372  rv = mProperties->SetProperty(name, value);
373  NS_ENSURE_SUCCESS(rv, rv);
374 
375  // Dispatch a device info changed event.
376  rv = mDevice->CreateAndDispatchEvent
378  NS_ENSURE_SUCCESS(rv, rv);
379 
380  return NS_OK;
381 }
382 
383 
390 NS_IMETHODIMP
391 sbIPDProperties::DeleteProperty(const nsAString& name)
392 {
393  return mProperties->DeleteProperty(name);
394 }
395 
396 
397 //------------------------------------------------------------------------------
398 //
399 // iPod device properties services.
400 //
401 //------------------------------------------------------------------------------
402 
408  mDevice(aDevice)
409 {
410  // Validate object fields.
411  NS_ASSERTION(mDevice, "mDevice is null");
412 }
413 
414 
420 {
421 }
422 
423 
428 nsresult
430 {
431  nsresult rv;
432 
433  // Create the internal property storage object.
434  mProperties = do_CreateInstance("@songbirdnest.com/moz/xpcom/sbpropertybag;1", &rv);
435  NS_ENSURE_SUCCESS(rv, rv);
436  mProperties2 = do_QueryInterface(mProperties, &rv);
437  NS_ENSURE_SUCCESS(rv, rv);
438 
439  // Copy the device creation parameters to the device properties.
440  nsCOMPtr<nsIPropertyBag2> parameters;
441  nsAutoString property;
442  rv = mDevice->GetParameters(getter_AddRefs(parameters));
443  NS_ENSURE_SUCCESS(rv, rv);
444  rv = parameters->GetPropertyAsAString
445  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MANUFACTURER),
446  property);
447  NS_ENSURE_SUCCESS(rv, rv);
448  rv = mProperties2->SetPropertyAsAString
449  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MANUFACTURER),
450  property);
451  NS_ENSURE_SUCCESS(rv, rv);
452  rv = parameters->GetPropertyAsAString
453  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MODEL),
454  property);
455  NS_ENSURE_SUCCESS(rv, rv);
456  rv = mProperties2->SetPropertyAsAString
457  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MODEL),
458  property);
459  NS_ENSURE_SUCCESS(rv, rv);
460  rv = parameters->GetPropertyAsAString
461  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_SERIAL_NUMBER),
462  property);
463  NS_ENSURE_SUCCESS(rv, rv);
464  rv = mProperties2->SetPropertyAsAString
465  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_SERIAL_NUMBER),
466  property);
467  NS_ENSURE_SUCCESS(rv, rv);
468  rv = mProperties2->SetPropertyAsBool
469  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_HIDDEN),
470  PR_FALSE);
471 
472  // Set the device access compatibility.
473  rv = mProperties2->SetPropertyAsAString
474  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_ACCESS_COMPATIBILITY),
475  NS_LITERAL_STRING("rw"));
476  NS_ENSURE_SUCCESS(rv, rv);
477 
478  // Set the device icon property.
479  rv = mProperties2->SetPropertyAsInterface
480  (NS_LITERAL_STRING("DeviceIcon"),
481  sbIPDURI("chrome://ipod/skin/icon-ipod.png").get());
482  NS_ENSURE_SUCCESS(rv, rv);
483 
484  return NS_OK;
485 }
486 
487 
492 void
494 {
495  // Remove object references.
496  mDevice = nsnull;
497  mProperties = nsnull;
498  mProperties2 = nsnull;
499 }
500 
501 
510 nsresult
512  nsIVariant* aValue)
513 {
514  // Validate properties.
515  NS_ENSURE_ARG_POINTER(aValue);
516 
517  // Set the internal property storage.
518  return mProperties->SetProperty(aName, aValue);
519 }
520 
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
return NS_OK
virtual ~sbIPDProperties()
onPageChanged aValue
Definition: FeedWriter.js:1395
#define SB_DEVICE_PROPERTY_HIDDEN
NS_IMETHOD SetPropertyAsAString(const nsAString &aName, const nsAString &aValue)
Songbird iPod Device Properties Definitions.
#define SB_DEVICE_PROPERTY_ACCESS_COMPATIBILITY
#define SB_DEVICE_PROPERTY_MANUFACTURER
#define SB_DEVICE_PROPERTY_DEFAULT_NAME
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
Songbird iPod Device Definitions.
static nsresult GetProperty(nsIPropertyBag2 *aProperties, nsAString const &aProp, nsAString &aValue)
const unsigned long EVENT_DEVICE_INFO_CHANGED
sbIPDProperties(sbIPDDevice *aDevice)
_updateCookies aName
countRef value
Definition: FeedWriter.js:1423
#define SB_DEVICE_PROPERTY_SERIAL_NUMBER
nsresult SetPropertyInternal(const nsAString &aName, nsIVariant *aValue)
#define SB_DEVICE_PROPERTY_MODEL