source: global.c @ ec9746d

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