source: global.c @ 044f19f

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