source: global.c @ e20dd769

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