4 * Manage user preferences with a little help from the Citadel server.
13 void load_preferences(void) {
17 serv_printf("GOTO %s", USERCONFIGROOM);
18 serv_getln(buf, sizeof buf);
19 if (buf[0] != '2') return;
21 serv_puts("MSGS ALL|0|1");
22 serv_getln(buf, sizeof buf);
24 serv_puts("subj|__ WebCit Preferences __");
27 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
32 serv_printf("MSG0 %ld", msgnum);
33 serv_getln(buf, sizeof buf);
35 while (serv_getln(buf, sizeof buf),
36 (strcmp(buf, "text") && strcmp(buf, "000"))) {
38 if (!strcmp(buf, "text")) {
39 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
40 if (WC->preferences == NULL) {
41 WC->preferences = malloc(SIZ);
42 strcpy(WC->preferences, "");
45 WC->preferences = realloc(
47 strlen(WC->preferences)
51 strcat(WC->preferences, buf);
52 strcat(WC->preferences, "\n");
58 /* Go back to the room we're supposed to be in */
59 serv_printf("GOTO %s", WC->wc_roomname);
60 serv_getln(buf, sizeof buf);
64 * Goto the user's configuration room, creating it if necessary.
65 * Returns 0 on success or nonzero upon failure.
67 int goto_config_room(void) {
70 serv_printf("GOTO %s", USERCONFIGROOM);
71 serv_getln(buf, sizeof buf);
72 if (buf[0] != '2') { /* try to create the config room if not there */
73 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
74 serv_getln(buf, sizeof buf);
75 serv_printf("GOTO %s", USERCONFIGROOM);
76 serv_getln(buf, sizeof buf);
77 if (buf[0] != '2') return(1);
83 void save_preferences(void) {
87 if (goto_config_room() != 0) return; /* oh well. */
88 serv_puts("MSGS ALL|0|1");
89 serv_getln(buf, sizeof buf);
91 serv_puts("subj|__ WebCit Preferences __");
94 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
99 serv_printf("DELE %ld", msgnum);
100 serv_getln(buf, sizeof buf);
103 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
104 serv_getln(buf, sizeof buf);
106 serv_puts(WC->preferences);
111 /* Go back to the room we're supposed to be in */
112 serv_printf("GOTO %s", WC->wc_roomname);
113 serv_getln(buf, sizeof buf);
116 void get_preference(char *key, char *value, size_t value_len) {
124 num_prefs = num_tokens(WC->preferences, '\n');
125 for (i=0; i<num_prefs; ++i) {
126 extract_token(buf, WC->preferences, i, '\n', sizeof buf);
127 extract_token(thiskey, buf, 0, '|', sizeof thiskey);
128 if (!strcasecmp(thiskey, key)) {
129 extract_token(value, buf, 1, '|', value_len);
134 void set_preference(char *key, char *value, int save_to_server) {
139 char *newprefs = NULL;
141 num_prefs = num_tokens(WC->preferences, '\n');
142 for (i=0; i<num_prefs; ++i) {
143 extract_token(buf, WC->preferences, i, '\n', sizeof buf);
144 if (num_tokens(buf, '|') == 2) {
145 extract_token(thiskey, buf, 0, '|', sizeof thiskey);
146 if (strcasecmp(thiskey, key)) {
147 if (newprefs == NULL) newprefs = strdup("");
148 newprefs = realloc(newprefs,
149 strlen(newprefs) + SIZ );
150 strcat(newprefs, buf);
151 strcat(newprefs, "\n");
157 if (newprefs == NULL) newprefs = strdup("");
158 newprefs = realloc(newprefs, strlen(newprefs) + SIZ);
159 sprintf(&newprefs[strlen(newprefs)], "%s|%s\n", key, value);
161 free(WC->preferences);
162 WC->preferences = newprefs;
164 if (save_to_server) save_preferences();
171 * display form for changing your preferences and settings
173 void display_preferences(void)
175 output_headers(1, 1, 2, 0, 0, 0);
178 wprintf("<div id=\"banner\">\n");
179 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
180 wprintf("<IMG SRC=\"/static/advanpage2_48x.gif\" ALT=\" \" ALIGN=MIDDLE>");
181 wprintf("<SPAN CLASS=\"titlebar\"> ");
182 wprintf(_("Preferences and settings"));
183 wprintf("</SPAN></TD><TD ALIGN=RIGHT>");
185 wprintf("</TD></TR></TABLE>\n");
187 "<div id=\"content\">\n");
189 wprintf("<div id=\"fix_scrollbar_bug\">"
190 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
194 "<form name=\"prefform\" action=\"set_preferences\" "
196 "<table border=0 cellspacing=5 cellpadding=5>\n");
201 get_preference("roomlistview", buf, sizeof buf);
203 wprintf(_("Room list view"));
204 wprintf("</td><td>");
206 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"folders\"");
207 if (!strcasecmp(buf, "folders")) wprintf(" checked");
209 wprintf(_("Tree (folders) view"));
210 wprintf("<br></input>\n");
212 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"rooms\"");
213 if (!strcasecmp(buf, "rooms")) wprintf(" checked");
215 wprintf(_("Table (rooms) view"));
216 wprintf("<br></input>\n");
218 wprintf("</td></tr>\n");
221 * Calendar hour format
223 get_preference("calhourformat", buf, sizeof buf);
224 if (buf[0] == 0) strcpy(buf, "12");
226 wprintf(_("Calendar hour format"));
227 wprintf("</td><td>");
229 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"12\"");
230 if (!strcasecmp(buf, "12")) wprintf(" checked");
232 wprintf(_("12 hour (am/pm)"));
233 wprintf("<br></input>\n");
235 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"24\"");
236 if (!strcasecmp(buf, "24")) wprintf(" checked");
238 wprintf(_("24 hour"));
239 wprintf("<br></input>\n");
241 wprintf("</td></tr>\n");
244 * Calendar hour format
246 get_preference("use_sig", buf, sizeof buf);
247 if (buf[0] == 0) strcpy(buf, "no");
249 wprintf(_("Attach signature to email messages?"));
250 wprintf("</td><td>");
252 wprintf("<input type=\"radio\" name=\"use_sig\" VALUE=\"no\"");
253 if (!strcasecmp(buf, "no")) wprintf(" checked");
255 wprintf(_("No signature"));
256 wprintf("<br></input>\n");
258 wprintf("<input type=\"radio\" name=\"use_sig\" VALUE=\"yes\"");
259 if (!strcasecmp(buf, "yes")) wprintf(" checked");
261 wprintf(_("Use this signature:"));
262 wprintf("<div id=\"signature_box\">"
263 "<br><textarea name=\"signature\" cols=\"40\" rows=\"5\">"
265 get_preference("signature", buf, sizeof buf);
267 wprintf("</textarea>"
271 wprintf("<br></input>\n");
273 wprintf("</td></tr>\n");
278 "<input type=\"submit\" name=\"change_button\" value=\"%s\">"
280 "<INPUT type=\"submit\" name=\"cancel_button\" value=\"%s\">\n",
285 wprintf("</form></center>\n");
290 wprintf("</td></tr></table></div>\n");
295 * Commit new preferences and settings
297 void set_preferences(void)
299 if (strlen(bstr("change_button")) == 0) {
300 safestrncpy(WC->ImportantMessage,
301 _("Cancelled. No settings were changed."),
302 sizeof WC->ImportantMessage);
307 /* Set the last argument to 1 only for the final setting, so
308 * we don't send the prefs file to the server repeatedly
310 set_preference("roomlistview", bstr("roomlistview"), 0);
311 set_preference("calhourformat", bstr("calhourformat"), 0);
312 set_preference("use_sig", bstr("use_sig"), 0);
313 set_preference("signature", bstr("signature"), 1);