mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 13:21:13 +00:00
Added duration readouts to directory browsing.
This commit is contained in:
parent
4a077922ae
commit
2263610b50
@ -184,7 +184,7 @@ void CategoryTrackListQuery::ProcessResult(musik::core::db::Statement& trackQuer
|
||||
std::string album = trackQuery.ColumnText(2);
|
||||
|
||||
if (this->parseHeaders && album != lastAlbum) {
|
||||
if (!headers->empty()) {
|
||||
if (!headers->empty()) { /* @copypaste */
|
||||
(*durations)[lastHeaderIndex] = runningDuration;
|
||||
lastHeaderIndex = index;
|
||||
runningDuration = 0;
|
||||
|
@ -60,15 +60,17 @@ DirectoryTrackListQuery::DirectoryTrackListQuery(
|
||||
this->filter = filter;
|
||||
this->result = std::make_shared<TrackList>(library);
|
||||
this->headers = std::make_shared<std::set<size_t>>();
|
||||
this->durations = std::make_shared<std::map<size_t, size_t>>();
|
||||
this->hash = std::hash<std::string>()(directory + "-" + filter);
|
||||
}
|
||||
|
||||
bool DirectoryTrackListQuery::OnRun(Connection& db) {
|
||||
this->result = std::make_shared<TrackList>(library);
|
||||
this->headers = std::make_shared<std::set<size_t>>();
|
||||
this->durations = std::make_shared<std::map<size_t, size_t>>();
|
||||
|
||||
std::string query =
|
||||
" SELECT t.id, al.name "
|
||||
" SELECT t.id, t.duration, al.name "
|
||||
" FROM tracks t, albums al, artists ar, genres gn "
|
||||
" WHERE t.visible=1 AND directory_id IN ("
|
||||
" SELECT id FROM directories WHERE name LIKE ?)"
|
||||
@ -81,16 +83,24 @@ bool DirectoryTrackListQuery::OnRun(Connection& db) {
|
||||
select.BindText(0, this->directory + "%");
|
||||
|
||||
std::string lastAlbum;
|
||||
size_t lastHeaderIndex = 0;
|
||||
size_t runningDuration = 0;
|
||||
size_t index = 0;
|
||||
while (select.Step() == db::Row) {
|
||||
const int64_t id = select.ColumnInt64(0);
|
||||
std::string album = select.ColumnText(1);
|
||||
runningDuration += select.ColumnInt32(1);
|
||||
std::string album = select.ColumnText(2);
|
||||
|
||||
if (!album.size()) {
|
||||
album = _TSTR("tracklist_unknown_album");
|
||||
}
|
||||
|
||||
if (album != lastAlbum) {
|
||||
if (!headers->empty()) { /* @copypaste */
|
||||
(*durations)[lastHeaderIndex] = runningDuration;
|
||||
lastHeaderIndex = index;
|
||||
runningDuration = 0;
|
||||
}
|
||||
headers->insert(index);
|
||||
lastAlbum = album;
|
||||
}
|
||||
@ -99,6 +109,10 @@ bool DirectoryTrackListQuery::OnRun(Connection& db) {
|
||||
++index;
|
||||
}
|
||||
|
||||
if (!headers->empty()) {
|
||||
(*durations)[lastHeaderIndex] = runningDuration;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -57,10 +57,8 @@ namespace musik { namespace core { namespace library { namespace query {
|
||||
Result GetResult() noexcept override { return this->result; }
|
||||
Headers GetHeaders() noexcept override { return this->headers; }
|
||||
size_t GetQueryHash() noexcept override { return this->hash; }
|
||||
Durations GetDurations() noexcept override {
|
||||
return std::make_shared<std::map<size_t, size_t>>();
|
||||
}
|
||||
|
||||
Durations GetDurations() noexcept override { return this->durations; }
|
||||
|
||||
/* ISerializableQuery */
|
||||
std::string SerializeQuery() override;
|
||||
std::string SerializeResult() override;
|
||||
@ -77,6 +75,7 @@ namespace musik { namespace core { namespace library { namespace query {
|
||||
std::string directory, filter;
|
||||
Result result;
|
||||
Headers headers;
|
||||
Durations durations;
|
||||
size_t hash;
|
||||
};
|
||||
|
||||
|
@ -171,7 +171,7 @@ bool SearchTrackListQuery::OnRun(Connection& db) {
|
||||
}
|
||||
|
||||
if (this->parseHeaders && album != lastAlbum) {
|
||||
if (!headers->empty()) {
|
||||
if (!headers->empty()) { /* @copypaste */
|
||||
(*durations)[lastHeaderIndex] = runningDuration;
|
||||
lastHeaderIndex = index;
|
||||
runningDuration = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user