4 * Displays and customizes the iconbar.
9 /* Values for ib_displayas ... don't change these or you will break the templates */
10 #define IB_PICTEXT 0 /* picture and text */
11 #define IB_PICONLY 1 /* just a picture */
12 #define IB_TEXTONLY 2 /* just text */
14 void DontDeleteThis(void *Data){}
16 #define IconbarIsEnabled(a, b) IconbarIsENABLED(a, sizeof(a) - 1, b)
18 long IconbarIsENABLED(const char *key, size_t keylen, long defval)
26 if (GetHash(WCC->IconBarSettings,
35 #ifdef DBG_ICONBAR_HASH
37 inline const char *PrintInt(void *Prefstr)
39 snprintf(nbuf, sizeof(nbuf), "%ld", (long)Prefstr);
44 /* Produces a stylesheet which hides any iconbar icons the user does not want */
45 void doUserIconStylesheet(void) {
52 output_custom_content_header("text/css");
53 hprintf("Cache-Control: private\r\n");
56 wprintf("#global { left: 16%%; }\r\n");
57 pos = GetNewHashPos(WC->IconBarSettings, 0);
58 while(GetNextHashPos(WC->IconBarSettings, pos, &HKLen, &key, &Data)) {
61 && strncasecmp("ib_displayas",key,12)
62 && strncasecmp("ib_logoff", key, 9)) {
63 /* Don't shoot me for this */
64 wprintf("#%s { display: none !important; }\r\n",key);
65 } else if (!strncasecmp("ib_users",key, 8) && value == 2) {
66 wprintf("#online_users { display: block; !important } \r\n");
73 int ConditionalIsActiveStylesheet(StrBuf *Target, WCTemplputParams *TP) {
77 testFor = GetTemplateTokenNumber(Target, TP, 3, IB_PICTEXT);
78 ib_displayas = IconbarIsENABLED(TKEY(2),0);
79 return (testFor == ib_displayas);
82 void LoadIconSettings(StrBuf *iconbar, long lvalue)
92 if (WCC->IconBarSettings == NULL)
93 WCC->IconBarSettings = NewHash(1, NULL);
95 * The initialized values of these variables also happen to
96 * specify the default values for users who haven't customized
97 * their iconbars. These should probably be set in a master
98 * configuration somewhere.
101 nTokens = StrBufNum_tokens(iconbar, ',');
102 for (i=0; i<nTokens; ++i) {
103 StrBufExtract_token(buf, iconbar, i, ',');
104 StrBufExtract_token(key, buf, 0, '=');
105 val = StrBufExtract_long(buf, 1, '=');
106 Put(WCC->IconBarSettings,
107 ChrPtr(key), StrLength(key),
108 (void*)val, DontDeleteThis);
111 #ifdef DBG_ICONBAR_HASH
112 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
121 * save changes to iconbar settings
123 void commit_iconbar(void) {
124 const StrBuf *MimeType;
145 if (!havebstr("ok_button")) {
150 iconbar = NewStrBuf();
152 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
153 for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) {
155 if (!strcasecmp(BSTR(boxen[i]), "yes")) {
158 else if (!strcasecmp(BSTR(boxen[i]), "yeslist")) {
164 StrBufPrintf(buf, ",%s=%s", boxen[i], Val);
165 StrBufAppendBuf(iconbar, buf, 0);
169 set_preference("iconbar", iconbar, 1);
173 MimeType = DoTemplate(HKEY("iconbar_save"), NULL, &NoCtx);
174 http_transmit_thing(ChrPtr(MimeType), 0);
175 #ifdef DBG_ICONBAR_HASH
176 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
181 void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
185 if ((WCC != NULL) && (WCC->logged_in)) {
186 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
194 WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet, 0);
195 WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0);
196 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
197 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, 0);
199 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
205 SessionDestroyModule_ICONBAR
208 DeleteHash(&sess->IconBarSettings);