source: global.c @ 47128d9

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