X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ficonbar.c;h=99350602b47902378fcbcb91a73a42729b677b96;hb=b4ad306de9560ec731db113ed509a1172209c444;hp=717fd5c2fd8039e89b1ec7fbf9311362d8a81517;hpb=f0d98ac2f8171bf599279e486b136264dc3547a1;p=citadel.git diff --git a/webcit/iconbar.c b/webcit/iconbar.c index 717fd5c2f..99350602b 100644 --- a/webcit/iconbar.c +++ b/webcit/iconbar.c @@ -1,518 +1,743 @@ -/* $Id$ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/* + * $Id$ + * + * Displays and customizes the iconbar. + */ + #include "webcit.h" -/* Values for ib_displayas */ -#define IB_PICTEXT 0 -#define IB_PICONLY 1 -#define IB_TEXTONLY 2 +/** Values for ib_displayas */ +#define IB_PICTEXT 0 /**< picture and text */ +#define IB_PICONLY 1 /**< just a picture */ +#define IB_TEXTONLY 2 /**< just text */ -void do_iconbar(void) { - char iconbar[SIZ]; - char buf[SIZ]; - char key[SIZ], value[SIZ]; - int i; - /* The initialized values of these variables also happen to +void do_iconbar(void); +void do_iconbar_roomlist(void); + +/** + * \brief draw the icon bar????? + */ +void do_selected_iconbar(void) { + if (WC->current_iconbar == current_iconbar_roomlist) { + do_iconbar_roomlist(); + } + else { + do_iconbar(); + } +} + +void DontDeleteThis(void *Data){}; + +#define IconbarIsEnabled(a, b) IconbarIsENABLED(a, sizeof(a) - 1, b) + +long IconbarIsENABLED(const char *key, size_t keylen, long defval) +{ + void *Data; + if (GetHash(WC->IconBarSetttings, key, keylen, + &Data)) + return (long) Data; + else + return defval; +} + +#ifdef DBG_ICONBAR_HASH +static char nbuf[32]; +inline const char *PrintInt(void *Prefstr) +{ + snprintf(nbuf, sizeof(nbuf), "%ld", (long)Prefstr); + return nbuf; +} +#endif + +void LoadIconSettings(void) +{ + struct wcsession *WCC = WC; + StrBuf *iconbar = NULL; + StrBuf *buf = NewStrBuf();; + StrBuf *key = NewStrBuf(); + long val; + int i, nTokens; + + WCC->current_iconbar = current_iconbar_menu; + if (WCC->IconBarSetttings == NULL) + WCC->IconBarSetttings = NewHash(1, NULL); + /** + * The initialized values of these variables also happen to * specify the default values for users who haven't customized * their iconbars. These should probably be set in a master * configuration somewhere. */ - int ib_displayas = 0; /* pictures and text, pictures, text */ - int ib_logo = 1; /* Site logo */ - int ib_summary = 0; /* Summary page icon */ - int ib_inbox = 0; /* Inbox icon */ - int ib_calendar = 0; /* Calendar icon */ - int ib_contacts = 0; /* Contacts icon */ - int ib_tasks = 0; /* Tasks icon */ - int ib_rooms = 1; /* Rooms icon */ - int ib_users = 1; /* Users icon */ - int ib_chat = 0; /* Chat icon */ - int ib_advanced = 1; /* Advanced Options icon */ - int ib_logoff = 1; /* Logoff button */ - int ib_citadel = 1; /* 'Powered by Citadel' logo */ - /* - */ - get_preference("iconbar", iconbar); - for (i=0; iIconBarSetttings, + ChrPtr(key), StrLength(key), + (void*)val, DontDeleteThis); + } } - output_headers(11); - do_template("beginbox_nt"); +#ifdef DBG_ICONBAR_HASH + dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL); +#endif - wprintf("
\n"); + FreeStrBuf(&key); + FreeStrBuf(&buf); +} - if (ib_logo) if (ib_displayas != IB_TEXTONLY) wprintf( - "\" \"" - "
\n" - ); - if (ib_summary) { - wprintf("" - "" +/** + * \brief draw the icon bar??? + */ +void do_iconbar(void) { + int ib_displayas = IB_PICTEXT; /**< pictures and text, pictures, text */ + + LoadIconSettings(); + ib_displayas = IconbarIsEnabled("ib_displayas", IB_PICTEXT); + +/** Site logo */ + if (IconbarIsEnabled("ib_logo", 0)) { + if (ib_displayas != IB_TEXTONLY) { + wprintf("
\" \" " + "
\n" + ); + } + wprintf("\n"); + } + +/** 'Powered by Citadel' logo */ + if (IconbarIsEnabled("ib_citadel", 1) && (ib_displayas != IB_TEXTONLY)) wprintf( + "
\n", + _("Find out more about Citadel"), + _("CITADEL") + ); + + wprintf("
\n"); - do_template("endbox"); - wDumpContent(2); + wprintf("\n"); + + if (IconbarIsEnabled("ib_users", 0)) { + wprintf( + " \n" + ); + } } +/** + * \brief roomtree view of the iconbar + * If the user has toggled the icon bar over to a room list, here's where + * we generate its innerHTML... + */ +void do_iconbar_roomlist(void) { + + WC->current_iconbar = current_iconbar_roomlist; -void display_customize_iconbar(void) { - char iconbar[SIZ]; - char buf[SIZ]; - char key[SIZ], value[SIZ]; - int i; - - /* The initialized values of these variables also happen to + /** + * The initialized values of these variables also happen to * specify the default values for users who haven't customized * their iconbars. These should probably be set in a master * configuration somewhere. */ - int ib_displayas = IB_PICTEXT; /* pictures and text, pictures, text */ - int ib_logo = 1; /* Site logo */ - int ib_summary = 0; /* Summary page icon */ - int ib_inbox = 0; /* Inbox icon */ - int ib_calendar = 0; /* Calendar icon */ - int ib_contacts = 0; /* Contacts icon */ - int ib_tasks = 0; /* Tasks icon */ - int ib_rooms = 1; /* Rooms icon */ - int ib_users = 1; /* Users icon */ - int ib_chat = 0; /* Chat icon */ - int ib_advanced = 1; /* Advanced Options icon */ - int ib_logoff = 1; /* Logoff button */ - int ib_citadel = 1; /* 'Powered by Citadel' logo */ - /* - */ + int ib_displayas; + + LoadIconSettings(); - get_preference("iconbar", iconbar); - for (i=0; i \" \" " + "\n" + ); + } + } + +/** 'Powered by Citadel' logo */ + if (IconbarIsEnabled("ib_citadel", 1) && (ib_displayas != IB_TEXTONLY)) wprintf( + "
" + " " + "\"%s\" " + "
\n", + _("Find out more about Citadel"), + _("CITADEL") + ); + + wprintf("\n"); + + /** embed the room list */ + list_all_rooms_by_floor("iconbar"); + + wprintf("\n"); +} + + +/** + * \brief display a customized version of the iconbar + */ +void display_customize_iconbar(void) { + int i; + int bar = 0; + long val; + + int ib_displayas; + + LoadIconSettings(); + + output_headers(1, 1, 2, 0, 0, 0); + wprintf("
"); + wprintf("

"); + wprintf(_("Customize the icon bar")); + wprintf("

\n"); + + wprintf("
\n"); - output_headers(3); - svprintf("BOXTITLE", WCS_STRING, "Customize the icon bar"); - do_template("beginbox"); + wprintf("
"); - wprintf("
\n"); + wprintf("\n"); + wprintf("\n", WC->nonce); - wprintf("
" - "Display icons as: "); + wprintf("\n"); + wprintf("\n"); + + bar = 1 - bar; + val = IconbarIsEnabled("ib_logo", 0); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Site logo"), + _("An icon describing this site") ); - wprintf("
"); + wprintf(_("Display icons as:")); + wprintf(""); + ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT); for (i=0; i<=2; ++i) { - wprintf(""); - if (i == IB_PICTEXT) wprintf("pictures and text"); - if (i == IB_PICONLY) wprintf("pictures only"); - if (i == IB_TEXTONLY) wprintf("text only"); + if (i == IB_PICTEXT) wprintf(_("pictures and text")); + if (i == IB_PICONLY) wprintf(_("pictures only")); + if (i == IB_TEXTONLY) wprintf(_("text only")); wprintf("\n"); } - wprintf("

\n"); - - wprintf("Select the icons you would like to see displayed " - "in the "icon bar" menu on the left side of the " - "screen.
\n" + wprintf("
\n"); + + wprintf(_("Select the icons you would like to see displayed " + "in the 'icon bar' menu on the left side of the " + "screen.")); + wprintf("
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
\n"); - - wprintf("\n", - (ib_logo ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_summary", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Summary"), + _("Your summary page") ); - wprintf("\n", - (ib_summary ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_inbox", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Mail (inbox)"), + _("A shortcut to your email Inbox") ); - wprintf("\n", - (ib_inbox ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_contacts", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Contacts"), + _("Your personal address book") ); - wprintf("\n", - (ib_contacts ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_notes", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Notes"), + _("Your personal notes") ); -#ifdef WEBCIT_WITH_CALENDAR_SERVICE - wprintf("\n", - (ib_calendar ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_calendar", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Calendar"), + _("A shortcut to your personal calendar") ); - wprintf("\n", - (ib_tasks ? "CHECKED" : "") - ); -#endif /* WEBCIT_WITH_CALENDAR_SERVICE */ - - wprintf("\n", - (ib_rooms ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_tasks", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Tasks"), + _("A shortcut to your personal task list") ); - wprintf("\n", - (ib_users ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_rooms", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Rooms"), + _("Clicking this icon displays a list of all accessible " + "rooms (or folders) available.") ); - wprintf("\n", - (ib_chat ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_users", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + ((val > 1) ? "CHECKED" : ""),_("Yes with users list"), + _("Who is online?"), + _("Clicking this icon displays a list of all users " + "currently logged in.") ); - wprintf("\n", - (ib_advanced ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_chat", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Chat"), + _("Clicking this icon enters real-time chat mode " + "with other users in the same room.") + ); - wprintf("\n", - (ib_logoff ? "CHECKED" : "") + bar = 1 - bar; + val = IconbarIsEnabled("ib_advanced", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Advanced options"), + _("Access to the complete menu of Citadel functions.") + ); - wprintf("\n", - (ib_citadel ? "CHECKED" : "") + + bar = 1 - bar; + val = IconbarIsEnabled("ib_citadel", 1); + wprintf("\n", + (bar ? "even" : "odd"), + (val ? "CHECKED" : ""),_("Yes"), + (!val ? "CHECKED" : ""),_("No"), + _("Citadel logo"), + _("Displays the 'Powered by Citadel' icon") ); - wprintf("
" - "" - "" - "\" \"" - "" - "Site logo
" - "A graphic describing this site" - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Summary
" - "Your summary page" - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Mail (inbox)
" - "A shortcut to your e-mail Inbox." - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Contacts
" - "Your personal address book." - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Calendar
" - "A shortcut to your personal calendar." - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Tasks
" - "A shortcut to your personal task list." - "
" - "" - "" - "\" \"" - "" - "Rooms
" - "Clicking this icon displays a list of all accesible " - "rooms (or folders) available." - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Users
" - "Clicking this icon displays a list of all users " - "currently logged in." - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Chat
" - "Clicking this icon enters real-time chat mode " - "with other users in the same room." - "
" + " %s    " + " %s
" + " %s" + "
" + "\" \"" + "" + "%s" + "
%s" + "
" - "" - "" - "\" \"" - "" - "Advanced options
" - "Access to the complete menu of Citadel functions." - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Log off
" - "Exit from the Citadel system. If you remove this icon " - "then you will have no way out!" - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "
" - "" - "" - "\" \"" - "" - "Citadel logo
" - "Displays the "Powered by Citadel" graphic" - "
" + " %s    " + " %s
" + "
" + "\" \"" + "" + "%s
" + "%s" + "

\n" - "
" - "" + wprintf("
\n" + "
" + "" " " - "" - "
\n" + "" + "
\n", + _("Save changes"), + _("Cancel") ); - do_template("endbox"); + wprintf("
\n"); wDumpContent(2); } - +/** + * \brief commit the changes of an edited iconbar ???? + */ void commit_iconbar(void) { - char iconbar[SIZ]; + StrBuf *iconbar; + StrBuf *buf; int i; char *boxen[] = { @@ -521,6 +746,7 @@ void commit_iconbar(void) { "ib_inbox", "ib_calendar", "ib_contacts", + "ib_notes", "ib_tasks", "ib_rooms", "ib_users", @@ -530,34 +756,77 @@ void commit_iconbar(void) { "ib_citadel" }; - if (strcmp(bstr("sc"), "OK")) { + if (!havebstr("ok_button")) { display_main_menu(); return; } - sprintf(iconbar, "ib_displayas=%d", atoi(bstr("ib_displayas"))); - + iconbar = NewStrBuf(); + buf = NewStrBuf(); + StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas")); for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) { - sprintf(&iconbar[strlen(iconbar)], ",%s=", boxen[i]); - if (!strcasecmp(bstr(boxen[i]), "yes")) { - sprintf(&iconbar[strlen(iconbar)], "1"); + char *Val; + if (!strcasecmp(BSTR(boxen[i]), "yes")) { + Val = "1"; + } + else if (!strcasecmp(BSTR(boxen[i]), "yeslist")) { + Val = "2"; } else { - sprintf(&iconbar[strlen(iconbar)], "0"); + Val = "0"; } + StrBufPrintf(buf, ",%s=%s", boxen[i], Val); + StrBufAppendBuf(iconbar, buf, 0); + } + FreeStrBuf(&buf); + set_preference("iconbar", iconbar, 1); - set_preference("iconbar", iconbar); + output_headers(1, 1, 2, 0, 0, 0); + wprintf("
\n"); + wprintf("

"); + wprintf(_("Customize the icon bar")); + wprintf("

\n"); - output_headers(3); - do_template("beginbox_nt"); + wprintf("
\n"); wprintf( - "" - " " - "Your icon bar has been updated. Please select any of its " - "choices to continue.\n" - ); - do_template("endbox"); + "
" + "" + " "); + wprintf(_("Your icon bar has been updated. Please select any of its " + "choices to continue.")); + wprintf("
\n"); wDumpContent(2); +#ifdef DBG_ICONBAR_HASH + dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL); +#endif } + + +void tmplput_iconbar(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + struct wcsession *WCC = WC; + + if ((WCC != NULL) && (WCC->logged_in)) { + wprintf("
"); + do_selected_iconbar(); + /** check for instant messages (these display in a new window) */ + page_popup(); + wprintf("
"); + } +} + +void +InitModule_ICONBAR +(void) +{ + WebcitAddUrlHandler(HKEY("iconbar_ajax_menu"), do_iconbar, AJAX); + WebcitAddUrlHandler(HKEY("iconbar_ajax_rooms"), do_iconbar_roomlist, AJAX); + WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar, 0); + WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0); + RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, 0); + +} + + +/*@}*/