source: global.c @ e8128c5

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