[Pkg-wmaker-commits] [wmforecast] 20/63: read user prefs from XDG_CONFIG_DIR/wmforecast/wmforecastrc

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 17 11:20:33 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmforecast.

commit 379c5ea7ef625e9dfc2c9ae5e90ae78f60d76590
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date:   Mon Apr 21 22:29:51 2014 -0500

    read user prefs from XDG_CONFIG_DIR/wmforecast/wmforecastrc
---
 ChangeLog    |  5 +++++
 wmforecast.c | 40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 5bcf976..50cfa05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,11 @@
 	  cause manpage to reflect changes in version and bug report email
 	* wmforecast.c (setConditions): append a "0" to one-digit codes so that
 	  the icon is correctly displayed
+	* wmforecast.c (WMGetPLStringForKey): new function to simplify reading
+	  values from WMPropLists (inspired by WMGetUDStringForKey), used for
+	  the following new feature...
+	* wmforecast.c (setPreferences): reads user defined preferences from
+	  XDG_CONFIG_DIR/wmforecast/wmforecastrc
 
 2014-04-19  Doug Torrance <dtorrance at monmouthcollege.edu>
 	* switched timer handler from pthread to WING's native WMAddPersistent-
diff --git a/wmforecast.c b/wmforecast.c
index 1c1f0be..9d40e0b 100755
--- a/wmforecast.c
+++ b/wmforecast.c
@@ -474,10 +474,22 @@ static void updateDockapp(void *data)
 	freeWeather(weather);
 }
 
+char *WMGetPLStringForKey(WMPropList *propList, char *key)
+{
+	WMPropList *value;
+	value = WMGetFromPLDictionary(propList,WMCreatePLString(key));
+	if (value)
+		return WMGetPropListDescription(value, False);
+	else
+		return NULL;
+}
+
 Preferences *setPreferences(int argc, char **argv)
 {
+	char *filename;
 	int c;
 	Preferences *prefs = wmalloc(sizeof(Preferences));
+	WMPropList *propList;
 	
 	//set defaults
 	prefs->units = "f";
@@ -486,6 +498,32 @@ Preferences *setPreferences(int argc, char **argv)
 	prefs->woeid_or_zip = NULL;
 	prefs->interval = 60;
 
+	//read from wmforecastrc
+	filename = getenv("XDG_CONFIG_DIR");
+	if (!filename)
+		filename = wstrconcat(getenv("HOME"), "/.config");
+	filename = wstrappend(filename, "/wmforecast/wmforecastrc");
+	propList = WMReadPropListFromFile(filename); 
+	if (propList) {
+		char *value;
+		value = WMGetPLStringForKey(propList, "units");
+		if (value)
+			prefs->units = value;
+		value = WMGetPLStringForKey(propList, "woeid");
+		if (value)
+			prefs->woeid = value;
+		value = WMGetPLStringForKey(propList, "zip");
+		if (value)
+			prefs->zip = value;
+		value = WMGetPLStringForKey(propList, "woeid_or_zip");
+		if (value)
+			prefs->woeid_or_zip = value;
+		value = WMGetPLStringForKey(propList, "interval");
+		if (value)
+			prefs->interval = strtol(value, NULL, 10);
+	}
+
+	//command line
 	while (1)
 	{
 		static struct option long_options[] =
@@ -584,7 +622,7 @@ Preferences *setPreferences(int argc, char **argv)
 			abort ();
 		}
 	}
-	
+
 	if (!prefs->woeid_or_zip) {
 		prefs->woeid_or_zip = "w";
 	}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmforecast.git



More information about the Pkg-wmaker-commits mailing list