mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 00:19:20 +00:00
Fixed some character encoding issues in file loading and track list
column rendering.
This commit is contained in:
parent
bb1bc9c822
commit
34e2ff1751
@ -81,7 +81,12 @@ bool LocalFileStream::Open(const char *filename, unsigned int options) {
|
||||
|
||||
this->filesize = (long)boost::filesystem::file_size(file);
|
||||
this->extension = file.extension().string();
|
||||
#ifdef WIN32
|
||||
std::wstring u16fn = u8to16(fn);
|
||||
this->file = _wfopen(u16fn.c_str(), L"rb");
|
||||
#else
|
||||
this->file = fopen(filename, "rb");
|
||||
#endif
|
||||
this->fd = new boost::iostreams::file_descriptor(file);
|
||||
this->fileStream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(*this->fd);
|
||||
this->fileStream->exceptions(std::ios_base::eofbit | std::ios_base::failbit | std::ios_base::badbit);
|
||||
@ -126,7 +131,7 @@ PositionType LocalFileStream::Read(void* buffer,PositionType readBytes) {
|
||||
}
|
||||
}
|
||||
|
||||
return this->fileStream->gcount();
|
||||
return (PositionType) this->fileStream->gcount();
|
||||
}
|
||||
|
||||
bool LocalFileStream::SetPosition(PositionType position) {
|
||||
@ -142,7 +147,7 @@ bool LocalFileStream::SetPosition(PositionType position) {
|
||||
}
|
||||
|
||||
PositionType LocalFileStream::Position() {
|
||||
return this->fileStream->tellg();
|
||||
return (PositionType) this->fileStream->tellg();
|
||||
}
|
||||
|
||||
bool LocalFileStream::Eof() {
|
||||
|
1
src/musikbox/app/playback/TrackListQueue.cpp
Executable file
1
src/musikbox/app/playback/TrackListQueue.cpp
Executable file
@ -0,0 +1 @@
|
||||
#include "stdafx.h"
|
3
src/musikbox/app/playback/TrackListQueue.h
Executable file
3
src/musikbox/app/playback/TrackListQueue.h
Executable file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
|
@ -7,14 +7,32 @@ namespace musik {
|
||||
namespace box {
|
||||
namespace text {
|
||||
void Truncate(std::string& str, size_t len) {
|
||||
if (str.size() > len) {
|
||||
str = str.substr(0, len);
|
||||
/* not a simple substr anymore, gotta deal with multi-byte
|
||||
characters... */
|
||||
if (u8len(str) > len) {
|
||||
std::string::iterator it = str.begin();
|
||||
std::string::iterator end = str.end();
|
||||
|
||||
size_t c = 0;
|
||||
while (c < len && it != str.end()) {
|
||||
try {
|
||||
utf8::next(it++, end);
|
||||
}
|
||||
catch (...) {
|
||||
it++; /* invalid encoding, just treat as a single char */
|
||||
}
|
||||
|
||||
++c;
|
||||
}
|
||||
|
||||
str = std::string(str.begin(), it);
|
||||
}
|
||||
}
|
||||
|
||||
void Ellipsize(std::string& str, size_t len) {
|
||||
if (str.size() > len) {
|
||||
str = str.substr(0, len - 2) + "..";
|
||||
if (u8len(str) > len) {
|
||||
Truncate(str, len - 2);
|
||||
str += "..";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,10 +92,17 @@ size_t TrackListView::Adapter::GetEntryCount() {
|
||||
return parent.metadata ? parent.metadata->size() : 0;
|
||||
}
|
||||
|
||||
#define TRACK_NUM_LENGTH 3
|
||||
#define ARTIST_LENGTH 14
|
||||
#define ALBUM_LENGTH 14
|
||||
#define DURATION_LENGTH 5 /* 00:00 */
|
||||
#define TRACK_COL_WIDTH 3
|
||||
#define ARTIST_COL_WIDTH 14
|
||||
#define ALBUM_COL_WIDTH 14
|
||||
#define DURATION_COL_WIDTH 5 /* 00:00 */
|
||||
|
||||
/* so this part is a bit tricky... we draw multiple columns, but we use
|
||||
standard std::setw() stuff, which is not aware of multi-byte characters.
|
||||
so we have to manually adjust the widths (i.e. we can't just use simple
|
||||
constants) */
|
||||
#define DISPLAY_WIDTH(chars, str) \
|
||||
chars + (str.size() - u8len(str))
|
||||
|
||||
IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
|
||||
int64 attrs = (index == parent.GetSelectedIndex()) ? COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN) : -1;
|
||||
@ -107,26 +114,34 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
|
||||
std::string title = track->GetValue(Track::TITLE);
|
||||
std::string duration = track->GetValue(Track::DURATION);
|
||||
|
||||
size_t titleCount =
|
||||
|
||||
int column0Width = DISPLAY_WIDTH(TRACK_COL_WIDTH, trackNum);
|
||||
int column2Width = DISPLAY_WIDTH(DURATION_COL_WIDTH, duration);
|
||||
int column3Width = DISPLAY_WIDTH(ARTIST_COL_WIDTH, artist);
|
||||
int column4Width = DISPLAY_WIDTH(ALBUM_COL_WIDTH, album);
|
||||
|
||||
size_t column1CharacterCount =
|
||||
this->GetWidth() -
|
||||
TRACK_NUM_LENGTH -
|
||||
ARTIST_LENGTH -
|
||||
ALBUM_LENGTH -
|
||||
DURATION_LENGTH -
|
||||
column0Width -
|
||||
column2Width -
|
||||
column3Width -
|
||||
column4Width -
|
||||
(3 * 4); /* 3 = spacing */
|
||||
|
||||
text::Ellipsize(artist, ARTIST_LENGTH);
|
||||
text::Ellipsize(album, ALBUM_LENGTH);
|
||||
text::Ellipsize(title, titleCount);
|
||||
int column1Width = DISPLAY_WIDTH(column1CharacterCount, title);
|
||||
|
||||
text::Ellipsize(artist, ARTIST_COL_WIDTH);
|
||||
text::Ellipsize(album, ALBUM_COL_WIDTH);
|
||||
text::Ellipsize(title, column1CharacterCount);
|
||||
duration = text::Duration(duration);
|
||||
|
||||
std::string text = boost::str(
|
||||
boost::format("%s %s %s %s %s")
|
||||
% group(setw(TRACK_NUM_LENGTH), setfill(' '), trackNum)
|
||||
% group(setw(titleCount), setiosflags(std::ios::left), setfill(' '), title)
|
||||
% group(setw(DURATION_LENGTH), setiosflags(std::ios::right), setfill(' '), duration)
|
||||
% group(setw(ARTIST_LENGTH), setiosflags(std::ios::left), setfill(' '), artist)
|
||||
% group(setw(ALBUM_LENGTH), setiosflags(std::ios::left), setfill(' '), album));
|
||||
% group(setw(column0Width), setfill(' '), trackNum)
|
||||
% group(setw(column1Width), setiosflags(std::ios::left), setfill(' '), title)
|
||||
% group(setw(column2Width), setiosflags(std::ios::right), setfill(' '), duration)
|
||||
% group(setw(column3Width), setiosflags(std::ios::left), setfill(' '), artist)
|
||||
% group(setw(column4Width), setiosflags(std::ios::left), setfill(' '), album));
|
||||
|
||||
IScrollAdapter::EntryPtr entry(new SingleLineEntry(text));
|
||||
|
||||
|
@ -117,6 +117,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="app\layout\LibraryLayout.cpp" />
|
||||
<ClCompile Include="app\layout\MainLayout.cpp" />
|
||||
<ClCompile Include="app\playback\TrackListQueue.cpp" />
|
||||
<ClCompile Include="app\query\CategoryListViewQuery.cpp" />
|
||||
<ClCompile Include="app\query\SingleTrackQuery.cpp" />
|
||||
<ClCompile Include="app\query\TrackListViewQuery.cpp" />
|
||||
@ -153,6 +154,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="app\layout\LibraryLayout.h" />
|
||||
<ClInclude Include="app\layout\MainLayout.h" />
|
||||
<ClInclude Include="app\playback\TrackListQueue.h" />
|
||||
<ClInclude Include="app\query\CategoryListViewQuery.h" />
|
||||
<ClInclude Include="app\query\SingleTrackQuery.h" />
|
||||
<ClInclude Include="app\query\TrackListViewQuery.h" />
|
||||
|
@ -90,6 +90,9 @@
|
||||
<ClCompile Include="cursespp\WindowLayout.cpp">
|
||||
<Filter>cursespp</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="app\playback\TrackListQueue.cpp">
|
||||
<Filter>app\playback</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
@ -216,6 +219,9 @@
|
||||
<ClInclude Include="cursespp\ILayoutStack.h">
|
||||
<Filter>cursespp</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="app\playback\TrackListQueue.h">
|
||||
<Filter>app\playback</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="cursespp">
|
||||
|
Loading…
Reference in New Issue
Block a user