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