4 * Displays and customizes the iconbar.
10 /** Values for ib_displayas */
11 #define IB_PICTEXT 0 /**< picture and text */
12 #define IB_PICONLY 1 /**< just a picture */
13 #define IB_TEXTONLY 2 /**< just text */
15 void DontDeleteThis(void *Data){}
17 #define IconbarIsEnabled(a, b) IconbarIsENABLED(a, sizeof(a) - 1, b)
19 long IconbarIsENABLED(const char *key, size_t keylen, long defval)
27 if (GetHash(WCC->IconBarSettings,
37 #ifdef DBG_ICONBAR_HASH
39 inline const char *PrintInt(void *Prefstr)
41 snprintf(nbuf, sizeof(nbuf), "%ld", (long)Prefstr);
46 /** Produces a stylesheet which hides any iconbar icons the user does not want */
47 void doUserIconStylesheet(void) {
54 output_custom_content_header("text/css");
55 hprintf("Cache-Control: private\r\n");
58 wprintf("#global { left: 16%%; }\r\n");
59 pos = GetNewHashPos(WC->IconBarSettings, 0);
60 while(GetNextHashPos(WC->IconBarSettings, pos, &HKLen, &key, &Data)) {
63 && strncasecmp("ib_displayas",key,12)
64 && strncasecmp("ib_logoff", key, 9)) {
65 /* Don't shoot me for this */
66 wprintf("#%s { display: none !important; }\r\n",key);
67 } else if (!strncasecmp("ib_users",key, 8) && value == 2) {
68 wprintf("#online_users { display: block; !important } \r\n");
75 int ConditionalIsActiveStylesheet(StrBuf *Target, WCTemplputParams *TP) {
76 long testFor = TP->Tokens->Params[3]->lvalue;
77 int ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT);
78 return (testFor == ib_displayas);
81 void LoadIconSettings(StrBuf *iconbar, long lvalue)
91 if (WCC->IconBarSettings == NULL)
92 WCC->IconBarSettings = NewHash(1, NULL);
94 * The initialized values of these variables also happen to
95 * specify the default values for users who haven't customized
96 * their iconbars. These should probably be set in a master
97 * configuration somewhere.
100 nTokens = StrBufNum_tokens(iconbar, ',');
101 for (i=0; i<nTokens; ++i) {
102 StrBufExtract_token(buf, iconbar, i, ',');
103 StrBufExtract_token(key, buf, 0, '=');
104 val = StrBufExtract_long(buf, 1, '=');
105 Put(WCC->IconBarSettings,
106 ChrPtr(key), StrLength(key),
107 (void*)val, DontDeleteThis);
110 #ifdef DBG_ICONBAR_HASH
111 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
119 * \brief display a customized version of the iconbar
121 void display_customize_iconbar(void) {
128 output_headers(1, 1, 2, 0, 0, 0);
129 wprintf("<div id=\"banner\">");
131 wprintf(_("Customize the icon bar"));
132 wprintf("</h1></div>\n");
134 wprintf("<div id=\"content\" class=\"service\">\n");
136 wprintf("<div class=\"fix_scrollbar_bug\">");
138 wprintf("<form method=\"post\" action=\"commit_iconbar\">\n");
139 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
141 wprintf("<table class=\"altern\" >\n");
142 wprintf("<tr><td></td><td colspan=\"2\"><b>");
143 wprintf(_("Display icons as:"));
145 ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT);
146 for (i=0; i<=2; ++i) {
147 wprintf("<input type=\"radio\" name=\"ib_displayas\" value=\"%d\"", i);
148 if (ib_displayas == i) wprintf(" CHECKED");
150 if (i == IB_PICTEXT) wprintf(_("pictures and text"));
151 if (i == IB_PICONLY) wprintf(_("pictures only"));
152 if (i == IB_TEXTONLY) wprintf(_("text only"));
157 wprintf(_("Select the icons you would like to see displayed "
158 "in the 'icon bar' menu on the left side of the "
160 wprintf("</td></tr>\n");
163 val = IconbarIsEnabled("ib_logo", 0);
164 wprintf("<tr class=\"%s\"><td>"
165 "<input type=\"radio\" name=\"ib_logo\" value=\"yes\" %s> %s "
166 "<input type=\"radio\" name=\"ib_logo\" value=\"no\" %s> %s <br />"
168 "<img src=\"image&name=hello\" width=\"48\" alt=\" \">"
173 (bar ? "even" : "odd"),
174 (val ? "CHECKED" : ""),_("Yes"),
175 (!val ? "CHECKED" : ""),_("No"),
177 _("An icon describing this site")
181 val = IconbarIsEnabled("ib_summary", 1);
182 wprintf("<tr class=\"%s\"><td>"
183 "<input type=\"radio\" name=\"ib_summary\" value=\"yes\" %s> %s "
184 "<input type=\"radio\" name=\"ib_summary\" value=\"no\" %s> %s <br />"
186 "<img src=\"static/summscreen_48x.gif\" alt=\" \">"
191 (bar ? "even" : "odd"),
192 (val ? "CHECKED" : ""),_("Yes"),
193 (!val ? "CHECKED" : ""),_("No"),
195 _("Your summary page")
199 val = IconbarIsEnabled("ib_inbox", 1);
200 wprintf("<tr class=\"%s\"><td>"
201 "<input type=\"radio\" name=\"ib_inbox\" value=\"yes\" %s> %s "
202 "<input type=\"radio\" name=\"ib_inbox\" value=\"no\" %s> %s <br />"
204 "<img src=\"static/privatemess_48x.gif\" alt=\" \">"
209 (bar ? "even" : "odd"),
210 (val ? "CHECKED" : ""),_("Yes"),
211 (!val ? "CHECKED" : ""),_("No"),
213 _("A shortcut to your email Inbox")
217 val = IconbarIsEnabled("ib_contacts", 1);
218 wprintf("<tr class=\"%s\"><td>"
219 "<input type=\"radio\" name=\"ib_contacts\" value=\"yes\" %s> %s "
220 "<input type=\"radio\" name=\"ib_contacts\" value=\"no\" %s> %s <br />"
222 "<img src=\"static/viewcontacts_48x.gif\" alt=\" \">"
227 (bar ? "even" : "odd"),
228 (val ? "CHECKED" : ""),_("Yes"),
229 (!val ? "CHECKED" : ""),_("No"),
231 _("Your personal address book")
235 val = IconbarIsEnabled("ib_notes", 1);
236 wprintf("<tr class=\"%s\"><td>"
237 "<input type=\"radio\" name=\"ib_notes\" value=\"yes\" %s> %s "
238 "<input type=\"radio\" name=\"ib_notes\" value=\"no\" %s> %s <br />"
240 "<img src=\"static/storenotes_48x.gif\" alt=\" \">"
245 (bar ? "even" : "odd"),
246 (val ? "CHECKED" : ""),_("Yes"),
247 (!val ? "CHECKED" : ""),_("No"),
249 _("Your personal notes")
253 val = IconbarIsEnabled("ib_calendar", 1);
254 wprintf("<tr class=\"%s\"><td>"
255 "<input type=\"radio\" name=\"ib_calendar\" value=\"yes\" %s> %s "
256 "<input type=\"radio\" name=\"ib_calendar\" value=\"no\" %s> %s <br />"
258 "<img src=\"static/calarea_48x.gif\" alt=\" \">"
263 (bar ? "even" : "odd"),
264 (val ? "CHECKED" : ""),_("Yes"),
265 (!val ? "CHECKED" : ""),_("No"),
267 _("A shortcut to your personal calendar")
271 val = IconbarIsEnabled("ib_tasks", 1);
272 wprintf("<tr class=\"%s\"><td>"
273 "<input type=\"radio\" name=\"ib_tasks\" value=\"yes\" %s> %s "
274 "<input type=\"radio\" name=\"ib_tasks\" value=\"no\" %s> %s <br />"
276 "<img src=\"static/taskmanag_48x.gif\" alt=\" \">"
281 (bar ? "even" : "odd"),
282 (val ? "CHECKED" : ""),_("Yes"),
283 (!val ? "CHECKED" : ""),_("No"),
285 _("A shortcut to your personal task list")
289 val = IconbarIsEnabled("ib_rooms", 1);
290 wprintf("<tr class=\"%s\"><td>"
291 "<input type=\"radio\" name=\"ib_rooms\" value=\"yes\" %s> %s "
292 "<input type=\"radio\" name=\"ib_rooms\" value=\"no\" %s> %s <br />"
294 "<img src=\"static/chatrooms_48x.gif\" alt=\" \">"
299 (bar ? "even" : "odd"),
300 (val ? "CHECKED" : ""),_("Yes"),
301 (!val ? "CHECKED" : ""),_("No"),
303 _("Clicking this icon displays a list of all accessible "
304 "rooms (or folders) available.")
308 val = IconbarIsEnabled("ib_users", 1);
309 wprintf("<tr class=\"%s\"><td>"
310 "<input type=\"radio\" name=\"ib_users\" value=\"yes\" %s> %s "
311 "<input type=\"radio\" name=\"ib_users\" value=\"no\" %s> %s <br />"
312 "<input type=\"radio\" name=\"ib_users\" value=\"yeslist\" %s> %s"
314 "<img src=\"static/usermanag_48x.gif\" alt=\" \">"
319 (bar ? "even" : "odd"),
320 (val ? "CHECKED" : ""),_("Yes"),
321 (!val ? "CHECKED" : ""),_("No"),
322 ((val > 1) ? "CHECKED" : ""),_("Yes with users list"),
324 _("Clicking this icon displays a list of all users "
325 "currently logged in.")
329 val = IconbarIsEnabled("ib_chat", 1);
330 wprintf("<tr class=\"%s\"><td>"
331 "<input type=\"radio\" name=\"ib_chat\" value=\"yes\" %s> %s "
332 "<input type=\"radio\" name=\"ib_chat\" value=\"no\" %s> %s <br />"
334 "<img src=\"static/citadelchat_48x.gif\" alt=\" \">"
339 (bar ? "even" : "odd"),
340 (val ? "CHECKED" : ""),_("Yes"),
341 (!val ? "CHECKED" : ""),_("No"),
343 _("Clicking this icon enters real-time chat mode "
344 "with other users in the same room.")
349 val = IconbarIsEnabled("ib_advanced", 1);
350 wprintf("<tr class=\"%s\"><td>"
351 "<input type=\"radio\" name=\"ib_advanced\" value=\"yes\" %s> %s "
352 "<input type=\"radio\" name=\"ib_advanced\" value=\"no\" %s> %s <br />"
354 "<img src=\"static/advanpage2_48x.gif\" alt=\" \">"
359 (bar ? "even" : "odd"),
360 (val ? "CHECKED" : ""),_("Yes"),
361 (!val ? "CHECKED" : ""),_("No"),
362 _("Advanced options"),
363 _("Access to the complete menu of Citadel functions.")
368 val = IconbarIsEnabled("ib_citadel", 1);
369 wprintf("<tr class=\"%s\"><td>"
370 "<input type=\"radio\" name=\"ib_citadel\" value=\"yes\" %s> %s "
371 "<input type=\"radio\" name=\"ib_citadel\" value=\"no\" %s> %s <br />"
373 "<img border=\"0\" width=\"48\" height=\"48\" "
374 "src=\"static/citadel-logo.gif\" alt=\" \">"
379 (bar ? "even" : "odd"),
380 (val ? "CHECKED" : ""),_("Yes"),
381 (!val ? "CHECKED" : ""),_("No"),
383 _("Displays the 'Powered by Citadel' icon")
386 wprintf("</table><br />\n"
388 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
390 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
396 wprintf("</form></div>\n");
401 * \brief commit the changes of an edited iconbar ????
403 void commit_iconbar(void) {
424 if (!havebstr("ok_button")) {
429 iconbar = NewStrBuf();
431 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
432 for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) {
434 if (!strcasecmp(BSTR(boxen[i]), "yes")) {
437 else if (!strcasecmp(BSTR(boxen[i]), "yeslist")) {
443 StrBufPrintf(buf, ",%s=%s", boxen[i], Val);
444 StrBufAppendBuf(iconbar, buf, 0);
448 set_preference("iconbar", iconbar, 1);
450 output_headers(1, 1, 2, 0, 0, 0);
452 wprintf("<div id=\"banner\">\n");
454 wprintf(_("Customize the icon bar"));
455 wprintf("</h1></div>\n");
457 wprintf("<div id=\"content\" class=\"service\">\n");
459 "<center><table border=1 bgcolor=\"#ffffff\"><tr><td>"
460 "<img src=\"static/advanpage2_48x.gif\">"
462 wprintf(_("Your icon bar has been updated. Please select any of its "
463 "choices to continue.<br/><span style=\"font-weight: bold;\">You may need to force refresh (SHIFT-F5) in order for changes to take effect</span>"));
464 wprintf("</td></tr></table>\n");
466 #ifdef DBG_ICONBAR_HASH
467 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
472 void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
476 if ((WCC != NULL) && (WCC->logged_in)) {
477 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
485 WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet, 0);
486 WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0);
487 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
488 WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar, 0);
489 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, 0);
491 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
497 SessionDestroyModule_ICONBAR
500 DeleteHash(&sess->IconBarSettings);