summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c36
-rw-r--r--src/player.c20
-rw-r--r--src/player.h4
-rw-r--r--src/settings.c65
-rw-r--r--src/settings.h10
-rw-r--r--src/ui.c229
-rw-r--r--src/ui.h14
-rw-r--r--src/ui_act.c85
-rw-r--r--src/ui_dispatch.c4
-rw-r--r--src/ui_types.h38
10 files changed, 345 insertions, 160 deletions
diff --git a/src/main.c b/src/main.c
index 6886afc..3fcb2da 100644
--- a/src/main.c
+++ b/src/main.c
@@ -85,7 +85,7 @@ static bool BarMainLoginUser (BarApp_t *app) {
reqData.password = app->settings.password;
reqData.step = 0;
- BarUiMsg (MSG_INFO, "Login... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Login... ");
ret = BarUiPianoCall (app, PIANO_REQUEST_LOGIN, &reqData, &pRet, &wRet);
BarUiStartEventCmd (&app->settings, "userlogin", NULL, NULL, &app->player,
NULL, pRet, wRet);
@@ -98,13 +98,13 @@ static void BarMainGetLoginCredentials (BarSettings_t *settings,
BarReadlineFds_t *input) {
if (settings->username == NULL) {
char nameBuf[100];
- BarUiMsg (MSG_QUESTION, "Username: ");
+ BarUiMsg (settings, MSG_QUESTION, "Username: ");
BarReadlineStr (nameBuf, sizeof (nameBuf), input, BAR_RL_DEFAULT);
settings->username = strdup (nameBuf);
}
if (settings->password == NULL) {
char passBuf[100];
- BarUiMsg (MSG_QUESTION, "Password: ");
+ BarUiMsg (settings, MSG_QUESTION, "Password: ");
BarReadlineStr (passBuf, sizeof (passBuf), input, BAR_RL_NOECHO);
write (STDIN_FILENO, "\n", 1);
settings->password = strdup (passBuf);
@@ -118,7 +118,7 @@ static bool BarMainGetStations (BarApp_t *app) {
WaitressReturn_t wRet;
bool ret;
- BarUiMsg (MSG_INFO, "Get stations... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Get stations... ");
ret = BarUiPianoCall (app, PIANO_REQUEST_GET_STATIONS, NULL, &pRet, &wRet);
BarUiStartEventCmd (&app->settings, "usergetstations", NULL, NULL, &app->player,
app->ph.stations, pRet, wRet);
@@ -133,16 +133,16 @@ static void BarMainGetInitialStation (BarApp_t *app) {
app->curStation = PianoFindStationById (app->ph.stations,
app->settings.autostartStation);
if (app->curStation == NULL) {
- BarUiMsg (MSG_ERR, "Error: Autostart station not found.\n");
+ BarUiMsg (&app->settings, MSG_ERR,
+ "Error: Autostart station not found.\n");
}
}
/* no autostart? ask the user */
if (app->curStation == NULL) {
- app->curStation = BarUiSelectStation (&app->ph, "Select station: ",
- app->settings.sortOrder, &app->input);
+ app->curStation = BarUiSelectStation (app, "Select station: ");
}
if (app->curStation != NULL) {
- BarUiPrintStation (app->curStation);
+ BarUiPrintStation (&app->settings, app->curStation);
}
}
@@ -166,14 +166,14 @@ static void BarMainGetPlaylist (BarApp_t *app) {
reqData.station = app->curStation;
reqData.format = app->settings.audioFormat;
- BarUiMsg (MSG_INFO, "Receiving new playlist... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Receiving new playlist... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_GET_PLAYLIST,
&reqData, &pRet, &wRet)) {
app->curStation = NULL;
} else {
app->playlist = reqData.retPlaylist;
if (app->playlist == NULL) {
- BarUiMsg (MSG_INFO, "No tracks left.\n");
+ BarUiMsg (&app->settings, MSG_INFO, "No tracks left.\n");
app->curStation = NULL;
}
}
@@ -190,7 +190,7 @@ static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
app->playlist->stationId) : NULL);
if (app->playlist->audioUrl == NULL) {
- BarUiMsg (MSG_ERR, "Invalid song url.\n");
+ BarUiMsg (&app->settings, MSG_ERR, "Invalid song url.\n");
} else {
/* setup player */
memset (&app->player, 0, sizeof (app->player));
@@ -212,6 +212,7 @@ static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
app->player.gain = app->playlist->fileGain;
app->player.scale = BarPlayerCalcScale (app->player.gain + app->settings.volume);
app->player.audioFormat = app->playlist->audioFormat;
+ app->player.settings = &app->settings;
/* throw event */
BarUiStartEventCmd (&app->settings, "songstart",
@@ -261,7 +262,7 @@ static void BarMainPrintTime (BarApp_t *app) {
sign = POSITIVE;
songRemaining = -songRemaining;
}
- BarUiMsg (MSG_TIME, "%c%02i:%02i/%02i:%02i\r",
+ BarUiMsg (&app->settings, MSG_TIME, "%c%02i:%02i/%02i:%02i\r",
(sign == POSITIVE ? '+' : '-'),
songRemaining / 60, songRemaining % 60,
app->player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR / 60,
@@ -356,11 +357,13 @@ int main (int argc, char **argv) {
BarSettingsInit (&app.settings);
BarSettingsRead (&app.settings);
- BarUiMsg (MSG_NONE, "Welcome to " PACKAGE " (" VERSION ")! ");
+ BarUiMsg (&app.settings, MSG_NONE,
+ "Welcome to " PACKAGE " (" VERSION ")! ");
if (app.settings.keys[BAR_KS_HELP] == BAR_KS_DISABLED) {
- BarUiMsg (MSG_NONE, "\n");
+ BarUiMsg (&app.settings, MSG_NONE, "\n");
} else {
- BarUiMsg (MSG_NONE, "Press %c for a list of commands.\n",
+ BarUiMsg (&app.settings, MSG_NONE,
+ "Press %c for a list of commands.\n",
app.settings.keys[BAR_KS_HELP]);
}
@@ -375,7 +378,8 @@ int main (int argc, char **argv) {
app.input.fds[1] = open (ctlPath, O_RDWR);
if (app.input.fds[1] != -1) {
FD_SET(app.input.fds[1], &app.input.set);
- BarUiMsg (MSG_INFO, "Control fifo at %s opened\n", ctlPath);
+ BarUiMsg (&app.settings, MSG_INFO, "Control fifo at %s opened\n",
+ ctlPath);
}
app.input.maxfd = app.input.fds[0] > app.input.fds[1] ? app.input.fds[0] :
app.input.fds[1];
diff --git a/src/player.c b/src/player.c
index 3e69804..b45b40d 100644
--- a/src/player.c
+++ b/src/player.c
@@ -33,6 +33,7 @@ THE SOFTWARE.
#include "player.h"
#include "config.h"
#include "ui.h"
+#include "ui_types.h"
#define bigToHostEndian32(x) ntohl(x)
@@ -88,7 +89,7 @@ static inline int BarPlayerBufferFill (struct audioPlayer *player, char *data,
size_t dataSize) {
/* fill buffer */
if (player->bufferFilled + dataSize > sizeof (player->buffer)) {
- BarUiMsg (MSG_ERR, "Buffer overflow!\n");
+ BarUiMsg (player->settings, MSG_ERR, "Buffer overflow!\n");
return 0;
}
memcpy (player->buffer+player->bufferFilled, data, dataSize);
@@ -140,7 +141,7 @@ static WaitressCbReturn_t BarPlayerAACCb (void *ptr, size_t size, void *stream)
player->buffer + player->bufferRead,
player->sampleSize[player->sampleSizeCurr]);
if (frameInfo.error != 0) {
- BarUiMsg (MSG_ERR, "Decoding error: %s\n",
+ BarUiMsg (player->settings, MSG_ERR, "Decoding error: %s\n",
NeAACDecGetErrorMessage (frameInfo.error));
break;
}
@@ -189,8 +190,8 @@ static WaitressCbReturn_t BarPlayerAACCb (void *ptr, size_t size, void *stream)
&player->channels);
player->bufferRead += 5;
if (err != 0) {
- BarUiMsg (MSG_ERR, "Error while "
- "initializing audio decoder"
+ BarUiMsg (player->settings, MSG_ERR,
+ "Error while initializing audio decoder "
"(%i)\n", err);
return WAITRESS_CB_RET_ERR;
}
@@ -204,7 +205,8 @@ static WaitressCbReturn_t BarPlayerAACCb (void *ptr, size_t size, void *stream)
&format, NULL)) == NULL) {
/* we're not interested in the errno */
player->aoError = 1;
- BarUiMsg (MSG_ERR, "Cannot open audio device\n");
+ BarUiMsg (player->settings, MSG_ERR,
+ "Cannot open audio device\n");
return WAITRESS_CB_RET_ERR;
}
player->mode = PLAYER_AUDIO_INITIALIZED;
@@ -329,7 +331,8 @@ static WaitressCbReturn_t BarPlayerMp3Cb (void *ptr, size_t size, void *stream)
if (mad_frame_decode (&player->mp3Frame, &player->mp3Stream) != 0) {
if (player->mp3Stream.error != MAD_ERROR_BUFLEN) {
- BarUiMsg (MSG_ERR, "mp3 decoding error: %s\n",
+ BarUiMsg (player->settings, MSG_ERR,
+ "mp3 decoding error: %s\n",
mad_stream_errorstr (&player->mp3Stream));
return WAITRESS_CB_RET_ERR;
} else {
@@ -362,7 +365,8 @@ static WaitressCbReturn_t BarPlayerMp3Cb (void *ptr, size_t size, void *stream)
if ((player->audioOutDevice = ao_open_live (audioOutDriver,
&format, NULL)) == NULL) {
player->aoError = 1;
- BarUiMsg (MSG_ERR, "Cannot open audio device\n");
+ BarUiMsg (player->settings, MSG_ERR,
+ "Cannot open audio device\n");
return WAITRESS_CB_RET_ERR;
}
@@ -444,7 +448,7 @@ void *BarPlayerThread (void *data) {
#endif /* ENABLE_MAD */
default:
- BarUiMsg (MSG_ERR, "Unsupported audio format!\n");
+ BarUiMsg (player->settings, MSG_ERR, "Unsupported audio format!\n");
return PLAYER_RET_OK;
break;
}
diff --git a/src/player.h b/src/player.h
index 66d9230..494fe51 100644
--- a/src/player.h
+++ b/src/player.h
@@ -42,6 +42,8 @@ THE SOFTWARE.
#include <piano.h>
#include <waitress.h>
+#include "settings.h"
+
#define BAR_PLAYER_MS_TO_S_FACTOR 1000
struct audioPlayer {
@@ -99,6 +101,8 @@ struct audioPlayer {
char doQuit;
pthread_mutex_t pauseMutex;
+
+ const BarSettings_t *settings;
};
enum {PLAYER_RET_OK = 0, PLAYER_RET_ERR = 1};
diff --git a/src/settings.c b/src/settings.c
index dddc05c..7b46df3 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -85,6 +85,12 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->eventCmd);
free (settings->loveIcon);
free (settings->banIcon);
+ free (settings->npSongFormat);
+ free (settings->npStationFormat);
+ for (size_t i = 0; i < MSG_COUNT; i++) {
+ free (settings->msgFormat[i].prefix);
+ free (settings->msgFormat[i].postfix);
+ }
memset (settings, 0, sizeof (*settings));
}
@@ -95,6 +101,7 @@ void BarSettingsDestroy (BarSettings_t *settings) {
void BarSettingsRead (BarSettings_t *settings) {
char configfile[PATH_MAX], key[256], val[256];
FILE *configfd;
+ static const char *formatMsgPrefix = "format_msg_";
assert (sizeof (settings->keys) / sizeof (*settings->keys) ==
sizeof (dispatchActions) / sizeof (*dispatchActions));
@@ -110,8 +117,26 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->history = 5;
settings->volume = 0;
settings->sortOrder = BAR_SORT_NAME_AZ;
- settings->loveIcon = strdup ("<3");
- settings->banIcon = strdup ("</3");
+ settings->loveIcon = strdup (" <3");
+ settings->banIcon = strdup (" </3");
+ settings->npSongFormat = strdup ("\"%t\" by \"%a\" on \"%l\"%r%@%s");
+ settings->npStationFormat = strdup ("Station \"%n\" (%i)");
+
+ settings->msgFormat[MSG_NONE].prefix = NULL;
+ settings->msgFormat[MSG_NONE].postfix = NULL;
+ settings->msgFormat[MSG_INFO].prefix = strdup ("(i) ");
+ settings->msgFormat[MSG_INFO].postfix = NULL;
+ settings->msgFormat[MSG_PLAYING].prefix = strdup ("|> ");
+ settings->msgFormat[MSG_PLAYING].postfix = NULL;
+ settings->msgFormat[MSG_TIME].prefix = strdup ("# ");
+ settings->msgFormat[MSG_TIME].postfix = NULL;
+ settings->msgFormat[MSG_ERR].prefix = strdup ("/!\\ ");
+ settings->msgFormat[MSG_ERR].postfix = NULL;
+ settings->msgFormat[MSG_QUESTION].prefix = strdup ("[?] ");
+ settings->msgFormat[MSG_QUESTION].postfix = NULL;
+ settings->msgFormat[MSG_LIST].prefix = strdup ("\t");
+ settings->msgFormat[MSG_LIST].postfix = NULL;
+
for (size_t i = 0; i < BAR_KS_COUNT; i++) {
settings->keys[i] = dispatchActions[i].defaultKey;
}
@@ -188,6 +213,42 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->banIcon = strdup (val);
} else if (streq ("volume", key)) {
settings->volume = atoi (val);
+ } else if (streq ("format_nowplaying_song", key)) {
+ free (settings->npSongFormat);
+ settings->npSongFormat = strdup (val);
+ } else if (streq ("format_nowplaying_station", key)) {
+ free (settings->npStationFormat);
+ settings->npStationFormat = strdup (val);
+ } else if (strncmp (formatMsgPrefix, key,
+ strlen (formatMsgPrefix)) == 0) {
+ static const char *mapping[] = {"none", "info", "nowplaying",
+ "time", "err", "question", "list"};
+ const char *typeStart = key + strlen (formatMsgPrefix);
+ for (size_t i = 0; i < sizeof (mapping) / sizeof (*mapping); i++) {
+ if (streq (typeStart, mapping[i])) {
+ const char *formatPos = strstr (val, "%s");
+
+ /* keep default if there is no format character */
+ if (formatPos != NULL) {
+ BarMsgFormatStr_t *format = &settings->msgFormat[i];
+
+ free (format->prefix);
+ free (format->postfix);
+
+ const size_t prefixLen = formatPos - val;
+ format->prefix = calloc (prefixLen + 1,
+ sizeof (*format->prefix));
+ memcpy (format->prefix, val, prefixLen);
+
+ const size_t postfixLen = strlen (val) -
+ (formatPos-val) - 2;
+ format->postfix = calloc (postfixLen + 1,
+ sizeof (*format->postfix));
+ memcpy (format->postfix, formatPos+2, postfixLen);
+ }
+ break;
+ }
+ }
}
}
diff --git a/src/settings.h b/src/settings.h
index 3bbeaa6..91ea8fe 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -70,6 +70,13 @@ typedef enum {
BAR_SORT_COUNT = 6,
} BarStationSorting_t;
+#include "ui_types.h"
+
+typedef struct {
+ char *prefix;
+ char *postfix;
+} BarMsgFormatStr_t;
+
typedef struct {
unsigned int history;
int volume;
@@ -84,6 +91,9 @@ typedef struct {
char *eventCmd;
char *loveIcon;
char *banIcon;
+ char *npSongFormat;
+ char *npStationFormat;
+ BarMsgFormatStr_t msgFormat[MSG_COUNT];
} BarSettings_t;
void BarSettingsInit (BarSettings_t *);
diff --git a/src/ui.c b/src/ui.c
index fd2302d..69f7bec 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -90,57 +90,42 @@ static const char *BarStrCaseStr (const char *haystack, const char *needle) {
/* output message and flush stdout
* @param message
*/
-inline void BarUiMsg (uiMsg_t type, const char *format, ...) {
- #define ANSI_CLEAR_LINE "\033[2K"
+void BarUiMsg (const BarSettings_t *settings, const BarUiMsg_t type,
+ const char *format, ...) {
va_list fmtargs;
+ assert (settings != NULL);
+ assert (type < MSG_COUNT);
+ assert (format != NULL);
+
switch (type) {
case MSG_INFO:
- printf (ANSI_CLEAR_LINE "(i) ");
- break;
-
case MSG_PLAYING:
- printf (ANSI_CLEAR_LINE "|> ");
- break;
-
case MSG_TIME:
- printf (ANSI_CLEAR_LINE "# ");
- break;
-
case MSG_ERR:
- printf (ANSI_CLEAR_LINE "/!\\ ");
- break;
-
case MSG_QUESTION:
- printf (ANSI_CLEAR_LINE "[?] ");
- break;
-
case MSG_LIST:
- printf (ANSI_CLEAR_LINE "\t");
+ /* print ANSI clear line */
+ fputs ("\033[2K", stdout);
break;
-
+
default:
break;
}
+
+ if (settings->msgFormat[type].prefix != NULL) {
+ fputs (settings->msgFormat[type].prefix, stdout);
+ }
+
va_start (fmtargs, format);
vprintf (format, fmtargs);
va_end (fmtargs);
- fflush (stdout);
-
- #undef ANSI_CLEAR_LINE
-}
-
-/* prints human readable status message based on return value
- * @param piano return value
- */
-inline PianoReturn_t BarUiPrintPianoStatus (PianoReturn_t ret) {
- if (ret != PIANO_RET_OK) {
- BarUiMsg (MSG_NONE, "Error: %s\n", PianoErrorToStr (ret));
- } else {
- BarUiMsg (MSG_NONE, "Ok.\n");
+ if (settings->msgFormat[type].postfix != NULL) {
+ fputs (settings->msgFormat[type].postfix, stdout);
}
- return ret;
+
+ fflush (stdout);
}
/* fetch http resource (post request)
@@ -177,14 +162,14 @@ int BarUiPianoCall (BarApp_t * const app, PianoRequestType_t type,
*pRet = PianoRequest (&app->ph, &req, type);
if (*pRet != PIANO_RET_OK) {
- BarUiMsg (MSG_NONE, "Error: %s\n", PianoErrorToStr (*pRet));
+ BarUiMsg (&app->settings, MSG_NONE, "Error: %s\n", PianoErrorToStr (*pRet));
PianoDestroyRequest (&req);
return 0;
}
*wRet = BarPianoHttpRequest (&app->waith, &req);
if (*wRet != WAITRESS_RET_OK) {
- BarUiMsg (MSG_NONE, "Network error: %s\n", WaitressErrorToStr (*wRet));
+ BarUiMsg (&app->settings, MSG_NONE, "Network error: %s\n", WaitressErrorToStr (*wRet));
if (req.responseData != NULL) {
free (req.responseData);
}
@@ -205,7 +190,7 @@ int BarUiPianoCall (BarApp_t * const app, PianoRequestType_t type,
reqData.password = app->settings.password;
reqData.step = 0;
- BarUiMsg (MSG_NONE, "Reauthentication required... ");
+ BarUiMsg (&app->settings, MSG_NONE, "Reauthentication required... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_LOGIN, &reqData, &authpRet,
&authwRet)) {
*pRet = authpRet;
@@ -218,17 +203,17 @@ int BarUiPianoCall (BarApp_t * const app, PianoRequestType_t type,
} else {
/* try again */
*pRet = PIANO_RET_CONTINUE_REQUEST;
- BarUiMsg (MSG_INFO, "Trying again... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Trying again... ");
}
} else if (*pRet != PIANO_RET_OK) {
- BarUiMsg (MSG_NONE, "Error: %s\n", PianoErrorToStr (*pRet));
+ BarUiMsg (&app->settings, MSG_NONE, "Error: %s\n", PianoErrorToStr (*pRet));
if (req.responseData != NULL) {
free (req.responseData);
}
PianoDestroyRequest (&req);
return 0;
} else {
- BarUiMsg (MSG_NONE, "Ok.\n");
+ BarUiMsg (&app->settings, MSG_NONE, "Ok.\n");
}
}
/* we can destroy the request at this point, even when this call needs
@@ -345,27 +330,27 @@ static PianoStation_t **BarSortedStations (PianoStation_t *unsortedStations,
* @param input fds
* @return pointer to selected station or NULL
*/
-PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt,
- BarStationSorting_t order, BarReadlineFds_t *input) {
+PianoStation_t *BarUiSelectStation (BarApp_t *app, const char *prompt) {
PianoStation_t **sortedStations = NULL, *retStation = NULL;
size_t stationCount, i;
char buf[100];
- if (ph->stations == NULL) {
- BarUiMsg (MSG_ERR, "No station available.\n");
+ if (app->ph.stations == NULL) {
+ BarUiMsg (&app->settings, MSG_ERR, "No station available.\n");
return NULL;
}
memset (buf, 0, sizeof (buf));
/* sort and print stations */
- sortedStations = BarSortedStations (ph->stations, &stationCount, order);
+ sortedStations = BarSortedStations (app->ph.stations, &stationCount,
+ app->settings.sortOrder);
do {
for (i = 0; i < stationCount; i++) {
const PianoStation_t *currStation = sortedStations[i];
if (BarStrCaseStr (currStation->name, buf) != NULL) {
- BarUiMsg (MSG_LIST, "%2i) %c%c%c %s\n", i,
+ BarUiMsg (&app->settings, MSG_LIST, "%2i) %c%c%c %s\n", i,
currStation->useQuickMix ? 'q' : ' ',
currStation->isQuickMix ? 'Q' : ' ',
!currStation->isCreator ? 'S' : ' ',
@@ -373,8 +358,9 @@ PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt,
}
}
- BarUiMsg (MSG_QUESTION, prompt);
- if (BarReadlineStr (buf, sizeof (buf), input, BAR_RL_DEFAULT) == 0) {
+ BarUiMsg (&app->settings, MSG_QUESTION, prompt);
+ if (BarReadlineStr (buf, sizeof (buf), &app->input,
+ BAR_RL_DEFAULT) == 0) {
free (sortedStations);
return NULL;
}
@@ -407,7 +393,7 @@ PianoSong_t *BarUiSelectSong (const BarSettings_t *settings,
do {
BarUiListSongs (settings, startSong, buf);
- BarUiMsg (MSG_QUESTION, "Select song: ");
+ BarUiMsg (settings, MSG_QUESTION, "Select song: ");
if (BarReadlineStr (buf, sizeof (buf), input, BAR_RL_DEFAULT) == 0) {
return NULL;
}
@@ -430,8 +416,7 @@ PianoSong_t *BarUiSelectSong (const BarSettings_t *settings,
* @param input fds
* @return pointer to selected artist or NULL on abort
*/
-PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist,
- BarReadlineFds_t *input) {
+PianoArtist_t *BarUiSelectArtist (BarApp_t *app, PianoArtist_t *startArtist) {
PianoArtist_t *tmpArtist = NULL;
char buf[100];
unsigned long i;
@@ -444,14 +429,15 @@ PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist,
tmpArtist = startArtist;
while (tmpArtist != NULL) {
if (BarStrCaseStr (tmpArtist->name, buf) != NULL) {
- BarUiMsg (MSG_LIST, "%2u) %s\n", i, tmpArtist->name);
+ BarUiMsg (&app->settings, MSG_LIST, "%2u) %s\n", i, tmpArtist->name);
}
i++;
tmpArtist = tmpArtist->next;
}
- BarUiMsg (MSG_QUESTION, "Select artist: ");
- if (BarReadlineStr (buf, sizeof (buf), input, BAR_RL_DEFAULT) == 0) {
+ BarUiMsg (&app->settings, MSG_QUESTION, "Select artist: ");
+ if (BarReadlineStr (buf, sizeof (buf), &app->input,
+ BAR_RL_DEFAULT) == 0) {
return NULL;
}
@@ -480,7 +466,7 @@ char *BarUiSelectMusicId (BarApp_t *app, char *similarToId, const char *msg) {
PianoArtist_t *tmpArtist;
PianoSong_t *tmpSong;
- BarUiMsg (MSG_QUESTION, msg);
+ BarUiMsg (&app->settings, MSG_QUESTION, msg);
if (BarReadlineStr (lineBuf, sizeof (lineBuf), &app->input,
BAR_RL_DEFAULT) > 0) {
if (strcmp ("?", lineBuf) == 0 && similarToId != NULL) {
@@ -491,7 +477,7 @@ char *BarUiSelectMusicId (BarApp_t *app, char *similarToId, const char *msg) {
reqData.musicId = similarToId;
reqData.max = 20;
- BarUiMsg (MSG_INFO, "Receiving suggestions... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Receiving suggestions... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_GET_SEED_SUGGESTIONS,
&reqData, &pRet, &wRet)) {
return NULL;
@@ -504,23 +490,22 @@ char *BarUiSelectMusicId (BarApp_t *app, char *similarToId, const char *msg) {
reqData.searchStr = lineBuf;
- BarUiMsg (MSG_INFO, "Searching... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Searching... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_SEARCH, &reqData, &pRet,
&wRet)) {
return NULL;
}
memcpy (&searchResult, &reqData.searchResult, sizeof (searchResult));
}
- BarUiMsg (MSG_NONE, "\r");
+ BarUiMsg (&app->settings, MSG_NONE, "\r");
if (searchResult.songs != NULL &&
searchResult.artists != NULL) {
/* songs and artists found */
- BarUiMsg (MSG_QUESTION, "Is this an [a]rtist or [t]rack name? ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "Is this an [a]rtist or [t]rack name? ");
BarReadline (selectBuf, sizeof (selectBuf), "at", &app->input,
BAR_RL_FULLRETURN, -1);
if (*selectBuf == 'a') {
- tmpArtist = BarUiSelectArtist (searchResult.artists,
- &app->input);
+ tmpArtist = BarUiSelectArtist (app, searchResult.artists);
if (tmpArtist != NULL) {
musicId = strdup (tmpArtist->musicId);
}
@@ -540,12 +525,12 @@ char *BarUiSelectMusicId (BarApp_t *app, char *similarToId, const char *msg) {
}
} else if (searchResult.artists != NULL) {
/* artists found */
- tmpArtist = BarUiSelectArtist (searchResult.artists, &app->input);
+ tmpArtist = BarUiSelectArtist (app, searchResult.artists);
if (tmpArtist != NULL) {
musicId = strdup (tmpArtist->musicId);
}
} else {
- BarUiMsg (MSG_INFO, "Nothing found...\n");
+ BarUiMsg (&app->settings, MSG_INFO, "Nothing found...\n");
}
PianoDestroySearchResult (&searchResult);
}
@@ -569,7 +554,7 @@ void BarStationFromGenre (BarApp_t *app) {
PianoReturn_t pRet;
WaitressReturn_t wRet;
- BarUiMsg (MSG_INFO, "Receiving genre stations... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Receiving genre stations... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_GET_GENRE_STATIONS, NULL,
&pRet, &wRet)) {
return;
@@ -580,12 +565,12 @@ void BarStationFromGenre (BarApp_t *app) {
curCat = app->ph.genreStations;
i = 0;
while (curCat != NULL) {
- BarUiMsg (MSG_LIST, "%2i) %s\n", i, curCat->name);
+ BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curCat->name);
i++;
curCat = curCat->next;
}
/* select category or exit */
- BarUiMsg (MSG_QUESTION, "Select category: ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "Select category: ");
if (BarReadlineInt (&i, &app->input) == 0) {
return;
}
@@ -599,11 +584,11 @@ void BarStationFromGenre (BarApp_t *app) {
curGenre = curCat->genres;
i = 0;
while (curGenre != NULL) {
- BarUiMsg (MSG_LIST, "%2i) %s\n", i, curGenre->name);
+ BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curGenre->name);
i++;
curGenre = curGenre->next;
}
- BarUiMsg (MSG_QUESTION, "Select genre: ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "Select genre: ");
if (BarReadlineInt (&i, &app->input) == 0) {
return;
}
@@ -613,17 +598,98 @@ void BarStationFromGenre (BarApp_t *app) {
i--;
}
/* create station */
- BarUiMsg (MSG_INFO, "Adding shared station \"%s\"... ", curGenre->name);
+ BarUiMsg (&app->settings, MSG_INFO, "Adding shared station \"%s\"... ", curGenre->name);
reqData.id = curGenre->musicId;
reqData.type = "mi";
BarUiPianoCall (app, PIANO_REQUEST_CREATE_STATION, &reqData, &pRet, &wRet);
}
-/* Print station infos (including station id)
+/* replaces format characters (%x) in format string with custom strings
+ * @param destination buffer
+ * @param dest buffer size
+ * @param format string
+ * @param format characters
+ * @param replacement for each given format character
+ */
+void BarUiCustomFormat (char *dest, size_t destSize, const char *format,
+ const char *formatChars, const char **formatVals) {
+ bool haveFormatChar = false;
+
+ while (*format != '\0' && destSize > 1) {
+ if (*format == '%' && !haveFormatChar) {
+ haveFormatChar = true;
+ } else if (haveFormatChar) {
+ const char *testChar = formatChars;
+ const char *val = NULL;
+
+ /* search for format character */
+ while (*testChar != '\0') {
+ if (*testChar == *format) {
+ val = formatVals[(testChar-formatChars)/sizeof (*testChar)];
+ break;
+ }
+ ++testChar;
+ }
+
+ if (val != NULL) {
+ /* concat */
+ while (*val != '\0' && destSize > 1) {
+ *dest = *val;
+ ++val;
+ ++dest;
+ --destSize;
+ }
+ } else {
+ /* invalid format character */
+ *dest = '%';
+ ++dest;
+ --destSize;
+ if (destSize > 1) {
+ *dest = *format;
+ ++dest;
+ --destSize;
+ }
+ }
+
+ haveFormatChar = false;
+ } else {
+ /* copy */
+ *dest = *format;
+ ++dest;
+ --destSize;
+ }
+ ++format;
+ }
+ *dest = '\0';
+}
+
+/* append \n to string
+ */
+static void BarUiAppendNewline (char *s, size_t maxlen) {
+ size_t len;
+
+ /* append \n */
+ if ((len = strlen (s)) == maxlen-1) {
+ s[maxlen-2] = '\n';
+ } else {
+ s[len] = '\n';
+ s[len+1] = '\0';
+ }
+}
+
+/* Print customizeable station infos
+ * @param pianobar settings
* @param the station
*/
-inline void BarUiPrintStation (PianoStation_t *station) {
- BarUiMsg (MSG_PLAYING, "Station \"%s\" (%s)\n", station->name, station->id);
+inline void BarUiPrintStation (const BarSettings_t *settings,
+ PianoStation_t *station) {
+ char outstr[512];
+ const char *vals[] = {station->name, station->id};
+
+ BarUiCustomFormat (outstr, sizeof (outstr), settings->npStationFormat,
+ "ni", vals);
+ BarUiAppendNewline (outstr, sizeof (outstr));
+ BarUiMsg (settings, MSG_PLAYING, outstr);
}
/* Print song infos (artist, title, album, loved)
@@ -633,12 +699,17 @@ inline void BarUiPrintStation (PianoStation_t *station) {
*/
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) ? " " : "",
+ char outstr[512];
+ const char *vals[] = {song->title, song->artist, song->album,
(song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "",
station != NULL ? " @ " : "",
- station != NULL ? station->name : "");
+ station != NULL ? station->name : "",
+ song->detailUrl};
+
+ BarUiCustomFormat (outstr, sizeof (outstr), settings->npSongFormat,
+ "talr@su", vals);
+ BarUiAppendNewline (outstr, sizeof (outstr));
+ BarUiMsg (settings, MSG_PLAYING, outstr);
}
/* Print list of songs
@@ -655,7 +726,7 @@ size_t BarUiListSongs (const BarSettings_t *settings,
if (filter == NULL ||
(filter != NULL && (BarStrCaseStr (song->artist, filter) != NULL ||
BarStrCaseStr (song->title, filter) != NULL))) {
- BarUiMsg (MSG_LIST, "%2lu) %s - %s %s%s\n", i, song->artist,
+ BarUiMsg (settings, 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 : "");
@@ -688,7 +759,7 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
}
if (pipe (pipeFd) == -1) {
- BarUiMsg (MSG_ERR, "Cannot create eventcmd pipe. (%s)\n", strerror (errno));
+ BarUiMsg (settings, MSG_ERR, "Cannot create eventcmd pipe. (%s)\n", strerror (errno));
return;
}
@@ -698,11 +769,11 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
close (pipeFd[1]);
dup2 (pipeFd[0], fileno (stdin));
execl (settings->eventCmd, settings->eventCmd, type, (char *) NULL);
- BarUiMsg (MSG_ERR, "Cannot start eventcmd. (%s)\n", strerror (errno));
+ BarUiMsg (settings, MSG_ERR, "Cannot start eventcmd. (%s)\n", strerror (errno));
close (pipeFd[0]);
exit (1);
} else if (chld == -1) {
- BarUiMsg (MSG_ERR, "Cannot fork eventcmd. (%s)\n", strerror (errno));
+ BarUiMsg (settings, MSG_ERR, "Cannot fork eventcmd. (%s)\n", strerror (errno));
} else {
/* parent */
int status, printfret;
diff --git a/src/ui.h b/src/ui.h
index 32f075a..f86f5f3 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -31,20 +31,16 @@ THE SOFTWARE.
#include "player.h"
#include "main.h"
#include "ui_readline.h"
+#include "ui_types.h"
-typedef enum {MSG_NONE, MSG_INFO, MSG_PLAYING, MSG_TIME, MSG_ERR,
- MSG_QUESTION, MSG_LIST} uiMsg_t;
-
-void BarUiMsg (uiMsg_t type, const char *format, ...);
-PianoReturn_t BarUiPrintPianoStatus (PianoReturn_t ret);
-PianoStation_t *BarUiSelectStation (PianoHandle_t *, const char *,
- BarStationSorting_t, BarReadlineFds_t *);
+void BarUiMsg (const BarSettings_t *, const BarUiMsg_t, const char *, ...);
+PianoStation_t *BarUiSelectStation (BarApp_t *, const char *);
PianoSong_t *BarUiSelectSong (const BarSettings_t *, PianoSong_t *,
BarReadlineFds_t *);
-PianoArtist_t *BarUiSelectArtist (PianoArtist_t *, BarReadlineFds_t *);
+PianoArtist_t *BarUiSelectArtist (BarApp_t *, PianoArtist_t *);
char *BarUiSelectMusicId (BarApp_t *, char *, const char *);
void BarStationFromGenre (BarApp_t *);
-void BarUiPrintStation (PianoStation_t *);
+void BarUiPrintStation (const BarSettings_t *, PianoStation_t *);
void BarUiPrintSong (const BarSettings_t *, const PianoSong_t *,
const PianoStation_t *);
size_t BarUiListSongs (const BarSettings_t *, const PianoSong_t *, const char *);
diff --git a/src/ui_act.c b/src/ui_act.c
index 3785f46..06affa1 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -66,7 +66,7 @@ static int BarTransformIfShared (BarApp_t *app, PianoStation_t *station) {
/* shared stations must be transformed */
if (!station->isCreator) {
- BarUiMsg (MSG_INFO, "Transforming station... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Transforming station... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_TRANSFORM_STATION, station,
&pRet, &wRet)) {
return 0;
@@ -78,12 +78,12 @@ static int BarTransformIfShared (BarApp_t *app, PianoStation_t *station) {
/* print current shortcut configuration
*/
BarUiActCallback(BarUiActHelp) {
- BarUiMsg (MSG_NONE, "\r");
+ BarUiMsg (&app->settings, MSG_NONE, "\r");
for (size_t i = 0; i < BAR_KS_COUNT; i++) {
if (dispatchActions[i].helpText != NULL &&
(context & dispatchActions[i].context) == dispatchActions[i].context &&
app->settings.keys[i] != BAR_KS_DISABLED) {
- BarUiMsg (MSG_LIST, "%c %s\n", app->settings.keys[i],
+ BarUiMsg (&app->settings, MSG_LIST, "%c %s\n", app->settings.keys[i],
dispatchActions[i].helpText);
}
}
@@ -106,7 +106,7 @@ BarUiActCallback(BarUiActAddMusic) {
}
reqData.station = selStation;
- BarUiMsg (MSG_INFO, "Adding music to station... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Adding music to station... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_ADD_SEED, &reqData);
free (reqData.musicId);
@@ -132,7 +132,7 @@ BarUiActCallback(BarUiActBanSong) {
reqData.song = selSong;
reqData.rating = PIANO_RATE_BAN;
- BarUiMsg (MSG_INFO, "Banning song... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Banning song... ");
if (BarUiActDefaultPianoCall (PIANO_REQUEST_RATE_SONG, &reqData) &&
selSong == app->playlist) {
BarUiDoSkipSong (&app->player);
@@ -151,7 +151,7 @@ BarUiActCallback(BarUiActCreateStation) {
"Create station from artist or title: ");
if (reqData.id != NULL) {
reqData.type = "mi";
- BarUiMsg (MSG_INFO, "Creating station... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Creating station... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData);
free (reqData.id);
BarUiActDefaultEventcmd ("stationcreate");
@@ -166,12 +166,12 @@ BarUiActCallback(BarUiActAddSharedStation) {
PianoRequestDataCreateStation_t reqData;
char stationId[50];
- BarUiMsg (MSG_QUESTION, "Station id: ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "Station id: ");
if (BarReadline (stationId, sizeof (stationId), "0123456789", &app->input,
BAR_RL_DEFAULT, -1) > 0) {
reqData.id = stationId;
reqData.type = "sh";
- BarUiMsg (MSG_INFO, "Adding shared station... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Adding shared station... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData);
BarUiActDefaultEventcmd ("stationaddshared");
}
@@ -185,10 +185,10 @@ BarUiActCallback(BarUiActDeleteStation) {
assert (selStation != NULL);
- BarUiMsg (MSG_QUESTION, "Really delete \"%s\"? [yN] ",
+ BarUiMsg (&app->settings, MSG_QUESTION, "Really delete \"%s\"? [yN] ",
app->curStation->name);
if (BarReadlineYesNo (false, &app->input)) {
- BarUiMsg (MSG_INFO, "Deleting station... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Deleting station... ");
if (BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_STATION,
selStation) && selStation == app->curStation) {
BarUiDoSkipSong (&app->player);
@@ -212,9 +212,9 @@ BarUiActCallback(BarUiActExplain) {
reqData.song = selSong;
- BarUiMsg (MSG_INFO, "Receiving explanation... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Receiving explanation... ");
if (BarUiActDefaultPianoCall (PIANO_REQUEST_EXPLAIN, &reqData)) {
- BarUiMsg (MSG_INFO, "%s\n", reqData.retExplain);
+ BarUiMsg (&app->settings, MSG_INFO, "%s\n", reqData.retExplain);
free (reqData.retExplain);
}
BarUiActDefaultEventcmd ("songexplain");
@@ -233,7 +233,7 @@ BarUiActCallback(BarUiActSongInfo) {
assert (selStation != NULL);
assert (selSong != NULL);
- BarUiPrintStation (selStation);
+ BarUiPrintStation (&app->settings, selStation);
/* print real station if quickmix */
BarUiPrintSong (&app->settings, selSong,
selStation->isQuickMix ?
@@ -247,7 +247,7 @@ BarUiActCallback(BarUiActDebug) {
assert (selSong != NULL);
/* print debug-alike infos */
- BarUiMsg (MSG_NONE,
+ BarUiMsg (&app->settings, MSG_NONE,
"album:\t%s\n"
"artist:\t%s\n"
"audioFormat:\t%i\n"
@@ -295,7 +295,7 @@ BarUiActCallback(BarUiActLoveSong) {
reqData.song = selSong;
reqData.rating = PIANO_RATE_LOVE;
- BarUiMsg (MSG_INFO, "Loving song... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Loving song... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_RATE_SONG, &reqData);
BarUiActDefaultEventcmd ("songlove");
}
@@ -317,15 +317,14 @@ BarUiActCallback(BarUiActMoveSong) {
reqData.step = 0;
- reqData.to = BarUiSelectStation (&app->ph, "Move song to station: ",
- app->settings.sortOrder, &app->input);
+ reqData.to = BarUiSelectStation (app, "Move song to station: ");
if (reqData.to != NULL) {
/* find original station (just is case we're playing a quickmix
* station) */
reqData.from = PianoFindStationById (app->ph.stations,
selSong->stationId);
if (reqData.from == NULL) {
- BarUiMsg (MSG_ERR, "Station not found\n");
+ BarUiMsg (&app->settings, MSG_ERR, "Station not found\n");
return;
}
@@ -333,7 +332,7 @@ BarUiActCallback(BarUiActMoveSong) {
!BarTransformIfShared (app, reqData.to)) {
return;
}
- BarUiMsg (MSG_INFO, "Moving song to \"%s\"... ", reqData.to->name);
+ BarUiMsg (&app->settings, MSG_INFO, "Moving song to \"%s\"... ", reqData.to->name);
reqData.song = selSong;
if (BarUiActDefaultPianoCall (PIANO_REQUEST_MOVE_SONG, &reqData) &&
selSong == app->playlist) {
@@ -361,7 +360,7 @@ BarUiActCallback(BarUiActRenameStation) {
assert (selStation != NULL);
- BarUiMsg (MSG_QUESTION, "New name: ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "New name: ");
if (BarReadlineStr (lineBuf, sizeof (lineBuf), &app->input, BAR_RL_DEFAULT) > 0) {
PianoRequestDataRenameStation_t reqData;
if (!BarTransformIfShared (app, selStation)) {
@@ -371,7 +370,7 @@ BarUiActCallback(BarUiActRenameStation) {
reqData.station = selStation;
reqData.newName = lineBuf;
- BarUiMsg (MSG_INFO, "Renaming station... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Renaming station... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_RENAME_STATION, &reqData);
BarUiActDefaultEventcmd ("stationrename");
}
@@ -380,11 +379,10 @@ BarUiActCallback(BarUiActRenameStation) {
/* play another station
*/
BarUiActCallback(BarUiActSelectStation) {
- PianoStation_t *newStation = BarUiSelectStation (&app->ph, "Select station: ",
- app->settings.sortOrder, &app->input);
+ PianoStation_t *newStation = BarUiSelectStation (app, "Select station: ");
if (newStation != NULL) {
app->curStation = newStation;
- BarUiPrintStation (app->curStation);
+ BarUiPrintStation (&app->settings, app->curStation);
BarUiDoSkipSong (&app->player);
if (app->playlist != NULL) {
PianoDestroyPlaylist (app->playlist->next);
@@ -402,7 +400,7 @@ BarUiActCallback(BarUiActTempBanSong) {
assert (selSong != NULL);
- BarUiMsg (MSG_INFO, "Putting song on shelf... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Putting song on shelf... ");
if (BarUiActDefaultPianoCall (PIANO_REQUEST_ADD_TIRED_SONG, selSong) &&
selSong == app->playlist) {
BarUiDoSkipSong (&app->player);
@@ -419,7 +417,7 @@ BarUiActCallback(BarUiActPrintUpcoming) {
if (nextSong != NULL) {
BarUiListSongs (&app->settings, nextSong, NULL);
} else {
- BarUiMsg (MSG_INFO, "No songs in queue.\n");
+ BarUiMsg (&app->settings, MSG_INFO, "No songs in queue.\n");
}
}
@@ -434,16 +432,15 @@ BarUiActCallback(BarUiActSelectQuickMix) {
if (selStation->isQuickMix) {
PianoStation_t *toggleStation;
- while ((toggleStation = BarUiSelectStation (&app->ph,
- "Toggle quickmix for station: ", app->settings.sortOrder,
- &app->input)) != NULL) {
+ while ((toggleStation = BarUiSelectStation (app,
+ "Toggle quickmix for station: ")) != NULL) {
toggleStation->useQuickMix = !toggleStation->useQuickMix;
}
- BarUiMsg (MSG_INFO, "Setting quickmix stations... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Setting quickmix stations... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_SET_QUICKMIX, NULL);
BarUiActDefaultEventcmd ("stationquickmixtoggle");
} else {
- BarUiMsg (MSG_ERR, "Not a QuickMix station.\n");
+ BarUiMsg (&app->settings, MSG_ERR, "Not a QuickMix station.\n");
}
}
@@ -469,14 +466,14 @@ BarUiActCallback(BarUiActHistory) {
histSong->stationId);
if (songStation == NULL) {
- BarUiMsg (MSG_ERR, "Station does not exist any more.\n");
+ BarUiMsg (&app->settings, MSG_ERR, "Station does not exist any more.\n");
return;
}
do {
action = BAR_KS_COUNT;
- BarUiMsg (MSG_QUESTION, "What to do with this song? ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "What to do with this song? ");
if (BarReadline (buf, sizeof (buf), NULL, &app->input,
BAR_RL_FULLRETURN, -1) > 0) {
@@ -488,7 +485,7 @@ BarUiActCallback(BarUiActHistory) {
} while (action == BAR_KS_HELP);
} /* end if histSong != NULL */
} else {
- BarUiMsg (MSG_INFO, (app->settings.history == 0) ? "History disabled.\n" :
+ BarUiMsg (&app->settings, MSG_INFO, (app->settings.history == 0) ? "History disabled.\n" :
"No history yet.\n");
}
}
@@ -502,15 +499,15 @@ BarUiActCallback(BarUiActBookmark) {
assert (selSong != NULL);
- BarUiMsg (MSG_QUESTION, "Bookmark [s]ong or [a]rtist? ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "Bookmark [s]ong or [a]rtist? ");
BarReadline (selectBuf, sizeof (selectBuf), "sa", &app->input,
BAR_RL_FULLRETURN, -1);
if (selectBuf[0] == 's') {
- BarUiMsg (MSG_INFO, "Bookmarking song... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Bookmarking song... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_BOOKMARK_SONG, selSong);
BarUiActDefaultEventcmd ("songbookmark");
} else if (selectBuf[0] == 'a') {
- BarUiMsg (MSG_INFO, "Bookmarking artist... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Bookmarking artist... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_BOOKMARK_ARTIST, selSong);
BarUiActDefaultEventcmd ("artistbookmark");
}
@@ -543,23 +540,23 @@ BarUiActCallback(BarUiActManageStation) {
memset (&reqData, 0, sizeof (reqData));
reqData.station = selStation;
- BarUiMsg (MSG_INFO, "Fetching station info... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Fetching station info... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_GET_STATION_INFO, &reqData);
BarUiActDefaultEventcmd ("stationfetchinfo");
- BarUiMsg (MSG_QUESTION, "Delete [a]rtist/[s]ong seeds or [f]eedback? ");
+ BarUiMsg (&app->settings, MSG_QUESTION, "Delete [a]rtist/[s]ong seeds or [f]eedback? ");
if (BarReadline (selectBuf, sizeof (selectBuf), "asf", &app->input,
BAR_RL_FULLRETURN, -1)) {
if (selectBuf[0] == 'a') {
- PianoArtist_t *artist = BarUiSelectArtist (reqData.info.artistSeeds,
- &app->input);
+ PianoArtist_t *artist = BarUiSelectArtist (app,
+ reqData.info.artistSeeds);
if (artist != NULL) {
PianoRequestDataDeleteSeed_t reqData;
memset (&reqData, 0, sizeof (reqData));
reqData.artist = artist;
- BarUiMsg (MSG_INFO, "Deleting artist seed... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Deleting artist seed... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_SEED, &reqData);
BarUiActDefaultEventcmd ("stationdeleteartistseed");
}
@@ -572,7 +569,7 @@ BarUiActCallback(BarUiActManageStation) {
memset (&reqData, 0, sizeof (reqData));
reqData.song = song;
- BarUiMsg (MSG_INFO, "Deleting song seed... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Deleting song seed... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_SEED, &reqData);
BarUiActDefaultEventcmd ("stationdeletesongseed");
}
@@ -580,7 +577,7 @@ BarUiActCallback(BarUiActManageStation) {
PianoSong_t *song = BarUiSelectSong (&app->settings,
reqData.info.feedback, &app->input);
if (song != NULL) {
- BarUiMsg (MSG_INFO, "Deleting feedback... ");
+ BarUiMsg (&app->settings, MSG_INFO, "Deleting feedback... ");
BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_FEEDBACK, song);
BarUiActDefaultEventcmd ("stationdeletefeedback");
}
diff --git a/src/ui_dispatch.c b/src/ui_dispatch.c
index ddcf60c..93c77c8 100644
--- a/src/ui_dispatch.c
+++ b/src/ui_dispatch.c
@@ -56,9 +56,9 @@ BarKeyShortcutId_t BarUiDispatch (BarApp_t *app, const char key, PianoStation_t
return i;
} else if (verbose) {
if (dispatchActions[i].context & BAR_DC_SONG) {
- BarUiMsg (MSG_ERR, "No song playing.\n");
+ BarUiMsg (&app->settings, MSG_ERR, "No song playing.\n");
} else if (dispatchActions[i].context & BAR_DC_STATION) {
- BarUiMsg (MSG_ERR, "No station selected.\n");
+ BarUiMsg (&app->settings, MSG_ERR, "No station selected.\n");
} else {
assert (0);
}
diff --git a/src/ui_types.h b/src/ui_types.h
new file mode 100644
index 0000000..c702676
--- /dev/null
+++ b/src/ui_types.h
@@ -0,0 +1,38 @@
+/*
+Copyright (c) 2011
+ Lars-Dominik Braun <lars@6xq.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef _UI_TYPES_H
+#define _UI_TYPES_H
+
+typedef enum {
+ MSG_NONE = 0,
+ MSG_INFO = 1,
+ MSG_PLAYING = 2,
+ MSG_TIME = 3,
+ MSG_ERR = 4,
+ MSG_QUESTION = 5,
+ MSG_LIST = 6,
+ MSG_COUNT = 7, /* invalid type */
+} BarUiMsg_t;
+
+#endif /* _UI_TYPES_H */