From ed3ab2743344dfe2b38427733560b9847d259c8c Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 2 Oct 2017 12:12:01 +0200 Subject: Show station in song lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iff song’s station is not the current station. This is only the case for the song history right now. Closes #638 --- src/ui.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 30b62f7..c682ca3 100644 --- a/src/ui.c +++ b/src/ui.c @@ -388,20 +388,21 @@ PianoStation_t *BarUiSelectStation (BarApp_t *app, PianoStation_t *stations, } /* let user pick one song - * @param pianobar settings + * @param app * @param song list * @param input fds * @return pointer to selected item in song list or NULL */ -PianoSong_t *BarUiSelectSong (const BarSettings_t *settings, +PianoSong_t *BarUiSelectSong (const BarApp_t * const app, PianoSong_t *startSong, BarReadline_t rl) { + const BarSettings_t * const settings = &app->settings; PianoSong_t *tmpSong = NULL; char buf[100]; memset (buf, 0, sizeof (buf)); do { - BarUiListSongs (settings, startSong, buf); + BarUiListSongs (app, startSong, buf); BarUiMsg (settings, MSG_QUESTION, "Select song: "); if (BarReadlineStr (buf, sizeof (buf), rl, BAR_RL_DEFAULT) == 0) { @@ -498,7 +499,7 @@ char *BarUiSelectMusicId (BarApp_t *app, PianoStation_t *station, musicId = strdup (tmpArtist->musicId); } } else if (*selectBuf == 't') { - tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, + tmpSong = BarUiSelectSong (app, searchResult.songs, app->rl); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); @@ -506,7 +507,7 @@ char *BarUiSelectMusicId (BarApp_t *app, PianoStation_t *station, } } else if (searchResult.songs != NULL) { /* songs found */ - tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, + tmpSong = BarUiSelectSong (app, searchResult.songs, app->rl); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); @@ -661,18 +662,34 @@ void BarUiPrintSong (const BarSettings_t *settings, * @param artist/song filter string * @return # of songs */ -size_t BarUiListSongs (const BarSettings_t *settings, +size_t BarUiListSongs (const BarApp_t * const app, const PianoSong_t *song, const char *filter) { + const BarSettings_t * const settings = &app->settings; size_t i = 0; PianoListForeachP (song) { if (filter == NULL || (filter != NULL && (BarStrCaseStr (song->artist, filter) != NULL || BarStrCaseStr (song->title, filter) != NULL))) { + const char * const empty = ""; + const char *stationName = "(deleted)"; + const PianoStation_t * const station = + PianoFindStationById (app->ph.stations, song->stationId); + if (station != NULL) { + if (station != app->curStation) { + stationName = station->name; + } else { + stationName = empty; + } + } + char outstr[512], digits[8], duration[8] = "??:??"; const char *vals[] = {digits, song->artist, song->title, ratingToIcon (settings, song), - duration}; + duration, + stationName != empty ? settings->atIcon : "", + stationName, + }; /* pre-format a few strings */ snprintf (digits, sizeof (digits) / sizeof (*digits), "%2zu", i); @@ -683,7 +700,7 @@ size_t BarUiListSongs (const BarSettings_t *settings, } BarUiCustomFormat (outstr, sizeof (outstr), settings->listSongFormat, - "iatrd", vals); + "iatrd@s", vals); BarUiAppendNewline (outstr, sizeof (outstr)); BarUiMsg (settings, MSG_LIST, "%s", outstr); } -- cgit v1.2.3