From 3fa2dbf607db03b7f2535d7eb98ee6bdae0239dd Mon Sep 17 00:00:00 2001 From: Alan Fitton Date: Wed, 19 Oct 2011 20:21:19 +0000 Subject: implement a TRG_PREFS_CONNECTION flag which gets prefs for the connected profile --- src/trg-prefs.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/trg-prefs.c') diff --git a/src/trg-prefs.c b/src/trg-prefs.c index 1501217..90d8887 100644 --- a/src/trg-prefs.c +++ b/src/trg-prefs.c @@ -39,6 +39,7 @@ struct _TrgPrefsPrivate { JsonObject *defaultsObj; JsonNode *user; JsonObject *userObj; + JsonObject *connectionObj; JsonObject *profile; gchar *file; }; @@ -213,8 +214,10 @@ JsonNode *trg_prefs_get_value(TrgPrefs *p, gchar *key, int type, int flags) { JsonNode *res; if ((flags & TRG_PREFS_PROFILE)) { - JsonObject *profile = trg_prefs_get_profile(p); - if ((res = trg_prefs_get_value_inner(profile, key, type, flags))) + if ((res = trg_prefs_get_value_inner(trg_prefs_get_profile(p), key, type, flags))) + return res; + } else if ((flags & TRG_PREFS_CONNECTION)) { + if ((res = trg_prefs_get_value_inner(priv->connectionObj, key, type, flags))) return res; } else { if ((res = trg_prefs_get_value_inner(priv->userObj, key, type, flags))) @@ -227,6 +230,19 @@ JsonNode *trg_prefs_get_value(TrgPrefs *p, gchar *key, int type, int flags) { return NULL; } +void trg_prefs_set_connection(TrgPrefs *p, JsonObject *profile) +{ + TrgPrefsPrivate *priv = GET_PRIVATE(p); + + if (priv->connectionObj) + json_object_unref(priv->connectionObj); + + if (profile) + json_object_ref(profile); + + priv->connectionObj = profile; +} + gchar *trg_prefs_get_string(TrgPrefs *p, gchar *key, int flags) { JsonNode *node = trg_prefs_get_value(p, key, JSON_NODE_VALUE, flags); if (node) @@ -337,6 +353,11 @@ JsonObject* trg_prefs_get_profile(TrgPrefs *p) { return priv->profile; } +JsonObject* trg_prefs_get_connection(TrgPrefs *p) { + TrgPrefsPrivate *priv = GET_PRIVATE(p); + return priv->connectionObj; +} + JsonArray* trg_prefs_get_profiles(TrgPrefs *p) { TrgPrefsPrivate *priv = GET_PRIVATE(p); return json_object_get_array_member(priv->userObj, TRG_PREFS_KEY_PROFILES); -- cgit v1.2.3