From 801159bfe83868b4c9f2d47ad206bf19b28e7785 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Mon, 30 Apr 2018 15:11:53 +0100 Subject: [PATCH] Display total songs in queue header --- htdocs/js/mpd.js | 2 +- src/mpd_client.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index d38543f..24ea6ab 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -302,7 +302,7 @@ function webSocketConnect() { var minutes = Math.floor(obj.totalTime / 60) - hours * 60; var seconds = obj.totalTime - hours * 3600 - minutes * 60; - $('#panel-heading-info').text('Total: ' + + $('#panel-heading-info').text(obj.totalSongs+' Songs – ' + (hours > 0 ? hours + '\u2009h ' + (minutes < 10 ? '0' : '') : '') + minutes + '\u2009m ' + (seconds < 10 ? '0' : '') + seconds + '\u2009s'); } else { diff --git a/src/mpd_client.c b/src/mpd_client.c index fd546f6..91eac1e 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -628,6 +628,7 @@ int mpd_put_queue(char *buffer, unsigned int offset) const char *end = buffer + MAX_SIZE; struct mpd_entity *entity; unsigned long totalTime = 0; + unsigned long totalSongs = 0; if (!mpd_send_list_queue_range_meta(mpd.conn, offset, offset+MAX_ELEMENTS_PER_PAGE)) RETURN_ERROR_AND_RECOVER("mpd_send_list_queue_meta"); @@ -663,6 +664,7 @@ int mpd_put_queue(char *buffer, unsigned int offset) cur += json_emit_raw_str(cur, end - cur, "},"); totalTime += drtn; + totalSongs ++; } mpd_entity_free(entity); } @@ -672,6 +674,8 @@ int mpd_put_queue(char *buffer, unsigned int offset) cur += json_emit_raw_str(cur, end - cur, "],\"totalTime\":"); cur += json_emit_int(cur, end - cur, totalTime); + cur += json_emit_raw_str(cur, end - cur, ",\"totalSongs\":"); + cur += json_emit_int(cur, end - cur, totalSongs); cur += json_emit_raw_str(cur, end - cur, "}"); return cur - buffer; }