mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-11 09:40:26 +00:00
very beginnings of the IndexerLayout where users can configure paths.
This commit is contained in:
parent
b5a4f5ff3d
commit
e1086b9847
@ -43,6 +43,7 @@
|
||||
|
||||
#include <app/layout/ConsoleLayout.h>
|
||||
#include <app/layout/LibraryLayout.h>
|
||||
#include <app/layout/IndexerLayout.h>
|
||||
#include <app/util/GlobalHotkeys.h>
|
||||
#include <app/service/PlaybackService.h>
|
||||
|
||||
@ -259,6 +260,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
ILayoutPtr libraryLayout((ILayout *) new LibraryLayout(playback, library));
|
||||
ILayoutPtr consoleLayout((ILayout *) new ConsoleLayout(transport, library));
|
||||
ILayoutPtr indexerLayout((ILayout *) new IndexerLayout(library));
|
||||
|
||||
int64 ch;
|
||||
timeout(IDLE_TIMEOUT_MS);
|
||||
@ -313,6 +315,9 @@ int main(int argc, char* argv[])
|
||||
else if (ch == KEY_F(2) || kn == "M-w") {
|
||||
changeLayout(state, libraryLayout);
|
||||
}
|
||||
else if (kn == "M-s") {
|
||||
changeLayout(state, indexerLayout);
|
||||
}
|
||||
else if (!globalHotkeys.Handle(kn)) {
|
||||
bool processed = false;
|
||||
if (state.input) {
|
||||
@ -337,6 +342,7 @@ int main(int argc, char* argv[])
|
||||
resize_term(0, 0);
|
||||
libraryLayout->Layout();
|
||||
consoleLayout->Layout();
|
||||
indexerLayout->Layout();
|
||||
state.layout->BringToTop();
|
||||
resizeAt = 0;
|
||||
}
|
||||
|
160
src/musikbox/app/layout/IndexerLayout.cpp
Executable file
160
src/musikbox/app/layout/IndexerLayout.cpp
Executable file
@ -0,0 +1,160 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <cursespp/SingleLineEntry.h>
|
||||
|
||||
#include <core/library/LocalLibraryConstants.h>
|
||||
#include <app/query/SearchTrackListQuery.h>
|
||||
|
||||
#include "IndexerLayout.h"
|
||||
|
||||
using namespace musik::core::library::constants;
|
||||
|
||||
using namespace musik::core;
|
||||
using namespace musik::box;
|
||||
using namespace cursespp;
|
||||
|
||||
#define SEARCH_HEIGHT 3
|
||||
|
||||
IndexerLayout::IndexerLayout(
|
||||
musik::core::LibraryPtr library)
|
||||
: LayoutBase()
|
||||
, library(library) {
|
||||
this->InitializeWindows();
|
||||
}
|
||||
|
||||
IndexerLayout::~IndexerLayout() {
|
||||
|
||||
}
|
||||
|
||||
#define LABEL_HEIGHT 1
|
||||
|
||||
#define TOP(w) w->GetY()
|
||||
#define BOTTOM(w) (w->GetY() + w->GetHeight())
|
||||
#define LEFT(w) w->GetX()
|
||||
#define RIGHT (x) (x->GetX() + w->GetWidth())
|
||||
|
||||
void IndexerLayout::Layout() {
|
||||
int x = 0, y = 0;
|
||||
int cx = Screen::GetWidth(), cy = Screen::GetHeight();
|
||||
this->SetFrameVisible(false);
|
||||
this->MoveAndResize(x, y, cx, cy);
|
||||
|
||||
this->title->MoveAndResize(0, 0, cx, LABEL_HEIGHT);
|
||||
|
||||
int startY = BOTTOM(this->title) + 1;
|
||||
int pathsHeight = cy / 3;
|
||||
int leftX = 0;
|
||||
int leftWidth = cx / 3; /* 1/3 width */
|
||||
int rightX = leftWidth;
|
||||
int rightWidth = cx - rightX; /* remainder (~2/3) */
|
||||
|
||||
this->browseLabel->MoveAndResize(leftX, startY, leftWidth, LABEL_HEIGHT);
|
||||
this->addedPathsLabel->MoveAndResize(rightX, startY, rightWidth, LABEL_HEIGHT);
|
||||
|
||||
int pathListsY = BOTTOM(this->browseLabel);
|
||||
this->browseList->MoveAndResize(leftX, pathListsY, leftWidth, pathsHeight);
|
||||
this->addedPathsList->MoveAndResize(rightX, pathListsY, rightWidth, pathsHeight);
|
||||
}
|
||||
|
||||
typedef IScrollAdapter::EntryPtr EntryPtr;
|
||||
|
||||
void IndexerLayout::RefreshAddedPaths() {
|
||||
this->addedPathsAdapter.Clear();
|
||||
|
||||
std::vector<std::string> paths;
|
||||
this->library->Indexer()->GetPaths(paths);
|
||||
|
||||
for (size_t i = 0; i < paths.size(); i++) {
|
||||
auto v = paths.at(i);
|
||||
auto e = EntryPtr(new SingleLineEntry(v));
|
||||
this->addedPathsAdapter.AddEntry(e);
|
||||
}
|
||||
|
||||
this->addedPathsList->OnAdapterChanged();
|
||||
}
|
||||
|
||||
void IndexerLayout::InitializeWindows() {
|
||||
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||
|
||||
this->title.reset(new TextLabel());
|
||||
this->title->SetText("settings", TextLabel::AlignCenter);
|
||||
|
||||
this->browseLabel.reset(new TextLabel());
|
||||
this->browseLabel->SetText("browse filesystem", TextLabel::AlignLeft);
|
||||
|
||||
this->addedPathsLabel.reset(new TextLabel());
|
||||
this->addedPathsLabel->SetText("indexed paths", TextLabel::AlignLeft);
|
||||
|
||||
this->addedPathsList.reset(new cursespp::ListWindow(&this->addedPathsAdapter, nullptr));
|
||||
this->addedPathsList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||
this->browseList.reset(new cursespp::ListWindow(nullptr, nullptr));
|
||||
this->browseList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||
|
||||
this->addedPathsList->SetFocusOrder(0);
|
||||
this->browseList->SetFocusOrder(1);
|
||||
|
||||
this->AddWindow(this->title);
|
||||
this->AddWindow(this->browseLabel);
|
||||
this->AddWindow(this->addedPathsLabel);
|
||||
this->AddWindow(this->browseList);
|
||||
this->AddWindow(this->addedPathsList);
|
||||
|
||||
this->RefreshAddedPaths();
|
||||
|
||||
this->Layout();
|
||||
}
|
||||
|
||||
void IndexerLayout::OnVisibilityChanged(bool visible) {
|
||||
LayoutBase::OnVisibilityChanged(visible);
|
||||
|
||||
if (visible) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void IndexerLayout::ProcessMessage(IMessage &message) {
|
||||
}
|
||||
|
||||
bool IndexerLayout::KeyPress(const std::string& key) {
|
||||
if (key == "^M") { /* enter. play the selection */
|
||||
return true;
|
||||
}
|
||||
|
||||
return LayoutBase::KeyPress(key);
|
||||
}
|
86
src/musikbox/app/layout/IndexerLayout.h
Executable file
86
src/musikbox/app/layout/IndexerLayout.h
Executable file
@ -0,0 +1,86 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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/ListWindow.h>
|
||||
#include <cursespp/TextLabel.h>
|
||||
#include <cursespp/SimpleScrollAdapter.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 IndexerLayout :
|
||||
public cursespp::LayoutBase,
|
||||
#if (__clang_major__ == 7 && __clang_minor__ == 3)
|
||||
public std::enable_shared_from_this<IndexerLayout>,
|
||||
#endif
|
||||
public sigslot::has_slots<>
|
||||
{
|
||||
public:
|
||||
IndexerLayout(
|
||||
musik::core::LibraryPtr library);
|
||||
|
||||
virtual ~IndexerLayout();
|
||||
|
||||
virtual void Layout();
|
||||
virtual void OnVisibilityChanged(bool visible);
|
||||
virtual bool KeyPress(const std::string& key);
|
||||
|
||||
protected:
|
||||
virtual void ProcessMessage(cursespp::IMessage &message);
|
||||
|
||||
private:
|
||||
void InitializeWindows();
|
||||
void RefreshAddedPaths();
|
||||
|
||||
musik::core::LibraryPtr library;
|
||||
|
||||
std::shared_ptr<cursespp::TextLabel> title;
|
||||
std::shared_ptr<cursespp::TextLabel> browseLabel;
|
||||
std::shared_ptr<cursespp::TextLabel> addedPathsLabel;
|
||||
std::shared_ptr<cursespp::ListWindow> browseList;
|
||||
std::shared_ptr<cursespp::ListWindow> addedPathsList;
|
||||
|
||||
cursespp::SimpleScrollAdapter addedPathsAdapter;
|
||||
};
|
||||
}
|
||||
}
|
@ -42,9 +42,20 @@ typedef IScrollAdapter::ScrollPosition ScrollPos;
|
||||
|
||||
size_t ListWindow::NO_SELECTION = (size_t) -1;
|
||||
|
||||
ListWindow::ListWindow(IWindow *parent)
|
||||
: ScrollableWindow(parent) {
|
||||
this->selectedIndex = (size_t) -1;
|
||||
class EmptyAdapter : public IScrollAdapter {
|
||||
public:
|
||||
virtual void SetDisplaySize(size_t width, size_t height) { }
|
||||
virtual size_t GetEntryCount() { return 0; }
|
||||
virtual EntryPtr GetEntry(size_t index) { return IScrollAdapter::EntryPtr(); }
|
||||
virtual void DrawPage(WINDOW* window, size_t index, ScrollPosition *result = NULL) { }
|
||||
};
|
||||
|
||||
static EmptyAdapter emptyAdapter;
|
||||
|
||||
ListWindow::ListWindow(IScrollAdapter* adapter, IWindow *parent)
|
||||
: ScrollableWindow(parent)
|
||||
, adapter(adapter) {
|
||||
|
||||
}
|
||||
|
||||
ListWindow::~ListWindow() {
|
||||
@ -56,6 +67,14 @@ void ListWindow::ScrollToTop() {
|
||||
this->ScrollTo(0);
|
||||
}
|
||||
|
||||
IScrollAdapter& ListWindow::GetScrollAdapter() {
|
||||
if (this->adapter) {
|
||||
return *this->adapter;
|
||||
}
|
||||
|
||||
return emptyAdapter;
|
||||
}
|
||||
|
||||
void ListWindow::ScrollToBottom() {
|
||||
IScrollAdapter& adapter = this->GetScrollAdapter();
|
||||
this->SetSelectedIndex(std::max((size_t) 0, adapter.GetEntryCount() - 1));
|
||||
|
@ -47,7 +47,7 @@ namespace cursespp {
|
||||
sigslot::signal3<ListWindow*, size_t, size_t> SelectionChanged;
|
||||
sigslot::signal2<ListWindow*, size_t> Invalidated;
|
||||
|
||||
ListWindow(IWindow *parent = NULL);
|
||||
ListWindow(IScrollAdapter* adapter = nullptr, IWindow *parent = nullptr);
|
||||
virtual ~ListWindow();
|
||||
|
||||
virtual void ScrollToTop();
|
||||
@ -61,15 +61,18 @@ namespace cursespp {
|
||||
virtual size_t GetSelectedIndex();
|
||||
virtual void SetSelectedIndex(size_t index);
|
||||
|
||||
protected:
|
||||
virtual void OnAdapterChanged();
|
||||
|
||||
protected:
|
||||
virtual void OnSelectionChanged(size_t newIndex, size_t oldIndex);
|
||||
virtual void OnInvalidated();
|
||||
virtual void OnSizeChanged();
|
||||
|
||||
virtual IScrollAdapter& GetScrollAdapter();
|
||||
virtual IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||
|
||||
private:
|
||||
IScrollAdapter* adapter;
|
||||
IScrollAdapter::ScrollPosition scrollPosition;
|
||||
size_t selectedIndex;
|
||||
};
|
||||
|
@ -61,10 +61,11 @@ namespace cursespp {
|
||||
virtual void Focus();
|
||||
virtual void Blur();
|
||||
|
||||
virtual void OnAdapterChanged();
|
||||
|
||||
protected:
|
||||
virtual IScrollAdapter& GetScrollAdapter() = 0;
|
||||
virtual IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||
virtual void OnAdapterChanged();
|
||||
|
||||
size_t GetPreviousPageEntryIndex();
|
||||
bool IsLastItemVisible();
|
||||
|
@ -116,6 +116,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="app\layout\BrowseLayout.cpp" />
|
||||
<ClCompile Include="app\layout\IndexerLayout.cpp" />
|
||||
<ClCompile Include="app\layout\LibraryLayout.cpp" />
|
||||
<ClCompile Include="app\layout\ConsoleLayout.cpp" />
|
||||
<ClCompile Include="app\layout\NowPlayingLayout.cpp" />
|
||||
@ -163,6 +164,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="app\layout\BrowseLayout.h" />
|
||||
<ClInclude Include="app\layout\IndexerLayout.h" />
|
||||
<ClInclude Include="app\layout\LibraryLayout.h" />
|
||||
<ClInclude Include="app\layout\ConsoleLayout.h" />
|
||||
<ClInclude Include="app\layout\NowPlayingLayout.h" />
|
||||
|
@ -123,6 +123,9 @@
|
||||
<ClCompile Include="app\query\SearchTrackListQuery.cpp">
|
||||
<Filter>app\query</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="app\layout\IndexerLayout.cpp">
|
||||
<Filter>app\layout</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
@ -288,6 +291,9 @@
|
||||
<ClInclude Include="app\query\SearchTrackListQuery.h">
|
||||
<Filter>app\query</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="app\layout\IndexerLayout.h">
|
||||
<Filter>app\layout</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="cursespp">
|
||||
|
Loading…
x
Reference in New Issue
Block a user