source: global.c @ 4dd115f

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