Added a stubbed track search view.

This commit is contained in:
Casey Langen 2016-06-18 11:10:58 -07:00
parent dfcaa7caa1
commit 00a1827b1f
8 changed files with 401 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -40,6 +40,7 @@
#include <app/layout/BrowseLayout.h>
#include <app/layout/NowPlayingLayout.h>
#include <app/layout/SearchLayout.h>
#include <app/layout/TrackSearchLayout.h>
#include <app/window/TransportWindow.h>
#include <app/service/PlaybackService.h>
@ -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<cursespp::LayoutBase> newLayout);
PlaybackService& playback;
@ -84,6 +88,7 @@ namespace musik {
std::shared_ptr<TransportWindow> transportView;
std::shared_ptr<NowPlayingLayout> nowPlayingLayout;
std::shared_ptr<SearchLayout> searchLayout;
std::shared_ptr<TrackSearchLayout> trackSearch;
std::shared_ptr<cursespp::LayoutBase> visibleLayout;
};
}

View File

@ -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 <cursespp/Colors.h>
#include <cursespp/Screen.h>
#include <core/library/LocalLibraryConstants.h>
#include <app/query/NowPlayingTrackListQuery.h>
#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<TrackListQueryBase>(
// 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);
}

View File

@ -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 <cursespp/LayoutBase.h>
#include <cursespp/TextInput.h>
#include <app/window/TrackListView.h>
#include <app/service/PlaybackService.h>
#include <core/library/ILibrary.h>
#include <sigslot/sigslot.h>
namespace musik {
namespace box {
class TrackSearchLayout :
public cursespp::LayoutBase,
#if (__clang_major__ == 7 && __clang_minor__ == 3)
public std::enable_shared_from_this<TrackSearchLayout>,
#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<TrackListView> trackList;
std::shared_ptr<cursespp::TextInput> input;
};
}
}

View File

@ -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();
}

View File

@ -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 <core/library/track/LibraryTrack.h>
#include <core/library/LocalLibraryConstants.h>
#include <core/db/Statement.h>
#include <boost/algorithm/string/case_conv.hpp>
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<size_t>());
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<std::string>()(this->filter);
return this->hash;
}
bool SearchTrackListQuery::OnRun(Connection& db) {
if (result) {
result.reset(new TrackList(this->library));
headers.reset(new std::set<size_t>());
}
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;
}

View File

@ -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;
};
}
}