3 * Displays and customizes the iconbar.
5 * Copyright (c) 1996-2012 by the citadel.org team
7 * This program is open source software. You can redistribute it and/or
8 * modify it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 /* Values for ib_displayas ... don't change these or you will break the templates */
19 #define IB_PICTEXT 0 /* picture and text */
20 #define IB_PICONLY 1 /* just a picture */
21 #define IB_TEXTONLY 2 /* just text */
23 void DontDeleteThis(void *Data) {
26 #define IconbarIsEnabled(a, b) IconbarIsENABLED(a, sizeof(a) - 1, b)
29 HashList *IB_Seeting_Order = NULL;
30 typedef struct _dflt_IB_Setting {
31 int DefVal; /* default value for non-set users */
32 long n; /* counter for internal purposes */
33 const char *Key; /* Stringvalue */
34 long len; /* Length... */
38 dflt_IB_Setting IconbarDefaults[] = {
39 { 0, 0, HKEY("unused") },
40 { 0, 1, HKEY("ib_displayas") },
41 { 0, 2, HKEY("ib_logo") },
42 { 1, 3, HKEY("ib_summary") },
43 { 1, 4, HKEY("ib_inbox") },
44 { 1, 5, HKEY("ib_calendar") },
45 { 1, 6, HKEY("ib_contacts") },
46 { 1, 7, HKEY("ib_notes") },
47 { 1, 8, HKEY("ib_tasks") },
48 { 1, 9, HKEY("ib_rooms") },
49 { 1, 10, HKEY("ib_users") },
50 { 1, 11, HKEY("ib_chat") },
51 { 1, 12, HKEY("ib_advanced") },
52 { 1, 13, HKEY("ib_logoff") },
53 { 1, 14, HKEY("ib_citadel") },
57 HashList *IBDfl = NULL;
60 long IconbarIsENABLED(long val, const char *key, size_t keylen) {
64 if ((WCC != NULL) && (WCC->IBSettingsVec != NULL) && (val < nIBV)) {
65 return WCC->IBSettingsVec[val];
67 if (GetHash(IBDfl, key, keylen, &vIBDfl)) {
68 dflt_IB_Setting *Set = (dflt_IB_Setting *) vIBDfl;
75 #ifdef DBG_ICONBAR_HASH
77 inline const char *PrintInt(void *Prefstr) {
78 snprintf(nbuf, sizeof(nbuf), "%ld", (long) Prefstr);
84 hprintf("Cache-Control: private\r\n");
88 int ConditionalIsActiveStylesheet(StrBuf * Target, WCTemplputParams * TP) {
93 lookAt = GetTemplateTokenNumber(Target, TP, 3, IB_PICTEXT);
94 testFor = GetTemplateTokenNumber(Target, TP, 2, IB_PICTEXT);
98 ib_displayas = IconbarIsENABLED(lookAt, TKEY(3));
101 printf ("%ld == %ld ? %s : %s\n",
104 IconbarDefaults[lookAt ].Key,
105 ChrPtr(TP->Tokens->FlatToken));
108 return (testFor == ib_displayas);
111 void LoadIconSettings(StrBuf * iconbar, long lvalue) {
113 dflt_IB_Setting *Set;
114 const char *pCh = NULL;
123 if (WCC->IBSettingsVec == NULL) {
124 WCC->IBSettingsVec = (long *) malloc(nIBV * sizeof(long));
127 * The initialized values of these variables also happen to
128 * specify the default values for users who haven't customized
129 * their iconbars. These should probably be set in a master
130 * configuration somewhere.
133 while (StrBufExtract_NextToken(buf, iconbar, &pCh, ',') >= 0) {
134 StrBufExtract_token(key, buf, 0, '=');
135 val = StrBufExtract_long(buf, 1, '=');
137 if (!GetHash(IBDfl, SKEY(key), &vIBDfl))
139 Set = (dflt_IB_Setting *) vIBDfl;
141 WCC->IBSettingsVec[Set->n] = val;
143 /* printf("%ld %s %s -> %ld \n", Set->n, Set->Key, IconbarDefaults[Set->n].Key, val);*/
145 #ifdef DBG_ICONBAR_HASH
146 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
155 * save changes to iconbar settings
157 void commit_iconbar(void) {
158 const StrBuf *MimeType;
164 if (!havebstr("ok_button")) {
169 iconbar = NewStrBuf();
171 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
172 for (i = 0; i < (sizeof(IconbarDefaults) / sizeof(dflt_IB_Setting)); ++i) {
174 if (!strcasecmp(Bstr(IconbarDefaults[i].Key, IconbarDefaults[i].len), "yes")) {
177 else if (!strcasecmp(Bstr(IconbarDefaults[i].Key, IconbarDefaults[i].len), "yeslist")) {
183 StrBufPrintf(buf, ",%s=%s", IconbarDefaults[i].Key, Val);
184 StrBufAppendBuf(iconbar, buf, 0);
188 set_preference("iconbar", iconbar, 1);
192 MimeType = DoTemplate(HKEY("iconbar_save"), NULL, &NoCtx);
193 http_transmit_thing(ChrPtr(MimeType), 0);
194 #ifdef DBG_ICONBAR_HASH
195 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
201 * Display the icon bar as long as we have an active session,
202 * and either the user is logged in or the server allows guest mode.
204 void tmplput_iconbar(StrBuf * Target, WCTemplputParams * TP) {
207 if ((WCC != NULL) && ((WCC->logged_in) || ((WCC->serv_info != NULL) && (WCC->serv_info->serv_supports_guest))
209 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
214 void ServerShutdownModule_ICONBAR(void) {
220 void ServerStartModule_ICONBAR(void) {
222 IBDfl = NewHash(1, NULL);
224 while (IconbarDefaults[i].len != 0) {
225 Put(IBDfl, IconbarDefaults[i].Key, IconbarDefaults[i].len, &IconbarDefaults[i], reference_free_handler);
231 int ConditionalWholistExpanded(StrBuf * Target, WCTemplputParams * TP) {
234 r = WC->ib_wholist_expanded;
235 syslog(LOG_DEBUG, "ConditionalWholistExpanded() returns %d", r);
240 int ConditionalRoomlistExpanded(StrBuf * Target, WCTemplputParams * TP) {
242 return (WC->ib_roomlist_expanded);
249 * Toggle the roomlist expanded state in session memory
251 void toggle_roomlist_expanded_state(void) {
255 wc_printf("no session");
259 WCC->ib_roomlist_expanded = IBSTR("wstate");
260 wc_printf("%d", WCC->ib_roomlist_expanded);
261 syslog(LOG_DEBUG, "ib_roomlist_expanded set to %d", WCC->ib_roomlist_expanded);
266 * Toggle the wholist expanded state in session memory
268 void toggle_wholist_expanded_state(void) {
272 wc_printf("no session");
276 WCC->ib_wholist_expanded = IBSTR("wstate");
277 wc_printf("%d", WCC->ib_wholist_expanded);
278 syslog(LOG_DEBUG, "ib_wholist_expanded set to %d", WCC->ib_wholist_expanded);
282 void InitModule_ICONBAR(void) {
285 /*WebcitAddUrlHandler(HKEY("user_iconbar"), "", 0, doUserIconStylesheet, 0); */
286 WebcitAddUrlHandler(HKEY("commit_iconbar"), "", 0, commit_iconbar, 0);
287 WebcitAddUrlHandler(HKEY("toggle_wholist_expanded_state"), "", 0, toggle_wholist_expanded_state, AJAX);
288 WebcitAddUrlHandler(HKEY("toggle_roomlist_expanded_state"), "", 0, toggle_roomlist_expanded_state, AJAX);
289 RegisterConditional("COND:ICONBAR:ACTIVE", 3, ConditionalIsActiveStylesheet, CTX_NONE);
290 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, NULL, CTX_NONE);
291 RegisterConditional("COND:ICONBAR:WHOLISTEXPANDED", 0, ConditionalWholistExpanded, CTX_NONE);
292 RegisterConditional("COND:ICONBAR:ROOMLISTEXPANDED", 0, ConditionalRoomlistExpanded, CTX_NONE);
294 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
296 while (IconbarDefaults[l].len != 0) {
297 RegisterTokenParamDefine(IconbarDefaults[l].Key, IconbarDefaults[l].len, l);
305 void SessionDestroyModule_ICONBAR(wcsession * sess) {
306 if (sess->IBSettingsVec != NULL)
307 free(sess->IBSettingsVec);