source: global.c @ 7e78e49

debianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7e78e49 was da466e0, checked in by Geoffrey Thomas <geofft@mit.edu>, 16 years ago
At broder/ccpost's suggestion, add a typewindelta variable that lets you expand the typewin on small screens when it is active, and keep it small by default.
  • Property mode set to 100644
File size: 20.4 KB
RevLine 
[7d4fbcd]1#include <stdio.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <termios.h>
7#include <sys/ioctl.h>
8#include <time.h>
9#include "owl.h"
10
[1aee7d9]11static const char fileIdent[] = "$Id$";
12
[7d4fbcd]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];
[ad15610]20  char *cd;
[7d4fbcd]21
[8262340]22  g->malloced=0;
23  g->freed=0;
24
[7d4fbcd]25  gethostname(hostname, MAXHOSTNAMELEN);
26  hent=gethostbyname(hostname);
27  if (!hent) {
[a8938c7]28    g->thishost=owl_strdup("localhost");
[7d4fbcd]29  } else {
[a8938c7]30    g->thishost=owl_strdup(hent->h_name);
[7d4fbcd]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;
[a8938c7]38  g->startupargs=NULL;
[7d4fbcd]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
[10b866d]48  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
[7d4fbcd]49
50  owl_keyhandler_init(&g->kh);
51  owl_keys_setup_keymaps(&g->kh);
52
[afbf668]53  owl_list_create(&(g->muxevents));
[7d4fbcd]54  owl_list_create(&(g->filterlist));
55  owl_list_create(&(g->puntlist));
[d09e5a1]56  owl_list_create(&(g->messagequeue));
[f1e629d]57  owl_dict_create(&(g->styledict));
[7d4fbcd]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;
[8fa9562]67  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
[7d4fbcd]68  g->debug=OWL_DEBUG;
[1fd0b25]69  g->searchactive=0;
70  g->searchstring=NULL;
[7d4fbcd]71  g->starttime=time(NULL); /* assumes we call init only a start time */
[7f792c1]72  g->lastinputtime=g->starttime;
[700c712]73  g->newmsgproc_pid=0;
[61e79a9]74 
[7d4fbcd]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);
[10b866d]78  owl_history_init(&(g->msghist));
79  owl_history_init(&(g->cmdhist));
[5a9f6fe]80  owl_history_set_norepeats(&(g->cmdhist));
[7d4fbcd]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 */
[a8938c7]87  g->homedir=owl_strdup(getenv("HOME"));
[7d4fbcd]88
[b363d83]89  g->confdir = NULL;
90  g->startupfile = NULL;
[ad15610]91  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
[b363d83]92  owl_global_set_confdir(g, cd);
93  owl_free(cd);
94
[7d4fbcd]95  owl_messagelist_create(&(g->msglist));
96  owl_mainwin_init(&(g->mw));
97  owl_popwin_init(&(g->pw));
[d09e5a1]98
99  g->aim_screenname=NULL;
[81655f8]100  g->aim_screenname_for_filters=NULL;
[d09e5a1]101  g->aim_loggedin=0;
[6a415e9]102  owl_timer_create_countdown(&(g->aim_noop_timer), 30);
103  owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);
[de03334]104  owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);
[aa5f725]105  owl_buddylist_init(&(g->buddylist));
[2404c3a]106   
[09489b89]107  g->havezephyr=0;
108  g->haveaim=0;
[a352335c]109  owl_global_set_no_doaimevents(g);
[ec6ff52]110
111  owl_errqueue_init(&(g->errqueue));
[c9e72d1]112  g->got_err_signal=0;
[5a95b69]113
114  owl_zbuddylist_create(&(g->zbuddies));
115  owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
[8e401cae]116
117  owl_obarray_init(&(g->obarray));
[a387d12e]118
119  owl_message_init_fmtext_cache();
[9c7a701]120  owl_list_create(&(g->dispatchlist));
[7d4fbcd]121}
122
123void _owl_global_setup_windows(owl_global *g) {
[ecd5dc5]124  int cols, typwin_lines;
[7d4fbcd]125
126  cols=g->cols;
[ecd5dc5]127  typwin_lines=owl_global_get_typwin_lines(g);
[7d4fbcd]128
129  /* set the new window sizes */
130  g->recwinlines=g->lines-(typwin_lines+2);
[176d3443]131  if (g->recwinlines<0) {
132    /* gotta deal with this */
133    g->recwinlines=0;
[ecd5dc5]134  }
[7d4fbcd]135
[176d3443]136  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
137
[7d4fbcd]138  /* create the new windows */
139  g->recwin=newwin(g->recwinlines, cols, 0, 0);
[ecd5dc5]140  if (g->recwin==NULL) {
[176d3443]141    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n", g->recwinlines, cols);
[ecd5dc5]142    endwin();
143    exit(50);
144  }
145     
[7d4fbcd]146  g->sepwin=newwin(1, cols, g->recwinlines, 0);
147  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
148  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
149
150  owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols);
151
152  idlok(g->typwin, FALSE);
153  idlok(g->recwin, FALSE);
154  idlok(g->sepwin, FALSE);
155  idlok(g->msgwin, FALSE);
156
157  nodelay(g->typwin, 1);
158  keypad(g->typwin, TRUE);
159  wmove(g->typwin, 0, 0);
160
161  meta(g->typwin, TRUE);
162}
163
164owl_context *owl_global_get_context(owl_global *g) {
165  return(&g->ctx);
166}
167                         
168int owl_global_get_lines(owl_global *g) {
169  return(g->lines);
170}
171
172int owl_global_get_cols(owl_global *g) {
173  return(g->cols);
174}
175
176int owl_global_get_recwin_lines(owl_global *g) {
177  return(g->recwinlines);
178}
179
180/* curmsg */
181
182int owl_global_get_curmsg(owl_global *g) {
183  return(g->curmsg);
184}
185
186void owl_global_set_curmsg(owl_global *g, int i) {
187  g->curmsg=i;
188  /* we will reset the vertical offset from here */
189  /* we might want to move this out to the functions later */
190  owl_global_set_curmsg_vert_offset(g, 0);
191}
192
193/* topmsg */
194
195int owl_global_get_topmsg(owl_global *g) {
196  return(g->topmsg);
197}
198
199void owl_global_set_topmsg(owl_global *g, int i) {
200  g->topmsg=i;
201}
202
203/* windows */
204
205owl_mainwin *owl_global_get_mainwin(owl_global *g) {
206  return(&(g->mw));
207}
208
209owl_popwin *owl_global_get_popwin(owl_global *g) {
210  return(&(g->pw));
211}
212
213/* msglist */
214
215owl_messagelist *owl_global_get_msglist(owl_global *g) {
216  return(&(g->msglist));
217}
218
219/* keyhandler */
220
221owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
222  return(&(g->kh));
223}
224
225/* curses windows */
226
227WINDOW *owl_global_get_curs_recwin(owl_global *g) {
228  return(g->recwin);
229}
230
231WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
232  return(g->sepwin);
233}
234
235WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
236  return(g->msgwin);
237}
238
239WINDOW *owl_global_get_curs_typwin(owl_global *g) {
240  return(g->typwin);
241}
242
243/* typwin */
244
245owl_editwin *owl_global_get_typwin(owl_global *g) {
246  return(&(g->tw));
247}
248
249/* buffercommand */
250
251void owl_global_set_buffercommand(owl_global *g, char *command) {
[1b6b2f3]252  owl_editwin_set_command(owl_global_get_typwin(g), command);
[7d4fbcd]253}
254
255char *owl_global_get_buffercommand(owl_global *g) {
[1b6b2f3]256  return owl_editwin_get_command(owl_global_get_typwin(g));
[7d4fbcd]257}
258
[1b6b2f3]259void owl_global_set_buffercallback(owl_global *g, void (*cb)(owl_editwin*)) {
260  owl_editwin_set_callback(owl_global_get_typwin(g), cb);
[4211f50b]261}
262
[1b6b2f3]263void (*owl_global_get_buffercallback(owl_global *g))(owl_editwin*) {
264  return owl_editwin_get_callback(owl_global_get_typwin(g));
[4211f50b]265}
266
[7d4fbcd]267/* refresh */
268
269int owl_global_is_needrefresh(owl_global *g) {
270  if (g->needrefresh==1) return(1);
271  return(0);
272}
273
274void owl_global_set_needrefresh(owl_global *g) {
275  g->needrefresh=1;
276}
277
278void owl_global_set_noneedrefresh(owl_global *g) {
279  g->needrefresh=0;
280}
281
282/* variable dictionary */
283
284owl_vardict *owl_global_get_vardict(owl_global *g) {
285  return &(g->vars);
286}
287
288/* command dictionary */
289
290owl_cmddict *owl_global_get_cmddict(owl_global *g) {
291  return &(g->cmds);
292}
293
294/* rightshift */
295
296void owl_global_set_rightshift(owl_global *g, int i) {
297  g->rightshift=i;
298}
299
300int owl_global_get_rightshift(owl_global *g) {
301  return(g->rightshift);
302}
303
304/* typwin */
305
306int owl_global_is_typwin_active(owl_global *g) {
307  if (g->typwinactive==1) return(1);
308  return(0);
309}
310
311void owl_global_set_typwin_active(owl_global *g) {
[da466e0]312  int d = owl_global_get_typewindelta(g);
313  if (d > 0)
314      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
315
[7d4fbcd]316  g->typwinactive=1;
317}
318
319void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]320  int d = owl_global_get_typewindelta(g);
321  if (d > 0)
322      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
323
[7d4fbcd]324  g->typwinactive=0;
325}
326
327/* resize */
328
329void owl_global_set_resize_pending(owl_global *g) {
330  g->resizepending=1;
331}
332
333char *owl_global_get_homedir(owl_global *g) {
[a8938c7]334  if (g->homedir) return(g->homedir);
335  return("/");
[7d4fbcd]336}
337
[b363d83]338char *owl_global_get_confdir(owl_global *g) {
339  if (g->confdir) return(g->confdir);
340  return("/");
341}
342
343/*
344 * Setting this also sets startupfile to confdir/startup
345 */
346void owl_global_set_confdir(owl_global *g, char *cd) {
347  free(g->confdir);
348  g->confdir = owl_strdup(cd);
349  free(g->startupfile);
350  g->startupfile = owl_sprintf("%s/startup", cd);
351}
352
353char *owl_global_get_startupfile(owl_global *g) {
354  if(g->startupfile) return(g->startupfile);
355  return("/");
356}
357
[7d4fbcd]358int owl_global_get_direction(owl_global *g) {
359  return(g->direction);
360}
361
362void owl_global_set_direction_downwards(owl_global *g) {
363  g->direction=OWL_DIRECTION_DOWNWARDS;
364}
365
366void owl_global_set_direction_upwards(owl_global *g) {
367  g->direction=OWL_DIRECTION_UPWARDS;
368}
369
370/* perl stuff */
371
372void owl_global_set_perlinterp(owl_global *g, void *p) {
373  g->perl=p;
374}
375
376void *owl_global_get_perlinterp(owl_global *g) {
377  return(g->perl);
378}
379
380int owl_global_is_config_format(owl_global *g) {
381  if (g->config_format) return(1);
382  return(0);
383}
384
385void owl_global_set_config_format(owl_global *g, int state) {
386  if (state==1) {
387    g->config_format=1;
388  } else {
389    g->config_format=0;
390  }
391}
392
393void owl_global_set_have_config(owl_global *g) {
394  g->haveconfig=1;
395}
396
397void owl_global_set_no_have_config(owl_global *g) {
398  g->haveconfig=0;
399}
400
401int owl_global_have_config(owl_global *g) {
402  if (g->haveconfig) return(1);
403  return(0);
404}
405
406void owl_global_resize(owl_global *g, int x, int y) {
407  /* resize the screen.  If x or y is 0 use the terminal size */
408  struct winsize size;
409   
410  if (!g->resizepending) return;
411
412  /* delete the current windows */
413  delwin(g->recwin);
414  delwin(g->sepwin);
415  delwin(g->msgwin);
416  delwin(g->typwin);
417  if (!isendwin()) {
418    endwin();
419  }
420
421  refresh();
422
423  /* get the new size */
424  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
425  if (x==0) {
[054894e]426    if (size.ws_row) {
427      g->lines=size.ws_row;
428    } else {
429      g->lines=LINES;
430    } 
[7d4fbcd]431  } else {
[054894e]432      g->lines=x;
[7d4fbcd]433  }
434
435  if (y==0) {
[054894e]436    if (size.ws_col) {
437      g->cols=size.ws_col;
438    } else {
439      g->cols=COLS;
440    } 
[7d4fbcd]441  } else {
442    g->cols=y;
443  }
444
[1bdffcb]445#ifdef HAVE_RESIZETERM
[74037d9]446  resizeterm(size.ws_row, size.ws_col);
[1bdffcb]447#endif
[7d4fbcd]448
449  /* re-initialize the windows */
450  _owl_global_setup_windows(g);
451
[f1e629d]452  /* in case any styles rely on the current width */
453  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
454
[c0f9e30]455  /* recalculate the topmsg to make sure the current message is on
456   * screen */
457  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
458
[7d4fbcd]459  /* refresh stuff */
460  g->needrefresh=1;
461  owl_mainwin_redisplay(&(g->mw));
462  sepbar(NULL);
[b24029a]463  owl_editwin_redisplay(&(g->tw), 0);
[8aa83ea3]464  owl_function_full_redisplay(&g);
[7d4fbcd]465
466  /* TODO: this should handle other forms of popwins */
467  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
468      && owl_global_get_viewwin(g)) {
469    owl_popwin_refresh(owl_global_get_popwin(g));
470    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
471  }
472
[ecd5dc5]473  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
[7d4fbcd]474  owl_function_makemsg("");
475  g->resizepending=0;
476}
477
478/* debug */
479
480int owl_global_is_debug_fast(owl_global *g) {
481  if (g->debug) return(1);
482  return(0);
483}
484
485/* starttime */
486
487time_t owl_global_get_starttime(owl_global *g) {
488  return(g->starttime);
489}
490
491time_t owl_global_get_runtime(owl_global *g) {
492  return(time(NULL)-g->starttime);
493}
494
[7f792c1]495time_t owl_global_get_lastinputtime(owl_global *g) {
496  return(g->lastinputtime);
497}
498
[eebef19]499void owl_global_set_lastinputtime(owl_global *g, time_t time) {
500  g->lastinputtime = time;
[7f792c1]501}
502
503time_t owl_global_get_idletime(owl_global *g) {
504  return(time(NULL)-g->lastinputtime);
505}
506
[7d4fbcd]507void owl_global_get_runtime_string(owl_global *g, char *buff) {
508  time_t diff;
509
510  diff=time(NULL)-owl_global_get_starttime(g);
511
512  /* print something nicer later */   
513  sprintf(buff, "%i seconds", (int) diff);
514}
515
[61e79a9]516char *owl_global_get_hostname(owl_global *g) {
[a8938c7]517  if (g->thishost) return(g->thishost);
518  return("");
[61e79a9]519}
520
[7d4fbcd]521/* userclue */
522
523void owl_global_set_userclue(owl_global *g, int clue) {
524  g->userclue=clue;
525}
526
527void owl_global_add_userclue(owl_global *g, int clue) {
528  g->userclue|=clue;
529}
530
531int owl_global_get_userclue(owl_global *g) {
532  return(g->userclue);
533}
534
535int owl_global_is_userclue(owl_global *g, int clue) {
536  if (g->userclue & clue) return(1);
537  return(0);
538}
539
540/* viewwin */
541
542owl_viewwin *owl_global_get_viewwin(owl_global *g) {
543  return(&(g->vw));
544}
545
546
547/* vert offset */
548
549int owl_global_get_curmsg_vert_offset(owl_global *g) {
550  return(g->curmsg_vert_offset);
551}
552
553void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
554  g->curmsg_vert_offset=i;
555}
556
557/* startup args */
558
559void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
[a8938c7]560  int i, len;
561
562  if (g->startupargs) owl_free(g->startupargs);
563 
564  len=0;
565  for (i=0; i<argc; i++) {
[591e6aa7]566    len+=strlen(argv[i])+5;
[a8938c7]567  }
[34509d5]568  g->startupargs=owl_malloc(len+5);
[7d4fbcd]569
570  strcpy(g->startupargs, "");
571  for (i=0; i<argc; i++) {
572    sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]);
573  }
574  g->startupargs[strlen(g->startupargs)-1]='\0';
575}
576
577char *owl_global_get_startupargs(owl_global *g) {
[a8938c7]578  if (g->startupargs) return(g->startupargs);
579  return("");
[7d4fbcd]580}
581
582/* history */
583
[10b866d]584owl_history *owl_global_get_msg_history(owl_global *g) {
585  return(&(g->msghist));
586}
587
588owl_history *owl_global_get_cmd_history(owl_global *g) {
589  return(&(g->cmdhist));
[7d4fbcd]590}
591
[afbf668]592/* muxevents */
593
594owl_muxevents *owl_global_get_muxevents(owl_global *g) {
595  return(&(g->muxevents));
596}
597
[7d4fbcd]598/* filterlist */
599
600owl_list *owl_global_get_filterlist(owl_global *g) {
601  return(&(g->filterlist));
602}
603
604owl_filter *owl_global_get_filter(owl_global *g, char *name) {
605  int i, j;
606  owl_filter *f;
607
608  j=owl_list_get_size(&(g->filterlist));
609  for (i=0; i<j; i++) {
610    f=owl_list_get_element(&(g->filterlist), i);
611    if (!strcmp(name, owl_filter_get_name(f))) {
612      return(f);
613    }
614  }
615  return(NULL);
616}
617
618void owl_global_add_filter(owl_global *g, owl_filter *f) {
619  owl_list_append_element(&(g->filterlist), f);
620}
621
622void owl_global_remove_filter(owl_global *g, char *name) {
623  int i, j;
624  owl_filter *f;
625
626  j=owl_list_get_size(&(g->filterlist));
627  for (i=0; i<j; i++) {
628    f=owl_list_get_element(&(g->filterlist), i);
629    if (!strcmp(name, owl_filter_get_name(f))) {
630      owl_filter_free(f);
631      owl_list_remove_element(&(g->filterlist), i);
632      break;
633    }
634  }
635}
636
637/* nextmsgid */
638
639int owl_global_get_nextmsgid(owl_global *g) {
640  return(g->nextmsgid++);
641}
642
643/* current view */
644
645owl_view *owl_global_get_current_view(owl_global *g) {
646  return(&(g->current_view));
647}
648
649/* has colors */
650
651int owl_global_get_hascolors(owl_global *g) {
652  if (g->hascolors) return(1);
653  return(0);
654}
655
656/* color pairs */
657
658int owl_global_get_colorpairs(owl_global *g) {
659  return(g->colorpairs);
660}
661
[8fa9562]662owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
663  return(&(g->cpmgr));
664}
665
[7d4fbcd]666/* puntlist */
667
668owl_list *owl_global_get_puntlist(owl_global *g) {
669  return(&(g->puntlist));
670}
671
672int owl_global_message_is_puntable(owl_global *g, owl_message *m) {
673  owl_list *pl;
674  int i, j;
675
676  pl=owl_global_get_puntlist(g);
677  j=owl_list_get_size(pl);
678  for (i=0; i<j; i++) {
679    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
680  }
681  return(0);
682}
683
684int owl_global_should_followlast(owl_global *g) {
685  owl_view *v;
686 
687  if (!owl_global_is__followlast(g)) return(0);
688 
689  v=owl_global_get_current_view(g);
690 
691  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
692  return(0);
693}
[1fd0b25]694
695int owl_global_is_search_active(owl_global *g) {
696  if (g->searchactive) return(1);
697  return(0);
698}
699
700void owl_global_set_search_active(owl_global *g, char *string) {
701  g->searchactive=1;
702  if (g->searchstring != NULL) owl_free(g->searchstring);
703  g->searchstring=owl_strdup(string);
704}
705
706void owl_global_set_search_inactive(owl_global *g) {
707  g->searchactive=0;
708}
709
710char *owl_global_get_search_string(owl_global *g) {
711  if (g->searchstring==NULL) return("");
712  return(g->searchstring);
713}
[700c712]714
715void owl_global_set_newmsgproc_pid(owl_global *g, int i) {
716  g->newmsgproc_pid=i;
717}
718
719int owl_global_get_newmsgproc_pid(owl_global *g) {
720  return(g->newmsgproc_pid);
721}
722
[8262340]723void owl_global_add_to_malloced(owl_global *g, int i) {
724  g->malloced+=i;
725}
726
727void owl_global_add_to_freed(owl_global *g, int i) {
728  g->freed+=1;
729}
730
731int owl_global_get_malloced(owl_global *g) {
732  return(g->malloced);
733}
734
735int owl_global_get_freed(owl_global *g) {
736  return(g->freed);
737}
738
739int owl_global_get_meminuse(owl_global *g) {
740  return(g->malloced-g->freed);
741}
[d09e5a1]742
743/* AIM stuff */
744
[6a415e9]745int owl_global_is_aimloggedin(owl_global *g)
746{
[d09e5a1]747  if (g->aim_loggedin) return(1);
748  return(0);
749}
750
[6a415e9]751char *owl_global_get_aim_screenname(owl_global *g)
752{
[a352335c]753  if (owl_global_is_aimloggedin(g)) {
754    return (g->aim_screenname);
755  }
756  return("");
[d09e5a1]757}
758
[81655f8]759char *owl_global_get_aim_screenname_for_filters(owl_global *g)
760{
761  if (owl_global_is_aimloggedin(g)) {
762    return (g->aim_screenname_for_filters);
763  }
764  return("");
765}
766
[6a415e9]767void owl_global_set_aimloggedin(owl_global *g, char *screenname)
768{
[81655f8]769  char *sn_escaped, *quote;
[d09e5a1]770  g->aim_loggedin=1;
771  if (g->aim_screenname) owl_free(g->aim_screenname);
[81655f8]772  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
[d09e5a1]773  g->aim_screenname=owl_strdup(screenname);
[81655f8]774  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
775  quote = owl_getquoting(sn_escaped);
[9f4e3f8]776  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
[81655f8]777  owl_free(sn_escaped);
[d09e5a1]778}
779
[6a415e9]780void owl_global_set_aimnologgedin(owl_global *g)
781{
[d09e5a1]782  g->aim_loggedin=0;
783}
784
[a352335c]785int owl_global_is_doaimevents(owl_global *g)
786{
787  if (g->aim_doprocessing) return(1);
788  return(0);
789}
790
791void owl_global_set_doaimevents(owl_global *g)
792{
793  g->aim_doprocessing=1;
794}
795
796void owl_global_set_no_doaimevents(owl_global *g)
797{
798  g->aim_doprocessing=0;
799}
800
[6a415e9]801aim_session_t *owl_global_get_aimsess(owl_global *g)
802{
[d09e5a1]803  return(&(g->aimsess));
804}
805
[c15bbfb]806aim_conn_t *owl_global_get_bosconn(owl_global *g)
807{
808  return(&(g->bosconn));
809}
810
811void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]812{
[c15bbfb]813  g->bosconn=*conn;
[d09e5a1]814}
815
[6a415e9]816int owl_global_is_aimnop_time(owl_global *g)
817{
818  if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);
[d09e5a1]819  return(0);
820}
821
[6a415e9]822void owl_global_aimnop_sent(owl_global *g)
823{
824  owl_timer_reset(&(g->aim_noop_timer));
825}
[d09e5a1]826
[6a415e9]827owl_timer *owl_global_get_aim_login_timer(owl_global *g)
828{
829  return(&(g->aim_ignorelogin_timer));
[d09e5a1]830}
831
832/* message queue */
833
[6a415e9]834void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
835{
[d09e5a1]836  owl_list_append_element(&(g->messagequeue), m);
837}
838
839/* pop off the first message and return it.  Return NULL if the queue
840 * is empty.  The caller should free the message after using it, if
841 * necessary.
842 */
[13a3c1db]843owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]844{
[d09e5a1]845  owl_message *out;
846
847  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
848  out=owl_list_get_element(&(g->messagequeue), 0);
849  owl_list_remove_element(&(g->messagequeue), 0);
850  return(out);
851}
852
[6a415e9]853int owl_global_messagequeue_pending(owl_global *g)
854{
[d09e5a1]855  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
856  return(1);
857}
[aa5f725]858
[6a415e9]859owl_buddylist *owl_global_get_buddylist(owl_global *g)
860{
[aa5f725]861  return(&(g->buddylist));
862}
863 
[bd3f232]864/* style */
865
866/* Return the style with name 'name'.  If it does not exist return
867 * NULL */
868owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
869{
[f1e629d]870  return owl_dict_find_element(&(g->styledict), name);
871}
872
873/* creates a list and fills it in with keys.  duplicates the keys,
874 * so they will need to be freed by the caller. */
875int owl_global_get_style_names(owl_global *g, owl_list *l) {
876  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]877}
878
[cf83b7a]879void owl_global_add_style(owl_global *g, owl_style *s)
880{
[f1fc47f]881  /*
882   * If we're redefining the current style, make sure to update
883   * pointers to it.
884   */
885  if(g->current_view.style
886     && !strcmp(owl_style_get_name(g->current_view.style),
887                owl_style_get_name(s)))
888    g->current_view.style = s;
889  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
890                          s, (void(*)(void*))owl_style_free);
[bd3f232]891}
[cf83b7a]892
[09489b89]893void owl_global_set_haveaim(owl_global *g)
894{
895  g->haveaim=1;
896}
897
898int owl_global_is_haveaim(owl_global *g)
899{
900  if (g->haveaim) return(1);
901  return(0);
902}
903
904void owl_global_set_havezephyr(owl_global *g)
905{
906  g->havezephyr=1;
907}
908
909int owl_global_is_havezephyr(owl_global *g)
910{
911  if (g->havezephyr) return(1);
912  return(0);
913}
[de03334]914
915owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)
916{
917  return(&(g->aim_buddyinfo_timer));
918}
[ec6ff52]919
920owl_errqueue *owl_global_get_errqueue(owl_global *g)
921{
922  return(&(g->errqueue));
923}
[c9e72d1]924
925void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
926{
927  g->got_err_signal = signum;
928  if (siginfo) {
929    g->err_signal_info = *siginfo;
930  } else {
931    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
932  }
933}
934
935int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
936{
937  int signum;
938  if (siginfo && g->got_err_signal) {
939    *siginfo = g->err_signal_info;
940  } 
941  signum = g->got_err_signal;
942  g->got_err_signal = 0;
943  return signum;
944}
945
[5a95b69]946owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)
947{
948  return(&(g->zephyr_buddycheck_timer));
949}
950
951owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
952{
953  return(&(g->zbuddies));
954}
[8232149]955
956struct termios *owl_global_get_startup_tio(owl_global *g)
957{
958  return(&(g->startup_tio));
959}
[8e401cae]960
961char * owl_global_intern(owl_global *g, char * string)
962{
963  return owl_obarray_insert(&(g->obarray), string);
964}
[9c7a701]965
966owl_list *owl_global_get_dispatchlist(owl_global *g)
967{
968  return &(g->dispatchlist);
969}
Note: See TracBrowser for help on using the repository browser.