]> code.citadel.org Git - citadel.git/blobdiff - webcit/preferences.c
* put filename reference into token, so we can put in errormessages where we wouldn...
[citadel.git] / webcit / preferences.c
index 49f430b733583ab13353550a07328adc04fb8d56..f6e4bab1458695743eebb7633ebb3ab62486f670 100644 (file)
@@ -671,7 +671,7 @@ void set_preferences(void)
 #define PRF_YESNO 4
 
 
-void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
+void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
        StrBuf *Setting;
        if (get_PREFERENCE(Token->Params[0]->Start,
@@ -680,7 +680,7 @@ void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *
                StrBufAppendBuf(Target, Setting, 0);
 }
 
-void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
+void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
        const char *SettingStr;
        SettingStr = PrefGetLocalStr(Token->Params[0]->Start,
@@ -690,24 +690,30 @@ void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *
 }
 
 
-void CfgZoneTempl(StrBuf *TemplBuffer, void *Context)
+void CfgZoneTempl(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
 {
+       StrBuf *Zone = (StrBuf*) vContext;
 
+       SVPutBuf("ZONENAME", Zone, 1);
 }
 
-int ConditionalPreference(WCTemplateToken *Token, void *Context)
+int ConditionalPreference(WCTemplateToken *Token, void *Context, int ContextType)
 {
+       StrBuf *Pref;
 
-       void *hash_value;
-
-       if (!GetHash(PreferenceHooks, 
-                    Token->Params[2]->Start,
-                    Token->Params[2]->len,
-                    &hash_value))
+       if (!get_PREFERENCE(Token->Params[2]->Start,
+                           Token->Params[2]->len,
+                           &Pref)) 
                return 0;
-
-       Prefs *Newpref = (Prefs*) hash_value;
-       return (strcmp(Token->Params[3]->Start, Newpref->PrefStr) == 0);
+       
+       if (Token->nParameters == 3) {
+               return 1;
+       }
+       else if (Token->Params[3]->Type == TYPE_STR)
+               return ((Token->Params[3]->len == StrLength(Pref)) &&
+                       (strcmp(Token->Params[3]->Start, ChrPtr(Pref)) == 0));
+       else 
+               return (StrTol(Pref) == Token->Params[3]->lvalue);
 }
 
 
@@ -729,10 +735,10 @@ InitModule_PREFERENCES
        RegisterPreference("default_header_charset", _("Default character set for email headers:") ,PRF_STRING);
        RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO);
        
-       RegisterNamespace("PREF:VALUE", 1, 1, tmplput_CFG_Value);
-       RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr);
-       RegisterIterator("PREF:ZONE", ZoneHash, NULL, CfgZoneTempl, NULL);
+       RegisterNamespace("PREF:VALUE", 1, 1, tmplput_CFG_Value, CTX_SESSION);
+       RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, CTX_SESSION);
+       RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL, CTX_PREF, CTX_NONE);
 
-       RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference);
+       RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
 }
 /*@}*/