1 | #include <stdio.h> |
---|
2 | #include <unistd.h> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <string.h> |
---|
5 | #include <netdb.h> |
---|
6 | #include <termios.h> |
---|
7 | #include <sys/ioctl.h> |
---|
8 | #include <time.h> |
---|
9 | #include "owl.h" |
---|
10 | |
---|
11 | static const char fileIdent[] = "$Id$"; |
---|
12 | |
---|
13 | #ifndef MAXHOSTNAMELEN |
---|
14 | #define MAXHOSTNAMELEN 256 |
---|
15 | #endif |
---|
16 | |
---|
17 | void owl_global_init(owl_global *g) { |
---|
18 | struct hostent *hent; |
---|
19 | char hostname[MAXHOSTNAMELEN]; |
---|
20 | |
---|
21 | g->malloced=0; |
---|
22 | g->freed=0; |
---|
23 | |
---|
24 | gethostname(hostname, MAXHOSTNAMELEN); |
---|
25 | hent=gethostbyname(hostname); |
---|
26 | if (!hent) { |
---|
27 | g->thishost=owl_strdup("localhost"); |
---|
28 | } else { |
---|
29 | g->thishost=owl_strdup(hent->h_name); |
---|
30 | } |
---|
31 | |
---|
32 | owl_context_init(&g->ctx); |
---|
33 | owl_context_set_startup(&g->ctx); |
---|
34 | g->curmsg=0; |
---|
35 | g->topmsg=0; |
---|
36 | g->needrefresh=1; |
---|
37 | g->startupargs=NULL; |
---|
38 | |
---|
39 | owl_variable_dict_setup(&(g->vars)); |
---|
40 | owl_cmddict_setup(&(g->cmds)); |
---|
41 | |
---|
42 | g->lines=LINES; |
---|
43 | g->cols=COLS; |
---|
44 | |
---|
45 | g->rightshift=0; |
---|
46 | |
---|
47 | owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL); |
---|
48 | |
---|
49 | owl_keyhandler_init(&g->kh); |
---|
50 | owl_keys_setup_keymaps(&g->kh); |
---|
51 | |
---|
52 | owl_list_create(&(g->filterlist)); |
---|
53 | owl_list_create(&(g->puntlist)); |
---|
54 | owl_list_create(&(g->messagequeue)); |
---|
55 | owl_list_create(&(g->stylelist)); |
---|
56 | g->curmsg_vert_offset=0; |
---|
57 | g->resizepending=0; |
---|
58 | g->typwinactive=0; |
---|
59 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
60 | g->zaway=0; |
---|
61 | if (has_colors()) { |
---|
62 | g->hascolors=1; |
---|
63 | } |
---|
64 | g->colorpairs=COLOR_PAIRS; |
---|
65 | g->debug=OWL_DEBUG; |
---|
66 | g->searchactive=0; |
---|
67 | g->searchstring=NULL; |
---|
68 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
69 | g->buffercommand=NULL; |
---|
70 | g->newmsgproc_pid=0; |
---|
71 | |
---|
72 | owl_global_set_config_format(g, 0); |
---|
73 | owl_global_set_userclue(g, OWL_USERCLUE_NONE); |
---|
74 | owl_global_set_no_have_config(g); |
---|
75 | owl_history_init(&(g->msghist)); |
---|
76 | owl_history_init(&(g->cmdhist)); |
---|
77 | g->nextmsgid=0; |
---|
78 | |
---|
79 | owl_filterelement_create_true(&(g->fe_true)); |
---|
80 | owl_filterelement_create_false(&(g->fe_false)); |
---|
81 | owl_filterelement_create_null(&(g->fe_null)); |
---|
82 | |
---|
83 | _owl_global_setup_windows(g); |
---|
84 | |
---|
85 | /* Fill in some variables which don't have constant defaults */ |
---|
86 | /* TODO: come back later and check passwd file first */ |
---|
87 | g->homedir=owl_strdup(getenv("HOME")); |
---|
88 | |
---|
89 | owl_messagelist_create(&(g->msglist)); |
---|
90 | owl_mainwin_init(&(g->mw)); |
---|
91 | owl_popwin_init(&(g->pw)); |
---|
92 | |
---|
93 | g->aim_screenname=NULL; |
---|
94 | g->aim_loggedin=0; |
---|
95 | owl_timer_create_countdown(&(g->aim_noop_timer), 30); |
---|
96 | owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0); |
---|
97 | owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60); |
---|
98 | owl_buddylist_init(&(g->buddylist)); |
---|
99 | g->response=NULL; |
---|
100 | g->havezephyr=0; |
---|
101 | g->haveaim=0; |
---|
102 | owl_global_set_no_doaimevents(g); |
---|
103 | } |
---|
104 | |
---|
105 | void _owl_global_setup_windows(owl_global *g) { |
---|
106 | int cols, typwin_lines; |
---|
107 | |
---|
108 | cols=g->cols; |
---|
109 | typwin_lines=owl_global_get_typwin_lines(g); |
---|
110 | |
---|
111 | /* set the new window sizes */ |
---|
112 | g->recwinlines=g->lines-(typwin_lines+2); |
---|
113 | if (g->recwinlines<1) { |
---|
114 | /* this will screw things up. I'm not sure what to do yet, |
---|
115 | but this is better than nothing */ |
---|
116 | /* g->recwinlines=1; */ |
---|
117 | } |
---|
118 | |
---|
119 | /* create the new windows */ |
---|
120 | g->recwin=newwin(g->recwinlines, cols, 0, 0); |
---|
121 | if (g->recwin==NULL) { |
---|
122 | owl_function_debugmsg("\n\nI just received an error on creating a new receive window\n"); |
---|
123 | owl_function_debugmsg("newwin was called with arguments (%i, %i, 0, 0) and returned NULL\n", |
---|
124 | g->recwinlines, cols); |
---|
125 | endwin(); |
---|
126 | |
---|
127 | exit(50); |
---|
128 | } |
---|
129 | |
---|
130 | g->sepwin=newwin(1, cols, g->recwinlines, 0); |
---|
131 | g->msgwin=newwin(1, cols, g->recwinlines+1, 0); |
---|
132 | g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0); |
---|
133 | |
---|
134 | owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols); |
---|
135 | |
---|
136 | idlok(g->typwin, FALSE); |
---|
137 | idlok(g->recwin, FALSE); |
---|
138 | idlok(g->sepwin, FALSE); |
---|
139 | idlok(g->msgwin, FALSE); |
---|
140 | |
---|
141 | nodelay(g->typwin, 1); |
---|
142 | keypad(g->typwin, TRUE); |
---|
143 | wmove(g->typwin, 0, 0); |
---|
144 | |
---|
145 | meta(g->typwin, TRUE); |
---|
146 | } |
---|
147 | |
---|
148 | owl_context *owl_global_get_context(owl_global *g) { |
---|
149 | return(&g->ctx); |
---|
150 | } |
---|
151 | |
---|
152 | int owl_global_get_lines(owl_global *g) { |
---|
153 | return(g->lines); |
---|
154 | } |
---|
155 | |
---|
156 | int owl_global_get_cols(owl_global *g) { |
---|
157 | return(g->cols); |
---|
158 | } |
---|
159 | |
---|
160 | int owl_global_get_recwin_lines(owl_global *g) { |
---|
161 | return(g->recwinlines); |
---|
162 | } |
---|
163 | |
---|
164 | /* curmsg */ |
---|
165 | |
---|
166 | int owl_global_get_curmsg(owl_global *g) { |
---|
167 | return(g->curmsg); |
---|
168 | } |
---|
169 | |
---|
170 | void owl_global_set_curmsg(owl_global *g, int i) { |
---|
171 | g->curmsg=i; |
---|
172 | /* we will reset the vertical offset from here */ |
---|
173 | /* we might want to move this out to the functions later */ |
---|
174 | owl_global_set_curmsg_vert_offset(g, 0); |
---|
175 | } |
---|
176 | |
---|
177 | /* topmsg */ |
---|
178 | |
---|
179 | int owl_global_get_topmsg(owl_global *g) { |
---|
180 | return(g->topmsg); |
---|
181 | } |
---|
182 | |
---|
183 | void owl_global_set_topmsg(owl_global *g, int i) { |
---|
184 | g->topmsg=i; |
---|
185 | } |
---|
186 | |
---|
187 | /* windows */ |
---|
188 | |
---|
189 | owl_mainwin *owl_global_get_mainwin(owl_global *g) { |
---|
190 | return(&(g->mw)); |
---|
191 | } |
---|
192 | |
---|
193 | owl_popwin *owl_global_get_popwin(owl_global *g) { |
---|
194 | return(&(g->pw)); |
---|
195 | } |
---|
196 | |
---|
197 | /* msglist */ |
---|
198 | |
---|
199 | owl_messagelist *owl_global_get_msglist(owl_global *g) { |
---|
200 | return(&(g->msglist)); |
---|
201 | } |
---|
202 | |
---|
203 | /* keyhandler */ |
---|
204 | |
---|
205 | owl_keyhandler *owl_global_get_keyhandler(owl_global *g) { |
---|
206 | return(&(g->kh)); |
---|
207 | } |
---|
208 | |
---|
209 | /* curses windows */ |
---|
210 | |
---|
211 | WINDOW *owl_global_get_curs_recwin(owl_global *g) { |
---|
212 | return(g->recwin); |
---|
213 | } |
---|
214 | |
---|
215 | WINDOW *owl_global_get_curs_sepwin(owl_global *g) { |
---|
216 | return(g->sepwin); |
---|
217 | } |
---|
218 | |
---|
219 | WINDOW *owl_global_get_curs_msgwin(owl_global *g) { |
---|
220 | return(g->msgwin); |
---|
221 | } |
---|
222 | |
---|
223 | WINDOW *owl_global_get_curs_typwin(owl_global *g) { |
---|
224 | return(g->typwin); |
---|
225 | } |
---|
226 | |
---|
227 | /* typwin */ |
---|
228 | |
---|
229 | owl_editwin *owl_global_get_typwin(owl_global *g) { |
---|
230 | return(&(g->tw)); |
---|
231 | } |
---|
232 | |
---|
233 | /* buffercommand */ |
---|
234 | |
---|
235 | void owl_global_set_buffercommand(owl_global *g, char *command) { |
---|
236 | if (g->buffercommand) owl_free(g->buffercommand); |
---|
237 | g->buffercommand=owl_strdup(command); |
---|
238 | } |
---|
239 | |
---|
240 | char *owl_global_get_buffercommand(owl_global *g) { |
---|
241 | if (g->buffercommand) return(g->buffercommand); |
---|
242 | return(""); |
---|
243 | } |
---|
244 | |
---|
245 | /* refresh */ |
---|
246 | |
---|
247 | int owl_global_is_needrefresh(owl_global *g) { |
---|
248 | if (g->needrefresh==1) return(1); |
---|
249 | return(0); |
---|
250 | } |
---|
251 | |
---|
252 | void owl_global_set_needrefresh(owl_global *g) { |
---|
253 | g->needrefresh=1; |
---|
254 | } |
---|
255 | |
---|
256 | void owl_global_set_noneedrefresh(owl_global *g) { |
---|
257 | g->needrefresh=0; |
---|
258 | } |
---|
259 | |
---|
260 | /* variable dictionary */ |
---|
261 | |
---|
262 | owl_vardict *owl_global_get_vardict(owl_global *g) { |
---|
263 | return &(g->vars); |
---|
264 | } |
---|
265 | |
---|
266 | /* command dictionary */ |
---|
267 | |
---|
268 | owl_cmddict *owl_global_get_cmddict(owl_global *g) { |
---|
269 | return &(g->cmds); |
---|
270 | } |
---|
271 | |
---|
272 | /* rightshift */ |
---|
273 | |
---|
274 | void owl_global_set_rightshift(owl_global *g, int i) { |
---|
275 | g->rightshift=i; |
---|
276 | } |
---|
277 | |
---|
278 | int owl_global_get_rightshift(owl_global *g) { |
---|
279 | return(g->rightshift); |
---|
280 | } |
---|
281 | |
---|
282 | /* typwin */ |
---|
283 | |
---|
284 | int owl_global_is_typwin_active(owl_global *g) { |
---|
285 | if (g->typwinactive==1) return(1); |
---|
286 | return(0); |
---|
287 | } |
---|
288 | |
---|
289 | void owl_global_set_typwin_active(owl_global *g) { |
---|
290 | g->typwinactive=1; |
---|
291 | } |
---|
292 | |
---|
293 | void owl_global_set_typwin_inactive(owl_global *g) { |
---|
294 | g->typwinactive=0; |
---|
295 | } |
---|
296 | |
---|
297 | /* resize */ |
---|
298 | |
---|
299 | void owl_global_set_resize_pending(owl_global *g) { |
---|
300 | g->resizepending=1; |
---|
301 | } |
---|
302 | |
---|
303 | char *owl_global_get_homedir(owl_global *g) { |
---|
304 | if (g->homedir) return(g->homedir); |
---|
305 | return("/"); |
---|
306 | } |
---|
307 | |
---|
308 | int owl_global_get_direction(owl_global *g) { |
---|
309 | return(g->direction); |
---|
310 | } |
---|
311 | |
---|
312 | void owl_global_set_direction_downwards(owl_global *g) { |
---|
313 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
314 | } |
---|
315 | |
---|
316 | void owl_global_set_direction_upwards(owl_global *g) { |
---|
317 | g->direction=OWL_DIRECTION_UPWARDS; |
---|
318 | } |
---|
319 | |
---|
320 | /* perl stuff */ |
---|
321 | |
---|
322 | void owl_global_set_perlinterp(owl_global *g, void *p) { |
---|
323 | g->perl=p; |
---|
324 | } |
---|
325 | |
---|
326 | void *owl_global_get_perlinterp(owl_global *g) { |
---|
327 | return(g->perl); |
---|
328 | } |
---|
329 | |
---|
330 | int owl_global_is_config_format(owl_global *g) { |
---|
331 | if (g->config_format) return(1); |
---|
332 | return(0); |
---|
333 | } |
---|
334 | |
---|
335 | void owl_global_set_config_format(owl_global *g, int state) { |
---|
336 | if (state==1) { |
---|
337 | g->config_format=1; |
---|
338 | } else { |
---|
339 | g->config_format=0; |
---|
340 | } |
---|
341 | } |
---|
342 | |
---|
343 | void owl_global_set_have_config(owl_global *g) { |
---|
344 | g->haveconfig=1; |
---|
345 | } |
---|
346 | |
---|
347 | void owl_global_set_no_have_config(owl_global *g) { |
---|
348 | g->haveconfig=0; |
---|
349 | } |
---|
350 | |
---|
351 | int owl_global_have_config(owl_global *g) { |
---|
352 | if (g->haveconfig) return(1); |
---|
353 | return(0); |
---|
354 | } |
---|
355 | |
---|
356 | void owl_global_resize(owl_global *g, int x, int y) { |
---|
357 | /* resize the screen. If x or y is 0 use the terminal size */ |
---|
358 | struct winsize size; |
---|
359 | |
---|
360 | if (!g->resizepending) return; |
---|
361 | |
---|
362 | /* delete the current windows */ |
---|
363 | delwin(g->recwin); |
---|
364 | delwin(g->sepwin); |
---|
365 | delwin(g->msgwin); |
---|
366 | delwin(g->typwin); |
---|
367 | if (!isendwin()) { |
---|
368 | endwin(); |
---|
369 | } |
---|
370 | |
---|
371 | refresh(); |
---|
372 | |
---|
373 | /* get the new size */ |
---|
374 | ioctl(STDIN_FILENO, TIOCGWINSZ, &size); |
---|
375 | if (x==0) { |
---|
376 | g->lines=size.ws_row; |
---|
377 | } else { |
---|
378 | g->lines=x; |
---|
379 | } |
---|
380 | |
---|
381 | if (y==0) { |
---|
382 | g->cols=size.ws_col; |
---|
383 | } else { |
---|
384 | g->cols=y; |
---|
385 | } |
---|
386 | |
---|
387 | /* resizeterm(size.ws_row, size.ws_col); */ |
---|
388 | |
---|
389 | /* re-initialize the windows */ |
---|
390 | _owl_global_setup_windows(g); |
---|
391 | |
---|
392 | /* refresh stuff */ |
---|
393 | g->needrefresh=1; |
---|
394 | owl_mainwin_redisplay(&(g->mw)); |
---|
395 | sepbar(NULL); |
---|
396 | |
---|
397 | if (owl_global_is_typwin_active(g)) { |
---|
398 | owl_editwin_redisplay(&(g->tw), 0); |
---|
399 | } |
---|
400 | /* TODO: this should handle other forms of popwins */ |
---|
401 | if (owl_popwin_is_active(owl_global_get_popwin(g)) |
---|
402 | && owl_global_get_viewwin(g)) { |
---|
403 | owl_popwin_refresh(owl_global_get_popwin(g)); |
---|
404 | owl_viewwin_redisplay(owl_global_get_viewwin(g), 0); |
---|
405 | } |
---|
406 | |
---|
407 | owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col); |
---|
408 | owl_function_makemsg(""); |
---|
409 | g->resizepending=0; |
---|
410 | } |
---|
411 | |
---|
412 | /* debug */ |
---|
413 | |
---|
414 | int owl_global_is_debug_fast(owl_global *g) { |
---|
415 | if (g->debug) return(1); |
---|
416 | return(0); |
---|
417 | } |
---|
418 | |
---|
419 | /* starttime */ |
---|
420 | |
---|
421 | time_t owl_global_get_starttime(owl_global *g) { |
---|
422 | return(g->starttime); |
---|
423 | } |
---|
424 | |
---|
425 | time_t owl_global_get_runtime(owl_global *g) { |
---|
426 | return(time(NULL)-g->starttime); |
---|
427 | } |
---|
428 | |
---|
429 | void owl_global_get_runtime_string(owl_global *g, char *buff) { |
---|
430 | time_t diff; |
---|
431 | |
---|
432 | diff=time(NULL)-owl_global_get_starttime(g); |
---|
433 | |
---|
434 | /* print something nicer later */ |
---|
435 | sprintf(buff, "%i seconds", (int) diff); |
---|
436 | } |
---|
437 | |
---|
438 | char *owl_global_get_hostname(owl_global *g) { |
---|
439 | if (g->thishost) return(g->thishost); |
---|
440 | return(""); |
---|
441 | } |
---|
442 | |
---|
443 | /* userclue */ |
---|
444 | |
---|
445 | void owl_global_set_userclue(owl_global *g, int clue) { |
---|
446 | g->userclue=clue; |
---|
447 | } |
---|
448 | |
---|
449 | void owl_global_add_userclue(owl_global *g, int clue) { |
---|
450 | g->userclue|=clue; |
---|
451 | } |
---|
452 | |
---|
453 | int owl_global_get_userclue(owl_global *g) { |
---|
454 | return(g->userclue); |
---|
455 | } |
---|
456 | |
---|
457 | int owl_global_is_userclue(owl_global *g, int clue) { |
---|
458 | if (g->userclue & clue) return(1); |
---|
459 | return(0); |
---|
460 | } |
---|
461 | |
---|
462 | /* viewwin */ |
---|
463 | |
---|
464 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
465 | return(&(g->vw)); |
---|
466 | } |
---|
467 | |
---|
468 | |
---|
469 | /* vert offset */ |
---|
470 | |
---|
471 | int owl_global_get_curmsg_vert_offset(owl_global *g) { |
---|
472 | return(g->curmsg_vert_offset); |
---|
473 | } |
---|
474 | |
---|
475 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
476 | g->curmsg_vert_offset=i; |
---|
477 | } |
---|
478 | |
---|
479 | /* startup args */ |
---|
480 | |
---|
481 | void owl_global_set_startupargs(owl_global *g, int argc, char **argv) { |
---|
482 | int i, len; |
---|
483 | |
---|
484 | if (g->startupargs) owl_free(g->startupargs); |
---|
485 | |
---|
486 | len=0; |
---|
487 | for (i=0; i<argc; i++) { |
---|
488 | len+=strlen(argv[i])+5; |
---|
489 | } |
---|
490 | g->startupargs=malloc(len+5); |
---|
491 | |
---|
492 | strcpy(g->startupargs, ""); |
---|
493 | for (i=0; i<argc; i++) { |
---|
494 | sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]); |
---|
495 | } |
---|
496 | g->startupargs[strlen(g->startupargs)-1]='\0'; |
---|
497 | } |
---|
498 | |
---|
499 | char *owl_global_get_startupargs(owl_global *g) { |
---|
500 | if (g->startupargs) return(g->startupargs); |
---|
501 | return(""); |
---|
502 | } |
---|
503 | |
---|
504 | /* history */ |
---|
505 | |
---|
506 | owl_history *owl_global_get_msg_history(owl_global *g) { |
---|
507 | return(&(g->msghist)); |
---|
508 | } |
---|
509 | |
---|
510 | owl_history *owl_global_get_cmd_history(owl_global *g) { |
---|
511 | return(&(g->cmdhist)); |
---|
512 | } |
---|
513 | |
---|
514 | /* filterlist */ |
---|
515 | |
---|
516 | owl_list *owl_global_get_filterlist(owl_global *g) { |
---|
517 | return(&(g->filterlist)); |
---|
518 | } |
---|
519 | |
---|
520 | owl_filter *owl_global_get_filter(owl_global *g, char *name) { |
---|
521 | int i, j; |
---|
522 | owl_filter *f; |
---|
523 | |
---|
524 | j=owl_list_get_size(&(g->filterlist)); |
---|
525 | for (i=0; i<j; i++) { |
---|
526 | f=owl_list_get_element(&(g->filterlist), i); |
---|
527 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
528 | return(f); |
---|
529 | } |
---|
530 | } |
---|
531 | return(NULL); |
---|
532 | } |
---|
533 | |
---|
534 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
535 | owl_list_append_element(&(g->filterlist), f); |
---|
536 | } |
---|
537 | |
---|
538 | void owl_global_remove_filter(owl_global *g, char *name) { |
---|
539 | int i, j; |
---|
540 | owl_filter *f; |
---|
541 | |
---|
542 | j=owl_list_get_size(&(g->filterlist)); |
---|
543 | for (i=0; i<j; i++) { |
---|
544 | f=owl_list_get_element(&(g->filterlist), i); |
---|
545 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
546 | owl_filter_free(f); |
---|
547 | owl_list_remove_element(&(g->filterlist), i); |
---|
548 | break; |
---|
549 | } |
---|
550 | } |
---|
551 | } |
---|
552 | |
---|
553 | /* nextmsgid */ |
---|
554 | |
---|
555 | int owl_global_get_nextmsgid(owl_global *g) { |
---|
556 | return(g->nextmsgid++); |
---|
557 | } |
---|
558 | |
---|
559 | /* current view */ |
---|
560 | |
---|
561 | owl_view *owl_global_get_current_view(owl_global *g) { |
---|
562 | return(&(g->current_view)); |
---|
563 | } |
---|
564 | |
---|
565 | owl_filterelement *owl_global_get_filterelement_true(owl_global *g) { |
---|
566 | return(&(g->fe_true)); |
---|
567 | } |
---|
568 | |
---|
569 | owl_filterelement *owl_global_get_filterelement_false(owl_global *g) { |
---|
570 | return(&(g->fe_false)); |
---|
571 | } |
---|
572 | |
---|
573 | owl_filterelement *owl_global_get_filterelement_null(owl_global *g) { |
---|
574 | return(&(g->fe_null)); |
---|
575 | } |
---|
576 | |
---|
577 | /* has colors */ |
---|
578 | |
---|
579 | int owl_global_get_hascolors(owl_global *g) { |
---|
580 | if (g->hascolors) return(1); |
---|
581 | return(0); |
---|
582 | } |
---|
583 | |
---|
584 | /* color pairs */ |
---|
585 | |
---|
586 | int owl_global_get_colorpairs(owl_global *g) { |
---|
587 | return(g->colorpairs); |
---|
588 | } |
---|
589 | |
---|
590 | /* puntlist */ |
---|
591 | |
---|
592 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
593 | return(&(g->puntlist)); |
---|
594 | } |
---|
595 | |
---|
596 | int owl_global_message_is_puntable(owl_global *g, owl_message *m) { |
---|
597 | owl_list *pl; |
---|
598 | int i, j; |
---|
599 | |
---|
600 | pl=owl_global_get_puntlist(g); |
---|
601 | j=owl_list_get_size(pl); |
---|
602 | for (i=0; i<j; i++) { |
---|
603 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
604 | } |
---|
605 | return(0); |
---|
606 | } |
---|
607 | |
---|
608 | int owl_global_should_followlast(owl_global *g) { |
---|
609 | owl_view *v; |
---|
610 | |
---|
611 | if (!owl_global_is__followlast(g)) return(0); |
---|
612 | |
---|
613 | v=owl_global_get_current_view(g); |
---|
614 | |
---|
615 | if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1); |
---|
616 | return(0); |
---|
617 | } |
---|
618 | |
---|
619 | int owl_global_is_search_active(owl_global *g) { |
---|
620 | if (g->searchactive) return(1); |
---|
621 | return(0); |
---|
622 | } |
---|
623 | |
---|
624 | void owl_global_set_search_active(owl_global *g, char *string) { |
---|
625 | g->searchactive=1; |
---|
626 | if (g->searchstring != NULL) owl_free(g->searchstring); |
---|
627 | g->searchstring=owl_strdup(string); |
---|
628 | } |
---|
629 | |
---|
630 | void owl_global_set_search_inactive(owl_global *g) { |
---|
631 | g->searchactive=0; |
---|
632 | } |
---|
633 | |
---|
634 | char *owl_global_get_search_string(owl_global *g) { |
---|
635 | if (g->searchstring==NULL) return(""); |
---|
636 | return(g->searchstring); |
---|
637 | } |
---|
638 | |
---|
639 | void owl_global_set_newmsgproc_pid(owl_global *g, int i) { |
---|
640 | g->newmsgproc_pid=i; |
---|
641 | } |
---|
642 | |
---|
643 | int owl_global_get_newmsgproc_pid(owl_global *g) { |
---|
644 | return(g->newmsgproc_pid); |
---|
645 | } |
---|
646 | |
---|
647 | void owl_global_add_to_malloced(owl_global *g, int i) { |
---|
648 | g->malloced+=i; |
---|
649 | } |
---|
650 | |
---|
651 | void owl_global_add_to_freed(owl_global *g, int i) { |
---|
652 | g->freed+=1; |
---|
653 | } |
---|
654 | |
---|
655 | int owl_global_get_malloced(owl_global *g) { |
---|
656 | return(g->malloced); |
---|
657 | } |
---|
658 | |
---|
659 | int owl_global_get_freed(owl_global *g) { |
---|
660 | return(g->freed); |
---|
661 | } |
---|
662 | |
---|
663 | int owl_global_get_meminuse(owl_global *g) { |
---|
664 | return(g->malloced-g->freed); |
---|
665 | } |
---|
666 | |
---|
667 | /* AIM stuff */ |
---|
668 | |
---|
669 | int owl_global_is_aimloggedin(owl_global *g) |
---|
670 | { |
---|
671 | if (g->aim_loggedin) return(1); |
---|
672 | return(0); |
---|
673 | } |
---|
674 | |
---|
675 | char *owl_global_get_aim_screenname(owl_global *g) |
---|
676 | { |
---|
677 | if (owl_global_is_aimloggedin(g)) { |
---|
678 | return (g->aim_screenname); |
---|
679 | } |
---|
680 | return(""); |
---|
681 | } |
---|
682 | |
---|
683 | void owl_global_set_aimloggedin(owl_global *g, char *screenname) |
---|
684 | { |
---|
685 | g->aim_loggedin=1; |
---|
686 | if (g->aim_screenname) owl_free(g->aim_screenname); |
---|
687 | g->aim_screenname=owl_strdup(screenname); |
---|
688 | } |
---|
689 | |
---|
690 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
691 | { |
---|
692 | g->aim_loggedin=0; |
---|
693 | } |
---|
694 | |
---|
695 | int owl_global_is_doaimevents(owl_global *g) |
---|
696 | { |
---|
697 | if (g->aim_doprocessing) return(1); |
---|
698 | return(0); |
---|
699 | } |
---|
700 | |
---|
701 | void owl_global_set_doaimevents(owl_global *g) |
---|
702 | { |
---|
703 | g->aim_doprocessing=1; |
---|
704 | } |
---|
705 | |
---|
706 | void owl_global_set_no_doaimevents(owl_global *g) |
---|
707 | { |
---|
708 | g->aim_doprocessing=0; |
---|
709 | } |
---|
710 | |
---|
711 | |
---|
712 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
713 | { |
---|
714 | return(&(g->aimsess)); |
---|
715 | } |
---|
716 | |
---|
717 | aim_conn_t *owl_global_get_waitingconn(owl_global *g) |
---|
718 | { |
---|
719 | return(&(g->waitingconn)); |
---|
720 | } |
---|
721 | |
---|
722 | int owl_global_is_aimnop_time(owl_global *g) |
---|
723 | { |
---|
724 | if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1); |
---|
725 | return(0); |
---|
726 | } |
---|
727 | |
---|
728 | void owl_global_aimnop_sent(owl_global *g) |
---|
729 | { |
---|
730 | owl_timer_reset(&(g->aim_noop_timer)); |
---|
731 | } |
---|
732 | |
---|
733 | owl_timer *owl_global_get_aim_login_timer(owl_global *g) |
---|
734 | { |
---|
735 | return(&(g->aim_ignorelogin_timer)); |
---|
736 | } |
---|
737 | |
---|
738 | /* message queue */ |
---|
739 | |
---|
740 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
741 | { |
---|
742 | owl_list_append_element(&(g->messagequeue), m); |
---|
743 | } |
---|
744 | |
---|
745 | /* pop off the first message and return it. Return NULL if the queue |
---|
746 | * is empty. The caller should free the message after using it, if |
---|
747 | * necessary. |
---|
748 | */ |
---|
749 | owl_message *owl_global_messageuque_popmsg(owl_global *g) |
---|
750 | { |
---|
751 | owl_message *out; |
---|
752 | |
---|
753 | if (owl_list_get_size(&(g->messagequeue))==0) return(NULL); |
---|
754 | out=owl_list_get_element(&(g->messagequeue), 0); |
---|
755 | owl_list_remove_element(&(g->messagequeue), 0); |
---|
756 | return(out); |
---|
757 | } |
---|
758 | |
---|
759 | int owl_global_messagequeue_pending(owl_global *g) |
---|
760 | { |
---|
761 | if (owl_list_get_size(&(g->messagequeue))==0) return(0); |
---|
762 | return(1); |
---|
763 | } |
---|
764 | |
---|
765 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
766 | { |
---|
767 | return(&(g->buddylist)); |
---|
768 | } |
---|
769 | |
---|
770 | /* style */ |
---|
771 | |
---|
772 | /* Return the style with name 'name'. If it does not exist return |
---|
773 | * NULL */ |
---|
774 | owl_style *owl_global_get_style_by_name(owl_global *g, char *name) |
---|
775 | { |
---|
776 | int i, j; |
---|
777 | owl_style *s; |
---|
778 | |
---|
779 | j=owl_list_get_size(&(g->stylelist)); |
---|
780 | for (i=0; i<j; i++) { |
---|
781 | s=owl_list_get_element(&(g->stylelist), i); |
---|
782 | if (owl_style_matches_name(s, name)) { |
---|
783 | return(s); |
---|
784 | } |
---|
785 | } |
---|
786 | return(NULL); |
---|
787 | } |
---|
788 | |
---|
789 | void owl_global_add_style(owl_global *g, owl_style *s) |
---|
790 | { |
---|
791 | owl_list_append_element(&(g->stylelist), s); |
---|
792 | } |
---|
793 | |
---|
794 | char *owl_global_get_response(owl_global *g) |
---|
795 | { |
---|
796 | if (g->response==NULL) return(""); |
---|
797 | return(g->response); |
---|
798 | } |
---|
799 | |
---|
800 | void owl_global_set_response(owl_global *g, char *resp) |
---|
801 | { |
---|
802 | if (g->response) owl_free(g->response); |
---|
803 | g->response=owl_strdup(resp); |
---|
804 | } |
---|
805 | |
---|
806 | |
---|
807 | void owl_global_set_haveaim(owl_global *g) |
---|
808 | { |
---|
809 | g->haveaim=1; |
---|
810 | } |
---|
811 | |
---|
812 | int owl_global_is_haveaim(owl_global *g) |
---|
813 | { |
---|
814 | if (g->haveaim) return(1); |
---|
815 | return(0); |
---|
816 | } |
---|
817 | |
---|
818 | void owl_global_set_havezephyr(owl_global *g) |
---|
819 | { |
---|
820 | g->havezephyr=1; |
---|
821 | } |
---|
822 | |
---|
823 | int owl_global_is_havezephyr(owl_global *g) |
---|
824 | { |
---|
825 | if (g->havezephyr) return(1); |
---|
826 | return(0); |
---|
827 | } |
---|
828 | |
---|
829 | owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g) |
---|
830 | { |
---|
831 | return(&(g->aim_buddyinfo_timer)); |
---|
832 | } |
---|