summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2012-07-05 22:00:22 +0200
committerLars-Dominik Braun <lars@6xq.net>2012-07-06 17:29:04 +0200
commit24ed240c865837b8c9d7c9240f6ef3ba9065b162 (patch)
treea6e0d2e26877ab899d451865fa4995f0b8bf382b
parentbf13c962d2db93bd09d7dd50a26978e44fb0e860 (diff)
downloadpianobar-24ed240c865837b8c9d7c9240f6ef3ba9065b162.tar.gz
pianobar-24ed240c865837b8c9d7c9240f6ef3ba9065b162.tar.bz2
pianobar-24ed240c865837b8c9d7c9240f6ef3ba9065b162.zip
Add feature: Create new station from selected song
New keybinding ā€˜vā€™, new setting act_createstationfromsong.
-rw-r--r--contrib/pianobar.14
-rw-r--r--src/libpiano/piano.h9
-rw-r--r--src/libpiano/request.c31
-rw-r--r--src/settings.h3
-rw-r--r--src/ui.c5
-rw-r--r--src/ui_act.c47
-rw-r--r--src/ui_act.h1
-rw-r--r--src/ui_dispatch.h2
8 files changed, 89 insertions, 13 deletions
diff --git a/contrib/pianobar.1 b/contrib/pianobar.1
index ddfd5e2..8c3584a 100644
--- a/contrib/pianobar.1
+++ b/contrib/pianobar.1
@@ -140,6 +140,10 @@ Ban song for one month.
Show next songs in playlist.
.TP
+.B act_stationcreatefromsong = v
+Create new station from the current song or artist.
+
+.TP
.B act_stationselectquickmix = x
Select quickmix stations. You can toggle the selection with 't', select all
with 'a' or select none with 'n'.
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'
diff --git a/src/ui.c b/src/ui.c
index b1a6407..8543018 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -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>