From 2b31c97de6fa541719cd26f9a61053cfc0e71203 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 18 Nov 2010 21:21:55 +0100 Subject: Show custom rating icon in upcoming/history song list Closes issue #54 --- src/main.c | 3 ++- src/pianobar.1 | 8 ++++++++ src/settings.c | 14 ++++++++++++++ src/settings.h | 2 ++ src/ui.c | 50 ++++++++++++++++++++++++++++++++++++-------------- src/ui.h | 6 ++++-- src/ui_act.c | 14 +++++--------- 7 files changed, 71 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index d401e65..b582baf 100644 --- a/src/main.c +++ b/src/main.c @@ -259,7 +259,8 @@ int main (int argc, char **argv) { } /* song ready to play */ if (app.playlist != NULL) { - BarUiPrintSong (app.playlist, app.curStation->isQuickMix ? + BarUiPrintSong (&app.settings, app.playlist, + app.curStation->isQuickMix ? PianoFindStationById (app.ph.stations, app.playlist->stationId) : NULL); diff --git a/src/pianobar.1 b/src/pianobar.1 index ac262ef..a27b606 100644 --- a/src/pianobar.1 +++ b/src/pianobar.1 @@ -139,6 +139,10 @@ by pressing or the key you defined in .B act_songinfo. +.TP +.B ban_icon = password); free (settings->autostartStation); free (settings->eventCmd); + free (settings->loveIcon); + free (settings->banIcon); memset (settings, 0, sizeof (*settings)); } @@ -175,6 +177,10 @@ void BarSettingsRead (BarSettings_t *settings) { break; } } + } else if (strcmp ("love_icon", key) == 0) { + settings->loveIcon = strdup (val); + } else if (strcmp ("ban_icon", key) == 0) { + settings->banIcon = strdup (val); } } @@ -186,5 +192,13 @@ void BarSettingsRead (BarSettings_t *settings) { } } + /* use default strings */ + if (settings->loveIcon == NULL) { + settings->loveIcon = strdup ("<3"); + } + if (settings->banIcon == NULL) { + settings->banIcon = strdup ("artist, - tmpSong->title); - i++; - tmpSong = tmpSong->next; - } + i = BarUiListSongs (settings, startSong); + BarUiMsg (MSG_QUESTION, "Select song: "); if (BarReadlineInt (&i, curFd) == 0) { return NULL; } + tmpSong = startSong; while (tmpSong != NULL && i > 0) { tmpSong = tmpSong->next; i--; } + return tmpSong; } @@ -436,14 +433,16 @@ char *BarUiSelectMusicId (BarApp_t *app, FILE *curFd, char *similarToId) { musicId = strdup (tmpArtist->musicId); } } else if (*selectBuf == 't') { - tmpSong = BarUiSelectSong (searchResult.songs, curFd); + tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, + curFd); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); } } } else if (searchResult.songs != NULL) { /* songs found */ - tmpSong = BarUiSelectSong (searchResult.songs, curFd); + tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, + curFd); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); } @@ -539,14 +538,37 @@ inline void BarUiPrintStation (PianoStation_t *station) { * @param the song * @param alternative station info (show real station for quickmix, e.g.) */ -inline void BarUiPrintSong (PianoSong_t *song, PianoStation_t *station) { - BarUiMsg (MSG_PLAYING, "\"%s\" by \"%s\" on \"%s\"%s%s%s\n", +inline void BarUiPrintSong (const BarSettings_t *settings, + const PianoSong_t *song, const PianoStation_t *station) { + BarUiMsg (MSG_PLAYING, "\"%s\" by \"%s\" on \"%s\"%s%s%s%s\n", song->title, song->artist, song->album, - (song->rating == PIANO_RATE_LOVE) ? " <3" : "", + (song->rating == PIANO_RATE_LOVE) ? " " : "", + (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "", station != NULL ? " @ " : "", station != NULL ? station->name : ""); } +/* Print list of songs + * @param pianobar settings + * @param linked list of songs + * @return # of songs + */ +size_t BarUiListSongs (const BarSettings_t *settings, + const PianoSong_t *song) { + size_t i = 0; + + while (song != NULL) { + BarUiMsg (MSG_LIST, "%2lu) %s - %s %s%s\n", i, song->artist, + song->title, + (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "", + (song->rating == PIANO_RATE_BAN) ? settings->banIcon : ""); + song = song->next; + i++; + } + + return i; +} + /* Excute external event handler * @param settings containing the cmdline * @param event type diff --git a/src/ui.h b/src/ui.h index 9a4dcb5..582ab5c 100644 --- a/src/ui.h +++ b/src/ui.h @@ -38,12 +38,14 @@ void BarUiMsg (uiMsg_t type, const char *format, ...); PianoReturn_t BarUiPrintPianoStatus (PianoReturn_t ret); PianoStation_t *BarUiSelectStation (PianoHandle_t *, const char *, BarStationSorting_t, FILE *); -PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd); +PianoSong_t *BarUiSelectSong (const BarSettings_t *, PianoSong_t *, FILE *); PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd); char *BarUiSelectMusicId (BarApp_t *, FILE *, char *); void BarStationFromGenre (BarApp_t *, FILE *); void BarUiPrintStation (PianoStation_t *); -void BarUiPrintSong (PianoSong_t *, PianoStation_t *); +void BarUiPrintSong (const BarSettings_t *, const PianoSong_t *, + const PianoStation_t *); +size_t BarUiListSongs (const BarSettings_t *, const PianoSong_t *); void BarUiStartEventCmd (const BarSettings_t *, const char *, const PianoStation_t *, const PianoSong_t *, const struct audioPlayer *, PianoReturn_t, WaitressReturn_t); diff --git a/src/ui_act.c b/src/ui_act.c index 0f66986..0f0cac2 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -254,7 +254,8 @@ BarUiActCallback(BarUiActSongInfo) { BarUiPrintStation (app->curStation); /* print real station if quickmix */ - BarUiPrintSong (app->playlist, app->curStation->isQuickMix ? + BarUiPrintSong (&app->settings, app->playlist, + app->curStation->isQuickMix ? PianoFindStationById (app->ph.stations, app->playlist->stationId) : NULL); } @@ -420,13 +421,7 @@ BarUiActCallback(BarUiActPrintUpcoming) { PianoSong_t *nextSong = app->playlist->next; if (nextSong != NULL) { - int i = 0; - while (nextSong != NULL) { - BarUiMsg (MSG_LIST, "%2i) \"%s\" by \"%s\"\n", i, nextSong->title, - nextSong->artist); - nextSong = nextSong->next; - i++; - } + BarUiListSongs (&app->settings, nextSong); } else { BarUiMsg (MSG_INFO, "No songs in queue.\n"); } @@ -472,7 +467,8 @@ BarUiActCallback(BarUiActHistory) { PianoSong_t *selectedSong; if (app->songHistory != NULL) { - selectedSong = BarUiSelectSong (app->songHistory, curFd); + selectedSong = BarUiSelectSong (&app->settings, app->songHistory, + curFd); if (selectedSong != NULL) { /* use user-defined keybindings */ allowedBuf[0] = app->settings.keys[BAR_KS_LOVE]; -- cgit v1.2.3