source: global.c @ 5b68c05

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 5b68c05 was 5b68c05, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Update the viewwin when the global search string changes This will want to be made less hacky when we have some notification mechanism for all of owl_global's properties. Also, use the new owl_viewwin_dirty in internal functions to avoid dirtying a NULL window.
  • 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
11#ifndef MAXHOSTNAMELEN
12#define MAXHOSTNAMELEN 256
13#endif
14
[571fab7]15static void _owl_global_init_windows(owl_global *g);
16
[7d4fbcd]17void owl_global_init(owl_global *g) {
18  struct hostent *hent;
19  char hostname[MAXHOSTNAMELEN];
[ad15610]20  char *cd;
[7d4fbcd]21
[0be3efd]22  g_type_init();
23
[7d4fbcd]24  gethostname(hostname, MAXHOSTNAMELEN);
25  hent=gethostbyname(hostname);
26  if (!hent) {
[a8938c7]27    g->thishost=owl_strdup("localhost");
[7d4fbcd]28  } else {
[a8938c7]29    g->thishost=owl_strdup(hent->h_name);
[7d4fbcd]30  }
31
[5cc7e5e]32  g->lines=LINES;
33  g->cols=COLS;
34  /* We shouldn't need this if we initialize lines and cols before the first
35   * owl_window_get_screen, but to be safe, we synchronize. */
36  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
37
[a999d9e]38  g->context_stack = NULL;
[07b59ea]39  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
[a999d9e]40
[7d4fbcd]41  g->curmsg=0;
42  g->topmsg=0;
[bd783db]43  g->markedmsgid=-1;
[a8938c7]44  g->startupargs=NULL;
[7d4fbcd]45
46  owl_variable_dict_setup(&(g->vars));
47
48  g->rightshift=0;
49
[38cc669]50  g->tw = NULL;
[7d4fbcd]51
52  owl_keyhandler_init(&g->kh);
53  owl_keys_setup_keymaps(&g->kh);
54
[129e609]55  owl_dict_create(&(g->filters));
56  g->filterlist = NULL;
[7d4fbcd]57  owl_list_create(&(g->puntlist));
[20aced3]58  g->messagequeue = g_queue_new();
[f1e629d]59  owl_dict_create(&(g->styledict));
[7d4fbcd]60  g->curmsg_vert_offset=0;
61  g->resizepending=0;
62  g->direction=OWL_DIRECTION_DOWNWARDS;
63  g->zaway=0;
64  if (has_colors()) {
65    g->hascolors=1;
66  }
67  g->colorpairs=COLOR_PAIRS;
[8fa9562]68  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
[7d4fbcd]69  g->debug=OWL_DEBUG;
[41c9a96]70  owl_regex_init(&g->search_re);
[7d4fbcd]71  g->starttime=time(NULL); /* assumes we call init only a start time */
[7f792c1]72  g->lastinputtime=g->starttime;
[700c712]73  g->newmsgproc_pid=0;
[61e79a9]74 
[7d4fbcd]75  owl_global_set_config_format(g, 0);
76  owl_global_set_no_have_config(g);
[10b866d]77  owl_history_init(&(g->msghist));
78  owl_history_init(&(g->cmdhist));
[5a9f6fe]79  owl_history_set_norepeats(&(g->cmdhist));
[7d4fbcd]80  g->nextmsgid=0;
81
82  /* Fill in some variables which don't have constant defaults */
83  /* TODO: come back later and check passwd file first */
[a8938c7]84  g->homedir=owl_strdup(getenv("HOME"));
[7d4fbcd]85
[b363d83]86  g->confdir = NULL;
87  g->startupfile = NULL;
[ad15610]88  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
[b363d83]89  owl_global_set_confdir(g, cd);
90  owl_free(cd);
91
[7d4fbcd]92  owl_messagelist_create(&(g->msglist));
[571fab7]93
94  _owl_global_init_windows(g);
[d09e5a1]95
96  g->aim_screenname=NULL;
[81655f8]97  g->aim_screenname_for_filters=NULL;
[d09e5a1]98  g->aim_loggedin=0;
[aa5f725]99  owl_buddylist_init(&(g->buddylist));
[b7bb454]100
[09489b89]101  g->havezephyr=0;
102  g->haveaim=0;
[b7bb454]103  g->ignoreaimlogin=0;
[a352335c]104  owl_global_set_no_doaimevents(g);
[ec6ff52]105
106  owl_errqueue_init(&(g->errqueue));
[c9e72d1]107  g->got_err_signal=0;
[5a95b69]108
109  owl_zbuddylist_create(&(g->zbuddies));
[8e401cae]110
[f25812b]111  g->zaldlist = NULL;
112  g->pseudologin_notify = 0;
113
[a387d12e]114  owl_message_init_fmtext_cache();
[df0138f]115  owl_list_create(&(g->io_dispatch_list));
[4f2166b]116  owl_list_create(&(g->psa_list));
[58d1f8a]117  g->timerlist = NULL;
[adee9cc]118  g->interrupted = FALSE;
[571fab7]119}
120
121static void _owl_global_init_windows(owl_global *g)
122{
123  /* Create the main window */
124  owl_mainpanel_init(&(g->mainpanel));
125
126  /* Create the widgets */
127  owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
128  owl_popwin_init(&(g->pw));
129  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
130  owl_sepbar_init(g->mainpanel.sepwin);
[0881cdd]131
[4dd115f]132  owl_window_set_default_cursor(g->mainpanel.sepwin);
[0881cdd]133
134  /* set up a pad for input */
135  g->input_pad = newpad(1, 1);
136  nodelay(g->input_pad, 1);
137  keypad(g->input_pad, 1);
138  meta(g->input_pad, 1);
[7d4fbcd]139}
140
[044f19f]141void owl_global_sepbar_dirty(owl_global *g)
142{
143  owl_window_dirty(g->mainpanel.sepwin);
144}
145
[eb6cedc]146/* Called once perl has been initialized */
147void owl_global_complete_setup(owl_global *g)
148{
149  owl_cmddict_setup(&(g->cmds));
150}
151
[7d4fbcd]152owl_context *owl_global_get_context(owl_global *g) {
[a999d9e]153  if (!g->context_stack)
154    return NULL;
155  return g->context_stack->data;
156}
157
[07b59ea]158static void owl_global_activate_context(owl_global *g, owl_context *c) {
159  if (!c)
[a999d9e]160    return;
161
[07b59ea]162  if (c->keymap) {
163    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
164      owl_function_error("Unable to activate keymap '%s'", c->keymap);
165    }
[a999d9e]166  }
[07b59ea]167  owl_window_set_cursor(c->cursor);
[7d4fbcd]168}
[a999d9e]169
[07b59ea]170void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
[a999d9e]171  owl_context *c;
172  if (!(mode & OWL_CTX_MODE_BITS))
173    mode |= OWL_CTX_INTERACTIVE;
174  c = owl_malloc(sizeof *c);
175  c->mode = mode;
176  c->data = data;
[07b59ea]177  c->cursor = cursor ? g_object_ref(cursor) : NULL;
[a999d9e]178  c->keymap = owl_strdup(keymap);
179  g->context_stack = g_list_prepend(g->context_stack, c);
[07b59ea]180  owl_global_activate_context(g, owl_global_get_context(g));
[a999d9e]181}
182
183void owl_global_pop_context(owl_global *g) {
184  owl_context *c;
185  if (!g->context_stack)
186    return;
187  c = owl_global_get_context(g);
188  g->context_stack = g_list_delete_link(g->context_stack,
189                                        g->context_stack);
[07b59ea]190  if (c->cursor)
191    g_object_unref(c->cursor);
[a999d9e]192  owl_free(c->keymap);
193  owl_free(c);
[07b59ea]194  owl_global_activate_context(g, owl_global_get_context(g));
[a999d9e]195}
196
[8742840]197int owl_global_get_lines(const owl_global *g) {
[7d4fbcd]198  return(g->lines);
199}
200
[8742840]201int owl_global_get_cols(const owl_global *g) {
[7d4fbcd]202  return(g->cols);
203}
204
[8742840]205int owl_global_get_recwin_lines(const owl_global *g) {
[d2a4534]206  return g->mainpanel.recwinlines;
[7d4fbcd]207}
208
209/* curmsg */
210
[8742840]211int owl_global_get_curmsg(const owl_global *g) {
[7d4fbcd]212  return(g->curmsg);
213}
214
215void owl_global_set_curmsg(owl_global *g, int i) {
216  g->curmsg=i;
217  /* we will reset the vertical offset from here */
218  /* we might want to move this out to the functions later */
219  owl_global_set_curmsg_vert_offset(g, 0);
220}
221
222/* topmsg */
223
[8742840]224int owl_global_get_topmsg(const owl_global *g) {
[7d4fbcd]225  return(g->topmsg);
226}
227
228void owl_global_set_topmsg(owl_global *g, int i) {
229  g->topmsg=i;
230}
231
[70110286]232/* markedmsgid */
233
[8742840]234int owl_global_get_markedmsgid(const owl_global *g) {
[70110286]235  return(g->markedmsgid);
236}
237
238void owl_global_set_markedmsgid(owl_global *g, int i) {
239  g->markedmsgid=i;
240  /* i; index of message in the current view.
[c08c70a]241  const owl_message *m;
[70110286]242  owl_view *v;
243
244  v = owl_global_get_current_view(&g);
245  m = owl_view_get_element(v, i);
246  g->markedmsgid = m ? owl_message_get_id(m) : 0;
247  */
248}
249
[7d4fbcd]250/* windows */
251
252owl_mainwin *owl_global_get_mainwin(owl_global *g) {
253  return(&(g->mw));
254}
255
256owl_popwin *owl_global_get_popwin(owl_global *g) {
257  return(&(g->pw));
258}
259
260/* msglist */
261
262owl_messagelist *owl_global_get_msglist(owl_global *g) {
263  return(&(g->msglist));
264}
265
266/* keyhandler */
267
268owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
269  return(&(g->kh));
270}
271
[8bba1ae]272/* underlying owl_windows */
[7d4fbcd]273
[8bba1ae]274owl_window *owl_global_get_typwin_window(const owl_global *g) {
[f6fae8d]275  return g->mainpanel.typwin;
[7d4fbcd]276}
277
278/* typwin */
279
[8742840]280owl_editwin *owl_global_get_typwin(const owl_global *g) {
[a556caa]281  return(g->tw);
[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) {
[8bba1ae]316    g_signal_handler_disconnect(owl_global_get_typwin_window(g), g->typwin_erase_id);
[f6fae8d]317    g->typwin_erase_id = 0;
318  }
319
[8bba1ae]320  g->tw = owl_editwin_new(owl_global_get_typwin_window(g),
[38cc669]321                          owl_global_get_typwin_lines(g),
322                          g->cols,
323                          style,
324                          hist);
[58d47ca]325  return g->tw;
[7d4fbcd]326}
327
328void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]329  int d = owl_global_get_typewindelta(g);
[73eda8c]330  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
[da466e0]331      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
332
[f6fae8d]333  if (!g->typwin_erase_id) {
334    g->typwin_erase_id =
[8bba1ae]335      g_signal_connect(owl_global_get_typwin_window(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
[f6fae8d]336  }
[8bba1ae]337  owl_window_dirty(owl_global_get_typwin_window(g));
[f6fae8d]338
[38cc669]339  g->tw = NULL;
[7d4fbcd]340}
341
342/* resize */
343
344void owl_global_set_resize_pending(owl_global *g) {
345  g->resizepending=1;
346}
347
[8742840]348const char *owl_global_get_homedir(const owl_global *g) {
[a8938c7]349  if (g->homedir) return(g->homedir);
350  return("/");
[7d4fbcd]351}
352
[8742840]353const char *owl_global_get_confdir(const owl_global *g) {
[b363d83]354  if (g->confdir) return(g->confdir);
355  return("/");
356}
357
358/*
359 * Setting this also sets startupfile to confdir/startup
360 */
[e19eb97]361void owl_global_set_confdir(owl_global *g, const char *cd) {
[27f6487]362  owl_free(g->confdir);
[b363d83]363  g->confdir = owl_strdup(cd);
[27f6487]364  owl_free(g->startupfile);
[b363d83]365  g->startupfile = owl_sprintf("%s/startup", cd);
366}
367
[8742840]368const char *owl_global_get_startupfile(const owl_global *g) {
[b363d83]369  if(g->startupfile) return(g->startupfile);
370  return("/");
371}
372
[8742840]373int owl_global_get_direction(const owl_global *g) {
[7d4fbcd]374  return(g->direction);
375}
376
377void owl_global_set_direction_downwards(owl_global *g) {
378  g->direction=OWL_DIRECTION_DOWNWARDS;
379}
380
381void owl_global_set_direction_upwards(owl_global *g) {
382  g->direction=OWL_DIRECTION_UPWARDS;
383}
384
385/* perl stuff */
386
387void owl_global_set_perlinterp(owl_global *g, void *p) {
388  g->perl=p;
389}
390
[8742840]391void *owl_global_get_perlinterp(const owl_global *g) {
[7d4fbcd]392  return(g->perl);
393}
394
[8742840]395int owl_global_is_config_format(const owl_global *g) {
[7d4fbcd]396  if (g->config_format) return(1);
397  return(0);
398}
399
400void owl_global_set_config_format(owl_global *g, int state) {
401  if (state==1) {
402    g->config_format=1;
403  } else {
404    g->config_format=0;
405  }
406}
407
408void owl_global_set_have_config(owl_global *g) {
409  g->haveconfig=1;
410}
411
412void owl_global_set_no_have_config(owl_global *g) {
413  g->haveconfig=0;
414}
415
416int owl_global_have_config(owl_global *g) {
417  if (g->haveconfig) return(1);
418  return(0);
419}
420
[285bc9a]421/*
422 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
423 * fail.
424 */
[d39f68c]425void owl_global_get_terminal_size(int *lines, int *cols) {
[285bc9a]426  struct winsize size;
427  /* get the new size */
428  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
429  if (size.ws_row) {
430    *lines = size.ws_row;
431  } else {
432    *lines = LINES;
433  }
434
435  if (size.ws_col) {
436    *cols = size.ws_col;
437  } else {
438    *cols = COLS;
439  }
440}
441
[99ce51c]442void owl_global_check_resize(owl_global *g) {
[3e0147f]443  /* resize the screen.  If lines or cols is 0 use the terminal size */
[7d4fbcd]444  if (!g->resizepending) return;
[8479494]445  g->resizepending = 0;
[7d4fbcd]446
[99ce51c]447  owl_global_get_terminal_size(&g->lines, &g->cols);
[7a6e6c7]448  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
[7d4fbcd]449
[f9f88f3]450  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
[7d4fbcd]451}
452
453/* debug */
454
[8742840]455int owl_global_is_debug_fast(const owl_global *g) {
[7d4fbcd]456  if (g->debug) return(1);
457  return(0);
458}
459
460/* starttime */
461
[8742840]462time_t owl_global_get_starttime(const owl_global *g) {
[7d4fbcd]463  return(g->starttime);
464}
465
[8742840]466time_t owl_global_get_runtime(const owl_global *g) {
[7d4fbcd]467  return(time(NULL)-g->starttime);
468}
469
[8742840]470time_t owl_global_get_lastinputtime(const owl_global *g) {
[7f792c1]471  return(g->lastinputtime);
472}
473
[eebef19]474void owl_global_set_lastinputtime(owl_global *g, time_t time) {
475  g->lastinputtime = time;
[7f792c1]476}
477
[8742840]478time_t owl_global_get_idletime(const owl_global *g) {
[7f792c1]479  return(time(NULL)-g->lastinputtime);
480}
481
[8742840]482const char *owl_global_get_hostname(const owl_global *g) {
[a8938c7]483  if (g->thishost) return(g->thishost);
484  return("");
[61e79a9]485}
486
[7d4fbcd]487/* viewwin */
488
489owl_viewwin *owl_global_get_viewwin(owl_global *g) {
490  return(&(g->vw));
491}
492
493
494/* vert offset */
495
[8742840]496int owl_global_get_curmsg_vert_offset(const owl_global *g) {
[7d4fbcd]497  return(g->curmsg_vert_offset);
498}
499
500void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
[5b80b87]501  g->curmsg_vert_offset = i;
[7d4fbcd]502}
503
504/* startup args */
505
[e19eb97]506void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
[a8938c7]507  int i, len;
508
509  if (g->startupargs) owl_free(g->startupargs);
510 
511  len=0;
512  for (i=0; i<argc; i++) {
[591e6aa7]513    len+=strlen(argv[i])+5;
[a8938c7]514  }
[34509d5]515  g->startupargs=owl_malloc(len+5);
[7d4fbcd]516
517  strcpy(g->startupargs, "");
518  for (i=0; i<argc; i++) {
[b9cb41b]519    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
[7d4fbcd]520  }
521  g->startupargs[strlen(g->startupargs)-1]='\0';
522}
523
[8742840]524const char *owl_global_get_startupargs(const owl_global *g) {
[a8938c7]525  if (g->startupargs) return(g->startupargs);
526  return("");
[7d4fbcd]527}
528
529/* history */
530
[10b866d]531owl_history *owl_global_get_msg_history(owl_global *g) {
532  return(&(g->msghist));
533}
534
535owl_history *owl_global_get_cmd_history(owl_global *g) {
536  return(&(g->cmdhist));
[7d4fbcd]537}
538
539/* filterlist */
[129e609]540typedef struct _owl_global_filter_ent {         /* noproto */
541  owl_global *g;
542  owl_filter *f;
543} owl_global_filter_ent;
[7d4fbcd]544
[8742840]545owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
[129e609]546  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
547  if (e) return e->f;
548  return NULL;
549}
[7d4fbcd]550
[5294cbf]551static void owl_global_delete_filter_ent(void *data)
552{
[129e609]553  owl_global_filter_ent *e = data;
554  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
555  owl_filter_delete(e->f);
556  owl_free(e);
[7d4fbcd]557}
558
559void owl_global_add_filter(owl_global *g, owl_filter *f) {
[129e609]560  owl_global_filter_ent *e = owl_malloc(sizeof *e);
561  e->g = g;
562  e->f = f;
563
564  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
[5294cbf]565                          e, owl_global_delete_filter_ent);
[129e609]566  g->filterlist = g_list_append(g->filterlist, f);
[7d4fbcd]567}
568
[e19eb97]569void owl_global_remove_filter(owl_global *g, const char *name) {
[129e609]570  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
571  if (e)
[5294cbf]572    owl_global_delete_filter_ent(e);
[7d4fbcd]573}
574
575/* nextmsgid */
576
577int owl_global_get_nextmsgid(owl_global *g) {
578  return(g->nextmsgid++);
579}
580
581/* current view */
582
583owl_view *owl_global_get_current_view(owl_global *g) {
584  return(&(g->current_view));
585}
586
587/* has colors */
588
[8742840]589int owl_global_get_hascolors(const owl_global *g) {
[7d4fbcd]590  if (g->hascolors) return(1);
591  return(0);
592}
593
594/* color pairs */
595
[8742840]596int owl_global_get_colorpairs(const owl_global *g) {
[7d4fbcd]597  return(g->colorpairs);
598}
599
[8fa9562]600owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
601  return(&(g->cpmgr));
602}
603
[7d4fbcd]604/* puntlist */
605
606owl_list *owl_global_get_puntlist(owl_global *g) {
607  return(&(g->puntlist));
608}
609
[c08c70a]610int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
[77bced3]611  const owl_list *pl;
[7d4fbcd]612  int i, j;
613
614  pl=owl_global_get_puntlist(g);
615  j=owl_list_get_size(pl);
616  for (i=0; i<j; i++) {
617    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
618  }
619  return(0);
620}
621
622int owl_global_should_followlast(owl_global *g) {
[9e5c9f3]623  const owl_view *v;
[7d4fbcd]624 
625  if (!owl_global_is__followlast(g)) return(0);
626 
627  v=owl_global_get_current_view(g);
628 
629  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
630  return(0);
631}
[1fd0b25]632
[8742840]633int owl_global_is_search_active(const owl_global *g) {
[41c9a96]634  if (owl_regex_is_set(&g->search_re)) return(1);
[1fd0b25]635  return(0);
636}
637
[89b2daf]638void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
[41c9a96]639  if (owl_regex_is_set(&g->search_re)) {
[5cbc929]640    owl_regex_cleanup(&g->search_re);
[41c9a96]641    owl_regex_init(&g->search_re);
642  }
643  if (re != NULL)
644    owl_regex_copy(re, &g->search_re);
[5b68c05]645  /* TODO: Emit a signal so we don't depend on the viewwin here. */
646  if (owl_global_get_viewwin(g))
647    owl_viewwin_dirty(owl_global_get_viewwin(g));
[1fd0b25]648}
649
[8742840]650const owl_regex *owl_global_get_search_re(const owl_global *g) {
[41c9a96]651  return &g->search_re;
[1fd0b25]652}
[700c712]653
[0e5afa2]654void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
[700c712]655  g->newmsgproc_pid=i;
656}
657
[0e5afa2]658pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
[700c712]659  return(g->newmsgproc_pid);
660}
661
[d09e5a1]662/* AIM stuff */
663
[8742840]664int owl_global_is_aimloggedin(const owl_global *g)
[6a415e9]665{
[d09e5a1]666  if (g->aim_loggedin) return(1);
667  return(0);
668}
669
[8742840]670const char *owl_global_get_aim_screenname(const owl_global *g)
[6a415e9]671{
[a352335c]672  if (owl_global_is_aimloggedin(g)) {
673    return (g->aim_screenname);
674  }
675  return("");
[d09e5a1]676}
677
[8742840]678const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
[81655f8]679{
680  if (owl_global_is_aimloggedin(g)) {
681    return (g->aim_screenname_for_filters);
682  }
683  return("");
684}
685
[e19eb97]686void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
[6a415e9]687{
[65b2173]688  char *sn_escaped;
[e19eb97]689  const char *quote;
[d09e5a1]690  g->aim_loggedin=1;
691  if (g->aim_screenname) owl_free(g->aim_screenname);
[81655f8]692  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
[d09e5a1]693  g->aim_screenname=owl_strdup(screenname);
[81655f8]694  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
695  quote = owl_getquoting(sn_escaped);
[9f4e3f8]696  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
[81655f8]697  owl_free(sn_escaped);
[d09e5a1]698}
699
[6a415e9]700void owl_global_set_aimnologgedin(owl_global *g)
701{
[d09e5a1]702  g->aim_loggedin=0;
703}
704
[8742840]705int owl_global_is_doaimevents(const owl_global *g)
[a352335c]706{
707  if (g->aim_doprocessing) return(1);
708  return(0);
709}
710
711void owl_global_set_doaimevents(owl_global *g)
712{
713  g->aim_doprocessing=1;
714}
715
716void owl_global_set_no_doaimevents(owl_global *g)
717{
718  g->aim_doprocessing=0;
719}
720
[6a415e9]721aim_session_t *owl_global_get_aimsess(owl_global *g)
722{
[d09e5a1]723  return(&(g->aimsess));
724}
725
[c15bbfb]726aim_conn_t *owl_global_get_bosconn(owl_global *g)
727{
728  return(&(g->bosconn));
729}
730
731void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]732{
[c15bbfb]733  g->bosconn=*conn;
[d09e5a1]734}
735
736/* message queue */
737
[6a415e9]738void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
739{
[20aced3]740  g_queue_push_tail(g->messagequeue, m);
[d09e5a1]741}
742
743/* pop off the first message and return it.  Return NULL if the queue
744 * is empty.  The caller should free the message after using it, if
745 * necessary.
746 */
[13a3c1db]747owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]748{
[d09e5a1]749  owl_message *out;
750
[20aced3]751  if (g_queue_is_empty(g->messagequeue))
752    return NULL;
753  out = g_queue_pop_head(g->messagequeue);
754  return out;
[d09e5a1]755}
756
[6a415e9]757int owl_global_messagequeue_pending(owl_global *g)
758{
[20aced3]759  return !g_queue_is_empty(g->messagequeue);
[d09e5a1]760}
[aa5f725]761
[6a415e9]762owl_buddylist *owl_global_get_buddylist(owl_global *g)
763{
[aa5f725]764  return(&(g->buddylist));
765}
766 
[bd3f232]767/* style */
768
769/* Return the style with name 'name'.  If it does not exist return
770 * NULL */
[8742840]771const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
[bd3f232]772{
[f1e629d]773  return owl_dict_find_element(&(g->styledict), name);
774}
775
776/* creates a list and fills it in with keys.  duplicates the keys,
777 * so they will need to be freed by the caller. */
[8742840]778int owl_global_get_style_names(const owl_global *g, owl_list *l) {
[f1e629d]779  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]780}
781
[cf83b7a]782void owl_global_add_style(owl_global *g, owl_style *s)
783{
[f1fc47f]784  /*
785   * If we're redefining the current style, make sure to update
786   * pointers to it.
787   */
788  if(g->current_view.style
789     && !strcmp(owl_style_get_name(g->current_view.style),
790                owl_style_get_name(s)))
791    g->current_view.style = s;
792  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
[516c27e]793                          s, (void (*)(void *))owl_style_delete);
[bd3f232]794}
[cf83b7a]795
[09489b89]796void owl_global_set_haveaim(owl_global *g)
797{
798  g->haveaim=1;
799}
800
[8742840]801int owl_global_is_haveaim(const owl_global *g)
[09489b89]802{
803  if (g->haveaim) return(1);
804  return(0);
805}
806
[b7bb454]807void owl_global_set_ignore_aimlogin(owl_global *g)
808{
809    g->ignoreaimlogin = 1;
810}
811
812void owl_global_unset_ignore_aimlogin(owl_global *g)
813{
814    g->ignoreaimlogin = 0;
815}
816
[8742840]817int owl_global_is_ignore_aimlogin(const owl_global *g)
[b7bb454]818{
819    return g->ignoreaimlogin;
820}
821
[09489b89]822void owl_global_set_havezephyr(owl_global *g)
823{
824  g->havezephyr=1;
825}
826
[8742840]827int owl_global_is_havezephyr(const owl_global *g)
[09489b89]828{
829  if (g->havezephyr) return(1);
830  return(0);
831}
[de03334]832
[ec6ff52]833owl_errqueue *owl_global_get_errqueue(owl_global *g)
834{
835  return(&(g->errqueue));
836}
[c9e72d1]837
838void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
839{
840  g->got_err_signal = signum;
841  if (siginfo) {
842    g->err_signal_info = *siginfo;
843  } else {
[7892963]844    siginfo_t si;
845    memset(&si, 0, sizeof(si));
846    g->err_signal_info = si;
[c9e72d1]847  }
848}
849
850int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
851{
852  int signum;
853  if (siginfo && g->got_err_signal) {
854    *siginfo = g->err_signal_info;
855  } 
856  signum = g->got_err_signal;
857  g->got_err_signal = 0;
858  return signum;
859}
860
[5a95b69]861
862owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
863{
864  return(&(g->zbuddies));
865}
[8232149]866
[f25812b]867GList **owl_global_get_zaldlist(owl_global *g)
868{
869  return &(g->zaldlist);
870}
871
872int owl_global_get_pseudologin_notify(owl_global *g)
873{
874  return g->pseudologin_notify;
875}
876
877void owl_global_set_pseudologin_notify(owl_global *g, int notify)
878{
879  g->pseudologin_notify = notify;
880}
881
[8232149]882struct termios *owl_global_get_startup_tio(owl_global *g)
883{
884  return(&(g->startup_tio));
885}
[8e401cae]886
[df0138f]887owl_list *owl_global_get_io_dispatch_list(owl_global *g)
888{
889  return &(g->io_dispatch_list);
890}
891
[4f2166b]892owl_list *owl_global_get_psa_list(owl_global *g)
893{
894  return &(g->psa_list);
895}
896
[58d1f8a]897GList **owl_global_get_timerlist(owl_global *g)
[b7bb454]898{
[58d1f8a]899  return &(g->timerlist);
[b7bb454]900}
[adee9cc]901
[8742840]902int owl_global_is_interrupted(const owl_global *g) {
[0cb6c26]903  return g->interrupted;
[adee9cc]904}
905
906void owl_global_set_interrupted(owl_global *g) {
907  g->interrupted = 1;
908}
909
910void owl_global_unset_interrupted(owl_global *g) {
911  g->interrupted = 0;
912}
[04b16f8]913
914void owl_global_setup_default_filters(owl_global *g)
915{
916  int i;
917  static const struct {
918    const char *name;
919    const char *desc;
920  } filters[] = {
921    { "personal",
[efc460e]922      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
[04b16f8]923    { "trash",
924      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
925    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
926    { "ping", "opcode ^ping$" },
927    { "auto", "opcode ^auto$" },
928    { "login", "not login ^none$" },
929    { "reply-lockout", "class ^noc or class ^mail$" },
930    { "out", "direction ^out$" },
931    { "aim", "type ^aim$" },
932    { "zephyr", "type ^zephyr$" },
933    { "none", "false" },
934    { "all", "true" },
935    { NULL, NULL }
936  };
937
938  owl_function_debugmsg("startup: creating default filters");
939
940  for (i = 0; filters[i].name != NULL; i++)
941    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
942                                                       filters[i].desc));
943}
[d12a8c7]944
945FILE *owl_global_get_debug_file_handle(owl_global *g) {
946  static char *open_file = NULL;
947  const char *filename = owl_global_get_debug_file(g);
948  if (g->debug_file == NULL ||
949      (open_file && strcmp(filename, open_file) != 0)) {
[26ad412]950    char *path;
[50522b5]951    int fd;
952
[d12a8c7]953    if (g->debug_file)
954      fclose(g->debug_file);
[50522b5]955
956    g->debug_file = NULL;
957
[26ad412]958    path = owl_sprintf("%s.%d", filename, getpid());
959    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
960    owl_free(path);
961
[50522b5]962    if (fd >= 0)
963      g->debug_file = fdopen(fd, "a");
[d12a8c7]964
965    owl_free(open_file);
966    open_file = owl_strdup(filename);
967  }
968  return g->debug_file;
969}
Note: See TracBrowser for help on using the repository browser.