source: global.c @ ab88b05

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