summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2009-04-11 15:21:51 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2009-04-11 15:21:51 +0200
commiteedd4b036bdd5f9d488ff011b7e6947ca1edf312 (patch)
treeb88be43b5e39f216f9d1e5749be4250a0d8ca55c /src
parentd5969cabc44375026d97f7f3d92e019782cdc331 (diff)
downloadpianobar-windows-eedd4b036bdd5f9d488ff011b7e6947ca1edf312.tar.gz
pianobar-windows-eedd4b036bdd5f9d488ff011b7e6947ca1edf312.tar.bz2
pianobar-windows-eedd4b036bdd5f9d488ff011b7e6947ca1edf312.zip
Read data from fifo
You may change your current station or add shared stations via fifo now
Diffstat (limited to 'src')
-rw-r--r--src/main.c19
-rw-r--r--src/settings.h2
-rw-r--r--src/ui.c33
-rw-r--r--src/ui.h11
-rw-r--r--src/ui_act.c19
-rw-r--r--src/ui_readline.c20
-rw-r--r--src/ui_readline.h8
7 files changed, 60 insertions, 52 deletions
diff --git a/src/main.c b/src/main.c
index ec2b052..03dd137 100644
--- a/src/main.c
+++ b/src/main.c
@@ -106,13 +106,13 @@ int main (int argc, char **argv) {
if (settings.username == NULL) {
char nameBuf[100];
BarUiMsg (MSG_QUESTION, "Username: ");
- BarReadlineStr (nameBuf, sizeof (nameBuf), 0);
+ BarReadlineStr (nameBuf, sizeof (nameBuf), 0, stdin);
settings.username = strdup (nameBuf);
}
if (settings.password == NULL) {
char passBuf[100];
BarUiMsg (MSG_QUESTION, "Password: ");
- BarReadlineStr (passBuf, sizeof (passBuf), 1);
+ BarReadlineStr (passBuf, sizeof (passBuf), 1, stdin);
settings.password = strdup (passBuf);
BarUiMsg (MSG_NONE, "\n");
}
@@ -155,7 +155,7 @@ int main (int argc, char **argv) {
}
/* no autostart? ask the user */
if (curStation == NULL) {
- curStation = BarUiSelectStation (&ph, "Select station: ");
+ curStation = BarUiSelectStation (&ph, "Select station: ", stdin);
}
if (curStation != NULL) {
BarUiPrintStation (curStation);
@@ -250,19 +250,20 @@ int main (int argc, char **argv) {
/* in the meantime: wait for user actions;
* 1000ms == 1s => refresh time display every second */
if (poll (polls, pollsLen, 1000) > 0) {
+ FILE *curFd = NULL;
+
if (polls[0].revents & POLLIN) {
- buf = fgetc (stdin);
+ curFd = stdin;
} else if (polls[1].revents & POLLIN) {
- buf = fgetc (ctlFd);
+ curFd = ctlFd;
}
+ buf = fgetc (curFd);
curShortcut = settings.keys;
- /* don't show what the user enters here, we could disable
- * echoing too... */
- BarUiMsg (MSG_NONE, "\r");
+
while (curShortcut != NULL) {
if (curShortcut->key == buf) {
curShortcut->cmd (&ph, &player, &settings, &curSong,
- &curStation, &doQuit);
+ &curStation, &doQuit, curFd);
break;
}
curShortcut = curShortcut->next;
diff --git a/src/settings.h b/src/settings.h
index 3fed541..1f8b63d 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -31,7 +31,7 @@ THE SOFTWARE.
#define BAR_KS_ARGS PianoHandle_t *ph, struct audioPlayer *player, \
struct BarSettings *settings, PianoSong_t **curSong, \
- PianoStation_t **curStation, char *doQuit
+ PianoStation_t **curStation, char *doQuit, FILE *curFd
struct BarSettings {
char *username;
diff --git a/src/ui.c b/src/ui.c
index 91860cf..e1f39fa 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -149,7 +149,8 @@ PianoStation_t **BarSortedStations (PianoStation_t *unsortedStations) {
* @param piano handle
* @return pointer to selected station or NULL
*/
-PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt) {
+PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt,
+ FILE *curFd) {
PianoStation_t **ss = NULL, **ssCurr = NULL, *retStation;
int i = 0;
@@ -167,7 +168,7 @@ PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt) {
}
BarUiMsg (MSG_QUESTION, prompt);
- if (BarReadlineInt (&i) == 0) {
+ if (BarReadlineInt (&i, curFd) == 0) {
free (ss);
return NULL;
}
@@ -185,7 +186,7 @@ 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) {
+PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd) {
PianoSong_t *tmpSong = NULL;
int i = 0;
@@ -198,7 +199,7 @@ PianoSong_t *BarUiSelectSong (PianoSong_t *startSong) {
tmpSong = tmpSong->next;
}
BarUiMsg (MSG_QUESTION, "Select song: ");
- if (BarReadlineInt (&i) == 0) {
+ if (BarReadlineInt (&i, curFd) == 0) {
return NULL;
}
tmpSong = startSong;
@@ -213,7 +214,7 @@ PianoSong_t *BarUiSelectSong (PianoSong_t *startSong) {
* @param artists (linked list)
* @return pointer to selected artist or NULL on abort
*/
-PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist) {
+PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd) {
PianoArtist_t *tmpArtist = NULL;
int i = 0;
@@ -225,7 +226,7 @@ PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist) {
tmpArtist = tmpArtist->next;
}
BarUiMsg (MSG_QUESTION, "Select artist: ");
- if (BarReadlineInt (&i) == 0) {
+ if (BarReadlineInt (&i, curFd) == 0) {
return NULL;
}
tmpArtist = startArtist;
@@ -240,7 +241,7 @@ PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist) {
* @param piano handle
* @return musicId or NULL on abort/error
*/
-char *BarUiSelectMusicId (const PianoHandle_t *ph) {
+char *BarUiSelectMusicId (const PianoHandle_t *ph, FILE *curFd) {
char *musicId = NULL;
char lineBuf[100], selectBuf[2];
PianoSearchResult_t searchResult;
@@ -248,7 +249,7 @@ char *BarUiSelectMusicId (const PianoHandle_t *ph) {
PianoSong_t *tmpSong;
BarUiMsg (MSG_QUESTION, "Search for artist/title: ");
- if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0) > 0) {
+ if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0, curFd) > 0) {
BarUiMsg (MSG_INFO, "Searching... ");
if (BarUiPrintPianoStatus (PianoSearchMusic (ph, lineBuf,
&searchResult)) != PIANO_RET_OK) {
@@ -259,27 +260,27 @@ char *BarUiSelectMusicId (const PianoHandle_t *ph) {
/* songs and artists found */
BarUiMsg (MSG_QUESTION, "Is this an [a]rtist or [t]rack name? "
"Press c to abort. ");
- BarReadline (selectBuf, sizeof (selectBuf), "atc", 1, 0);
+ BarReadline (selectBuf, sizeof (selectBuf), "atc", 1, 0, curFd);
if (*selectBuf == 'a') {
- tmpArtist = BarUiSelectArtist (searchResult.artists);
+ tmpArtist = BarUiSelectArtist (searchResult.artists, curFd);
if (tmpArtist != NULL) {
musicId = strdup (tmpArtist->musicId);
}
} else if (*selectBuf == 't') {
- tmpSong = BarUiSelectSong (searchResult.songs);
+ tmpSong = BarUiSelectSong (searchResult.songs, curFd);
if (tmpSong != NULL) {
musicId = strdup (tmpSong->musicId);
}
}
} else if (searchResult.songs != NULL) {
/* songs found */
- tmpSong = BarUiSelectSong (searchResult.songs);
+ tmpSong = BarUiSelectSong (searchResult.songs, curFd);
if (tmpSong != NULL) {
musicId = strdup (tmpSong->musicId);
}
} else if (searchResult.artists != NULL) {
/* artists found */
- tmpArtist = BarUiSelectArtist (searchResult.artists);
+ tmpArtist = BarUiSelectArtist (searchResult.artists, curFd);
if (tmpArtist != NULL) {
musicId = strdup (tmpArtist->musicId);
}
@@ -295,7 +296,7 @@ char *BarUiSelectMusicId (const PianoHandle_t *ph) {
/* browse genre stations and create shared station
* @param piano handle
*/
-void BarStationFromGenre (PianoHandle_t *ph) {
+void BarStationFromGenre (PianoHandle_t *ph, FILE *curFd) {
int i;
PianoGenreCategory_t *curCat;
PianoStation_t *curStation;
@@ -319,7 +320,7 @@ void BarStationFromGenre (PianoHandle_t *ph) {
}
/* select category or exit */
BarUiMsg (MSG_QUESTION, "Select category: ");
- if (BarReadlineInt (&i) == 0) {
+ if (BarReadlineInt (&i, curFd) == 0) {
return;
}
curCat = ph->genreStations;
@@ -337,7 +338,7 @@ void BarStationFromGenre (PianoHandle_t *ph) {
curStation = curStation->next;
}
BarUiMsg (MSG_QUESTION, "Select genre: ");
- if (BarReadlineInt (&i) == 0) {
+ if (BarReadlineInt (&i, curFd) == 0) {
return;
}
curStation = curCat->stations;
diff --git a/src/ui.h b/src/ui.h
index 794003d..4206983 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -33,11 +33,12 @@ typedef enum {MSG_NONE, MSG_INFO, MSG_PLAYING, MSG_TIME, MSG_ERR,
inline void BarUiMsg (uiMsg_t type, const char *format, ...);
inline PianoReturn_t BarUiPrintPianoStatus (PianoReturn_t ret);
-PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt);
-PianoSong_t *BarUiSelectSong (PianoSong_t *startSong);
-PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist);
-char *BarUiSelectMusicId (const PianoHandle_t *ph);
-void BarStationFromGenre (PianoHandle_t *ph);
+PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt,
+ FILE *curFd);
+PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd);
+PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd);
+char *BarUiSelectMusicId (const PianoHandle_t *ph, FILE *curFd);
+void BarStationFromGenre (PianoHandle_t *ph, FILE *curFd);
inline void BarUiPrintStation (PianoStation_t *);
inline void BarUiPrintSong (PianoSong_t *, PianoStation_t *);
void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
diff --git a/src/ui_act.c b/src/ui_act.c
index 951116e..b897d93 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -86,7 +86,7 @@ void BarUiActAddMusic (BAR_KS_ARGS) {
RETURN_IF_NO_STATION;
- musicId = BarUiSelectMusicId (ph);
+ musicId = BarUiSelectMusicId (ph, curFd);
if (musicId != NULL) {
if (!BarTransformIfShared (ph, *curStation)) {
return;
@@ -117,7 +117,7 @@ void BarUiActBanSong (BAR_KS_ARGS) {
*/
void BarUiActCreateStation (BAR_KS_ARGS) {
char *musicId;
- musicId = BarUiSelectMusicId (ph);
+ musicId = BarUiSelectMusicId (ph, curFd);
if (musicId != NULL) {
BarUiMsg (MSG_INFO, "Creating station... ");
BarUiPrintPianoStatus (PianoCreateStation (ph, "mi", musicId));
@@ -131,7 +131,8 @@ void BarUiActAddSharedStation (BAR_KS_ARGS) {
char stationId[50];
BarUiMsg (MSG_QUESTION, "Station id: ");
- if (BarReadline (stationId, sizeof (stationId), "0123456789", 0, 0) > 0) {
+ if (BarReadline (stationId, sizeof (stationId), "0123456789", 0, 0,
+ curFd) > 0) {
BarUiMsg (MSG_INFO, "Adding shared station... ");
BarUiPrintPianoStatus (PianoCreateStation (ph, "sh",
(char *) stationId));
@@ -145,7 +146,7 @@ void BarUiActDeleteStation (BAR_KS_ARGS) {
BarUiMsg (MSG_QUESTION, "Really delete \"%s\"? [yN] ",
(*curStation)->name);
- if (BarReadlineYesNo (0)) {
+ if (BarReadlineYesNo (0, curFd)) {
BarUiMsg (MSG_INFO, "Deleting station... ");
if (BarUiPrintPianoStatus (PianoDeleteStation (ph,
*curStation)) == PIANO_RET_OK) {
@@ -176,7 +177,7 @@ void BarUiActExplain (BAR_KS_ARGS) {
*/
void BarUiActStationFromGenre (BAR_KS_ARGS) {
/* use genre station */
- BarStationFromGenre (ph);
+ BarStationFromGenre (ph, curFd);
}
/* print verbose song information
@@ -242,7 +243,7 @@ void BarUiActMoveSong (BAR_KS_ARGS) {
RETURN_IF_NO_SONG;
- moveStation = BarUiSelectStation (ph, "Move song to station: ");
+ moveStation = BarUiSelectStation (ph, "Move song to station: ", curFd);
if (moveStation != NULL) {
if (!BarTransformIfShared (ph, *curStation) ||
!BarTransformIfShared (ph, moveStation)) {
@@ -278,7 +279,7 @@ void BarUiActRenameStation (BAR_KS_ARGS) {
RETURN_IF_NO_STATION;
BarUiMsg (MSG_QUESTION, "New name: ");
- if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0) > 0) {
+ if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0, curFd) > 0) {
if (!BarTransformIfShared (ph, *curStation)) {
return;
}
@@ -294,7 +295,7 @@ void BarUiActSelectStation (BAR_KS_ARGS) {
BarUiDoSkipSong (player);
PianoDestroyPlaylist (ph);
*curSong = NULL;
- *curStation = BarUiSelectStation (ph, "Select station: ");
+ *curStation = BarUiSelectStation (ph, "Select station: ", curFd);
if (*curStation != NULL) {
BarUiPrintStation ((*curStation));
}
@@ -340,7 +341,7 @@ void BarUiActSelectQuickMix (BAR_KS_ARGS) {
if ((*curStation)->isQuickMix) {
PianoStation_t *selStation;
while ((selStation = BarUiSelectStation (ph,
- "Toggle quickmix for station: ")) != NULL) {
+ "Toggle quickmix for station: ", curFd)) != NULL) {
selStation->useQuickMix = !selStation->useQuickMix;
}
BarUiMsg (MSG_INFO, "Setting quickmix stations... ");
diff --git a/src/ui_readline.c b/src/ui_readline.c
index fd4eb29..3ce1d17 100644
--- a/src/ui_readline.c
+++ b/src/ui_readline.c
@@ -54,10 +54,11 @@ inline char BarReadlineIsUtf8Content (char b) {
* @param accept these characters
* @param return if buffer full (otherwise more characters are not accepted)
* @param don't echo anything (for passwords)
+ * @param read from this fd
* @return number of bytes read from stdin
*/
size_t BarReadline (char *buf, size_t bufSize, const char *mask,
- char fullReturn, char noEcho) {
+ char fullReturn, char noEcho, FILE *fd) {
int chr = 0;
size_t bufPos = 0;
size_t bufLen = 0;
@@ -65,7 +66,9 @@ size_t BarReadline (char *buf, size_t bufSize, const char *mask,
memset (buf, 0, bufSize);
- while ((chr = fgetc (stdin)) != EOF) {
+ /* if fd is a fifo fgetc will always return EOF if nobody writes to
+ * it, stdin will block */
+ while ((chr = fgetc (fd)) != EOF) {
switch (chr) {
/* EOT */
case 4:
@@ -162,19 +165,20 @@ size_t BarReadline (char *buf, size_t bufSize, const char *mask,
* @param buffer size
* @return number of bytes read from stdin
*/
-inline size_t BarReadlineStr (char *buf, size_t bufSize, char noEcho) {
- return BarReadline (buf, bufSize, NULL, 0, noEcho);
+inline size_t BarReadlineStr (char *buf, size_t bufSize, char noEcho,
+ FILE *fd) {
+ return BarReadline (buf, bufSize, NULL, 0, noEcho, fd);
}
/* Read int from stdin
* @param write result into this variable
* @return number of bytes read from stdin
*/
-size_t BarReadlineInt (int *ret) {
+size_t BarReadlineInt (int *ret, FILE *fd) {
int rlRet = 0;
char buf[16];
- rlRet = BarReadline (buf, sizeof (buf), "0123456789", 0, 0);
+ rlRet = BarReadline (buf, sizeof (buf), "0123456789", 0, 0, fd);
*ret = atoi ((char *) buf);
return rlRet;
@@ -183,9 +187,9 @@ size_t BarReadlineInt (int *ret) {
/* Yes/No?
* @param defaul (user presses enter)
*/
-int BarReadlineYesNo (char def) {
+int BarReadlineYesNo (char def, FILE *fd) {
char buf[2];
- BarReadline (buf, sizeof (buf), "yYnN", 1, 0);
+ BarReadline (buf, sizeof (buf), "yYnN", 1, 0, fd);
if (*buf == 'y' || *buf == 'Y' || (def == 1 && *buf == '\0')) {
return 1;
} else {
diff --git a/src/ui_readline.h b/src/ui_readline.h
index 3f2e886..194668a 100644
--- a/src/ui_readline.h
+++ b/src/ui_readline.h
@@ -21,8 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-size_t BarReadline (char *, size_t, const char *, char, char);
-inline size_t BarReadlineStr (char *, size_t, char);
-size_t BarReadlineInt (int *);
-int BarReadlineYesNo (char def);
+size_t BarReadline (char *, size_t, const char *, char, char, FILE *);
+inline size_t BarReadlineStr (char *, size_t, char, FILE *);
+size_t BarReadlineInt (int *, FILE *);
+int BarReadlineYesNo (char def, FILE *);