source: global.c @ bbc31e4

Last change on this file since bbc31e4 was 0792d99, checked in by Anders Kaseorg <andersk@mit.edu>, 9 years ago
Replace deprecated GLib < 2.31.0 thread APIs As of GLib 2.31.0, - threading is now always enabled in GLib - libgthread is now an empty shell and g_thread_init() is no longer required (and has been deprecated) - simplified new thread creation API with the old API deprecated. The concept of joinability has disappeared (all threads are joinable) as have priority levels, 'bound'ness (ie: kernel vs. userspace threads) and ability to manipulate the stack size. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 21.3 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();
[0792d99]12#if !GLIB_CHECK_VERSION(2, 31, 0)
[3535a6e]13  g_thread_init(NULL);
[0792d99]14#endif
[0be3efd]15
[2c79eae]16  owl_select_init();
[0be3efd]17
[5cc7e5e]18  g->lines=LINES;
19  g->cols=COLS;
20  /* We shouldn't need this if we initialize lines and cols before the first
21   * owl_window_get_screen, but to be safe, we synchronize. */
22  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
23
[a999d9e]24  g->context_stack = NULL;
[07b59ea]25  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
[a999d9e]26
[7d4fbcd]27  g->curmsg=0;
28  g->topmsg=0;
[bd783db]29  g->markedmsgid=-1;
[a8938c7]30  g->startupargs=NULL;
[7d4fbcd]31
32  owl_variable_dict_setup(&(g->vars));
33
34  g->rightshift=0;
35
[03ca005]36  g->pw = NULL;
[9eb38bb]37  g->vw = NULL;
[38cc669]38  g->tw = NULL;
[7d4fbcd]39
40  owl_keyhandler_init(&g->kh);
41  owl_keys_setup_keymaps(&g->kh);
42
[129e609]43  owl_dict_create(&(g->filters));
44  g->filterlist = NULL;
[e6d7e4e]45  g->puntlist = g_ptr_array_new();
[20aced3]46  g->messagequeue = g_queue_new();
[f1e629d]47  owl_dict_create(&(g->styledict));
[7d4fbcd]48  g->curmsg_vert_offset=0;
49  g->resizepending=0;
50  g->direction=OWL_DIRECTION_DOWNWARDS;
[8fa9562]51  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
[7d4fbcd]52  g->debug=OWL_DEBUG;
[41c9a96]53  owl_regex_init(&g->search_re);
[7d4fbcd]54  g->starttime=time(NULL); /* assumes we call init only a start time */
[7f792c1]55  g->lastinputtime=g->starttime;
[700c712]56  g->newmsgproc_pid=0;
[61e79a9]57 
[7d4fbcd]58  owl_global_set_config_format(g, 0);
59  owl_global_set_no_have_config(g);
[10b866d]60  owl_history_init(&(g->msghist));
61  owl_history_init(&(g->cmdhist));
[7d4fbcd]62  g->nextmsgid=0;
63
64  /* Fill in some variables which don't have constant defaults */
[8510d5b]65
66  /* glib's g_get_home_dir prefers passwd entries to $HOME, so we
67   * explicitly check getenv first. */
68  homedir = getenv("HOME");
69  if (!homedir)
70    homedir = g_get_home_dir();
[d4927a7]71  g->homedir = g_strdup(homedir);
[7d4fbcd]72
[b363d83]73  g->confdir = NULL;
74  g->startupfile = NULL;
[dde1b4d]75  cd = g_build_filename(g->homedir, OWL_CONFIG_DIR, NULL);
[b363d83]76  owl_global_set_confdir(g, cd);
[ddbbcffa]77  g_free(cd);
[b363d83]78
[219f52c]79  g->msglist = owl_messagelist_new();
[571fab7]80
81  _owl_global_init_windows(g);
[d09e5a1]82
83  g->aim_screenname=NULL;
[81655f8]84  g->aim_screenname_for_filters=NULL;
[d09e5a1]85  g->aim_loggedin=0;
[aa5f725]86  owl_buddylist_init(&(g->buddylist));
[b7bb454]87
[09489b89]88  g->havezephyr=0;
89  g->haveaim=0;
[b7bb454]90  g->ignoreaimlogin=0;
[a352335c]91  owl_global_set_no_doaimevents(g);
[ec6ff52]92
93  owl_errqueue_init(&(g->errqueue));
[5a95b69]94
95  owl_zbuddylist_create(&(g->zbuddies));
[8e401cae]96
[f25812b]97  g->zaldlist = NULL;
98  g->pseudologin_notify = 0;
99
[a387d12e]100  owl_message_init_fmtext_cache();
[5f8ec6b]101  g->kill_buffer = NULL;
[47128d9]102
103  g->interrupt_count = 0;
[cb124fc6]104#if GLIB_CHECK_VERSION(2, 31, 0)
105  g_mutex_init(&g->interrupt_lock);
106#else
[47128d9]107  g->interrupt_lock = g_mutex_new();
[cb124fc6]108#endif
[571fab7]109}
110
111static void _owl_global_init_windows(owl_global *g)
112{
113  /* Create the main window */
114  owl_mainpanel_init(&(g->mainpanel));
115
116  /* Create the widgets */
[ab88b05]117  g->mw = owl_mainwin_new(g->mainpanel.recwin);
[571fab7]118  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
119  owl_sepbar_init(g->mainpanel.sepwin);
[0881cdd]120
[4dd115f]121  owl_window_set_default_cursor(g->mainpanel.sepwin);
[0881cdd]122
123  /* set up a pad for input */
124  g->input_pad = newpad(1, 1);
125  nodelay(g->input_pad, 1);
126  keypad(g->input_pad, 1);
127  meta(g->input_pad, 1);
[7d4fbcd]128}
129
[044f19f]130void owl_global_sepbar_dirty(owl_global *g)
131{
132  owl_window_dirty(g->mainpanel.sepwin);
133}
134
[eb6cedc]135/* Called once perl has been initialized */
136void owl_global_complete_setup(owl_global *g)
137{
138  owl_cmddict_setup(&(g->cmds));
139}
140
[005eae5]141owl_context *owl_global_get_context(const owl_global *g) {
[a999d9e]142  if (!g->context_stack)
143    return NULL;
144  return g->context_stack->data;
145}
146
[07b59ea]147static void owl_global_activate_context(owl_global *g, owl_context *c) {
148  if (!c)
[a999d9e]149    return;
150
[07b59ea]151  if (c->keymap) {
152    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
153      owl_function_error("Unable to activate keymap '%s'", c->keymap);
154    }
[a999d9e]155  }
[07b59ea]156  owl_window_set_cursor(c->cursor);
[7d4fbcd]157}
[a999d9e]158
[07b59ea]159void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
[a999d9e]160  owl_context *c;
[cb81570]161  c = owl_context_new(mode, data, keymap, cursor);
[1d74663]162  owl_global_push_context_obj(g, c);
163}
164
165void owl_global_push_context_obj(owl_global *g, owl_context *c)
166{
[a999d9e]167  g->context_stack = g_list_prepend(g->context_stack, c);
[07b59ea]168  owl_global_activate_context(g, owl_global_get_context(g));
[a999d9e]169}
170
[1d74663]171/* Pops the current context from the context stack and returns it. Caller is
172 * responsible for freeing. */
[6829afc]173CALLER_OWN owl_context *owl_global_pop_context_no_delete(owl_global *g)
[d427f08]174{
[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
[ab88b05]249owl_mainwin *owl_global_get_mainwin(owl_global *g)
250{
251  return g->mw;
[7d4fbcd]252}
253
254owl_popwin *owl_global_get_popwin(owl_global *g) {
[03ca005]255  return g->pw;
256}
257
258void owl_global_set_popwin(owl_global *g, owl_popwin *pw) {
259  g->pw = pw;
[7d4fbcd]260}
261
262/* msglist */
263
264owl_messagelist *owl_global_get_msglist(owl_global *g) {
[219f52c]265  return g->msglist;
[7d4fbcd]266}
267
268/* keyhandler */
269
270owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
271  return(&(g->kh));
272}
273
[005eae5]274/* Gets the currently active typwin out of the current context. */
[818f19c]275owl_editwin *owl_global_current_typwin(const owl_global *g) {
[005eae5]276  owl_context *ctx = owl_global_get_context(g);
[c394de8]277  return owl_editcontext_get_editwin(ctx);
[7d4fbcd]278}
279
280/* variable dictionary */
281
282owl_vardict *owl_global_get_vardict(owl_global *g) {
283  return &(g->vars);
284}
285
286/* command dictionary */
287
288owl_cmddict *owl_global_get_cmddict(owl_global *g) {
289  return &(g->cmds);
290}
291
292/* rightshift */
293
294void owl_global_set_rightshift(owl_global *g, int i) {
[5b80b87]295  g->rightshift = i;
[e92e2a1]296  owl_mainwin_redisplay(owl_global_get_mainwin(g));
[7d4fbcd]297}
298
[8742840]299int owl_global_get_rightshift(const owl_global *g) {
[7d4fbcd]300  return(g->rightshift);
301}
302
303/* typwin */
304
[58d47ca]305owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
[38cc669]306  int d;
307  d = owl_global_get_typewindelta(g);
[73eda8c]308  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
[da466e0]309      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
310
[f6fae8d]311  if (g->typwin_erase_id) {
[08263a8]312    g_signal_handler_disconnect(g->mainpanel.typwin, g->typwin_erase_id);
[f6fae8d]313    g->typwin_erase_id = 0;
314  }
315
[08263a8]316  g->tw = owl_editwin_new(g->mainpanel.typwin,
[38cc669]317                          owl_global_get_typwin_lines(g),
318                          g->cols,
319                          style,
320                          hist);
[58d47ca]321  return g->tw;
[7d4fbcd]322}
323
[fc5eef4]324void owl_global_deactivate_editcontext(owl_context *ctx) {
325  owl_global *g = ctx->cbdata;
326  owl_global_set_typwin_inactive(g);
327}
328
[7d4fbcd]329void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]330  int d = owl_global_get_typewindelta(g);
[73eda8c]331  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
[da466e0]332      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
333
[f6fae8d]334  if (!g->typwin_erase_id) {
335    g->typwin_erase_id =
[08263a8]336      g_signal_connect(g->mainpanel.typwin, "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
[f6fae8d]337  }
[08263a8]338  owl_window_dirty(g->mainpanel.typwin);
[f6fae8d]339
[c394de8]340  owl_editwin_unref(g->tw);
[38cc669]341  g->tw = NULL;
[7d4fbcd]342}
343
344/* resize */
345
346void owl_global_set_resize_pending(owl_global *g) {
[3535a6e]347  g->resizepending = true;
[7d4fbcd]348}
349
[8742840]350const char *owl_global_get_homedir(const owl_global *g) {
[a8938c7]351  if (g->homedir) return(g->homedir);
352  return("/");
[7d4fbcd]353}
354
[8742840]355const char *owl_global_get_confdir(const owl_global *g) {
[b363d83]356  if (g->confdir) return(g->confdir);
357  return("/");
358}
359
360/*
361 * Setting this also sets startupfile to confdir/startup
362 */
[e19eb97]363void owl_global_set_confdir(owl_global *g, const char *cd) {
[ddbbcffa]364  g_free(g->confdir);
[d4927a7]365  g->confdir = g_strdup(cd);
[ddbbcffa]366  g_free(g->startupfile);
[dde1b4d]367  g->startupfile = g_build_filename(cd, "startup", NULL);
[b363d83]368}
369
[8742840]370const char *owl_global_get_startupfile(const owl_global *g) {
[b363d83]371  if(g->startupfile) return(g->startupfile);
372  return("/");
373}
374
[8742840]375int owl_global_get_direction(const owl_global *g) {
[7d4fbcd]376  return(g->direction);
377}
378
379void owl_global_set_direction_downwards(owl_global *g) {
380  g->direction=OWL_DIRECTION_DOWNWARDS;
381}
382
383void owl_global_set_direction_upwards(owl_global *g) {
384  g->direction=OWL_DIRECTION_UPWARDS;
385}
386
387/* perl stuff */
388
389void owl_global_set_perlinterp(owl_global *g, void *p) {
390  g->perl=p;
391}
392
[8742840]393void *owl_global_get_perlinterp(const owl_global *g) {
[7d4fbcd]394  return(g->perl);
395}
396
[8742840]397int owl_global_is_config_format(const owl_global *g) {
[7d4fbcd]398  if (g->config_format) return(1);
399  return(0);
400}
401
402void owl_global_set_config_format(owl_global *g, int state) {
403  if (state==1) {
404    g->config_format=1;
405  } else {
406    g->config_format=0;
407  }
408}
409
410void owl_global_set_have_config(owl_global *g) {
411  g->haveconfig=1;
412}
413
414void owl_global_set_no_have_config(owl_global *g) {
415  g->haveconfig=0;
416}
417
418int owl_global_have_config(owl_global *g) {
419  if (g->haveconfig) return(1);
420  return(0);
421}
422
[285bc9a]423/*
424 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
425 * fail.
426 */
[d39f68c]427void owl_global_get_terminal_size(int *lines, int *cols) {
[285bc9a]428  struct winsize size;
429  /* get the new size */
430  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
431  if (size.ws_row) {
432    *lines = size.ws_row;
433  } else {
434    *lines = LINES;
435  }
436
437  if (size.ws_col) {
438    *cols = size.ws_col;
439  } else {
440    *cols = COLS;
441  }
442}
443
[99ce51c]444void owl_global_check_resize(owl_global *g) {
[3e0147f]445  /* resize the screen.  If lines or cols is 0 use the terminal size */
[7d4fbcd]446  if (!g->resizepending) return;
[3535a6e]447  g->resizepending = false;
[7d4fbcd]448
[99ce51c]449  owl_global_get_terminal_size(&g->lines, &g->cols);
[7a6e6c7]450  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
[7d4fbcd]451
[f9f88f3]452  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
[7d4fbcd]453}
454
455/* debug */
456
[8742840]457int owl_global_is_debug_fast(const owl_global *g) {
[7d4fbcd]458  if (g->debug) return(1);
459  return(0);
460}
461
462/* starttime */
463
[8742840]464time_t owl_global_get_starttime(const owl_global *g) {
[7d4fbcd]465  return(g->starttime);
466}
467
[8742840]468time_t owl_global_get_runtime(const owl_global *g) {
[7d4fbcd]469  return(time(NULL)-g->starttime);
470}
471
[8742840]472time_t owl_global_get_lastinputtime(const owl_global *g) {
[7f792c1]473  return(g->lastinputtime);
474}
475
[eebef19]476void owl_global_set_lastinputtime(owl_global *g, time_t time) {
477  g->lastinputtime = time;
[7f792c1]478}
479
[8742840]480time_t owl_global_get_idletime(const owl_global *g) {
[7f792c1]481  return(time(NULL)-g->lastinputtime);
482}
483
[7d4fbcd]484/* viewwin */
485
486owl_viewwin *owl_global_get_viewwin(owl_global *g) {
[9eb38bb]487  return g->vw;
488}
489
490void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) {
491  g->vw = vw;
[7d4fbcd]492}
493
494
495/* vert offset */
496
[8742840]497int owl_global_get_curmsg_vert_offset(const owl_global *g) {
[7d4fbcd]498  return(g->curmsg_vert_offset);
499}
500
501void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
[5b80b87]502  g->curmsg_vert_offset = i;
[7d4fbcd]503}
504
505/* startup args */
506
[d3941a0]507void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
[3b8a563]508  g_free(g->startupargs);
[d3941a0]509  g->startupargs = g_strjoinv(" ", argv);
[7d4fbcd]510}
511
[8742840]512const char *owl_global_get_startupargs(const owl_global *g) {
[a8938c7]513  if (g->startupargs) return(g->startupargs);
514  return("");
[7d4fbcd]515}
516
517/* history */
518
[10b866d]519owl_history *owl_global_get_msg_history(owl_global *g) {
520  return(&(g->msghist));
521}
522
523owl_history *owl_global_get_cmd_history(owl_global *g) {
524  return(&(g->cmdhist));
[7d4fbcd]525}
526
527/* filterlist */
[129e609]528typedef struct _owl_global_filter_ent {         /* noproto */
529  owl_global *g;
530  owl_filter *f;
531} owl_global_filter_ent;
[7d4fbcd]532
[8742840]533owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
[129e609]534  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
535  if (e) return e->f;
536  return NULL;
537}
[7d4fbcd]538
[5294cbf]539static void owl_global_delete_filter_ent(void *data)
540{
[129e609]541  owl_global_filter_ent *e = data;
542  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
543  owl_filter_delete(e->f);
[ddbbcffa]544  g_free(e);
[7d4fbcd]545}
546
547void owl_global_add_filter(owl_global *g, owl_filter *f) {
[96828e4]548  owl_global_filter_ent *e = g_new(owl_global_filter_ent, 1);
[129e609]549  e->g = g;
550  e->f = f;
551
552  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
[5294cbf]553                          e, owl_global_delete_filter_ent);
[129e609]554  g->filterlist = g_list_append(g->filterlist, f);
[7d4fbcd]555}
556
[e19eb97]557void owl_global_remove_filter(owl_global *g, const char *name) {
[129e609]558  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
559  if (e)
[5294cbf]560    owl_global_delete_filter_ent(e);
[7d4fbcd]561}
562
563/* nextmsgid */
564
565int owl_global_get_nextmsgid(owl_global *g) {
566  return(g->nextmsgid++);
567}
568
569/* current view */
570
571owl_view *owl_global_get_current_view(owl_global *g) {
572  return(&(g->current_view));
573}
574
[8fa9562]575owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
576  return(&(g->cpmgr));
577}
578
[7d4fbcd]579/* puntlist */
580
[e6d7e4e]581GPtrArray *owl_global_get_puntlist(owl_global *g) {
582  return g->puntlist;
[7d4fbcd]583}
584
[c08c70a]585int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
[e6d7e4e]586  const GPtrArray *pl;
587  int i;
[7d4fbcd]588
[e6d7e4e]589  pl = owl_global_get_puntlist(g);
590  for (i = 0; i < pl->len; i++) {
591    if (owl_filter_message_match(pl->pdata[i], m)) return 1;
[7d4fbcd]592  }
[e6d7e4e]593  return 0;
[7d4fbcd]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
[dc1edbd]678bool owl_global_is_doaimevents(const owl_global *g)
[a352335c]679{
[dc1edbd]680  return g->aim_event_source != NULL;
[a352335c]681}
682
683void owl_global_set_doaimevents(owl_global *g)
684{
[dc1edbd]685  if (g->aim_event_source)
686    return;
687  g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g));
688  g_source_attach(g->aim_event_source, NULL);
[a352335c]689}
690
691void owl_global_set_no_doaimevents(owl_global *g)
692{
[dc1edbd]693  if (!g->aim_event_source)
694    return;
695  g_source_destroy(g->aim_event_source);
696  g_source_unref(g->aim_event_source);
697  g->aim_event_source = NULL;
[a352335c]698}
699
[6a415e9]700aim_session_t *owl_global_get_aimsess(owl_global *g)
701{
[d09e5a1]702  return(&(g->aimsess));
703}
704
[c15bbfb]705aim_conn_t *owl_global_get_bosconn(owl_global *g)
706{
707  return(&(g->bosconn));
708}
709
710void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]711{
[c15bbfb]712  g->bosconn=*conn;
[d09e5a1]713}
714
715/* message queue */
716
[6a415e9]717void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
718{
[20aced3]719  g_queue_push_tail(g->messagequeue, m);
[d09e5a1]720}
721
722/* pop off the first message and return it.  Return NULL if the queue
723 * is empty.  The caller should free the message after using it, if
724 * necessary.
725 */
[2560529]726CALLER_OWN owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]727{
[d09e5a1]728  owl_message *out;
729
[20aced3]730  if (g_queue_is_empty(g->messagequeue))
731    return NULL;
732  out = g_queue_pop_head(g->messagequeue);
733  return out;
[d09e5a1]734}
735
[6a415e9]736int owl_global_messagequeue_pending(owl_global *g)
737{
[20aced3]738  return !g_queue_is_empty(g->messagequeue);
[d09e5a1]739}
[aa5f725]740
[6a415e9]741owl_buddylist *owl_global_get_buddylist(owl_global *g)
742{
[aa5f725]743  return(&(g->buddylist));
744}
745 
[bd3f232]746/* style */
747
748/* Return the style with name 'name'.  If it does not exist return
749 * NULL */
[8742840]750const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
[bd3f232]751{
[f1e629d]752  return owl_dict_find_element(&(g->styledict), name);
753}
754
[ce68f23]755CALLER_OWN GPtrArray *owl_global_get_style_names(const owl_global *g)
756{
757  return owl_dict_get_keys(&g->styledict);
[bd3f232]758}
759
[cf83b7a]760void owl_global_add_style(owl_global *g, owl_style *s)
761{
[f1fc47f]762  /*
763   * If we're redefining the current style, make sure to update
764   * pointers to it.
765   */
766  if(g->current_view.style
767     && !strcmp(owl_style_get_name(g->current_view.style),
768                owl_style_get_name(s)))
769    g->current_view.style = s;
770  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
[516c27e]771                          s, (void (*)(void *))owl_style_delete);
[bd3f232]772}
[cf83b7a]773
[09489b89]774void owl_global_set_haveaim(owl_global *g)
775{
776  g->haveaim=1;
777}
778
[8742840]779int owl_global_is_haveaim(const owl_global *g)
[09489b89]780{
781  if (g->haveaim) return(1);
782  return(0);
783}
784
[b7bb454]785void owl_global_set_ignore_aimlogin(owl_global *g)
786{
787    g->ignoreaimlogin = 1;
788}
789
790void owl_global_unset_ignore_aimlogin(owl_global *g)
791{
792    g->ignoreaimlogin = 0;
793}
794
[8742840]795int owl_global_is_ignore_aimlogin(const owl_global *g)
[b7bb454]796{
797    return g->ignoreaimlogin;
798}
799
[09489b89]800void owl_global_set_havezephyr(owl_global *g)
801{
802  g->havezephyr=1;
803}
804
[8742840]805int owl_global_is_havezephyr(const owl_global *g)
[09489b89]806{
807  if (g->havezephyr) return(1);
808  return(0);
809}
[de03334]810
[ec6ff52]811owl_errqueue *owl_global_get_errqueue(owl_global *g)
812{
813  return(&(g->errqueue));
814}
[c9e72d1]815
[5a95b69]816owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
817{
818  return(&(g->zbuddies));
819}
[8232149]820
[f25812b]821GList **owl_global_get_zaldlist(owl_global *g)
822{
823  return &(g->zaldlist);
824}
825
826int owl_global_get_pseudologin_notify(owl_global *g)
827{
828  return g->pseudologin_notify;
829}
830
831void owl_global_set_pseudologin_notify(owl_global *g, int notify)
832{
833  g->pseudologin_notify = notify;
834}
835
[8232149]836struct termios *owl_global_get_startup_tio(owl_global *g)
837{
838  return(&(g->startup_tio));
839}
[8e401cae]840
[04b16f8]841void owl_global_setup_default_filters(owl_global *g)
842{
843  int i;
844  static const struct {
845    const char *name;
846    const char *desc;
847  } filters[] = {
848    { "personal",
[efc460e]849      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
[04b16f8]850    { "trash",
851      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
852    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
853    { "ping", "opcode ^ping$" },
854    { "auto", "opcode ^auto$" },
855    { "login", "not login ^none$" },
[9078f69]856    { "reply-lockout", "class ^mail$" },
[04b16f8]857    { "out", "direction ^out$" },
858    { "aim", "type ^aim$" },
859    { "zephyr", "type ^zephyr$" },
860    { "none", "false" },
861    { "all", "true" },
862    { NULL, NULL }
863  };
864
865  owl_function_debugmsg("startup: creating default filters");
866
867  for (i = 0; filters[i].name != NULL; i++)
868    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
869                                                       filters[i].desc));
870}
[d12a8c7]871
872FILE *owl_global_get_debug_file_handle(owl_global *g) {
873  static char *open_file = NULL;
874  const char *filename = owl_global_get_debug_file(g);
875  if (g->debug_file == NULL ||
876      (open_file && strcmp(filename, open_file) != 0)) {
[26ad412]877    char *path;
[50522b5]878    int fd;
879
[d12a8c7]880    if (g->debug_file)
881      fclose(g->debug_file);
[50522b5]882
883    g->debug_file = NULL;
884
[3472845]885    path = g_strdup_printf("%s.%d", filename, getpid());
[26ad412]886    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
[ddbbcffa]887    g_free(path);
[26ad412]888
[50522b5]889    if (fd >= 0)
890      g->debug_file = fdopen(fd, "a");
[d12a8c7]891
[ddbbcffa]892    g_free(open_file);
[d4927a7]893    open_file = g_strdup(filename);
[d12a8c7]894  }
895  return g->debug_file;
896}
[5f8ec6b]897
[47e0a6a]898const char *owl_global_get_kill_buffer(owl_global *g) {
[5f8ec6b]899  return g->kill_buffer;
900}
901
[47e0a6a]902void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) {
903  g_free(g->kill_buffer);
904  g->kill_buffer = g_strndup(kill, len);
[5f8ec6b]905}
[47128d9]906
[c748e8a]907static GMutex *owl_global_get_interrupt_lock(owl_global *g)
908{
[cb124fc6]909#if GLIB_CHECK_VERSION(2, 31, 0)
910  return &g->interrupt_lock;
911#else
[c748e8a]912  return g->interrupt_lock;
[cb124fc6]913#endif
[c748e8a]914}
915
[47128d9]916void owl_global_add_interrupt(owl_global *g) {
917  /* TODO: This can almost certainly be done with atomic
918   * operations. Whatever. */
[c748e8a]919  g_mutex_lock(owl_global_get_interrupt_lock(g));
[47128d9]920  g->interrupt_count++;
[c748e8a]921  g_mutex_unlock(owl_global_get_interrupt_lock(g));
[47128d9]922}
923
924bool owl_global_take_interrupt(owl_global *g) {
925  bool ans = false;
[c748e8a]926  g_mutex_lock(owl_global_get_interrupt_lock(g));
[47128d9]927  if (g->interrupt_count > 0) {
928    ans = true;
929    g->interrupt_count--;
930  }
[c748e8a]931  g_mutex_unlock(owl_global_get_interrupt_lock(g));
[47128d9]932  return ans;
933}
Note: See TracBrowser for help on using the repository browser.