27 #include <nsIClassInfoImpl.h>
28 #include <nsIMutableArray.h>
30 #include <sbIMediaListView.h>
31 #include <sbIDevice.h>
32 #include <sbIDeviceLibrary.h>
33 #include <sbIDeviceManager.h>
34 #include <sbILibraryChangeset.h>
35 #include <sbILibraryManager.h>
37 #include <nsArrayUtils.h>
39 #include <nsISupportsUtils.h>
86 NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
148 nsIArray *aListItems = NULL);
181 nsIArray **aPropertyChanges);
187 nsIArray **aPropertyChanges);
193 nsString aPropertyName,
241 class ListAddingEnumerationListener:
246 NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
253 nsIMutableArray *aListItems):
267 ListAddingEnumerationListener::OnEnumerationBegin(
sbIMediaList *aMediaList,
276 ListAddingEnumerationListener::OnEnumeratedItem(
sbIMediaList *aMediaList,
280 NS_ENSURE_ARG_POINTER(aMediaList);
281 NS_ENSURE_ARG_POINTER(aMediaItem);
282 NS_ENSURE_ARG_POINTER(_retval);
287 nsCOMPtr<sbIMediaItem> destItem;
290 getter_AddRefs(destItem));
291 NS_ENSURE_SUCCESS(rv, rv);
297 rv =
mListItems->AppendElement(aMediaItem, PR_FALSE);
298 NS_ENSURE_SUCCESS(rv, rv);
302 rv =
mListItems->AppendElement(destItem, PR_FALSE);
303 NS_ENSURE_SUCCESS(rv, rv);
316 ListAddingEnumerationListener::OnEnumerationEnd(
sbIMediaList *aMediaList,
317 nsresult aStatusCode)
335 NS_ENSURE_TRUE(
mChangeset, NS_ERROR_OUT_OF_MEMORY);
338 "@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
339 NS_ENSURE_SUCCESS(rv, rv);
352 NS_ENSURE_SUCCESS(rv, rv);
358 SyncEnumListenerBase::OnEnumerationBegin(
sbIMediaList *aMediaList,
367 SyncEnumListenerBase::OnEnumeratedItem(
sbIMediaList *aMediaList,
371 NS_ENSURE_ARG_POINTER(aMediaList);
372 NS_ENSURE_ARG_POINTER(aMediaItem);
373 NS_ENSURE_ARG_POINTER(_retval);
377 nsCOMPtr<sbIMediaList> itemAsList = do_QueryInterface(aMediaItem, &rv);
378 bool isList = NS_SUCCEEDED(rv);
390 rv = aMediaItem->GetGuid(itemId);
391 NS_ENSURE_SUCCESS(rv, rv);
398 NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
404 NS_ENSURE_SUCCESS(rv, rv);
406 if (!hidden.EqualsLiteral(
"1")) {
410 NS_ENSURE_SUCCESS(rv, rv);
419 SyncEnumListenerBase::OnEnumerationEnd(
sbIMediaList *aMediaList,
420 nsresult aStatusCode)
431 rv = aList->GetListContentType(&listType);
432 NS_ENSURE_SUCCESS(rv,
false);
444 rv = aList->GetListContentType(&listType);
445 NS_ENSURE_SUCCESS(rv,
false);
470 nsString contentType;
471 rv = aItem->GetContentType(contentType);
472 NS_ENSURE_SUCCESS(rv,
false);
474 if ((contentType.EqualsLiteral(
"audio") &&
476 (contentType.EqualsLiteral(
"video") &&
486 nsIArray **aPropertyChanges)
490 nsCOMPtr<sbIPropertyArray> sourceProperties;
491 nsCOMPtr<sbIPropertyArray> destinationProperties;
493 rv = aSourceItem->GetProperties(nsnull,
494 getter_AddRefs(sourceProperties));
495 NS_ENSURE_SUCCESS(rv, rv);
496 rv = aDestinationItem->GetProperties(nsnull,
497 getter_AddRefs(destinationProperties));
498 NS_ENSURE_SUCCESS(rv, rv);
500 nsCOMPtr<nsIMutableArray> propertyChanges =
501 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
502 NS_ENSURE_SUCCESS(rv, rv);
504 PRUint32 sourceLength;
505 rv = sourceProperties->GetLength(&sourceLength);
506 NS_ENSURE_SUCCESS(rv, rv);
508 PRUint32 destinationLength;
509 rv = destinationProperties->GetLength(&destinationLength);
510 NS_ENSURE_SUCCESS(rv, rv);
512 nsCOMPtr<sbIProperty> property;
513 nsTHashtable<nsStringHashKey> sourcePropertyNamesFoundInDestination;
515 PRBool success = sourcePropertyNamesFoundInDestination.Init();
516 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
521 nsTHashtable<nsStringHashKey> propertyExclusionList;
522 success = propertyExclusionList.Init();
523 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
525 nsStringHashKey* successHashkey =
527 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
531 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
535 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
539 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
543 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
547 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
552 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
558 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
562 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
567 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
573 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
579 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
582 nsString propertyValue;
583 nsString propertyDestinationValue;
586 for(PRUint32 current = 0; current < sourceLength; ++current)
588 rv = sourceProperties->GetPropertyAt(current, getter_AddRefs(property));
589 NS_ENSURE_SUCCESS(rv, rv);
591 rv =
property->GetId(propertyId);
592 NS_ENSURE_SUCCESS(rv, rv);
594 rv =
property->GetValue(propertyValue);
595 NS_ENSURE_SUCCESS(rv, rv);
597 if(propertyExclusionList.GetEntry(propertyId)) {
601 rv = destinationProperties->GetPropertyValue(propertyId,
602 propertyDestinationValue);
604 if(rv == NS_ERROR_NOT_AVAILABLE) {
607 propertyValue.Equals(NS_LITERAL_STRING(
"audio"))) {
610 nsRefPtr<sbPropertyChange> propertyChange;
612 NS_ENSURE_TRUE(propertyChange, NS_ERROR_OUT_OF_MEMORY);
618 NS_ENSURE_SUCCESS(rv, rv);
620 nsCOMPtr<nsISupports>
element =
622 NS_ENSURE_SUCCESS(rv, rv);
624 rv = propertyChanges->AppendElement(element,
626 NS_ENSURE_SUCCESS(rv, rv);
630 NS_ENSURE_SUCCESS(rv, rv);
633 successHashkey = sourcePropertyNamesFoundInDestination.PutEntry(propertyId);
634 NS_ENSURE_TRUE(successHashkey, NS_ERROR_OUT_OF_MEMORY);
639 if (NS_SUCCEEDED(rv)) {
640 PRUint64
const destDuration =
644 if (NS_SUCCEEDED(rv)) {
646 PRInt64 durationDiff = sourceDuration - destDuration;
647 if ((durationDiff < 0 && -durationDiff < PR_USEC_PER_SEC) ||
648 durationDiff < PR_USEC_PER_SEC)
655 else if(propertyValue.Equals(propertyDestinationValue)) {
659 nsRefPtr<sbPropertyChange> propertyChange;
661 NS_ENSURE_TRUE(propertyChange, NS_ERROR_OUT_OF_MEMORY);
665 propertyDestinationValue,
667 NS_ENSURE_SUCCESS(rv, rv);
669 nsCOMPtr<nsISupports>
element =
671 NS_ENSURE_SUCCESS(rv, rv);
672 rv = propertyChanges->AppendElement(element,
674 NS_ENSURE_SUCCESS(rv, rv);
681 for(PRUint32 current = 0; current < destinationLength; ++current) {
682 rv = destinationProperties->GetPropertyAt(current,
683 getter_AddRefs(property));
684 NS_ENSURE_SUCCESS(rv, rv);
686 rv =
property->GetId(propertyId);
687 NS_ENSURE_SUCCESS(rv, rv);
689 rv =
property->GetValue(propertyDestinationValue);
690 NS_ENSURE_SUCCESS(rv, rv);
692 if(propertyExclusionList.GetEntry(propertyId)) {
696 if(!sourcePropertyNamesFoundInDestination.GetEntry(propertyId)) {
700 nsRefPtr<sbPropertyChange> propertyChange;
702 NS_ENSURE_TRUE(propertyChange, NS_ERROR_OUT_OF_MEMORY);
706 propertyDestinationValue,
708 NS_ENSURE_SUCCESS(rv, rv);
710 rv = propertyChanges->AppendElement(NS_ISUPPORTS_CAST(
sbIPropertyChange *, propertyChange),
712 NS_ENSURE_SUCCESS(rv, rv);
716 return CallQueryInterface(propertyChanges.get(), aPropertyChanges);
722 nsIArray **aPropertyChanges)
724 nsCOMPtr<sbIPropertyArray> properties;
725 nsresult rv = aSourceItem->GetProperties(nsnull, getter_AddRefs(properties));
726 NS_ENSURE_SUCCESS(rv, rv);
728 nsCOMPtr<nsIMutableArray> propertyChanges =
729 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
730 NS_ENSURE_SUCCESS(rv, rv);
732 PRUint32 propertyCount = 0;
733 rv = properties->GetLength(&propertyCount);
734 NS_ENSURE_SUCCESS(rv, rv);
736 nsString strPropertyID;
737 nsString strPropertyValue;
738 nsCOMPtr<sbIProperty> property;
740 for(PRUint32 current = 0; current < propertyCount; ++current) {
742 rv = properties->GetPropertyAt(current, getter_AddRefs(property));
743 NS_ENSURE_SUCCESS(rv, rv);
745 rv =
property->GetId(strPropertyID);
746 NS_ENSURE_SUCCESS(rv, rv);
748 rv =
property->GetValue(strPropertyValue);
749 NS_ENSURE_SUCCESS(rv, rv);
751 nsRefPtr<sbPropertyChange> propertyChange;
753 NS_ENSURE_TRUE(propertyChange, NS_ERROR_OUT_OF_MEMORY);
759 NS_ENSURE_SUCCESS(rv, rv);
761 nsCOMPtr<nsISupports>
element =
763 NS_ENSURE_SUCCESS(rv, rv);
765 rv = propertyChanges->AppendElement(element,
767 NS_ENSURE_SUCCESS(rv, rv);
770 return CallQueryInterface(propertyChanges.get(), aPropertyChanges);
780 nsCOMPtr<nsIMutableArray> listItems =
781 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
786 nsRefPtr<ListAddingEnumerationListener>
listener =
787 new ListAddingEnumerationListener(
this, listItems);
789 aSrcList->EnumerateAllItems(listener,
791 NS_ENSURE_SUCCESS(rv, rv);
793 nsCOMPtr<sbIMediaItem> srcItem = do_QueryInterface(aSrcList, &rv);
794 NS_ENSURE_SUCCESS(rv, rv);
796 nsCOMPtr<sbIMediaItem> dstItem;
798 dstItem = do_QueryInterface(aDstList, &rv);
799 NS_ENSURE_SUCCESS(rv, rv);
806 NS_ENSURE_SUCCESS(rv, rv);
815 nsIArray *aListItems)
819 nsRefPtr<sbLibraryChange> libraryChange;
820 NS_NEWXPCOM(libraryChange, sbLibraryChange);
821 NS_ENSURE_TRUE(libraryChange, NS_ERROR_OUT_OF_MEMORY);
823 nsCOMPtr<nsIArray> propertyChanges;
827 getter_AddRefs(propertyChanges));
828 NS_ENSURE_SUCCESS(rv, rv);
833 getter_AddRefs(propertyChanges));
834 NS_ENSURE_SUCCESS(rv, rv);
837 PR_NOT_REACHED(
"Wrong change type");
840 rv = libraryChange->InitWithValues(aChangeType,
846 NS_ENSURE_SUCCESS(rv, rv);
848 nsCOMPtr<nsISupports>
element =
851 NS_ENSURE_SUCCESS(rv, rv);
854 NS_ENSURE_SUCCESS(rv, rv);
861 nsString aPropertyName,
865 nsresult rv = aMediaItem->GetProperty(aPropertyName, str);
866 NS_ENSURE_SUCCESS(rv, rv);
869 NS_ENSURE_SUCCESS(rv, rv);
916 nsCOMPtr<nsIArray> items;
917 rv = aDeviceLibrary->GetItemsByProperty(
920 getter_AddRefs(items));
921 if (rv == NS_ERROR_NOT_AVAILABLE) {
929 rv = items->GetLength(&count);
930 NS_ENSURE_SUCCESS(rv, rv);
932 NS_WARN_IF_FALSE(count < 2,
"Multiple OriginGUID matches");
933 NS_ASSERTION(count == 1,
"GetItemsByProperty returned bogus array");
935 nsCOMPtr<sbIMediaItem> item = do_QueryElementAt(items, 0, &rv);
936 NS_ENSURE_SUCCESS(rv, rv);
938 item.forget(aMediaItem);
952 rv = aList->GetGuid(listId);
953 NS_ENSURE_SUCCESS(rv, rv);
955 nsCOMPtr<sbIMediaItem> matchingItem;
957 NS_ENSURE_SUCCESS(rv, rv);
960 rv = CallQueryInterface(matchingItem.get(), aMatchingList);
961 NS_ENSURE_SUCCESS(rv, rv);
973 nsCOMPtr<sbIMediaList> itemAsList = do_QueryInterface(aMediaItem, &rv);
974 if (NS_SUCCEEDED(rv)) {
978 nsCOMPtr<sbIMediaList>*
element =
980 NS_ENSURE_TRUE(element, NS_ERROR_OUT_OF_MEMORY);
984 nsCOMPtr<sbIMediaList> destList;
986 NS_ENSURE_SUCCESS(rv, rv);
988 switch (changeType) {
993 NS_ENSURE_SUCCESS(rv, rv);
999 NS_ENSURE_SUCCESS(rv, rv);
1009 nsCOMPtr<sbIMediaItem> destItem;
1011 NS_ENSURE_SUCCESS(rv, rv);
1013 switch (changeType) {
1018 NS_ENSURE_SUCCESS(rv, rv);
1024 NS_ENSURE_SUCCESS(rv, rv);
1050 nsCOMPtr<sbIMediaList> matchingPlaylist;
1053 getter_AddRefs(matchingPlaylist));
1054 NS_ENSURE_SUCCESS(rv, rv);
1056 if (matchingPlaylist) {
1058 PRInt64 itemLastModifiedTime;
1059 PRInt64 lastSyncTime;
1060 rv = aMediaList->GetUpdated(&itemLastModifiedTime);
1061 NS_ENSURE_SUCCESS(rv, rv);
1067 if (NS_SUCCEEDED(rv) && itemLastModifiedTime > lastSyncTime) {
1077 matchingPlaylist.forget(aDestMediaList);
1103 rv = aMediaItem->GetGuid(itemId);
1104 NS_ENSURE_SUCCESS(rv, rv);
1106 nsCOMPtr<sbIMediaItem> destMediaItem;
1109 getter_AddRefs(destMediaItem));
1110 PRBool hasOriginMatch = NS_SUCCEEDED(rv) && destMediaItem;
1115 if (hasOriginMatch) {
1117 destMediaItem.forget(aDestMediaItem);
1127 if (hasOriginMatch) {
1128 PRInt64 itemLastModifiedTime;
1129 PRInt64 lastSyncTime;
1130 rv = aMediaItem->GetUpdated(&itemLastModifiedTime);
1131 NS_ENSURE_SUCCESS(rv, rv);
1137 if (NS_SUCCEEDED(rv) && itemLastModifiedTime > lastSyncTime) {
1140 destMediaItem.forget(aDestMediaItem);
1147 destMediaItem.forget(aDestMediaItem);
1155 nsCOMPtr<nsIArray> matchedItems;
1158 getter_AddRefs(matchedItems));
1159 NS_ENSURE_SUCCESS(rv, rv);
1161 PRUint32 matchedItemsLength;
1162 rv = matchedItems->GetLength(&matchedItemsLength);
1163 NS_ENSURE_SUCCESS(rv, rv);
1165 if (matchedItemsLength == 0) {
1176 nsCOMPtr<sbIMediaItem> matchItem = do_QueryElementAt(
1177 matchedItems, 0, &rv);
1178 NS_ENSURE_SUCCESS(rv, rv);
1180 matchItem.forget(aDestMediaItem);
1207 PRBool *aFromMainLibrary);
1233 rv = aList->GetName(listName);
1234 NS_ENSURE_SUCCESS(rv, rv);
1237 nsCOMPtr<nsIArray> items;
1238 rv = aLibrary->GetItemsByProperty(
1241 getter_AddRefs(items));
1242 if (rv == NS_ERROR_NOT_AVAILABLE) {
1245 NS_ENSURE_SUCCESS(rv, rv);
1247 PRUint32 itemsLength;
1248 rv = items->GetLength(&itemsLength);
1249 NS_ENSURE_SUCCESS(rv, rv);
1251 for (PRUint32
i = 0;
i < itemsLength;
i++) {
1252 nsCOMPtr<sbIMediaList> list = do_QueryElementAt(items, 0, &rv);
1256 nsString playlistType;
1257 rv = list->GetType(playlistType);
1258 NS_ENSURE_SUCCESS(rv, rv);
1260 if (playlistType.EqualsLiteral(
"simple")) {
1263 list.forget(aMatchingList);
1269 *aMatchingList = NULL;
1275 PRBool *aFromMainLibrary)
1282 nsString originItemGUID;
1285 NS_ENSURE_SUCCESS(rv, rv);
1287 if (originItemGUID.IsVoid()) {
1288 *aFromMainLibrary = PR_FALSE;
1292 nsString originLibraryGUID;
1295 NS_ENSURE_SUCCESS(rv, rv);
1297 nsString mainLibraryGUID;
1299 NS_ENSURE_SUCCESS(rv, rv);
1301 *aFromMainLibrary = originLibraryGUID.Equals(mainLibraryGUID);
1314 nsString originItemGUID;
1317 NS_ENSURE_SUCCESS(rv, rv);
1319 nsCOMPtr<sbIMediaItem> item;
1320 rv =
mMainLibrary->GetMediaItem(originItemGUID, getter_AddRefs(item));
1322 if (NS_SUCCEEDED(rv) && item) {
1323 item.forget(aMainLibraryItem);
1337 nsString originLibraryGUID;
1340 NS_ENSURE_SUCCESS(rv, rv);
1342 nsString libraryGUID;
1343 rv = aLibrary->GetGuid(libraryGUID);
1344 NS_ENSURE_SUCCESS(rv, rv);
1346 if (!libraryGUID.Equals(originLibraryGUID)) {
1347 *aMatchingList = nsnull;
1352 nsString originItemGUID;
1355 NS_ENSURE_SUCCESS(rv, rv);
1358 nsCOMPtr<sbIMediaItem> matchingItem;
1359 rv = aLibrary->GetMediaItem(originItemGUID, getter_AddRefs(matchingItem));
1361 if (rv == NS_ERROR_NOT_AVAILABLE) {
1362 *aMatchingList = nsnull;
1365 NS_ENSURE_SUCCESS(rv, rv);
1367 return CallQueryInterface(matchingItem.get(), aMatchingList);
1382 nsCOMPtr<sbIMediaList> matchingPlaylist;
1385 getter_AddRefs(matchingPlaylist));
1386 NS_ENSURE_SUCCESS(rv, rv);
1388 if (matchingPlaylist) {
1389 nsString playlistType;
1390 rv = matchingPlaylist->GetType(playlistType);
1391 NS_ENSURE_SUCCESS(rv, rv);
1394 if (playlistType.EqualsLiteral(
"simple")) {
1397 matchingPlaylist.forget(aDestMediaList);
1403 PRInt64 itemLastModifiedTime;
1404 PRInt64 lastSyncTime;
1405 rv = matchingPlaylist->GetUpdated(&itemLastModifiedTime);
1406 NS_ENSURE_SUCCESS(rv, rv);
1411 NS_ENSURE_SUCCESS(rv, rv);
1413 if (itemLastModifiedTime < lastSyncTime) {
1421 matchingPlaylist.forget(aDestMediaList);
1427 matchingPlaylist.forget(aDestMediaList);
1437 nsCOMPtr<sbIMediaList> matchingSimplePlaylist;
1441 getter_AddRefs(matchingSimplePlaylist));
1442 NS_ENSURE_SUCCESS(rv, rv);
1444 if (matchingSimplePlaylist) {
1446 matchingSimplePlaylist.forget(aDestMediaList);
1457 matchingPlaylist.forget(aDestMediaList);
1485 PRBool isFromMainLibrary;
1487 NS_ENSURE_SUCCESS(rv, rv);
1491 if (isFromMainLibrary) {
1493 nsCOMPtr<sbIMediaItem> mainLibItem;
1495 NS_ENSURE_SUCCESS(rv, rv);
1505 mainLibItem.forget(aDestMediaItem);
1517 if (!isFromMainLibrary) {
1521 nsCOMPtr<nsIArray> matchedItems;
1524 getter_AddRefs(matchedItems));
1525 NS_ENSURE_SUCCESS(rv, rv);
1527 PRUint32 matchedItemsLength;
1528 rv = matchedItems->GetLength(&matchedItemsLength);
1529 NS_ENSURE_SUCCESS(rv, rv);
1531 if (matchedItemsLength == 0) {
1541 nsCOMPtr<sbIMediaItem> matchItem = do_QueryElementAt(
1542 matchedItems, 0, &rv);
1543 NS_ENSURE_SUCCESS(rv, rv);
1545 matchItem.forget(aDestMediaItem);
1552 nsCOMPtr<sbIMediaItem> mainLibItem;
1554 NS_ENSURE_SUCCESS(rv, rv);
1558 mainLibItem.forget(aDestMediaItem);
1575 nsCOMPtr<sbIMediaList> itemAsList = do_QueryInterface(aMediaItem, &rv);
1576 if (NS_SUCCEEDED(rv)) {
1578 nsCOMPtr<sbIMediaList> destList;
1580 NS_ENSURE_SUCCESS(rv, rv);
1582 switch (changeType) {
1587 NS_ENSURE_SUCCESS(rv, rv);
1593 NS_ENSURE_SUCCESS(rv, rv);
1603 nsCOMPtr<sbIMediaItem> destItem;
1605 NS_ENSURE_SUCCESS(rv, rv);
1607 switch (changeType) {
1612 NS_ENSURE_SUCCESS(rv, rv);
1618 NS_ENSURE_SUCCESS(rv, rv);
1636 sbDeviceLibrarySyncDiff::~sbDeviceLibrarySyncDiff()
1641 sbDeviceLibrarySyncDiff::GenerateSyncLists(
1642 PRUint32 aMediaTypesToExportAll,
1643 PRUint32 aMediaTypesToImportAll,
1646 nsIArray *aSourceLists,
1650 NS_ENSURE_ARG_POINTER(aSourceLibrary);
1651 NS_ENSURE_ARG_POINTER(aDestLibrary);
1652 NS_ENSURE_ARG_POINTER(aExportChangeset);
1653 NS_ENSURE_ARG_POINTER(aImportChangeset);
1660 nsRefPtr<SyncExportEnumListener> exportListener =
1662 NS_ENSURE_TRUE(exportListener, NS_ERROR_OUT_OF_MEMORY);
1666 NS_ENSURE_SUCCESS(rv, rv);
1671 if (aMediaTypesToExportAll) {
1677 exportListener->SetMediaTypes(aMediaTypesToExportAll);
1681 rv = aSourceLibrary->EnumerateAllItems(
1684 NS_ENSURE_SUCCESS(rv, rv);
1689 rv = aSourceLibrary->EnumerateAllItems(
1692 NS_ENSURE_SUCCESS(rv, rv);
1696 if (aMediaTypesToExportAll != mixedMediaTypes) {
1698 exportListener->SetMediaTypes(mixedMediaTypes);
1699 PRInt32
const mixedListCount =
1700 exportListener->mMixedContentPlaylists.Length();
1701 for (PRInt32
i = 0;
i < mixedListCount;
i++) {
1702 rv = exportListener->mMixedContentPlaylists[
i]->EnumerateAllItems(
1705 NS_ENSURE_SUCCESS(rv, rv);
1718 exportListener->SetMediaTypes(mixedMediaTypes);
1720 PRUint32 sourceListLength;
1721 rv = aSourceLists->GetLength(&sourceListLength);
1722 NS_ENSURE_SUCCESS(rv, rv);
1724 nsCOMPtr<sbIMediaList> list;
1725 for (PRUint32
i = 0;
i < sourceListLength;
i++) {
1726 list = do_QueryElementAt(aSourceLists,
i, &rv);
1727 NS_ENSURE_SUCCESS(rv, rv);
1732 nsCOMPtr<sbIMediaList> destList;
1733 rv = exportListener->SelectChangeForList(list,
1735 getter_AddRefs(destList));
1736 NS_ENSURE_SUCCESS(rv, rv);
1741 list->EnumerateAllItems(exportListener,
1743 NS_ENSURE_SUCCESS(rv, rv);
1750 NS_ENSURE_SUCCESS(rv, rv);
1756 NS_ENSURE_SUCCESS(rv, rv);
1762 rv = exportListener->Finish();
1763 NS_ENSURE_SUCCESS(rv, rv);
1767 nsRefPtr<SyncImportEnumListener> importListener =
1769 NS_ENSURE_TRUE(importListener, NS_ERROR_OUT_OF_MEMORY);
1773 NS_ENSURE_SUCCESS(rv, rv);
1775 if (aMediaTypesToImportAll) {
1780 importListener->SetMediaTypes(aMediaTypesToImportAll);
1782 rv = aDestLibrary->EnumerateAllItems(
1785 NS_ENSURE_SUCCESS(rv, rv);
1788 rv = aDestLibrary->EnumerateAllItems(
1791 NS_ENSURE_SUCCESS(rv, rv);
1794 rv = importListener->Finish();
1795 NS_ENSURE_SUCCESS(rv, rv);
1797 NS_IF_ADDREF(*aExportChangeset = exportListener->mChangeset);
1798 NS_IF_ADDREF(*aImportChangeset = importListener->mChangeset);
1804 sbDeviceLibrarySyncDiff::GenerateDropLists(
1808 nsIArray *aSourceItems,
1809 nsIArray **aDestItems NS_OUTPARAM,
1812 NS_ENSURE_ARG_POINTER (aDestLibrary);
1813 NS_ENSURE_ARG_POINTER (aChangeset);
1816 NS_ENSURE_ARG_POINTER(aSourceItems);
1824 bool toDevice =
false;
1825 nsCOMPtr<sbIDeviceManager2> deviceManager = do_GetService(
1826 "@songbirdnest.com/Songbird/DeviceManager;2", &rv);
1827 NS_ENSURE_SUCCESS(rv, rv);
1829 nsCOMPtr<sbIDevice> device;
1830 rv = deviceManager->GetDeviceForItem(aDestLibrary, getter_AddRefs(device));
1831 if (NS_SUCCEEDED(rv) && device) {
1839 nsCOMPtr<nsIMutableArray> destItems = do_CreateInstance(
1840 "@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1841 NS_ENSURE_SUCCESS(rv, rv);
1843 nsRefPtr<SyncEnumListenerBase>
listener;
1856 NS_ENSURE_TRUE(listener, NS_ERROR_OUT_OF_MEMORY);
1857 rv = listener->Init(dropAction,
1860 NS_ENSURE_SUCCESS(rv, rv);
1864 NS_ENSURE_TRUE(listener, NS_ERROR_OUT_OF_MEMORY);
1865 rv = listener->Init(dropAction,
1868 NS_ENSURE_SUCCESS(rv, rv);
1871 listener->SetMediaTypes(allMediaTypes);
1878 aSourceList->EnumerateAllItems(listener,
1880 NS_ENSURE_SUCCESS(rv, rv);
1883 rv = listener->ProcessItem(aSourceLibrary, aSourceList);
1884 NS_ENSURE_SUCCESS(rv, rv);
1891 rv = aSourceItems->GetLength(&itemsLen);
1892 NS_ENSURE_SUCCESS(rv, rv);
1894 for (PRUint32
i = 0;
i < itemsLen;
i++) {
1895 nsCOMPtr<sbIMediaItem> item = do_QueryElementAt(aSourceItems,
i, &rv);
1896 NS_ENSURE_SUCCESS(rv, rv);
1898 rv = listener->ProcessItem(aSourceLibrary, item);
1899 NS_ENSURE_SUCCESS(rv, rv);
1902 nsCOMPtr<sbIMediaItem> destItem;
1903 rv = listener->SelectChangeForItem(item,
1905 getter_AddRefs(destItem));
1906 NS_ENSURE_SUCCESS(rv, rv);
1908 switch(changeType) {
1912 rv = destItems->AppendElement(item, PR_FALSE);
1913 NS_ENSURE_SUCCESS(rv, rv);
1917 rv = destItems->AppendElement(destItem, PR_FALSE);
1918 NS_ENSURE_SUCCESS(rv, rv);
1927 rv = listener->Finish();
1928 NS_ENSURE_SUCCESS(rv, rv);
1930 NS_ADDREF(*aChangeset = listener->mChangeset);
1931 NS_ADDREF(*aDestItems = destItems);
const unsigned long DELETED
nsCOMPtr< nsIMutableArray > mLibraryChanges
#define SB_PRLOG_SETUP(x)
nsCOMPtr< sbILibrary > mMainLibrary
#define SB_PROPERTY_MEDIALISTNAME
nsresult GetItemWithOriginGUID(sbILibrary *aDeviceLibrary, nsString aItemID, sbIMediaItem **aMediaItem)
#define SB_PROPERTY_ORIGINLIBRARYGUID
virtual nsresult SelectChangeForItem(sbIMediaItem *aMediaItem, ChangeType *aChangeType, sbIMediaItem **aDestMediaItem)
#define SB_PROPERTY_ORIGINURL
nsresult CreatePropertyChangesForItemAdded(sbIMediaItem *aSourceItem, nsIArray **aPropertyChanges)
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
nsCOMPtr< sbILibrary > mDeviceLibrary
void SetMediaTypes(PRUint32 aMediaTypes)
PRUint64 nsString_ToUint64(const nsAString &str, nsresult *rv)
bool ListIsMixed(sbIMediaList *aList)
virtual nsresult SelectChangeForItem(sbIMediaItem *aMediaItem, ChangeType *aChangeType, sbIMediaItem **aDestMediaItem)
#define SB_PROPERTY_HIDDEN
sbLibraryChangeset Definition.
nsresult AddChange(PRUint32 aChangeType, sbIMediaItem *aSrcItem, sbIMediaItem *aDstItem, nsIArray *aListItems=NULL)
nsresult GetTimeProperty(sbIMediaItem *aMediaItem, nsString aPropertyName, PRInt64 *_result)
virtual nsresult Init(DropAction aDropAction, sbILibrary *aMainLibrary, sbILibrary *aDeviceLibrary)
#define SB_PROPERTY_LAST_SYNC_TIME
nsTHashtable< nsStringHashKey > mSeenMediaItems
virtual ~SyncEnumListenerBase()
#define SB_PROPERTY_CONTENTLENGTH
nsresult AddListChange(PRUint32 aChangeType, sbIMediaList *aSrcList, sbIMediaList *aDstList)
virtual nsresult SelectChangeForItem(sbIMediaItem *aMediaItem, ChangeType *aChangeType, sbIMediaItem **aDestMediaItem)=0
virtual nsresult ProcessItem(sbIMediaList *aMediaList, sbIMediaItem *aMediaItem)
virtual nsresult SelectChangeForList(sbIMediaList *aMediaList, ChangeType *aChangeType, sbIMediaList **aDestMediaList)=0
#define SB_PROPERTY_CREATED
#define SB_PROPERTY_COLUMNSPEC
nsresult IsFromMainLibrary(sbIMediaItem *aMediaItem, PRBool *aFromMainLibrary)
void SetHandleMode(HandleMode aMode)
#define SB_PROPERTY_UPDATED
#define SB_PROPERTY_CONTENTTYPE
nsCOMPtr< SyncEnumListenerBase > mMainListener
nsresult GetSimplePlaylistWithSameName(sbILibrary *aLibrary, sbIMediaList *aList, sbIMediaList **aMatchingList)
#define SB_PROPERTY_DURATION
virtual nsresult GetMatchingPlaylist(sbILibrary *aLibrary, sbIMediaList *aList, sbIMediaList **aMatchingList)
const unsigned long SYNC_TYPE_AUDIO
#define SB_PROPERTY_ORIGIN_IS_IN_MAIN_LIBRARY
const unsigned long MODIFIED
bool ListHasCorrectContentType(sbIMediaList *aList)
Media library abstraction.
bool HasCorrectContentType(sbIMediaItem *aItem)
virtual nsresult ProcessItem(sbIMediaList *aMediaList, sbIMediaItem *aMediaItem)
virtual nsresult GetMatchingPlaylist(sbILibrary *aLibrary, sbIMediaList *aList, sbIMediaList **aMatchingList)=0
const unsigned long SYNC_TYPE_VIDEO
PRInt64 nsString_ToInt64(const nsAString &str, nsresult *rv)
virtual nsresult SelectChangeForList(sbIMediaList *aMediaList, ChangeType *aChangeType, sbIMediaList **aDestMediaList)
virtual nsresult GetMatchingPlaylist(sbILibrary *aLibrary, sbIMediaList *aList, sbIMediaList **aMatchingList)
nsRefPtr< sbLibraryChangeset > mChangeset
virtual nsresult ProcessItem(sbIMediaList *aMediaList, sbIMediaItem *aMediaItem)=0
virtual ~SyncImportEnumListener()
nsCOMPtr< nsIMutableArray > mListItems
nsTArray< nsCOMPtr< sbIMediaList > > mMixedContentPlaylists
nsresult GetItemInMainLibrary(sbIMediaItem *aMediaItem, sbIMediaItem **aMainLibraryItem)
#define SB_PROPERTY_PLAYLISTURL
#define SB_PROPERTY_AVAILABILITY
virtual nsresult SelectChangeForList(sbIMediaList *aMediaList, ChangeType *aChangeType, sbIMediaList **aDestMediaList)
nsresult CreatePropertyChangesForItemModified(sbIMediaItem *aSourceItem, sbIMediaItem *aDestinationItem, nsIArray **aPropertyChanges)
#define SB_PROPERTY_CONTENTURL
#define SB_PROPERTY_ORIGINITEMGUID
_getSelectedPageStyle s i
const unsigned long ADDED
NS_IMPL_THREADSAFE_ISUPPORTS1(SyncEnumListenerBase, sbIMediaListEnumerationListener) class ListAddingEnumerationListener