source: global.c @ db0ac7e

barnowl_perlaimdebianrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since db0ac7e was db0ac7e, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 13 years ago
Merged revisions 983-1032 via svnmerge from file:///afs/sipb.mit.edu/project/barnowl/src/svn/trunk ........ r985 | nelhage | 2008-03-11 12:38:20 -0400 (Tue, 11 Mar 2008) | 2 lines Generate less ugly error spew if a module fails to load ........ r986 | geofft | 2008-03-13 15:56:20 -0400 (Thu, 13 Mar 2008) | 1 line Added :webzephyr command with keybinding W. ........ r987 | asedeno | 2008-03-18 23:57:24 -0400 (Tue, 18 Mar 2008) | 2 lines Fix a race condition in which zephyrs received during init are not noticed until the next zephyr after entering the mainloop. ........ r988 | geofft | 2008-03-19 15:46:43 -0400 (Wed, 19 Mar 2008) | 6 lines IRC: explicitly include the network (-a $alias) in reply commands. This may be unnecessary because :irc-msg looks at getcurmsg() if it cannot automatically determine the network. ........ r989 | geofft | 2008-03-21 14:47:51 -0400 (Fri, 21 Mar 2008) | 1 line syntax error. ........ r990 | nelhage | 2008-03-26 02:24:26 -0400 (Wed, 26 Mar 2008) | 2 lines Fix sending jabbers to JIDs beginning with `+' ........ r994 | nelhage | 2008-03-29 17:02:05 -0400 (Sat, 29 Mar 2008) | 3 lines Compile zcrypt.c with -w so I don't get all these warnings in my compile output whenever I change any headers ........ r998 | geofft | 2008-03-31 01:59:47 -0400 (Mon, 31 Mar 2008) | 1 line Implement /me for outgoing IRC messages ........ r999 | geofft | 2008-03-31 09:58:56 -0400 (Mon, 31 Mar 2008) | 1 line I think this fixes the resizing bug. ........ r1000 | nelhage | 2008-03-31 11:29:29 -0400 (Mon, 31 Mar 2008) | 2 lines Make `svkversion' handle exported trees better ........ r1001 | nelhage | 2008-03-31 11:52:39 -0400 (Mon, 31 Mar 2008) | 2 lines Add a makefile rule to support emacs flymake-mode ........ r1015 | nelhage | 2008-04-04 14:58:45 -0400 (Fri, 04 Apr 2008) | 3 lines Bind the combinations the iPhone sends for arrow keys [probably other terminals, too] ........ r1018 | shadow | 2008-04-08 13:57:49 -0400 (Tue, 08 Apr 2008) | 2 lines avoid null pointer dereference if msg is NULL (or a 0 length is claimed) ........ r1019 | nelhage | 2008-04-09 18:08:26 -0400 (Wed, 09 Apr 2008) | 2 lines Fix some stupid typos ........ r1020 | chmrr | 2008-04-09 18:16:02 -0400 (Wed, 09 Apr 2008) | 3 lines r29300@kohr-ah: chmrr | 2008-04-09 18:14:37 -0400 * It's apparently a popular typo ........ r1022 | asedeno | 2008-04-16 17:05:36 -0400 (Wed, 16 Apr 2008) | 2 lines Jabber reply bugfix. Reported by several people, resolved by arolfe. ........ r1023 | nelhage | 2008-04-28 23:33:03 -0400 (Mon, 28 Apr 2008) | 3 lines Initialized merge tracking via "svnmerge" with revisions "735" from svn+ssh://lunatique.mit.edu/mit/barnowl/src/svn/branches/barnowl_unicode ........ r1024 | nelhage | 2008-04-28 23:33:12 -0400 (Mon, 28 Apr 2008) | 3 lines Initialized merge tracking via "svnmerge" with revisions "735" from svn+ssh://lunatique.mit.edu/mit/barnowl/src/svn/branches/barnowl_sqlite ........ r1025 | nelhage | 2008-04-29 01:21:12 -0400 (Tue, 29 Apr 2008) | 2 lines Clone owl_perl from the sqlite branch because I'm about to make use of it. ........ r1026 | nelhage | 2008-04-29 01:21:13 -0400 (Tue, 29 Apr 2008) | 4 lines Initial step of moving styles from the current mishmash of different options to a unified object interface. No backwards-compatibility support yet. ........ r1027 | nelhage | 2008-04-29 01:21:15 -0400 (Tue, 29 Apr 2008) | 2 lines Implement back-compat with old-style owl::format_msg() styles ........ r1028 | nelhage | 2008-04-29 01:21:16 -0400 (Tue, 29 Apr 2008) | 2 lines Remove nearly all references to the "basic" style. ........ r1029 | nelhage | 2008-04-29 01:21:17 -0400 (Tue, 29 Apr 2008) | 2 lines Support the `style' command again. Note that it is deprecated. ........ r1031 | nelhage | 2008-04-30 13:29:45 -0400 (Wed, 30 Apr 2008) | 2 lines Refactor default style code somewhat to be more easily extensible ........
  • Property mode set to 100644
