summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2010-11-18 21:21:55 +0100
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2010-11-21 12:35:28 +0100
commit2b31c97de6fa541719cd26f9a61053cfc0e71203 (patch)
treed131aadb5277d293199666651810c547f4d0152d /src
parentc58688994ae409c4d9c748a9bc2add16ca02e6de (diff)
downloadpianobar-2b31c97de6fa541719cd26f9a61053cfc0e71203.tar.gz
pianobar-2b31c97de6fa541719cd26f9a61053cfc0e71203.tar.bz2
pianobar-2b31c97de6fa541719cd26f9a61053cfc0e71203.zip
Show custom rating icon in upcoming/history song list
Closes issue #54
Diffstat (limited to 'src')
-rw-r--r--src/main.c3
-rw-r--r--src/pianobar.18
-rw-r--r--src/settings.c14
-rw-r--r--src/settings.h2
-rw-r--r--src/ui.c50
-rw-r--r--src/ui.h6
-rw-r--r--src/ui_act.c14
7 files changed, 71 insertions, 26 deletions
diff --git a/src/main.c b/src/main.c
index d401e65..b582baf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -259,7 +259,8 @@ int main (int argc, char **argv) {
}
/* song ready to play */
if (app.playlist != NULL) {
- BarUiPrintSong (app.playlist, app.curStation->isQuickMix ?
+ BarUiPrintSong (&app.settings, app.playlist,
+ app.curStation->isQuickMix ?
PianoFindStationById (app.ph.stations,
app.playlist->stationId) : NULL);
diff --git a/src/pianobar.1 b/src/pianobar.1
index ac262ef..a27b606 100644
--- a/src/pianobar.1
+++ b/src/pianobar.1
@@ -140,6 +140,10 @@ or the key you defined in
.B act_songinfo.
.TP
+.B ban_icon = </3
+Icon for banned songs.
+
+.TP
.B control_proxy = http://host:port/
Non-american users need a proxy to use pandora.com. Only the xmlrpc interface
will use this proxy. The music is streamed directly.
@@ -154,6 +158,10 @@ File that is executed when event occurs. See section
Keep a history of the last n songs (5, by default). You can rate these songs.
.TP
+.B love_icon = <3
+Icon for loved songs.
+
+.TP
.B password = plaintext_password
Your pandora.com password. Plain-text.
diff --git a/src/settings.c b/src/settings.c
index d085aff..43d2ca4 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -77,6 +77,8 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->password);
free (settings->autostartStation);
free (settings->eventCmd);
+ free (settings->loveIcon);
+ free (settings->banIcon);
memset (settings, 0, sizeof (*settings));
}
@@ -175,6 +177,10 @@ void BarSettingsRead (BarSettings_t *settings) {
break;
}
}
+ } else if (strcmp ("love_icon", key) == 0) {
+ settings->loveIcon = strdup (val);
+ } else if (strcmp ("ban_icon", key) == 0) {
+ settings->banIcon = strdup (val);
}
}
@@ -186,5 +192,13 @@ void BarSettingsRead (BarSettings_t *settings) {
}
}
+ /* use default strings */
+ if (settings->loveIcon == NULL) {
+ settings->loveIcon = strdup ("<3");
+ }
+ if (settings->banIcon == NULL) {
+ settings->banIcon = strdup ("</3");
+ }
+
fclose (configfd);
}
diff --git a/src/settings.h b/src/settings.h
index f977a47..078c337 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -77,6 +77,8 @@ typedef struct {
char keys[BAR_KS_COUNT];
char *autostartStation;
char *eventCmd;
+ char *loveIcon;
+ char *banIcon;
} BarSettings_t;
void BarSettingsInit (BarSettings_t *);
diff --git a/src/ui.c b/src/ui.c
index 480dc83..509cfa5 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -330,27 +330,24 @@ PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt,
* @param song list
* @return pointer to selected item in song list or NULL
*/
-PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd) {
+PianoSong_t *BarUiSelectSong (const BarSettings_t *settings,
+ PianoSong_t *startSong, FILE *curFd) {
PianoSong_t *tmpSong = NULL;
int i = 0;
- /* print all songs */
- tmpSong = startSong;
- while (tmpSong != NULL) {
- BarUiMsg (MSG_LIST, "%2u) %s - %s\n", i, tmpSong->artist,
- tmpSong->title);
- i++;
- tmpSong = tmpSong->next;
- }
+ i = BarUiListSongs (settings, startSong);
+
BarUiMsg (MSG_QUESTION, "Select song: ");
if (BarReadlineInt (&i, curFd) == 0) {
return NULL;
}
+
tmpSong = startSong;
while (tmpSong != NULL && i > 0) {
tmpSong = tmpSong->next;
i--;
}
+
return tmpSong;
}
@@ -436,14 +433,16 @@ char *BarUiSelectMusicId (BarApp_t *app, FILE *curFd, char *similarToId) {
musicId = strdup (tmpArtist->musicId);
}
} else if (*selectBuf == 't') {
- tmpSong = BarUiSelectSong (searchResult.songs, curFd);
+ tmpSong = BarUiSelectSong (&app->settings, searchResult.songs,
+ curFd);
if (tmpSong != NULL) {
musicId = strdup (tmpSong->musicId);
}
}
} else if (searchResult.songs != NULL) {
/* songs found */
- tmpSong = BarUiSelectSong (searchResult.songs, curFd);
+ tmpSong = BarUiSelectSong (&app->settings, searchResult.songs,
+ curFd);
if (tmpSong != NULL) {
musicId = strdup (tmpSong->musicId);
}
@@ -539,14 +538,37 @@ inline void BarUiPrintStation (PianoStation_t *station) {
* @param the song
* @param alternative station info (show real station for quickmix, e.g.)
*/
-inline void BarUiPrintSong (PianoSong_t *song, PianoStation_t *station) {
- BarUiMsg (MSG_PLAYING, "\"%s\" by \"%s\" on \"%s\"%s%s%s\n",
+inline void BarUiPrintSong (const BarSettings_t *settings,
+ const PianoSong_t *song, const PianoStation_t *station) {
+ BarUiMsg (MSG_PLAYING, "\"%s\" by \"%s\" on \"%s\"%s%s%s%s\n",
song->title, song->artist, song->album,
- (song->rating == PIANO_RATE_LOVE) ? " <3" : "",
+ (song->rating == PIANO_RATE_LOVE) ? " " : "",
+ (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "",
station != NULL ? " @ " : "",
station != NULL ? station->name : "");
}
+/* Print list of songs
+ * @param pianobar settings
+ * @param linked list of songs
+ * @return # of songs
+ */
+size_t BarUiListSongs (const BarSettings_t *settings,
+ const PianoSong_t *song) {
+ size_t i = 0;
+
+ while (song != NULL) {
+ BarUiMsg (MSG_LIST, "%2lu) %s - %s %s%s\n", i, song->artist,
+ song->title,
+ (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "",
+ (song->rating == PIANO_RATE_BAN) ? settings->banIcon : "");
+ song = song->next;
+ i++;
+ }
+
+ return i;
+}
+
/* Excute external event handler
* @param settings containing the cmdline
* @param event type
diff --git a/src/ui.h b/src/ui.h
index 9a4dcb5..582ab5c 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -38,12 +38,14 @@ void BarUiMsg (uiMsg_t type, const char *format, ...);
PianoReturn_t BarUiPrintPianoStatus (PianoReturn_t ret);
PianoStation_t *BarUiSelectStation (PianoHandle_t *, const char *,
BarStationSorting_t, FILE *);
-PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd);
+PianoSong_t *BarUiSelectSong (const BarSettings_t *, PianoSong_t *, FILE *);
PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd);
char *BarUiSelectMusicId (BarApp_t *, FILE *, char *);
void BarStationFromGenre (BarApp_t *, FILE *);
void BarUiPrintStation (PianoStation_t *);
-void BarUiPrintSong (PianoSong_t *, PianoStation_t *);
+void BarUiPrintSong (const BarSettings_t *, const PianoSong_t *,
+ const PianoStation_t *);
+size_t BarUiListSongs (const BarSettings_t *, const PianoSong_t *);
void BarUiStartEventCmd (const BarSettings_t *, const char *,
const PianoStation_t *, const PianoSong_t *, const struct audioPlayer *,
PianoReturn_t, WaitressReturn_t);
diff --git a/src/ui_act.c b/src/ui_act.c
index 0f66986..0f0cac2 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -254,7 +254,8 @@ BarUiActCallback(BarUiActSongInfo) {
BarUiPrintStation (app->curStation);
/* print real station if quickmix */
- BarUiPrintSong (app->playlist, app->curStation->isQuickMix ?
+ BarUiPrintSong (&app->settings, app->playlist,
+ app->curStation->isQuickMix ?
PianoFindStationById (app->ph.stations, app->playlist->stationId) :
NULL);
}
@@ -420,13 +421,7 @@ BarUiActCallback(BarUiActPrintUpcoming) {
PianoSong_t *nextSong = app->playlist->next;
if (nextSong != NULL) {
- int i = 0;
- while (nextSong != NULL) {
- BarUiMsg (MSG_LIST, "%2i) \"%s\" by \"%s\"\n", i, nextSong->title,
- nextSong->artist);
- nextSong = nextSong->next;
- i++;
- }
+ BarUiListSongs (&app->settings, nextSong);
} else {
BarUiMsg (MSG_INFO, "No songs in queue.\n");
}
@@ -472,7 +467,8 @@ BarUiActCallback(BarUiActHistory) {
PianoSong_t *selectedSong;
if (app->songHistory != NULL) {
- selectedSong = BarUiSelectSong (app->songHistory, curFd);
+ selectedSong = BarUiSelectSong (&app->settings, app->songHistory,
+ curFd);
if (selectedSong != NULL) {
/* use user-defined keybindings */
allowedBuf[0] = app->settings.keys[BAR_KS_LOVE];