2 * Displays and customizes the iconbar.
4 * Copyright (c) 1996-2012 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
17 /* Values for ib_displayas ... don't change these or you will break the templates */
18 #define IB_PICTEXT 0 /* picture and text */
19 #define IB_PICONLY 1 /* just a picture */
20 #define IB_TEXTONLY 2 /* just text */
22 void DontDeleteThis(void *Data){}
24 #define IconbarIsEnabled(a, b) IconbarIsENABLED(a, sizeof(a) - 1, b)
27 HashList *IB_Seeting_Order = NULL;
28 typedef struct _dflt_IB_Setting {
29 int DefVal; /* default value for non-set users */
30 long n; /* counter for internal purposes */
31 const char *Key; /* Stringvalue */
32 long len; /* Length... */
36 dflt_IB_Setting IconbarDefaults[] = {
37 {0, 0, HKEY("unused")},
38 {0, 1, HKEY("ib_displayas")},
39 {0, 2, HKEY("ib_logo")},
40 {1, 3, HKEY("ib_summary")},
41 {1, 4, HKEY("ib_inbox")},
42 {1, 5, HKEY("ib_calendar")},
43 {1, 6, HKEY("ib_contacts")},
44 {1, 7, HKEY("ib_notes")},
45 {1, 8, HKEY("ib_tasks")},
46 {1, 9, HKEY("ib_rooms")},
47 {1, 10, HKEY("ib_users")},
48 {1, 11, HKEY("ib_chat")},
49 {1, 12, HKEY("ib_advanced")},
50 {1, 13, HKEY("ib_logoff")},
51 {1, 14, HKEY("ib_citadel")},
55 HashList *IBDfl = NULL;
58 long IconbarIsENABLED(long val, const char *key, size_t keylen)
64 (WCC->IBSettingsVec != NULL) &&
67 return WCC->IBSettingsVec[val];
69 if (GetHash(IBDfl, key, keylen, &vIBDfl)) {
70 dflt_IB_Setting *Set = (dflt_IB_Setting*)vIBDfl;
77 #ifdef DBG_ICONBAR_HASH
79 inline const char *PrintInt(void *Prefstr)
81 snprintf(nbuf, sizeof(nbuf), "%ld", (long)Prefstr);
87 hprintf("Cache-Control: private\r\n");
91 int ConditionalIsActiveStylesheet(StrBuf *Target, WCTemplputParams *TP) {
96 lookAt = GetTemplateTokenNumber(Target, TP, 3, IB_PICTEXT);
97 testFor = GetTemplateTokenNumber(Target, TP, 2, IB_PICTEXT);
101 ib_displayas = IconbarIsENABLED(lookAt, TKEY(3));
103 printf ("%ld == %ld ? %s : %s\n",
106 IconbarDefaults[lookAt ].Key,
107 ChrPtr(TP->Tokens->FlatToken));
110 return (testFor == ib_displayas);
113 void LoadIconSettings(StrBuf *iconbar, long lvalue)
116 dflt_IB_Setting *Set;
117 const char *pCh = NULL;
126 if (WCC->IBSettingsVec == NULL)
128 WCC->IBSettingsVec = (long*) malloc (nIBV * sizeof(long));
131 * The initialized values of these variables also happen to
132 * specify the default values for users who haven't customized
133 * their iconbars. These should probably be set in a master
134 * configuration somewhere.
137 while (StrBufExtract_NextToken(buf, iconbar, &pCh, ',') >= 0)
139 StrBufExtract_token(key, buf, 0, '=');
140 val = StrBufExtract_long(buf, 1, '=');
142 if (!GetHash(IBDfl, SKEY(key), &vIBDfl))
144 Set = (dflt_IB_Setting*)vIBDfl;
146 WCC->IBSettingsVec[Set->n] = val;
147 /* printf("%ld %s %s -> %ld \n", Set->n, Set->Key, IconbarDefaults[Set->n].Key, val);*/
149 #ifdef DBG_ICONBAR_HASH
150 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
159 * save changes to iconbar settings
161 void commit_iconbar(void) {
162 const StrBuf *MimeType;
168 if (!havebstr("ok_button")) {
173 iconbar = NewStrBuf();
175 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
176 for (i=0; i<(sizeof(IconbarDefaults)/sizeof(dflt_IB_Setting )); ++i) {
178 if (!strcasecmp(Bstr(IconbarDefaults[i].Key,
179 IconbarDefaults[i].len),
184 else if (!strcasecmp(Bstr(IconbarDefaults[i].Key,
185 IconbarDefaults[i].len),
193 StrBufPrintf(buf, ",%s=%s", IconbarDefaults[i].Key, Val);
194 StrBufAppendBuf(iconbar, buf, 0);
198 set_preference("iconbar", iconbar, 1);
202 MimeType = DoTemplate(HKEY("iconbar_save"), NULL, &NoCtx);
203 http_transmit_thing(ChrPtr(MimeType), 0);
204 #ifdef DBG_ICONBAR_HASH
205 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
211 * Display the icon bar as long as we have an active session,
212 * and either the user is logged in or the server allows guest mode.
214 void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
218 if ( (WCC != NULL) &&
220 ((WCC->serv_info != NULL) &&
221 (WCC->serv_info->serv_supports_guest))
224 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
230 ServerShutdownModule_ICONBAR
239 ServerStartModule_ICONBAR
243 IBDfl = NewHash(1, NULL);
245 while (IconbarDefaults[i].len != 0)
248 IconbarDefaults[i].Key,
249 IconbarDefaults[i].len,
251 reference_free_handler);
257 int ConditionalWholistExpanded(StrBuf *Target, WCTemplputParams *TP)
260 if (WC) r = WC->ib_wholist_expanded;
261 syslog(LOG_DEBUG, "ConditionalWholistExpanded() returns %d", r);
266 int ConditionalRoomlistExpanded(StrBuf *Target, WCTemplputParams *TP)
268 if (WC) return(WC->ib_roomlist_expanded);
275 * Toggle the roomlist expanded state in session memory
277 void toggle_roomlist_expanded_state(void) {
281 wc_printf("no session");
285 WCC->ib_roomlist_expanded = IBSTR("wstate");
286 wc_printf("%d", WCC->ib_roomlist_expanded);
287 syslog(LOG_DEBUG, "ib_roomlist_expanded set to %d", WCC->ib_roomlist_expanded);
292 * Toggle the wholist expanded state in session memory
294 void toggle_wholist_expanded_state(void) {
298 wc_printf("no session");
302 WCC->ib_wholist_expanded = IBSTR("wstate");
303 wc_printf("%d", WCC->ib_wholist_expanded);
304 syslog(LOG_DEBUG, "ib_wholist_expanded set to %d", WCC->ib_wholist_expanded);
314 /*WebcitAddUrlHandler(HKEY("user_iconbar"), "", 0, doUserIconStylesheet, 0); */
315 WebcitAddUrlHandler(HKEY("commit_iconbar"), "", 0, commit_iconbar, 0);
316 WebcitAddUrlHandler(HKEY("toggle_wholist_expanded_state"), "", 0, toggle_wholist_expanded_state, AJAX);
317 WebcitAddUrlHandler(HKEY("toggle_roomlist_expanded_state"), "", 0, toggle_roomlist_expanded_state, AJAX);
318 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
319 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, NULL, CTX_NONE);
320 RegisterConditional(HKEY("COND:ICONBAR:WHOLISTEXPANDED"), 0, ConditionalWholistExpanded, CTX_NONE);
321 RegisterConditional(HKEY("COND:ICONBAR:ROOMLISTEXPANDED"), 0, ConditionalRoomlistExpanded, CTX_NONE);
323 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
325 while (IconbarDefaults[l].len != 0)
327 RegisterTokenParamDefine(IconbarDefaults[l].Key,
328 IconbarDefaults[l].len, l);
337 SessionDestroyModule_ICONBAR
340 if (sess->IBSettingsVec != NULL)
341 free(sess->IBSettingsVec);