File size: 19.7 KB
Line 
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
11static const char fileIdent[] = "$Id$";
12
13#ifndef MAXHOSTNAMELEN
14#define MAXHOSTNAMELEN 256
15#endif
16
17void owl_global_init(owl_global *g) {
18  struct hostent *hent;
19  char hostname[MAXHOSTNAMELEN];
20  char *cd;
21
22  g->malloced=0;
23  g->freed=0;
24
25  gethostname(hostname, MAXHOSTNAMELEN);
26  hent=gethostbyname(hostname);
27  if (!hent) {
28    g->thishost=owl_strdup("localhost");
29  } else {
30    g->thishost=owl_strdup(hent->h_name);
31  }
32
33  owl_context_init(&g->ctx);
34  owl_context_set_startup(&g->ctx);
35  g->curmsg=0;
36  g->topmsg=0;
37  g->needrefresh=1;
38  g->startupargs=NULL;
39
40  owl_variable_dict_setup(&(g->vars));
41  owl_cmddict_setup(&(g->cmds));
42
43  g->lines=LINES;
44  g->cols=COLS;
45
46  g->rightshift=0;
47
48  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
49
50  owl_keyhandler_init(&g->kh);
51  owl_keys_setup_keymaps(&g->kh);
52
53  owl_list_create(&(g->muxevents));
54  owl_list_create(&(g->filterlist));
55  owl_list_create(&(g->puntlist));
56  owl_list_create(&(g->messagequeue));
57  owl_dict_create(&(g->styledict));
58  g->curmsg_vert_offset=0;
59  g->resizepending=0;
60  g->typwinactive=0;
61  g->direction=OWL_DIRECTION_DOWNWARDS;
62  g->zaway=0;
63  if (has_colors()) {
64    g->hascolors=1;
65  }
66  g->colorpairs=COLOR_PAIRS;
67  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
68  g->debug=OWL_DEBUG;
69  g->searchactive=0;
70  g->searchstring=NULL;
71  g->starttime=time(NULL); /* assumes we call init only a start time */
72  g->lastinputtime=g->starttime;
73  g->newmsgproc_pid=0;
74 
75  owl_global_set_config_format(g, 0);
76  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
77  owl_global_set_no_have_config(g);
78  owl_history_init(&(g->msghist));
79  owl_history_init(&(g->cmdhist));
80  owl_history_set_norepeats(&(g->cmdhist));
81  g->nextmsgid=0;
82
83  _owl_global_setup_windows(g);
84
85  /* Fill in some variables which don't have constant defaults */
86  /* TODO: come back later and check passwd file first */
87  g->homedir=owl_strdup(getenv("HOME"));
88
89  g->confdir = NULL;
90  g->startupfile = NULL;
91  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
92  owl_global_set_confdir(g, cd);
93  owl_free(cd);
94
95  owl_messagelist_create(&(g->msglist));
96  owl_mainwin_init(&(g->mw));
97  owl_popwin_init(&(g->pw));
98
99  g->aim_screenname=NULL;
100  g->aim_loggedin=0;
101  owl_timer_create_countdown(&(g->aim_noop_timer), 30);
102  owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);
103  owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);
104  owl_buddylist_init(&(g->buddylist));
105   
106  g->havezephyr=0;
107  g->haveaim=0;
108  owl_global_set_no_doaimevents(g);
109
110  owl_errqueue_init(&(g->errqueue));
111  g->got_err_signal=0;
112
113  owl_zbuddylist_create(&(g->zbuddies));
114  owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
115
116  owl_obarray_init(&(g->obarray));
117
118  owl_message_init_fmtext_cache();
119  owl_list_create(&(g->dispatchlist));
120}
121
122void _owl_global_setup_windows(owl_global *g) {
123  int cols, typwin_lines;
124
125  cols=g->cols;
126  typwin_lines=owl_global_get_typwin_lines(g);
127
128  /* set the new window sizes */
129  g->recwinlines=g->lines-(typwin_lines+2);
130  if (g->recwinlines<0) {
131    /* gotta deal with this */
132    g->recwinlines=0;
133  }
134
135  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
136
137  /* create the new windows */
138  g->recwin=newwin(g->recwinlines, cols, 0, 0);
139  if (g->recwin==NULL) {
140    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n", g->recwinlines, cols);
141    endwin();
142    exit(50);
143  }
144     
145  g->sepwin=newwin(1, cols, g->recwinlines, 0);
146  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
147  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
148
149  owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols);
150
151  idlok(g->typwin, FALSE);
152  idlok(g->recwin, FALSE);
153  idlok(g->sepwin, FALSE);
154  idlok(g->msgwin, FALSE);
155
156  nodelay(g->typwin, 1);
157  keypad(g->typwin, TRUE);
158  wmove(g->typwin, 0, 0);
159
160  meta(g->typwin, TRUE);
161}
162
163owl_context *owl_global_get_context(owl_global *g) {
164  return(&g->ctx);
165}
166                         
167int owl_global_get_lines(owl_global *g) {
168  return(g->lines);
169}
170
171int owl_global_get_cols(owl_global *g) {
172  return(g->cols);
173}
174
175int owl_global_get_recwin_lines(owl_global *g) {
176  return(g->recwinlines);
177}
178
179/* curmsg */
180
181int owl_global_get_curmsg(owl_global *g) {
182  return(g->curmsg);
183}
184
185void owl_global_set_curmsg(owl_global *g, int i) {
186  g->curmsg=i;
187  /* we will reset the vertical offset from here */
188  /* we might want to move this out to the functions later */
189  owl_global_set_curmsg_vert_offset(g, 0);
190}
191
192/* topmsg */
193
194int owl_global_get_topmsg(owl_global *g) {
195  return(g->topmsg);
196}
197
198void owl_global_set_topmsg(owl_global *g, int i) {
199  g->topmsg=i;
200}
201
202/* windows */
203
204owl_mainwin *owl_global_get_mainwin(owl_global *g) {
205  return(&(g->mw));
206}
207
208owl_popwin *owl_global_get_popwin(owl_global *g) {
209  return(&(g->pw));
210}
211
212/* msglist */
213
214owl_messagelist *owl_global_get_msglist(owl_global *g) {
215  return(&(g->msglist));
216}
217
218/* keyhandler */
219
220owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
221  return(&(g->kh));
222}
223
224/* curses windows */
225
226WINDOW *owl_global_get_curs_recwin(owl_global *g) {
227  return(g->recwin);
228}
229
230WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
231  return(g->sepwin);
232}
233
234WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
235  return(g->msgwin);
236}
237
238WINDOW *owl_global_get_curs_typwin(owl_global *g) {
239  return(g->typwin);
240}
241
242/* typwin */
243
244owl_editwin *owl_global_get_typwin(owl_global *g) {
245  return(&(g->tw));
246}
247
248/* buffercommand */
249
250void owl_global_set_buffercommand(owl_global *g, char *command) {
251  owl_editwin_set_command(owl_global_get_typwin(g), command);
252}
253
254char *owl_global_get_buffercommand(owl_global *g) {
255  return owl_editwin_get_command(owl_global_get_typwin(g));
256}
257
258void owl_global_set_buffercallback(owl_global *g, void (*cb)(owl_editwin*)) {
259  owl_editwin_set_callback(owl_global_get_typwin(g), cb);
260}
261
262void (*owl_global_get_buffercallback(owl_global *g))(owl_editwin*) {
263  return owl_editwin_get_callback(owl_global_get_typwin(g));
264}
265
266/* refresh */
267
268int owl_global_is_needrefresh(owl_global *g) {
269  if (g->needrefresh==1) return(1);
270  return(0);
271}
272
273void owl_global_set_needrefresh(owl_global *g) {
274  g->needrefresh=1;
275}
276
277void owl_global_set_noneedrefresh(owl_global *g) {
278  g->needrefresh=0;
279}
280
281/* variable dictionary */
282
283owl_vardict *owl_global_get_vardict(owl_global *g) {
284  return &(g->vars);
285}
286
287/* command dictionary */
288
289owl_cmddict *owl_global_get_cmddict(owl_global *g) {
290  return &(g->cmds);
291}
292
293/* rightshift */
294
295void owl_global_set_rightshift(owl_global *g, int i) {
296  g->rightshift=i;
297}
298
299int owl_global_get_rightshift(owl_global *g) {
300  return(g->rightshift);
301}
302
303/* typwin */
304
305int owl_global_is_typwin_active(owl_global *g) {
306  if (g->typwinactive==1) return(1);
307  return(0);
308}
309
310void owl_global_set_typwin_active(owl_global *g) {
311  g->typwinactive=1;
312}
313
314void owl_global_set_typwin_inactive(owl_global *g) {
315  g->typwinactive=0;
316}
317
318/* resize */
319
320void owl_global_set_resize_pending(owl_global *g) {
321  g->resizepending=1;
322}
323
324char *owl_global_get_homedir(owl_global *g) {
325  if (g->homedir) return(g->homedir);
326  return("/");
327}
328
329char *owl_global_get_confdir(owl_global *g) {
330  if (g->confdir) return(g->confdir);
331  return("/");
332}
333
334/*
335 * Setting this also sets startupfile to confdir/startup
336 */
337void owl_global_set_confdir(owl_global *g, char *cd) {
338  free(g->confdir);
339  g->confdir = owl_strdup(cd);
340  free(g->startupfile);
341  g->startupfile = owl_sprintf("%s/startup", cd);
342}
343
344char *owl_global_get_startupfile(owl_global *g) {
345  if(g->startupfile) return(g->startupfile);
346  return("/");
347}
348
349int owl_global_get_direction(owl_global *g) {
350  return(g->direction);
351}
352
353void owl_global_set_direction_downwards(owl_global *g) {
354  g->direction=OWL_DIRECTION_DOWNWARDS;
355}
356
357void owl_global_set_direction_upwards(owl_global *g) {
358  g->direction=OWL_DIRECTION_UPWARDS;
359}
360
361/* perl stuff */
362
363void owl_global_set_perlinterp(owl_global *g, void *p) {
364  g->perl=p;
365}
366
367void *owl_global_get_perlinterp(owl_global *g) {
368  return(g->perl);
369}
370
371int owl_global_is_config_format(owl_global *g) {
372  if (g->config_format) return(1);
373  return(0);
374}
375
376void owl_global_set_config_format(owl_global *g, int state) {
377  if (state==1) {
378    g->config_format=1;
379  } else {
380    g->config_format=0;
381  }
382}
383
384void owl_global_set_have_config(owl_global *g) {
385  g->haveconfig=1;
386}
387
388void owl_global_set_no_have_config(owl_global *g) {
389  g->haveconfig=0;
390}
391
392int owl_global_have_config(owl_global *g) {
393  if (g->haveconfig) return(1);
394  return(0);
395}
396
397void owl_global_resize(owl_global *g, int x, int y) {
398  /* resize the screen.  If x or y is 0 use the terminal size */
399  struct winsize size;
400   
401  if (!g->resizepending) return;
402
403  /* delete the current windows */
404  delwin(g->recwin);
405  delwin(g->sepwin);
406  delwin(g->msgwin);
407  delwin(g->typwin);
408  if (!isendwin()) {
409    endwin();
410  }
411
412  refresh();
413
414  /* get the new size */
415  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
416  if (x==0) {
417    if (size.ws_row) {
418      g->lines=size.ws_row;
419    } else {
420      g->lines=LINES;
421    } 
422  } else {
423      g->lines=x;
424  }
425
426  if (y==0) {
427    if (size.ws_col) {
428      g->cols=size.ws_col;
429    } else {
430      g->cols=COLS;
431    } 
432  } else {
433    g->cols=y;
434  }
435
436#ifdef HAVE_RESIZETERM
437  resizeterm(size.ws_row, size.ws_col);
438#endif
439
440  /* re-initialize the windows */
441  _owl_global_setup_windows(g);
442
443  /* in case any styles rely on the current width */
444  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
445
446  /* recalculate the topmsg to make sure the current message is on
447   * screen */
448  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
449
450  /* refresh stuff */
451  g->needrefresh=1;
452  owl_mainwin_redisplay(&(g->mw));
453  sepbar(NULL);
454  owl_editwin_redisplay(&(g->tw), 0);
455  owl_function_full_redisplay(&g);
456
457  /* TODO: this should handle other forms of popwins */
458  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
459      && owl_global_get_viewwin(g)) {
460    owl_popwin_refresh(owl_global_get_popwin(g));
461    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
462  }
463
464  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
465  owl_function_makemsg("");
466  g->resizepending=0;
467}
468
469/* debug */
470
471int owl_global_is_debug_fast(owl_global *g) {
472  if (g->debug) return(1);
473  return(0);
474}
475
476/* starttime */
477
478time_t owl_global_get_starttime(owl_global *g) {
479  return(g->starttime);
480}
481
482time_t owl_global_get_runtime(owl_global *g) {
483  return(time(NULL)-g->starttime);
484}
485
486time_t owl_global_get_lastinputtime(owl_global *g) {
487  return(g->lastinputtime);
488}
489
490void owl_global_set_lastinputtime(owl_global *g, time_t time) {
491  g->lastinputtime = time;
492}
493
494time_t owl_global_get_idletime(owl_global *g) {
495  return(time(NULL)-g->lastinputtime);
496}
497
498void owl_global_get_runtime_string(owl_global *g, char *buff) {
499  time_t diff;
500
501  diff=time(NULL)-owl_global_get_starttime(g);
502
503  /* print something nicer later */   
504  sprintf(buff, "%i seconds", (int) diff);
505}
506
507char *owl_global_get_hostname(owl_global *g) {
508  if (g->thishost) return(g->thishost);
509  return("");
510}
511
512/* userclue */
513
514void owl_global_set_userclue(owl_global *g, int clue) {
515  g->userclue=clue;
516}
517
518void owl_global_add_userclue(owl_global *g, int clue) {
519  g->userclue|=clue;
520}
521
522int owl_global_get_userclue(owl_global *g) {
523  return(g->userclue);
524}
525
526int owl_global_is_userclue(owl_global *g, int clue) {
527  if (g->userclue & clue) return(1);
528  return(0);
529}
530
531/* viewwin */
532
533owl_viewwin *owl_global_get_viewwin(owl_global *g) {
534  return(&(g->vw));
535}
536
537
538/* vert offset */
539
540int owl_global_get_curmsg_vert_offset(owl_global *g) {
541  return(g->curmsg_vert_offset);
542}
543
544void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
545  g->curmsg_vert_offset=i;
546}
547
548/* startup args */
549
550void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
551  int i, len;
552
553  if (g->startupargs) owl_free(g->startupargs);
554 
555  len=0;
556  for (i=0; i<argc; i++) {
557    len+=strlen(argv[i])+5;
558  }
559  g->startupargs=owl_malloc(len+5);
560
561  strcpy(g->startupargs, "");
562  for (i=0; i<argc; i++) {
563    sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]);
564  }
565  g->startupargs[strlen(g->startupargs)-1]='\0';
566}
567
568char *owl_global_get_startupargs(owl_global *g) {
569  if (g->startupargs) return(g->startupargs);
570  return("");
571}
572
573/* history */
574
575owl_history *owl_global_get_msg_history(owl_global *g) {
576  return(&(g->msghist));
577}
578
579owl_history *owl_global_get_cmd_history(owl_global *g) {
580  return(&(g->cmdhist));
581}
582
583/* muxevents */
584
585owl_muxevents *owl_global_get_muxevents(owl_global *g) {
586  return(&(g->muxevents));
587}
588
589/* filterlist */
590
591owl_list *owl_global_get_filterlist(owl_global *g) {
592  return(&(g->filterlist));
593}
594
595owl_filter *owl_global_get_filter(owl_global *g, char *name) {
596  int i, j;
597  owl_filter *f;
598
599  j=owl_list_get_size(&(g->filterlist));
600  for (i=0; i<j; i++) {
601    f=owl_list_get_element(&(g->filterlist), i);
602    if (!strcmp(name, owl_filter_get_name(f))) {
603      return(f);
604    }
605  }
606  return(NULL);
607}
608
609void owl_global_add_filter(owl_global *g, owl_filter *f) {
610  owl_list_append_element(&(g->filterlist), f);
611}
612
613void owl_global_remove_filter(owl_global *g, char *name) {
614  int i, j;
615  owl_filter *f;
616
617  j=owl_list_get_size(&(g->filterlist));
618  for (i=0; i<j; i++) {
619    f=owl_list_get_element(&(g->filterlist), i);
620    if (!strcmp(name, owl_filter_get_name(f))) {
621      owl_filter_free(f);
622      owl_list_remove_element(&(g->filterlist), i);
623      break;
624    }
625  }
626}
627
628/* nextmsgid */
629
630int owl_global_get_nextmsgid(owl_global *g) {
631  return(g->nextmsgid++);
632}
633
634/* current view */
635
636owl_view *owl_global_get_current_view(owl_global *g) {
637  return(&(g->current_view));
638}
639
640/* has colors */
641
642int owl_global_get_hascolors(owl_global *g) {
643  if (g->hascolors) return(1);
644  return(0);
645}
646
647/* color pairs */
648
649int owl_global_get_colorpairs(owl_global *g) {
650  return(g->colorpairs);
651}
652
653owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
654  return(&(g->cpmgr));
655}
656
657/* puntlist */
658
659owl_list *owl_global_get_puntlist(owl_global *g) {
660  return(&(g->puntlist));
661}
662
663int owl_global_message_is_puntable(owl_global *g, owl_message *m) {
664  owl_list *pl;
665  int i, j;
666
667  pl=owl_global_get_puntlist(g);
668  j=owl_list_get_size(pl);
669  for (i=0; i<j; i++) {
670    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
671  }
672  return(0);
673}
674
675int owl_global_should_followlast(owl_global *g) {
676  owl_view *v;
677 
678  if (!owl_global_is__followlast(g)) return(0);
679 
680  v=owl_global_get_current_view(g);
681 
682  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
683  return(0);
684}
685
686int owl_global_is_search_active(owl_global *g) {
687  if (g->searchactive) return(1);
688  return(0);
689}
690
691void owl_global_set_search_active(owl_global *g, char *string) {
692  g->searchactive=1;
693  if (g->searchstring != NULL) owl_free(g->searchstring);
694  g->searchstring=owl_strdup(string);
695}
696
697void owl_global_set_search_inactive(owl_global *g) {
698  g->searchactive=0;
699}
700
701char *owl_global_get_search_string(owl_global *g) {
702  if (g->searchstring==NULL) return("");
703  return(g->searchstring);
704}
705
706void owl_global_set_newmsgproc_pid(owl_global *g, int i) {
707  g->newmsgproc_pid=i;
708}
709
710int owl_global_get_newmsgproc_pid(owl_global *g) {
711  return(g->newmsgproc_pid);
712}
713
714void owl_global_add_to_malloced(owl_global *g, int i) {
715  g->malloced+=i;
716}
717
718void owl_global_add_to_freed(owl_global *g, int i) {
719  g->freed+=1;
720}
721
722int owl_global_get_malloced(owl_global *g) {
723  return(g->malloced);
724}
725
726int owl_global_get_freed(owl_global *g) {
727  return(g->freed);
728}
729
730int owl_global_get_meminuse(owl_global *g) {
731  return(g->malloced-g->freed);
732}
733
734/* AIM stuff */
735
736int owl_global_is_aimloggedin(owl_global *g)
737{
738  if (g->aim_loggedin) return(1);
739  return(0);
740}
741
742char *owl_global_get_aim_screenname(owl_global *g)
743{
744  if (owl_global_is_aimloggedin(g)) {
745    return (g->aim_screenname);
746  }
747  return("");
748}
749
750void owl_global_set_aimloggedin(owl_global *g, char *screenname)
751{
752  g->aim_loggedin=1;
753  if (g->aim_screenname) owl_free(g->aim_screenname);
754  g->aim_screenname=owl_strdup(screenname);
755}
756
757void owl_global_set_aimnologgedin(owl_global *g)
758{
759  g->aim_loggedin=0;
760}
761
762int owl_global_is_doaimevents(owl_global *g)
763{
764  if (g->aim_doprocessing) return(1);
765  return(0);
766}
767
768void owl_global_set_doaimevents(owl_global *g)
769{
770  g->aim_doprocessing=1;
771}
772
773void owl_global_set_no_doaimevents(owl_global *g)
774{
775  g->aim_doprocessing=0;
776}
777
778aim_session_t *owl_global_get_aimsess(owl_global *g)
779{
780  return(&(g->aimsess));
781}
782
783aim_conn_t *owl_global_get_bosconn(owl_global *g)
784{
785  return(&(g->bosconn));
786}
787
788void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
789{
790  g->bosconn=*conn;
791}
792
793int owl_global_is_aimnop_time(owl_global *g)
794{
795  if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);
796  return(0);
797}
798
799void owl_global_aimnop_sent(owl_global *g)
800{
801  owl_timer_reset(&(g->aim_noop_timer));
802}
803
804owl_timer *owl_global_get_aim_login_timer(owl_global *g)
805{
806  return(&(g->aim_ignorelogin_timer));
807}
808
809/* message queue */
810
811void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
812{
813  owl_list_append_element(&(g->messagequeue), m);
814}
815
816/* pop off the first message and return it.  Return NULL if the queue
817 * is empty.  The caller should free the message after using it, if
818 * necessary.
819 */
820owl_message *owl_global_messagequeue_popmsg(owl_global *g)
821{
822  owl_message *out;
823
824  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
825  out=owl_list_get_element(&(g->messagequeue), 0);
826  owl_list_remove_element(&(g->messagequeue), 0);
827  return(out);
828}
829
830int owl_global_messagequeue_pending(owl_global *g)
831{
832  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
833  return(1);
834}
835
836owl_buddylist *owl_global_get_buddylist(owl_global *g)
837{
838  return(&(g->buddylist));
839}
840 
841/* style */
842
843/* Return the style with name 'name'.  If it does not exist return
844 * NULL */
845owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
846{
847  return owl_dict_find_element(&(g->styledict), name);
848}
849
850/* creates a list and fills it in with keys.  duplicates the keys,
851 * so they will need to be freed by the caller. */
852int owl_global_get_style_names(owl_global *g, owl_list *l) {
853  return owl_dict_get_keys(&(g->styledict), l);
854}
855
856void owl_global_add_style(owl_global *g, owl_style *s)
857{
858  /*
859   * If we're redefining the current style, make sure to update
860   * pointers to it.
861   */
862  if(g->current_view.style
863     && !strcmp(owl_style_get_name(g->current_view.style),
864                owl_style_get_name(s)))
865    g->current_view.style = s;
866  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
867                          s, (void(*)(void*))owl_style_free);
868}
869
870void owl_global_set_haveaim(owl_global *g)
871{
872  g->haveaim=1;
873}
874
875int owl_global_is_haveaim(owl_global *g)
876{
877  if (g->haveaim) return(1);
878  return(0);
879}
880
881void owl_global_set_havezephyr(owl_global *g)
882{
883  g->havezephyr=1;
884}
885
886int owl_global_is_havezephyr(owl_global *g)
887{
888  if (g->havezephyr) return(1);
889  return(0);
890}
891
892owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)
893{
894  return(&(g->aim_buddyinfo_timer));
895}
896
897owl_errqueue *owl_global_get_errqueue(owl_global *g)
898{
899  return(&(g->errqueue));
900}
901
902void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
903{
904  g->got_err_signal = signum;
905  if (siginfo) {
906    g->err_signal_info = *siginfo;
907  } else {
908    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
909  }
910}
911
912int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
913{
914  int signum;
915  if (siginfo && g->got_err_signal) {
916    *siginfo = g->err_signal_info;
917  } 
918  signum = g->got_err_signal;
919  g->got_err_signal = 0;
920  return signum;
921}
922
923owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)
924{
925  return(&(g->zephyr_buddycheck_timer));
926}
927
928owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
929{
930  return(&(g->zbuddies));
931}
932
933struct termios *owl_global_get_startup_tio(owl_global *g)
934{
935  return(&(g->startup_tio));
936}
937
938char * owl_global_intern(owl_global *g, char * string)
939{
940  return owl_obarray_insert(&(g->obarray), string);
941}
942
943owl_list *owl_global_get_dispatchlist(owl_global *g)
944{
945  return &(g->dispatchlist);
946}
Note: See TracBrowser for help on using the repository browser.