From c225eea4edfb8cf8ede845cc6f9b7e858aabe6e8 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 26 Feb 2011 14:44:52 +0100 Subject: Always add song to history --- src/ui.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 0e8f80b..cd0b7d2 100644 --- a/src/ui.c +++ b/src/ui.c @@ -694,3 +694,33 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, waitpid (chld, &status, 0); } } + +/* prepend song to history, must not be a list of songs as ->next is modified! + */ +void BarUiHistoryPrepend (BarApp_t *app, PianoSong_t *song) { + if (app->settings.history != 0) { + PianoSong_t *tmpSong; + + song->next = app->songHistory; + app->songHistory = song; + + /* limit history's length */ + /* start with 1, so we're stopping at n-1 and have the + * chance to set ->next = NULL */ + unsigned int i = 1; + tmpSong = app->songHistory; + while (i < app->settings.history && tmpSong != NULL) { + tmpSong = tmpSong->next; + ++i; + } + /* if too many songs in history... */ + if (tmpSong != NULL) { + PianoSong_t *delSong = tmpSong->next; + tmpSong->next = NULL; + if (delSong != NULL) { + PianoDestroyPlaylist (delSong); + } + } + } +} + -- cgit v1.2.3