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 pos
= GetNewHashPos(WC
->IconBarSettings
, 0);
52 while(GetNextHashPos(WC
->IconBarSettings
, pos
, &HKLen
, &key
, &Data
)) {
55 && strncasecmp("ib_displayas",key
,12)
56 && strncasecmp("ib_logoff", key
, 9)) {
57 /* Don't shoot me for this */
58 wprintf("#%s { display: none !important; }\r\n",key
);
59 } else if (!strncasecmp("ib_users",key
, 8) && value
== 2) {
60 wprintf("#online_users { display: block; !important } \r\n");
67 int ConditionalIsActiveStylesheet(StrBuf
*Target
, WCTemplputParams
*TP
) {
68 long testFor
= TP
->Tokens
->Params
[3]->lvalue
;
69 int ib_displayas
= IconbarIsEnabled("ib_displayas",IB_PICTEXT
);
70 return (testFor
== ib_displayas
);
73 void LoadIconSettings(void)
76 StrBuf
*iconbar
= NULL
;
84 if (WCC
->IconBarSettings
== NULL
)
85 WCC
->IconBarSettings
= NewHash(1, NULL
);
87 * The initialized values of these variables also happen to
88 * specify the default values for users who haven't customized
89 * their iconbars. These should probably be set in a master
90 * configuration somewhere.
93 if (get_preference("iconbar", &iconbar
)) {
94 nTokens
= StrBufNum_tokens(iconbar
, ',');
95 for (i
=0; i
<nTokens
; ++i
) {
96 StrBufExtract_token(buf
, iconbar
, i
, ',');
97 StrBufExtract_token(key
, buf
, 0, '=');
98 val
= StrBufExtract_long(buf
, 1, '=');
99 Put(WCC
->IconBarSettings
,
100 ChrPtr(key
), StrLength(key
),
101 (void*)val
, DontDeleteThis
);
105 #ifdef DBG_ICONBAR_HASH
106 dbg_PrintHash(WCC
->IconBarSetttings
, PrintInt
, NULL
);
114 * \brief display a customized version of the iconbar
116 void display_customize_iconbar(void) {
125 output_headers(1, 1, 2, 0, 0, 0);
126 wprintf("<div id=\"banner\">");
128 wprintf(_("Customize the icon bar"));
129 wprintf("</h1></div>\n");
131 wprintf("<div id=\"content\" class=\"service\">\n");
133 wprintf("<div class=\"fix_scrollbar_bug\">");
135 wprintf("<form method=\"post\" action=\"commit_iconbar\">\n");
136 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC
->nonce
);
138 wprintf("<table class=\"altern\" >\n");
139 wprintf("<tr><td></td><td colspan=\"2\"><b>");
140 wprintf(_("Display icons as:"));
142 ib_displayas
= IconbarIsEnabled("ib_displayas",IB_PICTEXT
);
143 for (i
=0; i
<=2; ++i
) {
144 wprintf("<input type=\"radio\" name=\"ib_displayas\" value=\"%d\"", i
);
145 if (ib_displayas
== i
) wprintf(" CHECKED");
147 if (i
== IB_PICTEXT
) wprintf(_("pictures and text"));
148 if (i
== IB_PICONLY
) wprintf(_("pictures only"));
149 if (i
== IB_TEXTONLY
) wprintf(_("text only"));
154 wprintf(_("Select the icons you would like to see displayed "
155 "in the 'icon bar' menu on the left side of the "
157 wprintf("</td></tr>\n");
160 val
= IconbarIsEnabled("ib_logo", 0);
161 wprintf("<tr class=\"%s\"><td>"
162 "<input type=\"radio\" name=\"ib_logo\" value=\"yes\" %s> %s "
163 "<input type=\"radio\" name=\"ib_logo\" value=\"no\" %s> %s <br />"
165 "<img src=\"image&name=hello\" width=\"48\" alt=\" \">"
170 (bar
? "even" : "odd"),
171 (val
? "CHECKED" : ""),_("Yes"),
172 (!val
? "CHECKED" : ""),_("No"),
174 _("An icon describing this site")
178 val
= IconbarIsEnabled("ib_summary", 1);
179 wprintf("<tr class=\"%s\"><td>"
180 "<input type=\"radio\" name=\"ib_summary\" value=\"yes\" %s> %s "
181 "<input type=\"radio\" name=\"ib_summary\" value=\"no\" %s> %s <br />"
183 "<img src=\"static/summscreen_48x.gif\" alt=\" \">"
188 (bar
? "even" : "odd"),
189 (val
? "CHECKED" : ""),_("Yes"),
190 (!val
? "CHECKED" : ""),_("No"),
192 _("Your summary page")
196 val
= IconbarIsEnabled("ib_inbox", 1);
197 wprintf("<tr class=\"%s\"><td>"
198 "<input type=\"radio\" name=\"ib_inbox\" value=\"yes\" %s> %s "
199 "<input type=\"radio\" name=\"ib_inbox\" value=\"no\" %s> %s <br />"
201 "<img src=\"static/privatemess_48x.gif\" alt=\" \">"
206 (bar
? "even" : "odd"),
207 (val
? "CHECKED" : ""),_("Yes"),
208 (!val
? "CHECKED" : ""),_("No"),
210 _("A shortcut to your email Inbox")
214 val
= IconbarIsEnabled("ib_contacts", 1);
215 wprintf("<tr class=\"%s\"><td>"
216 "<input type=\"radio\" name=\"ib_contacts\" value=\"yes\" %s> %s "
217 "<input type=\"radio\" name=\"ib_contacts\" value=\"no\" %s> %s <br />"
219 "<img src=\"static/viewcontacts_48x.gif\" alt=\" \">"
224 (bar
? "even" : "odd"),
225 (val
? "CHECKED" : ""),_("Yes"),
226 (!val
? "CHECKED" : ""),_("No"),
228 _("Your personal address book")
232 val
= IconbarIsEnabled("ib_notes", 1);
233 wprintf("<tr class=\"%s\"><td>"
234 "<input type=\"radio\" name=\"ib_notes\" value=\"yes\" %s> %s "
235 "<input type=\"radio\" name=\"ib_notes\" value=\"no\" %s> %s <br />"
237 "<img src=\"static/storenotes_48x.gif\" alt=\" \">"
242 (bar
? "even" : "odd"),
243 (val
? "CHECKED" : ""),_("Yes"),
244 (!val
? "CHECKED" : ""),_("No"),
246 _("Your personal notes")
250 val
= IconbarIsEnabled("ib_calendar", 1);
251 wprintf("<tr class=\"%s\"><td>"
252 "<input type=\"radio\" name=\"ib_calendar\" value=\"yes\" %s> %s "
253 "<input type=\"radio\" name=\"ib_calendar\" value=\"no\" %s> %s <br />"
255 "<img src=\"static/calarea_48x.gif\" alt=\" \">"
260 (bar
? "even" : "odd"),
261 (val
? "CHECKED" : ""),_("Yes"),
262 (!val
? "CHECKED" : ""),_("No"),
264 _("A shortcut to your personal calendar")
268 val
= IconbarIsEnabled("ib_tasks", 1);
269 wprintf("<tr class=\"%s\"><td>"
270 "<input type=\"radio\" name=\"ib_tasks\" value=\"yes\" %s> %s "
271 "<input type=\"radio\" name=\"ib_tasks\" value=\"no\" %s> %s <br />"
273 "<img src=\"static/taskmanag_48x.gif\" alt=\" \">"
278 (bar
? "even" : "odd"),
279 (val
? "CHECKED" : ""),_("Yes"),
280 (!val
? "CHECKED" : ""),_("No"),
282 _("A shortcut to your personal task list")
286 val
= IconbarIsEnabled("ib_rooms", 1);
287 wprintf("<tr class=\"%s\"><td>"
288 "<input type=\"radio\" name=\"ib_rooms\" value=\"yes\" %s> %s "
289 "<input type=\"radio\" name=\"ib_rooms\" value=\"no\" %s> %s <br />"
291 "<img src=\"static/chatrooms_48x.gif\" alt=\" \">"
296 (bar
? "even" : "odd"),
297 (val
? "CHECKED" : ""),_("Yes"),
298 (!val
? "CHECKED" : ""),_("No"),
300 _("Clicking this icon displays a list of all accessible "
301 "rooms (or folders) available.")
305 val
= IconbarIsEnabled("ib_users", 1);
306 wprintf("<tr class=\"%s\"><td>"
307 "<input type=\"radio\" name=\"ib_users\" value=\"yes\" %s> %s "
308 "<input type=\"radio\" name=\"ib_users\" value=\"no\" %s> %s <br />"
309 "<input type=\"radio\" name=\"ib_users\" value=\"yeslist\" %s> %s"
311 "<img src=\"static/usermanag_48x.gif\" alt=\" \">"
316 (bar
? "even" : "odd"),
317 (val
? "CHECKED" : ""),_("Yes"),
318 (!val
? "CHECKED" : ""),_("No"),
319 ((val
> 1) ? "CHECKED" : ""),_("Yes with users list"),
321 _("Clicking this icon displays a list of all users "
322 "currently logged in.")
326 val
= IconbarIsEnabled("ib_chat", 1);
327 wprintf("<tr class=\"%s\"><td>"
328 "<input type=\"radio\" name=\"ib_chat\" value=\"yes\" %s> %s "
329 "<input type=\"radio\" name=\"ib_chat\" value=\"no\" %s> %s <br />"
331 "<img src=\"static/citadelchat_48x.gif\" alt=\" \">"
336 (bar
? "even" : "odd"),
337 (val
? "CHECKED" : ""),_("Yes"),
338 (!val
? "CHECKED" : ""),_("No"),
340 _("Clicking this icon enters real-time chat mode "
341 "with other users in the same room.")
346 val
= IconbarIsEnabled("ib_advanced", 1);
347 wprintf("<tr class=\"%s\"><td>"
348 "<input type=\"radio\" name=\"ib_advanced\" value=\"yes\" %s> %s "
349 "<input type=\"radio\" name=\"ib_advanced\" value=\"no\" %s> %s <br />"
351 "<img src=\"static/advanpage2_48x.gif\" alt=\" \">"
356 (bar
? "even" : "odd"),
357 (val
? "CHECKED" : ""),_("Yes"),
358 (!val
? "CHECKED" : ""),_("No"),
359 _("Advanced options"),
360 _("Access to the complete menu of Citadel functions.")
365 val
= IconbarIsEnabled("ib_citadel", 1);
366 wprintf("<tr class=\"%s\"><td>"
367 "<input type=\"radio\" name=\"ib_citadel\" value=\"yes\" %s> %s "
368 "<input type=\"radio\" name=\"ib_citadel\" value=\"no\" %s> %s <br />"
370 "<img border=\"0\" width=\"48\" height=\"48\" "
371 "src=\"static/citadel-logo.gif\" alt=\" \">"
376 (bar
? "even" : "odd"),
377 (val
? "CHECKED" : ""),_("Yes"),
378 (!val
? "CHECKED" : ""),_("No"),
380 _("Displays the 'Powered by Citadel' icon")
383 wprintf("</table><br />\n"
385 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
387 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
393 wprintf("</form></div>\n");
398 * \brief commit the changes of an edited iconbar ????
400 void commit_iconbar(void) {
421 if (!havebstr("ok_button")) {
426 iconbar
= NewStrBuf();
428 StrBufPrintf(iconbar
, "ib_displayas=%d", ibstr("ib_displayas"));
429 for (i
=0; i
<(sizeof(boxen
)/sizeof(char *)); ++i
) {
431 if (!strcasecmp(BSTR(boxen
[i
]), "yes")) {
434 else if (!strcasecmp(BSTR(boxen
[i
]), "yeslist")) {
440 StrBufPrintf(buf
, ",%s=%s", boxen
[i
], Val
);
441 StrBufAppendBuf(iconbar
, buf
, 0);
445 set_preference("iconbar", iconbar
, 1);
447 output_headers(1, 1, 2, 0, 0, 0);
449 wprintf("<div id=\"banner\">\n");
451 wprintf(_("Customize the icon bar"));
452 wprintf("</h1></div>\n");
454 wprintf("<div id=\"content\" class=\"service\">\n");
456 "<center><table border=1 bgcolor=\"#ffffff\"><tr><td>"
457 "<img src=\"static/advanpage2_48x.gif\">"
459 wprintf(_("Your icon bar has been updated. Please select any of its "
460 "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>"));
461 wprintf("</td></tr></table>\n");
463 #ifdef DBG_ICONBAR_HASH
464 dbg_PrintHash(WC
->IconBarSetttings
, PrintInt
, NULL
);
469 void tmplput_iconbar(StrBuf
*Target
, WCTemplputParams
*TP
)
473 if ((WCC
!= NULL
) && (WCC
->logged_in
)) {
474 DoTemplate(HKEY("iconbar"), NULL
, &NoCtx
);
482 WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet
, 0);
483 WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar
, 0);
484 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet
, CTX_NONE
);
485 WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar
, 0);
486 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar
, 0);