33 #include <nsArrayUtils.h>
34 #include <nsCOMArray.h>
40 #include <sbILibraryChangeset.h>
41 #include <sbIDeviceLibraryMediaSyncSettings.h>
42 #include <sbIDeviceLibrarySyncDiff.h>
43 #include <sbIDeviceLibrarySyncSettings.h>
44 #include <sbIMediaItem.h>
45 #include <sbIMediaList.h>
51 NS_ENSURE_ARG_POINTER(aImportToLibrary);
52 NS_ENSURE_ARG_POINTER(aImportChangeset);
57 nsCOMPtr<nsIArray> changeList;
58 rv = aImportChangeset->GetChanges(getter_AddRefs(changeList));
59 NS_ENSURE_SUCCESS(rv, rv);
62 rv = changeList->GetLength(&changeCount);
63 NS_ENSURE_SUCCESS(rv, rv);
66 if (changeCount == 0) {
70 nsCOMPtr<nsIMutableArray> mediaItemsToAdd =
71 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
72 NS_ENSURE_SUCCESS(rv, rv);
73 nsCOMPtr<nsIMutableArray> mediaListsToAdd =
74 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
75 NS_ENSURE_SUCCESS(rv, rv);
76 nsCOMPtr<nsIMutableArray> mediaItemsToRemove =
77 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
79 NS_ENSURE_SUCCESS(rv, rv);
80 nsCOMPtr<nsIMutableArray> mediaListsToUpdate =
81 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
82 NS_ENSURE_SUCCESS(rv, rv);
88 for (PRUint32
i = 0;
i < changeCount;
i++) {
93 nsCOMPtr<sbILibraryChange> change = do_QueryElementAt(changeList,
i, &rv);
94 NS_ENSURE_SUCCESS(rv, rv);
98 rv = change->GetOperation(&operation);
99 NS_ENSURE_SUCCESS(rv, rv);
103 rv = change->GetItemIsList(&itemIsList);
104 NS_ENSURE_SUCCESS(rv, rv);
107 if (itemIsList && !playlistsSupported) {
114 nsCOMPtr<sbIMediaItem> mediaItem;
115 rv = change->GetSourceItem(getter_AddRefs(mediaItem));
116 NS_ENSURE_SUCCESS(rv, rv);
119 rv = mediaListsToAdd->AppendElement(change, PR_FALSE);
120 NS_ENSURE_SUCCESS(rv, rv);
122 rv = mediaItemsToAdd->AppendElement(mediaItem, PR_FALSE);
123 NS_ENSURE_SUCCESS(rv, rv);
128 nsCOMPtr<sbIMediaItem> destItem;
129 rv = change->GetDestinationItem(getter_AddRefs(destItem));
130 NS_ENSURE_SUCCESS(rv, rv);
132 nsCOMPtr<sbIMediaList> destItemAsList =
133 do_QueryInterface(destItem);
135 if (destItemAsList) {
138 PRBool success = mediaListsToUpdate->AppendElement(change, PR_FALSE);
139 NS_ENSURE_SUCCESS(success, NS_ERROR_OUT_OF_MEMORY);
143 rv = mediaItemsToRemove->AppendElement(destItem, PR_FALSE);
144 NS_ENSURE_SUCCESS(rv, rv);
146 nsCOMPtr<sbIMediaItem> sourceItem;
147 rv = change->GetSourceItem(getter_AddRefs(sourceItem));
149 rv = mediaItemsToAdd->AppendElement(sourceItem, PR_FALSE);
150 NS_ENSURE_SUCCESS(rv, rv);
155 NS_WARNING(
"Unexpected change operation value in sbBaseDevice::Import");
162 nsCOMPtr<nsISimpleEnumerator> enumerator;
163 rv = mediaItemsToRemove->Enumerate(getter_AddRefs(enumerator));
164 NS_ENSURE_SUCCESS(rv, rv);
166 rv = aImportToLibrary->RemoveSome(enumerator);
167 NS_ENSURE_SUCCESS(rv, rv);
170 rv = mediaItemsToAdd->Enumerate(getter_AddRefs(enumerator));
171 NS_ENSURE_SUCCESS(rv, rv);
173 rv = aImportToLibrary->AddSome(enumerator);
174 NS_ENSURE_SUCCESS(rv, rv);
177 NS_ENSURE_SUCCESS(rv, rv);
180 NS_ENSURE_SUCCESS(rv, rv);
nsresult AddMediaLists(sbILibrary *aLibrary, nsIArray *aMediaLists)
virtual PRBool IsRequestAborted()
static bool ArePlaylistsSupported(sbIDevice *aDevice)
const unsigned long MODIFIED
Media library abstraction.
nsresult UpdateMediaLists(nsIArray *aMediaLists)
NS_IMETHOD ImportFromDevice(sbILibrary *aImportToLibrary, sbILibraryChangeset *aImportChangeset)
_getSelectedPageStyle s i
const unsigned long ADDED