diff options
author | Matthew Beckler <matthew@mbeckler.org> | 2011-01-13 17:18:25 -0500 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2011-01-15 12:37:21 +0100 |
commit | d166a010670ac829d1e6d4f37dbac075d13d9b26 (patch) | |
tree | bbca581c2de6c88fad0ecdf0e0be1c761449a15b /src/ui.c | |
parent | c5c4dcc9cd471aa060be568491141703b96ae0f8 (diff) | |
download | pianobar-d166a010670ac829d1e6d4f37dbac075d13d9b26.tar.gz pianobar-d166a010670ac829d1e6d4f37dbac075d13d9b26.tar.bz2 pianobar-d166a010670ac829d1e6d4f37dbac075d13d9b26.zip |
Send station list to eventcmd
See issue #76
Diffstat (limited to 'src/ui.c')
-rw-r--r-- | src/ui.c | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -590,8 +590,8 @@ size_t BarUiListSongs (const BarSettings_t *settings, */ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, const PianoStation_t *curStation, const PianoSong_t *curSong, - const struct audioPlayer *player, PianoReturn_t pRet, - WaitressReturn_t wRet) { + const struct audioPlayer *player, PianoStation_t *stations, + PianoReturn_t pRet, WaitressReturn_t wRet) { pid_t chld; char pipeBuf[1024]; int pipeFd[2]; @@ -629,7 +629,7 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, player->songPlayed, curSong == NULL ? PIANO_RATE_NONE : curSong->rating ); - + if (pipe (pipeFd) == -1) { BarUiMsg (MSG_ERR, "Cannot create eventcmd pipe. (%s)\n", strerror (errno)); return; @@ -651,6 +651,30 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, int status; close (pipeFd[0]); write (pipeFd[1], pipeBuf, strlen (pipeBuf)); + + if (stations != NULL) { + /* send station list */ + PianoStation_t **sortedStations = NULL; + size_t stationCount; + sortedStations = BarSortedStations (stations, &stationCount, + settings->sortOrder); + assert (sortedStations != NULL); + + snprintf (pipeBuf, sizeof (pipeBuf), "stationCount=%zd\n", stationCount); + write (pipeFd[1], pipeBuf, strlen (pipeBuf)); + + for (size_t i = 0; i < stationCount; i++) { + const PianoStation_t *currStation = sortedStations[i]; + snprintf (pipeBuf, sizeof (pipeBuf), "station%zd=%s\n", i, + currStation->name); + write (pipeFd[1], pipeBuf, strlen (pipeBuf)); + } + free (sortedStations); + } else { + const char *msg = "stationCount=0\n"; + write (pipeFd[1], msg, strlen (msg)); + } + close (pipeFd[1]); /* wait to get rid of the zombie */ waitpid (chld, &status, 0); |