source: global.c @ 044f19f

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