source: global.c @ 87833a8

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