Added playlist deletion queries and basic UI.

This commit is contained in:
Casey Langen 2017-01-26 22:50:27 -08:00
parent 715a58f2d1
commit 3d4bf9e4a4
5 changed files with 242 additions and 64 deletions

View File

@ -3,6 +3,7 @@ set(GLUE_SOURCES
./query/GetPlaylistQuery.cpp
./query/CategoryListQuery.cpp
./query/CategoryTrackListQuery.cpp
./query/DeletePlaylistQuery.cpp
./query/NowPlayingTrackListQuery.cpp
./query/SavePlaylistQuery.cpp
./query/SearchTrackListQuery.cpp

View File

@ -0,0 +1,80 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "DeletePlaylistQuery.h"
#include <core/db/ScopedTransaction.h>
#include <core/db/Statement.h>
using namespace musik::core;
using namespace musik::core::query;
using namespace musik::core::db;
using namespace musik::glue;
static std::string DELETE_PLAYLIST_TRACKS_QUERY =
"DELETE FROM playlist_tracks WHERE playlist_id=?;";
static std::string DELETE_PLAYLIST_QUERY =
"DELETE FROM playlists WHERE id=?;";
DeletePlaylistQuery::DeletePlaylistQuery(const DBID playlistId) {
this->playlistId = playlistId;
}
DeletePlaylistQuery::~DeletePlaylistQuery() {
}
bool DeletePlaylistQuery::OnRun(musik::core::db::Connection &db) {
ScopedTransaction transaction(db);
/* create playlist */
Statement deleteTracks(DELETE_PLAYLIST_TRACKS_QUERY.c_str(), db);
deleteTracks.BindInt(0, this->playlistId);
if (deleteTracks.Step() == db::Error) {
transaction.Cancel();
return false;
}
/* add tracks to playlist */
Statement deletePlaylist(DELETE_PLAYLIST_QUERY.c_str(), db);
deletePlaylist.BindInt(0, this->playlistId);
if (deletePlaylist.Step() == db::Error) {
transaction.Cancel();
return false;
}
return true;
}

View File

@ -0,0 +1,56 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <core/library/query/QueryBase.h>
#include <core/db/Connection.h>
namespace musik {
namespace glue {
class DeletePlaylistQuery : public musik::core::query::QueryBase {
public:
DeletePlaylistQuery(const DBID playlistId);
virtual ~DeletePlaylistQuery();
virtual std::string Name() { return "DeletePlaylistQuery"; }
protected:
virtual bool OnRun(musik::core::db::Connection &db);
private:
DBID playlistId;
};
}
}

View File

@ -229,7 +229,7 @@ bool NowPlayingLayout::KeyPress(const std::string& key) {
PlayQueueOverlays::ShowRenamePlaylistOverlay(this->library);
return true;
}
else if (key == "M-d") {
else if (key == "M-x") {
PlayQueueOverlays::ShowDeletePlaylistOverlay(this->library);
return true;
}

View File

@ -43,6 +43,7 @@
#include <glue/query/CategoryListQuery.h>
#include <glue/query/GetPlaylistQuery.h>
#include <glue/query/SavePlaylistQuery.h>
#include <glue/query/DeletePlaylistQuery.h>
#include <cursespp/App.h>
#include <cursespp/SimpleScrollAdapter.h>
@ -108,6 +109,91 @@ static void showPlaylistListOverlay(
cursespp::App::Overlays().Push(dialog);
}
static void confirmOverwritePlaylist(
musik::core::ILibraryPtr library,
const std::string& playlistName,
const DBID playlistId,
std::shared_ptr<TrackList> tracks)
{
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
(*dialog)
.SetTitle("musikbox")
.SetMessage("are you sure you want to overwrite the playlist '" + playlistName + "'?")
.AddButton("^[", "ESC", "no")
.AddButton(
"KEY_ENTER",
"ENTER",
"yes",
[library, playlistId, tracks](const std::string& str) {
library->Enqueue(SavePlaylistQuery::Replace(playlistId, tracks));
});
App::Overlays().Push(dialog);
}
static void createNewPlaylist(
std::shared_ptr<TrackList> tracks,
musik::core::ILibraryPtr library)
{
std::shared_ptr<InputOverlay> dialog(new InputOverlay());
dialog->SetTitle("playlist name")
.SetWidth(DEFAULT_OVERLAY_WIDTH)
.SetText("")
.SetInputAcceptedCallback(
[tracks, library](const std::string& name) {
if (name.size()) {
library->Enqueue(SavePlaylistQuery::Save(name, tracks));
}
});
cursespp::App::Overlays().Push(dialog);
}
static void renamePlaylist(
musik::core::ILibraryPtr library,
const DBID playlistId,
const std::string& oldName)
{
std::shared_ptr<InputOverlay> dialog(new InputOverlay());
dialog->SetTitle("new playlist name")
.SetWidth(DEFAULT_OVERLAY_WIDTH)
.SetText(oldName)
.SetInputAcceptedCallback(
[library, playlistId](const std::string& name) {
if (name.size()) {
library->Enqueue(SavePlaylistQuery::Rename(playlistId, name));
}
});
cursespp::App::Overlays().Push(dialog);
}
static void confirmDeletePlaylist(
musik::core::ILibraryPtr library,
const std::string& playlistName,
const DBID playlistId)
{
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
(*dialog)
.SetTitle("musikbox")
.SetMessage("are you sure you want to delete '" + playlistName + "'?")
.AddButton("^[", "ESC", "no")
.AddButton(
"KEY_ENTER",
"ENTER",
"yes",
[library, playlistId](const std::string& str) {
library->Enqueue(std::shared_ptr<DeletePlaylistQuery>(
new DeletePlaylistQuery(playlistId)));
});
App::Overlays().Push(dialog);
}
PlayQueueOverlays::PlayQueueOverlays() {
}
@ -225,48 +311,6 @@ void PlayQueueOverlays::ShowLoadPlaylistOverlay(
});
}
static void createNewPlaylist(
std::shared_ptr<TrackList> tracks,
musik::core::ILibraryPtr library)
{
std::shared_ptr<InputOverlay> dialog(new InputOverlay());
dialog->SetTitle("playlist name")
.SetWidth(DEFAULT_OVERLAY_WIDTH)
.SetText("")
.SetInputAcceptedCallback(
[tracks, library](const std::string& name) {
if (name.size()) {
library->Enqueue(SavePlaylistQuery::Save(name, tracks));
}
});
cursespp::App::Overlays().Push(dialog);
}
static void confirmOverwritePlaylist(
musik::core::ILibraryPtr library,
const std::string& playlistName,
const DBID playlistId,
std::shared_ptr<TrackList> tracks)
{
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
(*dialog)
.SetTitle("musikbox")
.SetMessage("are you sure you want to overwrite the playlist '" + playlistName + "'?")
.AddButton("^[", "ESC", "no")
.AddButton(
"KEY_ENTER",
"ENTER",
"yes",
[library, playlistId, tracks](const std::string& str) {
library->Enqueue(SavePlaylistQuery::Replace(playlistId, tracks));
});
App::Overlays().Push(dialog);
}
void PlayQueueOverlays::ShowSavePlaylistOverlay(
musik::core::audio::PlaybackService& playback,
musik::core::ILibraryPtr library)
@ -299,26 +343,6 @@ void PlayQueueOverlays::ShowSavePlaylistOverlay(
});
}
static void renamePlaylist(
musik::core::ILibraryPtr library,
const DBID playlistId,
const std::string& oldName)
{
std::shared_ptr<InputOverlay> dialog(new InputOverlay());
dialog->SetTitle("new playlist name")
.SetWidth(DEFAULT_OVERLAY_WIDTH)
.SetText(oldName)
.SetInputAcceptedCallback(
[library, playlistId](const std::string& name) {
if (name.size()) {
library->Enqueue(SavePlaylistQuery::Rename(playlistId, name));
}
});
cursespp::App::Overlays().Push(dialog);
}
void PlayQueueOverlays::ShowRenamePlaylistOverlay(musik::core::ILibraryPtr library) {
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
auto result = query->GetResult();
@ -340,5 +364,22 @@ void PlayQueueOverlays::ShowRenamePlaylistOverlay(musik::core::ILibraryPtr libra
}
void PlayQueueOverlays::ShowDeletePlaylistOverlay(musik::core::ILibraryPtr library) {
/* stubbed */
std::shared_ptr<CategoryListQuery> query = queryPlaylists(library);
auto result = query->GetResult();
std::shared_ptr<Adapter> adapter(new Adapter());
adapter->SetSelectable(true);
addPlaylistsToAdapter(adapter, result);
showPlaylistListOverlay(
"delete playlist",
adapter,
[library, result]
(cursespp::IScrollAdapterPtr adapter, size_t index) {
if (index != ListWindow::NO_SELECTION) {
DBID playlistId = (*result)[index]->id;
std::string playlistName = (*result)[index]->displayValue;
confirmDeletePlaylist(library, playlistName, playlistId);
}
});
}