seamus

commit 3663485e83ca7aa36cc8c32ce5ec8bd8a104a41e

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

queue: deal with errors and don't display more than we can fit

 src/queue.c | 6 ++++++
 src/ui.c | 25 +++++++++++++------------


diff --git a/src/queue.c b/src/queue.c
index 40ec7042297d86ef805f80b37222095280fdb544..6c12dc210676944e961ce8a1dd86344200221331 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -19,6 +19,12 @@
 		for (index = 0; index < max_count; index++) {
 			entity = mpd_recv_entity(seamus->conn);
 			if (entity == NULL) {
+				if (mpd_connection_get_error(seamus->conn) != MPD_ERROR_SUCCESS) {
+					log_error("%s\n", mpd_connection_get_error_message(seamus->conn));
+
+					return 1;
+				}
+
 				continue;
 			} else {
 				enum mpd_entity_type type = mpd_entity_get_type(entity);




diff --git a/src/ui.c b/src/ui.c
index 2dac5a1d27f5deb30aa3399b53526ef994c8e866..e9614b9e19f4a2adec39258b3ccc3279168e637a 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -155,22 +155,23 @@ 	fetch_current_queue(seamus, max_songs);
 
 	if (seamus->queue_size > 0) {
 		for (size_t i = 0; i < seamus->queue_size; ++i) {
-			struct seamus_song *s = &seamus->queue[i];
+			if (i < max_songs) {
+				struct seamus_song *s = &seamus->queue[i];
 
-			if (s == NULL) {
-				log_info("Nothing here...");
-			} else {
-				char *song_str = malloc(
-						sizeof(char) *
-						(strlen(s->artist) + strlen(s->title) + 4));
+				if (s == NULL) {
+					log_info("Nothing here...");
+				} else {
+					char *song_str = malloc(
+							sizeof(char) *
+							(strlen(s->artist) + strlen(s->title) + 4));
 
-				sprintf(song_str, "%s - %s", s->artist, s->title);
+					sprintf(song_str, "%s - %s", s->artist, s->title);
 
-				tickit_renderbuffer_goto(render_buffer, 4 + i, 0);
-				tickit_renderbuffer_text(render_buffer, song_str);
+					tickit_renderbuffer_goto(render_buffer, 4 + i, 0);
+					tickit_renderbuffer_text(render_buffer, song_str);
 
-				log_debug("Song queued: %d: %s\n", i, song_str);
-				free(song_str);
+					free(song_str);
+				}
 			}
 		}
 	} else {