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