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