mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Added album separators in TrackListView, and cleaned up IScrollAdapter::IEntry interface in the process.
This commit is contained in:
parent
6793be3ae8
commit
c9630312ef
@ -20,6 +20,7 @@ TrackListViewQuery::TrackListViewQuery(LibraryPtr library, const std::string& co
|
||||
this->column = column;
|
||||
this->id = id;
|
||||
this->result.reset(new std::vector<TrackPtr>());
|
||||
this->headers.reset(new std::set<size_t>());
|
||||
}
|
||||
|
||||
TrackListViewQuery::~TrackListViewQuery() {
|
||||
@ -30,9 +31,14 @@ TrackListViewQuery::Result TrackListViewQuery::GetResult() {
|
||||
return this->result;
|
||||
}
|
||||
|
||||
TrackListViewQuery::Headers TrackListViewQuery::GetHeaders() {
|
||||
return this->headers;
|
||||
}
|
||||
|
||||
bool TrackListViewQuery::OnRun(Connection& db) {
|
||||
if (result) {
|
||||
result.reset(new std::vector<TrackPtr>());
|
||||
headers.reset(new std::set<size_t>());
|
||||
}
|
||||
|
||||
std::string query = boost::str(boost::format(
|
||||
@ -41,11 +47,20 @@ bool TrackListViewQuery::OnRun(Connection& db) {
|
||||
"WHERE t.%s=? AND t.album_id=al.id AND t.visual_genre_id=gn.id AND t.visual_artist_id=ar.id "
|
||||
"ORDER BY album, track, artist") % this->column);
|
||||
|
||||
std::string lastAlbum;
|
||||
size_t index = 0;
|
||||
|
||||
Statement trackQuery(query.c_str(), db);
|
||||
|
||||
trackQuery.BindInt(0, this->id);
|
||||
while (trackQuery.Step() == Row) {
|
||||
TrackPtr track = TrackPtr(new LibraryTrack(this->id, this->library));
|
||||
std::string album = trackQuery.ColumnText(8);
|
||||
|
||||
if (album != lastAlbum) {
|
||||
headers->insert(index);
|
||||
lastAlbum = album;
|
||||
}
|
||||
|
||||
track->SetValue(Track::TRACK_NUM, trackQuery.ColumnText(0));
|
||||
track->SetValue(Track::BPM, trackQuery.ColumnText(1));
|
||||
@ -55,12 +70,13 @@ bool TrackListViewQuery::OnRun(Connection& db) {
|
||||
track->SetValue(Track::TITLE, trackQuery.ColumnText(5));
|
||||
track->SetValue(Track::FILENAME, trackQuery.ColumnText(6));
|
||||
track->SetValue(Track::THUMBNAIL_ID, trackQuery.ColumnText(7));
|
||||
track->SetValue(Track::ALBUM_ID, trackQuery.ColumnText(8));
|
||||
track->SetValue(Track::ALBUM_ID, album.c_str());
|
||||
track->SetValue(Track::GENRE_ID, trackQuery.ColumnText(9));
|
||||
track->SetValue(Track::ARTIST_ID, trackQuery.ColumnText(10));
|
||||
track->SetValue(Track::FILETIME, trackQuery.ColumnText(11));
|
||||
|
||||
result->push_back(track);
|
||||
++index;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -12,6 +12,8 @@ namespace musik {
|
||||
typedef std::shared_ptr<
|
||||
std::vector<musik::core::TrackPtr> > Result;
|
||||
|
||||
typedef std::shared_ptr<std::set<size_t> > Headers;
|
||||
|
||||
TrackListViewQuery(
|
||||
musik::core::LibraryPtr library,
|
||||
const std::string& column, DBID id);
|
||||
@ -21,11 +23,13 @@ namespace musik {
|
||||
std::string Name() { return "TrackListViewQuery"; }
|
||||
|
||||
virtual Result GetResult();
|
||||
virtual Headers GetHeaders();
|
||||
|
||||
protected:
|
||||
virtual bool OnRun(musik::core::db::Connection &db);
|
||||
|
||||
Result result;
|
||||
Headers headers;
|
||||
|
||||
private:
|
||||
musik::core::LibraryPtr library;
|
||||
|
@ -100,7 +100,7 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(size_t index) {
|
||||
text::Ellipsize(value, this->GetWidth());
|
||||
|
||||
int64 attrs = (index == parent.GetSelectedIndex()) ? COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN) : -1;
|
||||
IScrollAdapter::EntryPtr entry(new SingleLineEntry(value));
|
||||
std::shared_ptr<SingleLineEntry> entry(new SingleLineEntry(value));
|
||||
entry->SetAttrs(attrs);
|
||||
return entry;
|
||||
}
|
||||
|
44
src/musikbox/app/window/EntryWithHeader.cpp
Executable file
44
src/musikbox/app/window/EntryWithHeader.cpp
Executable file
@ -0,0 +1,44 @@
|
||||
#include <stdafx.h>
|
||||
#include "EntryWithHeader.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <app/util/Text.h>
|
||||
|
||||
using namespace musik::box;
|
||||
|
||||
EntryWithHeader::EntryWithHeader(
|
||||
const std::string& header, const std::string& value)
|
||||
{
|
||||
this->header = header;
|
||||
this->value = value;
|
||||
this->attrs = -1;
|
||||
}
|
||||
|
||||
void EntryWithHeader::SetWidth(size_t width) {
|
||||
this->width = width;
|
||||
}
|
||||
|
||||
int64 EntryWithHeader::GetAttrs(size_t line) {
|
||||
return (line == 0) ? this->headerAttrs : this->attrs;
|
||||
}
|
||||
|
||||
void EntryWithHeader::SetAttrs(int64 headerAttrs, int64 attrs) {
|
||||
this->headerAttrs = headerAttrs;
|
||||
this->attrs = attrs;
|
||||
}
|
||||
|
||||
size_t EntryWithHeader::GetLineCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
#define TRUNCATE(value, width) \
|
||||
u8substr(value, 0, width > 0 ? width : 0)
|
||||
|
||||
std::string EntryWithHeader::GetLine(size_t line) {
|
||||
if (line == 0) {
|
||||
std::string ellipsized = this->header;
|
||||
musik::box::text::Ellipsize(ellipsized, this->width);
|
||||
return ellipsized;
|
||||
}
|
||||
|
||||
return TRUNCATE(this->value, this->width);
|
||||
}
|
25
src/musikbox/app/window/EntryWithHeader.h
Executable file
25
src/musikbox/app/window/EntryWithHeader.h
Executable file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <cursespp/IScrollAdapter.h>
|
||||
|
||||
namespace musik {
|
||||
namespace box {
|
||||
class EntryWithHeader : public cursespp::IScrollAdapter::IEntry {
|
||||
public:
|
||||
EntryWithHeader(const std::string& header, const std::string& value);
|
||||
virtual ~EntryWithHeader() { }
|
||||
|
||||
virtual void SetWidth(size_t width);
|
||||
virtual int64 GetAttrs(size_t line);
|
||||
virtual size_t GetLineCount();
|
||||
virtual std::string GetLine(size_t line);
|
||||
|
||||
void SetAttrs(int64 headerAttrs, int64 attrs);
|
||||
|
||||
private:
|
||||
size_t width;
|
||||
std::string header, value;
|
||||
int64 headerAttrs, attrs;
|
||||
};
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
#include <core/library/LocalLibraryConstants.h>
|
||||
|
||||
#include <app/util/Text.h>
|
||||
#include <app/window/EntryWithHeader.h>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/format/group.hpp>
|
||||
@ -68,6 +69,7 @@ void TrackListView::ProcessMessage(IMessage &message) {
|
||||
if (message.Type() == WINDOW_MESSAGE_QUERY_COMPLETED) {
|
||||
if (this->query && this->query->GetStatus() == IQuery::Finished) {
|
||||
this->metadata = this->query->GetResult();
|
||||
this->headers = this->query->GetHeaders();
|
||||
this->query.reset();
|
||||
this->SetSelectedIndex(0);
|
||||
this->OnAdapterChanged();
|
||||
@ -137,9 +139,15 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
|
||||
% group(setw(column3Width), setiosflags(std::ios::left), setfill(' '), artist)
|
||||
% group(setw(column4Width), setiosflags(std::ios::left), setfill(' '), album));
|
||||
|
||||
IScrollAdapter::EntryPtr entry(new SingleLineEntry(text));
|
||||
|
||||
entry->SetAttrs(attrs);
|
||||
|
||||
if (this->parent.headers->find(index) != this->parent.headers->end()) {
|
||||
std::string album = track->GetValue(constants::Track::ALBUM_ID);
|
||||
std::shared_ptr<EntryWithHeader> entry(new EntryWithHeader(album, text));
|
||||
entry->SetAttrs(COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK), attrs);
|
||||
return entry;
|
||||
}
|
||||
else {
|
||||
std::shared_ptr<SingleLineEntry> entry(new SingleLineEntry(text));
|
||||
entry->SetAttrs(attrs);
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ namespace musik {
|
||||
private:
|
||||
std::shared_ptr<TrackListViewQuery> query;
|
||||
std::shared_ptr<std::vector<TrackPtr> > metadata;
|
||||
std::shared_ptr<std::set<size_t> > headers;
|
||||
Adapter* adapter;
|
||||
PlaybackService& playback;
|
||||
musik::core::LibraryPtr library;
|
||||
|
@ -28,10 +28,8 @@ namespace cursespp {
|
||||
virtual ~IEntry() { }
|
||||
virtual size_t GetLineCount() = 0;
|
||||
virtual std::string GetLine(size_t line) = 0;
|
||||
virtual std::string GetValue() = 0;
|
||||
virtual void SetWidth(size_t width) = 0;
|
||||
virtual void SetAttrs(int64 attrs) = 0;
|
||||
virtual int64 GetAttrs() = 0;
|
||||
virtual int64 GetAttrs(size_t line) = 0;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<IEntry> EntryPtr;
|
||||
|
@ -21,26 +21,10 @@ std::string MultiLineEntry::GetLine(size_t n) {
|
||||
return this->lines.at(n);
|
||||
}
|
||||
|
||||
std::string MultiLineEntry::GetValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
size_t MultiLineEntry::GetIndex() {
|
||||
return this->index;
|
||||
}
|
||||
|
||||
void MultiLineEntry::SetIndex(size_t index) {
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
int64 MultiLineEntry::GetAttrs() {
|
||||
int64 MultiLineEntry::GetAttrs(size_t line) {
|
||||
return this->attrs;
|
||||
}
|
||||
|
||||
void MultiLineEntry::SetAttrs(int64 attrs) {
|
||||
this->attrs = attrs;
|
||||
}
|
||||
|
||||
inline static void breakIntoSubLines(
|
||||
std::string& line,
|
||||
size_t width,
|
||||
|
@ -6,18 +6,16 @@ namespace cursespp {
|
||||
class MultiLineEntry : public IScrollAdapter::IEntry {
|
||||
public:
|
||||
MultiLineEntry(const std::string& value, int64 attrs = -1);
|
||||
virtual ~MultiLineEntry() { }
|
||||
|
||||
virtual size_t GetLineCount();
|
||||
virtual std::string GetLine(size_t line);
|
||||
virtual void SetWidth(size_t width);
|
||||
virtual int64 GetAttrs(size_t line);
|
||||
|
||||
size_t GetIndex();
|
||||
void SetIndex(size_t index);
|
||||
size_t GetLineCount();
|
||||
std::string GetLine(size_t line);
|
||||
std::string GetValue();
|
||||
void SetWidth(size_t width);
|
||||
void SetAttrs(int64 attrs);
|
||||
int64 GetAttrs();
|
||||
|
||||
private:
|
||||
size_t index;
|
||||
std::string value;
|
||||
std::vector<std::string> lines;
|
||||
size_t charCount;
|
||||
|
@ -101,13 +101,14 @@ void ScrollAdapterBase::DrawPage(WINDOW* window, size_t index, ScrollPosition *r
|
||||
for (size_t e = 0; e < visible.size(); e++) {
|
||||
EntryPtr entry = visible.at(e);
|
||||
size_t count = entry->GetLineCount();
|
||||
int64 attrs = entry->GetAttrs();
|
||||
|
||||
for (size_t i = 0; i < count && drawnLines < this->height; i++) {
|
||||
int64 attrs = entry->GetAttrs(i);
|
||||
|
||||
if (attrs != -1) {
|
||||
wattron(window, attrs);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count && drawnLines < this->height; i++) {
|
||||
std::string line = entry->GetLine(i);
|
||||
size_t len = u8len(line);
|
||||
|
||||
@ -123,12 +124,12 @@ void ScrollAdapterBase::DrawPage(WINDOW* window, size_t index, ScrollPosition *r
|
||||
|
||||
wprintw(window, "%s", line.c_str());
|
||||
|
||||
++drawnLines;
|
||||
}
|
||||
|
||||
if (attrs != -1) {
|
||||
wattroff(window, attrs);
|
||||
}
|
||||
|
||||
++drawnLines;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != NULL) {
|
||||
|
@ -9,19 +9,11 @@ SingleLineEntry::SingleLineEntry(const std::string& value) {
|
||||
this->attrs = -1;
|
||||
}
|
||||
|
||||
size_t SingleLineEntry::GetIndex() {
|
||||
return this->index;
|
||||
}
|
||||
|
||||
void SingleLineEntry::SetWidth(size_t width) {
|
||||
this->width = width;
|
||||
}
|
||||
|
||||
void SingleLineEntry::SetIndex(size_t index) {
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
int64 SingleLineEntry::GetAttrs() {
|
||||
int64 SingleLineEntry::GetAttrs(size_t line) {
|
||||
return this->attrs;
|
||||
}
|
||||
|
||||
@ -36,7 +28,3 @@ size_t SingleLineEntry::GetLineCount() {
|
||||
std::string SingleLineEntry::GetLine(size_t line) {
|
||||
return u8substr(this->value, 0, this->width > 0 ? this->width : 0);
|
||||
}
|
||||
|
||||
std::string SingleLineEntry::GetValue() {
|
||||
return this->value;
|
||||
}
|
@ -6,19 +6,17 @@ namespace cursespp {
|
||||
class SingleLineEntry : public IScrollAdapter::IEntry {
|
||||
public:
|
||||
SingleLineEntry(const std::string& value);
|
||||
virtual ~SingleLineEntry() { }
|
||||
|
||||
virtual void SetWidth(size_t width);
|
||||
virtual int64 GetAttrs(size_t line);
|
||||
virtual size_t GetLineCount();
|
||||
virtual std::string GetLine(size_t line);
|
||||
|
||||
size_t GetIndex();
|
||||
void SetIndex(size_t index);
|
||||
void SetWidth(size_t width);
|
||||
void SetAttrs(int64 attrs);
|
||||
int64 GetAttrs();
|
||||
|
||||
size_t GetLineCount();
|
||||
std::string GetLine(size_t line);
|
||||
std::string GetValue();
|
||||
|
||||
private:
|
||||
size_t index, width;
|
||||
size_t width;
|
||||
std::string value;
|
||||
int64 attrs;
|
||||
};
|
||||
|
@ -60,7 +60,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>./;../;../3rdparty/include;../3rdparty/win32_include;../../../boost_1_60_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -89,7 +89,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>./;../;../3rdparty/include;../3rdparty/win32_include;../../../boost_1_60_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@ -126,6 +126,7 @@
|
||||
<ClCompile Include="app\util\Text.cpp" />
|
||||
<ClCompile Include="app\window\CategoryListView.cpp" />
|
||||
<ClCompile Include="app\window\CommandWindow.cpp" />
|
||||
<ClCompile Include="app\window\EntryWithHeader.cpp" />
|
||||
<ClCompile Include="app\window\LogWindow.cpp" />
|
||||
<ClCompile Include="app\window\OutputWindow.cpp" />
|
||||
<ClCompile Include="app\window\ResourcesWindow.cpp" />
|
||||
@ -163,6 +164,7 @@
|
||||
<ClInclude Include="app\util\Text.h" />
|
||||
<ClInclude Include="app\window\CategoryListView.h" />
|
||||
<ClInclude Include="app\window\CommandWindow.h" />
|
||||
<ClInclude Include="app\window\EntryWithHeader.h" />
|
||||
<ClInclude Include="app\window\LogWindow.h" />
|
||||
<ClInclude Include="app\window\OutputWindow.h" />
|
||||
<ClInclude Include="app\window\ResourcesWindow.h" />
|
||||
|
@ -93,6 +93,9 @@
|
||||
<ClCompile Include="cursespp\Colors.cpp">
|
||||
<Filter>app</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="app\window\EntryWithHeader.cpp">
|
||||
<Filter>app\window</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
@ -225,6 +228,9 @@
|
||||
<ClInclude Include="cursespp\IMessageTarget.h">
|
||||
<Filter>cursespp</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="app\window\EntryWithHeader.h">
|
||||
<Filter>app\window</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="cursespp">
|
||||
|
Loading…
Reference in New Issue
Block a user