source: global.c @ 2be605a

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