source: global.c @ ad788b5

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