source: global.c @ 4dd115f

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