]> code.citadel.org Git - citadel.git/commitdiff
* use onload handler for iconbar stuff. This fixes forgettyness about the iconbar...
authorWilfried Göesgens <willi@citadel.org>
Sun, 7 Jun 2009 20:55:30 +0000 (20:55 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 7 Jun 2009 20:55:30 +0000 (20:55 +0000)
webcit/iconbar.c
webcit/webcit.h

index 5abdee85ea4f925740c3bdc3969b7562c7510372..b789798628cb0b7c0de8719ccf02b5a41f27b436 100644 (file)
@@ -19,8 +19,16 @@ void DontDeleteThis(void *Data){}
 long IconbarIsENABLED(const char *key, size_t keylen, long defval)
 {
        void *Data;
-       if (GetHash(WC->IconBarSettings, key, keylen,
-                   &Data))
+       wcsession *WCC = WC;
+
+       if (WCC == NULL) 
+               return defval;
+
+       if (GetHash(WCC->IconBarSettings, 
+                   key, 
+                   keylen,
+                   &Data) && 
+           (Data != NULL))
                return (long) Data;
        else 
                return defval;
@@ -37,44 +45,42 @@ inline const char *PrintInt(void *Prefstr)
 
 /** Produces a stylesheet which hides any iconbar icons the user does not want */
 void doUserIconStylesheet(void) {
-  HashPos *pos;
-  void *Data;
-  long value;
-  const char *key;
-  long HKLen;
-
-  LoadIconSettings();
-  output_custom_content_header("text/css");
-  hprintf("Cache-Control: private\r\n");
-  
-  begin_burst();
-  wprintf("#global { left: 16%%; }\r\n");
-  pos = GetNewHashPos(WC->IconBarSettings, 0);
-  while(GetNextHashPos(WC->IconBarSettings, pos, &HKLen, &key, &Data)) {
-    value = (long) Data;
-    if (value == 0 
-       && strncasecmp("ib_displayas",key,12) 
-       && strncasecmp("ib_logoff", key, 9)) {
-           /* Don't shoot me for this */
-      wprintf("#%s { display: none !important; }\r\n",key);
-    } else if (!strncasecmp("ib_users",key, 8) && value == 2) {
-      wprintf("#online_users { display: block; !important } \r\n");
-    }
-  }
-  DeleteHashPos(&pos);
-  end_burst();
+       HashPos *pos;
+       void *Data;
+       long value;
+       const char *key;
+       long HKLen;
+       
+       output_custom_content_header("text/css");
+       hprintf("Cache-Control: private\r\n");
+       
+       begin_burst();
+       wprintf("#global { left: 16%%; }\r\n");
+       pos = GetNewHashPos(WC->IconBarSettings, 0);
+       while(GetNextHashPos(WC->IconBarSettings, pos, &HKLen, &key, &Data)) {
+               value = (long) Data;
+               if (value == 0 
+                   && strncasecmp("ib_displayas",key,12) 
+                   && strncasecmp("ib_logoff", key, 9)) {
+                       /* Don't shoot me for this */
+                       wprintf("#%s { display: none !important; }\r\n",key);
+               } else if (!strncasecmp("ib_users",key, 8) && value == 2) {
+                       wprintf("#online_users { display: block; !important } \r\n");
+               }
+       }
+       DeleteHashPos(&pos);
+       end_burst();
 }
 
 int ConditionalIsActiveStylesheet(StrBuf *Target, WCTemplputParams *TP) {
-  long testFor = TP->Tokens->Params[3]->lvalue;
-  int ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT);
-  return (testFor == ib_displayas);
+       long testFor = TP->Tokens->Params[3]->lvalue;
+       int ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT);
+       return (testFor == ib_displayas);
 }
 
-void LoadIconSettings(void)
+void LoadIconSettings(StrBuf *iconbar, long lvalue)
 {
        wcsession *WCC = WC;
-       StrBuf *iconbar = NULL;
        StrBuf *buf;
        StrBuf *key;
        long val;
@@ -91,16 +97,14 @@ void LoadIconSettings(void)
         * configuration somewhere.
         */
 
-       if (get_preference("iconbar", &iconbar)) {
-               nTokens = StrBufNum_tokens(iconbar, ',');
-               for (i=0; i<nTokens; ++i) {
-                       StrBufExtract_token(buf, iconbar, i, ',');
-                       StrBufExtract_token(key, buf, 0, '=');
-                       val = StrBufExtract_long(buf, 1, '=');
-                       Put(WCC->IconBarSettings, 
-                           ChrPtr(key), StrLength(key),
-                           (void*)val, DontDeleteThis);
-               }
+       nTokens = StrBufNum_tokens(iconbar, ',');
+       for (i=0; i<nTokens; ++i) {
+               StrBufExtract_token(buf, iconbar, i, ',');
+               StrBufExtract_token(key, buf, 0, '=');
+               val = StrBufExtract_long(buf, 1, '=');
+               Put(WCC->IconBarSettings, 
+                   ChrPtr(key), StrLength(key),
+                   (void*)val, DontDeleteThis);
        }
 
 #ifdef DBG_ICONBAR_HASH
@@ -121,8 +125,6 @@ void display_customize_iconbar(void) {
 
        int ib_displayas;
 
-       LoadIconSettings();
-
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">");
        wprintf("<h1>");
@@ -480,12 +482,13 @@ void
 InitModule_ICONBAR
 (void)
 {
-  WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet, 0);
-  WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0);
-  RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
+       WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet, 0);
+       WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0);
+       RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
        WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar, 0);
        RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, 0);
 
+       RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
 }
 
 
index b65b29d274b458ce1a5102ff65b9725a5a1d0411..e3275432752c581288d4412b93d1809cf517138c 100644 (file)
@@ -929,5 +929,3 @@ typedef void (*IcalCallbackFunc)(icalcomponent *, long, char*, int, struct calvi
 #define WC_TIMEFORMAT_AMPM 1
 #define WC_TIMEFORMAT_24 2
 
-
-void LoadIconSettings(void);