]> code.citadel.org Git - citadel.git/blobdiff - webcit/iconbar.c
* use GetTemplateTokenNumber to retrieve token parameter values; this was one of...
[citadel.git] / webcit / iconbar.c
index 41e7e73e5b6ec402e5a10a4d0f39cf972ca4256e..532dfbdee53855f343dcdf3ada70d0db32a420ee 100644 (file)
@@ -6,11 +6,10 @@
 
 #include "webcit.h"
 
-
-/** Values for ib_displayas */
-#define IB_PICTEXT     0 /**< picture and text */
-#define IB_PICONLY     1 /**< just a picture */
-#define IB_TEXTONLY    2 /**< just text */
+/* Values for ib_displayas ... don't change these or you will break the templates */
+#define IB_PICTEXT     0       /* picture and text */
+#define IB_PICONLY     1       /* just a picture */
+#define IB_TEXTONLY    2       /* just text */
 
 void DontDeleteThis(void *Data){}
 
@@ -19,8 +18,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;
@@ -35,44 +42,47 @@ inline const char *PrintInt(void *Prefstr)
 }
 #endif
 
-/** Produces a stylesheet which hides any iconbar icons the user does not want */
+/* 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();
-  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: none; !important } \r\n");
-    }
-  }
-  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;
+       int ib_displayas;
+
+       testFor = GetTemplateTokenNumber(Target, TP, 3, IB_PICTEXT);
+       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;
@@ -89,16 +99,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
@@ -109,8 +117,8 @@ void LoadIconSettings(void)
        FreeStrBuf(&buf);
 }
 
-/**
- * \brief display a customized version of the iconbar
+/*
+ * display a customized version of the iconbar
  */
 void display_customize_iconbar(void) {
        int i;
@@ -119,8 +127,6 @@ void display_customize_iconbar(void) {
 
        int ib_displayas;
 
-       LoadIconSettings();
-
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">");
        wprintf("<h1>");
@@ -393,8 +399,8 @@ void display_customize_iconbar(void) {
        wDumpContent(2);
 }
 
-/**
- * \brief commit the changes of an edited iconbar ????
+/*
+ * save changes to iconbar settings
  */
 void commit_iconbar(void) {
        StrBuf *iconbar;
@@ -478,13 +484,20 @@ 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);
 }
 
 
-/*@}*/
+
+void 
+SessionDestroyModule_ICONBAR
+(wcsession *sess)
+{
+       DeleteHash(&sess->IconBarSettings);
+}