diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2017-10-02 12:12:01 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2017-10-02 12:12:01 +0200 |
commit | 4dfca5b56b441faf4938b6c8e97585f68e468039 (patch) | |
tree | 325b622767611e0fc08c08f4792c1b85ca020f07 /src | |
parent | 41a00cc1e643d9e9a69991ead268777ecd17c154 (diff) | |
download | pianobar-4dfca5b56b441faf4938b6c8e97585f68e468039.tar.gz pianobar-4dfca5b56b441faf4938b6c8e97585f68e468039.tar.bz2 pianobar-4dfca5b56b441faf4938b6c8e97585f68e468039.zip |
Show station in song lists
Iff song’s station is not the current station. This is only the case for
the song history right now.
Closes #638
Diffstat (limited to 'src')
-rw-r--r-- | src/libpiano/piano.c | 6 | ||||
-rw-r--r-- | src/ui.c | 33 | ||||
-rw-r--r-- | src/ui.h | 7 | ||||
-rw-r--r-- | src/ui_act.c | 8 |
4 files changed, 38 insertions, 16 deletions
diff --git a/src/libpiano/piano.c b/src/libpiano/piano.c index 72502f7..a189f34 100644 --- a/src/libpiano/piano.c +++ b/src/libpiano/piano.c @@ -219,7 +219,11 @@ void PianoDestroyRequest (PianoRequest_t *req) { */ PianoStation_t *PianoFindStationById (PianoStation_t * const stations, const char * const searchStation) { - assert (searchStation != NULL); + assert (stations != NULL); + + if (searchStation == NULL) { + return NULL; + } PianoStation_t *currStation = stations; PianoListForeachP (currStation) { @@ -486,20 +486,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, BarReadlineFds_t *input) { + 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), input, BAR_RL_DEFAULT) == 0) { @@ -598,7 +599,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->input); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); @@ -606,7 +607,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->input); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); @@ -757,18 +758,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); @@ -779,7 +796,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); } @@ -38,14 +38,15 @@ typedef void (*BarUiSelectStationCallback_t) (BarApp_t *app, char *buf); void BarUiMsg (const BarSettings_t *, const BarUiMsg_t, const char *, ...) __attribute__((format(printf, 3, 4))); PianoStation_t *BarUiSelectStation (BarApp_t *, PianoStation_t *, const char *, BarUiSelectStationCallback_t, bool); -PianoSong_t *BarUiSelectSong (const BarSettings_t *, PianoSong_t *, - BarReadlineFds_t *); +PianoSong_t *BarUiSelectSong (const BarApp_t * const app, + PianoSong_t *startSong, BarReadlineFds_t *input); PianoArtist_t *BarUiSelectArtist (BarApp_t *, PianoArtist_t *); char *BarUiSelectMusicId (BarApp_t *, PianoStation_t *, const char *); void BarUiPrintStation (const BarSettings_t *, PianoStation_t *); void BarUiPrintSong (const BarSettings_t *, const PianoSong_t *, const PianoStation_t *); -size_t BarUiListSongs (const BarSettings_t *, const PianoSong_t *, const char *); +size_t BarUiListSongs (const BarApp_t * const app, + const PianoSong_t *song, const char *filter); void BarUiStartEventCmd (const BarSettings_t *, const char *, const PianoStation_t *, const PianoSong_t *, const player_t *, PianoStation_t *, PianoReturn_t, CURLcode); diff --git a/src/ui_act.c b/src/ui_act.c index ee43809..2c5f264 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -505,7 +505,7 @@ BarUiActCallback(BarUiActTempBanSong) { BarUiActCallback(BarUiActPrintUpcoming) { PianoSong_t * const nextSong = PianoListNextP (selSong); if (nextSong != NULL) { - BarUiListSongs (&app->settings, nextSong, NULL); + BarUiListSongs (app, nextSong, NULL); } else { BarUiMsg (&app->settings, MSG_INFO, "No songs in queue.\n"); } @@ -587,7 +587,7 @@ BarUiActCallback(BarUiActHistory) { PianoSong_t *histSong; if (app->songHistory != NULL) { - histSong = BarUiSelectSong (&app->settings, app->songHistory, + histSong = BarUiSelectSong (app, app->songHistory, &app->input); if (histSong != NULL) { BarKeyShortcutId_t action; @@ -842,7 +842,7 @@ BarUiActCallback(BarUiActManageStation) { BarUiActDefaultEventcmd ("stationdeleteartistseed"); } } else if (selectBuf[0] == 's') { - PianoSong_t *song = BarUiSelectSong (&app->settings, + PianoSong_t *song = BarUiSelectSong (app, reqData.info.songSeeds, &app->input); if (song != NULL) { PianoRequestDataDeleteSeed_t subReqData; @@ -869,7 +869,7 @@ BarUiActCallback(BarUiActManageStation) { BarUiActDefaultEventcmd ("stationdeletestationseed"); } } else if (selectBuf[0] == 'f') { - PianoSong_t *song = BarUiSelectSong (&app->settings, + PianoSong_t *song = BarUiSelectSong (app, reqData.info.feedback, &app->input); if (song != NULL) { BarUiMsg (&app->settings, MSG_INFO, "Deleting feedback... "); |