diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2011-08-29 13:02:01 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2011-08-29 13:07:26 +0200 |
commit | f97f73d03f1ea7b6db6a3ef7d3756680f566f191 (patch) | |
tree | 8d805afd655cf7967d27c23cb0855b0e289c1d53 /src | |
parent | b8cf55c28e131ebdcb0a32fe0e8c14fefebebcea (diff) | |
download | pianobar-f97f73d03f1ea7b6db6a3ef7d3756680f566f191.tar.gz pianobar-f97f73d03f1ea7b6db6a3ef7d3756680f566f191.tar.bz2 pianobar-f97f73d03f1ea7b6db6a3ef7d3756680f566f191.zip |
Customizeable list format (songs)
Fixes #151
Diffstat (limited to 'src')
-rw-r--r-- | src/settings.c | 5 | ||||
-rw-r--r-- | src/settings.h | 1 | ||||
-rw-r--r-- | src/ui.c | 31 |
3 files changed, 32 insertions, 5 deletions
diff --git a/src/settings.c b/src/settings.c index 49d75e6..9867b47 100644 --- a/src/settings.c +++ b/src/settings.c @@ -91,6 +91,7 @@ void BarSettingsDestroy (BarSettings_t *settings) { free (settings->atIcon); free (settings->npSongFormat); free (settings->npStationFormat); + free (settings->listSongFormat); free (settings->fifo); for (size_t i = 0; i < MSG_COUNT; i++) { free (settings->msgFormat[i].prefix); @@ -127,6 +128,7 @@ void BarSettingsRead (BarSettings_t *settings) { settings->atIcon = strdup (" @ "); settings->npSongFormat = strdup ("\"%t\" by \"%a\" on \"%l\"%r%@%s"); settings->npStationFormat = strdup ("Station \"%n\" (%i)"); + settings->listSongFormat = strdup ("%i) %a - %t%r"); settings->fifo = malloc (PATH_MAX * sizeof (*settings->fifo)); BarGetXdgConfigDir (PACKAGE "/ctl", settings->fifo, PATH_MAX); @@ -231,6 +233,9 @@ void BarSettingsRead (BarSettings_t *settings) { } else if (streq ("format_nowplaying_station", key)) { free (settings->npStationFormat); settings->npStationFormat = strdup (val); + } else if (streq ("format_list_song", key)) { + free (settings->listSongFormat); + settings->listSongFormat = strdup (val); } else if (streq ("fifo", key)) { free (settings->fifo); settings->fifo = strdup (val); diff --git a/src/settings.h b/src/settings.h index ca5db60..6162395 100644 --- a/src/settings.h +++ b/src/settings.h @@ -94,6 +94,7 @@ typedef struct { char *atIcon; char *npSongFormat; char *npStationFormat; + char *listSongFormat; char *fifo; BarMsgFormatStr_t msgFormat[MSG_COUNT]; } BarSettings_t; @@ -723,6 +723,20 @@ inline void BarUiPrintSong (const BarSettings_t *settings, BarUiMsg (settings, MSG_PLAYING, outstr); } +/* Incremets two digit ASCII counter + */ +static void BarUiIncDigits (char digits[3]) { + ++digits[1]; + if (digits[1] == ':') { + digits[1] = '0'; + digits[0] |= 0x30; + ++digits[0]; + if (digits[0] == ':') { + digits[0] = ' '; + } + } +} + /* Print list of songs * @param pianobar settings * @param linked list of songs @@ -732,18 +746,25 @@ inline void BarUiPrintSong (const BarSettings_t *settings, size_t BarUiListSongs (const BarSettings_t *settings, const PianoSong_t *song, const char *filter) { size_t i = 0; + char digits[3] = " 0"; while (song != NULL) { if (filter == NULL || (filter != NULL && (BarStrCaseStr (song->artist, filter) != NULL || BarStrCaseStr (song->title, filter) != NULL))) { - BarUiMsg (settings, 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 : ""); + char outstr[512]; + const char *vals[] = {digits, song->artist, song->title, + (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : + ((song->rating == PIANO_RATE_BAN) ? settings->banIcon : "")}; + + BarUiCustomFormat (outstr, sizeof (outstr), settings->listSongFormat, + "iatr", vals); + BarUiAppendNewline (outstr, sizeof (outstr)); + BarUiMsg (settings, MSG_LIST, outstr); } - song = song->next; i++; + BarUiIncDigits (digits); + song = song->next; } return i; |