source: global.c @ 438409f

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 438409f was 07b59ea, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Maintain the cursor location with the context stack
  • Property mode set to 100644
File size: 21.1 KB
Line 
1#include <stdio.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <termios.h>
7#include <sys/ioctl.h>
8#include <time.h>
9#include "owl.h"
10#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
340int owl_global_get_rightshift(const owl_global *g) {
341  return(g->rightshift);
342}
343
344/* typwin */
345
346owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
347  int d;
348  d = owl_global_get_typewindelta(g);
349  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
350      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
351
352  if (g->typwin_erase_id) {
353    g_signal_handler_disconnect(owl_global_get_curs_typwin(g), g->typwin_erase_id);
354    g->typwin_erase_id = 0;
355  }
356
357  g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
358                          owl_global_get_typwin_lines(g),
359                          g->cols,
360                          style,
361                          hist);
362  return g->tw;
363}
364
365void owl_global_set_typwin_inactive(owl_global *g) {
366  int d = owl_global_get_typewindelta(g);
367  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
368      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
369
370  if (!g->typwin_erase_id) {
371    g->typwin_erase_id =
372      g_signal_connect(owl_global_get_curs_typwin(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
373  }
374  owl_window_dirty(owl_global_get_curs_typwin(g));
375
376  g->tw = NULL;
377}
378
379/* resize */
380
381void owl_global_set_resize_pending(owl_global *g) {
382  g->resizepending=1;
383}
384
385const char *owl_global_get_homedir(const owl_global *g) {
386  if (g->homedir) return(g->homedir);
387  return("/");
388}
389
390const char *owl_global_get_confdir(const owl_global *g) {
391  if (g->confdir) return(g->confdir);
392  return("/");
393}
394
395/*
396 * Setting this also sets startupfile to confdir/startup
397 */
398void owl_global_set_confdir(owl_global *g, const char *cd) {
399  owl_free(g->confdir);
400  g->confdir = owl_strdup(cd);
401  owl_free(g->startupfile);
402  g->startupfile = owl_sprintf("%s/startup", cd);
403}
404
405const char *owl_global_get_startupfile(const owl_global *g) {
406  if(g->startupfile) return(g->startupfile);
407  return("/");
408}
409
410int owl_global_get_direction(const owl_global *g) {
411  return(g->direction);
412}
413
414void owl_global_set_direction_downwards(owl_global *g) {
415  g->direction=OWL_DIRECTION_DOWNWARDS;
416}
417
418void owl_global_set_direction_upwards(owl_global *g) {
419  g->direction=OWL_DIRECTION_UPWARDS;
420}
421
422/* perl stuff */
423
424void owl_global_set_perlinterp(owl_global *g, void *p) {
425  g->perl=p;
426}
427
428void *owl_global_get_perlinterp(const owl_global *g) {
429  return(g->perl);
430}
431
432int owl_global_is_config_format(const owl_global *g) {
433  if (g->config_format) return(1);
434  return(0);
435}
436
437void owl_global_set_config_format(owl_global *g, int state) {
438  if (state==1) {
439    g->config_format=1;
440  } else {
441    g->config_format=0;
442  }
443}
444
445void owl_global_set_have_config(owl_global *g) {
446  g->haveconfig=1;
447}
448
449void owl_global_set_no_have_config(owl_global *g) {
450  g->haveconfig=0;
451}
452
453int owl_global_have_config(owl_global *g) {
454  if (g->haveconfig) return(1);
455  return(0);
456}
457
458/*
459 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
460 * fail.
461 */
462void owl_global_get_terminal_size(int *lines, int *cols) {
463  struct winsize size;
464  /* get the new size */
465  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
466  if (size.ws_row) {
467    *lines = size.ws_row;
468  } else {
469    *lines = LINES;
470  }
471
472  if (size.ws_col) {
473    *cols = size.ws_col;
474  } else {
475    *cols = COLS;
476  }
477}
478
479void owl_global_check_resize(owl_global *g) {
480  /* resize the screen.  If lines or cols is 0 use the terminal size */
481  if (!g->resizepending) return;
482  g->resizepending = 0;
483
484  owl_global_get_terminal_size(&g->lines, &g->cols);
485  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
486
487  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
488}
489
490/* debug */
491
492int owl_global_is_debug_fast(const owl_global *g) {
493  if (g->debug) return(1);
494  return(0);
495}
496
497/* starttime */
498
499time_t owl_global_get_starttime(const owl_global *g) {
500  return(g->starttime);
501}
502
503time_t owl_global_get_runtime(const owl_global *g) {
504  return(time(NULL)-g->starttime);
505}
506
507time_t owl_global_get_lastinputtime(const owl_global *g) {
508  return(g->lastinputtime);
509}
510
511void owl_global_set_lastinputtime(owl_global *g, time_t time) {
512  g->lastinputtime = time;
513}
514
515time_t owl_global_get_idletime(const owl_global *g) {
516  return(time(NULL)-g->lastinputtime);
517}
518
519const char *owl_global_get_hostname(const owl_global *g) {
520  if (g->thishost) return(g->thishost);
521  return("");
522}
523
524/* userclue */
525
526void owl_global_set_userclue(owl_global *g, int clue) {
527  g->userclue=clue;
528}
529
530void owl_global_add_userclue(owl_global *g, int clue) {
531  g->userclue|=clue;
532}
533
534int owl_global_get_userclue(const owl_global *g) {
535  return(g->userclue);
536}
537
538int owl_global_is_userclue(const owl_global *g, int clue) {
539  if (g->userclue & clue) return(1);
540  return(0);
541}
542
543/* viewwin */
544
545owl_viewwin *owl_global_get_viewwin(owl_global *g) {
546  return(&(g->vw));
547}
548
549
550/* vert offset */
551
552int owl_global_get_curmsg_vert_offset(const owl_global *g) {
553  return(g->curmsg_vert_offset);
554}
555
556void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
557  g->curmsg_vert_offset = i;
558  g_object_notify(G_OBJECT(g->gn), "curmsg-vert-offset");
559}
560
561/* startup args */
562
563void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
564  int i, len;
565
566  if (g->startupargs) owl_free(g->startupargs);
567 
568  len=0;
569  for (i=0; i<argc; i++) {
570    len+=strlen(argv[i])+5;
571  }
572  g->startupargs=owl_malloc(len+5);
573
574  strcpy(g->startupargs, "");
575  for (i=0; i<argc; i++) {
576    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
577  }
578  g->startupargs[strlen(g->startupargs)-1]='\0';
579}
580
581const char *owl_global_get_startupargs(const owl_global *g) {
582  if (g->startupargs) return(g->startupargs);
583  return("");
584}
585
586/* history */
587
588owl_history *owl_global_get_msg_history(owl_global *g) {
589  return(&(g->msghist));
590}
591
592owl_history *owl_global_get_cmd_history(owl_global *g) {
593  return(&(g->cmdhist));
594}
595
596/* filterlist */
597typedef struct _owl_global_filter_ent {         /* noproto */
598  owl_global *g;
599  owl_filter *f;
600} owl_global_filter_ent;
601
602owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
603  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
604  if (e) return e->f;
605  return NULL;
606}
607
608static void owl_global_delete_filter_ent(void *data)
609{
610  owl_global_filter_ent *e = data;
611  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
612  owl_filter_delete(e->f);
613  owl_free(e);
614}
615
616void owl_global_add_filter(owl_global *g, owl_filter *f) {
617  owl_global_filter_ent *e = owl_malloc(sizeof *e);
618  e->g = g;
619  e->f = f;
620
621  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
622                          e, owl_global_delete_filter_ent);
623  g->filterlist = g_list_append(g->filterlist, f);
624}
625
626void owl_global_remove_filter(owl_global *g, const char *name) {
627  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
628  if (e)
629    owl_global_delete_filter_ent(e);
630}
631
632/* nextmsgid */
633
634int owl_global_get_nextmsgid(owl_global *g) {
635  return(g->nextmsgid++);
636}
637
638/* current view */
639
640owl_view *owl_global_get_current_view(owl_global *g) {
641  return(&(g->current_view));
642}
643
644/* has colors */
645
646int owl_global_get_hascolors(const owl_global *g) {
647  if (g->hascolors) return(1);
648  return(0);
649}
650
651/* color pairs */
652
653int owl_global_get_colorpairs(const owl_global *g) {
654  return(g->colorpairs);
655}
656
657owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
658  return(&(g->cpmgr));
659}
660
661/* puntlist */
662
663owl_list *owl_global_get_puntlist(owl_global *g) {
664  return(&(g->puntlist));
665}
666
667int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
668  const owl_list *pl;
669  int i, j;
670
671  pl=owl_global_get_puntlist(g);
672  j=owl_list_get_size(pl);
673  for (i=0; i<j; i++) {
674    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
675  }
676  return(0);
677}
678
679int owl_global_should_followlast(owl_global *g) {
680  const owl_view *v;
681 
682  if (!owl_global_is__followlast(g)) return(0);
683 
684  v=owl_global_get_current_view(g);
685 
686  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
687  return(0);
688}
689
690int owl_global_is_search_active(const owl_global *g) {
691  if (owl_regex_is_set(&g->search_re)) return(1);
692  return(0);
693}
694
695void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
696  if (owl_regex_is_set(&g->search_re)) {
697    owl_regex_cleanup(&g->search_re);
698    owl_regex_init(&g->search_re);
699  }
700  if (re != NULL)
701    owl_regex_copy(re, &g->search_re);
702}
703
704const owl_regex *owl_global_get_search_re(const owl_global *g) {
705  return &g->search_re;
706}
707
708void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
709  g->newmsgproc_pid=i;
710}
711
712pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
713  return(g->newmsgproc_pid);
714}
715
716/* AIM stuff */
717
718int owl_global_is_aimloggedin(const owl_global *g)
719{
720  if (g->aim_loggedin) return(1);
721  return(0);
722}
723
724const char *owl_global_get_aim_screenname(const owl_global *g)
725{
726  if (owl_global_is_aimloggedin(g)) {
727    return (g->aim_screenname);
728  }
729  return("");
730}
731
732const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
733{
734  if (owl_global_is_aimloggedin(g)) {
735    return (g->aim_screenname_for_filters);
736  }
737  return("");
738}
739
740void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
741{
742  char *sn_escaped;
743  const char *quote;
744  g->aim_loggedin=1;
745  if (g->aim_screenname) owl_free(g->aim_screenname);
746  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
747  g->aim_screenname=owl_strdup(screenname);
748  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
749  quote = owl_getquoting(sn_escaped);
750  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
751  owl_free(sn_escaped);
752}
753
754void owl_global_set_aimnologgedin(owl_global *g)
755{
756  g->aim_loggedin=0;
757}
758
759int owl_global_is_doaimevents(const owl_global *g)
760{
761  if (g->aim_doprocessing) return(1);
762  return(0);
763}
764
765void owl_global_set_doaimevents(owl_global *g)
766{
767  g->aim_doprocessing=1;
768}
769
770void owl_global_set_no_doaimevents(owl_global *g)
771{
772  g->aim_doprocessing=0;
773}
774
775aim_session_t *owl_global_get_aimsess(owl_global *g)
776{
777  return(&(g->aimsess));
778}
779
780aim_conn_t *owl_global_get_bosconn(owl_global *g)
781{
782  return(&(g->bosconn));
783}
784
785void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
786{
787  g->bosconn=*conn;
788}
789
790/* message queue */
791
792void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
793{
794  g_queue_push_tail(g->messagequeue, m);
795}
796
797/* pop off the first message and return it.  Return NULL if the queue
798 * is empty.  The caller should free the message after using it, if
799 * necessary.
800 */
801owl_message *owl_global_messagequeue_popmsg(owl_global *g)
802{
803  owl_message *out;
804
805  if (g_queue_is_empty(g->messagequeue))
806    return NULL;
807  out = g_queue_pop_head(g->messagequeue);
808  return out;
809}
810
811int owl_global_messagequeue_pending(owl_global *g)
812{
813  return !g_queue_is_empty(g->messagequeue);
814}
815
816owl_buddylist *owl_global_get_buddylist(owl_global *g)
817{
818  return(&(g->buddylist));
819}
820 
821/* style */
822
823/* Return the style with name 'name'.  If it does not exist return
824 * NULL */
825const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
826{
827  return owl_dict_find_element(&(g->styledict), name);
828}
829
830/* creates a list and fills it in with keys.  duplicates the keys,
831 * so they will need to be freed by the caller. */
832int owl_global_get_style_names(const owl_global *g, owl_list *l) {
833  return owl_dict_get_keys(&(g->styledict), l);
834}
835
836void owl_global_add_style(owl_global *g, owl_style *s)
837{
838  /*
839   * If we're redefining the current style, make sure to update
840   * pointers to it.
841   */
842  if(g->current_view.style
843     && !strcmp(owl_style_get_name(g->current_view.style),
844                owl_style_get_name(s)))
845    g->current_view.style = s;
846  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
847                          s, (void (*)(void *))owl_style_delete);
848}
849
850void owl_global_set_haveaim(owl_global *g)
851{
852  g->haveaim=1;
853}
854
855int owl_global_is_haveaim(const owl_global *g)
856{
857  if (g->haveaim) return(1);
858  return(0);
859}
860
861void owl_global_set_ignore_aimlogin(owl_global *g)
862{
863    g->ignoreaimlogin = 1;
864}
865
866void owl_global_unset_ignore_aimlogin(owl_global *g)
867{
868    g->ignoreaimlogin = 0;
869}
870
871int owl_global_is_ignore_aimlogin(const owl_global *g)
872{
873    return g->ignoreaimlogin;
874}
875
876void owl_global_set_havezephyr(owl_global *g)
877{
878  g->havezephyr=1;
879}
880
881int owl_global_is_havezephyr(const owl_global *g)
882{
883  if (g->havezephyr) return(1);
884  return(0);
885}
886
887owl_errqueue *owl_global_get_errqueue(owl_global *g)
888{
889  return(&(g->errqueue));
890}
891
892void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
893{
894  g->got_err_signal = signum;
895  if (siginfo) {
896    g->err_signal_info = *siginfo;
897  } else {
898    siginfo_t si;
899    memset(&si, 0, sizeof(si));
900    g->err_signal_info = si;
901  }
902}
903
904int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
905{
906  int signum;
907  if (siginfo && g->got_err_signal) {
908    *siginfo = g->err_signal_info;
909  } 
910  signum = g->got_err_signal;
911  g->got_err_signal = 0;
912  return signum;
913}
914
915
916owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
917{
918  return(&(g->zbuddies));
919}
920
921GList **owl_global_get_zaldlist(owl_global *g)
922{
923  return &(g->zaldlist);
924}
925
926int owl_global_get_pseudologin_notify(owl_global *g)
927{
928  return g->pseudologin_notify;
929}
930
931void owl_global_set_pseudologin_notify(owl_global *g, int notify)
932{
933  g->pseudologin_notify = notify;
934}
935
936struct termios *owl_global_get_startup_tio(owl_global *g)
937{
938  return(&(g->startup_tio));
939}
940
941owl_list *owl_global_get_io_dispatch_list(owl_global *g)
942{
943  return &(g->io_dispatch_list);
944}
945
946owl_list *owl_global_get_psa_list(owl_global *g)
947{
948  return &(g->psa_list);
949}
950
951GList **owl_global_get_timerlist(owl_global *g)
952{
953  return &(g->timerlist);
954}
955
956int owl_global_is_interrupted(const owl_global *g) {
957  return g->interrupted;
958}
959
960void owl_global_set_interrupted(owl_global *g) {
961  g->interrupted = 1;
962}
963
964void owl_global_unset_interrupted(owl_global *g) {
965  g->interrupted = 0;
966}
Note: See TracBrowser for help on using the repository browser.