source: global.c @ 205e164

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 205e164 was d296c9a, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Merge branch 'owl_window' Conflicts: global.c
  • Property mode set to 100644
File size: 21.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
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->tw = NULL;
51
52  owl_keyhandler_init(&g->kh);
53  owl_keys_setup_keymaps(&g->kh);
54
55  owl_dict_create(&(g->filters));
56  g->filterlist = NULL;
57  owl_list_create(&(g->puntlist));
58  g->messagequeue = g_queue_new();
59  owl_dict_create(&(g->styledict));
60  g->curmsg_vert_offset=0;
61  g->resizepending=0;
62  g->direction=OWL_DIRECTION_DOWNWARDS;
63  g->zaway=0;
64  if (has_colors()) {
65    g->hascolors=1;
66  }
67  g->colorpairs=COLOR_PAIRS;
68  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
69  g->debug=OWL_DEBUG;
70  owl_regex_init(&g->search_re);
71  g->starttime=time(NULL); /* assumes we call init only a start time */
72  g->lastinputtime=g->starttime;
73  g->newmsgproc_pid=0;
74 
75  owl_global_set_config_format(g, 0);
76  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
77  owl_global_set_no_have_config(g);
78  owl_history_init(&(g->msghist));
79  owl_history_init(&(g->cmdhist));
80  owl_history_set_norepeats(&(g->cmdhist));
81  g->nextmsgid=0;
82
83  /* Fill in some variables which don't have constant defaults */
84  /* TODO: come back later and check passwd file first */
85  g->homedir=owl_strdup(getenv("HOME"));
86
87  g->confdir = NULL;
88  g->startupfile = NULL;
89  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
90  owl_global_set_confdir(g, cd);
91  owl_free(cd);
92
93  owl_messagelist_create(&(g->msglist));
94
95  _owl_global_init_windows(g);
96
97  g->aim_screenname=NULL;
98  g->aim_screenname_for_filters=NULL;
99  g->aim_loggedin=0;
100  owl_buddylist_init(&(g->buddylist));
101
102  g->havezephyr=0;
103  g->haveaim=0;
104  g->ignoreaimlogin=0;
105  owl_global_set_no_doaimevents(g);
106
107  owl_errqueue_init(&(g->errqueue));
108  g->got_err_signal=0;
109
110  owl_zbuddylist_create(&(g->zbuddies));
111
112  g->zaldlist = NULL;
113  g->pseudologin_notify = 0;
114
115  owl_message_init_fmtext_cache();
116  owl_list_create(&(g->io_dispatch_list));
117  owl_list_create(&(g->psa_list));
118  g->timerlist = NULL;
119  g->interrupted = FALSE;
120}
121
122static void _owl_global_init_windows(owl_global *g)
123{
124  /* Create the main window */
125  owl_mainpanel_init(&(g->mainpanel));
126
127  /* Create the widgets */
128  owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
129  owl_popwin_init(&(g->pw));
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
153/* If *pan does not exist, we create a new panel, otherwise we replace the
154   window in *pan with win.
155
156   libpanel PANEL objects cannot exist without owner a valid window. This
157   maintains the invariant for _owl_global_setup_windows. */
158void _owl_panel_set_window(PANEL **pan, WINDOW *win)
159{
160  WINDOW *oldwin;
161
162  if (win == NULL) {
163    owl_function_debugmsg("_owl_panel_set_window: passed NULL win (failed to allocate?)");
164    endwin();
165    exit(50);
166  }
167
168  if (*pan) {
169    oldwin = panel_window(*pan);
170    replace_panel(*pan, win);
171    delwin(oldwin);
172  } else {
173    *pan = new_panel(win);
174  }
175}
176
177owl_context *owl_global_get_context(owl_global *g) {
178  if (!g->context_stack)
179    return NULL;
180  return g->context_stack->data;
181}
182
183static void owl_global_activate_context(owl_global *g, owl_context *c) {
184  if (!c)
185    return;
186
187  if (c->keymap) {
188    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
189      owl_function_error("Unable to activate keymap '%s'", c->keymap);
190    }
191  }
192  owl_window_set_cursor(c->cursor);
193}
194
195void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
196  owl_context *c;
197  if (!(mode & OWL_CTX_MODE_BITS))
198    mode |= OWL_CTX_INTERACTIVE;
199  c = owl_malloc(sizeof *c);
200  c->mode = mode;
201  c->data = data;
202  c->cursor = cursor ? g_object_ref(cursor) : NULL;
203  c->keymap = owl_strdup(keymap);
204  g->context_stack = g_list_prepend(g->context_stack, c);
205  owl_global_activate_context(g, owl_global_get_context(g));
206}
207
208void owl_global_pop_context(owl_global *g) {
209  owl_context *c;
210  if (!g->context_stack)
211    return;
212  c = owl_global_get_context(g);
213  g->context_stack = g_list_delete_link(g->context_stack,
214                                        g->context_stack);
215  if (c->cursor)
216    g_object_unref(c->cursor);
217  owl_free(c->keymap);
218  owl_free(c);
219  owl_global_activate_context(g, owl_global_get_context(g));
220}
221
222int owl_global_get_lines(const owl_global *g) {
223  return(g->lines);
224}
225
226int owl_global_get_cols(const owl_global *g) {
227  return(g->cols);
228}
229
230int owl_global_get_recwin_lines(const owl_global *g) {
231  return g->mainpanel.recwinlines;
232}
233
234/* curmsg */
235
236int owl_global_get_curmsg(const owl_global *g) {
237  return(g->curmsg);
238}
239
240void owl_global_set_curmsg(owl_global *g, int i) {
241  g->curmsg=i;
242  /* we will reset the vertical offset from here */
243  /* we might want to move this out to the functions later */
244  owl_global_set_curmsg_vert_offset(g, 0);
245}
246
247/* topmsg */
248
249int owl_global_get_topmsg(const owl_global *g) {
250  return(g->topmsg);
251}
252
253void owl_global_set_topmsg(owl_global *g, int i) {
254  g->topmsg=i;
255}
256
257/* markedmsgid */
258
259int owl_global_get_markedmsgid(const owl_global *g) {
260  return(g->markedmsgid);
261}
262
263void owl_global_set_markedmsgid(owl_global *g, int i) {
264  g->markedmsgid=i;
265  /* i; index of message in the current view.
266  const owl_message *m;
267  owl_view *v;
268
269  v = owl_global_get_current_view(&g);
270  m = owl_view_get_element(v, i);
271  g->markedmsgid = m ? owl_message_get_id(m) : 0;
272  */
273}
274
275/* windows */
276
277owl_mainwin *owl_global_get_mainwin(owl_global *g) {
278  return(&(g->mw));
279}
280
281owl_popwin *owl_global_get_popwin(owl_global *g) {
282  return(&(g->pw));
283}
284
285/* msglist */
286
287owl_messagelist *owl_global_get_msglist(owl_global *g) {
288  return(&(g->msglist));
289}
290
291/* keyhandler */
292
293owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
294  return(&(g->kh));
295}
296
297/* underlying owl_windows */
298
299owl_window *owl_global_get_typwin_window(const owl_global *g) {
300  return g->mainpanel.typwin;
301}
302
303/* typwin */
304
305owl_editwin *owl_global_get_typwin(const owl_global *g) {
306  return(g->tw);
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/* userclue */
513
514void owl_global_set_userclue(owl_global *g, int clue) {
515  g->userclue=clue;
516}
517
518void owl_global_add_userclue(owl_global *g, int clue) {
519  g->userclue|=clue;
520}
521
522int owl_global_get_userclue(const owl_global *g) {
523  return(g->userclue);
524}
525
526int owl_global_is_userclue(const owl_global *g, int clue) {
527  if (g->userclue & clue) return(1);
528  return(0);
529}
530
531/* viewwin */
532
533owl_viewwin *owl_global_get_viewwin(owl_global *g) {
534  return(&(g->vw));
535}
536
537
538/* vert offset */
539
540int owl_global_get_curmsg_vert_offset(const owl_global *g) {
541  return(g->curmsg_vert_offset);
542}
543
544void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
545  g->curmsg_vert_offset = i;
546}
547
548/* startup args */
549
550void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
551  int i, len;
552
553  if (g->startupargs) owl_free(g->startupargs);
554 
555  len=0;
556  for (i=0; i<argc; i++) {
557    len+=strlen(argv[i])+5;
558  }
559  g->startupargs=owl_malloc(len+5);
560
561  strcpy(g->startupargs, "");
562  for (i=0; i<argc; i++) {
563    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
564  }
565  g->startupargs[strlen(g->startupargs)-1]='\0';
566}
567
568const char *owl_global_get_startupargs(const owl_global *g) {
569  if (g->startupargs) return(g->startupargs);
570  return("");
571}
572
573/* history */
574
575owl_history *owl_global_get_msg_history(owl_global *g) {
576  return(&(g->msghist));
577}
578
579owl_history *owl_global_get_cmd_history(owl_global *g) {
580  return(&(g->cmdhist));
581}
582
583/* filterlist */
584typedef struct _owl_global_filter_ent {         /* noproto */
585  owl_global *g;
586  owl_filter *f;
587} owl_global_filter_ent;
588
589owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
590  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
591  if (e) return e->f;
592  return NULL;
593}
594
595static void owl_global_delete_filter_ent(void *data)
596{
597  owl_global_filter_ent *e = data;
598  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
599  owl_filter_delete(e->f);
600  owl_free(e);
601}
602
603void owl_global_add_filter(owl_global *g, owl_filter *f) {
604  owl_global_filter_ent *e = owl_malloc(sizeof *e);
605  e->g = g;
606  e->f = f;
607
608  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
609                          e, owl_global_delete_filter_ent);
610  g->filterlist = g_list_append(g->filterlist, f);
611}
612
613void owl_global_remove_filter(owl_global *g, const char *name) {
614  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
615  if (e)
616    owl_global_delete_filter_ent(e);
617}
618
619/* nextmsgid */
620
621int owl_global_get_nextmsgid(owl_global *g) {
622  return(g->nextmsgid++);
623}
624
625/* current view */
626
627owl_view *owl_global_get_current_view(owl_global *g) {
628  return(&(g->current_view));
629}
630
631/* has colors */
632
633int owl_global_get_hascolors(const owl_global *g) {
634  if (g->hascolors) return(1);
635  return(0);
636}
637
638/* color pairs */
639
640int owl_global_get_colorpairs(const owl_global *g) {
641  return(g->colorpairs);
642}
643
644owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
645  return(&(g->cpmgr));
646}
647
648/* puntlist */
649
650owl_list *owl_global_get_puntlist(owl_global *g) {
651  return(&(g->puntlist));
652}
653
654int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
655  const owl_list *pl;
656  int i, j;
657
658  pl=owl_global_get_puntlist(g);
659  j=owl_list_get_size(pl);
660  for (i=0; i<j; i++) {
661    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
662  }
663  return(0);
664}
665
666int owl_global_should_followlast(owl_global *g) {
667  const owl_view *v;
668 
669  if (!owl_global_is__followlast(g)) return(0);
670 
671  v=owl_global_get_current_view(g);
672 
673  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
674  return(0);
675}
676
677int owl_global_is_search_active(const owl_global *g) {
678  if (owl_regex_is_set(&g->search_re)) return(1);
679  return(0);
680}
681
682void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
683  if (owl_regex_is_set(&g->search_re)) {
684    owl_regex_cleanup(&g->search_re);
685    owl_regex_init(&g->search_re);
686  }
687  if (re != NULL)
688    owl_regex_copy(re, &g->search_re);
689}
690
691const owl_regex *owl_global_get_search_re(const owl_global *g) {
692  return &g->search_re;
693}
694
695void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
696  g->newmsgproc_pid=i;
697}
698
699pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
700  return(g->newmsgproc_pid);
701}
702
703/* AIM stuff */
704
705int owl_global_is_aimloggedin(const owl_global *g)
706{
707  if (g->aim_loggedin) return(1);
708  return(0);
709}
710
711const char *owl_global_get_aim_screenname(const owl_global *g)
712{
713  if (owl_global_is_aimloggedin(g)) {
714    return (g->aim_screenname);
715  }
716  return("");
717}
718
719const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
720{
721  if (owl_global_is_aimloggedin(g)) {
722    return (g->aim_screenname_for_filters);
723  }
724  return("");
725}
726
727void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
728{
729  char *sn_escaped;
730  const char *quote;
731  g->aim_loggedin=1;
732  if (g->aim_screenname) owl_free(g->aim_screenname);
733  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
734  g->aim_screenname=owl_strdup(screenname);
735  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
736  quote = owl_getquoting(sn_escaped);
737  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
738  owl_free(sn_escaped);
739}
740
741void owl_global_set_aimnologgedin(owl_global *g)
742{
743  g->aim_loggedin=0;
744}
745
746int owl_global_is_doaimevents(const owl_global *g)
747{
748  if (g->aim_doprocessing) return(1);
749  return(0);
750}
751
752void owl_global_set_doaimevents(owl_global *g)
753{
754  g->aim_doprocessing=1;
755}
756
757void owl_global_set_no_doaimevents(owl_global *g)
758{
759  g->aim_doprocessing=0;
760}
761
762aim_session_t *owl_global_get_aimsess(owl_global *g)
763{
764  return(&(g->aimsess));
765}
766
767aim_conn_t *owl_global_get_bosconn(owl_global *g)
768{
769  return(&(g->bosconn));
770}
771
772void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
773{
774  g->bosconn=*conn;
775}
776
777/* message queue */
778
779void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
780{
781  g_queue_push_tail(g->messagequeue, m);
782}
783
784/* pop off the first message and return it.  Return NULL if the queue
785 * is empty.  The caller should free the message after using it, if
786 * necessary.
787 */
788owl_message *owl_global_messagequeue_popmsg(owl_global *g)
789{
790  owl_message *out;
791
792  if (g_queue_is_empty(g->messagequeue))
793    return NULL;
794  out = g_queue_pop_head(g->messagequeue);
795  return out;
796}
797
798int owl_global_messagequeue_pending(owl_global *g)
799{
800  return !g_queue_is_empty(g->messagequeue);
801}
802
803owl_buddylist *owl_global_get_buddylist(owl_global *g)
804{
805  return(&(g->buddylist));
806}
807 
808/* style */
809
810/* Return the style with name 'name'.  If it does not exist return
811 * NULL */
812const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
813{
814  return owl_dict_find_element(&(g->styledict), name);
815}
816
817/* creates a list and fills it in with keys.  duplicates the keys,
818 * so they will need to be freed by the caller. */
819int owl_global_get_style_names(const owl_global *g, owl_list *l) {
820  return owl_dict_get_keys(&(g->styledict), l);
821}
822
823void owl_global_add_style(owl_global *g, owl_style *s)
824{
825  /*
826   * If we're redefining the current style, make sure to update
827   * pointers to it.
828   */
829  if(g->current_view.style
830     && !strcmp(owl_style_get_name(g->current_view.style),
831                owl_style_get_name(s)))
832    g->current_view.style = s;
833  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
834                          s, (void (*)(void *))owl_style_delete);
835}
836
837void owl_global_set_haveaim(owl_global *g)
838{
839  g->haveaim=1;
840}
841
842int owl_global_is_haveaim(const owl_global *g)
843{
844  if (g->haveaim) return(1);
845  return(0);
846}
847
848void owl_global_set_ignore_aimlogin(owl_global *g)
849{
850    g->ignoreaimlogin = 1;
851}
852
853void owl_global_unset_ignore_aimlogin(owl_global *g)
854{
855    g->ignoreaimlogin = 0;
856}
857
858int owl_global_is_ignore_aimlogin(const owl_global *g)
859{
860    return g->ignoreaimlogin;
861}
862
863void owl_global_set_havezephyr(owl_global *g)
864{
865  g->havezephyr=1;
866}
867
868int owl_global_is_havezephyr(const owl_global *g)
869{
870  if (g->havezephyr) return(1);
871  return(0);
872}
873
874owl_errqueue *owl_global_get_errqueue(owl_global *g)
875{
876  return(&(g->errqueue));
877}
878
879void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
880{
881  g->got_err_signal = signum;
882  if (siginfo) {
883    g->err_signal_info = *siginfo;
884  } else {
885    siginfo_t si;
886    memset(&si, 0, sizeof(si));
887    g->err_signal_info = si;
888  }
889}
890
891int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
892{
893  int signum;
894  if (siginfo && g->got_err_signal) {
895    *siginfo = g->err_signal_info;
896  } 
897  signum = g->got_err_signal;
898  g->got_err_signal = 0;
899  return signum;
900}
901
902
903owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
904{
905  return(&(g->zbuddies));
906}
907
908GList **owl_global_get_zaldlist(owl_global *g)
909{
910  return &(g->zaldlist);
911}
912
913int owl_global_get_pseudologin_notify(owl_global *g)
914{
915  return g->pseudologin_notify;
916}
917
918void owl_global_set_pseudologin_notify(owl_global *g, int notify)
919{
920  g->pseudologin_notify = notify;
921}
922
923struct termios *owl_global_get_startup_tio(owl_global *g)
924{
925  return(&(g->startup_tio));
926}
927
928owl_list *owl_global_get_io_dispatch_list(owl_global *g)
929{
930  return &(g->io_dispatch_list);
931}
932
933owl_list *owl_global_get_psa_list(owl_global *g)
934{
935  return &(g->psa_list);
936}
937
938GList **owl_global_get_timerlist(owl_global *g)
939{
940  return &(g->timerlist);
941}
942
943int owl_global_is_interrupted(const owl_global *g) {
944  return g->interrupted;
945}
946
947void owl_global_set_interrupted(owl_global *g) {
948  g->interrupted = 1;
949}
950
951void owl_global_unset_interrupted(owl_global *g) {
952  g->interrupted = 0;
953}
954
955void owl_global_setup_default_filters(owl_global *g)
956{
957  int i;
958  static const struct {
959    const char *name;
960    const char *desc;
961  } filters[] = {
962    { "personal",
963      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
964    { "trash",
965      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
966    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
967    { "ping", "opcode ^ping$" },
968    { "auto", "opcode ^auto$" },
969    { "login", "not login ^none$" },
970    { "reply-lockout", "class ^noc or class ^mail$" },
971    { "out", "direction ^out$" },
972    { "aim", "type ^aim$" },
973    { "zephyr", "type ^zephyr$" },
974    { "none", "false" },
975    { "all", "true" },
976    { NULL, NULL }
977  };
978
979  owl_function_debugmsg("startup: creating default filters");
980
981  for (i = 0; filters[i].name != NULL; i++)
982    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
983                                                       filters[i].desc));
984}
Note: See TracBrowser for help on using the repository browser.