mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 11:10:52 +00:00
Added an error dialog when trying to edit an empty list of playlists. Also
added the ability for the save playlist dialog to pre-select a playlist by id.
This commit is contained in:
parent
fe4869e673
commit
18faa2056d
@ -96,14 +96,15 @@ static void addPlaylistsToAdapter(
|
||||
static void showPlaylistListOverlay(
|
||||
const std::string& title,
|
||||
std::shared_ptr<Adapter> adapter,
|
||||
ListOverlay::ItemSelectedCallback callback)
|
||||
ListOverlay::ItemSelectedCallback callback,
|
||||
size_t selectedIndex = 0)
|
||||
{
|
||||
std::shared_ptr<ListOverlay> dialog(new ListOverlay());
|
||||
|
||||
dialog->SetAdapter(adapter)
|
||||
.SetTitle(title)
|
||||
.SetWidth(DEFAULT_OVERLAY_WIDTH)
|
||||
.SetSelectedIndex(0)
|
||||
.SetSelectedIndex(selectedIndex)
|
||||
.SetItemSelectedCallback(callback);
|
||||
|
||||
cursespp::App::Overlays().Push(dialog);
|
||||
@ -194,6 +195,17 @@ static void confirmDeletePlaylist(
|
||||
App::Overlays().Push(dialog);
|
||||
}
|
||||
|
||||
static void showNoPlaylistsDialog() {
|
||||
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
|
||||
|
||||
(*dialog)
|
||||
.SetTitle("musikbox")
|
||||
.SetMessage("you haven't saved any playlists!")
|
||||
.AddButton("KEY_ENTER", "ENTER", "ok");
|
||||
|
||||
App::Overlays().Push(dialog);
|
||||
}
|
||||
|
||||
PlayQueueOverlays::PlayQueueOverlays() {
|
||||
}
|
||||
|
||||
@ -295,6 +307,11 @@ void PlayQueueOverlays::ShowLoadPlaylistOverlay(
|
||||
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
|
||||
auto result = query->GetResult();
|
||||
|
||||
if (!result->size()) {
|
||||
showNoPlaylistsDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Adapter> adapter(new Adapter());
|
||||
adapter->SetSelectable(true);
|
||||
addPlaylistsToAdapter(adapter, result);
|
||||
@ -313,7 +330,8 @@ void PlayQueueOverlays::ShowLoadPlaylistOverlay(
|
||||
|
||||
void PlayQueueOverlays::ShowSavePlaylistOverlay(
|
||||
musik::core::audio::PlaybackService& playback,
|
||||
musik::core::ILibraryPtr library)
|
||||
musik::core::ILibraryPtr library,
|
||||
DBID selectedPlaylistId)
|
||||
{
|
||||
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
|
||||
auto result = query->GetResult();
|
||||
@ -323,6 +341,18 @@ void PlayQueueOverlays::ShowSavePlaylistOverlay(
|
||||
adapter->AddEntry("new...");
|
||||
addPlaylistsToAdapter(adapter, result);
|
||||
|
||||
/* the caller can specify a playlistId that we should try to
|
||||
select by default. if they did, try to find it */
|
||||
size_t selectedIndex = 0;
|
||||
if (selectedPlaylistId != -1) {
|
||||
for (size_t i = 0; i < result->size(); i++) {
|
||||
if (result->at(i)->id == selectedPlaylistId) {
|
||||
selectedIndex = i + 1; /* offset "new..." */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showPlaylistListOverlay(
|
||||
"save playlist",
|
||||
adapter,
|
||||
@ -340,13 +370,19 @@ void PlayQueueOverlays::ShowSavePlaylistOverlay(
|
||||
std::string playlistName = (*result)[index]->displayValue;
|
||||
confirmOverwritePlaylist(library, playlistName, playlistId, tracks);
|
||||
}
|
||||
});
|
||||
},
|
||||
selectedIndex);
|
||||
}
|
||||
|
||||
void PlayQueueOverlays::ShowRenamePlaylistOverlay(musik::core::ILibraryPtr library) {
|
||||
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
|
||||
auto result = query->GetResult();
|
||||
|
||||
if (!result->size()) {
|
||||
showNoPlaylistsDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Adapter> adapter(new Adapter());
|
||||
adapter->SetSelectable(true);
|
||||
addPlaylistsToAdapter(adapter, result);
|
||||
@ -367,6 +403,11 @@ void PlayQueueOverlays::ShowDeletePlaylistOverlay(musik::core::ILibraryPtr libra
|
||||
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
|
||||
auto result = query->GetResult();
|
||||
|
||||
if (!result->size()) {
|
||||
showNoPlaylistsDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Adapter> adapter(new Adapter());
|
||||
adapter->SetSelectable(true);
|
||||
addPlaylistsToAdapter(adapter, result);
|
||||
|
@ -62,7 +62,8 @@ namespace musik {
|
||||
|
||||
static void ShowSavePlaylistOverlay(
|
||||
musik::core::audio::PlaybackService& playback,
|
||||
musik::core::ILibraryPtr library);
|
||||
musik::core::ILibraryPtr library,
|
||||
DBID selectedPlaylistId = -1);
|
||||
|
||||
static void ShowRenamePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library);
|
||||
|
Loading…
Reference in New Issue
Block a user