source: global.c @ 7ba9ead9

debianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7ba9ead9 was da466e0, checked in by Geoffrey Thomas <geofft@mit.edu>, 16 years ago
At broder/ccpost's suggestion, add a typewindelta variable that lets you expand the typewin on small screens when it is active, and keep it small by default.
  • Property mode set to 100644
File size: 20.4 KB
Line 
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
11static const char fileIdent[] = "$Id$";
12
13#ifndef MAXHOSTNAMELEN
14#define MAXHOSTNAMELEN 256
15#endif
16
17void owl_global_init(owl_global *g) {
18  struct hostent *hent;
19  char hostname[MAXHOSTNAMELEN];
20  char *cd;
21
22  g->malloced=0;
23  g->freed=0;
24
25  gethostname(hostname, MAXHOSTNAMELEN);
26  hent=gethostbyname(hostname);
27  if (!hent) {
28    g->thishost=owl_strdup("localhost");
29  } else {
30    g->thishost=owl_strdup(hent->h_name);
31  }
32
33  owl_context_init(&g->ctx);
34  owl_context_set_startup(&g->ctx);
35  g->curmsg=0;
36  g->topmsg=0;
37  g->needrefresh=1;
38  g->startupargs=NULL;
39
40  owl_variable_dict_setup(&(g->vars));
41  owl_cmddict_setup(&(g->cmds));
42
43  g->lines=LINES;
44  g->cols=COLS;
45
46  g->rightshift=0;
47
48  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
49
50  owl_keyhandler_init(&g->kh);
51  owl_keys_setup_keymaps(&g->kh);
52
53  owl_list_create(&(g->muxevents));
54  owl_list_create(&(g->filterlist));
55  owl_list_create(&(g->puntlist));
56  owl_list_create(&(g->messagequeue));
57  owl_dict_create(&(g->styledict));
58  g->curmsg_vert_offset=0;
59  g->resizepending=0;
60  g->typwinactive=0;
61  g->direction=OWL_DIRECTION_DOWNWARDS;
62  g->zaway=0;
63  if (has_colors()) {
64    g->hascolors=1;
65  }
66  g->colorpairs=COLOR_PAIRS;
67  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
68  g->debug=OWL_DEBUG;
69  g->searchactive=0;
70  g->searchstring=NULL;
71  g->starttime=time(NULL); /* assumes we call init only a start time */
72  g->lastinputtime=g->starttime;
73  g->newmsgproc_pid=0;
74 
75  owl_global_set_config_format(g, 0);
76  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
77  owl_global_set_no_have_config(g);
78  owl_history_init(&(g->msghist));
79  owl_history_init(&(g->cmdhist));
80  owl_history_set_norepeats(&(g->cmdhist));
81  g->nextmsgid=0;
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  g->confdir = NULL;
90  g->startupfile = NULL;
91  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
92  owl_global_set_confdir(g, cd);
93  owl_free(cd);
94
95  owl_messagelist_create(&(g->msglist));
96  owl_mainwin_init(&(g->mw));
97  owl_popwin_init(&(g->pw));
98
99  g->aim_screenname=NULL;
100  g->aim_screenname_for_filters=NULL;
101  g->aim_loggedin=0;
102  owl_timer_create_countdown(&(g->aim_noop_timer), 30);
103  owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);
104  owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);
105  owl_buddylist_init(&(g->buddylist));
106   
107  g->havezephyr=0;
108  g->haveaim=0;
109  owl_global_set_no_doaimevents(g);
110
111  owl_errqueue_init(&(g->errqueue));
112  g->got_err_signal=0;
113
114  owl_zbuddylist_create(&(g->zbuddies));
115  owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
116
117  owl_obarray_init(&(g->obarray));
118
119  owl_message_init_fmtext_cache();
120  owl_list_create(&(g->dispatchlist));
121}
122
123void _owl_global_setup_windows(owl_global *g) {
124  int cols, typwin_lines;
125
126  cols=g->cols;
127  typwin_lines=owl_global_get_typwin_lines(g);
128
129  /* set the new window sizes */
130  g->recwinlines=g->lines-(typwin_lines+2);
131  if (g->recwinlines<0) {
132    /* gotta deal with this */
133    g->recwinlines=0;
134  }
135
136  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
137
138  /* create the new windows */
139  g->recwin=newwin(g->recwinlines, cols, 0, 0);
140  if (g->recwin==NULL) {
141    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n", g->recwinlines, cols);
142    endwin();
143    exit(50);
144  }
145     
146  g->sepwin=newwin(1, cols, g->recwinlines, 0);
147  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
148  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
149
150  owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols);
151
152  idlok(g->typwin, FALSE);
153  idlok(g->recwin, FALSE);
154  idlok(g->sepwin, FALSE);
155  idlok(g->msgwin, FALSE);
156
157  nodelay(g->typwin, 1);
158  keypad(g->typwin, TRUE);
159  wmove(g->typwin, 0, 0);
160
161  meta(g->typwin, TRUE);
162}
163
164owl_context *owl_global_get_context(owl_global *g) {
165  return(&g->ctx);
166}
167                         
168int owl_global_get_lines(owl_global *g) {
169  return(g->lines);
170}
171
172int owl_global_get_cols(owl_global *g) {
173  return(g->cols);
174}
175
176int owl_global_get_recwin_lines(owl_global *g) {
177  return(g->recwinlines);
178}
179
180/* curmsg */
181
182int owl_global_get_curmsg(owl_global *g) {
183  return(g->curmsg);
184}
185
186void owl_global_set_curmsg(owl_global *g, int i) {
187  g->curmsg=i;
188  /* we will reset the vertical offset from here */
189  /* we might want to move this out to the functions later */
190  owl_global_set_curmsg_vert_offset(g, 0);
191}
192
193/* topmsg */
194
195int owl_global_get_topmsg(owl_global *g) {
196  return(g->topmsg);
197}
198
199void owl_global_set_topmsg(owl_global *g, int i) {
200  g->topmsg=i;
201}
202
203/* windows */
204
205owl_mainwin *owl_global_get_mainwin(owl_global *g) {
206  return(&(g->mw));
207}
208
209owl_popwin *owl_global_get_popwin(owl_global *g) {
210  return(&(g->pw));
211}
212
213/* msglist */
214
215owl_messagelist *owl_global_get_msglist(owl_global *g) {
216  return(&(g->msglist));
217}
218
219/* keyhandler */
220
221owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
222  return(&(g->kh));
223}
224
225/* curses windows */
226
227WINDOW *owl_global_get_curs_recwin(owl_global *g) {
228  return(g->recwin);
229}
230
231WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
232  return(g->sepwin);
233}
234
235WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
236  return(g->msgwin);
237}
238
239WINDOW *owl_global_get_curs_typwin(owl_global *g) {
240  return(g->typwin);
241}
242
243/* typwin */
244
245owl_editwin *owl_global_get_typwin(owl_global *g) {
246  return(&(g->tw));
247}
248
249/* buffercommand */
250
251void owl_global_set_buffercommand(owl_global *g, char *command) {
252  owl_editwin_set_command(owl_global_get_typwin(g), command);
253}
254
255char *owl_global_get_buffercommand(owl_global *g) {
256  return owl_editwin_get_command(owl_global_get_typwin(g));
257}
258
259void owl_global_set_buffercallback(owl_global *g, void (*cb)(owl_editwin*)) {
260  owl_editwin_set_callback(owl_global_get_typwin(g), cb);
261}
262
263void (*owl_global_get_buffercallback(owl_global *g))(owl_editwin*) {
264  return owl_editwin_get_callback(owl_global_get_typwin(g));
265}
266
267/* refresh */
268
269int owl_global_is_needrefresh(owl_global *g) {
270  if (g->needrefresh==1) return(1);
271  return(0);
272}
273
274void owl_global_set_needrefresh(owl_global *g) {
275  g->needrefresh=1;
276}
277
278void owl_global_set_noneedrefresh(owl_global *g) {
279  g->needrefresh=0;
280}
281
282/* variable dictionary */
283
284owl_vardict *owl_global_get_vardict(owl_global *g) {
285  return &(g->vars);
286}
287
288/* command dictionary */
289
290owl_cmddict *owl_global_get_cmddict(owl_global *g) {
291  return &(g->cmds);
292}
293
294/* rightshift */
295
296void owl_global_set_rightshift(owl_global *g, int i) {
297  g->rightshift=i;
298}
299
300int owl_global_get_rightshift(owl_global *g) {
301  return(g->rightshift);
302}
303
304/* typwin */
305
306int owl_global_is_typwin_active(owl_global *g) {
307  if (g->typwinactive==1) return(1);
308  return(0);
309}
310
311void owl_global_set_typwin_active(owl_global *g) {
312  int d = owl_global_get_typewindelta(g);
313  if (d > 0)
314      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
315
316  g->typwinactive=1;
317}
318
319void owl_global_set_typwin_inactive(owl_global *g) {
320  int d = owl_global_get_typewindelta(g);
321  if (d > 0)
322      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
323
324  g->typwinactive=0;
325}
326
327/* resize */
328
329void owl_global_set_resize_pending(owl_global *g) {
330  g->resizepending=1;
331}
332
333char *owl_global_get_homedir(owl_global *g) {
334  if (g->homedir) return(g->homedir);
335  return("/");
336}
337
338char *owl_global_get_confdir(owl_global *g) {
339  if (g->confdir) return(g->confdir);
340  return("/");
341}
342
343/*
344 * Setting this also sets startupfile to confdir/startup
345 */
346void owl_global_set_confdir(owl_global *g, char *cd) {
347  free(g->confdir);
348  g->confdir = owl_strdup(cd);
349  free(g->startupfile);
350  g->startupfile = owl_sprintf("%s/startup", cd);
351}
352
353char *owl_global_get_startupfile(owl_global *g) {
354  if(g->startupfile) return(g->startupfile);
355  return("/");
356}
357
358int owl_global_get_direction(owl_global *g) {
359  return(g->direction);
360}
361
362void owl_global_set_direction_downwards(owl_global *g) {
363  g->direction=OWL_DIRECTION_DOWNWARDS;
364}
365
366void owl_global_set_direction_upwards(owl_global *g) {
367  g->direction=OWL_DIRECTION_UPWARDS;
368}
369
370/* perl stuff */
371
372void owl_global_set_perlinterp(owl_global *g, void *p) {
373  g->perl=p;
374}
375
376void *owl_global_get_perlinterp(owl_global *g) {
377  return(g->perl);
378}
379
380int owl_global_is_config_format(owl_global *g) {
381  if (g->config_format) return(1);
382  return(0);
383}
384
385void owl_global_set_config_format(owl_global *g, int state) {
386  if (state==1) {
387    g->config_format=1;
388  } else {
389    g->config_format=0;
390  }
391}
392
393void owl_global_set_have_config(owl_global *g) {
394  g->haveconfig=1;
395}
396
397void owl_global_set_no_have_config(owl_global *g) {
398  g->haveconfig=0;
399}
400
401int owl_global_have_config(owl_global *g) {
402  if (g->haveconfig) return(1);
403  return(0);
404}
405
406void owl_global_resize(owl_global *g, int x, int y) {
407  /* resize the screen.  If x or y is 0 use the terminal size */
408  struct winsize size;
409   
410  if (!g->resizepending) return;
411
412  /* delete the current windows */
413  delwin(g->recwin);
414  delwin(g->sepwin);
415  delwin(g->msgwin);
416  delwin(g->typwin);
417  if (!isendwin()) {
418    endwin();
419  }
420
421  refresh();
422
423  /* get the new size */
424  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
425  if (x==0) {
426    if (size.ws_row) {
427      g->lines=size.ws_row;
428    } else {
429      g->lines=LINES;
430    } 
431  } else {
432      g->lines=x;
433  }
434
435  if (y==0) {
436    if (size.ws_col) {
437      g->cols=size.ws_col;
438    } else {
439      g->cols=COLS;
440    } 
441  } else {
442    g->cols=y;
443  }
444
445#ifdef HAVE_RESIZETERM
446  resizeterm(size.ws_row, size.ws_col);
447#endif
448
449  /* re-initialize the windows */
450  _owl_global_setup_windows(g);
451
452  /* in case any styles rely on the current width */
453  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
454
455  /* recalculate the topmsg to make sure the current message is on
456   * screen */
457  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
458
459  /* refresh stuff */
460  g->needrefresh=1;
461  owl_mainwin_redisplay(&(g->mw));
462  sepbar(NULL);
463  owl_editwin_redisplay(&(g->tw), 0);
464  owl_function_full_redisplay(&g);
465
466  /* TODO: this should handle other forms of popwins */
467  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
468      && owl_global_get_viewwin(g)) {
469    owl_popwin_refresh(owl_global_get_popwin(g));
470    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
471  }
472
473  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
474  owl_function_makemsg("");
475  g->resizepending=0;
476}
477
478/* debug */
479
480int owl_global_is_debug_fast(owl_global *g) {
481  if (g->debug) return(1);
482  return(0);
483}
484
485/* starttime */
486
487time_t owl_global_get_starttime(owl_global *g) {
488  return(g->starttime);
489}
490
491time_t owl_global_get_runtime(owl_global *g) {
492  return(time(NULL)-g->starttime);
493}
494
495time_t owl_global_get_lastinputtime(owl_global *g) {
496  return(g->lastinputtime);
497}
498
499void owl_global_set_lastinputtime(owl_global *g, time_t time) {
500  g->lastinputtime = time;
501}
502
503time_t owl_global_get_idletime(owl_global *g) {
504  return(time(NULL)-g->lastinputtime);
505}
506
507void owl_global_get_runtime_string(owl_global *g, char *buff) {
508  time_t diff;
509
510  diff=time(NULL)-owl_global_get_starttime(g);
511
512  /* print something nicer later */   
513  sprintf(buff, "%i seconds", (int) diff);
514}
515
516char *owl_global_get_hostname(owl_global *g) {
517  if (g->thishost) return(g->thishost);
518  return("");
519}
520
521/* userclue */
522
523void owl_global_set_userclue(owl_global *g, int clue) {
524  g->userclue=clue;
525}
526
527void owl_global_add_userclue(owl_global *g, int clue) {
528  g->userclue|=clue;
529}
530
531int owl_global_get_userclue(owl_global *g) {
532  return(g->userclue);
533}
534
535int owl_global_is_userclue(owl_global *g, int clue) {
536  if (g->userclue & clue) return(1);
537  return(0);
538}
539
540/* viewwin */
541
542owl_viewwin *owl_global_get_viewwin(owl_global *g) {
543  return(&(g->vw));
544}
545
546
547/* vert offset */
548
549int owl_global_get_curmsg_vert_offset(owl_global *g) {
550  return(g->curmsg_vert_offset);
551}
552
553void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
554  g->curmsg_vert_offset=i;
555}
556
557/* startup args */
558
559void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
560  int i, len;
561
562  if (g->startupargs) owl_free(g->startupargs);
563 
564  len=0;
565  for (i=0; i<argc; i++) {
566    len+=strlen(argv[i])+5;
567  }
568  g->startupargs=owl_malloc(len+5);
569
570  strcpy(g->startupargs, "");
571  for (i=0; i<argc; i++) {
572    sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]);
573  }
574  g->startupargs[strlen(g->startupargs)-1]='\0';
575}
576
577char *owl_global_get_startupargs(owl_global *g) {
578  if (g->startupargs) return(g->startupargs);
579  return("");
580}
581
582/* history */
583
584owl_history *owl_global_get_msg_history(owl_global *g) {
585  return(&(g->msghist));
586}
587
588owl_history *owl_global_get_cmd_history(owl_global *g) {
589  return(&(g->cmdhist));
590}
591
592/* muxevents */
593
594owl_muxevents *owl_global_get_muxevents(owl_global *g) {
595  return(&(g->muxevents));
596}
597
598/* filterlist */
599
600owl_list *owl_global_get_filterlist(owl_global *g) {
601  return(&(g->filterlist));
602}
603
604owl_filter *owl_global_get_filter(owl_global *g, char *name) {
605  int i, j;
606  owl_filter *f;
607
608  j=owl_list_get_size(&(g->filterlist));
609  for (i=0; i<j; i++) {
610    f=owl_list_get_element(&(g->filterlist), i);
611    if (!strcmp(name, owl_filter_get_name(f))) {
612      return(f);
613    }
614  }
615  return(NULL);
616}
617
618void owl_global_add_filter(owl_global *g, owl_filter *f) {
619  owl_list_append_element(&(g->filterlist), f);
620}
621
622void owl_global_remove_filter(owl_global *g, char *name) {
623  int i, j;
624  owl_filter *f;
625
626  j=owl_list_get_size(&(g->filterlist));
627  for (i=0; i<j; i++) {
628    f=owl_list_get_element(&(g->filterlist), i);
629    if (!strcmp(name, owl_filter_get_name(f))) {
630      owl_filter_free(f);
631      owl_list_remove_element(&(g->filterlist), i);
632      break;
633    }
634  }
635}
636
637/* nextmsgid */
638
639int owl_global_get_nextmsgid(owl_global *g) {
640  return(g->nextmsgid++);
641}
642
643/* current view */
644
645owl_view *owl_global_get_current_view(owl_global *g) {
646  return(&(g->current_view));
647}
648
649/* has colors */
650
651int owl_global_get_hascolors(owl_global *g) {
652  if (g->hascolors) return(1);
653  return(0);
654}
655
656/* color pairs */
657
658int owl_global_get_colorpairs(owl_global *g) {
659  return(g->colorpairs);
660}
661
662owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
663  return(&(g->cpmgr));
664}
665
666/* puntlist */
667
668owl_list *owl_global_get_puntlist(owl_global *g) {
669  return(&(g->puntlist));
670}
671
672int owl_global_message_is_puntable(owl_global *g, owl_message *m) {
673  owl_list *pl;
674  int i, j;
675
676  pl=owl_global_get_puntlist(g);
677  j=owl_list_get_size(pl);
678  for (i=0; i<j; i++) {
679    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
680  }
681  return(0);
682}
683
684int owl_global_should_followlast(owl_global *g) {
685  owl_view *v;
686 
687  if (!owl_global_is__followlast(g)) return(0);
688 
689  v=owl_global_get_current_view(g);
690 
691  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
692  return(0);
693}
694
695int owl_global_is_search_active(owl_global *g) {
696  if (g->searchactive) return(1);
697  return(0);
698}
699
700void owl_global_set_search_active(owl_global *g, char *string) {
701  g->searchactive=1;
702  if (g->searchstring != NULL) owl_free(g->searchstring);
703  g->searchstring=owl_strdup(string);
704}
705
706void owl_global_set_search_inactive(owl_global *g) {
707  g->searchactive=0;
708}
709
710char *owl_global_get_search_string(owl_global *g) {
711  if (g->searchstring==NULL) return("");
712  return(g->searchstring);
713}
714
715void owl_global_set_newmsgproc_pid(owl_global *g, int i) {
716  g->newmsgproc_pid=i;
717}
718
719int owl_global_get_newmsgproc_pid(owl_global *g) {
720  return(g->newmsgproc_pid);
721}
722
723void owl_global_add_to_malloced(owl_global *g, int i) {
724  g->malloced+=i;
725}
726
727void owl_global_add_to_freed(owl_global *g, int i) {
728  g->freed+=1;
729}
730
731int owl_global_get_malloced(owl_global *g) {
732  return(g->malloced);
733}
734
735int owl_global_get_freed(owl_global *g) {
736  return(g->freed);
737}
738
739int owl_global_get_meminuse(owl_global *g) {
740  return(g->malloced-g->freed);
741}
742
743/* AIM stuff */
744
745int owl_global_is_aimloggedin(owl_global *g)
746{
747  if (g->aim_loggedin) return(1);
748  return(0);
749}
750
751char *owl_global_get_aim_screenname(owl_global *g)
752{
753  if (owl_global_is_aimloggedin(g)) {
754    return (g->aim_screenname);
755  }
756  return("");
757}
758
759char *owl_global_get_aim_screenname_for_filters(owl_global *g)
760{
761  if (owl_global_is_aimloggedin(g)) {
762    return (g->aim_screenname_for_filters);
763  }
764  return("");
765}
766
767void owl_global_set_aimloggedin(owl_global *g, char *screenname)
768{
769  char *sn_escaped, *quote;
770  g->aim_loggedin=1;
771  if (g->aim_screenname) owl_free(g->aim_screenname);
772  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
773  g->aim_screenname=owl_strdup(screenname);
774  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
775  quote = owl_getquoting(sn_escaped);
776  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
777  owl_free(sn_escaped);
778}
779
780void owl_global_set_aimnologgedin(owl_global *g)
781{
782  g->aim_loggedin=0;
783}
784
785int owl_global_is_doaimevents(owl_global *g)
786{
787  if (g->aim_doprocessing) return(1);
788  return(0);
789}
790
791void owl_global_set_doaimevents(owl_global *g)
792{
793  g->aim_doprocessing=1;
794}
795
796void owl_global_set_no_doaimevents(owl_global *g)
797{
798  g->aim_doprocessing=0;
799}
800
801aim_session_t *owl_global_get_aimsess(owl_global *g)
802{
803  return(&(g->aimsess));
804}
805
806aim_conn_t *owl_global_get_bosconn(owl_global *g)
807{
808  return(&(g->bosconn));
809}
810
811void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
812{
813  g->bosconn=*conn;
814}
815
816int owl_global_is_aimnop_time(owl_global *g)
817{
818  if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);
819  return(0);
820}
821
822void owl_global_aimnop_sent(owl_global *g)
823{
824  owl_timer_reset(&(g->aim_noop_timer));
825}
826
827owl_timer *owl_global_get_aim_login_timer(owl_global *g)
828{
829  return(&(g->aim_ignorelogin_timer));
830}
831
832/* message queue */
833
834void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
835{
836  owl_list_append_element(&(g->messagequeue), m);
837}
838
839/* pop off the first message and return it.  Return NULL if the queue
840 * is empty.  The caller should free the message after using it, if
841 * necessary.
842 */
843owl_message *owl_global_messagequeue_popmsg(owl_global *g)
844{
845  owl_message *out;
846
847  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
848  out=owl_list_get_element(&(g->messagequeue), 0);
849  owl_list_remove_element(&(g->messagequeue), 0);
850  return(out);
851}
852
853int owl_global_messagequeue_pending(owl_global *g)
854{
855  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
856  return(1);
857}
858
859owl_buddylist *owl_global_get_buddylist(owl_global *g)
860{
861  return(&(g->buddylist));
862}
863 
864/* style */
865
866/* Return the style with name 'name'.  If it does not exist return
867 * NULL */
868owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
869{
870  return owl_dict_find_element(&(g->styledict), name);
871}
872
873/* creates a list and fills it in with keys.  duplicates the keys,
874 * so they will need to be freed by the caller. */
875int owl_global_get_style_names(owl_global *g, owl_list *l) {
876  return owl_dict_get_keys(&(g->styledict), l);
877}
878
879void owl_global_add_style(owl_global *g, owl_style *s)
880{
881  /*
882   * If we're redefining the current style, make sure to update
883   * pointers to it.
884   */
885  if(g->current_view.style
886     && !strcmp(owl_style_get_name(g->current_view.style),
887                owl_style_get_name(s)))
888    g->current_view.style = s;
889  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
890                          s, (void(*)(void*))owl_style_free);
891}
892
893void owl_global_set_haveaim(owl_global *g)
894{
895  g->haveaim=1;
896}
897
898int owl_global_is_haveaim(owl_global *g)
899{
900  if (g->haveaim) return(1);
901  return(0);
902}
903
904void owl_global_set_havezephyr(owl_global *g)
905{
906  g->havezephyr=1;
907}
908
909int owl_global_is_havezephyr(owl_global *g)
910{
911  if (g->havezephyr) return(1);
912  return(0);
913}
914
915owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)
916{
917  return(&(g->aim_buddyinfo_timer));
918}
919
920owl_errqueue *owl_global_get_errqueue(owl_global *g)
921{
922  return(&(g->errqueue));
923}
924
925void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
926{
927  g->got_err_signal = signum;
928  if (siginfo) {
929    g->err_signal_info = *siginfo;
930  } else {
931    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
932  }
933}
934
935int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
936{
937  int signum;
938  if (siginfo && g->got_err_signal) {
939    *siginfo = g->err_signal_info;
940  } 
941  signum = g->got_err_signal;
942  g->got_err_signal = 0;
943  return signum;
944}
945
946owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)
947{
948  return(&(g->zephyr_buddycheck_timer));
949}
950
951owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
952{
953  return(&(g->zbuddies));
954}
955
956struct termios *owl_global_get_startup_tio(owl_global *g)
957{
958  return(&(g->startup_tio));
959}
960
961char * owl_global_intern(owl_global *g, char * string)
962{
963  return owl_obarray_insert(&(g->obarray), string);
964}
965
966owl_list *owl_global_get_dispatchlist(owl_global *g)
967{
968  return &(g->dispatchlist);
969}
Note: See TracBrowser for help on using the repository browser.