summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2017-09-30 17:06:41 +0200
committerMichał Cichoń <michcic@gmail.com>2018-10-30 12:01:37 +0100
commitf43a0894cb1386bbb5c0c1f068a4f60192070658 (patch)
treeeb15a3cd6a326830089a92b36f735bfd63d19a32 /src
parent99fc43dec0fc2132d6b3a1a2a4c4cbd771802473 (diff)
downloadpianobar-windows-f43a0894cb1386bbb5c0c1f068a4f60192070658.tar.gz
pianobar-windows-f43a0894cb1386bbb5c0c1f068a4f60192070658.tar.bz2
pianobar-windows-f43a0894cb1386bbb5c0c1f068a4f60192070658.zip
Add tired rating to song
Now we can show a tired icon in the history. Closes #637.
Diffstat (limited to 'src')
-rw-r--r--src/libpiano/piano.h3
-rw-r--r--src/libpiano/request.c3
-rw-r--r--src/libpiano/response.c7
-rw-r--r--src/settings.c5
-rw-r--r--src/settings.h3
-rw-r--r--src/ui.c22
6 files changed, 35 insertions, 8 deletions
diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h
index 2dbf607..b595249 100644
--- a/src/libpiano/piano.h
+++ b/src/libpiano/piano.h
@@ -64,7 +64,8 @@ typedef struct PianoStation {
typedef enum {
PIANO_RATE_NONE = 0,
PIANO_RATE_LOVE = 1,
- PIANO_RATE_BAN = 2
+ PIANO_RATE_BAN = 2,
+ PIANO_RATE_TIRED = 3,
} PianoSongRating_t;
/* UNKNOWN should be 0, because memset sets audio format to 0 */
diff --git a/src/libpiano/request.c b/src/libpiano/request.c
index 5d499af..d678aac 100644
--- a/src/libpiano/request.c
+++ b/src/libpiano/request.c
@@ -186,7 +186,8 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req,
assert (reqData != NULL);
assert (reqData->trackToken != NULL);
assert (reqData->stationId != NULL);
- assert (reqData->rating != PIANO_RATE_NONE);
+ assert (reqData->rating != PIANO_RATE_NONE &&
+ reqData->rating != PIANO_RATE_TIRED);
json_object_object_add (j, "stationToken",
json_object_new_string (reqData->stationId));
diff --git a/src/libpiano/response.c b/src/libpiano/response.c
index e37824e..48a07db 100644
--- a/src/libpiano/response.c
+++ b/src/libpiano/response.c
@@ -436,8 +436,13 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
break;
}
+ case PIANO_REQUEST_ADD_TIRED_SONG: {
+ PianoSong_t * const song = req->data;
+ song->rating = PIANO_RATE_TIRED;
+ break;
+ }
+
case PIANO_REQUEST_ADD_SEED:
- case PIANO_REQUEST_ADD_TIRED_SONG:
case PIANO_REQUEST_SET_QUICKMIX:
case PIANO_REQUEST_BOOKMARK_SONG:
case PIANO_REQUEST_BOOKMARK_ARTIST:
diff --git a/src/settings.c b/src/settings.c
index 4f0ef8c..553c86e 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -129,6 +129,7 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->eventCmd);
free (settings->loveIcon);
free (settings->banIcon);
+ free (settings->tiredIcon);
free (settings->atIcon);
free (settings->npSongFormat);
free (settings->npStationFormat);
@@ -177,6 +178,7 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->sortOrder = BAR_SORT_NAME_AZ;
settings->loveIcon = strdup (" <3");
settings->banIcon = strdup (" </3");
+ settings->tiredIcon = strdup (" zZ");
settings->atIcon = strdup (" @ ");
settings->npSongFormat = strdup ("\"%t\" by \"%a\" on \"%l\"%r%@%s");
settings->npStationFormat = strdup ("Station \"%n\" (%i)");
@@ -374,6 +376,9 @@ void BarSettingsRead (BarSettings_t *settings) {
} else if (streq ("ban_icon", key)) {
free (settings->banIcon);
settings->banIcon = strdup (val);
+ } else if (streq ("tired_icon", key)) {
+ free (settings->tiredIcon);
+ settings->tiredIcon = strdup (val);
} else if (streq ("at_icon", key)) {
free (settings->atIcon);
settings->atIcon = strdup (val);
diff --git a/src/settings.h b/src/settings.h
index 0edb544..8ec69ac 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -98,8 +98,7 @@ typedef struct {
char *bindTo;
char *autostartStation;
char *eventCmd;
- char *loveIcon;
- char *banIcon;
+ char *loveIcon, *banIcon, *tiredIcon;
char *atIcon;
char *npSongFormat;
char *npStationFormat;
diff --git a/src/ui.c b/src/ui.c
index 5f683ca..30b62f7 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -614,6 +614,23 @@ void BarUiPrintStation (const BarSettings_t *settings,
BarUiMsg (settings, MSG_PLAYING, "%s", outstr);
}
+static const char *ratingToIcon (const BarSettings_t * const settings,
+ const PianoSong_t * const song) {
+ switch (song->rating) {
+ case PIANO_RATE_LOVE:
+ return settings->loveIcon;
+
+ case PIANO_RATE_BAN:
+ return settings->banIcon;
+
+ case PIANO_RATE_TIRED:
+ return settings->tiredIcon;
+
+ default:
+ return "";
+ }
+}
+
/* Print song infos (artist, title, album, loved)
* @param pianobar settings
* @param the song
@@ -623,7 +640,7 @@ void BarUiPrintSong (const BarSettings_t *settings,
const PianoSong_t *song, const PianoStation_t *station) {
char outstr[512];
const char *vals[] = {song->title, song->artist, song->album,
- (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "",
+ ratingToIcon (settings, song),
station != NULL ? settings->atIcon : "",
station != NULL ? station->name : "",
song->detailUrl};
@@ -654,8 +671,7 @@ size_t BarUiListSongs (const BarSettings_t *settings,
BarStrCaseStr (song->title, filter) != NULL))) {
char outstr[512], digits[8], duration[8] = "??:??";
const char *vals[] = {digits, song->artist, song->title,
- (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon :
- ((song->rating == PIANO_RATE_BAN) ? settings->banIcon : ""),
+ ratingToIcon (settings, song),
duration};
/* pre-format a few strings */