From 7f6457aa9b7110869e89111c42651b1055728679 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Fri, 7 Aug 2020 08:08:10 +0200 Subject: Allow changing station mode Fixes #700. --- src/ui_act.c | 82 ++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 22 deletions(-) (limited to 'src/ui_act.c') diff --git a/src/ui_act.c b/src/ui_act.c index ba340c1..43d5b6e 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -224,6 +224,15 @@ BarUiActCallback(BarUiActAddSharedStation) { } } +static void drainPlaylist (BarApp_t * const app) { + BarUiDoSkipSong (&app->player); + if (app->playlist != NULL) { + /* drain playlist */ + PianoDestroyPlaylist (PianoListNextP (app->playlist)); + app->playlist->head.next = NULL; + } +} + /* delete current station */ BarUiActCallback(BarUiActDeleteStation) { @@ -238,13 +247,7 @@ BarUiActCallback(BarUiActDeleteStation) { BarUiMsg (&app->settings, MSG_INFO, "Deleting station... "); if (BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_STATION, selStation) && selStation == app->curStation) { - BarUiDoSkipSong (&app->player); - if (app->playlist != NULL) { - /* drain playlist */ - PianoDestroyPlaylist (PianoListNextP (app->playlist)); - app->playlist->head.next = NULL; - selSong = NULL; - } + drainPlaylist (app); app->nextStation = NULL; /* XXX: usually we shoudn’t touch cur*, but DELETE_STATION destroys * station struct */ @@ -478,12 +481,7 @@ BarUiActCallback(BarUiActSelectStation) { "Select station: ", NULL, app->settings.autoselect); if (newStation != NULL) { app->nextStation = newStation; - BarUiDoSkipSong (&app->player); - if (app->playlist != NULL) { - /* drain playlist */ - PianoDestroyPlaylist (PianoListNextP (app->playlist)); - app->playlist->head.next = NULL; - } + drainPlaylist (app); } } @@ -773,7 +771,7 @@ BarUiActCallback(BarUiActManageStation) { CURLcode wRet; PianoRequestDataGetStationInfo_t reqData; char selectBuf[2], allowedActions[6], *allowedPos = allowedActions; - char question[64]; + char question[128]; memset (&reqData, 0, sizeof (reqData)); reqData.station = selStation; @@ -816,18 +814,17 @@ BarUiActCallback(BarUiActManageStation) { strcat (question, "[f]eedback"); *allowedPos++ = 'f'; } + /* station mode is always available */ + if (allowedPos != allowedActions) { + strcat (question, "? "); + } + strcat (question, "Manage [m]ode? "); + *allowedPos++ = 'm'; + *allowedPos = '\0'; - strcat (question, "? "); assert (strlen (question) < sizeof (question) / sizeof (*question)); - /* nothing to see? */ - if (allowedPos == allowedActions) { - BarUiMsg (&app->settings, MSG_ERR, "No seeds or feedback available yet.\n"); - PianoDestroyStationInfo (&reqData.info); - return; - } - BarUiMsg (&app->settings, MSG_QUESTION, "%s", question); if (BarReadline (selectBuf, sizeof (selectBuf), allowedActions, &app->input, BAR_RL_FULLRETURN, -1)) { @@ -879,6 +876,47 @@ BarUiActCallback(BarUiActManageStation) { BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_FEEDBACK, song); BarUiActDefaultEventcmd ("stationdeletefeedback"); } + } else if (selectBuf[0] == 'm') { + PianoRequestDataGetStationModes_t subReqData = + { .station = selStation }; + BarUiMsg (&app->settings, MSG_INFO, "Fetching modes... "); + BarUiActDefaultPianoCall (PIANO_REQUEST_GET_STATION_MODES, + &subReqData); + BarUiActDefaultEventcmd ("stationgetmodes"); + + const PianoStationMode_t *curMode = subReqData.retModes; + unsigned int i = 0; + PianoListForeachP (curMode) { + BarUiMsg (&app->settings, MSG_LIST, "%2i) %s: %s%s\n", i, + curMode->name, curMode->description, + curMode->active ? " (active)" : ""); + i++; + } + + BarUiMsg (&app->settings, MSG_QUESTION, "Pick a new mode: "); + int selected; + while (true) { + if (BarReadlineInt (&selected, &app->input) == 0) { + break; + } + + const PianoStationMode_t * const selMode = + PianoListGetP (subReqData.retModes, selected); + if (selMode != NULL) { + PianoRequestDataSetStationMode_t subReqDataSet = + {.station = selStation, .id = selected}; + BarUiMsg (&app->settings, MSG_INFO, + "Selecting mode \"%s\"... ", selMode->name); + if (BarUiActDefaultPianoCall ( + PIANO_REQUEST_SET_STATION_MODE, &subReqDataSet)) { + drainPlaylist (app); + } + BarUiActDefaultEventcmd ("stationsetmode"); + break; + } + } + + PianoDestroyStationMode (subReqData.retModes); } } -- cgit v1.2.3