Mercurial > pidgin
annotate src/gaimrc.c @ 191:948100a8cb23
[gaim-migrate @ 201]
Wrote a plugin for IcedSoal to put an asterisk in the titlebar of conversations
where you haven't replied to the person yet (e.g. you weren't the last person
to say something).
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 27 Apr 2000 12:14:16 +0000 |
parents | 0ff9f19b9b23 |
children | 83dd297aa363 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
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. | |
15 * | |
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 | |
19 * | |
20 */ | |
21 | |
22 #include <string.h> | |
23 #include <sys/time.h> | |
24 | |
25 #include <sys/types.h> | |
26 #include <sys/stat.h> | |
27 | |
28 #include <unistd.h> | |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
31 #include <gtk/gtk.h> | |
32 #include "gaim.h" | |
33 #include "proxy.h" | |
34 | |
84 | 35 #ifdef USE_APPLET |
82 | 36 #include "gnome_applet_mgr.h" |
37 #endif | |
38 | |
1 | 39 |
40 struct aim_user *current_user = NULL; | |
41 GList *aim_users = NULL; | |
42 int general_options; | |
43 int display_options; | |
44 int sound_options; | |
45 int font_options; | |
46 | |
47 int report_idle, web_browser; | |
48 struct save_pos blist_pos; | |
49 char web_command[2048]; | |
50 char aim_host[512]; | |
51 int aim_port; | |
52 char login_host[512]; | |
53 int login_port; | |
180 | 54 char latest_ver[25]; |
1 | 55 |
56 struct parse { | |
57 char option[256]; | |
58 char value[6][256]; | |
59 }; | |
60 | |
61 static struct parse *parse_line(char *line) | |
62 { | |
63 char *c = line; | |
64 int inopt = 1, inval = 0, curval = -1; | |
65 int optlen = 0, vallen = 0; | |
66 static struct parse p; | |
67 | |
68 | |
69 while(*c) { | |
70 if (*c == '\t') { | |
71 c++; | |
72 continue; | |
73 } | |
74 if (inopt) { | |
75 // if ((*c < 'a' || *c > 'z') && *c != '_') { | |
76 if ((*c < 'a' || *c > 'z') && *c != '_' && (*c < 'A' || *c > 'Z')) { | |
77 inopt = 0; | |
78 p.option[optlen] = 0; | |
79 c++; | |
80 continue; | |
81 } | |
82 | |
83 p.option[optlen] = *c; | |
84 optlen++; | |
85 c++; | |
86 continue; | |
87 } else if (inval) { | |
88 if ( (*c == '}') ) { | |
89 if (*(c-1) == '\\') { | |
90 p.value[curval][vallen - 1] = *c; | |
91 c++; | |
92 continue; | |
93 } else { | |
94 p.value[curval][vallen - 1] = 0; | |
95 inval = 0; | |
96 c++; | |
97 continue; | |
98 } | |
99 } else { | |
100 p.value[curval][vallen] = *c; | |
101 vallen++; | |
102 c++; | |
103 continue; } | |
104 } else if (*c == '{') { | |
105 if (*(c-1) == '\\') { | |
106 p.value[curval][vallen-1] = *c; | |
107 c++; | |
108 continue; | |
109 } | |
110 else | |
111 { | |
112 curval++; | |
113 vallen = 0; | |
114 inval = 1; | |
115 c++; | |
116 c++; | |
117 continue; | |
118 } | |
119 } | |
120 c++; | |
121 } | |
122 return &p; | |
123 } | |
124 | |
125 | |
126 static int gaimrc_parse_tag(FILE *f) | |
127 { | |
128 char buf[2048]; | |
129 char tag[256]; | |
130 buf[0] = '#'; | |
131 | |
132 while (buf[0] == '#' && !feof(f)) | |
133 fgets(buf, sizeof(buf), f); | |
134 | |
135 if (feof(f)) | |
136 return -1; | |
137 | |
138 sscanf(buf, "%s {", tag); | |
139 | |
140 if (!strcmp(tag, "users")) { | |
141 return 0; | |
142 } else if (!strcmp(tag, "options")) { | |
143 return 1; | |
144 } else if (!strcmp(tag, "away")) { | |
145 return 2; | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
146 } else if (!strcmp(tag, "plugins")) { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
147 return 3; |
1 | 148 } |
149 | |
150 return -1; | |
151 } | |
152 | |
153 void filter_break(char *msg) | |
154 { | |
44 | 155 char *c; |
156 int mc; | |
157 int cc; | |
158 | |
159 c = g_malloc(strlen(msg)+1); | |
160 strcpy(c, msg); | |
1 | 161 |
44 | 162 mc = 0; |
163 cc = 0; | |
164 while (c[cc] != '\0') | |
165 { | |
166 if (c[cc] == '\\') { | |
167 cc++; | |
168 msg[mc] = c[cc]; | |
169 } | |
170 else { | |
171 msg[mc] = c[cc]; | |
172 } | |
173 mc++; | |
174 cc++; | |
175 } | |
176 msg[mc] = 0; | |
177 g_free(c); | |
1 | 178 } |
179 | |
44 | 180 |
1 | 181 static void gaimrc_read_away(FILE *f) |
182 { | |
183 struct parse *p; | |
184 char buf[4096]; | |
185 struct away_message *a; | |
186 | |
187 buf[0] = 0; | |
188 | |
189 while (buf[0] != '}') | |
190 { | |
191 if (!fgets(buf, sizeof(buf), f)) | |
192 return; | |
193 | |
194 if (buf[0] == '}') | |
195 return; | |
196 | |
197 p = parse_line(buf); | |
15 | 198 if (!strcmp(p->option, "message")) |
199 { | |
200 a = g_new0(struct away_message, 1); | |
1 | 201 |
15 | 202 g_snprintf(a->name, sizeof(a->name), "%s", p->value[0]); |
203 g_snprintf(a->message, sizeof(a->message), "%s", p->value[1]); | |
204 filter_break(a->message); | |
205 away_messages = g_list_append(away_messages, a); | |
206 } | |
1 | 207 } |
208 } | |
209 | |
210 static void gaimrc_write_away(FILE *f) | |
211 { | |
212 GList *awy = away_messages; | |
213 struct away_message *a; | |
214 | |
215 fprintf(f, "away {\n"); | |
216 | |
217 while (awy) { | |
26 | 218 char *str1, *str2; |
219 | |
1 | 220 a = (struct away_message *)awy->data; |
26 | 221 |
222 str1 = escape_text2(a->name); | |
223 str2 = escape_text2(a->message); | |
224 | |
225 fprintf(f, "\tmessage { %s } { %s }\n", str1, str2); | |
226 | |
227 /* escape_text2 uses malloc(), so we don't want to g_free these */ | |
228 free(str1); | |
229 free(str2); | |
230 | |
1 | 231 awy = awy->next; |
232 } | |
233 | |
234 fprintf(f, "}\n"); | |
235 } | |
236 | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
237 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
238 static void gaimrc_write_plugins(FILE *f) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
239 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
240 GList *pl = plugins; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
241 struct gaim_plugin *p; |
1 | 242 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
243 fprintf(f, "plugins {\n"); |
1 | 244 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
245 while (pl) { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
246 char *path; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
247 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
248 p = (struct gaim_plugin *)pl->data; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
249 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
250 path = escape_text2(p->filename); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
251 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
252 fprintf(f, "\tplugin { %s }\n", path); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
253 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
254 free(path); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
255 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
256 pl = pl->next; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
257 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
258 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
259 fprintf(f, "}\n"); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
260 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
261 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
262 static void gaimrc_read_plugins(FILE *f) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
263 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
264 struct parse *p; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
265 char buf[4096]; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
266 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
267 buf[0] = 0; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
268 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
269 while (buf[0] != '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
270 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
271 if (!fgets(buf, sizeof(buf), f)) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
272 return; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
273 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
274 if (buf[0] == '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
275 return; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
276 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
277 p = parse_line(buf); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
278 if (!strcmp(p->option, "plugin")) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
279 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
280 load_plugin(p->value[0]); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
281 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
282 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
283 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
284 #endif /* GAIM_PLUGINS */ |
1 | 285 |
286 static struct aim_user *gaimrc_read_user(FILE *f) | |
287 { | |
288 struct parse *p; | |
289 struct aim_user *u; | |
290 char buf[4096]; | |
291 | |
292 if (!fgets(buf, sizeof(buf), f)) | |
293 return NULL; | |
294 | |
295 p = parse_line(buf); | |
296 | |
297 if (strcmp(p->option, "ident")) | |
298 return NULL; | |
299 | |
300 u = g_new0(struct aim_user, 1); | |
301 | |
302 strcpy(u->username, p->value[0]); | |
303 strcpy(u->password, p->value[1]); | |
304 | |
305 u->user_info[0] = 0; | |
306 | |
307 if (!fgets(buf, sizeof(buf), f)) | |
308 return u; | |
309 | |
310 if (strcmp(buf, "\t\tuser_info {\n")) { | |
311 return u; | |
312 } | |
313 | |
314 if (!fgets(buf, sizeof(buf), f)) | |
315 return u; | |
316 | |
317 while (strncmp(buf, "\t\t}", 3)) { | |
318 if (strlen(buf) > 3) | |
319 strcat(u->user_info, &buf[3]); | |
320 | |
321 if (!fgets(buf, sizeof(buf), f)) { | |
322 return u; | |
323 } | |
324 } | |
325 | |
326 return u; | |
327 | |
328 } | |
329 | |
330 static void gaimrc_write_user(FILE *f, struct aim_user *u) | |
331 { | |
332 char *c; | |
333 int nl = 1;; | |
131
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
334 if (general_options & OPT_GEN_REMEMBER_PASS) |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
335 fprintf(f, "\t\tident { %s } { %s }\n", u->username, u->password); |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
336 else |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
337 fprintf(f, "\t\tident { %s } { }\n", u->username); |
1 | 338 fprintf(f, "\t\tuser_info {"); |
339 c = u->user_info; | |
340 while(*c) { | |
341 /* This is not as silly as it looks. */ | |
342 if (*c == '\n') { | |
343 nl++; | |
344 } else { | |
345 if (nl) { | |
346 while(nl) { | |
347 fprintf(f, "\n\t\t\t"); | |
348 nl--; | |
349 } | |
350 } | |
351 fprintf(f, "%c", *c); | |
352 } | |
353 c++; | |
354 } | |
355 fprintf(f, "\n\t\t}\n"); | |
356 | |
357 } | |
358 | |
359 | |
360 static void gaimrc_read_users(FILE *f) | |
361 { | |
362 char buf[2048]; | |
363 struct aim_user *u; | |
364 struct parse *p; | |
365 int cur = 0; | |
366 | |
367 buf[0] = 0; | |
368 | |
369 while (buf[0] != '}') { | |
370 if (buf[0] == '#') | |
371 continue; | |
372 | |
373 if (!fgets(buf, sizeof(buf), f)) | |
374 return; | |
375 | |
376 | |
377 | |
378 p = parse_line(buf); | |
379 | |
380 if (!strcmp(p->option, "current_user")) { | |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
381 cur = 1; |
1 | 382 } else if (strcmp(p->option, "user")) { |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
383 cur = 0; |
1 | 384 continue; |
159
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
385 } else { |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
386 cur = 0; |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
387 } |
1 | 388 |
389 u = gaimrc_read_user(f); | |
390 | |
391 if (cur) | |
392 current_user = u; | |
393 | |
394 aim_users = g_list_append(aim_users, u); | |
395 } | |
396 } | |
397 | |
398 static void gaimrc_write_users(FILE *f) | |
399 { | |
400 GList *usr = aim_users; | |
401 struct aim_user *u; | |
402 | |
403 fprintf(f, "users {\n"); | |
404 | |
405 while(usr) { | |
406 u = (struct aim_user *)usr->data; | |
407 if (current_user == u) { | |
408 fprintf(f, "\tcurrent_user {\n"); | |
409 } else { | |
410 fprintf(f, "\tuser {\n"); | |
411 } | |
412 gaimrc_write_user(f, u); | |
413 | |
414 fprintf(f, "\t}\n"); | |
415 | |
416 usr = usr->next; | |
417 } | |
418 | |
419 fprintf(f, "}\n"); | |
420 } | |
421 | |
422 | |
423 | |
424 | |
425 static void gaimrc_read_options(FILE *f) | |
426 { | |
427 char buf[2048]; | |
428 struct parse *p; | |
429 | |
430 buf[0] = 0; | |
431 | |
432 while (buf[0] != '}') { | |
433 if (buf[0] == '#') | |
434 continue; | |
435 | |
436 if (!fgets(buf, sizeof(buf), f)) | |
437 return; | |
438 | |
439 p = parse_line(buf); | |
440 | |
441 if (!strcmp(p->option, "general_options")) { | |
442 general_options = atoi(p->value[0]); | |
443 } else if (!strcmp(p->option, "display_options")) { | |
444 display_options = atoi(p->value[0]); | |
445 } else if (!strcmp(p->option, "sound_options")) { | |
446 sound_options = atoi(p->value[0]); | |
447 } else if (!strcmp(p->option, "font_options")) { | |
448 font_options = atoi(p->value[0]); | |
180 | 449 } else if (!strcmp(p->option, "latest_ver")) { |
450 g_snprintf(latest_ver, BUF_LONG, "%s", p->value[0]); | |
1 | 451 } else if (!strcmp(p->option, "report_idle")) { |
452 report_idle = atoi(p->value[0]); | |
453 } else if (!strcmp(p->option, "web_browser")) { | |
454 web_browser = atoi(p->value[0]); | |
455 } else if (!strcmp(p->option, "web_command")) { | |
456 strcpy(web_command, p->value[0]); | |
457 } else if (!strcmp(p->option, "proxy_type")) { | |
458 proxy_type = atoi(p->value[0]); | |
459 } else if (!strcmp(p->option, "proxy_host")) { | |
460 strcpy(proxy_host, p->value[0]); | |
461 } else if (!strcmp(p->option, "proxy_port")) { | |
462 proxy_port = atoi(p->value[0]); | |
463 } else if (!strcmp(p->option, "aim_host")) { | |
464 strcpy(aim_host, p->value[0]); | |
465 } else if (!strcmp(p->option, "aim_port")) { | |
466 aim_port = atoi(p->value[0]); | |
467 } else if (!strcmp(p->option, "login_host")) { | |
468 strcpy(login_host, p->value[0]); | |
469 } else if (!strcmp(p->option, "login_port")) { | |
470 login_port = atoi(p->value[0]); | |
471 } else if (!strcmp(p->option, "blist_pos")) { | |
472 blist_pos.x = atoi(p->value[0]); | |
473 blist_pos.y = atoi(p->value[1]); | |
474 blist_pos.width = atoi(p->value[2]); | |
475 blist_pos.height = atoi(p->value[3]); | |
476 blist_pos.xoff = atoi(p->value[4]); | |
477 blist_pos.yoff = atoi(p->value[5]); | |
82 | 478 } |
1 | 479 |
480 } | |
481 | |
482 } | |
483 | |
484 static void gaimrc_write_options(FILE *f) | |
485 { | |
486 | |
487 fprintf(f, "options {\n"); | |
488 fprintf(f, "\tgeneral_options { %d }\n", general_options); | |
489 fprintf(f, "\tdisplay_options { %d }\n", display_options); | |
490 fprintf(f, "\tsound_options { %d }\n", sound_options); | |
491 fprintf(f, "\tfont_options { %d }\n", font_options); | |
492 fprintf(f, "\treport_idle { %d }\n", report_idle); | |
493 fprintf(f, "\tweb_browser { %d }\n", web_browser); | |
494 fprintf(f, "\tweb_command { %s }\n", web_command); | |
495 fprintf(f, "\tproxy_type { %d }\n", proxy_type); | |
496 fprintf(f, "\tproxy_host { %s }\n", proxy_host); | |
497 fprintf(f, "\tproxy_port { %d }\n", proxy_port); | |
498 fprintf(f, "\taim_host { %s }\n", aim_host); | |
499 fprintf(f, "\taim_port { %d }\n", aim_port); | |
500 fprintf(f, "\tlogin_host { %s }\n", login_host); | |
501 fprintf(f, "\tlogin_port { %d }\n", login_port); | |
502 fprintf(f, "\tblist_pos { %d } { %d } { %d } { %d } { %d } { %d }\n", | |
503 blist_pos.x, blist_pos.y, blist_pos.width, blist_pos.height, | |
504 blist_pos.xoff, blist_pos.yoff); | |
180 | 505 fprintf(f, "\tlatest_ver { %s }\n", latest_ver); |
1 | 506 fprintf(f, "}\n"); |
507 } | |
508 | |
509 | |
510 void set_defaults() | |
511 { | |
512 general_options = | |
513 OPT_GEN_SEND_LINKS | | |
514 OPT_GEN_ENTER_SENDS | | |
515 OPT_GEN_SAVED_WINDOWS | | |
516 OPT_GEN_REMEMBER_PASS | | |
180 | 517 OPT_GEN_REGISTERED | |
518 OPT_GEN_CHECK_VERSIONS; | |
1 | 519 display_options = |
520 OPT_DISP_SHOW_IDLETIME | | |
521 OPT_DISP_SHOW_TIME | | |
522 OPT_DISP_SHOW_PIXMAPS | | |
523 OPT_DISP_SHOW_BUTTON_XPM; | |
524 font_options = 0; | |
156 | 525 sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND | OPT_SOUND_SILENT_SIGNON; |
1 | 526 report_idle = IDLE_GAIM; |
527 web_browser = BROWSER_NETSCAPE; | |
528 proxy_type = PROXY_NONE; | |
529 | |
530 aim_port = TOC_PORT; | |
531 login_port = AUTH_PORT; | |
532 g_snprintf(aim_host, sizeof(aim_host), "%s", TOC_HOST); | |
533 g_snprintf(login_host, sizeof(login_host), "%s", AUTH_HOST); | |
534 proxy_host[0] = 0; | |
535 proxy_port = 0; | |
536 g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s"); | |
537 blist_pos.width = 0; | |
538 blist_pos.height = 0; | |
539 blist_pos.x = 0; | |
540 blist_pos.y = 0; | |
541 blist_pos.xoff = 0; | |
542 blist_pos.yoff = 0; | |
180 | 543 g_snprintf(latest_ver, BUF_LONG, "%s", VERSION); |
1 | 544 } |
545 | |
546 | |
547 void load_prefs() | |
548 { | |
549 FILE *f; | |
550 char buf[1024]; | |
551 int ver = 0; | |
552 | |
553 if (getenv("HOME")) { | |
554 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
555 if ((f = fopen(buf,"r"))) { | |
556 fgets(buf, sizeof(buf), f); | |
557 sscanf(buf, "# .gaimrc v%d", &ver); | |
15 | 558 if ( (ver <= 1) || (buf[0] != '#')) { |
1 | 559 fclose(f); |
560 set_defaults(); | |
561 save_prefs(); | |
562 load_prefs(); | |
563 return; | |
564 } | |
565 while(!feof(f)) { | |
566 switch(gaimrc_parse_tag(f)) { | |
567 case -1: | |
568 /* Let the loop end, EOF*/ | |
569 break; | |
570 case 0: | |
571 gaimrc_read_users(f); | |
572 break; | |
573 case 1: | |
574 gaimrc_read_options(f); | |
575 break; | |
576 case 2: | |
577 gaimrc_read_away(f); | |
578 break; | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
579 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
580 case 3: |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
581 gaimrc_read_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
582 break; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
583 #endif |
1 | 584 default: |
585 /* NOOP */ | |
586 break; | |
587 } | |
588 } | |
589 fclose(f); | |
590 } | |
591 } | |
592 | |
593 } | |
594 | |
595 void save_prefs() | |
596 { | |
597 FILE *f; | |
598 char buf[BUF_LONG]; | |
599 | |
600 if (getenv("HOME")) { | |
601 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
602 if ((f = fopen(buf,"w"))) { | |
15 | 603 fprintf(f, "# .gaimrc v%d\n", 2); |
1 | 604 gaimrc_write_users(f); |
605 gaimrc_write_options(f); | |
606 gaimrc_write_away(f); | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
607 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
608 gaimrc_write_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
609 #endif |
1 | 610 fclose(f); |
611 chmod(buf, S_IRUSR | S_IWUSR); | |
612 } | |
613 | |
614 } | |
615 } | |
616 |