summaryrefslogtreecommitdiffstats
path: root/mpd-notification.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2016-04-01 09:26:47 +0200
committerGravatar Christian Hesse <mail@eworm.de>2016-04-01 09:26:47 +0200
commitcb6b3750228ae4041a254e344fb24dbd50f38434 (patch)
treed8a5ff41e8e1115d4ab06865f011e066e84be68e /mpd-notification.c
parent6457fb8d8248278bbb787cd0d044a566bb8c08b4 (diff)
downloadmpd-notification-cb6b3750228ae4041a254e344fb24dbd50f38434.tar.gz
mpd-notification-cb6b3750228ae4041a254e344fb24dbd50f38434.tar.zst
Allow one line notifications
This is related to #9.
Diffstat (limited to 'mpd-notification.c')
-rw-r--r--mpd-notification.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/mpd-notification.c b/mpd-notification.c
index 49673e4..56dbaa2 100644
--- a/mpd-notification.c
+++ b/mpd-notification.c
@@ -7,12 +7,13 @@
#include "mpd-notification.h"
-const static char optstring[] = "hH:m:p:t:vV";
+const static char optstring[] = "hH:m:op:t:vV";
const static struct option options_long[] = {
/* name has_arg flag val */
{ "help", no_argument, NULL, 'h' },
{ "host", required_argument, NULL, 'H' },
{ "music-dir", required_argument, NULL, 'm' },
+ { "oneline", no_argument, NULL, 'o' },
{ "port", required_argument, NULL, 'p' },
{ "timeout", required_argument, NULL, 't' },
{ "verbose", no_argument, NULL, 'v' },
@@ -26,6 +27,7 @@ NotifyNotification * notification = NULL;
struct mpd_connection * conn = NULL;
uint8_t doexit = 0;
uint8_t verbose = 0;
+uint8_t oneline = 0;
/*** received_signal ***/
void received_signal(int signal) {
@@ -157,14 +159,21 @@ char * get_icon(const char * music_dir, const char * uri) {
}
/*** append_string ***/
-char * append_string(char * string, const char * format, const char * s) {
- char * tmp;
+char * append_string(char * string, const char * format, const char delim, const char * s) {
+ char * tmp, * offset;
tmp = g_markup_escape_text(s, -1);
- string = realloc(string, strlen(string) + strlen(format) + strlen(tmp));
+ string = realloc(string, strlen(string) + strlen(format) + strlen(tmp) + 2 /* delim + line break */);
- sprintf(string + strlen(string), format, tmp);
+ offset = string + strlen(string);
+
+ if (delim > 0) {
+ *offset = delim;
+ offset++;
+ }
+
+ sprintf(offset, format, tmp);
free(tmp);
@@ -201,6 +210,9 @@ int main(int argc, char ** argv) {
case 'h':
help++;
break;
+ case 'o':
+ oneline++;
+ break;
case 'v':
verbose++;
break;
@@ -319,13 +331,13 @@ int main(int argc, char ** argv) {
/* initial allocation and string termination */
notifystr = strdup("");
- notifystr = append_string(notifystr, TEXT_PLAY_TITLE, title);
+ notifystr = append_string(notifystr, TEXT_PLAY_TITLE, 0, title);
if ((artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0)) != NULL)
- notifystr = append_string(notifystr, TEXT_PLAY_ARTIST, artist);
+ notifystr = append_string(notifystr, TEXT_PLAY_ARTIST, oneline ? ' ' : '\n', artist);
if ((album = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0)) != NULL)
- notifystr = append_string(notifystr, TEXT_PLAY_ALBUM, album);
+ notifystr = append_string(notifystr, TEXT_PLAY_ALBUM, oneline ? ' ' : '\n', album);
uri = mpd_song_get_uri(song);