source: global.c @ 05ca0d8

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