56 #include <nsComponentManagerUtils.h>
57 #include <nsISimpleEnumerator.h>
71 sbIPDDevice::ImportPlaylists()
74 GList* playlistList = mITDB->playlists;
75 while (playlistList) {
80 Itdb_Playlist* playlist = (Itdb_Playlist *) playlistList->data;
81 playlistList = playlistList->next;
84 if (itdb_playlist_is_mpl(playlist))
88 ImportPlaylist(playlist);
103 sbIPDDevice::ImportPlaylist(Itdb_Playlist*
aPlaylist)
106 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
109 return ImportPlaylist(mDeviceLibrary, aPlaylist);
124 sbIPDDevice::ImportPlaylist(
sbILibrary* aLibrary,
129 NS_ASSERTION(aLibrary,
"aLibrary is null");
130 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
133 nsCOMPtr<sbIMediaList> mediaList;
137 FIELD_LOG((
"Importing playlist %s\n", aPlaylist->name));
140 PRBool inDeviceLibrary;
141 rv = aLibrary->Equals(mDeviceLibrary, &inDeviceLibrary);
142 NS_ENSURE_SUCCESS(rv, rv);
146 sbIPDAutoStopIgnoreLibrary autoStopIgnoreLibrary;
147 sbIPDAutoStopIgnoreMediaLists autoStopIgnoreMediaLists;
148 if (inDeviceLibrary) {
152 autoStopIgnoreMediaLists.Set(
this);
157 if (inDeviceLibrary) {
158 nsCOMPtr<sbIMediaItem> mediaItem;
162 getter_AddRefs(mediaItem));
163 if (NS_SUCCEEDED(rv)) {
164 mediaList = do_QueryInterface(mediaItem, &rv);
165 NS_ENSURE_SUCCESS(rv, rv);
166 rv = mediaList->Clear();
167 NS_ENSURE_SUCCESS(rv, rv);
169 NS_ENSURE_TRUE(rv == NS_ERROR_NOT_AVAILABLE, rv);
175 rv = aLibrary->CreateMediaList(NS_LITERAL_STRING(
"simple"),
177 getter_AddRefs(mediaList));
178 NS_ENSURE_SUCCESS(rv, rv);
182 nsAutoString playlistName;
183 playlistName.Assign(NS_ConvertUTF8toUTF16(aPlaylist->name));
184 rv = mediaList->SetName(playlistName);
185 NS_ENSURE_SUCCESS(rv, rv);
189 if (inDeviceLibrary) {
190 rv = mediaList->SetProperty
193 NS_ENSURE_SUCCESS(rv, rv);
194 rv = mediaList->SetProperty
196 NS_LITERAL_STRING(
"1"));
197 NS_ENSURE_SUCCESS(rv, rv);
201 if (inDeviceLibrary) {
203 autoStopIgnoreLibrary.forget();
205 autoStopIgnoreMediaLists.forget();
209 rv = ImportPlaylistTracks(aPlaylist, mediaList);
210 NS_ENSURE_SUCCESS(rv, rv);
214 NS_ADDREF(*aMediaList = mediaList);
229 sbIPDDevice::ImportPlaylistTracks(Itdb_Playlist* aPlaylist,
233 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
234 NS_ASSERTION(aMediaList,
"aMediaList is null");
237 Itdb_Track** trackBatch =
238 static_cast<Itdb_Track**
>
239 (NS_Alloc(TrackBatchSize *
sizeof (Itdb_Track *)));
240 NS_ENSURE_TRUE(trackBatch, NS_ERROR_OUT_OF_MEMORY);
244 int trackCount = itdb_playlist_tracks_number(aPlaylist);
245 GList* trackList = aPlaylist->members;
246 PRUint32 trackNum = 0;
247 PRUint32 batchCount = 0;
253 Itdb_Track* track = (Itdb_Track *) trackList->data;
254 trackList = trackList->next;
257 mIPDStatus->
ItemStart(aPlaylist, track, trackNum, trackCount);
260 trackBatch[batchCount] = track;
264 if ((batchCount >= TrackBatchSize) || (!trackList)) {
265 ImportPlaylistTrackBatch(aMediaList, trackBatch, batchCount);
287 sbIPDDevice::ImportPlaylistTrackBatch(
sbIMediaList* aMediaList,
288 Itdb_Track** aTrackBatch,
289 PRUint32 aBatchCount)
292 NS_ASSERTION(aMediaList,
"aMediaList is null");
293 NS_ASSERTION(aTrackBatch,
"aTrackBatch is null");
299 nsCOMPtr<sbILibrary> tgtLibrary;
300 PRBool inDeviceLibrary;
301 rv = aMediaList->GetLibrary(getter_AddRefs(tgtLibrary));
302 NS_ENSURE_SUCCESS(rv, rv);
303 rv = tgtLibrary->Equals(mDeviceLibrary, &inDeviceLibrary);
304 NS_ENSURE_SUCCESS(rv, rv);
308 sbIPDAutoStopIgnoreLibrary autoStopIgnoreLibrary;
309 sbIPDAutoStopIgnoreMediaLists autoStopIgnoreMediaLists;
310 if (inDeviceLibrary) {
314 autoStopIgnoreMediaLists.Set(
this);
318 nsCOMPtr<nsIMutableArray> trackMediaItemArray =
319 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
320 NS_ENSURE_SUCCESS(rv, rv);
323 for (PRUint32
i = 0;
i < aBatchCount;
i++) {
325 Itdb_Track* track = aTrackBatch[
i];
326 nsCOMPtr<sbIMediaItem> mediaItem;
327 if (inDeviceLibrary) {
331 getter_AddRefs(mediaItem));
336 getter_AddRefs(mediaItem));
338 if (NS_SUCCEEDED(rv))
339 trackMediaItemArray->AppendElement(mediaItem, PR_FALSE);
341 nsCOMPtr<nsISimpleEnumerator> trackMediaItemEnum;
342 rv = trackMediaItemArray->Enumerate(getter_AddRefs(trackMediaItemEnum));
343 NS_ENSURE_SUCCESS(rv, rv);
346 rv = aMediaList->AddSome(trackMediaItemEnum);
347 NS_ENSURE_SUCCESS(rv, rv);
369 Itdb_Playlist** aPlaylist)
373 NS_ASSERTION(aMediaList,
"aMediaList is null");
374 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
380 nsAutoString playlistName;
381 rv = aMediaList->GetName(playlistName);
382 NS_ENSURE_SUCCESS(rv, rv);
385 Itdb_Playlist* playlist = itdb_playlist_new
386 (NS_ConvertUTF16toUTF8(playlistName).
get(),
388 NS_ENSURE_TRUE(playlist, NS_ERROR_OUT_OF_MEMORY);
389 itdb_playlist_add(mITDB, playlist, -1);
393 rv = aMediaList->SetProperty
397 NS_ENSURE_SUCCESS(rv, rv);
400 mITDBDirty = PR_TRUE;
403 *aPlaylist = playlist;
418 NS_ASSERTION(aMediaList,
"aMediaList is null");
424 Itdb_Playlist* playlist;
425 rv = GetPlaylist(aMediaList, &playlist);
426 NS_ENSURE_SUCCESS(rv, rv);
429 itdb_playlist_remove(playlist);
432 mITDBDirty = PR_TRUE;
448 sbIPDDevice::PlaylistUpdateProperties(
sbIMediaList* aMediaList,
449 Itdb_Playlist* aPlaylist)
452 NS_ASSERTION(aMediaList,
"aMediaList is null");
460 rv = GetPlaylist(aMediaList, &playlist);
461 NS_ENSURE_SUCCESS(rv, rv);
465 nsAutoString nsPlaylistName;
466 gchar* cPlaylistName;
467 rv = aMediaList->GetName(nsPlaylistName);
468 NS_ENSURE_SUCCESS(rv, rv);
469 cPlaylistName = g_strdup(NS_ConvertUTF16toUTF8(nsPlaylistName).
get());
470 NS_ENSURE_TRUE(cPlaylistName, NS_ERROR_OUT_OF_MEMORY);
471 sbAutoGMemPtr autoCPlaylistName(cPlaylistName);
474 if (strcmp(cPlaylistName, playlist->name)) {
476 g_free(playlist->name);
477 playlist->name = cPlaylistName;
478 autoCPlaylistName.forget();
482 mITDBDirty = PR_TRUE;
506 NS_ASSERTION(aMediaList,
"aMediaList is null");
507 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
513 Itdb_Playlist* playlist;
514 rv = GetPlaylist(aMediaList, &playlist);
515 NS_ENSURE_SUCCESS(rv, rv);
519 rv = GetTrack(aMediaItem, &track);
520 NS_ENSURE_SUCCESS(rv, rv);
523 itdb_playlist_add_track(playlist, track, aIndex);
526 mITDBDirty = PR_TRUE;
545 sbIPDDevice::PlaylistRemoveTrack(
sbIMediaList* aMediaList,
550 NS_ASSERTION(aMediaList,
"aMediaList is null");
551 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
557 Itdb_Playlist* playlist;
558 rv = GetPlaylist(aMediaList, &playlist);
559 NS_ENSURE_SUCCESS(rv, rv);
563 GList* members = playlist->members;
564 GList* trackMember = g_list_nth(members, aIndex);
565 NS_ENSURE_TRUE(trackMember, NS_ERROR_INVALID_ARG);
566 playlist->members = g_list_delete_link(members, trackMember);
569 mITDBDirty = PR_TRUE;
581 Itdb_Playlist* playlist;
582 nsresult rv = GetPlaylist(aMediaList, &playlist);
583 NS_ENSURE_SUCCESS(rv, rv);
586 GList* members = playlist->members;
587 playlist->members = g_list_alloc();
588 g_list_free(members);
591 mITDBDirty = PR_TRUE;
609 sbIPDDevice::PlaylistMoveTrack(
sbIMediaList* aMediaList,
614 NS_ASSERTION(aMediaList,
"aMediaList is null");
620 Itdb_Playlist* playlist;
621 rv = GetPlaylist(aMediaList, &playlist);
622 NS_ENSURE_SUCCESS(rv, rv);
625 GList* members = playlist->members;
626 GList* trackMember = g_list_nth(members, aIndexFrom);
627 NS_ENSURE_TRUE(trackMember, NS_ERROR_INVALID_ARG);
628 Itdb_Track* track = (Itdb_Track *) trackMember->data;
632 playlist->members = g_list_delete_link(members, trackMember);
635 itdb_playlist_add_track(playlist, track, aIndexTo);
638 mITDBDirty = PR_TRUE;
656 sbIPDDevice::ProcessOTGPlaylists()
661 PRBool otgPlaylistsPresent = PR_FALSE;
662 PRUint32 otgPlaylistIndex = 1;
663 GList* playlistList = mITDB->playlists;
664 while (playlistList) {
669 Itdb_Playlist* playlist = (Itdb_Playlist *) playlistList->data;
670 playlistList = playlistList->next;
675 if (playlist->is_otg) {
677 otgPlaylistsPresent = PR_TRUE;
678 rv = SetOTGPlaylistName(playlist, otgPlaylistIndex);
680 itdb_playlist_remove(playlist);
684 mITDBDirty = PR_TRUE;
701 sbIPDDevice::SetOTGPlaylistName(Itdb_Playlist* aPlaylist,
702 PRUint32 aPlaylistIndex)
705 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
711 nsAutoString playlistName;
713 const PRUnichar *stringList[1] = { playlistIndex.get() };
714 rv = mLocale->FormatStringFromName
715 (NS_LITERAL_STRING(
"on_the_go.playlist_name").
get(),
718 getter_Copies(playlistName));
719 NS_ENSURE_SUCCESS(rv, rv);
722 gchar *cPlaylistName = g_strdup(NS_ConvertUTF16toUTF8(playlistName).
get());
723 NS_ENSURE_TRUE(cPlaylistName, NS_ERROR_OUT_OF_MEMORY);
725 g_free(aPlaylist->name);
726 aPlaylist->name = cPlaylistName;
729 mITDBDirty = PR_TRUE;
751 Itdb_Playlist** aPlaylist)
754 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
755 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
758 Itdb_Playlist* playlist;
763 rv = GetIPodID(aMediaItem, &iPodID);
764 NS_ENSURE_SUCCESS(rv, rv);
767 playlist = itdb_playlist_by_id(mITDB, iPodID);
768 NS_ENSURE_TRUE(playlist, NS_ERROR_NOT_AVAILABLE);
771 *aPlaylist = playlist;
static nsresult GetOriginMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
Songbird iPod Device Utility Definitions.
void ItemStart(PRInt32 aItemNum=-1, PRInt32 aItemCount=-1)
#define SB_PROPERTY_DEVICE_PERSISTENT_ID
nsRefPtr< sbBaseDeviceLibraryListener > mLibraryListener
virtual PRBool IsRequestAborted()
Songbird iPod Device Definitions.
Songbird iPod Device Logging Definitions.
Media library abstraction.
nsresult SetIgnoreMediaListListeners(PRBool aIgnoreListener)
static nsresult GetMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
#define SB_PROPERTY_AVAILABILITY
_getSelectedPageStyle s i