mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-14 18:40:48 +00:00
The directory browser is kind of basically working, but still has a couple hard-coded values and will need to be tweaked for Windows.
This commit is contained in:
parent
45c8aeb1c7
commit
1702b37d0a
@ -8,6 +8,7 @@ set (BOX_SRCS
|
|||||||
./app/layout/NowPlayingLayout.cpp
|
./app/layout/NowPlayingLayout.cpp
|
||||||
./app/layout/SearchLayout.cpp
|
./app/layout/SearchLayout.cpp
|
||||||
./app/layout/TrackSearchLayout.cpp
|
./app/layout/TrackSearchLayout.cpp
|
||||||
|
./app/model/DirectoryAdapter.cpp
|
||||||
./app/model/TrackList.cpp
|
./app/model/TrackList.cpp
|
||||||
./app/query/CategoryListViewQuery.cpp
|
./app/query/CategoryListViewQuery.cpp
|
||||||
./app/query/CategoryTrackListQuery.cpp
|
./app/query/CategoryTrackListQuery.cpp
|
||||||
|
@ -49,7 +49,14 @@ using namespace musik::box;
|
|||||||
using namespace cursespp;
|
using namespace cursespp;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
#define SEARCH_HEIGHT 3
|
#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())
|
||||||
|
|
||||||
|
typedef IScrollAdapter::EntryPtr EntryPtr;
|
||||||
|
|
||||||
IndexerLayout::IndexerLayout(musik::core::LibraryPtr library)
|
IndexerLayout::IndexerLayout(musik::core::LibraryPtr library)
|
||||||
: LayoutBase()
|
: LayoutBase()
|
||||||
@ -61,13 +68,6 @@ 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() {
|
void IndexerLayout::Layout() {
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
int cx = Screen::GetWidth(), cy = Screen::GetHeight();
|
int cx = Screen::GetWidth(), cy = Screen::GetHeight();
|
||||||
@ -91,8 +91,6 @@ void IndexerLayout::Layout() {
|
|||||||
this->addedPathsList->MoveAndResize(rightX, pathListsY, rightWidth, pathsHeight);
|
this->addedPathsList->MoveAndResize(rightX, pathListsY, rightWidth, pathsHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef IScrollAdapter::EntryPtr EntryPtr;
|
|
||||||
|
|
||||||
void IndexerLayout::RefreshAddedPaths() {
|
void IndexerLayout::RefreshAddedPaths() {
|
||||||
this->addedPathsAdapter.Clear();
|
this->addedPathsAdapter.Clear();
|
||||||
|
|
||||||
@ -105,20 +103,20 @@ void IndexerLayout::RefreshAddedPaths() {
|
|||||||
this->addedPathsAdapter.AddEntry(e);
|
this->addedPathsAdapter.AddEntry(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollAdapterBase::ItemDecorator decorator =
|
|
||||||
std::bind(&IndexerLayout::ListItemDecorator, this, _1, _2, _3);
|
|
||||||
|
|
||||||
this->addedPathsAdapter.SetItemDecorator(decorator);
|
|
||||||
this->addedPathsList->OnAdapterChanged();
|
this->addedPathsList->OnAdapterChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 IndexerLayout::ListItemDecorator(
|
int64 IndexerLayout::ListItemDecorator(
|
||||||
cursespp::ScrollableWindow* scrollable,
|
ScrollableWindow* scrollable,
|
||||||
size_t index,
|
size_t index,
|
||||||
cursespp::IScrollAdapter::EntryPtr entry)
|
size_t line,
|
||||||
|
IScrollAdapter::EntryPtr entry)
|
||||||
{
|
{
|
||||||
if (scrollable == this->addedPathsList.get()) {
|
if (scrollable == this->addedPathsList.get() ||
|
||||||
if (index == this->addedPathsList->GetSelectedIndex()) {
|
scrollable == this->browseList.get())
|
||||||
|
{
|
||||||
|
ListWindow* lw = static_cast<ListWindow*>(scrollable);
|
||||||
|
if (lw->GetSelectedIndex() == index) {
|
||||||
return COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN);
|
return COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,22 +135,26 @@ void IndexerLayout::InitializeWindows() {
|
|||||||
this->addedPathsLabel.reset(new TextLabel());
|
this->addedPathsLabel.reset(new TextLabel());
|
||||||
this->addedPathsLabel->SetText("indexed paths (DEL to remove)", TextLabel::AlignLeft);
|
this->addedPathsLabel->SetText("indexed paths (DEL to remove)", TextLabel::AlignLeft);
|
||||||
|
|
||||||
this->addedPathsList.reset(new cursespp::ListWindow(&this->addedPathsAdapter, nullptr));
|
this->addedPathsList.reset(new cursespp::ListWindow(&this->addedPathsAdapter));
|
||||||
this->addedPathsList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
this->addedPathsList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||||
this->browseList.reset(new cursespp::ListWindow(nullptr, nullptr));
|
this->browseList.reset(new cursespp::ListWindow(&this->browseAdapter));
|
||||||
this->browseList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
this->browseList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||||
|
|
||||||
this->addedPathsList->SetFocusOrder(0);
|
this->addedPathsList->SetFocusOrder(0);
|
||||||
this->browseList->SetFocusOrder(1);
|
this->browseList->SetFocusOrder(1);
|
||||||
|
|
||||||
|
ScrollAdapterBase::ItemDecorator decorator =
|
||||||
|
std::bind(&IndexerLayout::ListItemDecorator, this, _1, _2, _3, _4);
|
||||||
|
|
||||||
|
this->addedPathsAdapter.SetItemDecorator(decorator);
|
||||||
|
this->browseAdapter.SetItemDecorator(decorator);
|
||||||
|
|
||||||
this->AddWindow(this->title);
|
this->AddWindow(this->title);
|
||||||
this->AddWindow(this->browseLabel);
|
this->AddWindow(this->browseLabel);
|
||||||
this->AddWindow(this->addedPathsLabel);
|
this->AddWindow(this->addedPathsLabel);
|
||||||
this->AddWindow(this->browseList);
|
this->AddWindow(this->browseList);
|
||||||
this->AddWindow(this->addedPathsList);
|
this->AddWindow(this->addedPathsList);
|
||||||
|
|
||||||
this->RefreshAddedPaths();
|
|
||||||
|
|
||||||
this->Layout();
|
this->Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +162,7 @@ void IndexerLayout::OnVisibilityChanged(bool visible) {
|
|||||||
LayoutBase::OnVisibilityChanged(visible);
|
LayoutBase::OnVisibilityChanged(visible);
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
|
this->RefreshAddedPaths();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,9 +170,14 @@ void IndexerLayout::ProcessMessage(IMessage &message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IndexerLayout::KeyPress(const std::string& key) {
|
bool IndexerLayout::KeyPress(const std::string& key) {
|
||||||
if (key == "^M") { /* enter. play the selection */
|
if (key == "^M") {
|
||||||
|
if (this->GetFocus() == this->browseList) {
|
||||||
|
this->browseAdapter.Select(this->browseList->GetSelectedIndex());
|
||||||
|
this->browseList->SetSelectedIndex(0);
|
||||||
|
this->browseList->OnAdapterChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return LayoutBase::KeyPress(key);
|
return LayoutBase::KeyPress(key);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <app/window/TrackListView.h>
|
#include <app/window/TrackListView.h>
|
||||||
#include <app/service/PlaybackService.h>
|
#include <app/service/PlaybackService.h>
|
||||||
|
#include <app/model/DirectoryAdapter.h>
|
||||||
|
|
||||||
#include <core/library/ILibrary.h>
|
#include <core/library/ILibrary.h>
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ namespace musik {
|
|||||||
int64 ListItemDecorator(
|
int64 ListItemDecorator(
|
||||||
cursespp::ScrollableWindow* w,
|
cursespp::ScrollableWindow* w,
|
||||||
size_t index,
|
size_t index,
|
||||||
|
size_t line,
|
||||||
cursespp::IScrollAdapter::EntryPtr entry);
|
cursespp::IScrollAdapter::EntryPtr entry);
|
||||||
|
|
||||||
musik::core::LibraryPtr library;
|
musik::core::LibraryPtr library;
|
||||||
@ -85,6 +87,7 @@ namespace musik {
|
|||||||
std::shared_ptr<cursespp::ListWindow> addedPathsList;
|
std::shared_ptr<cursespp::ListWindow> addedPathsList;
|
||||||
|
|
||||||
cursespp::SimpleScrollAdapter addedPathsAdapter;
|
cursespp::SimpleScrollAdapter addedPathsAdapter;
|
||||||
|
DirectoryAdapter browseAdapter;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
102
src/musikbox/app/model/DirectoryAdapter.cpp
Executable file
102
src/musikbox/app/model/DirectoryAdapter.cpp
Executable file
@ -0,0 +1,102 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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/ScrollAdapterBase.h>
|
||||||
|
#include <cursespp/SingleLineEntry.h>
|
||||||
|
|
||||||
|
#include "DirectoryAdapter.h"
|
||||||
|
|
||||||
|
using namespace musik::box;
|
||||||
|
using namespace cursespp;
|
||||||
|
using namespace boost::filesystem;
|
||||||
|
|
||||||
|
void buildDirectoryList(const path& p, std::vector<std::string>& target)
|
||||||
|
{
|
||||||
|
target.clear();
|
||||||
|
|
||||||
|
try {
|
||||||
|
directory_iterator end;
|
||||||
|
directory_iterator file(p);
|
||||||
|
|
||||||
|
while (file != end) {
|
||||||
|
if (is_directory(file->status())) {
|
||||||
|
std::string leaf = file->path().leaf().string();
|
||||||
|
if (leaf[0] != '.') {
|
||||||
|
target.push_back(leaf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
/* todo: log */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectoryAdapter::DirectoryAdapter() {
|
||||||
|
this->dir = "/Users/clangen";
|
||||||
|
buildDirectoryList(this->dir, this->subdirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectoryAdapter::~DirectoryAdapter() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectoryAdapter::Select(size_t index) {
|
||||||
|
if (dir.has_parent_path() && index == 0) {
|
||||||
|
this->dir = this->dir.parent_path();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dir /= this->subdirs[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
buildDirectoryList(dir, subdirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t DirectoryAdapter::GetEntryCount() {
|
||||||
|
size_t count = subdirs.size();
|
||||||
|
return dir.has_parent_path() ? count + 1 : count;
|
||||||
|
}
|
||||||
|
|
||||||
|
IScrollAdapter::EntryPtr DirectoryAdapter::GetEntry(size_t index) {
|
||||||
|
if (dir.has_parent_path()) {
|
||||||
|
if (index == 0) {
|
||||||
|
return IScrollAdapter::EntryPtr(new SingleLineEntry(".."));
|
||||||
|
}
|
||||||
|
--index;
|
||||||
|
}
|
||||||
|
return IScrollAdapter::EntryPtr(new SingleLineEntry(this->subdirs[index]));
|
||||||
|
}
|
58
src/musikbox/app/model/DirectoryAdapter.h
Executable file
58
src/musikbox/app/model/DirectoryAdapter.h
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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/ScrollAdapterBase.h>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace musik {
|
||||||
|
namespace box {
|
||||||
|
class DirectoryAdapter : public cursespp::ScrollAdapterBase {
|
||||||
|
public:
|
||||||
|
DirectoryAdapter();
|
||||||
|
virtual ~DirectoryAdapter();
|
||||||
|
|
||||||
|
virtual size_t GetEntryCount();
|
||||||
|
virtual EntryPtr GetEntry(size_t index);
|
||||||
|
|
||||||
|
void Select(size_t index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
boost::filesystem::path dir;
|
||||||
|
std::vector<std::string> subdirs;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -143,7 +143,7 @@ void ScrollAdapterBase::DrawPage(ScrollableWindow* scrollable, size_t index, Scr
|
|||||||
int64 attrs = -1;
|
int64 attrs = -1;
|
||||||
|
|
||||||
if (this->decorator) {
|
if (this->decorator) {
|
||||||
attrs = this->decorator(scrollable, e, entry);
|
attrs = this->decorator(scrollable, topIndex + e, i, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attrs == -1) {
|
if (attrs == -1) {
|
||||||
|
@ -41,7 +41,11 @@
|
|||||||
namespace cursespp {
|
namespace cursespp {
|
||||||
class ScrollAdapterBase : public IScrollAdapter {
|
class ScrollAdapterBase : public IScrollAdapter {
|
||||||
public:
|
public:
|
||||||
typedef std::function<int64(ScrollableWindow*, size_t, EntryPtr)> ItemDecorator;
|
typedef std::function<int64(
|
||||||
|
ScrollableWindow*,
|
||||||
|
size_t,
|
||||||
|
size_t,
|
||||||
|
EntryPtr)> ItemDecorator;
|
||||||
|
|
||||||
ScrollAdapterBase();
|
ScrollAdapterBase();
|
||||||
virtual ~ScrollAdapterBase();
|
virtual ~ScrollAdapterBase();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user