source: global.c @ 22e02cd

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 22e02cd was 04b16f8, checked in by Nelson Elhage <nelhage@mit.edu>, 14 years ago
Set up filters and a view in the tester.
  • Property mode set to 100644
File size: 24.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));
[d09e5a1]55  owl_list_create(&(g->messagequeue));
[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
[8e401cae]115  owl_obarray_init(&(g->obarray));
[a387d12e]116
117  owl_message_init_fmtext_cache();
[df0138f]118  owl_list_create(&(g->io_dispatch_list));
[4f2166b]119  owl_list_create(&(g->psa_list));
[58d1f8a]120  g->timerlist = NULL;
[adee9cc]121  g->interrupted = FALSE;
[0881cdd]122
123  /* set up a pad for input */
124  g->input_pad = newpad(1, 1);
125  nodelay(g->input_pad, 1);
126  keypad(g->input_pad, 1);
127  meta(g->input_pad, 1);
[7d4fbcd]128}
129
[eb6cedc]130/* Called once perl has been initialized */
131void owl_global_complete_setup(owl_global *g)
132{
133  owl_cmddict_setup(&(g->cmds));
134}
135
[8ae2de9]136/* If *pan does not exist, we create a new panel, otherwise we replace the
137   window in *pan with win.
138
139   libpanel PANEL objects cannot exist without owner a valid window. This
140   maintains the invariant for _owl_global_setup_windows. */
141void _owl_panel_set_window(PANEL **pan, WINDOW *win)
142{
143  WINDOW *oldwin;
[b3adfb5]144
145  if (win == NULL) {
[0e3cdf1]146    owl_function_debugmsg("_owl_panel_set_window: passed NULL win (failed to allocate?)");
[b3adfb5]147    endwin();
148    exit(50);
149  }
150
[8ae2de9]151  if (*pan) {
152    oldwin = panel_window(*pan);
153    replace_panel(*pan, win);
154    delwin(oldwin);
155  } else {
156    *pan = new_panel(win);
157  }
158}
159
[7d4fbcd]160void _owl_global_setup_windows(owl_global *g) {
[ecd5dc5]161  int cols, typwin_lines;
[7d4fbcd]162
163  cols=g->cols;
[ecd5dc5]164  typwin_lines=owl_global_get_typwin_lines(g);
[7d4fbcd]165
166  /* set the new window sizes */
167  g->recwinlines=g->lines-(typwin_lines+2);
[176d3443]168  if (g->recwinlines<0) {
169    /* gotta deal with this */
170    g->recwinlines=0;
[ecd5dc5]171  }
[7d4fbcd]172
173  /* create the new windows */
[b3adfb5]174  _owl_panel_set_window(&g->recpan, newwin(g->recwinlines, cols, 0, 0));
175  _owl_panel_set_window(&g->seppan, newwin(1, cols, g->recwinlines, 0));
176  _owl_panel_set_window(&g->msgpan, newwin(1, cols, g->recwinlines+1, 0));
177  _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0));
178
[38cc669]179  if (g->tw)
180      owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);
[b3adfb5]181
182  idlok(owl_global_get_curs_typwin(g), FALSE);
183  idlok(owl_global_get_curs_recwin(g), FALSE);
184  idlok(owl_global_get_curs_sepwin(g), FALSE);
185  idlok(owl_global_get_curs_msgwin(g), FALSE);
186
187  wmove(owl_global_get_curs_typwin(g), 0, 0);
[7d4fbcd]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) {
[b3adfb5]308  return panel_window(g->recpan);
[7d4fbcd]309}
310
[8742840]311WINDOW *owl_global_get_curs_sepwin(const owl_global *g) {
[b3adfb5]312  return panel_window(g->seppan);
[7d4fbcd]313}
314
[8742840]315WINDOW *owl_global_get_curs_msgwin(const owl_global *g) {
[b3adfb5]316  return panel_window(g->msgpan);
[7d4fbcd]317}
318
[8742840]319WINDOW *owl_global_get_curs_typwin(const owl_global *g) {
[b3adfb5]320  return panel_window(g->typpan);
[7d4fbcd]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/* refresh */
330
[8742840]331int owl_global_is_needrefresh(const owl_global *g) {
[7d4fbcd]332  if (g->needrefresh==1) return(1);
333  return(0);
334}
335
336void owl_global_set_needrefresh(owl_global *g) {
337  g->needrefresh=1;
338}
339
340void owl_global_set_noneedrefresh(owl_global *g) {
341  g->needrefresh=0;
342}
343
344/* variable dictionary */
345
346owl_vardict *owl_global_get_vardict(owl_global *g) {
347  return &(g->vars);
348}
349
350/* command dictionary */
351
352owl_cmddict *owl_global_get_cmddict(owl_global *g) {
353  return &(g->cmds);
354}
355
356/* rightshift */
357
358void owl_global_set_rightshift(owl_global *g, int i) {
359  g->rightshift=i;
360}
361
[8742840]362int owl_global_get_rightshift(const owl_global *g) {
[7d4fbcd]363  return(g->rightshift);
364}
365
366/* typwin */
367
[58d47ca]368owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
[38cc669]369  int d;
370  d = owl_global_get_typewindelta(g);
[73eda8c]371  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
[da466e0]372      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
373
[38cc669]374  g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
375                          owl_global_get_typwin_lines(g),
376                          g->cols,
377                          style,
378                          hist);
[58d47ca]379  return g->tw;
[7d4fbcd]380}
381
382void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]383  int d = owl_global_get_typewindelta(g);
[73eda8c]384  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
[da466e0]385      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
386
[38cc669]387  werase(owl_global_get_curs_typwin(g));
388  g->tw = NULL;
[7d4fbcd]389}
390
391/* resize */
392
393void owl_global_set_resize_pending(owl_global *g) {
394  g->resizepending=1;
395}
396
[f7cf6c2]397void owl_global_set_relayout_pending(owl_global *g) {
398  g->relayoutpending = 1;
399}
400
[8742840]401const char *owl_global_get_homedir(const owl_global *g) {
[a8938c7]402  if (g->homedir) return(g->homedir);
403  return("/");
[7d4fbcd]404}
405
[8742840]406const char *owl_global_get_confdir(const owl_global *g) {
[b363d83]407  if (g->confdir) return(g->confdir);
408  return("/");
409}
410
411/*
412 * Setting this also sets startupfile to confdir/startup
413 */
[e19eb97]414void owl_global_set_confdir(owl_global *g, const char *cd) {
[27f6487]415  owl_free(g->confdir);
[b363d83]416  g->confdir = owl_strdup(cd);
[27f6487]417  owl_free(g->startupfile);
[b363d83]418  g->startupfile = owl_sprintf("%s/startup", cd);
419}
420
[8742840]421const char *owl_global_get_startupfile(const owl_global *g) {
[b363d83]422  if(g->startupfile) return(g->startupfile);
423  return("/");
424}
425
[8742840]426int owl_global_get_direction(const owl_global *g) {
[7d4fbcd]427  return(g->direction);
428}
429
430void owl_global_set_direction_downwards(owl_global *g) {
431  g->direction=OWL_DIRECTION_DOWNWARDS;
432}
433
434void owl_global_set_direction_upwards(owl_global *g) {
435  g->direction=OWL_DIRECTION_UPWARDS;
436}
437
438/* perl stuff */
439
440void owl_global_set_perlinterp(owl_global *g, void *p) {
441  g->perl=p;
442}
443
[8742840]444void *owl_global_get_perlinterp(const owl_global *g) {
[7d4fbcd]445  return(g->perl);
446}
447
[8742840]448int owl_global_is_config_format(const owl_global *g) {
[7d4fbcd]449  if (g->config_format) return(1);
450  return(0);
451}
452
453void owl_global_set_config_format(owl_global *g, int state) {
454  if (state==1) {
455    g->config_format=1;
456  } else {
457    g->config_format=0;
458  }
459}
460
461void owl_global_set_have_config(owl_global *g) {
462  g->haveconfig=1;
463}
464
465void owl_global_set_no_have_config(owl_global *g) {
466  g->haveconfig=0;
467}
468
469int owl_global_have_config(owl_global *g) {
470  if (g->haveconfig) return(1);
471  return(0);
472}
473
[285bc9a]474/*
475 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
476 * fail.
477 */
478static void _owl_global_get_size(int *lines, int *cols) {
479  struct winsize size;
480  /* get the new size */
481  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
482  if (size.ws_row) {
483    *lines = size.ws_row;
484  } else {
485    *lines = LINES;
486  }
487
488  if (size.ws_col) {
489    *cols = size.ws_col;
490  } else {
491    *cols = COLS;
492  }
493}
494
[7d4fbcd]495void owl_global_resize(owl_global *g, int x, int y) {
496  /* resize the screen.  If x or y is 0 use the terminal size */
497  if (!g->resizepending) return;
[8479494]498  g->resizepending = 0;
[7d4fbcd]499
[285bc9a]500  _owl_global_get_size(&g->lines, &g->cols);
501  if (x != 0) {
502    g->lines = x;
[7d4fbcd]503  }
[285bc9a]504  if (y != 0) {
505    g->cols = y;
[7d4fbcd]506  }
507
[1f3a423]508  resizeterm(g->lines, g->cols);
[7d4fbcd]509
[f9f88f3]510  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
[f7cf6c2]511  owl_global_set_relayout_pending(g);
[f9f88f3]512}
513
514void owl_global_relayout(owl_global *g) {
[719173c4]515  owl_popwin *pw;
516  owl_viewwin *vw;
517
[f7cf6c2]518  if (!g->relayoutpending) return;
519  g->relayoutpending = 0;
520
[f9f88f3]521  owl_function_debugmsg("Relayouting...");
522
[7d4fbcd]523  /* re-initialize the windows */
524  _owl_global_setup_windows(g);
525
[f1e629d]526  /* in case any styles rely on the current width */
527  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
528
[c0f9e30]529  /* recalculate the topmsg to make sure the current message is on
530   * screen */
531  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
532
[719173c4]533  /* recreate the popwin */
534  pw = owl_global_get_popwin(g);
535  if (owl_popwin_is_active(pw)) {
536    /*
537     * This is somewhat hacky; we probably want a proper windowing layer. We
538     * destroy the popwin and recreate it. Then the viewwin is redirected to
539     * the new window.
540     */
541    vw = owl_global_get_viewwin(g);
542    owl_popwin_close(pw);
543    owl_popwin_up(pw);
544    owl_viewwin_set_curswin(vw, owl_popwin_get_curswin(pw),
545        owl_popwin_get_lines(pw), owl_popwin_get_cols(pw));
546    owl_viewwin_redisplay(vw);
547  }
548
[7d4fbcd]549  /* refresh stuff */
550  g->needrefresh=1;
551  owl_mainwin_redisplay(&(g->mw));
552  sepbar(NULL);
[38cc669]553  if (g->tw)
554      owl_editwin_redisplay(g->tw);
[59ab8dd]555  else
556    werase(owl_global_get_curs_typwin(g));
557
[8240bce]558  owl_function_full_redisplay();
[7d4fbcd]559
560  owl_function_makemsg("");
561}
562
563/* debug */
564
[8742840]565int owl_global_is_debug_fast(const owl_global *g) {
[7d4fbcd]566  if (g->debug) return(1);
567  return(0);
568}
569
570/* starttime */
571
[8742840]572time_t owl_global_get_starttime(const owl_global *g) {
[7d4fbcd]573  return(g->starttime);
574}
575
[8742840]576time_t owl_global_get_runtime(const owl_global *g) {
[7d4fbcd]577  return(time(NULL)-g->starttime);
578}
579
[8742840]580time_t owl_global_get_lastinputtime(const owl_global *g) {
[7f792c1]581  return(g->lastinputtime);
582}
583
[eebef19]584void owl_global_set_lastinputtime(owl_global *g, time_t time) {
585  g->lastinputtime = time;
[7f792c1]586}
587
[8742840]588time_t owl_global_get_idletime(const owl_global *g) {
[7f792c1]589  return(time(NULL)-g->lastinputtime);
590}
591
[8742840]592const char *owl_global_get_hostname(const owl_global *g) {
[a8938c7]593  if (g->thishost) return(g->thishost);
594  return("");
[61e79a9]595}
596
[7d4fbcd]597/* userclue */
598
599void owl_global_set_userclue(owl_global *g, int clue) {
600  g->userclue=clue;
601}
602
603void owl_global_add_userclue(owl_global *g, int clue) {
604  g->userclue|=clue;
605}
606
[8742840]607int owl_global_get_userclue(const owl_global *g) {
[7d4fbcd]608  return(g->userclue);
609}
610
[8742840]611int owl_global_is_userclue(const owl_global *g, int clue) {
[7d4fbcd]612  if (g->userclue & clue) return(1);
613  return(0);
614}
615
616/* viewwin */
617
618owl_viewwin *owl_global_get_viewwin(owl_global *g) {
619  return(&(g->vw));
620}
621
622
623/* vert offset */
624
[8742840]625int owl_global_get_curmsg_vert_offset(const owl_global *g) {
[7d4fbcd]626  return(g->curmsg_vert_offset);
627}
628
629void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
630  g->curmsg_vert_offset=i;
631}
632
633/* startup args */
634
[e19eb97]635void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
[a8938c7]636  int i, len;
637
638  if (g->startupargs) owl_free(g->startupargs);
639 
640  len=0;
641  for (i=0; i<argc; i++) {
[591e6aa7]642    len+=strlen(argv[i])+5;
[a8938c7]643  }
[34509d5]644  g->startupargs=owl_malloc(len+5);
[7d4fbcd]645
646  strcpy(g->startupargs, "");
647  for (i=0; i<argc; i++) {
[b9cb41b]648    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
[7d4fbcd]649  }
650  g->startupargs[strlen(g->startupargs)-1]='\0';
651}
652
[8742840]653const char *owl_global_get_startupargs(const owl_global *g) {
[a8938c7]654  if (g->startupargs) return(g->startupargs);
655  return("");
[7d4fbcd]656}
657
658/* history */
659
[10b866d]660owl_history *owl_global_get_msg_history(owl_global *g) {
661  return(&(g->msghist));
662}
663
664owl_history *owl_global_get_cmd_history(owl_global *g) {
665  return(&(g->cmdhist));
[7d4fbcd]666}
667
668/* filterlist */
[129e609]669typedef struct _owl_global_filter_ent {         /* noproto */
670  owl_global *g;
671  owl_filter *f;
672} owl_global_filter_ent;
[7d4fbcd]673
[8742840]674owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
[129e609]675  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
676  if (e) return e->f;
677  return NULL;
678}
[7d4fbcd]679
[5294cbf]680static void owl_global_delete_filter_ent(void *data)
681{
[129e609]682  owl_global_filter_ent *e = data;
683  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
684  owl_filter_delete(e->f);
685  owl_free(e);
[7d4fbcd]686}
687
688void owl_global_add_filter(owl_global *g, owl_filter *f) {
[129e609]689  owl_global_filter_ent *e = owl_malloc(sizeof *e);
690  e->g = g;
691  e->f = f;
692
693  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
[5294cbf]694                          e, owl_global_delete_filter_ent);
[129e609]695  g->filterlist = g_list_append(g->filterlist, f);
[7d4fbcd]696}
697
[e19eb97]698void owl_global_remove_filter(owl_global *g, const char *name) {
[129e609]699  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
700  if (e)
[5294cbf]701    owl_global_delete_filter_ent(e);
[7d4fbcd]702}
703
704/* nextmsgid */
705
706int owl_global_get_nextmsgid(owl_global *g) {
707  return(g->nextmsgid++);
708}
709
710/* current view */
711
712owl_view *owl_global_get_current_view(owl_global *g) {
713  return(&(g->current_view));
714}
715
716/* has colors */
717
[8742840]718int owl_global_get_hascolors(const owl_global *g) {
[7d4fbcd]719  if (g->hascolors) return(1);
720  return(0);
721}
722
723/* color pairs */
724
[8742840]725int owl_global_get_colorpairs(const owl_global *g) {
[7d4fbcd]726  return(g->colorpairs);
727}
728
[8fa9562]729owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
730  return(&(g->cpmgr));
731}
732
[7d4fbcd]733/* puntlist */
734
735owl_list *owl_global_get_puntlist(owl_global *g) {
736  return(&(g->puntlist));
737}
738
[c08c70a]739int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
[77bced3]740  const owl_list *pl;
[7d4fbcd]741  int i, j;
742
743  pl=owl_global_get_puntlist(g);
744  j=owl_list_get_size(pl);
745  for (i=0; i<j; i++) {
746    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
747  }
748  return(0);
749}
750
751int owl_global_should_followlast(owl_global *g) {
[9e5c9f3]752  const owl_view *v;
[7d4fbcd]753 
754  if (!owl_global_is__followlast(g)) return(0);
755 
756  v=owl_global_get_current_view(g);
757 
758  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
759  return(0);
760}
[1fd0b25]761
[8742840]762int owl_global_is_search_active(const owl_global *g) {
[41c9a96]763  if (owl_regex_is_set(&g->search_re)) return(1);
[1fd0b25]764  return(0);
765}
766
[89b2daf]767void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
[41c9a96]768  if (owl_regex_is_set(&g->search_re)) {
[5cbc929]769    owl_regex_cleanup(&g->search_re);
[41c9a96]770    owl_regex_init(&g->search_re);
771  }
772  if (re != NULL)
773    owl_regex_copy(re, &g->search_re);
[1fd0b25]774}
775
[8742840]776const owl_regex *owl_global_get_search_re(const owl_global *g) {
[41c9a96]777  return &g->search_re;
[1fd0b25]778}
[700c712]779
[0e5afa2]780void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
[700c712]781  g->newmsgproc_pid=i;
782}
783
[0e5afa2]784pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
[700c712]785  return(g->newmsgproc_pid);
786}
787
[d09e5a1]788/* AIM stuff */
789
[8742840]790int owl_global_is_aimloggedin(const owl_global *g)
[6a415e9]791{
[d09e5a1]792  if (g->aim_loggedin) return(1);
793  return(0);
794}
795
[8742840]796const char *owl_global_get_aim_screenname(const owl_global *g)
[6a415e9]797{
[a352335c]798  if (owl_global_is_aimloggedin(g)) {
799    return (g->aim_screenname);
800  }
801  return("");
[d09e5a1]802}
803
[8742840]804const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
[81655f8]805{
806  if (owl_global_is_aimloggedin(g)) {
807    return (g->aim_screenname_for_filters);
808  }
809  return("");
810}
811
[e19eb97]812void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
[6a415e9]813{
[65b2173]814  char *sn_escaped;
[e19eb97]815  const char *quote;
[d09e5a1]816  g->aim_loggedin=1;
817  if (g->aim_screenname) owl_free(g->aim_screenname);
[81655f8]818  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
[d09e5a1]819  g->aim_screenname=owl_strdup(screenname);
[81655f8]820  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
821  quote = owl_getquoting(sn_escaped);
[9f4e3f8]822  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
[81655f8]823  owl_free(sn_escaped);
[d09e5a1]824}
825
[6a415e9]826void owl_global_set_aimnologgedin(owl_global *g)
827{
[d09e5a1]828  g->aim_loggedin=0;
829}
830
[8742840]831int owl_global_is_doaimevents(const owl_global *g)
[a352335c]832{
833  if (g->aim_doprocessing) return(1);
834  return(0);
835}
836
837void owl_global_set_doaimevents(owl_global *g)
838{
839  g->aim_doprocessing=1;
840}
841
842void owl_global_set_no_doaimevents(owl_global *g)
843{
844  g->aim_doprocessing=0;
845}
846
[6a415e9]847aim_session_t *owl_global_get_aimsess(owl_global *g)
848{
[d09e5a1]849  return(&(g->aimsess));
850}
851
[c15bbfb]852aim_conn_t *owl_global_get_bosconn(owl_global *g)
853{
854  return(&(g->bosconn));
855}
856
857void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]858{
[c15bbfb]859  g->bosconn=*conn;
[d09e5a1]860}
861
862/* message queue */
863
[6a415e9]864void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
865{
[d09e5a1]866  owl_list_append_element(&(g->messagequeue), m);
867}
868
869/* pop off the first message and return it.  Return NULL if the queue
870 * is empty.  The caller should free the message after using it, if
871 * necessary.
872 */
[13a3c1db]873owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]874{
[d09e5a1]875  owl_message *out;
876
877  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
878  out=owl_list_get_element(&(g->messagequeue), 0);
879  owl_list_remove_element(&(g->messagequeue), 0);
880  return(out);
881}
882
[6a415e9]883int owl_global_messagequeue_pending(owl_global *g)
884{
[d09e5a1]885  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
886  return(1);
887}
[aa5f725]888
[6a415e9]889owl_buddylist *owl_global_get_buddylist(owl_global *g)
890{
[aa5f725]891  return(&(g->buddylist));
892}
893 
[bd3f232]894/* style */
895
896/* Return the style with name 'name'.  If it does not exist return
897 * NULL */
[8742840]898const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
[bd3f232]899{
[f1e629d]900  return owl_dict_find_element(&(g->styledict), name);
901}
902
903/* creates a list and fills it in with keys.  duplicates the keys,
904 * so they will need to be freed by the caller. */
[8742840]905int owl_global_get_style_names(const owl_global *g, owl_list *l) {
[f1e629d]906  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]907}
908
[cf83b7a]909void owl_global_add_style(owl_global *g, owl_style *s)
910{
[f1fc47f]911  /*
912   * If we're redefining the current style, make sure to update
913   * pointers to it.
914   */
915  if(g->current_view.style
916     && !strcmp(owl_style_get_name(g->current_view.style),
917                owl_style_get_name(s)))
918    g->current_view.style = s;
919  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
[516c27e]920                          s, (void (*)(void *))owl_style_delete);
[bd3f232]921}
[cf83b7a]922
[09489b89]923void owl_global_set_haveaim(owl_global *g)
924{
925  g->haveaim=1;
926}
927
[8742840]928int owl_global_is_haveaim(const owl_global *g)
[09489b89]929{
930  if (g->haveaim) return(1);
931  return(0);
932}
933
[b7bb454]934void owl_global_set_ignore_aimlogin(owl_global *g)
935{
936    g->ignoreaimlogin = 1;
937}
938
939void owl_global_unset_ignore_aimlogin(owl_global *g)
940{
941    g->ignoreaimlogin = 0;
942}
943
[8742840]944int owl_global_is_ignore_aimlogin(const owl_global *g)
[b7bb454]945{
946    return g->ignoreaimlogin;
947}
948
[09489b89]949void owl_global_set_havezephyr(owl_global *g)
950{
951  g->havezephyr=1;
952}
953
[8742840]954int owl_global_is_havezephyr(const owl_global *g)
[09489b89]955{
956  if (g->havezephyr) return(1);
957  return(0);
958}
[de03334]959
[ec6ff52]960owl_errqueue *owl_global_get_errqueue(owl_global *g)
961{
962  return(&(g->errqueue));
963}
[c9e72d1]964
965void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
966{
967  g->got_err_signal = signum;
968  if (siginfo) {
969    g->err_signal_info = *siginfo;
970  } else {
[7892963]971    siginfo_t si;
972    memset(&si, 0, sizeof(si));
973    g->err_signal_info = si;
[c9e72d1]974  }
975}
976
977int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
978{
979  int signum;
980  if (siginfo && g->got_err_signal) {
981    *siginfo = g->err_signal_info;
982  } 
983  signum = g->got_err_signal;
984  g->got_err_signal = 0;
985  return signum;
986}
987
[5a95b69]988
989owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
990{
991  return(&(g->zbuddies));
992}
[8232149]993
[f25812b]994GList **owl_global_get_zaldlist(owl_global *g)
995{
996  return &(g->zaldlist);
997}
998
999int owl_global_get_pseudologin_notify(owl_global *g)
1000{
1001  return g->pseudologin_notify;
1002}
1003
1004void owl_global_set_pseudologin_notify(owl_global *g, int notify)
1005{
1006  g->pseudologin_notify = notify;
1007}
1008
[8232149]1009struct termios *owl_global_get_startup_tio(owl_global *g)
1010{
1011  return(&(g->startup_tio));
1012}
[8e401cae]1013
[e19eb97]1014const char * owl_global_intern(owl_global *g, const char * string)
[8e401cae]1015{
1016  return owl_obarray_insert(&(g->obarray), string);
1017}
[9c7a701]1018
[df0138f]1019owl_list *owl_global_get_io_dispatch_list(owl_global *g)
1020{
1021  return &(g->io_dispatch_list);
1022}
1023
[4f2166b]1024owl_list *owl_global_get_psa_list(owl_global *g)
1025{
1026  return &(g->psa_list);
1027}
1028
[58d1f8a]1029GList **owl_global_get_timerlist(owl_global *g)
[b7bb454]1030{
[58d1f8a]1031  return &(g->timerlist);
[b7bb454]1032}
[adee9cc]1033
[8742840]1034int owl_global_is_interrupted(const owl_global *g) {
[0cb6c26]1035  return g->interrupted;
[adee9cc]1036}
1037
1038void owl_global_set_interrupted(owl_global *g) {
1039  g->interrupted = 1;
1040}
1041
1042void owl_global_unset_interrupted(owl_global *g) {
1043  g->interrupted = 0;
1044}
[04b16f8]1045
1046void owl_global_setup_default_filters(owl_global *g)
1047{
1048  int i;
1049  static const struct {
1050    const char *name;
1051    const char *desc;
1052  } filters[] = {
1053    { "personal",
1054      "private ^true$ and ( not type ^zephyr$ or "
1055      "( class ^message and ( instance ^personal$ or instance ^urgent$ ) ) )" },
1056    { "trash",
1057      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
1058    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
1059    { "ping", "opcode ^ping$" },
1060    { "auto", "opcode ^auto$" },
1061    { "login", "not login ^none$" },
1062    { "reply-lockout", "class ^noc or class ^mail$" },
1063    { "out", "direction ^out$" },
1064    { "aim", "type ^aim$" },
1065    { "zephyr", "type ^zephyr$" },
1066    { "none", "false" },
1067    { "all", "true" },
1068    { NULL, NULL }
1069  };
1070
1071  owl_function_debugmsg("startup: creating default filters");
1072
1073  for (i = 0; filters[i].name != NULL; i++)
1074    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
1075                                                       filters[i].desc));
1076}
Note: See TracBrowser for help on using the repository browser.