30 #include <nsArrayUtils.h>
31 #include <nsISupportsPrimitives.h>
32 #include <nsIVariant.h>
33 #include <nsIWritablePropertyBag2.h>
39 #include <sbIDevice.h>
40 #include <sbIDeviceCapabilities.h>
41 #include <sbIDeviceEvent.h>
42 #include <sbIDeviceEventTarget.h>
43 #include <sbIDeviceManager.h>
44 #include <sbIMediaItem.h>
45 #include <sbITranscodeManager.h>
56 static PRLogModuleInfo* gDefaultBaseDeviceInfoRegistrarLog = nsnull;
57 #define TRACE(args) PR_LOG(gDefaultBaseDeviceInfoRegistrarLog , PR_LOG_DEBUG, args)
58 #define LOG(args) PR_LOG(gDefaultBaseDeviceInfoRegistrarLog , PR_LOG_WARN, args)
60 #define __FUNCTION__ __PRETTY_FUNCTION__
69 mDeviceXMLInfoPresent(PR_FALSE)
72 if (!gDefaultBaseDeviceInfoRegistrarLog)
73 gDefaultBaseDeviceInfoRegistrarLog =
74 PR_NewLogModule(
"sbDefaultBaseDeviceInfoRegistrar");
84 sbDefaultBaseDeviceInfoRegistrar::GetType(PRUint32 *aType)
86 TRACE((
"%s: default", __FUNCTION__));
87 NS_ENSURE_ARG_POINTER(aType);
94 sbDefaultBaseDeviceInfoRegistrar::
97 TRACE((
"%s", __FUNCTION__));
98 NS_ENSURE_ARG_POINTER(aDevice);
99 NS_ENSURE_ARG_POINTER(aCapabilities);
104 nsCOMPtr<nsIVariant> capabilitiesVariant;
105 rv = aDevice->GetPreference(NS_LITERAL_STRING(
"capabilities"),
106 getter_AddRefs(capabilitiesVariant));
107 if (NS_SUCCEEDED(rv)) {
109 rv = capabilitiesVariant->GetDataType(&dataType);
110 NS_ENSURE_SUCCESS(rv, rv);
112 if ((dataType == nsIDataType::VTYPE_INTERFACE) ||
113 (dataType == nsIDataType::VTYPE_INTERFACE_IS)) {
114 nsCOMPtr<nsISupports> capabilitiesISupports;
115 nsCOMPtr<sbIDeviceCapabilities> capabilities;
116 rv = capabilitiesVariant->GetAsISupports
117 (getter_AddRefs(capabilitiesISupports));
118 NS_ENSURE_SUCCESS(rv, rv);
119 capabilities = do_QueryInterface(capabilitiesISupports, &rv);
120 NS_ENSURE_SUCCESS(rv, rv);
121 rv = aCapabilities->AddCapabilities(capabilities);
122 NS_ENSURE_SUCCESS(rv, rv);
130 NS_ENSURE_SUCCESS(rv, rv);
133 nsCOMPtr<nsIDOMElement> deviceInfoElement;
135 NS_ENSURE_SUCCESS(rv, rv);
138 if (deviceInfoElement) {
139 PRBool addedCapabilities;
144 NS_ENSURE_SUCCESS(rv, rv);
152 sbDefaultBaseDeviceInfoRegistrar::GetDefaultName(
sbIDevice* aDevice,
155 TRACE((
"%s", __FUNCTION__));
165 NS_ENSURE_SUCCESS(rv, rv);
171 NS_ENSURE_SUCCESS(rv, rv);
177 sbDefaultBaseDeviceInfoRegistrar::GetDeviceFolder(
sbIDevice* aDevice,
178 PRUint32 aContentType,
181 TRACE((
"%s", __FUNCTION__));
191 NS_ENSURE_SUCCESS(rv, rv);
197 NS_ENSURE_SUCCESS(rv, rv);
203 sbDefaultBaseDeviceInfoRegistrar::GetImportRules(
205 nsIArray ** _retval NS_OUTPARAM)
207 TRACE((
"%s", __FUNCTION__));
209 NS_ENSURE_ARG_POINTER(_retval);
216 NS_ENSURE_SUCCESS(rv, rv);
222 NS_ENSURE_SUCCESS(rv, rv);
228 sbDefaultBaseDeviceInfoRegistrar::GetMountTimeout(
sbIDevice* aDevice,
231 TRACE((
"%s", __FUNCTION__));
233 NS_ENSURE_ARG_POINTER(aDevice);
234 NS_ENSURE_ARG_POINTER(retval);
241 NS_ENSURE_SUCCESS(rv, rv);
243 return NS_ERROR_NOT_AVAILABLE;
247 if (rv == NS_ERROR_NOT_AVAILABLE)
248 return NS_ERROR_NOT_AVAILABLE;
249 NS_ENSURE_SUCCESS(rv, rv);
255 sbDefaultBaseDeviceInfoRegistrar::GetExcludedFolders(
sbIDevice * aDevice,
256 nsAString & aFolders)
258 TRACE((
"%s", __FUNCTION__));
266 NS_ENSURE_SUCCESS(rv, rv);
271 NS_ENSURE_SUCCESS(rv, rv);
277 sbDefaultBaseDeviceInfoRegistrar::GetDoesDeviceSupportReformat(
279 PRBool *aOutSupportsReformat)
281 NS_ENSURE_ARG_POINTER(aDevice);
282 NS_ENSURE_ARG_POINTER(aOutSupportsReformat);
287 NS_ENSURE_SUCCESS(rv, rv);
292 NS_ENSURE_SUCCESS(rv, rv);
298 sbDefaultBaseDeviceInfoRegistrar::GetOnlyMountMediaFolders
300 PRBool *aOnlyMountMediaFolders)
302 TRACE((
"%s", __FUNCTION__));
304 NS_ENSURE_ARG_POINTER(aDevice);
305 NS_ENSURE_ARG_POINTER(aOnlyMountMediaFolders);
310 NS_ENSURE_SUCCESS(rv, rv);
316 NS_ENSURE_SUCCESS(rv, rv);
322 sbDefaultBaseDeviceInfoRegistrar::GetStorageDeviceInfoList
326 TRACE((
"%s", __FUNCTION__));
328 NS_ENSURE_ARG_POINTER(aDevice);
329 NS_ENSURE_ARG_POINTER(retval);
336 NS_ENSURE_SUCCESS(rv, rv);
338 return NS_ERROR_NOT_AVAILABLE;
342 if (rv == NS_ERROR_NOT_AVAILABLE)
343 return NS_ERROR_NOT_AVAILABLE;
344 NS_ENSURE_SUCCESS(rv, rv);
350 sbDefaultBaseDeviceInfoRegistrar::GetDeviceIcon(
sbIDevice* aDevice,
353 TRACE((
"%s", __FUNCTION__));
356 NS_ENSURE_ARG_POINTER(aDevice);
367 NS_ENSURE_SUCCESS(rv, rv);
373 NS_ENSURE_SUCCESS(rv, rv);
379 sbDefaultBaseDeviceInfoRegistrar::InterestedInDevice(
sbIDevice *aDevice,
382 NS_ENSURE_ARG_POINTER(aDevice);
383 NS_ENSURE_ARG_POINTER(retval);
390 nsCString xmlInfoSpec;
392 NS_ENSURE_SUCCESS(rv, rv);
393 if (xmlInfoSpec.IsEmpty())
397 NS_ENSURE_TRUE(xmlInfo, NS_ERROR_OUT_OF_MEMORY);
399 nsCString xmlInfoExtensions;
401 NS_ENSURE_SUCCESS(rv, rv);
402 rv = xmlInfo->Read(xmlInfoSpec.get(), xmlInfoExtensions.get());
403 NS_ENSURE_SUCCESS(rv, rv);
406 PRBool infoPresent = PR_FALSE;
407 rv = xmlInfo->GetDeviceInfoPresent(&infoPresent);
408 NS_ENSURE_SUCCESS(rv, rv);
422 NS_ENSURE_ARG_POINTER(aDevice);
423 NS_ENSURE_ARG_POINTER(aDeviceXMLInfo);
428 *aDeviceXMLInfo = nsnull;
431 if (mDeviceXMLInfo && (aDevice == mDevice)) {
432 if (mDeviceXMLInfoPresent)
433 *aDeviceXMLInfo = mDeviceXMLInfo;
441 nsCAutoString deviceXMLInfoSpec;
442 rv = GetDeviceXMLInfoSpec(deviceXMLInfoSpec);
443 NS_ENSURE_SUCCESS(rv, rv);
446 if (!deviceXMLInfoSpec.IsEmpty()) {
447 rv = GetDeviceXMLInfo(deviceXMLInfoSpec, aDevice);
448 NS_ENSURE_SUCCESS(rv, rv);
453 if (!mDeviceXMLInfoPresent) {
454 rv = GetDefaultDeviceXMLInfoSpec(deviceXMLInfoSpec);
455 NS_ENSURE_SUCCESS(rv, rv);
456 rv = GetDeviceXMLInfo(deviceXMLInfoSpec, aDevice);
457 NS_ENSURE_SUCCESS(rv, rv);
461 if (mDeviceXMLInfoPresent)
462 *aDeviceXMLInfo = mDeviceXMLInfo;
469 (
const nsACString& aDeviceXMLInfoSpec,
472 NS_ENSURE_ARG_POINTER(aDevice);
478 NS_ENSURE_TRUE(mDeviceXMLInfo, NS_ERROR_OUT_OF_MEMORY);
479 nsCString xmlInfoExtensions;
480 rv = GetDeviceXMLInfoExtensions(xmlInfoExtensions);
481 NS_ENSURE_SUCCESS(rv, rv);
482 rv = mDeviceXMLInfo->Read(aDeviceXMLInfoSpec.BeginReading(),
483 xmlInfoExtensions.get());
484 NS_ENSURE_SUCCESS(rv, rv);
487 rv = mDeviceXMLInfo->GetDeviceInfoPresent(&mDeviceXMLInfoPresent);
488 NS_ENSURE_SUCCESS(rv, rv);
495 (nsACString& aDeviceXMLInfoSpec)
497 aDeviceXMLInfoSpec.Truncate();
503 (nsACString& aDeviceXMLInfoExtensions)
505 aDeviceXMLInfoExtensions.Truncate();
511 (nsACString& aDeviceXMLInfoSpec)
513 aDeviceXMLInfoSpec.Assign
514 (
"chrome://songbird/content/devices/sbDefaultDeviceInfo.xml");
nsresult GetDeviceXMLInfo(sbIDevice *aDevice, sbDeviceXMLInfo **aDeviceXMLInfo)
virtual nsresult GetDefaultDeviceXMLInfoSpec(nsACString &aDeviceXMLInfoSpec)
[UNIMPLEMENTED UNTIL AFTER 0.3]
nsresult GetStorageDeviceInfoList(nsIArray **aStorageDeviceInfoList)
Songbird Variant Utility Definitions.
nsresult GetDeviceInfoElement(nsIDOMElement **aDeviceInfoElement)
nsresult GetDeviceIcon(nsAString &aDeviceIconURL)
nsresult GetDeviceFolder(const nsAString &aFolderType, nsAString &aFolderURL)
nsresult GetDefaultName(nsAString &aDefaultName)
virtual ~sbDefaultBaseDeviceInfoRegistrar()
nsresult GetOnlyMountMediaFolders(PRBool *aOnlyMountMediaFolders)
static nsresult AddCapabilities(sbIDeviceCapabilities *aCapabilities, const char *aXMLCapabilitiesSpec, PRBool *aAddedCapabilities=nsnull, sbIDevice *aDevice=nsnull)
virtual nsresult GetDeviceXMLInfoSpec(nsACString &aDeviceXMLInfoSpec)
nsresult GetDoesDeviceSupportReformat(PRBool *aOutSupportsReformat)
NS_DECL_SBIDEVICEINFOREGISTRAR sbDefaultBaseDeviceInfoRegistrar()
virtual nsresult GetDeviceXMLInfoExtensions(nsACString &aDeviceXMLInfoExtensions)
nsresult GetMountTimeout(PRUint32 *aMountTimeout)
nsresult GetImportRules(nsIArray **aImportRules)
nsresult GetExcludedFolders(nsAString &aExcludedFolders)