sbLibraryListenerHelpers.cpp
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2011 POTI, Inc.
9 // http://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 */
27 
29 
30 // Mozilla includes
31 #include <pratom.h>
32 #include <prlog.h>
33 #include <nsNetUtil.h>
34 
35 // Mozilla includes
36 #include <nsIURI.h>
37 
38 
39 // Local includes
40 #include "sbBaseDevice.h"
41 
42 #include <sbDebugUtils.h>
43 // Songbird includes
44 
45 #include <sbLibraryUtils.h>
46 #include <nsIURI.h>
47 #include <nsNetUtil.h>
48 
49 // Songbird interfaces
50 #include <sbIMediaItem.h>
51 #include <sbIMediaList.h>
52 #include <sbIOrderableMediaList.h>
53 
54 //
55 // To log this module, set the following environment variable:
56 // NSPR_LOG_MODULES=sbLibraryListenerHelpers:5
57 //
58 
59 nsresult
60 sbBaseIgnore::SetIgnoreListener(PRBool aIgnoreListener) {
61  if (aIgnoreListener) {
62  PR_AtomicIncrement(&mIgnoreListenerCounter);
63  } else {
64  PRInt32 SB_UNUSED_IN_RELEASE(result) = PR_AtomicDecrement(&mIgnoreListenerCounter);
65  NS_ASSERTION(result >= 0, "invalid device library ignore listener counter");
66  }
67  return NS_OK;
68 }
69 
71  NS_ENSURE_ARG_POINTER(aItem);
72 
73  nsString guid;
74  nsresult rv = aItem->GetGuid(guid);
75  NS_ENSURE_SUCCESS(rv, rv);
76 
77  nsAutoLock lock(mLock);
78 
79  PRInt32 itemCount = 0;
80  // We don't care if this fails, itemCount is zero in that case which is fine
81  // We have to assume failure is always due to "not found"
82  mIgnored.Get(guid, &itemCount);
83  if (!mIgnored.Put(guid, ++itemCount))
84  return NS_ERROR_FAILURE;
85 
86  return NS_OK;
87 }
88 
93  NS_ENSURE_ARG_POINTER(aItem);
94 
95  nsString guid;
96  // If ignoring all or ignoring this specific item return PR_TRUE
97  if (mIgnoreListenerCounter > 0)
98  return PR_TRUE;
99  nsAutoLock lock(mLock);
100  nsresult rv = aItem->GetGuid(guid);
101 
102  // If the guid was valid and it's in our ignore list then it's ignored
103  return (NS_SUCCEEDED(rv) && mIgnored.Get(guid, nsnull)) ? PR_TRUE :
104  PR_FALSE;
105 }
106 
108  nsString guid;
109  nsresult rv = aItem->GetGuid(guid);
110  NS_ENSURE_SUCCESS(rv, rv);
111 
112  nsAutoLock lock(mLock);
113  PRInt32 itemCount = 0;
114  if (!mIgnored.Get(guid, &itemCount)) {
115  // We're out of balance at this point
116  return NS_ERROR_FAILURE;
117  }
118  // If the item count is less than zero then remove the guid else just decrement it
119  if (--itemCount == 0) {
120  mIgnored.Remove(guid);
121  }
122  else
123  mIgnored.Put(guid, itemCount);
124  return NS_OK;
125 }
126 
131 {
132 public:
133  MediaItemContentSrcArrayCreator(nsIMutableArray* aURIs) :
134  mURIs(aURIs)
135  {}
137  NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
138 private:
139  nsCOMPtr<nsIMutableArray> mURIs;
140 };
141 
144 
145 NS_IMETHODIMP
146 MediaItemContentSrcArrayCreator::OnEnumerationBegin(sbIMediaList*,
147  PRUint16 *_retval)
148 {
149  NS_ENSURE_ARG_POINTER(_retval);
151  return NS_OK;
152 }
153 
154 NS_IMETHODIMP
155 MediaItemContentSrcArrayCreator::OnEnumeratedItem(sbIMediaList*,
156  sbIMediaItem* aItem,
157  PRUint16 *_retval)
158 {
159  NS_ENSURE_ARG_POINTER(aItem);
160  NS_ENSURE_ARG_POINTER(_retval);
161 
162  nsresult rv;
163 
164  // If the item is a media list, get the playlist URL property. Otherwise,
165  // get the media item content source.
166  nsCOMPtr<nsIURI> uri;
167  nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(aItem, &rv);
168  if (NS_SUCCEEDED(rv)) {
169  nsAutoString playlistURL;
170  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_PLAYLISTURL),
171  playlistURL);
172  NS_ENSURE_SUCCESS(rv, rv);
173  rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(playlistURL));
174  NS_ENSURE_SUCCESS(rv, rv);
175  }
176  else {
177  rv = aItem->GetContentSrc(getter_AddRefs(uri));
178  NS_ENSURE_SUCCESS(rv, rv);
179  }
180 
181  // Add the URI.
182  rv = mURIs->AppendElement(uri, PR_FALSE);
183  NS_ENSURE_SUCCESS(rv, rv);
184 
186  return NS_OK;
187 }
188 
189 NS_IMETHODIMP
190 MediaItemContentSrcArrayCreator::OnEnumerationEnd(sbIMediaList*,
191  nsresult)
192 {
193  return NS_OK;
194 }
195 
196 //sbBaseDeviceLibraryListener class.
200 
202 : mDevice(nsnull)
203 {
204  SB_PRLOG_SETUP(sbLibraryListenerHelpers);
205 }
206 
208 {
209 }
210 
211 nsresult
213 {
214  NS_ENSURE_ARG_POINTER(aDevice);
215 
216  mDevice = aDevice;
217 
218  return NS_OK;
219 }
220 
221 void
223 {
224  mDevice = nsnull;
225 }
226 
227 NS_IMETHODIMP
228 sbBaseDeviceLibraryListener::OnBatchBegin(sbIMediaList *aMediaList)
229 {
230  return mDevice->BatchBegin();
231 }
232 
233 NS_IMETHODIMP
234 sbBaseDeviceLibraryListener::OnBatchEnd(sbIMediaList *aMediaList)
235 {
236  nsRefPtr<nsISupports> grip(NS_ISUPPORTS_CAST(sbIDevice*, mDevice));
237  NS_ENSURE_STATE(grip);
238  return mDevice->BatchEnd();
239 }
240 
241 inline bool
243 {
244  nsString hidden;
245  nsresult rv = aMediaItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_HIDDEN),
246  hidden);
247  return NS_SUCCEEDED(rv) && hidden.Equals(NS_LITERAL_STRING("1"));
248 }
249 
250 NS_IMETHODIMP
251 sbBaseDeviceLibraryListener::OnItemAdded(sbIMediaList *aMediaList,
252  sbIMediaItem *aMediaItem,
253  PRUint32 aIndex,
254  PRBool *aNoMoreForBatch)
255 {
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);
260 
261  *aNoMoreForBatch = PR_FALSE;
262 
263  nsresult rv;
264 
265  // Skip hidden or ignored media items
266  if (IsItemHidden(aMediaList) || MediaItemIgnored(aMediaList)) {
267  return NS_OK;
268  }
269 
270  //XXXAus: Before adding to queue, make sure it doesn't come from
271  //another device. Ask DeviceManager for the device library
272  //containing this item.
273 
274  // Hide the item. It is the responsibility of the device to make the item
275  // visible when the transfer is successful.
276  // Listen to all added lists unless hidden.
277  nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem);
278  if (list) {
279  if (IsItemHidden(list)) {
280  return NS_OK;
281  }
282 
283  rv = mDevice->ListenToList(list);
284  NS_ENSURE_SUCCESS(rv, rv);
285 
286  // new playlist
288  aMediaItem, aMediaList, aIndex);
289  NS_ENSURE_SUCCESS(rv, rv);
290  } else {
291  IgnoreMediaItem(aMediaItem);
292  // Hide the item. It is the responsibility of the device to make the item
293  // visible when the transfer is successful.
294  rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_HIDDEN),
295  NS_LITERAL_STRING("1"));
296  NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
297  "Failed to hide newly added item");
298 
299  UnignoreMediaItem(aMediaItem);
300 
302  aMediaItem, aMediaList, aIndex);
303  NS_ENSURE_SUCCESS(rv, rv);
304  }
305 
306  return NS_OK;
307 }
308 
309 NS_IMETHODIMP
310 sbBaseDeviceLibraryListener::OnBeforeItemRemoved(sbIMediaList *aMediaList,
311  sbIMediaItem *aMediaItem,
312  PRUint32 aIndex,
313  PRBool *aNoMoreForBatch)
314 {
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);
319 
320  *aNoMoreForBatch = PR_FALSE;
321  return NS_OK;
322 }
323 
324 NS_IMETHODIMP
325 sbBaseDeviceLibraryListener::OnAfterItemRemoved(sbIMediaList *aMediaList,
326  sbIMediaItem *aMediaItem,
327  PRUint32 aIndex,
328  PRBool *aNoMoreForBatch)
329 {
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);
334 
335  *aNoMoreForBatch = PR_FALSE;
336 
337  if(MediaItemIgnored(aMediaList)) {
338  return NS_OK;
339  }
340 
341  // Skip hidden media items
342  if (IsItemHidden(aMediaItem) || IsItemHidden(aMediaList)) {
343  return NS_OK;
344  }
345 
346  nsresult rv;
347 
348  /* If the item is hidden, then it wasn't transferred to the device (which
349  will clear the hidden property once the transfer is complete), so don't
350  delete it
351  */
352  nsString hiddenValue;
353  rv = aMediaItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_HIDDEN),
354  hiddenValue);
355  if (NS_SUCCEEDED(rv) && hiddenValue.Equals(NS_LITERAL_STRING("1")))
356  return NS_OK;
357 
359  aMediaItem, aMediaList, aIndex);
360  NS_ENSURE_SUCCESS(rv, rv);
361 
362  return NS_OK;
363 }
364 
365 NS_IMETHODIMP
366 sbBaseDeviceLibraryListener::OnListCleared(sbIMediaList *aMediaList,
367  PRBool aExcludeLists,
368  PRBool* aNoMoreForBatch)
369 {
370  NS_ENSURE_ARG_POINTER(aMediaList);
371  NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
372  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
373 
374  *aNoMoreForBatch = PR_FALSE;
375 
376  return NS_OK;
377 }
378 NS_IMETHODIMP
379 sbBaseDeviceLibraryListener::OnBeforeListCleared(sbIMediaList *aMediaList,
380  PRBool aExcludeLists,
381  PRBool *_retval)
382 {
383  NS_ENSURE_ARG_POINTER(aMediaList);
384  NS_ENSURE_ARG_POINTER(_retval);
385  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
386 
387  nsresult rv;
388 
389  /* yay, we're going to wipe the device! */
390  if(MediaItemIgnored(aMediaList)) {
391  return NS_OK;
392  }
393 
394  // Skip hidden media items
395  if (IsItemHidden(aMediaList)) {
396  return NS_OK;
397  }
398 
399  // We capture the list of content that's going to be deleted here
400  // and hand it over to the device as an nsIArray<nsIURIs> through
401  // the TransferRequest's data member.
402  nsCOMPtr<nsIMutableArray> uris =
403  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
404  NS_ENSURE_SUCCESS(rv, rv);
405 
406  nsRefPtr<MediaItemContentSrcArrayCreator> creator =
408  if (aExcludeLists) {
409  rv = aMediaList->EnumerateItemsByProperty
410  (NS_LITERAL_STRING(SB_PROPERTY_ISLIST),
411  NS_LITERAL_STRING("0"),
412  creator,
414  NS_ENSURE_SUCCESS(rv, rv);
415  }
416  else {
417  rv = aMediaList->EnumerateAllItems(creator,
419  NS_ENSURE_SUCCESS(rv, rv);
420  }
421 
423  aMediaList,
424  nsnull,
427  uris);
428  NS_ENSURE_SUCCESS(rv, rv);
429 
430  return NS_OK;
431 }
432 
433 NS_IMETHODIMP
434 sbBaseDeviceLibraryListener::OnItemUpdated(sbIMediaList *aMediaList,
435  sbIMediaItem *aMediaItem,
436  sbIPropertyArray* aProperties,
437  PRBool* aNoMoreForBatch)
438 {
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);
444 
445  *aNoMoreForBatch = PR_FALSE;
446 
447  if(MediaItemIgnored(aMediaItem)) {
448  return NS_OK;
449  }
450 
451  // Skip hidden media items
452  if (IsItemHidden(aMediaItem)) {
453  return NS_OK;
454  }
455 
456  nsresult rv;
457 
458  // We don't want to send updates for column spec only changes. The device
459  // doesn't care about it, it just creates needless thrashing of the device
460  // playlists.
461  // TODO: XXX See Bug 24191 to see what's to come and feel free to comment.
462  nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem);
463  if (list) {
464  nsString name;
465  rv = aProperties->GetPropertyValue(NS_LITERAL_STRING(SB_PROPERTY_COLUMNSPEC),
466  name);
467  PRUint32 length;
468  rv = aProperties->GetLength(&length);
469  // If the column spec property is the only thing changing, ignore the update
470  if (NS_SUCCEEDED(rv) && length == 1) {
471  return NS_OK;
472  }
473  }
475  aMediaItem,
476  aMediaList,
479  aProperties);
480  NS_ENSURE_SUCCESS(rv, rv);
481 
482  return NS_OK;
483 }
484 
485 NS_IMETHODIMP
486 sbBaseDeviceLibraryListener::OnItemMoved(sbIMediaList *aMediaList,
487  PRUint32 aFromIndex,
488  PRUint32 aToIndex,
489  PRBool *aNoMoreForBatch)
490 {
491  NS_ENSURE_ARG_POINTER(aMediaList);
492  NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
493  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
494 
495  *aNoMoreForBatch = PR_FALSE;
496 
497  if(MediaItemIgnored(aMediaList)) {
498  return NS_OK;
499  }
500 
501  // Skip hidden media items
502  if (IsItemHidden(aMediaList)) {
503  return NS_OK;
504  }
505 
506  nsresult rv;
508  nsnull,
509  aMediaList,
510  aFromIndex,
511  aToIndex);
512  NS_ENSURE_SUCCESS(rv, rv);
513 
514  return NS_OK;
515 }
516 
517 NS_IMETHODIMP
518 sbBaseDeviceLibraryListener::OnItemCopied(sbIMediaItem *aSourceItem,
519  sbIMediaItem *aDestItem)
520 {
521  NS_ENSURE_ARG_POINTER(aSourceItem);
522  NS_ENSURE_ARG_POINTER(aDestItem);
523  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
524  return NS_OK;
525 }
526 
527 NS_IMETHODIMP
528 sbBaseDeviceLibraryListener::OnBeforeCreateMediaItem(nsIURI *aContentUri,
529  sbIPropertyArray *aProperties,
530  PRBool aAllowDuplicates,
531  PRBool *_retval)
532 {
533  NS_ENSURE_ARG_POINTER(aContentUri);
534  NS_ENSURE_ARG_POINTER(_retval);
535  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
536  return NS_OK;
537 }
538 
539 NS_IMETHODIMP
540 sbBaseDeviceLibraryListener::OnBeforeCreateMediaList(const nsAString & aType,
541  sbIPropertyArray *aProperties,
542  PRBool *_retval)
543 {
544  NS_ENSURE_ARG_POINTER(_retval);
545  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
546  return NS_OK;
547 }
548 
549 NS_IMETHODIMP
550 sbBaseDeviceLibraryListener::OnBeforeAdd(sbIMediaItem *aMediaItem,
551  PRBool *_retval)
552 {
553  NS_ENSURE_ARG_POINTER(aMediaItem);
554  NS_ENSURE_ARG_POINTER(_retval);
555  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
556  return NS_OK;
557 }
558 
559 NS_IMETHODIMP sbBaseDeviceLibraryListener::OnBeforeAddAll(sbIMediaList *aMediaList,
560  PRBool *_retval)
561 {
562  NS_ENSURE_ARG_POINTER(aMediaList);
563  NS_ENSURE_ARG_POINTER(_retval);
564  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
565  return NS_OK;
566 }
567 
568 NS_IMETHODIMP sbBaseDeviceLibraryListener::OnBeforeAddSome(nsISimpleEnumerator *aMediaItems,
569  PRBool *_retval)
570 {
571  NS_ENSURE_ARG_POINTER(aMediaItems);
572  NS_ENSURE_ARG_POINTER(_retval);
573  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
574  return NS_OK;
575 }
576 
577 NS_IMETHODIMP sbBaseDeviceLibraryListener::OnBeforeClear(PRBool *_retval)
578 {
579  NS_ENSURE_ARG_POINTER(_retval);
580  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
581  return NS_OK;
582 }
583 
584 //sbILocalDatabaseMediaListCopyListener
587 
589 : mDevice(nsnull)
590 {
591  SB_PRLOG_SETUP(sbLibraryListenerHelpers);
592 }
593 
595 {
596 
597 }
598 
599 nsresult
601 {
602  NS_ENSURE_ARG_POINTER(aDevice);
603 
604  mDevice = aDevice;
605 
606  return NS_OK;
607 }
608 
609 NS_IMETHODIMP
610 sbDeviceBaseLibraryCopyListener::OnItemCopied(sbIMediaItem *aSourceItem,
611  sbIMediaItem *aDestItem)
612 {
613  NS_ENSURE_ARG_POINTER(aSourceItem);
614  NS_ENSURE_ARG_POINTER(aDestItem);
615 
616  nsresult rv;
617 
618  #if PR_LOGGING
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);
626  }
627  rv = aSourceItem->GetLibrary(getter_AddRefs(srcLib));
628  if (NS_SUCCEEDED(rv)) {
629  rv = srcLib->GetGuid(srcLibId);
630  }
631  rv = aDestItem->GetContentSrc(getter_AddRefs(destURI));
632  if (NS_SUCCEEDED(rv)) {
633  rv = destURI->GetSpec(destSpec);
634  }
635  rv = aDestItem->GetLibrary(getter_AddRefs(destLib));
636  if (NS_SUCCEEDED(rv)) {
637  rv = destLib->GetGuid(destLibId);
638  }
639  TRACE("%s: %s::%s -> %s::%s",
640  __FUNCTION__,
641  NS_ConvertUTF16toUTF8(srcLibId).get(), srcSpec.get(),
642  NS_ConvertUTF16toUTF8(destLibId).get(), destSpec.get());
643  #endif
644 
646  aSourceItem, nsnull);
647  NS_ENSURE_SUCCESS(rv, rv);
648 
649  return NS_OK;
650 }
651 
654 
656 : mDevice(nsnull)
657 {
658 
659 }
660 
662 {
663 
664 }
665 
666 nsresult
668 {
669  NS_ENSURE_ARG_POINTER(aDevice);
670  NS_ENSURE_FALSE(mDevice, NS_ERROR_ALREADY_INITIALIZED);
671  mDevice = aDevice;
672  return NS_OK;
673 }
674 
675 NS_IMETHODIMP
676 sbBaseDeviceMediaListListener::OnItemAdded(sbIMediaList *aMediaList,
677  sbIMediaItem *aMediaItem,
678  PRUint32 aIndex,
679  PRBool *_retval)
680 {
681  NS_ENSURE_ARG_POINTER(aMediaList);
682  NS_ENSURE_ARG_POINTER(aMediaItem);
683  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
684 
685  if(MediaItemIgnored(aMediaList)) {
686  return NS_OK;
687  }
688 
689  nsresult rv;
690 
691  nsCOMPtr<sbILibrary> lib = do_QueryInterface(aMediaList);
692  if (lib) {
693  // umm, why are we listening to a library adding an item?
694  *_retval = PR_FALSE;
695  return NS_OK;
696  }
697 
698  nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem);
699  if (list) {
700  // a list being added to a list? we don't care, I think?
701  } else {
703  aMediaItem, aMediaList, aIndex);
704  NS_ENSURE_SUCCESS(rv, rv);
705  }
706 
707  if (_retval) {
708  *_retval = PR_FALSE; /* don't stop */
709  }
710 
711  return NS_OK;
712 }
713 
714 NS_IMETHODIMP
715 sbBaseDeviceMediaListListener::OnBeforeItemRemoved(sbIMediaList *aMediaList,
716  sbIMediaItem *aMediaItem,
717  PRUint32 aIndex,
718  PRBool *_retval)
719 {
720  return NS_OK;
721 }
722 
723 NS_IMETHODIMP
724 sbBaseDeviceMediaListListener::OnAfterItemRemoved(sbIMediaList *aMediaList,
725  sbIMediaItem *aMediaItem,
726  PRUint32 aIndex,
727  PRBool *_retval)
728 {
729  NS_ENSURE_ARG_POINTER(aMediaList);
730  NS_ENSURE_ARG_POINTER(aMediaItem);
731  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
732 
733  if(MediaItemIgnored(aMediaList)) {
734  return NS_OK;
735  }
736 
737  nsresult rv;
738 
740  aMediaItem, aMediaList, aIndex);
741  NS_ENSURE_SUCCESS(rv, rv);
742 
743  if (_retval) {
744  *_retval = PR_FALSE; /* don't stop */
745  }
746 
747  return NS_OK;
748 }
749 
750 NS_IMETHODIMP
751 sbBaseDeviceMediaListListener::OnItemUpdated(sbIMediaList *aMediaList,
752  sbIMediaItem *aMediaItem,
753  sbIPropertyArray *aProperties,
754  PRBool *_retval)
755 {
756  return NS_OK;
757 }
758 
759 NS_IMETHODIMP
760 sbBaseDeviceMediaListListener::OnItemMoved(sbIMediaList *aMediaList,
761  PRUint32 aFromIndex,
762  PRUint32 aToIndex,
763  PRBool *_retval)
764 {
765  NS_ENSURE_ARG_POINTER(aMediaList);
766  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
767 
768  if(MediaItemIgnored(aMediaList)) {
769  return NS_OK;
770  }
771 
772  nsresult rv;
774  nsnull, aMediaList, aFromIndex, aToIndex);
775  NS_ENSURE_SUCCESS(rv, rv);
776 
777  if (_retval) {
778  *_retval = PR_FALSE; /* don't stop */
779  }
780 
781  return NS_OK;
782 }
783 
784 NS_IMETHODIMP
785 sbBaseDeviceMediaListListener::OnBeforeListCleared(sbIMediaList *aMediaList,
786  PRBool aExcludeLists,
787  PRBool *_retval)
788 {
789  return NS_OK;
790 }
791 
792 NS_IMETHODIMP
793 sbBaseDeviceMediaListListener::OnListCleared(sbIMediaList *aMediaList,
794  PRBool aExcludeLists,
795  PRBool * /* aNoMoreForBatch */)
796 {
797  NS_ENSURE_ARG_POINTER(aMediaList);
798 
799  NS_ENSURE_TRUE(mDevice, NS_ERROR_NOT_INITIALIZED);
800 
801  // Check if we're ignoring then do nothing
802 
803  if(MediaItemIgnored(aMediaList)) {
804  return NS_OK;
805  }
806 
807  // Send the wipe request
808  nsresult rv;
810  aMediaList);
811  NS_ENSURE_SUCCESS(rv, rv);
812 
813  return NS_OK;
814 }
815 
816 NS_IMETHODIMP
817 sbBaseDeviceMediaListListener::OnBatchBegin(sbIMediaList *aMediaList)
818 {
819  if(MediaItemIgnored(aMediaList)) {
820  return NS_OK;
821  }
822  return mDevice->BatchBegin();
823 }
824 
825 NS_IMETHODIMP
826 sbBaseDeviceMediaListListener::OnBatchEnd(sbIMediaList *aMediaList)
827 {
828  if(MediaItemIgnored(aMediaList)) {
829  return NS_OK;
830  }
831  return mDevice->BatchEnd();
832 }
nsresult Init(sbBaseDevice *aDevice)
#define SB_PRLOG_SETUP(x)
Definition: sbDebugUtils.h:115
return NS_OK
nsresult BatchEnd()
nsresult BatchBegin()
Interface used to enumerate the items in a media list.
nsresult Init(sbBaseDevice *aDevice)
var uris
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
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
A brief description of the contents of this interface.
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)
Interface used to listen to changes to a media list.
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICELIBRARYLISTENER sbBaseDeviceLibraryListener()
#define SB_PROPERTY_COLUMNSPEC
NS_DECL_ISUPPORTS NS_DECL_SBILOCALDATABASEMEDIALISTCOPYLISTENER sbDeviceBaseLibraryCopyListener()
nsresult UnignoreMediaItem(sbIMediaItem *aItem)
function TRACE(s)
PRBool MediaItemIgnored(sbIMediaItem *aItem)
nsresult Init(sbBaseDevice *aDevice)
const PR_UINT32_MAX
Definition: httpd.js:55
var uri
Definition: FeedWriter.js:1135
MediaItemContentSrcArrayCreator(nsIMutableArray *aURIs)
Interface that defines a single item of media in the system.
#define SB_PROPERTY_PLAYLISTURL
var hidden
#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)
Definition: sbDebugUtils.h:55
const unsigned short ENUMERATIONTYPE_LOCKING
This flag means that the list is protected from changes by other threads during the enumeration...
nsresult IgnoreMediaItem(sbIMediaItem *aItem)