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)
20 typedef struct _dflt_IB_Setting {
26 dflt_IB_Setting IconbarDefaults[] = {
27 {0, HKEY("ib_displayas")},
29 {1, HKEY("ib_summary")},
30 {1, HKEY("ib_inbox")},
31 {1, HKEY("ib_calendar")},
32 {1, HKEY("ib_contacts")},
33 {1, HKEY("ib_notes")},
34 {1, HKEY("ib_tasks")},
35 {1, HKEY("ib_rooms")},
36 {1, HKEY("ib_users")},
38 {1, HKEY("ib_advanced")},
39 {1, HKEY("ib_logoff")},
40 {1, HKEY("ib_citadel")},
44 HashList *IBDfl = NULL;
46 long IconbarGetDefault(const char *key, size_t keylen)
50 if (GetHash(IBDfl, key, keylen, &vIBDfl)) {
51 dflt_IB_Setting *Set = (dflt_IB_Setting*)vIBDfl;
56 long IconbarIsENABLED(const char *key, size_t keylen, long defval)
64 if (GetHash(WCC->IconBarSettings,
73 #ifdef DBG_ICONBAR_HASH
75 inline const char *PrintInt(void *Prefstr)
77 snprintf(nbuf, sizeof(nbuf), "%ld", (long)Prefstr);
82 /* Produces a stylesheet which hides any iconbar icons the user does not want */
83 void doUserIconStylesheet(void) {
90 output_custom_content_header("text/css");
91 hprintf("Cache-Control: private\r\n");
94 wprintf("#global { left: 16%%; }\r\n");
95 pos = GetNewHashPos(WC->IconBarSettings, 0);
96 while(GetNextHashPos(WC->IconBarSettings, pos, &HKLen, &key, &Data)) {
99 && strncasecmp("ib_displayas",key,12)
100 && strncasecmp("ib_logoff", key, 9)) {
101 /* Don't shoot me for this */
102 wprintf("#%s { display: none !important; }\r\n",key);
103 } else if (!strncasecmp("ib_users",key, 8) && value == 2) {
104 wprintf("#online_users { display: block; !important } \r\n");
111 int ConditionalIsActiveStylesheet(StrBuf *Target, WCTemplputParams *TP) {
115 testFor = GetTemplateTokenNumber(Target, TP, 3, IB_PICTEXT);
116 ib_displayas = IconbarIsENABLED(TKEY(2),IconbarGetDefault(TKEY(2)));
117 return (testFor == ib_displayas);
120 void LoadIconSettings(StrBuf *iconbar, long lvalue)
130 if (WCC->IconBarSettings == NULL)
131 WCC->IconBarSettings = NewHash(1, NULL);
133 * The initialized values of these variables also happen to
134 * specify the default values for users who haven't customized
135 * their iconbars. These should probably be set in a master
136 * configuration somewhere.
139 nTokens = StrBufNum_tokens(iconbar, ',');
140 for (i=0; i<nTokens; ++i) {
141 StrBufExtract_token(buf, iconbar, i, ',');
142 StrBufExtract_token(key, buf, 0, '=');
143 val = StrBufExtract_long(buf, 1, '=');
144 Put(WCC->IconBarSettings,
145 ChrPtr(key), StrLength(key),
146 (void*)val, DontDeleteThis);
149 #ifdef DBG_ICONBAR_HASH
150 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
159 * save changes to iconbar settings
161 void commit_iconbar(void) {
162 const StrBuf *MimeType;
168 if (!havebstr("ok_button")) {
173 iconbar = NewStrBuf();
175 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
176 for (i=0; i<(sizeof(IconbarDefaults)/sizeof(dflt_IB_Setting )); ++i) {
178 if (!strcasecmp(Bstr(IconbarDefaults[i].Key,
179 IconbarDefaults[i].len),
184 else if (!strcasecmp(Bstr(IconbarDefaults[i].Key,
185 IconbarDefaults[i].len),
193 StrBufPrintf(buf, ",%s=%s", IconbarDefaults[i].Key, Val);
194 StrBufAppendBuf(iconbar, buf, 0);
198 set_preference("iconbar", iconbar, 1);
202 MimeType = DoTemplate(HKEY("iconbar_save"), NULL, &NoCtx);
203 http_transmit_thing(ChrPtr(MimeType), 0);
204 #ifdef DBG_ICONBAR_HASH
205 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
210 void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
214 if ((WCC != NULL) && (WCC->logged_in)) {
215 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
221 ServerShutdownModule_ICONBAR
230 ServerStartModule_ICONBAR
234 IBDfl = NewHash(1, NULL);
236 while (IconbarDefaults[i].len != 0)
239 IconbarDefaults[i].Key,
240 IconbarDefaults[i].len,
242 reference_free_handler);
251 WebcitAddUrlHandler(HKEY("user_iconbar"), "", 0, doUserIconStylesheet, 0);
252 WebcitAddUrlHandler(HKEY("commit_iconbar"), "", 0, commit_iconbar, 0);
253 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
254 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, NULL, CTX_NONE);
256 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
262 SessionDestroyModule_ICONBAR
265 DeleteHash(&sess->IconBarSettings);