aboutsummaryrefslogtreecommitdiffstats
path: root/mpd-notification.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2016-10-05 23:23:49 +0200
committerGravatar Christian Hesse <mail@eworm.de>2016-10-05 23:47:53 +0200
commit053e5ac36dfce0f4247bcf91656a11016701c997 (patch)
treea258372f26205bbd0ea2749a709b2822e3552455 /mpd-notification.c
parent90b01922ea7622de0eab2216912445040389ed5c (diff)
downloadmpd-notification-053e5ac36dfce0f4247bcf91656a11016701c997.tar.gz
mpd-notification-053e5ac36dfce0f4247bcf91656a11016701c997.tar.zst
support reading options from config file
This tries to read ~/.local/mpd-notification.conf, which is expected to look like this: host = localhost port = 6600 music-dir = /srv/media/music/ scale = 200 timeout = 20 Unused options can be commented or removed completely.
Diffstat (limited to 'mpd-notification.c')
-rw-r--r--mpd-notification.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/mpd-notification.c b/mpd-notification.c
index f504836..543f60a 100644
--- a/mpd-notification.c
+++ b/mpd-notification.c
@@ -176,6 +176,7 @@ char * append_string(char * string, const char * format, const char delim, const
/*** main ***/
int main(int argc, char ** argv) {
+ dictionary * ini = NULL;
const char * title = NULL, * artist = NULL, * album = NULL;
char * notifystr = NULL;
GdkPixbuf * pixbuf = NULL;
@@ -198,6 +199,17 @@ int main(int argc, char ** argv) {
music_dir = getenv("XDG_MUSIC_DIR");
+ /* parse config file */
+ if (chdir(getenv("HOME")) == 0 && access(".config/mpd-notification.conf", R_OK) == 0 &&
+ (ini = iniparser_load(".config/mpd-notification.conf")) != NULL) {
+ file_workaround = iniparser_getboolean(ini, ":notification-file-workaround", file_workaround);
+ mpd_host = iniparser_getstring(ini, ":host", mpd_host);
+ mpd_port = iniparser_getint(ini, ":port", mpd_port);
+ notification_timeout = iniparser_getint(ini, ":timeout", notification_timeout);
+ music_dir = iniparser_getstring(ini, ":music-dir", music_dir);
+ scale = iniparser_getint(ini, ":scale", scale);
+ }
+
/* get the verbose status */
while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) {
switch (i) {
@@ -435,5 +447,8 @@ nonotification:
g_object_unref(G_OBJECT(notification));
notify_uninit();
+ if (ini != NULL)
+ iniparser_freedict(ini);
+
return EXIT_SUCCESS;
}