seamus

commit a33a8354986d851998017d3651807f056fe0a8ef

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

ui: play the selected song

Shall we replace this with a toggle though?

 include/ui.h | 1 +
 src/queue.c | 2 +-
 src/ui.c | 30 ++++++++++++++++++++++++++----


diff --git a/include/ui.h b/include/ui.h
index b9588da44a727e7efd4637f1082b137f3d30cc98..97e359f639c73d70b86351bf6d81bb8ac89d5408 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -9,6 +9,7 @@ int tickit_start(struct seamus_frontend *s);
 int tickit_finish(struct seamus_frontend *s);
 
 static int on_key_event(TickitTerm *t, TickitEventFlags flags, void *_info, void *data);
+static int toggle_playing_status(struct seamus_frontend *seamus);
 static int update_scroll_position(struct seamus_frontend *seamus, int direction);
 static int update_status(Tickit *t, TickitEventFlags flags, void *_info, void *data);
 static int update_main_window(Tickit *t, TickitEventFlags flags, void *_info, void *data);




diff --git a/src/queue.c b/src/queue.c
index 7990c3ae6754412baebe1fc2c199d3bdc23a6bb5..611c6157a045fd89d623fe1838a5c5ded2d64d16 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -15,7 +15,7 @@ 		struct mpd_entity *entity;
 		int index = 0;
 		int max_items = 0;
 
-		// XXX: The logic here is. We check the amount of items queued.
+		// XXX: The logic here is: We check the amount of items queued.
 		// Then we have the info o how many items we can fit into the
 		// screen. The decision we need to make here is: if the amount
 		// of items queued is larger than what we can display on the




diff --git a/src/ui.c b/src/ui.c
index 40ab41768d84b8878a18ff0550d67ac71b70b260..4f6ad061d5f710eec6bae0c8241101dc177019e5 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -72,26 +72,46 @@
 	struct seamus_frontend *seamus = (struct seamus_frontend*) data;
 	const char *key_pressed = info->str;
 
+	// TODO: Replace those with enums
 	if (strcmp(key_pressed, "q") == 0) {
 		tickit_window_close(seamus->main_window);
 		tickit_window_close(seamus->status_window);
 
 		tickit_stop(seamus->t);
-		//tickit_finish(seamus);
-
 	} else if (strcmp(key_pressed, "j") == 0) {
 		log_info("Scroll down");
-		// TODO: Replace with an enum
+
 		update_scroll_position(seamus, +1);
 	} else if (strcmp(key_pressed, "k") == 0) {
 		log_info("Scroll up");
-		// TODO: Replace with an enum
+
 		update_scroll_position(seamus, -1);
+	} else if (strcmp(key_pressed, "Enter") == 0) {
+		log_info("Pressed enter");
+
+		toggle_playing_status(seamus);
 	} else {
 		log_info("Pressed something else %s", key_pressed);
 	}
 
 	return 1;
+}
+
+static int
+toggle_playing_status(struct seamus_frontend *seamus)
+{
+	log_info("Current position %d", seamus->scroll_position);
+	struct seamus_song song = seamus->queue[seamus->scroll_position];
+	log_info("Current song on queue %d - %s", song.song_id, song.title);
+
+	if (mpd_run_play_id(seamus->conn, song.song_id)) {
+		log_info("Requested to play song");
+	} else {
+		log_info("Failed to play song");
+	}
+
+	fetch_current_status(seamus);
+	tickit_window_expose(seamus->main_window, NULL);
 }
 
 static int
@@ -204,6 +224,7 @@
 static int
 render_main_window(TickitWindow *win, TickitEventFlags flags, void *_info, void *data)
 {
+	log_info("Rendering the main window");
 	TickitExposeEventInfo *info = _info;
 	TickitRenderBuffer *render_buffer = info->rb;
 	struct seamus_frontend *seamus = (struct seamus_frontend*) data;
@@ -253,6 +274,7 @@
 static int
 render_queue(struct seamus_frontend *seamus, TickitRenderBuffer *render_buffer)
 {
+	log_info("Rendering the queue");
 	for (size_t i = 0; i < seamus->queue_size; ++i) {
 		struct seamus_song *song = &seamus->queue[i];