Library and now playing switching seems to work?

This commit is contained in:
casey 2016-06-03 02:04:41 -07:00
parent 40bc4d31ad
commit c418305b30
10 changed files with 94 additions and 70 deletions

View File

@ -205,15 +205,15 @@ int main(int argc, char* argv[])
#endif
#endif
musik::debug::init();
PluginFactory::Instance(); /* initialize */
#ifdef __PDCURSES__
PDC_set_resize_limits(26, 38, 100, 150);
PDC_set_title("musikbox ♫");
PDC_set_function_key(FUNCTION_KEY_SHUT_DOWN, 4);
#endif
musik::debug::init();
PluginFactory::Instance(); /* initialize */
initscr();
nonl();
cbreak();

View File

@ -74,9 +74,12 @@ IWindowPtr BrowseLayout::GetFocus() {
return this->focused ? this->focused : LayoutBase::GetFocus();
}
void BrowseLayout::Show() {
LayoutBase::Show();
this->categoryList->Requery();
void BrowseLayout::OnVisibilityChanged(bool visible) {
LayoutBase::OnVisibilityChanged(visible);
if (visible) {
this->categoryList->Requery();
}
}
void BrowseLayout::RequeryTrackList(ListWindow *view) {

View File

@ -23,7 +23,7 @@ namespace musik {
virtual ~BrowseLayout();
virtual void Layout();
virtual void Show();
virtual void OnVisibilityChanged(bool visible);
virtual cursespp::IWindowPtr GetFocus();
virtual bool KeyPress(const std::string& key);

View File

@ -57,25 +57,30 @@ void LibraryLayout::Layout() {
this->ShowBrowse();
}
void LibraryLayout::ShowNowPlaying() {
if (this->focusedLayout != this->nowPlayingLayout) {
this->AddWindow(this->nowPlayingLayout);
this->RemoveWindow(this->browseLayout);
this->focusedLayout = this->nowPlayingLayout;
this->nowPlayingLayout->Layout();
this->nowPlayingLayout->Show();
this->BringToTop();
void LibraryLayout::ChangeMainLayout(std::shared_ptr<cursespp::LayoutBase> newLayout) {
if (this->visibleLayout != newLayout) {
if (this->visibleLayout) {
this->RemoveWindow(this->visibleLayout);
this->visibleLayout->Hide();
}
this->visibleLayout = newLayout;
this->AddWindow(this->visibleLayout);
this->visibleLayout->Layout();
this->visibleLayout->Show();
if (this->IsVisible()) {
this->BringToTop();
}
}
}
void LibraryLayout::ShowNowPlaying() {
this->ChangeMainLayout(this->nowPlayingLayout);
}
void LibraryLayout::ShowBrowse() {
if (this->focusedLayout != this->browseLayout) {
this->RemoveWindow(this->nowPlayingLayout);
this->AddWindow(this->browseLayout);
this->focusedLayout = this->browseLayout;
this->browseLayout->Layout();
this->BringToTop();
}
this->ChangeMainLayout(this->browseLayout);
}
void LibraryLayout::InitializeWindows() {
@ -88,33 +93,33 @@ void LibraryLayout::InitializeWindows() {
this->Layout();
}
void LibraryLayout::Show() {
LayoutBase::Show();
this->transportView->Update();
void LibraryLayout::OnVisibilityChanged(bool visible) {
LayoutBase::OnVisibilityChanged(visible);
if (visible) {
this->BringToTop();
}
}
IWindowPtr LibraryLayout::FocusNext() {
return this->focusedLayout->FocusNext();
return this->visibleLayout->FocusNext();
}
IWindowPtr LibraryLayout::FocusPrev() {
return this->focusedLayout->FocusPrev();
return this->visibleLayout->FocusPrev();
}
IWindowPtr LibraryLayout::GetFocus() {
return this->focusedLayout->GetFocus();
return this->visibleLayout->GetFocus();
}
bool LibraryLayout::KeyPress(const std::string& key) {
if (key == "^N") {
this->ShowNowPlaying();
return true;
if (key == "^[") { /* escape switches between browse/now playing */
(this->visibleLayout == this->nowPlayingLayout)
? this->ShowBrowse() : this->ShowNowPlaying();
}
else if (key == "^[") {
this->ShowBrowse();
return true;
}
else if (this->focusedLayout && this->focusedLayout->KeyPress(key)) {
/* forward to the visible layout */
else if (this->visibleLayout && this->visibleLayout->KeyPress(key)) {
return true;
}
else if (key == " ") {

View File

@ -29,13 +29,14 @@ namespace musik {
virtual cursespp::IWindowPtr FocusPrev();
virtual cursespp::IWindowPtr GetFocus();
virtual void Show();
virtual void OnVisibilityChanged(bool visible);
virtual bool KeyPress(const std::string& key);
private:
void InitializeWindows();
void ShowNowPlaying();
void ShowBrowse();
void ChangeMainLayout(std::shared_ptr<cursespp::LayoutBase> newLayout);
PlaybackService& playback;
musik::core::audio::Transport& transport;
@ -43,7 +44,7 @@ namespace musik {
std::shared_ptr<BrowseLayout> browseLayout;
std::shared_ptr<TransportWindow> transportView;
std::shared_ptr<NowPlayingLayout> nowPlayingLayout;
cursespp::ILayoutPtr focusedLayout;
std::shared_ptr<cursespp::LayoutBase> visibleLayout;
};
}
}

View File

@ -2,11 +2,8 @@
#include <cursespp/Colors.h>
#include <cursespp/Screen.h>
#include <core/library/LocalLibraryConstants.h>
#include <app/query/NowPlayingTrackListQuery.h>
#include "NowPlayingLayout.h"
using namespace musik::core::library::constants;
@ -54,9 +51,12 @@ IWindowPtr NowPlayingLayout::GetFocus() {
return this->trackList;
}
void NowPlayingLayout::Show() {
LayoutBase::Show();
this->RequeryTrackList();
void NowPlayingLayout::OnVisibilityChanged(bool visible) {
LayoutBase::OnVisibilityChanged(visible);
if (visible) {
this->RequeryTrackList();
}
}
void NowPlayingLayout::RequeryTrackList() {

View File

@ -23,7 +23,7 @@ namespace musik {
virtual ~NowPlayingLayout();
virtual void Layout();
virtual void Show();
virtual void OnVisibilityChanged(bool visible);
virtual cursespp::IWindowPtr GetFocus();
virtual bool KeyPress(const std::string& key);

View File

@ -125,8 +125,6 @@ bool LayoutBase::RemoveWindow(IWindowPtr window) {
}
}
RemoveFocusable(window);
return false;
}

View File

@ -183,6 +183,10 @@ void Window::OnSizeChanged() {
/* for subclass use */
}
void Window::OnVisibilityChanged(bool visible) {
/* for subclass use */
}
int Window::GetWidth() const {
return this->width;
}
@ -261,15 +265,18 @@ void Window::SetFocusOrder(int order) {
void Window::Show() {
if (this->framePanel) {
show_panel(this->framePanel);
if (!this->isVisible) {
show_panel(this->framePanel);
if (this->framePanel != this->contentPanel) {
show_panel(this->contentPanel);
if (this->framePanel != this->contentPanel) {
show_panel(this->contentPanel);
}
this->isVisible = true;
drawPending = true;
this->OnVisibilityChanged(true);
}
this->isVisible = true;
drawPending = true;
return;
}
else {
this->Create();
@ -284,17 +291,23 @@ void Window::Recreate() {
void Window::Create() {
/* if we have a parent, place the new window relative to the parent. */
this->frame = (this->parent == NULL)
? newwin(
this->height,
this->width,
this->y,
this->x)
: newwin(
this->height,
this->width,
this->parent->GetY() + this->y,
this->parent->GetX() + this->x);
this->frame = newwin(
this->height,
this->width,
this->y,
this->x);
//this->frame = (this->parent == NULL)
// ? newwin(
// this->height,
// this->width,
// this->y,
// this->x)
// : newwin(
// this->height,
// this->width,
// this->parent->GetY() + this->y,
// this->parent->GetX() + this->x);
this->framePanel = new_panel(this->frame);
@ -337,14 +350,17 @@ void Window::Create() {
void Window::Hide() {
if (this->frame) {
hide_panel(this->framePanel);
if (this->isVisible) {
hide_panel(this->framePanel);
if (this->content != this->frame) {
hide_panel(this->contentPanel);
if (this->content != this->frame) {
hide_panel(this->contentPanel);
}
this->isVisible = false;
this->OnVisibilityChanged(false);
}
}
this->isVisible = false;
}
void Window::Destroy() {

View File

@ -65,6 +65,7 @@ namespace cursespp {
virtual void OnPositionChanged();
virtual void OnSizeChanged();
virtual void OnVisibilityChanged(bool visible);
private:
IWindow* parent;