static void showAddTrackToPlaylistOverlay( IMessageQueue& queue, ILibraryPtr library, TrackPtr track) { std::shared_ptr<CategoryListQuery> query = queryPlaylists(library); auto result = query->GetResult(); std::shared_ptr<Adapter> adapter(new Adapter()); adapter->SetSelectable(true); adapter->AddEntry(_TSTR("playqueue_overlay_new")); addPlaylistsToAdapter(adapter, result); size_t selectedIndex = 0; if (!lastOperationExpired() && lastPlaylistId >= 0) { int index = findPlaylistIndex(result, lastPlaylistId); if (index >= 0) { selectedIndex = (size_t) index + 1; /* +1 offsets "new..." */ } } showPlaylistListOverlay( _TSTR("playqueue_overlay_select_playlist_title"), adapter, [library, track, &queue, result] (ListOverlay* overlay, IScrollAdapterPtr adapter, size_t index) { if (index != ListWindow::NO_SELECTION) { std::shared_ptr<TrackList> list(new TrackList(library)); list->Add(track->GetId()); if (index == 0) { /* new playlist */ createNewPlaylist(queue, list, library); } else { /* add to existing */ int64_t playlistId = (*result)[index - 1]->GetId(); setLastPlaylistId(playlistId); library->Enqueue(SavePlaylistQuery::Append(library, playlistId, list), 0); } } }, selectedIndex); }
void PlayQueueOverlays::ShowAddTrackOverlay( IMessageQueue& messageQueue, ILibraryPtr library, PlaybackService& playback, TrackPtr track) { std::shared_ptr<Adapter> adapter(new Adapter()); adapter->AddEntry(_TSTR("playqueue_overlay_album_jump_to")); adapter->AddEntry(_TSTR("playqueue_overlay_artist_jump_to")); adapter->AddEntry(_TSTR("playqueue_overlay_genre_jump_to")); adapter->AddEntry(_TSTR("playqueue_overlay_add_to_playlist")); adapter->AddEntry(_TSTR("playqueue_overlay_add_to_start_of_queue")); adapter->AddEntry(_TSTR("playqueue_overlay_add_to_end_in_queue")); adapter->AddEntry(_TSTR("playqueue_overlay_add_as_next_in_queue")); adapter->SetSelectable(true); size_t selectedIndex = 0; if (!lastOperationExpired()) { selectedIndex = lastTrackOverlayIndex; } std::shared_ptr<ListOverlay> dialog(new ListOverlay()); dialog->SetAdapter(adapter) .SetTitle(_TSTR("playqueue_overlay_track_actions_title")) .SetWidth(_DIMEN("playqueue_playlist_add_to_queue_overlay_width", DEFAULT_OVERLAY_WIDTH)) .SetSelectedIndex(selectedIndex) .SetItemSelectedCallback( [track, library, &messageQueue, &playback] (ListOverlay* overlay, IScrollAdapterPtr adapter, size_t index) { if (index == ListWindow::NO_SELECTION) { return; } setLastTrackOverlayIndex(index); auto editor = playback.Edit(); if (index <= 2) { handleJumpTo(index, messageQueue, track); } else if (index == 3) { showAddTrackToPlaylistOverlay(messageQueue, library, track); } else if (index == 4) { /* start */ editor.Insert(track->GetId(), 0); } else if (index == 5) { /* end */ editor.Add(track->GetId()); } else { /* next */ size_t position = playback.GetIndex(); if (position == ListWindow::NO_SELECTION) { editor.Add(track->GetId()); } else { editor.Insert(track->GetId(), position + 1); } } }); cursespp::App::Overlays().Push(dialog); }