source: global.c @ e92e2a1

release-1.7release-1.8release-1.9
Last change on this file since e92e2a1 was e92e2a1, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Don't use a signal to connect rightshift While the signal is cleaner, rightshift should likely be a private property of owl_mainwin anyway. (Or at least a property of owl_view.) This is with the goal of removing the dependence on globalnotifier for the first iteration.
  • Property mode set to 100644
File size: 21.2 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
143/* Called once perl has been initialized */
144void owl_global_complete_setup(owl_global *g)
145{
146  owl_cmddict_setup(&(g->cmds));
147}
148
149/* If *pan does not exist, we create a new panel, otherwise we replace the
150   window in *pan with win.
151
152   libpanel PANEL objects cannot exist without owner a valid window. This
153   maintains the invariant for _owl_global_setup_windows. */
154void _owl_panel_set_window(PANEL **pan, WINDOW *win)
155{
156  WINDOW *oldwin;
157
158  if (win == NULL) {
159    owl_function_debugmsg("_owl_panel_set_window: passed NULL win (failed to allocate?)");
160    endwin();
161    exit(50);
162  }
163
164  if (*pan) {
165    oldwin = panel_window(*pan);
166    replace_panel(*pan, win);
167    delwin(oldwin);
168  } else {
169    *pan = new_panel(win);
170  }
171}
172
173owl_context *owl_global_get_context(owl_global *g) {
174  if (!g->context_stack)
175    return NULL;
176  return g->context_stack->data;
177}
178
179static void owl_global_activate_context(owl_global *g, owl_context *c) {
180  if (!c)
181    return;
182
183  if (c->keymap) {
184    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
185      owl_function_error("Unable to activate keymap '%s'", c->keymap);
186    }
187  }
188  owl_window_set_cursor(c->cursor);
189}
190
191void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
192  owl_context *c;
193  if (!(mode & OWL_CTX_MODE_BITS))
194    mode |= OWL_CTX_INTERACTIVE;
195  c = owl_malloc(sizeof *c);
196  c->mode = mode;
197  c->data = data;
198  c->cursor = cursor ? g_object_ref(cursor) : NULL;
199  c->keymap = owl_strdup(keymap);
200  g->context_stack = g_list_prepend(g->context_stack, c);
201  owl_global_activate_context(g, owl_global_get_context(g));
202}
203
204void owl_global_pop_context(owl_global *g) {
205  owl_context *c;
206  if (!g->context_stack)
207    return;
208  c = owl_global_get_context(g);
209  g->context_stack = g_list_delete_link(g->context_stack,
210                                        g->context_stack);
211  if (c->cursor)
212    g_object_unref(c->cursor);
213  owl_free(c->keymap);
214  owl_free(c);
215  owl_global_activate_context(g, owl_global_get_context(g));
216}
217
218int owl_global_get_lines(const owl_global *g) {
219  return(g->lines);
220}
221
222int owl_global_get_cols(const owl_global *g) {
223  return(g->cols);
224}
225
226int owl_global_get_recwin_lines(const owl_global *g) {
227  return g->mainpanel.recwinlines;
228}
229
230/* curmsg */
231
232int owl_global_get_curmsg(const owl_global *g) {
233  return(g->curmsg);
234}
235
236void owl_global_set_curmsg(owl_global *g, int i) {
237  g->curmsg=i;
238  g_object_notify(G_OBJECT(g->gn), "curmsg");
239  /* we will reset the vertical offset from here */
240  /* we might want to move this out to the functions later */
241  owl_global_set_curmsg_vert_offset(g, 0);
242}
243
244/* topmsg */
245
246int owl_global_get_topmsg(const owl_global *g) {
247  return(g->topmsg);
248}
249
250void owl_global_set_topmsg(owl_global *g, int i) {
251  g->topmsg=i;
252}
253
254/* markedmsgid */
255
256int owl_global_get_markedmsgid(const owl_global *g) {
257  return(g->markedmsgid);
258}
259
260void owl_global_set_markedmsgid(owl_global *g, int i) {
261  g->markedmsgid=i;
262  /* i; index of message in the current view.
263  const owl_message *m;
264  owl_view *v;
265
266  v = owl_global_get_current_view(&g);
267  m = owl_view_get_element(v, i);
268  g->markedmsgid = m ? owl_message_get_id(m) : 0;
269  */
270}
271
272/* windows */
273
274owl_mainwin *owl_global_get_mainwin(owl_global *g) {
275  return(&(g->mw));
276}
277
278owl_popwin *owl_global_get_popwin(owl_global *g) {
279  return(&(g->pw));
280}
281
282/* msglist */
283
284owl_messagelist *owl_global_get_msglist(owl_global *g) {
285  return(&(g->msglist));
286}
287
288/* keyhandler */
289
290owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
291  return(&(g->kh));
292}
293
294/* curses windows */
295
296owl_window *owl_global_get_curs_typwin(const owl_global *g) {
297  return g->mainpanel.typwin;
298}
299
300/* typwin */
301
302owl_editwin *owl_global_get_typwin(const owl_global *g) {
303  return(g->tw);
304}
305
306/* refresh */
307
308int owl_global_is_needrefresh(const owl_global *g) {
309  if (g->needrefresh==1) return(1);
310  return(0);
311}
312
313void owl_global_set_needrefresh(owl_global *g) {
314  g->needrefresh=1;
315}
316
317void owl_global_set_noneedrefresh(owl_global *g) {
318  g->needrefresh=0;
319}
320
321/* variable dictionary */
322
323owl_vardict *owl_global_get_vardict(owl_global *g) {
324  return &(g->vars);
325}
326
327/* command dictionary */
328
329owl_cmddict *owl_global_get_cmddict(owl_global *g) {
330  return &(g->cmds);
331}
332
333/* rightshift */
334
335void owl_global_set_rightshift(owl_global *g, int i) {
336  g->rightshift = i;
337  g_object_notify(G_OBJECT(g->gn), "rightshift");
338
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  g_object_notify(G_OBJECT(g->gn), "curmsg-vert-offset");
561}
562
563/* startup args */
564
565void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
566  int i, len;
567
568  if (g->startupargs) owl_free(g->startupargs);
569 
570  len=0;
571  for (i=0; i<argc; i++) {
572    len+=strlen(argv[i])+5;
573  }
574  g->startupargs=owl_malloc(len+5);
575
576  strcpy(g->startupargs, "");
577  for (i=0; i<argc; i++) {
578    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
579  }
580  g->startupargs[strlen(g->startupargs)-1]='\0';
581}
582
583const char *owl_global_get_startupargs(const owl_global *g) {
584  if (g->startupargs) return(g->startupargs);
585  return("");
586}
587
588/* history */
589
590owl_history *owl_global_get_msg_history(owl_global *g) {
591  return(&(g->msghist));
592}
593
594owl_history *owl_global_get_cmd_history(owl_global *g) {
595  return(&(g->cmdhist));
596}
597
598/* filterlist */
599typedef struct _owl_global_filter_ent {         /* noproto */
600  owl_global *g;
601  owl_filter *f;
602} owl_global_filter_ent;
603
604owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
605  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
606  if (e) return e->f;
607  return NULL;
608}
609
610static void owl_global_delete_filter_ent(void *data)
611{
612  owl_global_filter_ent *e = data;
613  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
614  owl_filter_delete(e->f);
615  owl_free(e);
616}
617
618void owl_global_add_filter(owl_global *g, owl_filter *f) {
619  owl_global_filter_ent *e = owl_malloc(sizeof *e);
620  e->g = g;
621  e->f = f;
622
623  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
624                          e, owl_global_delete_filter_ent);
625  g->filterlist = g_list_append(g->filterlist, f);
626}
627
628void owl_global_remove_filter(owl_global *g, const char *name) {
629  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
630  if (e)
631    owl_global_delete_filter_ent(e);
632}
633
634/* nextmsgid */
635
636int owl_global_get_nextmsgid(owl_global *g) {
637  return(g->nextmsgid++);
638}
639
640/* current view */
641
642owl_view *owl_global_get_current_view(owl_global *g) {
643  return(&(g->current_view));
644}
645
646/* has colors */
647
648int owl_global_get_hascolors(const owl_global *g) {
649  if (g->hascolors) return(1);
650  return(0);
651}
652
653/* color pairs */
654
655int owl_global_get_colorpairs(const owl_global *g) {
656  return(g->colorpairs);
657}
658
659owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
660  return(&(g->cpmgr));
661}
662
663/* puntlist */
664
665owl_list *owl_global_get_puntlist(owl_global *g) {
666  return(&(g->puntlist));
667}
668
669int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
670  const owl_list *pl;
671  int i, j;
672
673  pl=owl_global_get_puntlist(g);
674  j=owl_list_get_size(pl);
675  for (i=0; i<j; i++) {
676    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
677  }
678  return(0);
679}
680
681int owl_global_should_followlast(owl_global *g) {
682  const owl_view *v;
683 
684  if (!owl_global_is__followlast(g)) return(0);
685 
686  v=owl_global_get_current_view(g);
687 
688  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
689  return(0);
690}
691
692int owl_global_is_search_active(const owl_global *g) {
693  if (owl_regex_is_set(&g->search_re)) return(1);
694  return(0);
695}
696
697void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
698  if (owl_regex_is_set(&g->search_re)) {
699    owl_regex_cleanup(&g->search_re);
700    owl_regex_init(&g->search_re);
701  }
702  if (re != NULL)
703    owl_regex_copy(re, &g->search_re);
704}
705
706const owl_regex *owl_global_get_search_re(const owl_global *g) {
707  return &g->search_re;
708}
709
710void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
711  g->newmsgproc_pid=i;
712}
713
714pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
715  return(g->newmsgproc_pid);
716}
717
718/* AIM stuff */
719
720int owl_global_is_aimloggedin(const owl_global *g)
721{
722  if (g->aim_loggedin) return(1);
723  return(0);
724}
725
726const char *owl_global_get_aim_screenname(const owl_global *g)
727{
728  if (owl_global_is_aimloggedin(g)) {
729    return (g->aim_screenname);
730  }
731  return("");
732}
733
734const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
735{
736  if (owl_global_is_aimloggedin(g)) {
737    return (g->aim_screenname_for_filters);
738  }
739  return("");
740}
741
742void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
743{
744  char *sn_escaped;
745  const char *quote;
746  g->aim_loggedin=1;
747  if (g->aim_screenname) owl_free(g->aim_screenname);
748  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
749  g->aim_screenname=owl_strdup(screenname);
750  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
751  quote = owl_getquoting(sn_escaped);
752  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
753  owl_free(sn_escaped);
754}
755
756void owl_global_set_aimnologgedin(owl_global *g)
757{
758  g->aim_loggedin=0;
759}
760
761int owl_global_is_doaimevents(const owl_global *g)
762{
763  if (g->aim_doprocessing) return(1);
764  return(0);
765}
766
767void owl_global_set_doaimevents(owl_global *g)
768{
769  g->aim_doprocessing=1;
770}
771
772void owl_global_set_no_doaimevents(owl_global *g)
773{
774  g->aim_doprocessing=0;
775}
776
777aim_session_t *owl_global_get_aimsess(owl_global *g)
778{
779  return(&(g->aimsess));
780}
781
782aim_conn_t *owl_global_get_bosconn(owl_global *g)
783{
784  return(&(g->bosconn));
785}
786
787void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
788{
789  g->bosconn=*conn;
790}
791
792/* message queue */
793
794void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
795{
796  g_queue_push_tail(g->messagequeue, m);
797}
798
799/* pop off the first message and return it.  Return NULL if the queue
800 * is empty.  The caller should free the message after using it, if
801 * necessary.
802 */
803owl_message *owl_global_messagequeue_popmsg(owl_global *g)
804{
805  owl_message *out;
806
807  if (g_queue_is_empty(g->messagequeue))
808    return NULL;
809  out = g_queue_pop_head(g->messagequeue);
810  return out;
811}
812
813int owl_global_messagequeue_pending(owl_global *g)
814{
815  return !g_queue_is_empty(g->messagequeue);
816}
817
818owl_buddylist *owl_global_get_buddylist(owl_global *g)
819{
820  return(&(g->buddylist));
821}
822 
823/* style */
824
825/* Return the style with name 'name'.  If it does not exist return
826 * NULL */
827const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
828{
829  return owl_dict_find_element(&(g->styledict), name);
830}
831
832/* creates a list and fills it in with keys.  duplicates the keys,
833 * so they will need to be freed by the caller. */
834int owl_global_get_style_names(const owl_global *g, owl_list *l) {
835  return owl_dict_get_keys(&(g->styledict), l);
836}
837
838void owl_global_add_style(owl_global *g, owl_style *s)
839{
840  /*
841   * If we're redefining the current style, make sure to update
842   * pointers to it.
843   */
844  if(g->current_view.style
845     && !strcmp(owl_style_get_name(g->current_view.style),
846                owl_style_get_name(s)))
847    g->current_view.style = s;
848  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
849                          s, (void (*)(void *))owl_style_delete);
850}
851
852void owl_global_set_haveaim(owl_global *g)
853{
854  g->haveaim=1;
855}
856
857int owl_global_is_haveaim(const owl_global *g)
858{
859  if (g->haveaim) return(1);
860  return(0);
861}
862
863void owl_global_set_ignore_aimlogin(owl_global *g)
864{
865    g->ignoreaimlogin = 1;
866}
867
868void owl_global_unset_ignore_aimlogin(owl_global *g)
869{
870    g->ignoreaimlogin = 0;
871}
872
873int owl_global_is_ignore_aimlogin(const owl_global *g)
874{
875    return g->ignoreaimlogin;
876}
877
878void owl_global_set_havezephyr(owl_global *g)
879{
880  g->havezephyr=1;
881}
882
883int owl_global_is_havezephyr(const owl_global *g)
884{
885  if (g->havezephyr) return(1);
886  return(0);
887}
888
889owl_errqueue *owl_global_get_errqueue(owl_global *g)
890{
891  return(&(g->errqueue));
892}
893
894void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
895{
896  g->got_err_signal = signum;
897  if (siginfo) {
898    g->err_signal_info = *siginfo;
899  } else {
900    siginfo_t si;
901    memset(&si, 0, sizeof(si));
902    g->err_signal_info = si;
903  }
904}
905
906int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
907{
908  int signum;
909  if (siginfo && g->got_err_signal) {
910    *siginfo = g->err_signal_info;
911  } 
912  signum = g->got_err_signal;
913  g->got_err_signal = 0;
914  return signum;
915}
916
917
918owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
919{
920  return(&(g->zbuddies));
921}
922
923GList **owl_global_get_zaldlist(owl_global *g)
924{
925  return &(g->zaldlist);
926}
927
928int owl_global_get_pseudologin_notify(owl_global *g)
929{
930  return g->pseudologin_notify;
931}
932
933void owl_global_set_pseudologin_notify(owl_global *g, int notify)
934{
935  g->pseudologin_notify = notify;
936}
937
938struct termios *owl_global_get_startup_tio(owl_global *g)
939{
940  return(&(g->startup_tio));
941}
942
943owl_list *owl_global_get_io_dispatch_list(owl_global *g)
944{
945  return &(g->io_dispatch_list);
946}
947
948owl_list *owl_global_get_psa_list(owl_global *g)
949{
950  return &(g->psa_list);
951}
952
953GList **owl_global_get_timerlist(owl_global *g)
954{
955  return &(g->timerlist);
956}
957
958int owl_global_is_interrupted(const owl_global *g) {
959  return g->interrupted;
960}
961
962void owl_global_set_interrupted(owl_global *g) {
963  g->interrupted = 1;
964}
965
966void owl_global_unset_interrupted(owl_global *g) {
967  g->interrupted = 0;
968}
Note: See TracBrowser for help on using the repository browser.