summaryrefslogtreecommitdiff
path: root/src/ui.c
diff options
context:
space:
mode:
authorMatthew Beckler <matthew@mbeckler.org>2011-01-13 17:18:25 -0500
committerLars-Dominik Braun <lars@6xq.net>2011-01-15 12:37:21 +0100
commitd166a010670ac829d1e6d4f37dbac075d13d9b26 (patch)
treebbca581c2de6c88fad0ecdf0e0be1c761449a15b /src/ui.c
parentc5c4dcc9cd471aa060be568491141703b96ae0f8 (diff)
downloadpianobar-windows-d166a010670ac829d1e6d4f37dbac075d13d9b26.tar.gz
pianobar-windows-d166a010670ac829d1e6d4f37dbac075d13d9b26.tar.bz2
pianobar-windows-d166a010670ac829d1e6d4f37dbac075d13d9b26.zip
Send station list to eventcmd
See issue #76
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/ui.c b/src/ui.c
index 8c8dc39..6166044 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -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);