[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] | 11 | static const char fileIdent[] = "$Id$"; |
---|
| 12 | |
---|
[7d4fbcd] | 13 | #ifndef MAXHOSTNAMELEN |
---|
| 14 | #define MAXHOSTNAMELEN 256 |
---|
| 15 | #endif |
---|
| 16 | |
---|
| 17 | void owl_global_init(owl_global *g) { |
---|
| 18 | struct hostent *hent; |
---|
| 19 | char hostname[MAXHOSTNAMELEN]; |
---|
| 20 | |
---|
[8262340] | 21 | g->malloced=0; |
---|
| 22 | g->freed=0; |
---|
| 23 | |
---|
[7d4fbcd] | 24 | gethostname(hostname, MAXHOSTNAMELEN); |
---|
| 25 | hent=gethostbyname(hostname); |
---|
| 26 | if (!hent) { |
---|
[a8938c7] | 27 | g->thishost=owl_strdup("localhost"); |
---|
[7d4fbcd] | 28 | } else { |
---|
[a8938c7] | 29 | g->thishost=owl_strdup(hent->h_name); |
---|
[7d4fbcd] | 30 | } |
---|
| 31 | |
---|
| 32 | owl_context_init(&g->ctx); |
---|
| 33 | owl_context_set_startup(&g->ctx); |
---|
| 34 | g->curmsg=0; |
---|
| 35 | g->topmsg=0; |
---|
| 36 | g->needrefresh=1; |
---|
[a8938c7] | 37 | g->startupargs=NULL; |
---|
[7d4fbcd] | 38 | |
---|
| 39 | owl_variable_dict_setup(&(g->vars)); |
---|
| 40 | owl_cmddict_setup(&(g->cmds)); |
---|
| 41 | |
---|
| 42 | g->lines=LINES; |
---|
| 43 | g->cols=COLS; |
---|
| 44 | |
---|
| 45 | g->rightshift=0; |
---|
| 46 | |
---|
[10b866d] | 47 | owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL); |
---|
[7d4fbcd] | 48 | |
---|
| 49 | owl_keyhandler_init(&g->kh); |
---|
| 50 | owl_keys_setup_keymaps(&g->kh); |
---|
| 51 | |
---|
| 52 | owl_list_create(&(g->filterlist)); |
---|
| 53 | owl_list_create(&(g->puntlist)); |
---|
[d09e5a1] | 54 | owl_list_create(&(g->messagequeue)); |
---|
[bd3f232] | 55 | owl_list_create(&(g->stylelist)); |
---|
[7d4fbcd] | 56 | g->curmsg_vert_offset=0; |
---|
| 57 | g->resizepending=0; |
---|
| 58 | g->typwinactive=0; |
---|
| 59 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 60 | g->zaway=0; |
---|
| 61 | if (has_colors()) { |
---|
| 62 | g->hascolors=1; |
---|
| 63 | } |
---|
| 64 | g->colorpairs=COLOR_PAIRS; |
---|
| 65 | g->debug=OWL_DEBUG; |
---|
[1fd0b25] | 66 | g->searchactive=0; |
---|
| 67 | g->searchstring=NULL; |
---|
[7d4fbcd] | 68 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
[a8938c7] | 69 | g->buffercommand=NULL; |
---|
[700c712] | 70 | g->newmsgproc_pid=0; |
---|
[61e79a9] | 71 | |
---|
[7d4fbcd] | 72 | owl_global_set_config_format(g, 0); |
---|
| 73 | owl_global_set_userclue(g, OWL_USERCLUE_NONE); |
---|
| 74 | owl_global_set_no_have_config(g); |
---|
[10b866d] | 75 | owl_history_init(&(g->msghist)); |
---|
| 76 | owl_history_init(&(g->cmdhist)); |
---|
[7d4fbcd] | 77 | g->nextmsgid=0; |
---|
| 78 | |
---|
| 79 | owl_filterelement_create_true(&(g->fe_true)); |
---|
| 80 | owl_filterelement_create_false(&(g->fe_false)); |
---|
| 81 | owl_filterelement_create_null(&(g->fe_null)); |
---|
| 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 | |
---|
| 89 | owl_messagelist_create(&(g->msglist)); |
---|
| 90 | owl_mainwin_init(&(g->mw)); |
---|
| 91 | owl_popwin_init(&(g->pw)); |
---|
[d09e5a1] | 92 | |
---|
| 93 | g->aim_screenname=NULL; |
---|
| 94 | g->aim_loggedin=0; |
---|
[6a415e9] | 95 | owl_timer_create_countdown(&(g->aim_noop_timer), 30); |
---|
| 96 | owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0); |
---|
[aa5f725] | 97 | owl_buddylist_init(&(g->buddylist)); |
---|
[7d4fbcd] | 98 | } |
---|
| 99 | |
---|
| 100 | void _owl_global_setup_windows(owl_global *g) { |
---|
[ecd5dc5] | 101 | int cols, typwin_lines; |
---|
[7d4fbcd] | 102 | |
---|
| 103 | cols=g->cols; |
---|
[ecd5dc5] | 104 | typwin_lines=owl_global_get_typwin_lines(g); |
---|
[7d4fbcd] | 105 | |
---|
| 106 | /* set the new window sizes */ |
---|
| 107 | g->recwinlines=g->lines-(typwin_lines+2); |
---|
[ecd5dc5] | 108 | if (g->recwinlines<1) { |
---|
| 109 | /* this will screw things up. I'm not sure what to do yet, |
---|
| 110 | but this is better than nothing */ |
---|
| 111 | /* g->recwinlines=1; */ |
---|
| 112 | } |
---|
[7d4fbcd] | 113 | |
---|
| 114 | /* create the new windows */ |
---|
| 115 | g->recwin=newwin(g->recwinlines, cols, 0, 0); |
---|
[ecd5dc5] | 116 | if (g->recwin==NULL) { |
---|
| 117 | owl_function_debugmsg("\n\nI just received an error on creating a new receive window\n"); |
---|
| 118 | owl_function_debugmsg("newwin was called with arguments (%i, %i, 0, 0) and returned NULL\n", |
---|
| 119 | g->recwinlines, cols); |
---|
| 120 | endwin(); |
---|
| 121 | |
---|
| 122 | exit(50); |
---|
| 123 | } |
---|
| 124 | |
---|
[7d4fbcd] | 125 | g->sepwin=newwin(1, cols, g->recwinlines, 0); |
---|
| 126 | g->msgwin=newwin(1, cols, g->recwinlines+1, 0); |
---|
| 127 | g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0); |
---|
| 128 | |
---|
| 129 | owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols); |
---|
| 130 | |
---|
| 131 | idlok(g->typwin, FALSE); |
---|
| 132 | idlok(g->recwin, FALSE); |
---|
| 133 | idlok(g->sepwin, FALSE); |
---|
| 134 | idlok(g->msgwin, FALSE); |
---|
| 135 | |
---|
| 136 | nodelay(g->typwin, 1); |
---|
| 137 | keypad(g->typwin, TRUE); |
---|
| 138 | wmove(g->typwin, 0, 0); |
---|
| 139 | |
---|
| 140 | meta(g->typwin, TRUE); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | owl_context *owl_global_get_context(owl_global *g) { |
---|
| 144 | return(&g->ctx); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | int owl_global_get_lines(owl_global *g) { |
---|
| 148 | return(g->lines); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | int owl_global_get_cols(owl_global *g) { |
---|
| 152 | return(g->cols); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | int owl_global_get_recwin_lines(owl_global *g) { |
---|
| 156 | return(g->recwinlines); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | /* curmsg */ |
---|
| 160 | |
---|
| 161 | int owl_global_get_curmsg(owl_global *g) { |
---|
| 162 | return(g->curmsg); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | void owl_global_set_curmsg(owl_global *g, int i) { |
---|
| 166 | g->curmsg=i; |
---|
| 167 | /* we will reset the vertical offset from here */ |
---|
| 168 | /* we might want to move this out to the functions later */ |
---|
| 169 | owl_global_set_curmsg_vert_offset(g, 0); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /* topmsg */ |
---|
| 173 | |
---|
| 174 | int owl_global_get_topmsg(owl_global *g) { |
---|
| 175 | return(g->topmsg); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | void owl_global_set_topmsg(owl_global *g, int i) { |
---|
| 179 | g->topmsg=i; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | /* windows */ |
---|
| 183 | |
---|
| 184 | owl_mainwin *owl_global_get_mainwin(owl_global *g) { |
---|
| 185 | return(&(g->mw)); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | owl_popwin *owl_global_get_popwin(owl_global *g) { |
---|
| 189 | return(&(g->pw)); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | /* msglist */ |
---|
| 193 | |
---|
| 194 | owl_messagelist *owl_global_get_msglist(owl_global *g) { |
---|
| 195 | return(&(g->msglist)); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /* keyhandler */ |
---|
| 199 | |
---|
| 200 | owl_keyhandler *owl_global_get_keyhandler(owl_global *g) { |
---|
| 201 | return(&(g->kh)); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | /* curses windows */ |
---|
| 205 | |
---|
| 206 | WINDOW *owl_global_get_curs_recwin(owl_global *g) { |
---|
| 207 | return(g->recwin); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | WINDOW *owl_global_get_curs_sepwin(owl_global *g) { |
---|
| 211 | return(g->sepwin); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | WINDOW *owl_global_get_curs_msgwin(owl_global *g) { |
---|
| 215 | return(g->msgwin); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | WINDOW *owl_global_get_curs_typwin(owl_global *g) { |
---|
| 219 | return(g->typwin); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | /* typwin */ |
---|
| 223 | |
---|
| 224 | owl_editwin *owl_global_get_typwin(owl_global *g) { |
---|
| 225 | return(&(g->tw)); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | /* buffercommand */ |
---|
| 229 | |
---|
| 230 | void owl_global_set_buffercommand(owl_global *g, char *command) { |
---|
[a8938c7] | 231 | if (g->buffercommand) owl_free(g->buffercommand); |
---|
| 232 | g->buffercommand=owl_strdup(command); |
---|
[7d4fbcd] | 233 | } |
---|
| 234 | |
---|
| 235 | char *owl_global_get_buffercommand(owl_global *g) { |
---|
[a8938c7] | 236 | if (g->buffercommand) return(g->buffercommand); |
---|
| 237 | return(""); |
---|
[7d4fbcd] | 238 | } |
---|
| 239 | |
---|
| 240 | /* refresh */ |
---|
| 241 | |
---|
| 242 | int owl_global_is_needrefresh(owl_global *g) { |
---|
| 243 | if (g->needrefresh==1) return(1); |
---|
| 244 | return(0); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | void owl_global_set_needrefresh(owl_global *g) { |
---|
| 248 | g->needrefresh=1; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | void owl_global_set_noneedrefresh(owl_global *g) { |
---|
| 252 | g->needrefresh=0; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | /* variable dictionary */ |
---|
| 256 | |
---|
| 257 | owl_vardict *owl_global_get_vardict(owl_global *g) { |
---|
| 258 | return &(g->vars); |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | /* command dictionary */ |
---|
| 262 | |
---|
| 263 | owl_cmddict *owl_global_get_cmddict(owl_global *g) { |
---|
| 264 | return &(g->cmds); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | /* rightshift */ |
---|
| 268 | |
---|
| 269 | void owl_global_set_rightshift(owl_global *g, int i) { |
---|
| 270 | g->rightshift=i; |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | int owl_global_get_rightshift(owl_global *g) { |
---|
| 274 | return(g->rightshift); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | /* typwin */ |
---|
| 278 | |
---|
| 279 | int owl_global_is_typwin_active(owl_global *g) { |
---|
| 280 | if (g->typwinactive==1) return(1); |
---|
| 281 | return(0); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | void owl_global_set_typwin_active(owl_global *g) { |
---|
| 285 | g->typwinactive=1; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | void owl_global_set_typwin_inactive(owl_global *g) { |
---|
| 289 | g->typwinactive=0; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | /* resize */ |
---|
| 293 | |
---|
| 294 | void owl_global_set_resize_pending(owl_global *g) { |
---|
| 295 | g->resizepending=1; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | char *owl_global_get_homedir(owl_global *g) { |
---|
[a8938c7] | 299 | if (g->homedir) return(g->homedir); |
---|
| 300 | return("/"); |
---|
[7d4fbcd] | 301 | } |
---|
| 302 | |
---|
| 303 | int owl_global_get_direction(owl_global *g) { |
---|
| 304 | return(g->direction); |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | void owl_global_set_direction_downwards(owl_global *g) { |
---|
| 308 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | void owl_global_set_direction_upwards(owl_global *g) { |
---|
| 312 | g->direction=OWL_DIRECTION_UPWARDS; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | /* perl stuff */ |
---|
| 316 | |
---|
| 317 | void owl_global_set_perlinterp(owl_global *g, void *p) { |
---|
| 318 | g->perl=p; |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | void *owl_global_get_perlinterp(owl_global *g) { |
---|
| 322 | return(g->perl); |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | int owl_global_is_config_format(owl_global *g) { |
---|
| 326 | if (g->config_format) return(1); |
---|
| 327 | return(0); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | void owl_global_set_config_format(owl_global *g, int state) { |
---|
| 331 | if (state==1) { |
---|
| 332 | g->config_format=1; |
---|
| 333 | } else { |
---|
| 334 | g->config_format=0; |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | void owl_global_set_have_config(owl_global *g) { |
---|
| 339 | g->haveconfig=1; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | void owl_global_set_no_have_config(owl_global *g) { |
---|
| 343 | g->haveconfig=0; |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | int owl_global_have_config(owl_global *g) { |
---|
| 347 | if (g->haveconfig) return(1); |
---|
| 348 | return(0); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | void owl_global_resize(owl_global *g, int x, int y) { |
---|
| 352 | /* resize the screen. If x or y is 0 use the terminal size */ |
---|
| 353 | struct winsize size; |
---|
| 354 | |
---|
| 355 | if (!g->resizepending) return; |
---|
| 356 | |
---|
| 357 | /* delete the current windows */ |
---|
| 358 | delwin(g->recwin); |
---|
| 359 | delwin(g->sepwin); |
---|
| 360 | delwin(g->msgwin); |
---|
| 361 | delwin(g->typwin); |
---|
| 362 | if (!isendwin()) { |
---|
| 363 | endwin(); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | refresh(); |
---|
| 367 | |
---|
| 368 | /* get the new size */ |
---|
| 369 | ioctl(STDIN_FILENO, TIOCGWINSZ, &size); |
---|
| 370 | if (x==0) { |
---|
| 371 | g->lines=size.ws_row; |
---|
| 372 | } else { |
---|
| 373 | g->lines=x; |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | if (y==0) { |
---|
| 377 | g->cols=size.ws_col; |
---|
| 378 | } else { |
---|
| 379 | g->cols=y; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | /* resizeterm(size.ws_row, size.ws_col); */ |
---|
| 383 | |
---|
| 384 | /* re-initialize the windows */ |
---|
| 385 | _owl_global_setup_windows(g); |
---|
| 386 | |
---|
| 387 | /* refresh stuff */ |
---|
| 388 | g->needrefresh=1; |
---|
| 389 | owl_mainwin_redisplay(&(g->mw)); |
---|
| 390 | sepbar(NULL); |
---|
| 391 | |
---|
| 392 | if (owl_global_is_typwin_active(g)) { |
---|
| 393 | owl_editwin_redisplay(&(g->tw), 0); |
---|
| 394 | } |
---|
| 395 | /* TODO: this should handle other forms of popwins */ |
---|
| 396 | if (owl_popwin_is_active(owl_global_get_popwin(g)) |
---|
| 397 | && owl_global_get_viewwin(g)) { |
---|
| 398 | owl_popwin_refresh(owl_global_get_popwin(g)); |
---|
| 399 | owl_viewwin_redisplay(owl_global_get_viewwin(g), 0); |
---|
| 400 | } |
---|
| 401 | |
---|
[ecd5dc5] | 402 | owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col); |
---|
[7d4fbcd] | 403 | owl_function_makemsg(""); |
---|
| 404 | g->resizepending=0; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | /* debug */ |
---|
| 408 | |
---|
| 409 | int owl_global_is_debug_fast(owl_global *g) { |
---|
| 410 | if (g->debug) return(1); |
---|
| 411 | return(0); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | /* starttime */ |
---|
| 415 | |
---|
| 416 | time_t owl_global_get_starttime(owl_global *g) { |
---|
| 417 | return(g->starttime); |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | time_t owl_global_get_runtime(owl_global *g) { |
---|
| 421 | return(time(NULL)-g->starttime); |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | void owl_global_get_runtime_string(owl_global *g, char *buff) { |
---|
| 425 | time_t diff; |
---|
| 426 | |
---|
| 427 | diff=time(NULL)-owl_global_get_starttime(g); |
---|
| 428 | |
---|
| 429 | /* print something nicer later */ |
---|
| 430 | sprintf(buff, "%i seconds", (int) diff); |
---|
| 431 | } |
---|
| 432 | |
---|
[61e79a9] | 433 | char *owl_global_get_hostname(owl_global *g) { |
---|
[a8938c7] | 434 | if (g->thishost) return(g->thishost); |
---|
| 435 | return(""); |
---|
[61e79a9] | 436 | } |
---|
| 437 | |
---|
[7d4fbcd] | 438 | /* userclue */ |
---|
| 439 | |
---|
| 440 | void owl_global_set_userclue(owl_global *g, int clue) { |
---|
| 441 | g->userclue=clue; |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | void owl_global_add_userclue(owl_global *g, int clue) { |
---|
| 445 | g->userclue|=clue; |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | int owl_global_get_userclue(owl_global *g) { |
---|
| 449 | return(g->userclue); |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | int owl_global_is_userclue(owl_global *g, int clue) { |
---|
| 453 | if (g->userclue & clue) return(1); |
---|
| 454 | return(0); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | /* viewwin */ |
---|
| 458 | |
---|
| 459 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
| 460 | return(&(g->vw)); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | |
---|
| 464 | /* vert offset */ |
---|
| 465 | |
---|
| 466 | int owl_global_get_curmsg_vert_offset(owl_global *g) { |
---|
| 467 | return(g->curmsg_vert_offset); |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
| 471 | g->curmsg_vert_offset=i; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | /* startup args */ |
---|
| 475 | |
---|
| 476 | void owl_global_set_startupargs(owl_global *g, int argc, char **argv) { |
---|
[a8938c7] | 477 | int i, len; |
---|
| 478 | |
---|
| 479 | if (g->startupargs) owl_free(g->startupargs); |
---|
| 480 | |
---|
| 481 | len=0; |
---|
| 482 | for (i=0; i<argc; i++) { |
---|
[591e6aa7] | 483 | len+=strlen(argv[i])+5; |
---|
[a8938c7] | 484 | } |
---|
| 485 | g->startupargs=malloc(len+5); |
---|
[7d4fbcd] | 486 | |
---|
| 487 | strcpy(g->startupargs, ""); |
---|
| 488 | for (i=0; i<argc; i++) { |
---|
| 489 | sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]); |
---|
| 490 | } |
---|
| 491 | g->startupargs[strlen(g->startupargs)-1]='\0'; |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | char *owl_global_get_startupargs(owl_global *g) { |
---|
[a8938c7] | 495 | if (g->startupargs) return(g->startupargs); |
---|
| 496 | return(""); |
---|
[7d4fbcd] | 497 | } |
---|
| 498 | |
---|
| 499 | /* history */ |
---|
| 500 | |
---|
[10b866d] | 501 | owl_history *owl_global_get_msg_history(owl_global *g) { |
---|
| 502 | return(&(g->msghist)); |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | owl_history *owl_global_get_cmd_history(owl_global *g) { |
---|
| 506 | return(&(g->cmdhist)); |
---|
[7d4fbcd] | 507 | } |
---|
| 508 | |
---|
| 509 | /* filterlist */ |
---|
| 510 | |
---|
| 511 | owl_list *owl_global_get_filterlist(owl_global *g) { |
---|
| 512 | return(&(g->filterlist)); |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | owl_filter *owl_global_get_filter(owl_global *g, char *name) { |
---|
| 516 | int i, j; |
---|
| 517 | owl_filter *f; |
---|
| 518 | |
---|
| 519 | j=owl_list_get_size(&(g->filterlist)); |
---|
| 520 | for (i=0; i<j; i++) { |
---|
| 521 | f=owl_list_get_element(&(g->filterlist), i); |
---|
| 522 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
| 523 | return(f); |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | return(NULL); |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
| 530 | owl_list_append_element(&(g->filterlist), f); |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | void owl_global_remove_filter(owl_global *g, char *name) { |
---|
| 534 | int i, j; |
---|
| 535 | owl_filter *f; |
---|
| 536 | |
---|
| 537 | j=owl_list_get_size(&(g->filterlist)); |
---|
| 538 | for (i=0; i<j; i++) { |
---|
| 539 | f=owl_list_get_element(&(g->filterlist), i); |
---|
| 540 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
| 541 | owl_filter_free(f); |
---|
| 542 | owl_list_remove_element(&(g->filterlist), i); |
---|
| 543 | break; |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | /* nextmsgid */ |
---|
| 549 | |
---|
| 550 | int owl_global_get_nextmsgid(owl_global *g) { |
---|
| 551 | return(g->nextmsgid++); |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | /* current view */ |
---|
| 555 | |
---|
| 556 | owl_view *owl_global_get_current_view(owl_global *g) { |
---|
| 557 | return(&(g->current_view)); |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | owl_filterelement *owl_global_get_filterelement_true(owl_global *g) { |
---|
| 561 | return(&(g->fe_true)); |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | owl_filterelement *owl_global_get_filterelement_false(owl_global *g) { |
---|
| 565 | return(&(g->fe_false)); |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | owl_filterelement *owl_global_get_filterelement_null(owl_global *g) { |
---|
| 569 | return(&(g->fe_null)); |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | /* has colors */ |
---|
| 573 | |
---|
| 574 | int owl_global_get_hascolors(owl_global *g) { |
---|
| 575 | if (g->hascolors) return(1); |
---|
| 576 | return(0); |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | /* color pairs */ |
---|
| 580 | |
---|
| 581 | int owl_global_get_colorpairs(owl_global *g) { |
---|
| 582 | return(g->colorpairs); |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | /* puntlist */ |
---|
| 586 | |
---|
| 587 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 588 | return(&(g->puntlist)); |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | int owl_global_message_is_puntable(owl_global *g, owl_message *m) { |
---|
| 592 | owl_list *pl; |
---|
| 593 | int i, j; |
---|
| 594 | |
---|
| 595 | pl=owl_global_get_puntlist(g); |
---|
| 596 | j=owl_list_get_size(pl); |
---|
| 597 | for (i=0; i<j; i++) { |
---|
| 598 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
| 599 | } |
---|
| 600 | return(0); |
---|
| 601 | } |
---|
| 602 | |
---|
| 603 | int owl_global_should_followlast(owl_global *g) { |
---|
| 604 | owl_view *v; |
---|
| 605 | |
---|
| 606 | if (!owl_global_is__followlast(g)) return(0); |
---|
| 607 | |
---|
| 608 | v=owl_global_get_current_view(g); |
---|
| 609 | |
---|
| 610 | if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1); |
---|
| 611 | return(0); |
---|
| 612 | } |
---|
[1fd0b25] | 613 | |
---|
| 614 | int owl_global_is_search_active(owl_global *g) { |
---|
| 615 | if (g->searchactive) return(1); |
---|
| 616 | return(0); |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | void owl_global_set_search_active(owl_global *g, char *string) { |
---|
| 620 | g->searchactive=1; |
---|
| 621 | if (g->searchstring != NULL) owl_free(g->searchstring); |
---|
| 622 | g->searchstring=owl_strdup(string); |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | void owl_global_set_search_inactive(owl_global *g) { |
---|
| 626 | g->searchactive=0; |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | char *owl_global_get_search_string(owl_global *g) { |
---|
| 630 | if (g->searchstring==NULL) return(""); |
---|
| 631 | return(g->searchstring); |
---|
| 632 | } |
---|
[700c712] | 633 | |
---|
| 634 | void owl_global_set_newmsgproc_pid(owl_global *g, int i) { |
---|
| 635 | g->newmsgproc_pid=i; |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | int owl_global_get_newmsgproc_pid(owl_global *g) { |
---|
| 639 | return(g->newmsgproc_pid); |
---|
| 640 | } |
---|
| 641 | |
---|
[8262340] | 642 | void owl_global_add_to_malloced(owl_global *g, int i) { |
---|
| 643 | g->malloced+=i; |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | void owl_global_add_to_freed(owl_global *g, int i) { |
---|
| 647 | g->freed+=1; |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | int owl_global_get_malloced(owl_global *g) { |
---|
| 651 | return(g->malloced); |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | int owl_global_get_freed(owl_global *g) { |
---|
| 655 | return(g->freed); |
---|
| 656 | } |
---|
| 657 | |
---|
| 658 | int owl_global_get_meminuse(owl_global *g) { |
---|
| 659 | return(g->malloced-g->freed); |
---|
| 660 | } |
---|
[d09e5a1] | 661 | |
---|
| 662 | /* AIM stuff */ |
---|
| 663 | |
---|
[6a415e9] | 664 | int owl_global_is_aimloggedin(owl_global *g) |
---|
| 665 | { |
---|
[d09e5a1] | 666 | if (g->aim_loggedin) return(1); |
---|
| 667 | return(0); |
---|
| 668 | } |
---|
| 669 | |
---|
[6a415e9] | 670 | char *owl_global_get_aim_screenname(owl_global *g) |
---|
| 671 | { |
---|
[d09e5a1] | 672 | return (g->aim_screenname); |
---|
| 673 | } |
---|
| 674 | |
---|
[6a415e9] | 675 | void owl_global_set_aimloggedin(owl_global *g, char *screenname) |
---|
| 676 | { |
---|
[d09e5a1] | 677 | g->aim_loggedin=1; |
---|
| 678 | if (g->aim_screenname) owl_free(g->aim_screenname); |
---|
| 679 | g->aim_screenname=owl_strdup(screenname); |
---|
| 680 | } |
---|
| 681 | |
---|
[6a415e9] | 682 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
| 683 | { |
---|
[d09e5a1] | 684 | g->aim_loggedin=0; |
---|
| 685 | } |
---|
| 686 | |
---|
[6a415e9] | 687 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
| 688 | { |
---|
[d09e5a1] | 689 | return(&(g->aimsess)); |
---|
| 690 | } |
---|
| 691 | |
---|
[6a415e9] | 692 | aim_conn_t *owl_global_get_waitingconn(owl_global *g) |
---|
| 693 | { |
---|
[d09e5a1] | 694 | return(&(g->waitingconn)); |
---|
| 695 | } |
---|
| 696 | |
---|
[6a415e9] | 697 | int owl_global_is_aimnop_time(owl_global *g) |
---|
| 698 | { |
---|
| 699 | if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1); |
---|
[d09e5a1] | 700 | return(0); |
---|
| 701 | } |
---|
| 702 | |
---|
[6a415e9] | 703 | void owl_global_aimnop_sent(owl_global *g) |
---|
| 704 | { |
---|
| 705 | owl_timer_reset(&(g->aim_noop_timer)); |
---|
| 706 | } |
---|
[d09e5a1] | 707 | |
---|
[6a415e9] | 708 | owl_timer *owl_global_get_aim_login_timer(owl_global *g) |
---|
| 709 | { |
---|
| 710 | return(&(g->aim_ignorelogin_timer)); |
---|
[d09e5a1] | 711 | } |
---|
| 712 | |
---|
| 713 | /* message queue */ |
---|
| 714 | |
---|
[6a415e9] | 715 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
| 716 | { |
---|
[d09e5a1] | 717 | owl_list_append_element(&(g->messagequeue), m); |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | /* pop off the first message and return it. Return NULL if the queue |
---|
| 721 | * is empty. The caller should free the message after using it, if |
---|
| 722 | * necessary. |
---|
| 723 | */ |
---|
[6a415e9] | 724 | owl_message *owl_global_messageuque_popmsg(owl_global *g) |
---|
| 725 | { |
---|
[d09e5a1] | 726 | owl_message *out; |
---|
| 727 | |
---|
| 728 | if (owl_list_get_size(&(g->messagequeue))==0) return(NULL); |
---|
| 729 | out=owl_list_get_element(&(g->messagequeue), 0); |
---|
| 730 | owl_list_remove_element(&(g->messagequeue), 0); |
---|
| 731 | return(out); |
---|
| 732 | } |
---|
| 733 | |
---|
[6a415e9] | 734 | int owl_global_messagequeue_pending(owl_global *g) |
---|
| 735 | { |
---|
[d09e5a1] | 736 | if (owl_list_get_size(&(g->messagequeue))==0) return(0); |
---|
| 737 | return(1); |
---|
| 738 | } |
---|
[aa5f725] | 739 | |
---|
[6a415e9] | 740 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
| 741 | { |
---|
[aa5f725] | 742 | return(&(g->buddylist)); |
---|
| 743 | } |
---|
| 744 | |
---|
[bd3f232] | 745 | /* style */ |
---|
| 746 | |
---|
| 747 | /* Return the style with name 'name'. If it does not exist return |
---|
| 748 | * NULL */ |
---|
| 749 | owl_style *owl_global_get_style_by_name(owl_global *g, char *name) |
---|
| 750 | { |
---|
| 751 | int i, j; |
---|
| 752 | owl_style *s; |
---|
| 753 | |
---|
| 754 | j=owl_list_get_size(&(g->stylelist)); |
---|
| 755 | for (i=0; i<j; i++) { |
---|
| 756 | s=owl_list_get_element(&(g->stylelist), i); |
---|
| 757 | if (owl_style_matches_name(s, name)) { |
---|
| 758 | return(s); |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | return(NULL); |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | void owl_global_add_style(owl_global *g, owl_style *s) { |
---|
| 765 | owl_list_append_element(&(g->stylelist), s); |
---|
| 766 | } |
---|