mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-24 03:40:03 +00:00
Ensure playlist browse uses sequential track numbers, instead of track
numbers from metadata.
This commit is contained in:
parent
4fd9d358a5
commit
5df2881a46
@ -245,6 +245,9 @@ void BrowseLayout::OnCategoryViewInvalidated(
|
|||||||
void BrowseLayout::SwitchCategory(const std::string& fieldName) {
|
void BrowseLayout::SwitchCategory(const std::string& fieldName) {
|
||||||
this->categoryList->SetFieldName(fieldName);
|
this->categoryList->SetFieldName(fieldName);
|
||||||
this->categoryList->SetFrameTitle(getTitleForCategory(fieldName));
|
this->categoryList->SetFrameTitle(getTitleForCategory(fieldName));
|
||||||
|
|
||||||
|
this->trackList->SetTrackNumType(fieldName == constants::Playlists::TABLE_NAME
|
||||||
|
? TrackListView::TrackNumType::Sequential : TrackListView::TrackNumType::Metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BrowseLayout::KeyPress(const std::string& key) {
|
bool BrowseLayout::KeyPress(const std::string& key) {
|
||||||
|
@ -88,6 +88,7 @@ TrackListView::TrackListView(
|
|||||||
this->lastChanged = now();
|
this->lastChanged = now();
|
||||||
this->formatter = formatter;
|
this->formatter = formatter;
|
||||||
this->decorator = decorator;
|
this->decorator = decorator;
|
||||||
|
this->trackNumType = TrackNumType::Metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackListView::~TrackListView() {
|
TrackListView::~TrackListView() {
|
||||||
@ -104,6 +105,13 @@ void TrackListView::SelectFirstTrack() {
|
|||||||
this->SetSelectedIndex(this->headers.HeaderAt(0) ? 1 : 0);
|
this->SetSelectedIndex(this->headers.HeaderAt(0) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackListView::SetTrackNumType(TrackNumType type) {
|
||||||
|
if (this->trackNumType != type) {
|
||||||
|
this->trackNumType = type;
|
||||||
|
this->OnAdapterChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TrackListView::OnQueryCompleted(IQuery* query) {
|
void TrackListView::OnQueryCompleted(IQuery* query) {
|
||||||
if (this->query && query == this->query.get()) {
|
if (this->query && query == this->query.get()) {
|
||||||
if (this->query->GetStatus() == IQuery::Finished) {
|
if (this->query->GetStatus() == IQuery::Finished) {
|
||||||
@ -339,12 +347,24 @@ size_t TrackListView::Adapter::GetEntryCount() {
|
|||||||
#define TRACK_COL_WIDTH 3
|
#define TRACK_COL_WIDTH 3
|
||||||
#define ARTIST_COL_WIDTH 17
|
#define ARTIST_COL_WIDTH 17
|
||||||
#define DURATION_COL_WIDTH 5 /* 00:00 */
|
#define DURATION_COL_WIDTH 5 /* 00:00 */
|
||||||
|
#define DIGITS(x) (x > 9 ? (int) log10((double) x) + 1 : 1)
|
||||||
|
|
||||||
static std::string formatWithoutAlbum(TrackPtr track, size_t width) {
|
using TrackNumType = TrackListView::TrackNumType;
|
||||||
std::string trackNum = text::Align(
|
|
||||||
track->GetString(constants::Track::TRACK_NUM),
|
static std::string formatWithoutAlbum(TrackPtr track, size_t index, size_t width, TrackNumType type) {
|
||||||
text::AlignRight,
|
std::string trackNum;
|
||||||
TRACK_COL_WIDTH);
|
|
||||||
|
int trackColWidth = TRACK_COL_WIDTH;
|
||||||
|
if (type == TrackNumType::Metadata) {
|
||||||
|
trackNum = text::Align(
|
||||||
|
track->GetString(constants::Track::TRACK_NUM),
|
||||||
|
text::AlignRight,
|
||||||
|
TRACK_COL_WIDTH);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
trackColWidth = std::max(TRACK_COL_WIDTH, DIGITS(index + 1));
|
||||||
|
trackNum = text::Align(std::to_string(index + 1), text::AlignRight, trackColWidth);
|
||||||
|
}
|
||||||
|
|
||||||
std::string duration = text::Align(
|
std::string duration = text::Align(
|
||||||
musik::core::duration::Duration(track->GetString(constants::Track::DURATION)),
|
musik::core::duration::Duration(track->GetString(constants::Track::DURATION)),
|
||||||
@ -358,7 +378,7 @@ static std::string formatWithoutAlbum(TrackPtr track, size_t width) {
|
|||||||
|
|
||||||
int titleWidth =
|
int titleWidth =
|
||||||
width -
|
width -
|
||||||
TRACK_COL_WIDTH -
|
trackColWidth -
|
||||||
DURATION_COL_WIDTH -
|
DURATION_COL_WIDTH -
|
||||||
ARTIST_COL_WIDTH -
|
ARTIST_COL_WIDTH -
|
||||||
(3 * 3); /* 3 = spacing */
|
(3 * 3); /* 3 = spacing */
|
||||||
@ -442,7 +462,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(cursespp::ScrollableWi
|
|||||||
|
|
||||||
std::string text = parent.formatter
|
std::string text = parent.formatter
|
||||||
? parent.formatter(track, this->GetWidth())
|
? parent.formatter(track, this->GetWidth())
|
||||||
: formatWithoutAlbum(track, this->GetWidth());
|
: formatWithoutAlbum(track, rawIndex, this->GetWidth(), parent.trackNumType);
|
||||||
|
|
||||||
std::shared_ptr<TrackListEntry> entry(
|
std::shared_ptr<TrackListEntry> entry(
|
||||||
new TrackListEntry(text, trackIndex, RowType::Track));
|
new TrackListEntry(text, trackIndex, RowType::Track));
|
||||||
|
@ -56,6 +56,8 @@ namespace musik {
|
|||||||
public sigslot::has_slots<>
|
public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum class TrackNumType: int { Metadata = 0, Sequential = 1 };
|
||||||
|
|
||||||
typedef musik::core::TrackPtr TrackPtr;
|
typedef musik::core::TrackPtr TrackPtr;
|
||||||
typedef musik::core::db::local::TrackListQueryBase TrackListQueryBase;
|
typedef musik::core::db::local::TrackListQueryBase TrackListQueryBase;
|
||||||
|
|
||||||
@ -89,6 +91,7 @@ namespace musik {
|
|||||||
void Clear();
|
void Clear();
|
||||||
size_t TrackCount();
|
size_t TrackCount();
|
||||||
size_t EntryCount();
|
size_t EntryCount();
|
||||||
|
void SetTrackNumType(TrackNumType type);
|
||||||
|
|
||||||
void Requery(std::shared_ptr<TrackListQueryBase> query);
|
void Requery(std::shared_ptr<TrackListQueryBase> query);
|
||||||
|
|
||||||
@ -162,6 +165,7 @@ namespace musik {
|
|||||||
RowFormatter formatter;
|
RowFormatter formatter;
|
||||||
RowDecorator decorator;
|
RowDecorator decorator;
|
||||||
std::chrono::milliseconds lastChanged;
|
std::chrono::milliseconds lastChanged;
|
||||||
|
TrackNumType trackNumType;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user