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
)
22 if (GetHash(WC
->IconBarSettings
, key
, keylen
,
29 #ifdef DBG_ICONBAR_HASH
31 inline const char *PrintInt(void *Prefstr
)
33 snprintf(nbuf
, sizeof(nbuf
), "%ld", (long)Prefstr
);
38 /** Produces a stylesheet which hides any iconbar icons the user does not want */
39 void doUserIconStylesheet(void) {
47 output_custom_content_header("text/css");
48 hprintf("Cache-Control: private\r\n");
51 wprintf("#global { left: 16%%; }\r\n");
52 pos
= GetNewHashPos(WC
->IconBarSettings
, 0);
53 while(GetNextHashPos(WC
->IconBarSettings
, pos
, &HKLen
, &key
, &Data
)) {
56 && strncasecmp("ib_displayas",key
,12)
57 && strncasecmp("ib_logoff", key
, 9)) {
58 /* Don't shoot me for this */
59 wprintf("#%s { display: none !important; }\r\n",key
);
60 } else if (!strncasecmp("ib_users",key
, 8) && value
== 2) {
61 wprintf("#online_users { display: block; !important } \r\n");
68 int ConditionalIsActiveStylesheet(StrBuf
*Target
, WCTemplputParams
*TP
) {
69 long testFor
= TP
->Tokens
->Params
[3]->lvalue
;
70 int ib_displayas
= IconbarIsEnabled("ib_displayas",IB_PICTEXT
);
71 return (testFor
== ib_displayas
);
74 void LoadIconSettings(void)
77 StrBuf
*iconbar
= NULL
;
85 if (WCC
->IconBarSettings
== NULL
)
86 WCC
->IconBarSettings
= NewHash(1, NULL
);
88 * The initialized values of these variables also happen to
89 * specify the default values for users who haven't customized
90 * their iconbars. These should probably be set in a master
91 * configuration somewhere.
94 if (get_preference("iconbar", &iconbar
)) {
95 nTokens
= StrBufNum_tokens(iconbar
, ',');
96 for (i
=0; i
<nTokens
; ++i
) {
97 StrBufExtract_token(buf
, iconbar
, i
, ',');
98 StrBufExtract_token(key
, buf
, 0, '=');
99 val
= StrBufExtract_long(buf
, 1, '=');
100 Put(WCC
->IconBarSettings
,
101 ChrPtr(key
), StrLength(key
),
102 (void*)val
, DontDeleteThis
);
106 #ifdef DBG_ICONBAR_HASH
107 dbg_PrintHash(WCC
->IconBarSetttings
, PrintInt
, NULL
);
115 * \brief display a customized version of the iconbar
117 void display_customize_iconbar(void) {
126 output_headers(1, 1, 2, 0, 0, 0);
127 wprintf("<div id=\"banner\">");
129 wprintf(_("Customize the icon bar"));
130 wprintf("</h1></div>\n");
132 wprintf("<div id=\"content\" class=\"service\">\n");
134 wprintf("<div class=\"fix_scrollbar_bug\">");
136 wprintf("<form method=\"post\" action=\"commit_iconbar\">\n");
137 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC
->nonce
);
139 wprintf("<table class=\"altern\" >\n");
140 wprintf("<tr><td></td><td colspan=\"2\"><b>");
141 wprintf(_("Display icons as:"));
143 ib_displayas
= IconbarIsEnabled("ib_displayas",IB_PICTEXT
);
144 for (i
=0; i
<=2; ++i
) {
145 wprintf("<input type=\"radio\" name=\"ib_displayas\" value=\"%d\"", i
);
146 if (ib_displayas
== i
) wprintf(" CHECKED");
148 if (i
== IB_PICTEXT
) wprintf(_("pictures and text"));
149 if (i
== IB_PICONLY
) wprintf(_("pictures only"));
150 if (i
== IB_TEXTONLY
) wprintf(_("text only"));
155 wprintf(_("Select the icons you would like to see displayed "
156 "in the 'icon bar' menu on the left side of the "
158 wprintf("</td></tr>\n");
161 val
= IconbarIsEnabled("ib_logo", 0);
162 wprintf("<tr class=\"%s\"><td>"
163 "<input type=\"radio\" name=\"ib_logo\" value=\"yes\" %s> %s "
164 "<input type=\"radio\" name=\"ib_logo\" value=\"no\" %s> %s <br />"
166 "<img src=\"image&name=hello\" width=\"48\" alt=\" \">"
171 (bar
? "even" : "odd"),
172 (val
? "CHECKED" : ""),_("Yes"),
173 (!val
? "CHECKED" : ""),_("No"),
175 _("An icon describing this site")
179 val
= IconbarIsEnabled("ib_summary", 1);
180 wprintf("<tr class=\"%s\"><td>"
181 "<input type=\"radio\" name=\"ib_summary\" value=\"yes\" %s> %s "
182 "<input type=\"radio\" name=\"ib_summary\" value=\"no\" %s> %s <br />"
184 "<img src=\"static/summscreen_48x.gif\" alt=\" \">"
189 (bar
? "even" : "odd"),
190 (val
? "CHECKED" : ""),_("Yes"),
191 (!val
? "CHECKED" : ""),_("No"),
193 _("Your summary page")
197 val
= IconbarIsEnabled("ib_inbox", 1);
198 wprintf("<tr class=\"%s\"><td>"
199 "<input type=\"radio\" name=\"ib_inbox\" value=\"yes\" %s> %s "
200 "<input type=\"radio\" name=\"ib_inbox\" value=\"no\" %s> %s <br />"
202 "<img src=\"static/privatemess_48x.gif\" alt=\" \">"
207 (bar
? "even" : "odd"),
208 (val
? "CHECKED" : ""),_("Yes"),
209 (!val
? "CHECKED" : ""),_("No"),
211 _("A shortcut to your email Inbox")
215 val
= IconbarIsEnabled("ib_contacts", 1);
216 wprintf("<tr class=\"%s\"><td>"
217 "<input type=\"radio\" name=\"ib_contacts\" value=\"yes\" %s> %s "
218 "<input type=\"radio\" name=\"ib_contacts\" value=\"no\" %s> %s <br />"
220 "<img src=\"static/viewcontacts_48x.gif\" alt=\" \">"
225 (bar
? "even" : "odd"),
226 (val
? "CHECKED" : ""),_("Yes"),
227 (!val
? "CHECKED" : ""),_("No"),
229 _("Your personal address book")
233 val
= IconbarIsEnabled("ib_notes", 1);
234 wprintf("<tr class=\"%s\"><td>"
235 "<input type=\"radio\" name=\"ib_notes\" value=\"yes\" %s> %s "
236 "<input type=\"radio\" name=\"ib_notes\" value=\"no\" %s> %s <br />"
238 "<img src=\"static/storenotes_48x.gif\" alt=\" \">"
243 (bar
? "even" : "odd"),
244 (val
? "CHECKED" : ""),_("Yes"),
245 (!val
? "CHECKED" : ""),_("No"),
247 _("Your personal notes")
251 val
= IconbarIsEnabled("ib_calendar", 1);
252 wprintf("<tr class=\"%s\"><td>"
253 "<input type=\"radio\" name=\"ib_calendar\" value=\"yes\" %s> %s "
254 "<input type=\"radio\" name=\"ib_calendar\" value=\"no\" %s> %s <br />"
256 "<img src=\"static/calarea_48x.gif\" alt=\" \">"
261 (bar
? "even" : "odd"),
262 (val
? "CHECKED" : ""),_("Yes"),
263 (!val
? "CHECKED" : ""),_("No"),
265 _("A shortcut to your personal calendar")
269 val
= IconbarIsEnabled("ib_tasks", 1);
270 wprintf("<tr class=\"%s\"><td>"
271 "<input type=\"radio\" name=\"ib_tasks\" value=\"yes\" %s> %s "
272 "<input type=\"radio\" name=\"ib_tasks\" value=\"no\" %s> %s <br />"
274 "<img src=\"static/taskmanag_48x.gif\" alt=\" \">"
279 (bar
? "even" : "odd"),
280 (val
? "CHECKED" : ""),_("Yes"),
281 (!val
? "CHECKED" : ""),_("No"),
283 _("A shortcut to your personal task list")
287 val
= IconbarIsEnabled("ib_rooms", 1);
288 wprintf("<tr class=\"%s\"><td>"
289 "<input type=\"radio\" name=\"ib_rooms\" value=\"yes\" %s> %s "
290 "<input type=\"radio\" name=\"ib_rooms\" value=\"no\" %s> %s <br />"
292 "<img src=\"static/chatrooms_48x.gif\" alt=\" \">"
297 (bar
? "even" : "odd"),
298 (val
? "CHECKED" : ""),_("Yes"),
299 (!val
? "CHECKED" : ""),_("No"),
301 _("Clicking this icon displays a list of all accessible "
302 "rooms (or folders) available.")
306 val
= IconbarIsEnabled("ib_users", 1);
307 wprintf("<tr class=\"%s\"><td>"
308 "<input type=\"radio\" name=\"ib_users\" value=\"yes\" %s> %s "
309 "<input type=\"radio\" name=\"ib_users\" value=\"no\" %s> %s <br />"
310 "<input type=\"radio\" name=\"ib_users\" value=\"yeslist\" %s> %s"
312 "<img src=\"static/usermanag_48x.gif\" alt=\" \">"
317 (bar
? "even" : "odd"),
318 (val
? "CHECKED" : ""),_("Yes"),
319 (!val
? "CHECKED" : ""),_("No"),
320 ((val
> 1) ? "CHECKED" : ""),_("Yes with users list"),
322 _("Clicking this icon displays a list of all users "
323 "currently logged in.")
327 val
= IconbarIsEnabled("ib_chat", 1);
328 wprintf("<tr class=\"%s\"><td>"
329 "<input type=\"radio\" name=\"ib_chat\" value=\"yes\" %s> %s "
330 "<input type=\"radio\" name=\"ib_chat\" value=\"no\" %s> %s <br />"
332 "<img src=\"static/citadelchat_48x.gif\" alt=\" \">"
337 (bar
? "even" : "odd"),
338 (val
? "CHECKED" : ""),_("Yes"),
339 (!val
? "CHECKED" : ""),_("No"),
341 _("Clicking this icon enters real-time chat mode "
342 "with other users in the same room.")
347 val
= IconbarIsEnabled("ib_advanced", 1);
348 wprintf("<tr class=\"%s\"><td>"
349 "<input type=\"radio\" name=\"ib_advanced\" value=\"yes\" %s> %s "
350 "<input type=\"radio\" name=\"ib_advanced\" value=\"no\" %s> %s <br />"
352 "<img src=\"static/advanpage2_48x.gif\" alt=\" \">"
357 (bar
? "even" : "odd"),
358 (val
? "CHECKED" : ""),_("Yes"),
359 (!val
? "CHECKED" : ""),_("No"),
360 _("Advanced options"),
361 _("Access to the complete menu of Citadel functions.")
366 val
= IconbarIsEnabled("ib_citadel", 1);
367 wprintf("<tr class=\"%s\"><td>"
368 "<input type=\"radio\" name=\"ib_citadel\" value=\"yes\" %s> %s "
369 "<input type=\"radio\" name=\"ib_citadel\" value=\"no\" %s> %s <br />"
371 "<img border=\"0\" width=\"48\" height=\"48\" "
372 "src=\"static/citadel-logo.gif\" alt=\" \">"
377 (bar
? "even" : "odd"),
378 (val
? "CHECKED" : ""),_("Yes"),
379 (!val
? "CHECKED" : ""),_("No"),
381 _("Displays the 'Powered by Citadel' icon")
384 wprintf("</table><br />\n"
386 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
388 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
394 wprintf("</form></div>\n");
399 * \brief commit the changes of an edited iconbar ????
401 void commit_iconbar(void) {
422 if (!havebstr("ok_button")) {
427 iconbar
= NewStrBuf();
429 StrBufPrintf(iconbar
, "ib_displayas=%d", ibstr("ib_displayas"));
430 for (i
=0; i
<(sizeof(boxen
)/sizeof(char *)); ++i
) {
432 if (!strcasecmp(BSTR(boxen
[i
]), "yes")) {
435 else if (!strcasecmp(BSTR(boxen
[i
]), "yeslist")) {
441 StrBufPrintf(buf
, ",%s=%s", boxen
[i
], Val
);
442 StrBufAppendBuf(iconbar
, buf
, 0);
446 set_preference("iconbar", iconbar
, 1);
448 output_headers(1, 1, 2, 0, 0, 0);
450 wprintf("<div id=\"banner\">\n");
452 wprintf(_("Customize the icon bar"));
453 wprintf("</h1></div>\n");
455 wprintf("<div id=\"content\" class=\"service\">\n");
457 "<center><table border=1 bgcolor=\"#ffffff\"><tr><td>"
458 "<img src=\"static/advanpage2_48x.gif\">"
460 wprintf(_("Your icon bar has been updated. Please select any of its "
461 "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>"));
462 wprintf("</td></tr></table>\n");
464 #ifdef DBG_ICONBAR_HASH
465 dbg_PrintHash(WC
->IconBarSetttings
, PrintInt
, NULL
);
470 void tmplput_iconbar(StrBuf
*Target
, WCTemplputParams
*TP
)
474 if ((WCC
!= NULL
) && (WCC
->logged_in
)) {
475 DoTemplate(HKEY("iconbar"), NULL
, &NoCtx
);
483 WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet
, 0);
484 WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar
, 0);
485 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet
, CTX_NONE
);
486 WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar
, 0);
487 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar
, 0);