source: global.c @ 8099357

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