diff options
Diffstat (limited to 'src/ui.c')
-rw-r--r-- | src/ui.c | 63 |
1 files changed, 51 insertions, 12 deletions
@@ -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); @@ -614,6 +615,23 @@ void BarUiPrintStation (const BarSettings_t *settings, BarUiMsg (settings, MSG_PLAYING, "%s", outstr); } +static const char *ratingToIcon (const BarSettings_t * const settings, + const PianoSong_t * const song) { + switch (song->rating) { + case PIANO_RATE_LOVE: + return settings->loveIcon; + + case PIANO_RATE_BAN: + return settings->banIcon; + + case PIANO_RATE_TIRED: + return settings->tiredIcon; + + default: + return ""; + } +} + /* Print song infos (artist, title, album, loved) * @param pianobar settings * @param the song @@ -623,7 +641,7 @@ void BarUiPrintSong (const BarSettings_t *settings, const PianoSong_t *song, const PianoStation_t *station) { char outstr[512]; const char *vals[] = {song->title, song->artist, song->album, - (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "", + ratingToIcon (settings, song), station != NULL ? settings->atIcon : "", station != NULL ? station->name : "", song->detailUrl}; @@ -644,23 +662,44 @@ 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; - char digits[8]; PianoListForeachP (song) { if (filter == NULL || (filter != NULL && (BarStrCaseStr (song->artist, filter) != NULL || BarStrCaseStr (song->title, filter) != NULL))) { - char outstr[512]; + const char * const deleted = "(deleted)", * const empty = ""; + const char *stationName = empty; + + const PianoStation_t * const station = + PianoFindStationById (app->ph.stations, song->stationId); + if (station != NULL && station != app->curStation) { + stationName = station->name; + } else if (station == NULL && song->stationId != NULL) { + stationName = deleted; + } + + char outstr[512], digits[8], duration[8] = "??:??"; const char *vals[] = {digits, song->artist, song->title, - (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : - ((song->rating == PIANO_RATE_BAN) ? settings->banIcon : "")}; + ratingToIcon (settings, song), + duration, + stationName != empty ? settings->atIcon : "", + stationName, + }; + /* pre-format a few strings */ snprintf (digits, sizeof (digits) / sizeof (*digits), "%2zu", i); + const unsigned int length = song->length; + if (length > 0) { + snprintf (duration, sizeof (duration), "%02u:%02u", + length / 60, length % 60); + } + BarUiCustomFormat (outstr, sizeof (outstr), settings->listSongFormat, - "iatr", vals); + "iatrd@s", vals); BarUiAppendNewline (outstr, sizeof (outstr)); BarUiMsg (settings, MSG_LIST, "%s", outstr); } |