diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libpiano/piano.h | 9 | ||||
-rw-r--r-- | src/libpiano/request.c | 31 | ||||
-rw-r--r-- | src/settings.h | 3 | ||||
-rw-r--r-- | src/ui.c | 5 | ||||
-rw-r--r-- | src/ui_act.c | 47 | ||||
-rw-r--r-- | src/ui_act.h | 1 | ||||
-rw-r--r-- | src/ui_dispatch.h | 2 |
7 files changed, 85 insertions, 13 deletions
diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h index e881621..00bc744 100644 --- a/src/libpiano/piano.h +++ b/src/libpiano/piano.h @@ -208,6 +208,15 @@ typedef struct { } PianoRequestDataSearch_t; typedef struct { + char *token; + enum { + PIANO_MUSICTYPE_INVALID = 0, + PIANO_MUSICTYPE_SONG, + PIANO_MUSICTYPE_ARTIST, + } type; +} PianoRequestDataCreateStation_t; + +typedef struct { PianoStation_t *station; char *musicId; } PianoRequestDataAddSeed_t; diff --git a/src/libpiano/request.c b/src/libpiano/request.c index cb1b30a..85d6286 100644 --- a/src/libpiano/request.c +++ b/src/libpiano/request.c @@ -204,12 +204,33 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req, case PIANO_REQUEST_CREATE_STATION: { /* create new station from specified musicToken or station number */ - char *token = req->data; + PianoRequestDataCreateStation_t *reqData = req->data; - assert (token != NULL); - - json_object_object_add (j, "musicToken", - json_object_new_string (token)); + assert (reqData != NULL); + assert (reqData->token != NULL); + + if (reqData->type == PIANO_MUSICTYPE_INVALID) { + json_object_object_add (j, "musicToken", + json_object_new_string (reqData->token)); + } else { + json_object_object_add (j, "trackToken", + json_object_new_string (reqData->token)); + switch (reqData->type) { + case PIANO_MUSICTYPE_SONG: + json_object_object_add (j, "musicType", + json_object_new_string ("song")); + break; + + case PIANO_MUSICTYPE_ARTIST: + json_object_object_add (j, "musicType", + json_object_new_string ("artist")); + break; + + default: + assert (0); + break; + } + } method = "station.createStation"; break; diff --git a/src/settings.h b/src/settings.h index 346551d..488a2fb 100644 --- a/src/settings.h +++ b/src/settings.h @@ -56,8 +56,9 @@ typedef enum { BAR_KS_VOLUP = 22, BAR_KS_MANAGESTATION = 23, BAR_KS_PLAYPAUSE2 = 24, + BAR_KS_CREATESTATIONFROMSONG = 25, /* insert new shortcuts _before_ this element and increase its value */ - BAR_KS_COUNT = 25, + BAR_KS_COUNT = 26, } BarKeyShortcutId_t; #define BAR_KS_DISABLED '\x00' @@ -611,8 +611,11 @@ void BarStationFromGenre (BarApp_t *app) { } while (curGenre == NULL); /* create station */ + PianoRequestDataCreateStation_t reqData; + reqData.token = curGenre->musicId; + reqData.type = PIANO_MUSICTYPE_INVALID; BarUiMsg (&app->settings, MSG_INFO, "Adding shared station \"%s\"... ", curGenre->name); - BarUiPianoCall (app, PIANO_REQUEST_CREATE_STATION, curGenre->musicId, &pRet, &wRet); + BarUiPianoCall (app, PIANO_REQUEST_CREATE_STATION, &reqData, &pRet, &wRet); } /* replaces format characters (%x) in format string with custom strings diff --git a/src/ui_act.c b/src/ui_act.c index 298180c..70fbc9a 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -147,14 +147,45 @@ BarUiActCallback(BarUiActBanSong) { BarUiActCallback(BarUiActCreateStation) { PianoReturn_t pRet; WaitressReturn_t wRet; - char *id = NULL; + PianoRequestDataCreateStation_t reqData; - id = BarUiSelectMusicId (app, NULL, + reqData.type = PIANO_MUSICTYPE_INVALID; + reqData.token = BarUiSelectMusicId (app, NULL, "Create station from artist or title: "); - if (id != NULL) { + if (reqData.token != NULL) { BarUiMsg (&app->settings, MSG_INFO, "Creating station... "); - BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, id); - free (id); + BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData); + free (reqData.token); + BarUiActDefaultEventcmd ("stationcreate"); + } +} + +/* create new station + */ +BarUiActCallback(BarUiActCreateStationFromSong) { + PianoReturn_t pRet; + WaitressReturn_t wRet; + PianoRequestDataCreateStation_t reqData; + char selectBuf[2]; + + reqData.token = selSong->trackToken; + reqData.type = PIANO_MUSICTYPE_INVALID; + + BarUiMsg (&app->settings, MSG_QUESTION, "Create station from [s]ong or [a]rtist? "); + BarReadline (selectBuf, sizeof (selectBuf), "sa", &app->input, + BAR_RL_FULLRETURN, -1); + switch (selectBuf[0]) { + case 's': + reqData.type = PIANO_MUSICTYPE_SONG; + break; + + case 'a': + reqData.type = PIANO_MUSICTYPE_ARTIST; + break; + } + if (reqData.type != PIANO_MUSICTYPE_INVALID) { + BarUiMsg (&app->settings, MSG_INFO, "Creating station... "); + BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData); BarUiActDefaultEventcmd ("stationcreate"); } } @@ -165,12 +196,16 @@ BarUiActCallback(BarUiActAddSharedStation) { PianoReturn_t pRet; WaitressReturn_t wRet; char stationId[50]; + PianoRequestDataCreateStation_t reqData; + + reqData.token = stationId; + reqData.type = PIANO_MUSICTYPE_INVALID; BarUiMsg (&app->settings, MSG_QUESTION, "Station id: "); if (BarReadline (stationId, sizeof (stationId), "0123456789", &app->input, BAR_RL_DEFAULT, -1) > 0) { BarUiMsg (&app->settings, MSG_INFO, "Adding shared station... "); - BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, stationId); + BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData); BarUiActDefaultEventcmd ("stationaddshared"); } } diff --git a/src/ui_act.h b/src/ui_act.h index 02cb54f..d225556 100644 --- a/src/ui_act.h +++ b/src/ui_act.h @@ -37,6 +37,7 @@ BarUiActCallback(BarUiActHelp); BarUiActCallback(BarUiActAddMusic); BarUiActCallback(BarUiActBanSong); BarUiActCallback(BarUiActCreateStation); +BarUiActCallback(BarUiActCreateStationFromSong); BarUiActCallback(BarUiActAddSharedStation); BarUiActCallback(BarUiActDeleteStation); BarUiActCallback(BarUiActExplain); diff --git a/src/ui_dispatch.h b/src/ui_dispatch.h index d43642a..9d87659 100644 --- a/src/ui_dispatch.h +++ b/src/ui_dispatch.h @@ -95,6 +95,8 @@ static const BarUiDispatchAction_t dispatchActions[BAR_KS_COUNT] = { "act_managestation"}, {' ', BAR_DC_GLOBAL | BAR_DC_STATION, BarUiActPause, NULL, "act_songpause2"}, + {'v', BAR_DC_SONG, BarUiActCreateStationFromSong, + "create new station from song or artist", "act_stationcreatefromsong"}, }; #include <piano.h> |