From 00a1827b1f9a62afc1ce9bb8f75bea4239e2a23a Mon Sep 17 00:00:00 2001 From: Casey Langen Date: Sat, 18 Jun 2016 11:10:58 -0700 Subject: [PATCH] Added a stubbed track search view. --- src/musikbox/CMakeLists.txt | 2 + src/musikbox/app/layout/LibraryLayout.cpp | 14 +- src/musikbox/app/layout/LibraryLayout.h | 9 +- src/musikbox/app/layout/TrackSearchLayout.cpp | 121 ++++++++++++++++++ src/musikbox/app/layout/TrackSearchLayout.h | 77 +++++++++++ src/musikbox/app/model/TrackList.cpp | 2 - .../app/query/SearchTrackListQuery.cpp | 115 +++++++++++++++++ src/musikbox/app/query/SearchTrackListQuery.h | 66 ++++++++++ 8 files changed, 401 insertions(+), 5 deletions(-) create mode 100755 src/musikbox/app/layout/TrackSearchLayout.cpp create mode 100755 src/musikbox/app/layout/TrackSearchLayout.h create mode 100755 src/musikbox/app/query/SearchTrackListQuery.cpp create mode 100755 src/musikbox/app/query/SearchTrackListQuery.h diff --git a/src/musikbox/CMakeLists.txt b/src/musikbox/CMakeLists.txt index af28c3548..218c82d7c 100644 --- a/src/musikbox/CMakeLists.txt +++ b/src/musikbox/CMakeLists.txt @@ -6,10 +6,12 @@ set (BOX_SRCS ./app/layout/LibraryLayout.cpp ./app/layout/NowPlayingLayout.cpp ./app/layout/SearchLayout.cpp + ./app/layout/TrackSearchLayout.cpp ./app/model/TrackList.cpp ./app/query/CategoryListViewQuery.cpp ./app/query/CategoryTrackListQuery.cpp ./app/query/NowPlayingTrackListQuery.cpp + ./app/query/SearchTrackListQuery.cpp ./app/service/PlaybackService.cpp ./app/util/GlobalHotkeys.cpp ./app/util/SystemInfo.cpp diff --git a/src/musikbox/app/layout/LibraryLayout.cpp b/src/musikbox/app/layout/LibraryLayout.cpp index e9bfbd74a..8b6bfc34f 100755 --- a/src/musikbox/app/layout/LibraryLayout.cpp +++ b/src/musikbox/app/layout/LibraryLayout.cpp @@ -84,6 +84,9 @@ void LibraryLayout::Layout() { this->searchLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT); this->searchLayout->Layout(); + this->trackSearch->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT); + this->trackSearch->Layout(); + this->transportView->MoveAndResize( 1, cy - TRANSPORT_HEIGHT, @@ -125,6 +128,10 @@ void LibraryLayout::ShowSearch() { this->ChangeMainLayout(this->searchLayout); } +void LibraryLayout::ShowTrackSearch() { + this->ChangeMainLayout(this->trackSearch); +} + void LibraryLayout::InitializeWindows() { this->browseLayout.reset(new BrowseLayout(this->playback, this->library)); this->nowPlayingLayout.reset(new NowPlayingLayout(this->playback, this->library)); @@ -132,6 +139,8 @@ void LibraryLayout::InitializeWindows() { this->searchLayout.reset(new SearchLayout(this->playback, this->library)); this->searchLayout->SearchResultSelected.connect(this, &LibraryLayout::OnSearchResultSelected); + this->trackSearch.reset(new TrackSearchLayout(this->playback, this->library)); + this->transportView.reset(new TransportWindow(this->playback)); this->AddWindow(this->transportView); @@ -168,9 +177,12 @@ bool LibraryLayout::KeyPress(const std::string& key) { this->ShowNowPlaying(); } } - else if (key == "M-f") { /* show search */ + else if (key == "M-f") { /* show album/artist/genre search */ this->ShowSearch(); } + else if (key == "M-t") { /* show track search */ + this->ShowTrackSearch(); + } /* forward to the visible layout */ else if (this->visibleLayout && this->visibleLayout->KeyPress(key)) { return true; diff --git a/src/musikbox/app/layout/LibraryLayout.h b/src/musikbox/app/layout/LibraryLayout.h index 954a72a56..b0c4c97a1 100755 --- a/src/musikbox/app/layout/LibraryLayout.h +++ b/src/musikbox/app/layout/LibraryLayout.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -67,14 +68,17 @@ namespace musik { private: void OnSearchResultSelected( - SearchLayout* layout, - std::string fieldType, + SearchLayout* layout, + std::string fieldType, DBID fieldId); void InitializeWindows(); + void ShowNowPlaying(); void ShowBrowse(); void ShowSearch(); + void ShowTrackSearch(); + void ChangeMainLayout(std::shared_ptr newLayout); PlaybackService& playback; @@ -84,6 +88,7 @@ namespace musik { std::shared_ptr transportView; std::shared_ptr nowPlayingLayout; std::shared_ptr searchLayout; + std::shared_ptr trackSearch; std::shared_ptr visibleLayout; }; } diff --git a/src/musikbox/app/layout/TrackSearchLayout.cpp b/src/musikbox/app/layout/TrackSearchLayout.cpp new file mode 100755 index 000000000..dad495db6 --- /dev/null +++ b/src/musikbox/app/layout/TrackSearchLayout.cpp @@ -0,0 +1,121 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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 "stdafx.h" + +#include +#include +#include +#include +#include "TrackSearchLayout.h" + +using namespace musik::core::library::constants; + +using namespace musik::core; +using namespace musik::core::audio; +using namespace musik::core::library; +using namespace musik::box; +using namespace cursespp; + +#define SEARCH_HEIGHT 3 + +TrackSearchLayout::TrackSearchLayout( + PlaybackService& playback, + musik::core::LibraryPtr library) +: LayoutBase() +, playback(playback) +, library(library) { + this->InitializeWindows(); +} + +TrackSearchLayout::~TrackSearchLayout() { + +} + +void TrackSearchLayout::Layout() { + size_t cx = this->GetWidth(), cy = this->GetHeight(); + + if (cx && cy) { + int x = this->GetX(), y = this->GetY(); + + size_t inputWidth = cx / 2; + size_t inputX = x + ((cx - inputWidth) / 2); + this->input->MoveAndResize(inputX, y, cx / 2, SEARCH_HEIGHT); + + this->trackList->MoveAndResize( + x, + y + SEARCH_HEIGHT, + this->GetWidth(), + this->GetHeight() - SEARCH_HEIGHT); + } +} + +void TrackSearchLayout::InitializeWindows() { + this->input.reset(new cursespp::TextInput()); + //this->input->TextChanged.connect(this, &SearchLayout::OnInputChanged); + this->input->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->input->SetFocusOrder(0); + this->AddWindow(this->input); + + this->trackList.reset(new TrackListView(this->playback, this->library)); + this->trackList->SetFocusOrder(1); + this->AddWindow(this->trackList); + + this->Layout(); +} + +void TrackSearchLayout::OnVisibilityChanged(bool visible) { + LayoutBase::OnVisibilityChanged(visible); + + if (visible) { + this->RequeryTrackList(); + } + else { + this->trackList->Clear(); + } +} + +void TrackSearchLayout::RequeryTrackList() { + // this->trackList->Requery(std::shared_ptr( + // new NowPlayingTrackListQuery(this->library, this->playback))); +} + +bool TrackSearchLayout::KeyPress(const std::string& key) { + // if (key == "^M") { /* enter. play the selection */ + // this->playback.Play(this->trackList->GetSelectedIndex()); + // return true; + // } + + return LayoutBase::KeyPress(key); +} diff --git a/src/musikbox/app/layout/TrackSearchLayout.h b/src/musikbox/app/layout/TrackSearchLayout.h new file mode 100755 index 000000000..80aeb1b04 --- /dev/null +++ b/src/musikbox/app/layout/TrackSearchLayout.h @@ -0,0 +1,77 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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 +#include + +#include +#include + +#include + +#include + +namespace musik { + namespace box { + class TrackSearchLayout : + public cursespp::LayoutBase, +#if (__clang_major__ == 7 && __clang_minor__ == 3) + public std::enable_shared_from_this, +#endif + public sigslot::has_slots<> + { + public: + TrackSearchLayout( + PlaybackService& playback, + musik::core::LibraryPtr library); + + virtual ~TrackSearchLayout(); + + virtual void Layout(); + virtual void OnVisibilityChanged(bool visible); + virtual bool KeyPress(const std::string& key); + + private: + void InitializeWindows(); + void RequeryTrackList(); + + PlaybackService& playback; + musik::core::LibraryPtr library; + std::shared_ptr trackList; + std::shared_ptr input; + }; + } +} diff --git a/src/musikbox/app/model/TrackList.cpp b/src/musikbox/app/model/TrackList.cpp index 30528416b..496fcb805 100755 --- a/src/musikbox/app/model/TrackList.cpp +++ b/src/musikbox/app/model/TrackList.cpp @@ -102,9 +102,7 @@ TrackPtr TrackList::Get(size_t index) { new TrackMetadataQuery(id, this->library)); this->library->Enqueue(query, ILibrary::QuerySynchronous); - this->AddToCache(id, query->Result()); - return query->Result(); } diff --git a/src/musikbox/app/query/SearchTrackListQuery.cpp b/src/musikbox/app/query/SearchTrackListQuery.cpp new file mode 100755 index 000000000..db83896a6 --- /dev/null +++ b/src/musikbox/app/query/SearchTrackListQuery.cpp @@ -0,0 +1,115 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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 "stdafx.h" +#include "SearchTrackListQuery.h" + +#include +#include +#include + +#include + +using musik::core::db::Statement; +using musik::core::db::Row; +using musik::core::TrackPtr; +using musik::core::LibraryTrack; +using musik::core::LibraryPtr; + +using namespace musik::core::db; +using namespace musik::core::library::constants; +using namespace musik::box; + +SearchTrackListQuery::SearchTrackListQuery(LibraryPtr library, const std::string& filter) { + this->library = library; + this->filter = "%" + boost::algorithm::to_lower_copy(filter) + "%"; + this->result.reset(new TrackList(library)); + this->headers.reset(new std::set()); + this->hash = 0; +} + +SearchTrackListQuery::~SearchTrackListQuery() { +} + +SearchTrackListQuery::Result SearchTrackListQuery::GetResult() { + return this->result; +} + +SearchTrackListQuery::Headers SearchTrackListQuery::GetHeaders() { + return this->headers; +} + +size_t SearchTrackListQuery::GetQueryHash() { + this->hash = std::hash()(this->filter); + return this->hash; +} + +bool SearchTrackListQuery::OnRun(Connection& db) { + if (result) { + result.reset(new TrackList(this->library)); + headers.reset(new std::set()); + } + + std::string lastAlbum; + size_t index = 0; + + std::string query = + "SELECT DISTINCT t.id, al.name " \ + "FROM tracks t, albums al, artists ar, genres gn " \ + "WHERE " + "(t.title LIKE ? OR al.name LIKE ? OR ar.name LIKE ? OR gn.name LIKE ?) " + " AND t.album_id=al.id AND t.visual_genre_id=gn.id AND t.visual_artist_id=ar.id " + "ORDER BY al.name, disc, track, ar.name"; + + Statement trackQuery(query.c_str(), db); + trackQuery.BindText(0, this->filter); + trackQuery.BindText(1, this->filter); + trackQuery.BindText(2, this->filter); + trackQuery.BindText(3, this->filter); + + while (trackQuery.Step() == Row) { + DBID id = trackQuery.ColumnInt64(0); + std::string album = trackQuery.ColumnText(1); + + if (album != lastAlbum) { + headers->insert(index); + lastAlbum = album; + } + + result->Add(id); + ++index; + } + + return true; +} diff --git a/src/musikbox/app/query/SearchTrackListQuery.h b/src/musikbox/app/query/SearchTrackListQuery.h new file mode 100755 index 000000000..b4d5572de --- /dev/null +++ b/src/musikbox/app/query/SearchTrackListQuery.h @@ -0,0 +1,66 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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 "TrackListQueryBase.h" + +namespace musik { + namespace box { + class SearchTrackListQuery : public TrackListQueryBase { + public: + SearchTrackListQuery( + musik::core::LibraryPtr library, + const std::string& filter); + + virtual ~SearchTrackListQuery(); + + virtual std::string Name() { return "SearchTrackListQuery"; } + + virtual Result GetResult(); + virtual Headers GetHeaders(); + virtual size_t GetQueryHash(); + + protected: + virtual bool OnRun(musik::core::db::Connection &db); + + private: + musik::core::LibraryPtr library; + Result result; + Headers headers; + std::string filter; + size_t hash; + }; + } +}