source: global.c @ 1d74663

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 1d74663 was 1d74663, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Add deactivate and delete hooks for owl_context Also make pushing and popping slightly more flexible.
  • Property mode set to 100644
File size: 22.5 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
11#ifndef MAXHOSTNAMELEN
12#define MAXHOSTNAMELEN 256
13#endif
14
15static void _owl_global_init_windows(owl_global *g);
16
17void owl_global_init(owl_global *g) {
18  struct hostent *hent;
19  char hostname[MAXHOSTNAMELEN];
20  char *cd;
21
22  g_type_init();
23
24  gethostname(hostname, MAXHOSTNAMELEN);
25  hent=gethostbyname(hostname);
26  if (!hent) {
27    g->thishost=owl_strdup("localhost");
28  } else {
29    g->thishost=owl_strdup(hent->h_name);
30  }
31
32  g->lines=LINES;
33  g->cols=COLS;
34  /* We shouldn't need this if we initialize lines and cols before the first
35   * owl_window_get_screen, but to be safe, we synchronize. */
36  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
37
38  g->context_stack = NULL;
39  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
40
41  g->curmsg=0;
42  g->topmsg=0;
43  g->markedmsgid=-1;
44  g->startupargs=NULL;
45
46  owl_variable_dict_setup(&(g->vars));
47
48  g->rightshift=0;
49
50  g->pw = NULL;
51  g->vw = NULL;
52  g->tw = NULL;
53
54  owl_keyhandler_init(&g->kh);
55  owl_keys_setup_keymaps(&g->kh);
56
57  owl_dict_create(&(g->filters));
58  g->filterlist = NULL;
59  owl_list_create(&(g->puntlist));
60  g->messagequeue = g_queue_new();
61  owl_dict_create(&(g->styledict));
62  g->curmsg_vert_offset=0;
63  g->resizepending=0;
64  g->direction=OWL_DIRECTION_DOWNWARDS;
65  g->zaway=0;
66  if (has_colors()) {
67    g->hascolors=1;
68  }
69  g->colorpairs=COLOR_PAIRS;
70  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
71  g->debug=OWL_DEBUG;
72  owl_regex_init(&g->search_re);
73  g->starttime=time(NULL); /* assumes we call init only a start time */
74  g->lastinputtime=g->starttime;
75  g->newmsgproc_pid=0;
76 
77  owl_global_set_config_format(g, 0);
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_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
131  owl_sepbar_init(g->mainpanel.sepwin);
132
133  owl_window_set_default_cursor(g->mainpanel.sepwin);
134
135  /* set up a pad for input */
136  g->input_pad = newpad(1, 1);
137  nodelay(g->input_pad, 1);
138  keypad(g->input_pad, 1);
139  meta(g->input_pad, 1);
140}
141
142void owl_global_sepbar_dirty(owl_global *g)
143{
144  owl_window_dirty(g->mainpanel.sepwin);
145}
146
147/* Called once perl has been initialized */
148void owl_global_complete_setup(owl_global *g)
149{
150  owl_cmddict_setup(&(g->cmds));
151}
152
153owl_context *owl_global_get_context(const owl_global *g) {
154  if (!g->context_stack)
155    return NULL;
156  return g->context_stack->data;
157}
158
159static void owl_global_activate_context(owl_global *g, owl_context *c) {
160  if (!c)
161    return;
162
163  if (c->keymap) {
164    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
165      owl_function_error("Unable to activate keymap '%s'", c->keymap);
166    }
167  }
168  owl_window_set_cursor(c->cursor);
169}
170
171void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
172  owl_context *c;
173  if (!(mode & OWL_CTX_MODE_BITS))
174    mode |= OWL_CTX_INTERACTIVE;
175  c = owl_malloc(sizeof *c);
176  memset(c, 0, sizeof(*c));
177  c->mode = mode;
178  c->data = data;
179  c->cursor = cursor ? g_object_ref(cursor) : NULL;
180  c->keymap = owl_strdup(keymap);
181  owl_global_push_context_obj(g, c);
182}
183
184void owl_global_push_context_obj(owl_global *g, owl_context *c)
185{
186  g->context_stack = g_list_prepend(g->context_stack, c);
187  owl_global_activate_context(g, owl_global_get_context(g));
188}
189
190/* Pops the current context from the context stack and returns it. Caller is
191 * responsible for freeing. */
192owl_context *owl_global_pop_context_no_delete(owl_global *g) {
193  owl_context *c;
194  if (!g->context_stack)
195    return NULL;
196  c = owl_global_get_context(g);
197  owl_context_deactivate(c);
198  g->context_stack = g_list_delete_link(g->context_stack,
199                                        g->context_stack);
200  owl_global_activate_context(g, owl_global_get_context(g));
201  return c;
202}
203
204/* Pops the current context from the context stack and deletes it. */
205void owl_global_pop_context(owl_global *g) {
206  owl_context *c;
207  c = owl_global_pop_context_no_delete(g);
208  if (c)
209    owl_context_delete(c);
210}
211
212int owl_global_get_lines(const owl_global *g) {
213  return(g->lines);
214}
215
216int owl_global_get_cols(const owl_global *g) {
217  return(g->cols);
218}
219
220int owl_global_get_recwin_lines(const owl_global *g) {
221  return g->mainpanel.recwinlines;
222}
223
224/* curmsg */
225
226int owl_global_get_curmsg(const owl_global *g) {
227  return(g->curmsg);
228}
229
230void owl_global_set_curmsg(owl_global *g, int i) {
231  g->curmsg=i;
232  /* we will reset the vertical offset from here */
233  /* we might want to move this out to the functions later */
234  owl_global_set_curmsg_vert_offset(g, 0);
235}
236
237/* topmsg */
238
239int owl_global_get_topmsg(const owl_global *g) {
240  return(g->topmsg);
241}
242
243void owl_global_set_topmsg(owl_global *g, int i) {
244  g->topmsg=i;
245}
246
247/* markedmsgid */
248
249int owl_global_get_markedmsgid(const owl_global *g) {
250  return(g->markedmsgid);
251}
252
253void owl_global_set_markedmsgid(owl_global *g, int i) {
254  g->markedmsgid=i;
255  /* i; index of message in the current view.
256  const owl_message *m;
257  owl_view *v;
258
259  v = owl_global_get_current_view(&g);
260  m = owl_view_get_element(v, i);
261  g->markedmsgid = m ? owl_message_get_id(m) : 0;
262  */
263}
264
265/* windows */
266
267owl_mainwin *owl_global_get_mainwin(owl_global *g) {
268  return(&(g->mw));
269}
270
271owl_popwin *owl_global_get_popwin(owl_global *g) {
272  return g->pw;
273}
274
275void owl_global_set_popwin(owl_global *g, owl_popwin *pw) {
276  g->pw = pw;
277}
278
279/* msglist */
280
281owl_messagelist *owl_global_get_msglist(owl_global *g) {
282  return(&(g->msglist));
283}
284
285/* keyhandler */
286
287owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
288  return(&(g->kh));
289}
290
291/* underlying owl_windows */
292
293owl_window *owl_global_get_typwin_window(const owl_global *g) {
294  return g->mainpanel.typwin;
295}
296
297/* typwin */
298
299/* Gets the currently active typwin out of the current context. */
300owl_editwin *owl_global_current_typwin(const owl_global *g) {
301  owl_context *ctx = owl_global_get_context(g);
302  /* Get the current editwin from the context. */
303  if (ctx && owl_context_matches(ctx, OWL_CTX_TYPWIN)) {
304    return owl_context_get_data(ctx);
305  }
306  return NULL;
307}
308
309/* variable dictionary */
310
311owl_vardict *owl_global_get_vardict(owl_global *g) {
312  return &(g->vars);
313}
314
315/* command dictionary */
316
317owl_cmddict *owl_global_get_cmddict(owl_global *g) {
318  return &(g->cmds);
319}
320
321/* rightshift */
322
323void owl_global_set_rightshift(owl_global *g, int i) {
324  g->rightshift = i;
325  owl_mainwin_redisplay(owl_global_get_mainwin(g));
326}
327
328int owl_global_get_rightshift(const owl_global *g) {
329  return(g->rightshift);
330}
331
332/* typwin */
333
334owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
335  int d;
336  d = owl_global_get_typewindelta(g);
337  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
338      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
339
340  if (g->typwin_erase_id) {
341    g_signal_handler_disconnect(owl_global_get_typwin_window(g), g->typwin_erase_id);
342    g->typwin_erase_id = 0;
343  }
344
345  g->tw = owl_editwin_new(owl_global_get_typwin_window(g),
346                          owl_global_get_typwin_lines(g),
347                          g->cols,
348                          style,
349                          hist);
350  return g->tw;
351}
352
353void owl_global_set_typwin_inactive(owl_global *g) {
354  int d = owl_global_get_typewindelta(g);
355  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
356      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
357
358  if (!g->typwin_erase_id) {
359    g->typwin_erase_id =
360      g_signal_connect(owl_global_get_typwin_window(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
361  }
362  owl_window_dirty(owl_global_get_typwin_window(g));
363
364  g->tw = NULL;
365}
366
367/* resize */
368
369void owl_global_set_resize_pending(owl_global *g) {
370  g->resizepending=1;
371}
372
373const char *owl_global_get_homedir(const owl_global *g) {
374  if (g->homedir) return(g->homedir);
375  return("/");
376}
377
378const char *owl_global_get_confdir(const owl_global *g) {
379  if (g->confdir) return(g->confdir);
380  return("/");
381}
382
383/*
384 * Setting this also sets startupfile to confdir/startup
385 */
386void owl_global_set_confdir(owl_global *g, const char *cd) {
387  owl_free(g->confdir);
388  g->confdir = owl_strdup(cd);
389  owl_free(g->startupfile);
390  g->startupfile = owl_sprintf("%s/startup", cd);
391}
392
393const char *owl_global_get_startupfile(const owl_global *g) {
394  if(g->startupfile) return(g->startupfile);
395  return("/");
396}
397
398int owl_global_get_direction(const owl_global *g) {
399  return(g->direction);
400}
401
402void owl_global_set_direction_downwards(owl_global *g) {
403  g->direction=OWL_DIRECTION_DOWNWARDS;
404}
405
406void owl_global_set_direction_upwards(owl_global *g) {
407  g->direction=OWL_DIRECTION_UPWARDS;
408}
409
410/* perl stuff */
411
412void owl_global_set_perlinterp(owl_global *g, void *p) {
413  g->perl=p;
414}
415
416void *owl_global_get_perlinterp(const owl_global *g) {
417  return(g->perl);
418}
419
420int owl_global_is_config_format(const owl_global *g) {
421  if (g->config_format) return(1);
422  return(0);
423}
424
425void owl_global_set_config_format(owl_global *g, int state) {
426  if (state==1) {
427    g->config_format=1;
428  } else {
429    g->config_format=0;
430  }
431}
432
433void owl_global_set_have_config(owl_global *g) {
434  g->haveconfig=1;
435}
436
437void owl_global_set_no_have_config(owl_global *g) {
438  g->haveconfig=0;
439}
440
441int owl_global_have_config(owl_global *g) {
442  if (g->haveconfig) return(1);
443  return(0);
444}
445
446/*
447 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
448 * fail.
449 */
450void owl_global_get_terminal_size(int *lines, int *cols) {
451  struct winsize size;
452  /* get the new size */
453  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
454  if (size.ws_row) {
455    *lines = size.ws_row;
456  } else {
457    *lines = LINES;
458  }
459
460  if (size.ws_col) {
461    *cols = size.ws_col;
462  } else {
463    *cols = COLS;
464  }
465}
466
467void owl_global_check_resize(owl_global *g) {
468  /* resize the screen.  If lines or cols is 0 use the terminal size */
469  if (!g->resizepending) return;
470  g->resizepending = 0;
471
472  owl_global_get_terminal_size(&g->lines, &g->cols);
473  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
474
475  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
476}
477
478/* debug */
479
480int owl_global_is_debug_fast(const owl_global *g) {
481  if (g->debug) return(1);
482  return(0);
483}
484
485/* starttime */
486
487time_t owl_global_get_starttime(const owl_global *g) {
488  return(g->starttime);
489}
490
491time_t owl_global_get_runtime(const owl_global *g) {
492  return(time(NULL)-g->starttime);
493}
494
495time_t owl_global_get_lastinputtime(const owl_global *g) {
496  return(g->lastinputtime);
497}
498
499void owl_global_set_lastinputtime(owl_global *g, time_t time) {
500  g->lastinputtime = time;
501}
502
503time_t owl_global_get_idletime(const owl_global *g) {
504  return(time(NULL)-g->lastinputtime);
505}
506
507const char *owl_global_get_hostname(const owl_global *g) {
508  if (g->thishost) return(g->thishost);
509  return("");
510}
511
512/* viewwin */
513
514owl_viewwin *owl_global_get_viewwin(owl_global *g) {
515  return g->vw;
516}
517
518void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) {
519  g->vw = vw;
520}
521
522
523/* vert offset */
524
525int owl_global_get_curmsg_vert_offset(const owl_global *g) {
526  return(g->curmsg_vert_offset);
527}
528
529void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
530  g->curmsg_vert_offset = i;
531}
532
533/* startup args */
534
535void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
536  int i, len;
537
538  if (g->startupargs) owl_free(g->startupargs);
539 
540  len=0;
541  for (i=0; i<argc; i++) {
542    len+=strlen(argv[i])+5;
543  }
544  g->startupargs=owl_malloc(len+5);
545
546  strcpy(g->startupargs, "");
547  for (i=0; i<argc; i++) {
548    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
549  }
550  g->startupargs[strlen(g->startupargs)-1]='\0';
551}
552
553const char *owl_global_get_startupargs(const owl_global *g) {
554  if (g->startupargs) return(g->startupargs);
555  return("");
556}
557
558/* history */
559
560owl_history *owl_global_get_msg_history(owl_global *g) {
561  return(&(g->msghist));
562}
563
564owl_history *owl_global_get_cmd_history(owl_global *g) {
565  return(&(g->cmdhist));
566}
567
568/* filterlist */
569typedef struct _owl_global_filter_ent {         /* noproto */
570  owl_global *g;
571  owl_filter *f;
572} owl_global_filter_ent;
573
574owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
575  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
576  if (e) return e->f;
577  return NULL;
578}
579
580static void owl_global_delete_filter_ent(void *data)
581{
582  owl_global_filter_ent *e = data;
583  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
584  owl_filter_delete(e->f);
585  owl_free(e);
586}
587
588void owl_global_add_filter(owl_global *g, owl_filter *f) {
589  owl_global_filter_ent *e = owl_malloc(sizeof *e);
590  e->g = g;
591  e->f = f;
592
593  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
594                          e, owl_global_delete_filter_ent);
595  g->filterlist = g_list_append(g->filterlist, f);
596}
597
598void owl_global_remove_filter(owl_global *g, const char *name) {
599  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
600  if (e)
601    owl_global_delete_filter_ent(e);
602}
603
604/* nextmsgid */
605
606int owl_global_get_nextmsgid(owl_global *g) {
607  return(g->nextmsgid++);
608}
609
610/* current view */
611
612owl_view *owl_global_get_current_view(owl_global *g) {
613  return(&(g->current_view));
614}
615
616/* has colors */
617
618int owl_global_get_hascolors(const owl_global *g) {
619  if (g->hascolors) return(1);
620  return(0);
621}
622
623/* color pairs */
624
625int owl_global_get_colorpairs(const owl_global *g) {
626  return(g->colorpairs);
627}
628
629owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
630  return(&(g->cpmgr));
631}
632
633/* puntlist */
634
635owl_list *owl_global_get_puntlist(owl_global *g) {
636  return(&(g->puntlist));
637}
638
639int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
640  const owl_list *pl;
641  int i, j;
642
643  pl=owl_global_get_puntlist(g);
644  j=owl_list_get_size(pl);
645  for (i=0; i<j; i++) {
646    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
647  }
648  return(0);
649}
650
651int owl_global_should_followlast(owl_global *g) {
652  const owl_view *v;
653 
654  if (!owl_global_is__followlast(g)) return(0);
655 
656  v=owl_global_get_current_view(g);
657 
658  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
659  return(0);
660}
661
662int owl_global_is_search_active(const owl_global *g) {
663  if (owl_regex_is_set(&g->search_re)) return(1);
664  return(0);
665}
666
667void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
668  if (owl_regex_is_set(&g->search_re)) {
669    owl_regex_cleanup(&g->search_re);
670    owl_regex_init(&g->search_re);
671  }
672  if (re != NULL)
673    owl_regex_copy(re, &g->search_re);
674  /* TODO: Emit a signal so we don't depend on the viewwin here. */
675  if (owl_global_get_viewwin(g))
676    owl_viewwin_dirty(owl_global_get_viewwin(g));
677}
678
679const owl_regex *owl_global_get_search_re(const owl_global *g) {
680  return &g->search_re;
681}
682
683void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
684  g->newmsgproc_pid=i;
685}
686
687pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
688  return(g->newmsgproc_pid);
689}
690
691/* AIM stuff */
692
693int owl_global_is_aimloggedin(const owl_global *g)
694{
695  if (g->aim_loggedin) return(1);
696  return(0);
697}
698
699const char *owl_global_get_aim_screenname(const owl_global *g)
700{
701  if (owl_global_is_aimloggedin(g)) {
702    return (g->aim_screenname);
703  }
704  return("");
705}
706
707const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
708{
709  if (owl_global_is_aimloggedin(g)) {
710    return (g->aim_screenname_for_filters);
711  }
712  return("");
713}
714
715void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
716{
717  char *sn_escaped;
718  const char *quote;
719  g->aim_loggedin=1;
720  if (g->aim_screenname) owl_free(g->aim_screenname);
721  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
722  g->aim_screenname=owl_strdup(screenname);
723  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
724  quote = owl_getquoting(sn_escaped);
725  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
726  owl_free(sn_escaped);
727}
728
729void owl_global_set_aimnologgedin(owl_global *g)
730{
731  g->aim_loggedin=0;
732}
733
734int owl_global_is_doaimevents(const owl_global *g)
735{
736  if (g->aim_doprocessing) return(1);
737  return(0);
738}
739
740void owl_global_set_doaimevents(owl_global *g)
741{
742  g->aim_doprocessing=1;
743}
744
745void owl_global_set_no_doaimevents(owl_global *g)
746{
747  g->aim_doprocessing=0;
748}
749
750aim_session_t *owl_global_get_aimsess(owl_global *g)
751{
752  return(&(g->aimsess));
753}
754
755aim_conn_t *owl_global_get_bosconn(owl_global *g)
756{
757  return(&(g->bosconn));
758}
759
760void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
761{
762  g->bosconn=*conn;
763}
764
765/* message queue */
766
767void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
768{
769  g_queue_push_tail(g->messagequeue, m);
770}
771
772/* pop off the first message and return it.  Return NULL if the queue
773 * is empty.  The caller should free the message after using it, if
774 * necessary.
775 */
776owl_message *owl_global_messagequeue_popmsg(owl_global *g)
777{
778  owl_message *out;
779
780  if (g_queue_is_empty(g->messagequeue))
781    return NULL;
782  out = g_queue_pop_head(g->messagequeue);
783  return out;
784}
785
786int owl_global_messagequeue_pending(owl_global *g)
787{
788  return !g_queue_is_empty(g->messagequeue);
789}
790
791owl_buddylist *owl_global_get_buddylist(owl_global *g)
792{
793  return(&(g->buddylist));
794}
795 
796/* style */
797
798/* Return the style with name 'name'.  If it does not exist return
799 * NULL */
800const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
801{
802  return owl_dict_find_element(&(g->styledict), name);
803}
804
805/* creates a list and fills it in with keys.  duplicates the keys,
806 * so they will need to be freed by the caller. */
807int owl_global_get_style_names(const owl_global *g, owl_list *l) {
808  return owl_dict_get_keys(&(g->styledict), l);
809}
810
811void owl_global_add_style(owl_global *g, owl_style *s)
812{
813  /*
814   * If we're redefining the current style, make sure to update
815   * pointers to it.
816   */
817  if(g->current_view.style
818     && !strcmp(owl_style_get_name(g->current_view.style),
819                owl_style_get_name(s)))
820    g->current_view.style = s;
821  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
822                          s, (void (*)(void *))owl_style_delete);
823}
824
825void owl_global_set_haveaim(owl_global *g)
826{
827  g->haveaim=1;
828}
829
830int owl_global_is_haveaim(const owl_global *g)
831{
832  if (g->haveaim) return(1);
833  return(0);
834}
835
836void owl_global_set_ignore_aimlogin(owl_global *g)
837{
838    g->ignoreaimlogin = 1;
839}
840
841void owl_global_unset_ignore_aimlogin(owl_global *g)
842{
843    g->ignoreaimlogin = 0;
844}
845
846int owl_global_is_ignore_aimlogin(const owl_global *g)
847{
848    return g->ignoreaimlogin;
849}
850
851void owl_global_set_havezephyr(owl_global *g)
852{
853  g->havezephyr=1;
854}
855
856int owl_global_is_havezephyr(const owl_global *g)
857{
858  if (g->havezephyr) return(1);
859  return(0);
860}
861
862owl_errqueue *owl_global_get_errqueue(owl_global *g)
863{
864  return(&(g->errqueue));
865}
866
867void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
868{
869  g->got_err_signal = signum;
870  if (siginfo) {
871    g->err_signal_info = *siginfo;
872  } else {
873    siginfo_t si;
874    memset(&si, 0, sizeof(si));
875    g->err_signal_info = si;
876  }
877}
878
879int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
880{
881  int signum;
882  if (siginfo && g->got_err_signal) {
883    *siginfo = g->err_signal_info;
884  } 
885  signum = g->got_err_signal;
886  g->got_err_signal = 0;
887  return signum;
888}
889
890
891owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
892{
893  return(&(g->zbuddies));
894}
895
896GList **owl_global_get_zaldlist(owl_global *g)
897{
898  return &(g->zaldlist);
899}
900
901int owl_global_get_pseudologin_notify(owl_global *g)
902{
903  return g->pseudologin_notify;
904}
905
906void owl_global_set_pseudologin_notify(owl_global *g, int notify)
907{
908  g->pseudologin_notify = notify;
909}
910
911struct termios *owl_global_get_startup_tio(owl_global *g)
912{
913  return(&(g->startup_tio));
914}
915
916owl_list *owl_global_get_io_dispatch_list(owl_global *g)
917{
918  return &(g->io_dispatch_list);
919}
920
921owl_list *owl_global_get_psa_list(owl_global *g)
922{
923  return &(g->psa_list);
924}
925
926GList **owl_global_get_timerlist(owl_global *g)
927{
928  return &(g->timerlist);
929}
930
931int owl_global_is_interrupted(const owl_global *g) {
932  return g->interrupted;
933}
934
935void owl_global_set_interrupted(owl_global *g) {
936  g->interrupted = 1;
937}
938
939void owl_global_unset_interrupted(owl_global *g) {
940  g->interrupted = 0;
941}
942
943void owl_global_setup_default_filters(owl_global *g)
944{
945  int i;
946  static const struct {
947    const char *name;
948    const char *desc;
949  } filters[] = {
950    { "personal",
951      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
952    { "trash",
953      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
954    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
955    { "ping", "opcode ^ping$" },
956    { "auto", "opcode ^auto$" },
957    { "login", "not login ^none$" },
958    { "reply-lockout", "class ^noc or class ^mail$" },
959    { "out", "direction ^out$" },
960    { "aim", "type ^aim$" },
961    { "zephyr", "type ^zephyr$" },
962    { "none", "false" },
963    { "all", "true" },
964    { NULL, NULL }
965  };
966
967  owl_function_debugmsg("startup: creating default filters");
968
969  for (i = 0; filters[i].name != NULL; i++)
970    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
971                                                       filters[i].desc));
972}
973
974FILE *owl_global_get_debug_file_handle(owl_global *g) {
975  static char *open_file = NULL;
976  const char *filename = owl_global_get_debug_file(g);
977  if (g->debug_file == NULL ||
978      (open_file && strcmp(filename, open_file) != 0)) {
979    char *path;
980    int fd;
981
982    if (g->debug_file)
983      fclose(g->debug_file);
984
985    g->debug_file = NULL;
986
987    path = owl_sprintf("%s.%d", filename, getpid());
988    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
989    owl_free(path);
990
991    if (fd >= 0)
992      g->debug_file = fdopen(fd, "a");
993
994    owl_free(open_file);
995    open_file = owl_strdup(filename);
996  }
997  return g->debug_file;
998}
Note: See TracBrowser for help on using the repository browser.