source: global.c @ 7b4f3be

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