2 * Displays and customizes the iconbar.
4 * Copyright (c) 1996-2011 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 as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* Values for ib_displayas ... don't change these or you will break the templates */
24 #define IB_PICTEXT 0 /* picture and text */
25 #define IB_PICONLY 1 /* just a picture */
26 #define IB_TEXTONLY 2 /* just text */
28 void DontDeleteThis(void *Data){}
30 #define IconbarIsEnabled(a, b) IconbarIsENABLED(a, sizeof(a) - 1, b)
33 HashList *IB_Seeting_Order = NULL;
34 typedef struct _dflt_IB_Setting {
35 int DefVal; /* default value for non-set users */
36 long n; /* counter for internal purposes */
37 const char *Key; /* Stringvalue */
38 long len; /* Length... */
42 dflt_IB_Setting IconbarDefaults[] = {
43 {0, 0, HKEY("unused")},
44 {0, 1, HKEY("ib_displayas")},
45 {0, 2, HKEY("ib_logo")},
46 {1, 3, HKEY("ib_summary")},
47 {1, 4, HKEY("ib_inbox")},
48 {1, 5, HKEY("ib_calendar")},
49 {1, 6, HKEY("ib_contacts")},
50 {1, 7, HKEY("ib_notes")},
51 {1, 8, HKEY("ib_tasks")},
52 {1, 9, HKEY("ib_rooms")},
53 {1, 10, HKEY("ib_users")},
54 {1, 11, HKEY("ib_chat")},
55 {1, 12, HKEY("ib_advanced")},
56 {1, 13, HKEY("ib_logoff")},
57 {1, 14, HKEY("ib_citadel")},
61 HashList *IBDfl = NULL;
64 long IconbarIsENABLED(long val, const char *key, size_t keylen)
70 (WCC->IBSettingsVec != NULL) &&
73 return WCC->IBSettingsVec[val];
75 if (GetHash(IBDfl, key, keylen, &vIBDfl)) {
76 dflt_IB_Setting *Set = (dflt_IB_Setting*)vIBDfl;
83 #ifdef DBG_ICONBAR_HASH
85 inline const char *PrintInt(void *Prefstr)
87 snprintf(nbuf, sizeof(nbuf), "%ld", (long)Prefstr);
93 hprintf("Cache-Control: private\r\n");
97 int ConditionalIsActiveStylesheet(StrBuf *Target, WCTemplputParams *TP) {
102 lookAt = GetTemplateTokenNumber(Target, TP, 3, IB_PICTEXT);
103 testFor = GetTemplateTokenNumber(Target, TP, 2, IB_PICTEXT);
107 ib_displayas = IconbarIsENABLED(lookAt, TKEY(3));
109 printf ("%ld == %ld ? %s : %s\n",
112 IconbarDefaults[lookAt ].Key,
113 ChrPtr(TP->Tokens->FlatToken));
116 return (testFor == ib_displayas);
119 void LoadIconSettings(StrBuf *iconbar, long lvalue)
122 dflt_IB_Setting *Set;
123 const char *pCh = NULL;
132 if (WCC->IBSettingsVec == NULL)
134 WCC->IBSettingsVec = (long*) malloc (nIBV * sizeof(long));
137 * The initialized values of these variables also happen to
138 * specify the default values for users who haven't customized
139 * their iconbars. These should probably be set in a master
140 * configuration somewhere.
143 while (StrBufExtract_NextToken(buf, iconbar, &pCh, ',') >= 0)
145 StrBufExtract_token(key, buf, 0, '=');
146 val = StrBufExtract_long(buf, 1, '=');
148 if (!GetHash(IBDfl, SKEY(key), &vIBDfl))
150 Set = (dflt_IB_Setting*)vIBDfl;
152 WCC->IBSettingsVec[Set->n] = val;
153 /* printf("%ld %s %s -> %ld \n", Set->n, Set->Key, IconbarDefaults[Set->n].Key, val);*/
155 #ifdef DBG_ICONBAR_HASH
156 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
165 * save changes to iconbar settings
167 void commit_iconbar(void) {
168 const StrBuf *MimeType;
174 if (!havebstr("ok_button")) {
179 iconbar = NewStrBuf();
181 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
182 for (i=0; i<(sizeof(IconbarDefaults)/sizeof(dflt_IB_Setting )); ++i) {
184 if (!strcasecmp(Bstr(IconbarDefaults[i].Key,
185 IconbarDefaults[i].len),
190 else if (!strcasecmp(Bstr(IconbarDefaults[i].Key,
191 IconbarDefaults[i].len),
199 StrBufPrintf(buf, ",%s=%s", IconbarDefaults[i].Key, Val);
200 StrBufAppendBuf(iconbar, buf, 0);
204 set_preference("iconbar", iconbar, 1);
208 MimeType = DoTemplate(HKEY("iconbar_save"), NULL, &NoCtx);
209 http_transmit_thing(ChrPtr(MimeType), 0);
210 #ifdef DBG_ICONBAR_HASH
211 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
217 * Display the icon bar as long as we have an active session,
218 * and either the user is logged in or the server allows guest mode.
220 void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
225 && ( (WCC->logged_in)
226 || (WCC->serv_info->serv_supports_guest)
229 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
235 ServerShutdownModule_ICONBAR
244 ServerStartModule_ICONBAR
248 IBDfl = NewHash(1, NULL);
250 while (IconbarDefaults[i].len != 0)
253 IconbarDefaults[i].Key,
254 IconbarDefaults[i].len,
256 reference_free_handler);
262 int ConditionalWholistExpanded(StrBuf *Target, WCTemplputParams *TP)
265 if (WC) r = WC->ib_wholist_expanded;
266 syslog(LOG_DEBUG, "ConditionalWholistExpanded() returns %d", r);
271 int ConditionalRoomlistExpanded(StrBuf *Target, WCTemplputParams *TP)
273 if (WC) return(WC->ib_roomlist_expanded);
280 * Toggle the roomlist expanded state in session memory
282 void toggle_roomlist_expanded_state(void) {
286 wc_printf("no session");
290 WCC->ib_roomlist_expanded = IBSTR("wstate");
291 wc_printf("%d", WCC->ib_roomlist_expanded);
292 syslog(LOG_DEBUG, "ib_roomlist_expanded set to %d", WCC->ib_roomlist_expanded);
297 * Toggle the wholist expanded state in session memory
299 void toggle_wholist_expanded_state(void) {
303 wc_printf("no session");
307 WCC->ib_wholist_expanded = IBSTR("wstate");
308 wc_printf("%d", WCC->ib_wholist_expanded);
309 syslog(LOG_DEBUG, "ib_wholist_expanded set to %d", WCC->ib_wholist_expanded);
319 /*WebcitAddUrlHandler(HKEY("user_iconbar"), "", 0, doUserIconStylesheet, 0); */
320 WebcitAddUrlHandler(HKEY("commit_iconbar"), "", 0, commit_iconbar, 0);
321 WebcitAddUrlHandler(HKEY("toggle_wholist_expanded_state"), "", 0, toggle_wholist_expanded_state, AJAX);
322 WebcitAddUrlHandler(HKEY("toggle_roomlist_expanded_state"), "", 0, toggle_roomlist_expanded_state, AJAX);
323 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
324 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, NULL, CTX_NONE);
325 RegisterConditional(HKEY("COND:ICONBAR:WHOLISTEXPANDED"), 0, ConditionalWholistExpanded, CTX_NONE);
326 RegisterConditional(HKEY("COND:ICONBAR:ROOMLISTEXPANDED"), 0, ConditionalRoomlistExpanded, CTX_NONE);
328 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
330 while (IconbarDefaults[l].len != 0)
332 RegisterTokenParamDefine(IconbarDefaults[l].Key,
333 IconbarDefaults[l].len, l);
342 SessionDestroyModule_ICONBAR
345 if (sess->IBSettingsVec != NULL)
346 free(sess->IBSettingsVec);