52 #include <sbILibrary.h>
53 #include <sbIPropertyArray.h>
96 NS_ENSURE_ARG_POINTER(aMediaItem);
97 NS_ENSURE_ARG_POINTER(aListener);
103 mWatchedMediaItem = aMediaItem;
104 mListener = aListener;
105 mWatchedPropertyIDs = aPropertyIDs;
108 nsCOMPtr<sbILibrary> library;
109 rv = mWatchedMediaItem->GetLibrary(getter_AddRefs(library));
110 NS_ENSURE_SUCCESS(rv, rv);
111 mWatchedLibraryML = do_QueryInterface(library, &rv);
112 NS_ENSURE_SUCCESS(rv, rv);
115 rv = mWatchedLibraryML->AddListener
122 mWatchedPropertyIDs);
123 NS_ENSURE_SUCCESS(rv, rv);
126 rv = GetWatchedMediaItemProperties(mWatchedMediaItemProperties);
127 NS_ENSURE_SUCCESS(rv, rv);
138 sbMediaItemWatcher::Cancel()
141 NS_WARN_IF_FALSE(mBatchLevel > 0,
142 "sbMediaItemWatcher::Cancel called during a batch");
144 if (mWatchedLibraryML)
145 mWatchedLibraryML->RemoveListener(
this);
148 mWatchedMediaItem = nsnull;
150 mWatchedPropertyIDs = nsnull;
151 mWatchedLibraryML = nsnull;
174 sbMediaItemWatcher::OnItemAdded(
sbIMediaList* aMediaList,
180 NS_ENSURE_ARG_POINTER(_retval);
197 sbMediaItemWatcher::OnBeforeItemRemoved(
sbIMediaList* aMediaList,
203 NS_ENSURE_ARG_POINTER(_retval);
220 sbMediaItemWatcher::OnAfterItemRemoved(
sbIMediaList* aMediaList,
227 NS_ENSURE_ARG_POINTER(aMediaItem);
228 NS_ENSURE_ARG_POINTER(_retval);
231 if (mBatchLevel > 0) {
237 if (aMediaItem == mWatchedMediaItem)
238 mListener->OnItemRemoved(mWatchedMediaItem);
259 sbMediaItemWatcher::OnItemUpdated(
sbIMediaList* aMediaList,
266 NS_ENSURE_ARG_POINTER(aMediaItem);
267 NS_ENSURE_ARG_POINTER(_retval);
275 rv = aProperties->ToString(props);
276 if (NS_FAILED(rv)) props.AssignLiteral(
"<ERROR>");
279 if (NS_FAILED(rv)) src.AssignLiteral(
"<ERROR>");
280 TRACE(
"item %s updated: %s",
281 NS_ConvertUTF16toUTF8(src).
get(),
282 NS_ConvertUTF16toUTF8(props).
get());
287 if (mBatchLevel > 0) {
288 TRACE(
"In a batch, skipping");
294 if (aMediaItem == mWatchedMediaItem) {
295 rv = DoItemUpdated();
296 TRACE(
"called: %08x", rv);
297 NS_ENSURE_SUCCESS(rv, rv);
318 sbMediaItemWatcher::OnItemMoved(
sbIMediaList* aMediaList,
324 NS_ENSURE_ARG_POINTER(_retval);
341 sbMediaItemWatcher::OnBeforeListCleared(
sbIMediaList* aMediaList,
342 PRBool aExcludeLists,
346 NS_ENSURE_ARG_POINTER(_retval);
363 sbMediaItemWatcher::OnListCleared(
sbIMediaList* aMediaList,
364 PRBool aExcludeLists,
369 NS_ENSURE_ARG_POINTER(_retval);
372 if (mBatchLevel > 0) {
378 if (mWatchedMediaItem) {
379 mListener->OnItemRemoved(mWatchedMediaItem);
401 sbMediaItemWatcher::OnBatchBegin(
sbIMediaList* aMediaList)
423 sbMediaItemWatcher::OnBatchEnd(
sbIMediaList* aMediaList)
434 if (!mWatchedMediaItem) {
435 NS_WARNING(
"sbMediaItemWatcher::OnBatchEnd");
439 nsAutoString properties;
440 rv = GetWatchedMediaItemProperties(properties);
441 NS_ENSURE_SUCCESS(rv, rv);
444 if (!properties.Equals(mWatchedMediaItemProperties)) {
445 rv = DoItemUpdated(properties);
446 NS_ENSURE_SUCCESS(rv, rv);
451 rv = mWatchedLibraryML->Contains(mWatchedMediaItem, &contains);
452 NS_ENSURE_SUCCESS(rv, rv);
454 mListener->OnItemRemoved(mWatchedMediaItem);
501 sbMediaItemWatcher::DoItemUpdated()
506 nsAutoString properties;
507 rv = GetWatchedMediaItemProperties(properties);
508 NS_ENSURE_SUCCESS(rv, rv);
511 rv = DoItemUpdated(properties);
512 NS_ENSURE_SUCCESS(rv, rv);
526 sbMediaItemWatcher::DoItemUpdated(nsAString& aItemProperties)
529 mWatchedMediaItemProperties.Assign(aItemProperties);
532 if (mWatchedMediaItem) {
533 mListener->OnItemUpdated(mWatchedMediaItem);
547 sbMediaItemWatcher::GetWatchedMediaItemProperties(nsAString& aProperties)
549 NS_ENSURE_TRUE(mWatchedMediaItem, NS_ERROR_NOT_AVAILABLE);
554 nsCOMPtr<sbIPropertyArray> propertyArray;
555 rv = mWatchedMediaItem->GetProperties(mWatchedPropertyIDs,
556 getter_AddRefs(propertyArray));
557 NS_ENSURE_SUCCESS(rv, rv);
558 rv = propertyArray->ToString(aProperties);
559 NS_ENSURE_SUCCESS(rv, rv);
#define SB_PRLOG_SETUP(x)
#define TRACE_FUNCTION(...)
#define SB_PROPERTY_CONTENTURL
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...