From 51437f299b9c310969284c16507c028b5aa0941c Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 13 Apr 2009 14:25:15 +0200 Subject: More events added --- contrib/eventcmd.sh | 7 +++++- src/main.c | 10 ++++++--- src/ui.c | 17 +++++++++------ src/ui.h | 3 ++- src/ui_act.c | 61 +++++++++++++++++++++++++++++++++++++++-------------- 5 files changed, 71 insertions(+), 27 deletions(-) diff --git a/contrib/eventcmd.sh b/contrib/eventcmd.sh index c414282..a857afd 100755 --- a/contrib/eventcmd.sh +++ b/contrib/eventcmd.sh @@ -5,7 +5,7 @@ while read L; do k="`echo "$L" | cut -d '=' -f 1`" v="`echo "$L" | cut -d '=' -f 2`" export "$k=$v" -done < <(grep -e '^\(title\|artist\)=' /dev/stdin) # don't overwrite $1... +done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\)=' /dev/stdin) # don't overwrite $1... case "$1" in songstart) @@ -13,5 +13,10 @@ case "$1" in #echo "$title -- $artist" > $HOME/.config/pianobar/nowplaying # or whatever you like... ;; + *) + if [ $pRet -ne 0 ]; then + echo "naughty.notify({title = \"pianobar\", text = \"$1 failed: $pRetStr\"})" | awesome-client - + fi + ;; esac diff --git a/src/main.c b/src/main.c index 03dd137..70ffcc7 100644 --- a/src/main.c +++ b/src/main.c @@ -203,10 +203,12 @@ int main (int argc, char **argv) { curSong = curSong->next; } if (curSong == NULL) { + PianoReturn_t pRet = PIANO_RET_ERR; + BarUiMsg (MSG_INFO, "Receiving new playlist... "); PianoDestroyPlaylist (&ph); - if (BarUiPrintPianoStatus (PianoGetPlaylist (&ph, - curStation->id, settings.audioFormat)) != + if ((pRet = BarUiPrintPianoStatus (PianoGetPlaylist (&ph, + curStation->id, settings.audioFormat))) != PIANO_RET_OK) { curStation = NULL; } else { @@ -216,6 +218,8 @@ int main (int argc, char **argv) { curStation = NULL; } } + BarUiStartEventCmd (&settings, "stationfetchplaylist", + curStation, curSong, pRet); } /* song ready to play */ if (curSong != NULL) { @@ -238,7 +242,7 @@ int main (int argc, char **argv) { /* throw event */ BarUiStartEventCmd (&settings, "songstart", curStation, - curSong); + curSong, PIANO_RET_OK); /* start player */ pthread_create (&playerThread, NULL, BarPlayerThread, diff --git a/src/ui.c b/src/ui.c index e1f39fa..53df28c 100644 --- a/src/ui.c +++ b/src/ui.c @@ -378,7 +378,8 @@ inline void BarUiPrintSong (PianoSong_t *song, PianoStation_t *station) { * @param piano error-code */ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, - const PianoStation_t *curStation, const PianoSong_t *curSong) { + const PianoStation_t *curStation, const PianoSong_t *curSong, + PianoReturn_t pRet) { pid_t chld; char pipeBuf[1024]; int pipeFd[2]; @@ -394,11 +395,15 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, "artist=%s\n" "title=%s\n" "album=%s\n" - "stationName=%s\n", - curSong->artist, - curSong->title, - curSong->album, - curStation->name); + "stationName=%s\n" + "pRet=%i\n" + "pRetStr=%s\n", + curSong == NULL ? "" : curSong->artist, + curSong == NULL ? "" : curSong->title, + curSong == NULL ? "" : curSong->album, + curStation == NULL ? "" : curStation->name, + pRet, + PianoErrorToStr (pRet)); if (pipe (pipeFd) == -1) { BarUiMsg (MSG_ERR, "Cannot create eventcmd pipe. (%s)\n", strerror (errno)); diff --git a/src/ui.h b/src/ui.h index 4206983..f7c8cc4 100644 --- a/src/ui.h +++ b/src/ui.h @@ -42,6 +42,7 @@ void BarStationFromGenre (PianoHandle_t *ph, FILE *curFd); inline void BarUiPrintStation (PianoStation_t *); inline void BarUiPrintSong (PianoSong_t *, PianoStation_t *); void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, - const PianoStation_t *curStation, const PianoSong_t *curSong); + const PianoStation_t *curStation, const PianoSong_t *curSong, + PianoReturn_t); #endif /* _UI_H */ diff --git a/src/ui_act.c b/src/ui_act.c index b897d93..60525ff 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -83,6 +83,7 @@ void BarUiActHelp (BAR_KS_ARGS) { */ void BarUiActAddMusic (BAR_KS_ARGS) { char *musicId; + PianoReturn_t pRet = PIANO_RET_ERR; RETURN_IF_NO_STATION; @@ -92,36 +93,43 @@ void BarUiActAddMusic (BAR_KS_ARGS) { return; } BarUiMsg (MSG_INFO, "Adding music to station... "); - BarUiPrintPianoStatus (PianoStationAddMusic (ph, - *curStation, musicId)); + pRet = BarUiPrintPianoStatus (PianoStationAddMusic (ph, *curStation, musicId)); free (musicId); + + BarUiStartEventCmd (settings, "stationaddmusic", *curStation, *curSong, pRet); } } /* ban song */ void BarUiActBanSong (BAR_KS_ARGS) { + PianoReturn_t pRet = PIANO_RET_ERR; + RETURN_IF_NO_SONG; if (!BarTransformIfShared (ph, *curStation)) { return; } BarUiMsg (MSG_INFO, "Banning song... "); - if (BarUiPrintPianoStatus (PianoRateTrack (ph, *curSong, - PIANO_RATE_BAN)) == PIANO_RET_OK) { + if ((pRet = BarUiPrintPianoStatus (PianoRateTrack (ph, *curSong, + PIANO_RATE_BAN))) == PIANO_RET_OK) { BarUiDoSkipSong (player); } + BarUiStartEventCmd (settings, "songban", *curStation, *curSong, pRet); } /* create new station */ void BarUiActCreateStation (BAR_KS_ARGS) { char *musicId; + PianoReturn_t pRet = PIANO_RET_ERR; + musicId = BarUiSelectMusicId (ph, curFd); if (musicId != NULL) { BarUiMsg (MSG_INFO, "Creating station... "); - BarUiPrintPianoStatus (PianoCreateStation (ph, "mi", musicId)); + pRet = BarUiPrintPianoStatus (PianoCreateStation (ph, "mi", musicId)); free (musicId); + BarUiStartEventCmd (settings, "stationcreate", *curStation, *curSong, pRet); } } @@ -129,32 +137,37 @@ void BarUiActCreateStation (BAR_KS_ARGS) { */ void BarUiActAddSharedStation (BAR_KS_ARGS) { char stationId[50]; + PianoReturn_t pRet = PIANO_RET_ERR; BarUiMsg (MSG_QUESTION, "Station id: "); if (BarReadline (stationId, sizeof (stationId), "0123456789", 0, 0, curFd) > 0) { BarUiMsg (MSG_INFO, "Adding shared station... "); - BarUiPrintPianoStatus (PianoCreateStation (ph, "sh", + pRet = BarUiPrintPianoStatus (PianoCreateStation (ph, "sh", (char *) stationId)); + BarUiStartEventCmd (settings, "stationaddshared", *curStation, *curSong, pRet); } } /* delete current station */ void BarUiActDeleteStation (BAR_KS_ARGS) { + PianoReturn_t pRet = PIANO_RET_ERR; + RETURN_IF_NO_STATION; BarUiMsg (MSG_QUESTION, "Really delete \"%s\"? [yN] ", (*curStation)->name); if (BarReadlineYesNo (0, curFd)) { BarUiMsg (MSG_INFO, "Deleting station... "); - if (BarUiPrintPianoStatus (PianoDeleteStation (ph, - *curStation)) == PIANO_RET_OK) { + if ((pRet = BarUiPrintPianoStatus (PianoDeleteStation (ph, + *curStation))) == PIANO_RET_OK) { BarUiDoSkipSong (player); PianoDestroyPlaylist (ph); *curSong = NULL; *curStation = NULL; } + BarUiStartEventCmd (settings, "stationdelete", *curStation, *curSong, pRet); } } @@ -162,15 +175,17 @@ void BarUiActDeleteStation (BAR_KS_ARGS) { */ void BarUiActExplain (BAR_KS_ARGS) { char *explanation; + PianoReturn_t pRet = PIANO_RET_ERR; RETURN_IF_NO_STATION; BarUiMsg (MSG_INFO, "Receiving explanation... "); - if (BarUiPrintPianoStatus (PianoExplain (ph, *curSong, - &explanation)) == PIANO_RET_OK) { + if ((pRet = BarUiPrintPianoStatus (PianoExplain (ph, *curSong, + &explanation))) == PIANO_RET_OK) { BarUiMsg (MSG_INFO, "%s\n", explanation); free (explanation); } + BarUiStartEventCmd (settings, "songexplain", *curStation, *curSong, pRet); } /* choose genre station and add it as shared station @@ -221,13 +236,16 @@ void BarUiActDebug (BAR_KS_ARGS) { /* rate current song */ void BarUiActLoveSong (BAR_KS_ARGS) { + PianoReturn_t pRet = PIANO_RET_ERR; + RETURN_IF_NO_SONG; if (!BarTransformIfShared (ph, *curStation)) { return; } BarUiMsg (MSG_INFO, "Loving song... "); - BarUiPrintPianoStatus (PianoRateTrack (ph, *curSong, PIANO_RATE_LOVE)); + pRet = BarUiPrintPianoStatus (PianoRateTrack (ph, *curSong, PIANO_RATE_LOVE)); + BarUiStartEventCmd (settings, "songlove", *curStation, *curSong, pRet); } /* skip song @@ -240,6 +258,7 @@ void BarUiActSkipSong (BAR_KS_ARGS) { */ void BarUiActMoveSong (BAR_KS_ARGS) { PianoStation_t *moveStation, *fromStation; + PianoReturn_t pRet = PIANO_RET_ERR; RETURN_IF_NO_SONG; @@ -255,10 +274,11 @@ void BarUiActMoveSong (BAR_KS_ARGS) { BarUiMsg (MSG_ERR, "Station not found\n"); return; } - if (BarUiPrintPianoStatus (PianoMoveSong (ph, fromStation, - moveStation, *curSong)) == PIANO_RET_OK) { + if ((pRet = BarUiPrintPianoStatus (PianoMoveSong (ph, fromStation, + moveStation, *curSong))) == PIANO_RET_OK) { BarUiDoSkipSong (player); } + BarUiStartEventCmd (settings, "songmove", *curStation, *curSong, pRet); } } @@ -275,6 +295,7 @@ void BarUiActPause (BAR_KS_ARGS) { */ void BarUiActRenameStation (BAR_KS_ARGS) { char lineBuf[100]; + PianoReturn_t pRet = PIANO_RET_ERR; RETURN_IF_NO_STATION; @@ -284,8 +305,9 @@ void BarUiActRenameStation (BAR_KS_ARGS) { return; } BarUiMsg (MSG_INFO, "Renaming station... "); - BarUiPrintPianoStatus (PianoRenameStation (ph, *curStation, + pRet = BarUiPrintPianoStatus (PianoRenameStation (ph, *curStation, (char *) lineBuf)); + BarUiStartEventCmd (settings, "stationrename", *curStation, *curSong, pRet); } } @@ -304,13 +326,16 @@ void BarUiActSelectStation (BAR_KS_ARGS) { /* ban song for 1 month */ void BarUiActTempBanSong (BAR_KS_ARGS) { + PianoReturn_t pRet = PIANO_RET_ERR; + RETURN_IF_NO_SONG; BarUiMsg (MSG_INFO, "Putting song on shelf... "); - if (BarUiPrintPianoStatus (PianoSongTired (ph, *curSong)) == + if ((pRet = BarUiPrintPianoStatus (PianoSongTired (ph, *curSong))) == PIANO_RET_OK) { BarUiDoSkipSong (player); } + BarUiStartEventCmd (settings, "songshelf", *curStation, *curSong, pRet); } /* print upcoming songs @@ -336,6 +361,8 @@ void BarUiActPrintUpcoming (BAR_KS_ARGS) { * quickmix */ void BarUiActSelectQuickMix (BAR_KS_ARGS) { + PianoReturn_t pRet = PIANO_RET_ERR; + RETURN_IF_NO_STATION; if ((*curStation)->isQuickMix) { @@ -345,7 +372,9 @@ void BarUiActSelectQuickMix (BAR_KS_ARGS) { selStation->useQuickMix = !selStation->useQuickMix; } BarUiMsg (MSG_INFO, "Setting quickmix stations... "); - BarUiPrintPianoStatus (PianoSetQuickmix (ph)); + pRet = BarUiPrintPianoStatus (PianoSetQuickmix (ph)); + BarUiStartEventCmd (settings, "stationquickmixtoggle", *curStation, + *curSong, pRet); } else { BarUiMsg (MSG_ERR, "Not a QuickMix station.\n"); } -- cgit v1.2.3