source: global.c @ 2c79eae

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