source: global.c @ f578d18

Last change on this file since f578d18 was f578d18, checked in by David Benjamin <davidben@mit.edu>, 13 years ago
Kill owl_global::psa_list It's not used anymore.
  • Property mode set to 100644
File size: 21.7 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));
[58d1f8a]112  g->timerlist = NULL;
[5f8ec6b]113  g->kill_buffer = NULL;
[37d188f]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) {
[ec9746d]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;
[ec9746d]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
[0af5f9d]698bool owl_global_is_doaimevents(const owl_global *g)
[a352335c]699{
[0af5f9d]700  return g->aim_event_source != NULL;
[a352335c]701}
702
703void owl_global_set_doaimevents(owl_global *g)
704{
[0af5f9d]705  if (g->aim_event_source)
706    return;
707  g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g));
708  g_source_attach(g->aim_event_source, NULL);
[a352335c]709}
710
711void owl_global_set_no_doaimevents(owl_global *g)
712{
[0af5f9d]713  if (!g->aim_event_source)
714    return;
715  g_source_destroy(g->aim_event_source);
716  g_source_unref(g->aim_event_source);
717  g->aim_event_source = NULL;
[a352335c]718}
719
[6a415e9]720aim_session_t *owl_global_get_aimsess(owl_global *g)
721{
[d09e5a1]722  return(&(g->aimsess));
723}
724
[c15bbfb]725aim_conn_t *owl_global_get_bosconn(owl_global *g)
726{
727  return(&(g->bosconn));
728}
729
730void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]731{
[c15bbfb]732  g->bosconn=*conn;
[d09e5a1]733}
734
735/* message queue */
736
[6a415e9]737void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
738{
[20aced3]739  g_queue_push_tail(g->messagequeue, m);
[d09e5a1]740}
741
742/* pop off the first message and return it.  Return NULL if the queue
743 * is empty.  The caller should free the message after using it, if
744 * necessary.
745 */
[13a3c1db]746owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]747{
[d09e5a1]748  owl_message *out;
749
[20aced3]750  if (g_queue_is_empty(g->messagequeue))
751    return NULL;
752  out = g_queue_pop_head(g->messagequeue);
753  return out;
[d09e5a1]754}
755
[6a415e9]756int owl_global_messagequeue_pending(owl_global *g)
757{
[20aced3]758  return !g_queue_is_empty(g->messagequeue);
[d09e5a1]759}
[aa5f725]760
[6a415e9]761owl_buddylist *owl_global_get_buddylist(owl_global *g)
762{
[aa5f725]763  return(&(g->buddylist));
764}
765 
[bd3f232]766/* style */
767
768/* Return the style with name 'name'.  If it does not exist return
769 * NULL */
[8742840]770const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
[bd3f232]771{
[f1e629d]772  return owl_dict_find_element(&(g->styledict), name);
773}
774
[8742840]775int owl_global_get_style_names(const owl_global *g, owl_list *l) {
[f1e629d]776  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]777}
778
[cf83b7a]779void owl_global_add_style(owl_global *g, owl_style *s)
780{
[f1fc47f]781  /*
782   * If we're redefining the current style, make sure to update
783   * pointers to it.
784   */
785  if(g->current_view.style
786     && !strcmp(owl_style_get_name(g->current_view.style),
787                owl_style_get_name(s)))
788    g->current_view.style = s;
789  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
[516c27e]790                          s, (void (*)(void *))owl_style_delete);
[bd3f232]791}
[cf83b7a]792
[09489b89]793void owl_global_set_haveaim(owl_global *g)
794{
795  g->haveaim=1;
796}
797
[8742840]798int owl_global_is_haveaim(const owl_global *g)
[09489b89]799{
800  if (g->haveaim) return(1);
801  return(0);
802}
803
[b7bb454]804void owl_global_set_ignore_aimlogin(owl_global *g)
805{
806    g->ignoreaimlogin = 1;
807}
808
809void owl_global_unset_ignore_aimlogin(owl_global *g)
810{
811    g->ignoreaimlogin = 0;
812}
813
[8742840]814int owl_global_is_ignore_aimlogin(const owl_global *g)
[b7bb454]815{
816    return g->ignoreaimlogin;
817}
818
[09489b89]819void owl_global_set_havezephyr(owl_global *g)
820{
821  g->havezephyr=1;
822}
823
[8742840]824int owl_global_is_havezephyr(const owl_global *g)
[09489b89]825{
826  if (g->havezephyr) return(1);
827  return(0);
828}
[de03334]829
[ec6ff52]830owl_errqueue *owl_global_get_errqueue(owl_global *g)
831{
832  return(&(g->errqueue));
833}
[c9e72d1]834
[5a95b69]835owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
836{
837  return(&(g->zbuddies));
838}
[8232149]839
[f25812b]840GList **owl_global_get_zaldlist(owl_global *g)
841{
842  return &(g->zaldlist);
843}
844
845int owl_global_get_pseudologin_notify(owl_global *g)
846{
847  return g->pseudologin_notify;
848}
849
850void owl_global_set_pseudologin_notify(owl_global *g, int notify)
851{
852  g->pseudologin_notify = notify;
853}
854
[8232149]855struct termios *owl_global_get_startup_tio(owl_global *g)
856{
857  return(&(g->startup_tio));
858}
[8e401cae]859
[df0138f]860owl_list *owl_global_get_io_dispatch_list(owl_global *g)
861{
862  return &(g->io_dispatch_list);
863}
864
[58d1f8a]865GList **owl_global_get_timerlist(owl_global *g)
[b7bb454]866{
[58d1f8a]867  return &(g->timerlist);
[b7bb454]868}
[adee9cc]869
[04b16f8]870void owl_global_setup_default_filters(owl_global *g)
871{
872  int i;
873  static const struct {
874    const char *name;
875    const char *desc;
876  } filters[] = {
877    { "personal",
[efc460e]878      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
[04b16f8]879    { "trash",
880      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
881    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
882    { "ping", "opcode ^ping$" },
883    { "auto", "opcode ^auto$" },
884    { "login", "not login ^none$" },
885    { "reply-lockout", "class ^noc or class ^mail$" },
886    { "out", "direction ^out$" },
887    { "aim", "type ^aim$" },
888    { "zephyr", "type ^zephyr$" },
889    { "none", "false" },
890    { "all", "true" },
891    { NULL, NULL }
892  };
893
894  owl_function_debugmsg("startup: creating default filters");
895
896  for (i = 0; filters[i].name != NULL; i++)
897    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
898                                                       filters[i].desc));
899}
[d12a8c7]900
901FILE *owl_global_get_debug_file_handle(owl_global *g) {
902  static char *open_file = NULL;
903  const char *filename = owl_global_get_debug_file(g);
904  if (g->debug_file == NULL ||
905      (open_file && strcmp(filename, open_file) != 0)) {
[26ad412]906    char *path;
[50522b5]907    int fd;
908
[d12a8c7]909    if (g->debug_file)
910      fclose(g->debug_file);
[50522b5]911
912    g->debug_file = NULL;
913
[3472845]914    path = g_strdup_printf("%s.%d", filename, getpid());
[26ad412]915    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
[ddbbcffa]916    g_free(path);
[26ad412]917
[50522b5]918    if (fd >= 0)
919      g->debug_file = fdopen(fd, "a");
[d12a8c7]920
[ddbbcffa]921    g_free(open_file);
[d4927a7]922    open_file = g_strdup(filename);
[d12a8c7]923  }
924  return g->debug_file;
925}
[5f8ec6b]926
[47e0a6a]927const char *owl_global_get_kill_buffer(owl_global *g) {
[5f8ec6b]928  return g->kill_buffer;
929}
930
[47e0a6a]931void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) {
932  g_free(g->kill_buffer);
933  g->kill_buffer = g_strndup(kill, len);
[5f8ec6b]934}
[37d188f]935
936void owl_global_add_interrupt(owl_global *g) {
937  /* TODO: This can almost certainly be done with atomic
938   * operations. Whatever. */
939  g_mutex_lock(g->interrupt_lock);
940  g->interrupt_count++;
941  g_mutex_unlock(g->interrupt_lock);
942}
943
944bool owl_global_take_interrupt(owl_global *g) {
945  bool ans = false;
946  g_mutex_lock(g->interrupt_lock);
947  if (g->interrupt_count > 0) {
948    ans = true;
949    g->interrupt_count--;
950  }
951  g_mutex_unlock(g->interrupt_lock);
952  return ans;
953}
Note: See TracBrowser for help on using the repository browser.