void Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex) { // the playlist is replaced by the refs in the message // or the refs are appended at the appendIndex // in the existing playlist if (appendIndex == APPEND_INDEX_APPEND_LAST) appendIndex = CountItems(); bool add = appendIndex != APPEND_INDEX_REPLACE_PLAYLIST; if (!add) MakeEmpty(); bool startPlaying = CountItems() == 0; Playlist temporaryPlaylist; Playlist* playlist = add ? &temporaryPlaylist : this; bool sortPlaylist = true; entry_ref ref; int32 subAppendIndex = CountItems(); for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++) { Playlist subPlaylist; if (_IsPlaylist(_MIMEString(&ref))) { AppendPlaylistToPlaylist(ref, &subPlaylist); // Do not sort the whole playlist anymore, as that // will screw up the ordering in the saved playlist. sortPlaylist = false; } else { AppendToPlaylistRecursive(ref, &subPlaylist); // At least sort this subsection of the playlist // if the whole playlist is not sorted anymore. if (!sortPlaylist) subPlaylist.Sort(); } int32 subPlaylistCount = subPlaylist.CountItems(); AdoptPlaylist(subPlaylist, subAppendIndex); subAppendIndex += subPlaylistCount; } if (sortPlaylist) playlist->Sort(); if (add) AdoptPlaylist(temporaryPlaylist, appendIndex); if (startPlaying) { // open first file SetCurrentItemIndex(0); } }
bool Playlist::AdoptPlaylist(Playlist& other, int32 index) { if (&other == this) return false; // NOTE: this is not intended to merge two "equal" playlists // the given playlist is assumed to be a temporary "dummy" if (fItems.AddList(&other.fItems, index)) { // take care of the notifications int32 count = other.CountItems(); for (int32 i = index; i < index + count; i++) { PlaylistItem* item = ItemAtFast(i); _NotifyItemAdded(item, i); } if (index <= fCurrentIndex) SetCurrentItemIndex(fCurrentIndex + count); // empty the other list, so that the PlaylistItems are now ours other.fItems.MakeEmpty(); return true; } return false; }