source: global.c @ 8510d5b

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