source: global.c @ 0b9e607

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 0b9e607 was d70f45f, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Port the msgwin to owl_window I feel kind of silly making a new file for this, but meh.
  • Property mode set to 100644
File size: 21.9 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
[d2a4534]81  owl_mainpanel_init(&(g->mainpanel));
[7d4fbcd]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));
[d70f45f]97  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
[d09e5a1]98
99  g->aim_screenname=NULL;
[81655f8]100  g->aim_screenname_for_filters=NULL;
[d09e5a1]101  g->aim_loggedin=0;
[aa5f725]102  owl_buddylist_init(&(g->buddylist));
[b7bb454]103
[09489b89]104  g->havezephyr=0;
105  g->haveaim=0;
[b7bb454]106  g->ignoreaimlogin=0;
[a352335c]107  owl_global_set_no_doaimevents(g);
[ec6ff52]108
109  owl_errqueue_init(&(g->errqueue));
[c9e72d1]110  g->got_err_signal=0;
[5a95b69]111
112  owl_zbuddylist_create(&(g->zbuddies));
[8e401cae]113
[f25812b]114  g->zaldlist = NULL;
115  g->pseudologin_notify = 0;
116
[a387d12e]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) {
[f6fae8d]161  int cols, recwinlines;
[7d4fbcd]162
163  cols=g->cols;
164
[d2a4534]165  recwinlines = owl_global_get_recwin_lines(g);
[7d4fbcd]166
167  /* create the new windows */
[d2a4534]168  _owl_panel_set_window(&g->recpan, newwin(recwinlines, cols, 0, 0));
169  _owl_panel_set_window(&g->seppan, newwin(1, cols, recwinlines, 0));
[7d4fbcd]170}
171
172owl_context *owl_global_get_context(owl_global *g) {
[a999d9e]173  if (!g->context_stack)
174    return NULL;
175  return g->context_stack->data;
176}
177
178static void owl_global_lookup_keymap(owl_global *g) {
179  owl_context *c = owl_global_get_context(g);
180  if (!c || !c->keymap)
181    return;
182
183  if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
184    owl_function_error("Unable to activate keymap '%s'", c->keymap);
185  }
[7d4fbcd]186}
[a999d9e]187
188void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap) {
189  owl_context *c;
190  if (!(mode & OWL_CTX_MODE_BITS))
191    mode |= OWL_CTX_INTERACTIVE;
192  c = owl_malloc(sizeof *c);
193  c->mode = mode;
194  c->data = data;
195  c->keymap = owl_strdup(keymap);
196  g->context_stack = g_list_prepend(g->context_stack, c);
197  owl_global_lookup_keymap(g);
198}
199
200void owl_global_pop_context(owl_global *g) {
201  owl_context *c;
202  if (!g->context_stack)
203    return;
204  c = owl_global_get_context(g);
205  g->context_stack = g_list_delete_link(g->context_stack,
206                                        g->context_stack);
207  owl_free(c->keymap);
208  owl_free(c);
209  owl_global_lookup_keymap(g);
210}
211
[8742840]212int owl_global_get_lines(const owl_global *g) {
[7d4fbcd]213  return(g->lines);
214}
215
[8742840]216int owl_global_get_cols(const owl_global *g) {
[7d4fbcd]217  return(g->cols);
218}
219
[8742840]220int owl_global_get_recwin_lines(const owl_global *g) {
[d2a4534]221  return g->mainpanel.recwinlines;
[7d4fbcd]222}
223
224/* curmsg */
225
[8742840]226int owl_global_get_curmsg(const owl_global *g) {
[7d4fbcd]227  return(g->curmsg);
228}
229
230void owl_global_set_curmsg(owl_global *g, int i) {
231  g->curmsg=i;
232  /* we will reset the vertical offset from here */
233  /* we might want to move this out to the functions later */
234  owl_global_set_curmsg_vert_offset(g, 0);
235}
236
237/* topmsg */
238
[8742840]239int owl_global_get_topmsg(const owl_global *g) {
[7d4fbcd]240  return(g->topmsg);
241}
242
243void owl_global_set_topmsg(owl_global *g, int i) {
244  g->topmsg=i;
245}
246
[70110286]247/* markedmsgid */
248
[8742840]249int owl_global_get_markedmsgid(const owl_global *g) {
[70110286]250  return(g->markedmsgid);
251}
252
253void owl_global_set_markedmsgid(owl_global *g, int i) {
254  g->markedmsgid=i;
255  /* i; index of message in the current view.
[c08c70a]256  const owl_message *m;
[70110286]257  owl_view *v;
258
259  v = owl_global_get_current_view(&g);
260  m = owl_view_get_element(v, i);
261  g->markedmsgid = m ? owl_message_get_id(m) : 0;
262  */
263}
264
[7d4fbcd]265/* windows */
266
267owl_mainwin *owl_global_get_mainwin(owl_global *g) {
268  return(&(g->mw));
269}
270
271owl_popwin *owl_global_get_popwin(owl_global *g) {
272  return(&(g->pw));
273}
274
275/* msglist */
276
277owl_messagelist *owl_global_get_msglist(owl_global *g) {
278  return(&(g->msglist));
279}
280
281/* keyhandler */
282
283owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
284  return(&(g->kh));
285}
286
287/* curses windows */
288
[8742840]289WINDOW *owl_global_get_curs_recwin(const owl_global *g) {
[b3adfb5]290  return panel_window(g->recpan);
[7d4fbcd]291}
292
[8742840]293WINDOW *owl_global_get_curs_sepwin(const owl_global *g) {
[b3adfb5]294  return panel_window(g->seppan);
[7d4fbcd]295}
296
[d70f45f]297owl_window *owl_global_get_curs_msgwin(const owl_global *g) {
298  return g->msgwin.window;
[7d4fbcd]299}
300
[f6fae8d]301owl_window *owl_global_get_curs_typwin(const owl_global *g) {
302  return g->mainpanel.typwin;
[7d4fbcd]303}
304
305/* typwin */
306
[8742840]307owl_editwin *owl_global_get_typwin(const owl_global *g) {
[a556caa]308  return(g->tw);
[7d4fbcd]309}
310
311/* refresh */
312
[8742840]313int owl_global_is_needrefresh(const owl_global *g) {
[7d4fbcd]314  if (g->needrefresh==1) return(1);
315  return(0);
316}
317
318void owl_global_set_needrefresh(owl_global *g) {
319  g->needrefresh=1;
320}
321
322void owl_global_set_noneedrefresh(owl_global *g) {
323  g->needrefresh=0;
324}
325
326/* variable dictionary */
327
328owl_vardict *owl_global_get_vardict(owl_global *g) {
329  return &(g->vars);
330}
331
332/* command dictionary */
333
334owl_cmddict *owl_global_get_cmddict(owl_global *g) {
335  return &(g->cmds);
336}
337
338/* rightshift */
339
340void owl_global_set_rightshift(owl_global *g, int i) {
341  g->rightshift=i;
342}
343
[8742840]344int owl_global_get_rightshift(const owl_global *g) {
[7d4fbcd]345  return(g->rightshift);
346}
347
348/* typwin */
349
[58d47ca]350owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
[38cc669]351  int d;
352  d = owl_global_get_typewindelta(g);
[73eda8c]353  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
[da466e0]354      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
355
[f6fae8d]356  if (g->typwin_erase_id) {
357    g_signal_handler_disconnect(owl_global_get_curs_typwin(g), g->typwin_erase_id);
358    g->typwin_erase_id = 0;
359  }
360
[38cc669]361  g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
362                          owl_global_get_typwin_lines(g),
363                          g->cols,
364                          style,
365                          hist);
[f6fae8d]366  owl_window_set_cursor(owl_global_get_curs_typwin(g));
[58d47ca]367  return g->tw;
[7d4fbcd]368}
369
370void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]371  int d = owl_global_get_typewindelta(g);
[73eda8c]372  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
[da466e0]373      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
374
[f6fae8d]375  if (!g->typwin_erase_id) {
376    g->typwin_erase_id =
377      g_signal_connect(owl_global_get_curs_typwin(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
378  }
379  owl_window_dirty(owl_global_get_curs_typwin(g));
380  /* owl_window_set_cursor(owl_global_get_curs_sepwin(g)); */
381
[38cc669]382  g->tw = NULL;
[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);
500}
501
502void owl_global_relayout(owl_global *g) {
[f7cf6c2]503  if (!g->relayoutpending) return;
504  g->relayoutpending = 0;
505
[f9f88f3]506  owl_function_debugmsg("Relayouting...");
507
[7d4fbcd]508  /* re-initialize the windows */
509  _owl_global_setup_windows(g);
510
[f1e629d]511  /* in case any styles rely on the current width */
512  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
513
[c0f9e30]514  /* recalculate the topmsg to make sure the current message is on
515   * screen */
516  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
517
[7d4fbcd]518  /* refresh stuff */
519  owl_mainwin_redisplay(&(g->mw));
520  sepbar(NULL);
[59ab8dd]521
[8240bce]522  owl_function_full_redisplay();
[7d4fbcd]523}
524
525/* debug */
526
[8742840]527int owl_global_is_debug_fast(const owl_global *g) {
[7d4fbcd]528  if (g->debug) return(1);
529  return(0);
530}
531
532/* starttime */
533
[8742840]534time_t owl_global_get_starttime(const owl_global *g) {
[7d4fbcd]535  return(g->starttime);
536}
537
[8742840]538time_t owl_global_get_runtime(const owl_global *g) {
[7d4fbcd]539  return(time(NULL)-g->starttime);
540}
541
[8742840]542time_t owl_global_get_lastinputtime(const owl_global *g) {
[7f792c1]543  return(g->lastinputtime);
544}
545
[eebef19]546void owl_global_set_lastinputtime(owl_global *g, time_t time) {
547  g->lastinputtime = time;
[7f792c1]548}
549
[8742840]550time_t owl_global_get_idletime(const owl_global *g) {
[7f792c1]551  return(time(NULL)-g->lastinputtime);
552}
553
[8742840]554const char *owl_global_get_hostname(const owl_global *g) {
[a8938c7]555  if (g->thishost) return(g->thishost);
556  return("");
[61e79a9]557}
558
[7d4fbcd]559/* userclue */
560
561void owl_global_set_userclue(owl_global *g, int clue) {
562  g->userclue=clue;
563}
564
565void owl_global_add_userclue(owl_global *g, int clue) {
566  g->userclue|=clue;
567}
568
[8742840]569int owl_global_get_userclue(const owl_global *g) {
[7d4fbcd]570  return(g->userclue);
571}
572
[8742840]573int owl_global_is_userclue(const owl_global *g, int clue) {
[7d4fbcd]574  if (g->userclue & clue) return(1);
575  return(0);
576}
577
578/* viewwin */
579
580owl_viewwin *owl_global_get_viewwin(owl_global *g) {
581  return(&(g->vw));
582}
583
584
585/* vert offset */
586
[8742840]587int owl_global_get_curmsg_vert_offset(const owl_global *g) {
[7d4fbcd]588  return(g->curmsg_vert_offset);
589}
590
591void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
592  g->curmsg_vert_offset=i;
593}
594
595/* startup args */
596
[e19eb97]597void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
[a8938c7]598  int i, len;
599
600  if (g->startupargs) owl_free(g->startupargs);
601 
602  len=0;
603  for (i=0; i<argc; i++) {
[591e6aa7]604    len+=strlen(argv[i])+5;
[a8938c7]605  }
[34509d5]606  g->startupargs=owl_malloc(len+5);
[7d4fbcd]607
608  strcpy(g->startupargs, "");
609  for (i=0; i<argc; i++) {
[b9cb41b]610    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
[7d4fbcd]611  }
612  g->startupargs[strlen(g->startupargs)-1]='\0';
613}
614
[8742840]615const char *owl_global_get_startupargs(const owl_global *g) {
[a8938c7]616  if (g->startupargs) return(g->startupargs);
617  return("");
[7d4fbcd]618}
619
620/* history */
621
[10b866d]622owl_history *owl_global_get_msg_history(owl_global *g) {
623  return(&(g->msghist));
624}
625
626owl_history *owl_global_get_cmd_history(owl_global *g) {
627  return(&(g->cmdhist));
[7d4fbcd]628}
629
630/* filterlist */
[129e609]631typedef struct _owl_global_filter_ent {         /* noproto */
632  owl_global *g;
633  owl_filter *f;
634} owl_global_filter_ent;
[7d4fbcd]635
[8742840]636owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
[129e609]637  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
638  if (e) return e->f;
639  return NULL;
640}
[7d4fbcd]641
[5294cbf]642static void owl_global_delete_filter_ent(void *data)
643{
[129e609]644  owl_global_filter_ent *e = data;
645  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
646  owl_filter_delete(e->f);
647  owl_free(e);
[7d4fbcd]648}
649
650void owl_global_add_filter(owl_global *g, owl_filter *f) {
[129e609]651  owl_global_filter_ent *e = owl_malloc(sizeof *e);
652  e->g = g;
653  e->f = f;
654
655  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
[5294cbf]656                          e, owl_global_delete_filter_ent);
[129e609]657  g->filterlist = g_list_append(g->filterlist, f);
[7d4fbcd]658}
659
[e19eb97]660void owl_global_remove_filter(owl_global *g, const char *name) {
[129e609]661  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
662  if (e)
[5294cbf]663    owl_global_delete_filter_ent(e);
[7d4fbcd]664}
665
666/* nextmsgid */
667
668int owl_global_get_nextmsgid(owl_global *g) {
669  return(g->nextmsgid++);
670}
671
672/* current view */
673
674owl_view *owl_global_get_current_view(owl_global *g) {
675  return(&(g->current_view));
676}
677
678/* has colors */
679
[8742840]680int owl_global_get_hascolors(const owl_global *g) {
[7d4fbcd]681  if (g->hascolors) return(1);
682  return(0);
683}
684
685/* color pairs */
686
[8742840]687int owl_global_get_colorpairs(const owl_global *g) {
[7d4fbcd]688  return(g->colorpairs);
689}
690
[8fa9562]691owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
692  return(&(g->cpmgr));
693}
694
[7d4fbcd]695/* puntlist */
696
697owl_list *owl_global_get_puntlist(owl_global *g) {
698  return(&(g->puntlist));
699}
700
[c08c70a]701int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
[77bced3]702  const owl_list *pl;
[7d4fbcd]703  int i, j;
704
705  pl=owl_global_get_puntlist(g);
706  j=owl_list_get_size(pl);
707  for (i=0; i<j; i++) {
708    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
709  }
710  return(0);
711}
712
713int owl_global_should_followlast(owl_global *g) {
[9e5c9f3]714  const owl_view *v;
[7d4fbcd]715 
716  if (!owl_global_is__followlast(g)) return(0);
717 
718  v=owl_global_get_current_view(g);
719 
720  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
721  return(0);
722}
[1fd0b25]723
[8742840]724int owl_global_is_search_active(const owl_global *g) {
[41c9a96]725  if (owl_regex_is_set(&g->search_re)) return(1);
[1fd0b25]726  return(0);
727}
728
[89b2daf]729void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
[41c9a96]730  if (owl_regex_is_set(&g->search_re)) {
[5cbc929]731    owl_regex_cleanup(&g->search_re);
[41c9a96]732    owl_regex_init(&g->search_re);
733  }
734  if (re != NULL)
735    owl_regex_copy(re, &g->search_re);
[1fd0b25]736}
737
[8742840]738const owl_regex *owl_global_get_search_re(const owl_global *g) {
[41c9a96]739  return &g->search_re;
[1fd0b25]740}
[700c712]741
[0e5afa2]742void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
[700c712]743  g->newmsgproc_pid=i;
744}
745
[0e5afa2]746pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
[700c712]747  return(g->newmsgproc_pid);
748}
749
[d09e5a1]750/* AIM stuff */
751
[8742840]752int owl_global_is_aimloggedin(const owl_global *g)
[6a415e9]753{
[d09e5a1]754  if (g->aim_loggedin) return(1);
755  return(0);
756}
757
[8742840]758const char *owl_global_get_aim_screenname(const owl_global *g)
[6a415e9]759{
[a352335c]760  if (owl_global_is_aimloggedin(g)) {
761    return (g->aim_screenname);
762  }
763  return("");
[d09e5a1]764}
765
[8742840]766const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
[81655f8]767{
768  if (owl_global_is_aimloggedin(g)) {
769    return (g->aim_screenname_for_filters);
770  }
771  return("");
772}
773
[e19eb97]774void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
[6a415e9]775{
[65b2173]776  char *sn_escaped;
[e19eb97]777  const char *quote;
[d09e5a1]778  g->aim_loggedin=1;
779  if (g->aim_screenname) owl_free(g->aim_screenname);
[81655f8]780  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
[d09e5a1]781  g->aim_screenname=owl_strdup(screenname);
[81655f8]782  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
783  quote = owl_getquoting(sn_escaped);
[9f4e3f8]784  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
[81655f8]785  owl_free(sn_escaped);
[d09e5a1]786}
787
[6a415e9]788void owl_global_set_aimnologgedin(owl_global *g)
789{
[d09e5a1]790  g->aim_loggedin=0;
791}
792
[8742840]793int owl_global_is_doaimevents(const owl_global *g)
[a352335c]794{
795  if (g->aim_doprocessing) return(1);
796  return(0);
797}
798
799void owl_global_set_doaimevents(owl_global *g)
800{
801  g->aim_doprocessing=1;
802}
803
804void owl_global_set_no_doaimevents(owl_global *g)
805{
806  g->aim_doprocessing=0;
807}
808
[6a415e9]809aim_session_t *owl_global_get_aimsess(owl_global *g)
810{
[d09e5a1]811  return(&(g->aimsess));
812}
813
[c15bbfb]814aim_conn_t *owl_global_get_bosconn(owl_global *g)
815{
816  return(&(g->bosconn));
817}
818
819void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]820{
[c15bbfb]821  g->bosconn=*conn;
[d09e5a1]822}
823
824/* message queue */
825
[6a415e9]826void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
827{
[20aced3]828  g_queue_push_tail(g->messagequeue, m);
[d09e5a1]829}
830
831/* pop off the first message and return it.  Return NULL if the queue
832 * is empty.  The caller should free the message after using it, if
833 * necessary.
834 */
[13a3c1db]835owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]836{
[d09e5a1]837  owl_message *out;
838
[20aced3]839  if (g_queue_is_empty(g->messagequeue))
840    return NULL;
841  out = g_queue_pop_head(g->messagequeue);
842  return out;
[d09e5a1]843}
844
[6a415e9]845int owl_global_messagequeue_pending(owl_global *g)
846{
[20aced3]847  return !g_queue_is_empty(g->messagequeue);
[d09e5a1]848}
[aa5f725]849
[6a415e9]850owl_buddylist *owl_global_get_buddylist(owl_global *g)
851{
[aa5f725]852  return(&(g->buddylist));
853}
854 
[bd3f232]855/* style */
856
857/* Return the style with name 'name'.  If it does not exist return
858 * NULL */
[8742840]859const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
[bd3f232]860{
[f1e629d]861  return owl_dict_find_element(&(g->styledict), name);
862}
863
864/* creates a list and fills it in with keys.  duplicates the keys,
865 * so they will need to be freed by the caller. */
[8742840]866int owl_global_get_style_names(const owl_global *g, owl_list *l) {
[f1e629d]867  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]868}
869
[cf83b7a]870void owl_global_add_style(owl_global *g, owl_style *s)
871{
[f1fc47f]872  /*
873   * If we're redefining the current style, make sure to update
874   * pointers to it.
875   */
876  if(g->current_view.style
877     && !strcmp(owl_style_get_name(g->current_view.style),
878                owl_style_get_name(s)))
879    g->current_view.style = s;
880  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
[516c27e]881                          s, (void (*)(void *))owl_style_delete);
[bd3f232]882}
[cf83b7a]883
[09489b89]884void owl_global_set_haveaim(owl_global *g)
885{
886  g->haveaim=1;
887}
888
[8742840]889int owl_global_is_haveaim(const owl_global *g)
[09489b89]890{
891  if (g->haveaim) return(1);
892  return(0);
893}
894
[b7bb454]895void owl_global_set_ignore_aimlogin(owl_global *g)
896{
897    g->ignoreaimlogin = 1;
898}
899
900void owl_global_unset_ignore_aimlogin(owl_global *g)
901{
902    g->ignoreaimlogin = 0;
903}
904
[8742840]905int owl_global_is_ignore_aimlogin(const owl_global *g)
[b7bb454]906{
907    return g->ignoreaimlogin;
908}
909
[09489b89]910void owl_global_set_havezephyr(owl_global *g)
911{
912  g->havezephyr=1;
913}
914
[8742840]915int owl_global_is_havezephyr(const owl_global *g)
[09489b89]916{
917  if (g->havezephyr) return(1);
918  return(0);
919}
[de03334]920
[ec6ff52]921owl_errqueue *owl_global_get_errqueue(owl_global *g)
922{
923  return(&(g->errqueue));
924}
[c9e72d1]925
926void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
927{
928  g->got_err_signal = signum;
929  if (siginfo) {
930    g->err_signal_info = *siginfo;
931  } else {
[7892963]932    siginfo_t si;
933    memset(&si, 0, sizeof(si));
934    g->err_signal_info = si;
[c9e72d1]935  }
936}
937
938int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
939{
940  int signum;
941  if (siginfo && g->got_err_signal) {
942    *siginfo = g->err_signal_info;
943  } 
944  signum = g->got_err_signal;
945  g->got_err_signal = 0;
946  return signum;
947}
948
[5a95b69]949
950owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
951{
952  return(&(g->zbuddies));
953}
[8232149]954
[f25812b]955GList **owl_global_get_zaldlist(owl_global *g)
956{
957  return &(g->zaldlist);
958}
959
960int owl_global_get_pseudologin_notify(owl_global *g)
961{
962  return g->pseudologin_notify;
963}
964
965void owl_global_set_pseudologin_notify(owl_global *g, int notify)
966{
967  g->pseudologin_notify = notify;
968}
969
[8232149]970struct termios *owl_global_get_startup_tio(owl_global *g)
971{
972  return(&(g->startup_tio));
973}
[8e401cae]974
[df0138f]975owl_list *owl_global_get_io_dispatch_list(owl_global *g)
976{
977  return &(g->io_dispatch_list);
978}
979
[4f2166b]980owl_list *owl_global_get_psa_list(owl_global *g)
981{
982  return &(g->psa_list);
983}
984
[58d1f8a]985GList **owl_global_get_timerlist(owl_global *g)
[b7bb454]986{
[58d1f8a]987  return &(g->timerlist);
[b7bb454]988}
[adee9cc]989
[8742840]990int owl_global_is_interrupted(const owl_global *g) {
[0cb6c26]991  return g->interrupted;
[adee9cc]992}
993
994void owl_global_set_interrupted(owl_global *g) {
995  g->interrupted = 1;
996}
997
998void owl_global_unset_interrupted(owl_global *g) {
999  g->interrupted = 0;
1000}
Note: See TracBrowser for help on using the repository browser.