source: global.c @ 33b64f22

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