33 #include <nsNetUtil.h>
47 #include <nsNetUtil.h>
50 #include <sbIMediaItem.h>
51 #include <sbIMediaList.h>
52 #include <sbIOrderableMediaList.h>
61 if (aIgnoreListener) {
62 PR_AtomicIncrement(&mIgnoreListenerCounter);
65 NS_ASSERTION(result >= 0,
"invalid device library ignore listener counter");
71 NS_ENSURE_ARG_POINTER(aItem);
74 nsresult rv = aItem->GetGuid(guid);
75 NS_ENSURE_SUCCESS(rv, rv);
77 nsAutoLock lock(mLock);
79 PRInt32 itemCount = 0;
82 mIgnored.Get(guid, &itemCount);
83 if (!mIgnored.Put(guid, ++itemCount))
84 return NS_ERROR_FAILURE;
93 NS_ENSURE_ARG_POINTER(aItem);
97 if (mIgnoreListenerCounter > 0)
99 nsAutoLock lock(mLock);
100 nsresult rv = aItem->GetGuid(guid);
103 return (NS_SUCCEEDED(rv) && mIgnored.Get(guid, nsnull)) ? PR_TRUE :
109 nsresult rv = aItem->GetGuid(guid);
110 NS_ENSURE_SUCCESS(rv, rv);
112 nsAutoLock lock(mLock);
113 PRInt32 itemCount = 0;
114 if (!mIgnored.Get(guid, &itemCount)) {
116 return NS_ERROR_FAILURE;
119 if (--itemCount == 0) {
120 mIgnored.Remove(guid);
123 mIgnored.Put(guid, itemCount);
137 NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
139 nsCOMPtr<nsIMutableArray> mURIs;
149 NS_ENSURE_ARG_POINTER(_retval);
155 MediaItemContentSrcArrayCreator::OnEnumeratedItem(
sbIMediaList*,
159 NS_ENSURE_ARG_POINTER(aItem);
160 NS_ENSURE_ARG_POINTER(_retval);
166 nsCOMPtr<nsIURI>
uri;
167 nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(aItem, &rv);
168 if (NS_SUCCEEDED(rv)) {
169 nsAutoString playlistURL;
172 NS_ENSURE_SUCCESS(rv, rv);
173 rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(playlistURL));
174 NS_ENSURE_SUCCESS(rv, rv);
177 rv = aItem->GetContentSrc(getter_AddRefs(uri));
178 NS_ENSURE_SUCCESS(rv, rv);
182 rv = mURIs->AppendElement(uri, PR_FALSE);
183 NS_ENSURE_SUCCESS(rv, rv);
190 MediaItemContentSrcArrayCreator::OnEnumerationEnd(
sbIMediaList*,
214 NS_ENSURE_ARG_POINTER(aDevice);
228 sbBaseDeviceLibraryListener::OnBatchBegin(
sbIMediaList *aMediaList)
234 sbBaseDeviceLibraryListener::OnBatchEnd(
sbIMediaList *aMediaList)
237 NS_ENSURE_STATE(grip);
247 return NS_SUCCEEDED(rv) && hidden.Equals(NS_LITERAL_STRING(
"1"));
251 sbBaseDeviceLibraryListener::OnItemAdded(
sbIMediaList *aMediaList,
254 PRBool *aNoMoreForBatch)
256 NS_ENSURE_ARG_POINTER(aMediaList);
257 NS_ENSURE_ARG_POINTER(aMediaItem);
258 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
259 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
261 *aNoMoreForBatch = PR_FALSE;
277 nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem);
284 NS_ENSURE_SUCCESS(rv, rv);
288 aMediaItem, aMediaList, aIndex);
289 NS_ENSURE_SUCCESS(rv, rv);
295 NS_LITERAL_STRING(
"1"));
296 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
297 "Failed to hide newly added item");
302 aMediaItem, aMediaList, aIndex);
303 NS_ENSURE_SUCCESS(rv, rv);
310 sbBaseDeviceLibraryListener::OnBeforeItemRemoved(
sbIMediaList *aMediaList,
313 PRBool *aNoMoreForBatch)
315 NS_ENSURE_ARG_POINTER(aMediaList);
316 NS_ENSURE_ARG_POINTER(aMediaItem);
317 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
318 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
320 *aNoMoreForBatch = PR_FALSE;
325 sbBaseDeviceLibraryListener::OnAfterItemRemoved(
sbIMediaList *aMediaList,
328 PRBool *aNoMoreForBatch)
330 NS_ENSURE_ARG_POINTER(aMediaList);
331 NS_ENSURE_ARG_POINTER(aMediaItem);
332 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
333 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
335 *aNoMoreForBatch = PR_FALSE;
352 nsString hiddenValue;
355 if (NS_SUCCEEDED(rv) && hiddenValue.Equals(NS_LITERAL_STRING(
"1")))
359 aMediaItem, aMediaList, aIndex);
360 NS_ENSURE_SUCCESS(rv, rv);
366 sbBaseDeviceLibraryListener::OnListCleared(
sbIMediaList *aMediaList,
367 PRBool aExcludeLists,
368 PRBool* aNoMoreForBatch)
370 NS_ENSURE_ARG_POINTER(aMediaList);
371 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
372 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
374 *aNoMoreForBatch = PR_FALSE;
379 sbBaseDeviceLibraryListener::OnBeforeListCleared(
sbIMediaList *aMediaList,
380 PRBool aExcludeLists,
383 NS_ENSURE_ARG_POINTER(aMediaList);
384 NS_ENSURE_ARG_POINTER(_retval);
385 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
402 nsCOMPtr<nsIMutableArray>
uris =
403 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
404 NS_ENSURE_SUCCESS(rv, rv);
406 nsRefPtr<MediaItemContentSrcArrayCreator> creator =
409 rv = aMediaList->EnumerateItemsByProperty
411 NS_LITERAL_STRING(
"0"),
414 NS_ENSURE_SUCCESS(rv, rv);
417 rv = aMediaList->EnumerateAllItems(creator,
419 NS_ENSURE_SUCCESS(rv, rv);
428 NS_ENSURE_SUCCESS(rv, rv);
434 sbBaseDeviceLibraryListener::OnItemUpdated(
sbIMediaList *aMediaList,
437 PRBool* aNoMoreForBatch)
439 NS_ENSURE_ARG_POINTER(aMediaItem);
440 NS_ENSURE_ARG_POINTER(aMediaList);
441 NS_ENSURE_ARG_POINTER(aProperties);
442 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
443 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
445 *aNoMoreForBatch = PR_FALSE;
462 nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem);
468 rv = aProperties->GetLength(&length);
470 if (NS_SUCCEEDED(rv) && length == 1) {
480 NS_ENSURE_SUCCESS(rv, rv);
486 sbBaseDeviceLibraryListener::OnItemMoved(
sbIMediaList *aMediaList,
489 PRBool *aNoMoreForBatch)
491 NS_ENSURE_ARG_POINTER(aMediaList);
492 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
493 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
495 *aNoMoreForBatch = PR_FALSE;
512 NS_ENSURE_SUCCESS(rv, rv);
518 sbBaseDeviceLibraryListener::OnItemCopied(
sbIMediaItem *aSourceItem,
521 NS_ENSURE_ARG_POINTER(aSourceItem);
522 NS_ENSURE_ARG_POINTER(aDestItem);
523 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
528 sbBaseDeviceLibraryListener::OnBeforeCreateMediaItem(nsIURI *aContentUri,
530 PRBool aAllowDuplicates,
533 NS_ENSURE_ARG_POINTER(aContentUri);
534 NS_ENSURE_ARG_POINTER(_retval);
535 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
540 sbBaseDeviceLibraryListener::OnBeforeCreateMediaList(
const nsAString & aType,
544 NS_ENSURE_ARG_POINTER(_retval);
545 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
550 sbBaseDeviceLibraryListener::OnBeforeAdd(
sbIMediaItem *aMediaItem,
553 NS_ENSURE_ARG_POINTER(aMediaItem);
554 NS_ENSURE_ARG_POINTER(_retval);
555 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
559 NS_IMETHODIMP sbBaseDeviceLibraryListener::OnBeforeAddAll(
sbIMediaList *aMediaList,
562 NS_ENSURE_ARG_POINTER(aMediaList);
563 NS_ENSURE_ARG_POINTER(_retval);
564 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
568 NS_IMETHODIMP sbBaseDeviceLibraryListener::OnBeforeAddSome(
nsISimpleEnumerator *aMediaItems,
571 NS_ENSURE_ARG_POINTER(aMediaItems);
572 NS_ENSURE_ARG_POINTER(_retval);
573 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
577 NS_IMETHODIMP sbBaseDeviceLibraryListener::OnBeforeClear(PRBool *_retval)
579 NS_ENSURE_ARG_POINTER(_retval);
580 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
602 NS_ENSURE_ARG_POINTER(aDevice);
610 sbDeviceBaseLibraryCopyListener::OnItemCopied(
sbIMediaItem *aSourceItem,
613 NS_ENSURE_ARG_POINTER(aSourceItem);
614 NS_ENSURE_ARG_POINTER(aDestItem);
619 nsCOMPtr<nsIURI> srcURI, destURI;
620 nsCString srcSpec, destSpec;
621 nsCOMPtr<sbILibrary> srcLib, destLib;
622 nsString srcLibId, destLibId;
623 rv = aSourceItem->GetContentSrc(getter_AddRefs(srcURI));
624 if (NS_SUCCEEDED(rv)) {
625 rv = srcURI->GetSpec(srcSpec);
627 rv = aSourceItem->GetLibrary(getter_AddRefs(srcLib));
628 if (NS_SUCCEEDED(rv)) {
629 rv = srcLib->GetGuid(srcLibId);
631 rv = aDestItem->GetContentSrc(getter_AddRefs(destURI));
632 if (NS_SUCCEEDED(rv)) {
633 rv = destURI->GetSpec(destSpec);
635 rv = aDestItem->GetLibrary(getter_AddRefs(destLib));
636 if (NS_SUCCEEDED(rv)) {
637 rv = destLib->GetGuid(destLibId);
639 TRACE(
"%s: %s::%s -> %s::%s",
641 NS_ConvertUTF16toUTF8(srcLibId).
get(), srcSpec.get(),
642 NS_ConvertUTF16toUTF8(destLibId).get(), destSpec.get());
646 aSourceItem, nsnull);
647 NS_ENSURE_SUCCESS(rv, rv);
669 NS_ENSURE_ARG_POINTER(aDevice);
670 NS_ENSURE_FALSE(
mDevice, NS_ERROR_ALREADY_INITIALIZED);
676 sbBaseDeviceMediaListListener::OnItemAdded(
sbIMediaList *aMediaList,
681 NS_ENSURE_ARG_POINTER(aMediaList);
682 NS_ENSURE_ARG_POINTER(aMediaItem);
683 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
691 nsCOMPtr<sbILibrary> lib = do_QueryInterface(aMediaList);
698 nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem);
703 aMediaItem, aMediaList, aIndex);
704 NS_ENSURE_SUCCESS(rv, rv);
715 sbBaseDeviceMediaListListener::OnBeforeItemRemoved(
sbIMediaList *aMediaList,
724 sbBaseDeviceMediaListListener::OnAfterItemRemoved(
sbIMediaList *aMediaList,
729 NS_ENSURE_ARG_POINTER(aMediaList);
730 NS_ENSURE_ARG_POINTER(aMediaItem);
731 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
740 aMediaItem, aMediaList, aIndex);
741 NS_ENSURE_SUCCESS(rv, rv);
751 sbBaseDeviceMediaListListener::OnItemUpdated(
sbIMediaList *aMediaList,
760 sbBaseDeviceMediaListListener::OnItemMoved(
sbIMediaList *aMediaList,
765 NS_ENSURE_ARG_POINTER(aMediaList);
766 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
774 nsnull, aMediaList, aFromIndex, aToIndex);
775 NS_ENSURE_SUCCESS(rv, rv);
785 sbBaseDeviceMediaListListener::OnBeforeListCleared(
sbIMediaList *aMediaList,
786 PRBool aExcludeLists,
793 sbBaseDeviceMediaListListener::OnListCleared(
sbIMediaList *aMediaList,
794 PRBool aExcludeLists,
797 NS_ENSURE_ARG_POINTER(aMediaList);
799 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
811 NS_ENSURE_SUCCESS(rv, rv);
817 sbBaseDeviceMediaListListener::OnBatchBegin(
sbIMediaList *aMediaList)
826 sbBaseDeviceMediaListListener::OnBatchEnd(
sbIMediaList *aMediaList)
nsresult Init(sbBaseDevice *aDevice)
#define SB_PRLOG_SETUP(x)
virtual ~sbDeviceBaseLibraryCopyListener()
nsresult Init(sbBaseDevice *aDevice)
NS_IMPL_THREADSAFE_ISUPPORTS2(sbBaseDeviceLibraryListener, sbIDeviceLibraryListener, nsISupportsWeakReference)
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceBaseLibraryCopyListener, sbILocalDatabaseMediaListCopyListener)
#define SB_PROPERTY_HIDDEN
NS_IMPL_ISUPPORTS1(MediaItemContentSrcArrayCreator, sbIMediaListEnumerationListener) NS_IMETHODIMP MediaItemContentSrcArrayCreator
Interface used to listen to changes to a device library.
nsresult SetIgnoreListener(PRBool aIgnoreListener)
nsresult ListenToList(sbIMediaList *aList)
nsresult PushRequest(const PRUint32 aType, sbIMediaItem *aItem=nsnull, sbIMediaList *aList=nsnull, PRUint32 aIndex=PR_UINT32_MAX, PRUint32 aOtherIndex=PR_UINT32_MAX, nsISupports *aData=nsnull)
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICELIBRARYLISTENER sbBaseDeviceLibraryListener()
#define SB_PROPERTY_COLUMNSPEC
NS_DECL_ISUPPORTS NS_DECL_SBILOCALDATABASEMEDIALISTCOPYLISTENER sbDeviceBaseLibraryCopyListener()
nsresult UnignoreMediaItem(sbIMediaItem *aItem)
PRBool MediaItemIgnored(sbIMediaItem *aItem)
MediaItemContentSrcArrayCreator(nsIMutableArray *aURIs)
#define SB_PROPERTY_PLAYLISTURL
virtual ~sbBaseDeviceLibraryListener()
#define SB_PROPERTY_ISLIST
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
bool IsItemHidden(sbIMediaItem *aMediaItem)
#define SB_UNUSED_IN_RELEASE(decl)
nsresult IgnoreMediaItem(sbIMediaItem *aItem)