summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2011-07-23 20:22:53 +0200
committerLars-Dominik Braun <lars@6xq.net>2011-07-25 13:47:51 +0200
commit0728b6a89de607e211bbc075b34f08495ac0d22f (patch)
tree09a42ba0970af7ba463f4adf6936289a60fbfe94
parentba936d5092e5369188e74737f820427acf3bd145 (diff)
downloadpianobar-windows-0728b6a89de607e211bbc075b34f08495ac0d22f.tar.gz
pianobar-windows-0728b6a89de607e211bbc075b34f08495ac0d22f.tar.bz2
pianobar-windows-0728b6a89de607e211bbc075b34f08495ac0d22f.zip
Added toggle to quickmix menu
Closes #141
-rw-r--r--contrib/pianobar.13
-rw-r--r--src/main.c2
-rw-r--r--src/ui.c10
-rw-r--r--src/ui.h4
-rw-r--r--src/ui_act.c44
5 files changed, 56 insertions, 7 deletions
diff --git a/contrib/pianobar.1 b/contrib/pianobar.1
index d036c1e..55300f8 100644
--- a/contrib/pianobar.1
+++ b/contrib/pianobar.1
@@ -133,7 +133,8 @@ Show next songs in playlist.
.TP
.B act_stationselectquickmix = x
-Select quickmix stations.
+Select quickmix stations. You can toggle the selection with 't', select all
+with 'a' or select none with 'n'.
.TP
.B act_voldown = (
diff --git a/src/main.c b/src/main.c
index e6f00cc..2940861 100644
--- a/src/main.c
+++ b/src/main.c
@@ -136,7 +136,7 @@ static void BarMainGetInitialStation (BarApp_t *app) {
}
/* no autostart? ask the user */
if (app->curStation == NULL) {
- app->curStation = BarUiSelectStation (app, "Select station: ");
+ app->curStation = BarUiSelectStation (app, "Select station: ", NULL);
}
if (app->curStation != NULL) {
BarUiPrintStation (&app->settings, app->curStation);
diff --git a/src/ui.c b/src/ui.c
index ab22f8a..25dee66 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -330,9 +330,11 @@ static PianoStation_t **BarSortedStations (PianoStation_t *unsortedStations,
/* let user pick one station
* @param app handle
* @param prompt string
+ * @param called if input was not a number
* @return pointer to selected station or NULL
*/
-PianoStation_t *BarUiSelectStation (BarApp_t *app, const char *prompt) {
+PianoStation_t *BarUiSelectStation (BarApp_t *app, const char *prompt,
+ BarUiSelectStationCallback_t callback) {
PianoStation_t **sortedStations = NULL, *retStation = NULL;
size_t stationCount, i;
char buf[100];
@@ -351,6 +353,7 @@ PianoStation_t *BarUiSelectStation (BarApp_t *app, const char *prompt) {
do {
for (i = 0; i < stationCount; i++) {
const PianoStation_t *currStation = sortedStations[i];
+ /* filter stations */
if (BarStrCaseStr (currStation->name, buf) != NULL) {
BarUiMsg (&app->settings, MSG_LIST, "%2i) %c%c%c %s\n", i,
currStation->useQuickMix ? 'q' : ' ',
@@ -373,6 +376,11 @@ PianoStation_t *BarUiSelectStation (BarApp_t *app, const char *prompt) {
retStation = sortedStations[selected];
}
}
+
+ /* hand over buffer to external function if it was not a station number */
+ if (retStation == NULL && callback != NULL) {
+ callback (app, buf);
+ }
} while (retStation == NULL);
free (sortedStations);
diff --git a/src/ui.h b/src/ui.h
index f86f5f3..db90646 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -33,8 +33,10 @@ THE SOFTWARE.
#include "ui_readline.h"
#include "ui_types.h"
+typedef void (*BarUiSelectStationCallback_t) (BarApp_t *app, char *buf);
+
void BarUiMsg (const BarSettings_t *, const BarUiMsg_t, const char *, ...);
-PianoStation_t *BarUiSelectStation (BarApp_t *, const char *);
+PianoStation_t *BarUiSelectStation (BarApp_t *, const char *, BarUiSelectStationCallback_t);
PianoSong_t *BarUiSelectSong (const BarSettings_t *, PianoSong_t *,
BarReadlineFds_t *);
PianoArtist_t *BarUiSelectArtist (BarApp_t *, PianoArtist_t *);
diff --git a/src/ui_act.c b/src/ui_act.c
index 22ca2da..08cd6e2 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -317,7 +317,7 @@ BarUiActCallback(BarUiActMoveSong) {
reqData.step = 0;
- reqData.to = BarUiSelectStation (app, "Move song to station: ");
+ reqData.to = BarUiSelectStation (app, "Move song to station: ", NULL);
if (reqData.to != NULL) {
/* find original station (just is case we're playing a quickmix
* station) */
@@ -379,7 +379,8 @@ BarUiActCallback(BarUiActRenameStation) {
/* play another station
*/
BarUiActCallback(BarUiActSelectStation) {
- PianoStation_t *newStation = BarUiSelectStation (app, "Select station: ");
+ PianoStation_t *newStation = BarUiSelectStation (app, "Select station: ",
+ NULL);
if (newStation != NULL) {
app->curStation = newStation;
BarUiPrintStation (&app->settings, app->curStation);
@@ -421,6 +422,42 @@ BarUiActCallback(BarUiActPrintUpcoming) {
}
}
+/* selectStation callback used by BarUiActSelectQuickMix; toggle, select
+ * all/none
+ */
+static void BarUiActQuickmixCallback (BarApp_t *app, char *buf) {
+ PianoStation_t *curStation = app->ph.stations;
+
+ switch (*buf) {
+ case 't':
+ /* toggle */
+ while (curStation != NULL) {
+ curStation->useQuickMix = !curStation->useQuickMix;
+ curStation = curStation->next;
+ }
+ *buf = '\0';
+ break;
+
+ case 'a':
+ /* enable all */
+ while (curStation != NULL) {
+ curStation->useQuickMix = true;
+ curStation = curStation->next;
+ }
+ *buf = '\0';
+ break;
+
+ case 'n':
+ /* enable none */
+ while (curStation != NULL) {
+ curStation->useQuickMix = false;
+ curStation = curStation->next;
+ }
+ *buf = '\0';
+ break;
+ }
+}
+
/* if current station is a quickmix: select stations that are played in
* quickmix
*/
@@ -433,7 +470,8 @@ BarUiActCallback(BarUiActSelectQuickMix) {
if (selStation->isQuickMix) {
PianoStation_t *toggleStation;
while ((toggleStation = BarUiSelectStation (app,
- "Toggle quickmix for station: ")) != NULL) {
+ "Toggle quickmix for station: ",
+ BarUiActQuickmixCallback)) != NULL) {
toggleStation->useQuickMix = !toggleStation->useQuickMix;
}
BarUiMsg (&app->settings, MSG_INFO, "Setting quickmix stations... ");