[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 | |
---|
| 11 | #ifndef MAXHOSTNAMELEN |
---|
| 12 | #define MAXHOSTNAMELEN 256 |
---|
| 13 | #endif |
---|
| 14 | |
---|
| 15 | void owl_global_init(owl_global *g) { |
---|
| 16 | struct hostent *hent; |
---|
| 17 | char hostname[MAXHOSTNAMELEN]; |
---|
[ad15610] | 18 | char *cd; |
---|
[7d4fbcd] | 19 | |
---|
| 20 | gethostname(hostname, MAXHOSTNAMELEN); |
---|
| 21 | hent=gethostbyname(hostname); |
---|
| 22 | if (!hent) { |
---|
[a8938c7] | 23 | g->thishost=owl_strdup("localhost"); |
---|
[7d4fbcd] | 24 | } else { |
---|
[a8938c7] | 25 | g->thishost=owl_strdup(hent->h_name); |
---|
[7d4fbcd] | 26 | } |
---|
| 27 | |
---|
[a999d9e] | 28 | g->context_stack = NULL; |
---|
| 29 | owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL); |
---|
| 30 | |
---|
[7d4fbcd] | 31 | g->curmsg=0; |
---|
| 32 | g->topmsg=0; |
---|
[bd783db] | 33 | g->markedmsgid=-1; |
---|
[7d4fbcd] | 34 | g->needrefresh=1; |
---|
[a8938c7] | 35 | g->startupargs=NULL; |
---|
[7d4fbcd] | 36 | |
---|
| 37 | owl_variable_dict_setup(&(g->vars)); |
---|
| 38 | |
---|
| 39 | g->lines=LINES; |
---|
| 40 | g->cols=COLS; |
---|
| 41 | |
---|
| 42 | g->rightshift=0; |
---|
| 43 | |
---|
[38cc669] | 44 | g->tw = NULL; |
---|
[7d4fbcd] | 45 | |
---|
| 46 | owl_keyhandler_init(&g->kh); |
---|
| 47 | owl_keys_setup_keymaps(&g->kh); |
---|
| 48 | |
---|
[129e609] | 49 | owl_dict_create(&(g->filters)); |
---|
| 50 | g->filterlist = NULL; |
---|
[7d4fbcd] | 51 | owl_list_create(&(g->puntlist)); |
---|
[20aced3] | 52 | g->messagequeue = g_queue_new(); |
---|
[f1e629d] | 53 | owl_dict_create(&(g->styledict)); |
---|
[7d4fbcd] | 54 | g->curmsg_vert_offset=0; |
---|
| 55 | g->resizepending=0; |
---|
[f7cf6c2] | 56 | g->relayoutpending = 0; |
---|
[7d4fbcd] | 57 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 58 | g->zaway=0; |
---|
| 59 | if (has_colors()) { |
---|
| 60 | g->hascolors=1; |
---|
| 61 | } |
---|
| 62 | g->colorpairs=COLOR_PAIRS; |
---|
[8fa9562] | 63 | owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); |
---|
[7d4fbcd] | 64 | g->debug=OWL_DEBUG; |
---|
[41c9a96] | 65 | owl_regex_init(&g->search_re); |
---|
[7d4fbcd] | 66 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
[7f792c1] | 67 | g->lastinputtime=g->starttime; |
---|
[700c712] | 68 | g->newmsgproc_pid=0; |
---|
[61e79a9] | 69 | |
---|
[7d4fbcd] | 70 | owl_global_set_config_format(g, 0); |
---|
| 71 | owl_global_set_userclue(g, OWL_USERCLUE_NONE); |
---|
| 72 | owl_global_set_no_have_config(g); |
---|
[10b866d] | 73 | owl_history_init(&(g->msghist)); |
---|
| 74 | owl_history_init(&(g->cmdhist)); |
---|
[5a9f6fe] | 75 | owl_history_set_norepeats(&(g->cmdhist)); |
---|
[7d4fbcd] | 76 | g->nextmsgid=0; |
---|
| 77 | |
---|
| 78 | _owl_global_setup_windows(g); |
---|
| 79 | |
---|
| 80 | /* Fill in some variables which don't have constant defaults */ |
---|
| 81 | /* TODO: come back later and check passwd file first */ |
---|
[a8938c7] | 82 | g->homedir=owl_strdup(getenv("HOME")); |
---|
[7d4fbcd] | 83 | |
---|
[b363d83] | 84 | g->confdir = NULL; |
---|
| 85 | g->startupfile = NULL; |
---|
[ad15610] | 86 | cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR); |
---|
[b363d83] | 87 | owl_global_set_confdir(g, cd); |
---|
| 88 | owl_free(cd); |
---|
| 89 | |
---|
[7d4fbcd] | 90 | owl_messagelist_create(&(g->msglist)); |
---|
| 91 | owl_mainwin_init(&(g->mw)); |
---|
| 92 | owl_popwin_init(&(g->pw)); |
---|
[d09e5a1] | 93 | |
---|
| 94 | g->aim_screenname=NULL; |
---|
[81655f8] | 95 | g->aim_screenname_for_filters=NULL; |
---|
[d09e5a1] | 96 | g->aim_loggedin=0; |
---|
[aa5f725] | 97 | owl_buddylist_init(&(g->buddylist)); |
---|
[b7bb454] | 98 | |
---|
[09489b89] | 99 | g->havezephyr=0; |
---|
| 100 | g->haveaim=0; |
---|
[b7bb454] | 101 | g->ignoreaimlogin=0; |
---|
[a352335c] | 102 | owl_global_set_no_doaimevents(g); |
---|
[ec6ff52] | 103 | |
---|
| 104 | owl_errqueue_init(&(g->errqueue)); |
---|
[c9e72d1] | 105 | g->got_err_signal=0; |
---|
[5a95b69] | 106 | |
---|
| 107 | owl_zbuddylist_create(&(g->zbuddies)); |
---|
[8e401cae] | 108 | |
---|
[f25812b] | 109 | g->zaldlist = NULL; |
---|
| 110 | g->pseudologin_notify = 0; |
---|
| 111 | |
---|
[a387d12e] | 112 | owl_message_init_fmtext_cache(); |
---|
[df0138f] | 113 | owl_list_create(&(g->io_dispatch_list)); |
---|
[4f2166b] | 114 | owl_list_create(&(g->psa_list)); |
---|
[58d1f8a] | 115 | g->timerlist = NULL; |
---|
[adee9cc] | 116 | g->interrupted = FALSE; |
---|
[0881cdd] | 117 | |
---|
| 118 | /* set up a pad for input */ |
---|
| 119 | g->input_pad = newpad(1, 1); |
---|
| 120 | nodelay(g->input_pad, 1); |
---|
| 121 | keypad(g->input_pad, 1); |
---|
| 122 | meta(g->input_pad, 1); |
---|
[7d4fbcd] | 123 | } |
---|
| 124 | |
---|
[eb6cedc] | 125 | /* Called once perl has been initialized */ |
---|
| 126 | void owl_global_complete_setup(owl_global *g) |
---|
| 127 | { |
---|
| 128 | owl_cmddict_setup(&(g->cmds)); |
---|
| 129 | } |
---|
| 130 | |
---|
[8ae2de9] | 131 | /* If *pan does not exist, we create a new panel, otherwise we replace the |
---|
| 132 | window in *pan with win. |
---|
| 133 | |
---|
| 134 | libpanel PANEL objects cannot exist without owner a valid window. This |
---|
| 135 | maintains the invariant for _owl_global_setup_windows. */ |
---|
| 136 | void _owl_panel_set_window(PANEL **pan, WINDOW *win) |
---|
| 137 | { |
---|
| 138 | WINDOW *oldwin; |
---|
[b3adfb5] | 139 | |
---|
| 140 | if (win == NULL) { |
---|
[0e3cdf1] | 141 | owl_function_debugmsg("_owl_panel_set_window: passed NULL win (failed to allocate?)"); |
---|
[b3adfb5] | 142 | endwin(); |
---|
| 143 | exit(50); |
---|
| 144 | } |
---|
| 145 | |
---|
[8ae2de9] | 146 | if (*pan) { |
---|
| 147 | oldwin = panel_window(*pan); |
---|
| 148 | replace_panel(*pan, win); |
---|
| 149 | delwin(oldwin); |
---|
| 150 | } else { |
---|
| 151 | *pan = new_panel(win); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
[7d4fbcd] | 155 | void _owl_global_setup_windows(owl_global *g) { |
---|
[ecd5dc5] | 156 | int cols, typwin_lines; |
---|
[7d4fbcd] | 157 | |
---|
| 158 | cols=g->cols; |
---|
[ecd5dc5] | 159 | typwin_lines=owl_global_get_typwin_lines(g); |
---|
[7d4fbcd] | 160 | |
---|
| 161 | /* set the new window sizes */ |
---|
| 162 | g->recwinlines=g->lines-(typwin_lines+2); |
---|
[176d3443] | 163 | if (g->recwinlines<0) { |
---|
| 164 | /* gotta deal with this */ |
---|
| 165 | g->recwinlines=0; |
---|
[ecd5dc5] | 166 | } |
---|
[7d4fbcd] | 167 | |
---|
| 168 | /* create the new windows */ |
---|
[b3adfb5] | 169 | _owl_panel_set_window(&g->recpan, newwin(g->recwinlines, cols, 0, 0)); |
---|
| 170 | _owl_panel_set_window(&g->seppan, newwin(1, cols, g->recwinlines, 0)); |
---|
| 171 | _owl_panel_set_window(&g->msgpan, newwin(1, cols, g->recwinlines+1, 0)); |
---|
| 172 | _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0)); |
---|
| 173 | |
---|
[38cc669] | 174 | if (g->tw) |
---|
| 175 | owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols); |
---|
[b3adfb5] | 176 | |
---|
| 177 | idlok(owl_global_get_curs_typwin(g), FALSE); |
---|
| 178 | idlok(owl_global_get_curs_recwin(g), FALSE); |
---|
| 179 | idlok(owl_global_get_curs_sepwin(g), FALSE); |
---|
| 180 | idlok(owl_global_get_curs_msgwin(g), FALSE); |
---|
| 181 | |
---|
| 182 | wmove(owl_global_get_curs_typwin(g), 0, 0); |
---|
[7d4fbcd] | 183 | } |
---|
| 184 | |
---|
| 185 | owl_context *owl_global_get_context(owl_global *g) { |
---|
[a999d9e] | 186 | if (!g->context_stack) |
---|
| 187 | return NULL; |
---|
| 188 | return g->context_stack->data; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | static void owl_global_lookup_keymap(owl_global *g) { |
---|
| 192 | owl_context *c = owl_global_get_context(g); |
---|
| 193 | if (!c || !c->keymap) |
---|
| 194 | return; |
---|
| 195 | |
---|
| 196 | if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) { |
---|
| 197 | owl_function_error("Unable to activate keymap '%s'", c->keymap); |
---|
| 198 | } |
---|
[7d4fbcd] | 199 | } |
---|
[a999d9e] | 200 | |
---|
| 201 | void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap) { |
---|
| 202 | owl_context *c; |
---|
| 203 | if (!(mode & OWL_CTX_MODE_BITS)) |
---|
| 204 | mode |= OWL_CTX_INTERACTIVE; |
---|
| 205 | c = owl_malloc(sizeof *c); |
---|
| 206 | c->mode = mode; |
---|
| 207 | c->data = data; |
---|
| 208 | c->keymap = owl_strdup(keymap); |
---|
| 209 | g->context_stack = g_list_prepend(g->context_stack, c); |
---|
| 210 | owl_global_lookup_keymap(g); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | void owl_global_pop_context(owl_global *g) { |
---|
| 214 | owl_context *c; |
---|
| 215 | if (!g->context_stack) |
---|
| 216 | return; |
---|
| 217 | c = owl_global_get_context(g); |
---|
| 218 | g->context_stack = g_list_delete_link(g->context_stack, |
---|
| 219 | g->context_stack); |
---|
| 220 | owl_free(c->keymap); |
---|
| 221 | owl_free(c); |
---|
| 222 | owl_global_lookup_keymap(g); |
---|
| 223 | } |
---|
| 224 | |
---|
[8742840] | 225 | int owl_global_get_lines(const owl_global *g) { |
---|
[7d4fbcd] | 226 | return(g->lines); |
---|
| 227 | } |
---|
| 228 | |
---|
[8742840] | 229 | int owl_global_get_cols(const owl_global *g) { |
---|
[7d4fbcd] | 230 | return(g->cols); |
---|
| 231 | } |
---|
| 232 | |
---|
[8742840] | 233 | int owl_global_get_recwin_lines(const owl_global *g) { |
---|
[7d4fbcd] | 234 | return(g->recwinlines); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | /* curmsg */ |
---|
| 238 | |
---|
[8742840] | 239 | int owl_global_get_curmsg(const owl_global *g) { |
---|
[7d4fbcd] | 240 | return(g->curmsg); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | void owl_global_set_curmsg(owl_global *g, int i) { |
---|
| 244 | g->curmsg=i; |
---|
| 245 | /* we will reset the vertical offset from here */ |
---|
| 246 | /* we might want to move this out to the functions later */ |
---|
| 247 | owl_global_set_curmsg_vert_offset(g, 0); |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | /* topmsg */ |
---|
| 251 | |
---|
[8742840] | 252 | int owl_global_get_topmsg(const owl_global *g) { |
---|
[7d4fbcd] | 253 | return(g->topmsg); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | void owl_global_set_topmsg(owl_global *g, int i) { |
---|
| 257 | g->topmsg=i; |
---|
| 258 | } |
---|
| 259 | |
---|
[70110286] | 260 | /* markedmsgid */ |
---|
| 261 | |
---|
[8742840] | 262 | int owl_global_get_markedmsgid(const owl_global *g) { |
---|
[70110286] | 263 | return(g->markedmsgid); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | void owl_global_set_markedmsgid(owl_global *g, int i) { |
---|
| 267 | g->markedmsgid=i; |
---|
| 268 | /* i; index of message in the current view. |
---|
[c08c70a] | 269 | const owl_message *m; |
---|
[70110286] | 270 | owl_view *v; |
---|
| 271 | |
---|
| 272 | v = owl_global_get_current_view(&g); |
---|
| 273 | m = owl_view_get_element(v, i); |
---|
| 274 | g->markedmsgid = m ? owl_message_get_id(m) : 0; |
---|
| 275 | */ |
---|
| 276 | } |
---|
| 277 | |
---|
[7d4fbcd] | 278 | /* windows */ |
---|
| 279 | |
---|
| 280 | owl_mainwin *owl_global_get_mainwin(owl_global *g) { |
---|
| 281 | return(&(g->mw)); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | owl_popwin *owl_global_get_popwin(owl_global *g) { |
---|
| 285 | return(&(g->pw)); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | /* msglist */ |
---|
| 289 | |
---|
| 290 | owl_messagelist *owl_global_get_msglist(owl_global *g) { |
---|
| 291 | return(&(g->msglist)); |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | /* keyhandler */ |
---|
| 295 | |
---|
| 296 | owl_keyhandler *owl_global_get_keyhandler(owl_global *g) { |
---|
| 297 | return(&(g->kh)); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | /* curses windows */ |
---|
| 301 | |
---|
[8742840] | 302 | WINDOW *owl_global_get_curs_recwin(const owl_global *g) { |
---|
[b3adfb5] | 303 | return panel_window(g->recpan); |
---|
[7d4fbcd] | 304 | } |
---|
| 305 | |
---|
[8742840] | 306 | WINDOW *owl_global_get_curs_sepwin(const owl_global *g) { |
---|
[b3adfb5] | 307 | return panel_window(g->seppan); |
---|
[7d4fbcd] | 308 | } |
---|
| 309 | |
---|
[8742840] | 310 | WINDOW *owl_global_get_curs_msgwin(const owl_global *g) { |
---|
[b3adfb5] | 311 | return panel_window(g->msgpan); |
---|
[7d4fbcd] | 312 | } |
---|
| 313 | |
---|
[8742840] | 314 | WINDOW *owl_global_get_curs_typwin(const owl_global *g) { |
---|
[b3adfb5] | 315 | return panel_window(g->typpan); |
---|
[7d4fbcd] | 316 | } |
---|
| 317 | |
---|
| 318 | /* typwin */ |
---|
| 319 | |
---|
[8742840] | 320 | owl_editwin *owl_global_get_typwin(const owl_global *g) { |
---|
[a556caa] | 321 | return(g->tw); |
---|
[7d4fbcd] | 322 | } |
---|
| 323 | |
---|
| 324 | /* refresh */ |
---|
| 325 | |
---|
[8742840] | 326 | int owl_global_is_needrefresh(const owl_global *g) { |
---|
[7d4fbcd] | 327 | if (g->needrefresh==1) return(1); |
---|
| 328 | return(0); |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | void owl_global_set_needrefresh(owl_global *g) { |
---|
| 332 | g->needrefresh=1; |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | void owl_global_set_noneedrefresh(owl_global *g) { |
---|
| 336 | g->needrefresh=0; |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | /* variable dictionary */ |
---|
| 340 | |
---|
| 341 | owl_vardict *owl_global_get_vardict(owl_global *g) { |
---|
| 342 | return &(g->vars); |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | /* command dictionary */ |
---|
| 346 | |
---|
| 347 | owl_cmddict *owl_global_get_cmddict(owl_global *g) { |
---|
| 348 | return &(g->cmds); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | /* rightshift */ |
---|
| 352 | |
---|
| 353 | void owl_global_set_rightshift(owl_global *g, int i) { |
---|
| 354 | g->rightshift=i; |
---|
| 355 | } |
---|
| 356 | |
---|
[8742840] | 357 | int owl_global_get_rightshift(const owl_global *g) { |
---|
[7d4fbcd] | 358 | return(g->rightshift); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | /* typwin */ |
---|
| 362 | |
---|
[58d47ca] | 363 | owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) { |
---|
[38cc669] | 364 | int d; |
---|
| 365 | d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 366 | if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 367 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d); |
---|
| 368 | |
---|
[38cc669] | 369 | g->tw = owl_editwin_new(owl_global_get_curs_typwin(g), |
---|
| 370 | owl_global_get_typwin_lines(g), |
---|
| 371 | g->cols, |
---|
| 372 | style, |
---|
| 373 | hist); |
---|
[58d47ca] | 374 | return g->tw; |
---|
[7d4fbcd] | 375 | } |
---|
| 376 | |
---|
| 377 | void owl_global_set_typwin_inactive(owl_global *g) { |
---|
[da466e0] | 378 | int d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 379 | if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 380 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d); |
---|
| 381 | |
---|
[38cc669] | 382 | werase(owl_global_get_curs_typwin(g)); |
---|
| 383 | g->tw = NULL; |
---|
[7d4fbcd] | 384 | } |
---|
| 385 | |
---|
| 386 | /* resize */ |
---|
| 387 | |
---|
| 388 | void owl_global_set_resize_pending(owl_global *g) { |
---|
| 389 | g->resizepending=1; |
---|
| 390 | } |
---|
| 391 | |
---|
[f7cf6c2] | 392 | void owl_global_set_relayout_pending(owl_global *g) { |
---|
| 393 | g->relayoutpending = 1; |
---|
| 394 | } |
---|
| 395 | |
---|
[8742840] | 396 | const char *owl_global_get_homedir(const owl_global *g) { |
---|
[a8938c7] | 397 | if (g->homedir) return(g->homedir); |
---|
| 398 | return("/"); |
---|
[7d4fbcd] | 399 | } |
---|
| 400 | |
---|
[8742840] | 401 | const char *owl_global_get_confdir(const owl_global *g) { |
---|
[b363d83] | 402 | if (g->confdir) return(g->confdir); |
---|
| 403 | return("/"); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | /* |
---|
| 407 | * Setting this also sets startupfile to confdir/startup |
---|
| 408 | */ |
---|
[e19eb97] | 409 | void owl_global_set_confdir(owl_global *g, const char *cd) { |
---|
[27f6487] | 410 | owl_free(g->confdir); |
---|
[b363d83] | 411 | g->confdir = owl_strdup(cd); |
---|
[27f6487] | 412 | owl_free(g->startupfile); |
---|
[b363d83] | 413 | g->startupfile = owl_sprintf("%s/startup", cd); |
---|
| 414 | } |
---|
| 415 | |
---|
[8742840] | 416 | const char *owl_global_get_startupfile(const owl_global *g) { |
---|
[b363d83] | 417 | if(g->startupfile) return(g->startupfile); |
---|
| 418 | return("/"); |
---|
| 419 | } |
---|
| 420 | |
---|
[8742840] | 421 | int owl_global_get_direction(const owl_global *g) { |
---|
[7d4fbcd] | 422 | return(g->direction); |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | void owl_global_set_direction_downwards(owl_global *g) { |
---|
| 426 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | void owl_global_set_direction_upwards(owl_global *g) { |
---|
| 430 | g->direction=OWL_DIRECTION_UPWARDS; |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | /* perl stuff */ |
---|
| 434 | |
---|
| 435 | void owl_global_set_perlinterp(owl_global *g, void *p) { |
---|
| 436 | g->perl=p; |
---|
| 437 | } |
---|
| 438 | |
---|
[8742840] | 439 | void *owl_global_get_perlinterp(const owl_global *g) { |
---|
[7d4fbcd] | 440 | return(g->perl); |
---|
| 441 | } |
---|
| 442 | |
---|
[8742840] | 443 | int owl_global_is_config_format(const owl_global *g) { |
---|
[7d4fbcd] | 444 | if (g->config_format) return(1); |
---|
| 445 | return(0); |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | void owl_global_set_config_format(owl_global *g, int state) { |
---|
| 449 | if (state==1) { |
---|
| 450 | g->config_format=1; |
---|
| 451 | } else { |
---|
| 452 | g->config_format=0; |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | void owl_global_set_have_config(owl_global *g) { |
---|
| 457 | g->haveconfig=1; |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | void owl_global_set_no_have_config(owl_global *g) { |
---|
| 461 | g->haveconfig=0; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | int owl_global_have_config(owl_global *g) { |
---|
| 465 | if (g->haveconfig) return(1); |
---|
| 466 | return(0); |
---|
| 467 | } |
---|
| 468 | |
---|
[285bc9a] | 469 | /* |
---|
| 470 | * Compute the size of the terminal. Try a ioctl, fallback to other stuff on |
---|
| 471 | * fail. |
---|
| 472 | */ |
---|
| 473 | static void _owl_global_get_size(int *lines, int *cols) { |
---|
| 474 | struct winsize size; |
---|
| 475 | /* get the new size */ |
---|
| 476 | ioctl(STDIN_FILENO, TIOCGWINSZ, &size); |
---|
| 477 | if (size.ws_row) { |
---|
| 478 | *lines = size.ws_row; |
---|
| 479 | } else { |
---|
| 480 | *lines = LINES; |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | if (size.ws_col) { |
---|
| 484 | *cols = size.ws_col; |
---|
| 485 | } else { |
---|
| 486 | *cols = COLS; |
---|
| 487 | } |
---|
| 488 | } |
---|
| 489 | |
---|
[7d4fbcd] | 490 | void owl_global_resize(owl_global *g, int x, int y) { |
---|
| 491 | /* resize the screen. If x or y is 0 use the terminal size */ |
---|
| 492 | if (!g->resizepending) return; |
---|
[8479494] | 493 | g->resizepending = 0; |
---|
[7d4fbcd] | 494 | |
---|
[285bc9a] | 495 | _owl_global_get_size(&g->lines, &g->cols); |
---|
| 496 | if (x != 0) { |
---|
| 497 | g->lines = x; |
---|
[7d4fbcd] | 498 | } |
---|
[285bc9a] | 499 | if (y != 0) { |
---|
| 500 | g->cols = y; |
---|
[7d4fbcd] | 501 | } |
---|
| 502 | |
---|
[1f3a423] | 503 | resizeterm(g->lines, g->cols); |
---|
[7d4fbcd] | 504 | |
---|
[f9f88f3] | 505 | owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols); |
---|
[f7cf6c2] | 506 | owl_global_set_relayout_pending(g); |
---|
[f9f88f3] | 507 | } |
---|
| 508 | |
---|
| 509 | void owl_global_relayout(owl_global *g) { |
---|
[719173c4] | 510 | owl_popwin *pw; |
---|
| 511 | owl_viewwin *vw; |
---|
| 512 | |
---|
[f7cf6c2] | 513 | if (!g->relayoutpending) return; |
---|
| 514 | g->relayoutpending = 0; |
---|
| 515 | |
---|
[f9f88f3] | 516 | owl_function_debugmsg("Relayouting..."); |
---|
| 517 | |
---|
[7d4fbcd] | 518 | /* re-initialize the windows */ |
---|
| 519 | _owl_global_setup_windows(g); |
---|
| 520 | |
---|
[f1e629d] | 521 | /* in case any styles rely on the current width */ |
---|
| 522 | owl_messagelist_invalidate_formats(owl_global_get_msglist(g)); |
---|
| 523 | |
---|
[c0f9e30] | 524 | /* recalculate the topmsg to make sure the current message is on |
---|
| 525 | * screen */ |
---|
| 526 | owl_function_calculate_topmsg(OWL_DIRECTION_NONE); |
---|
| 527 | |
---|
[719173c4] | 528 | /* recreate the popwin */ |
---|
| 529 | pw = owl_global_get_popwin(g); |
---|
| 530 | if (owl_popwin_is_active(pw)) { |
---|
| 531 | /* |
---|
| 532 | * This is somewhat hacky; we probably want a proper windowing layer. We |
---|
| 533 | * destroy the popwin and recreate it. Then the viewwin is redirected to |
---|
| 534 | * the new window. |
---|
| 535 | */ |
---|
| 536 | vw = owl_global_get_viewwin(g); |
---|
| 537 | owl_popwin_close(pw); |
---|
| 538 | owl_popwin_up(pw); |
---|
| 539 | owl_viewwin_set_curswin(vw, owl_popwin_get_curswin(pw), |
---|
| 540 | owl_popwin_get_lines(pw), owl_popwin_get_cols(pw)); |
---|
| 541 | owl_viewwin_redisplay(vw); |
---|
| 542 | } |
---|
| 543 | |
---|
[7d4fbcd] | 544 | /* refresh stuff */ |
---|
| 545 | g->needrefresh=1; |
---|
| 546 | owl_mainwin_redisplay(&(g->mw)); |
---|
| 547 | sepbar(NULL); |
---|
[38cc669] | 548 | if (g->tw) |
---|
| 549 | owl_editwin_redisplay(g->tw); |
---|
[59ab8dd] | 550 | else |
---|
| 551 | werase(owl_global_get_curs_typwin(g)); |
---|
| 552 | |
---|
[8240bce] | 553 | owl_function_full_redisplay(); |
---|
[7d4fbcd] | 554 | |
---|
| 555 | owl_function_makemsg(""); |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | /* debug */ |
---|
| 559 | |
---|
[8742840] | 560 | int owl_global_is_debug_fast(const owl_global *g) { |
---|
[7d4fbcd] | 561 | if (g->debug) return(1); |
---|
| 562 | return(0); |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | /* starttime */ |
---|
| 566 | |
---|
[8742840] | 567 | time_t owl_global_get_starttime(const owl_global *g) { |
---|
[7d4fbcd] | 568 | return(g->starttime); |
---|
| 569 | } |
---|
| 570 | |
---|
[8742840] | 571 | time_t owl_global_get_runtime(const owl_global *g) { |
---|
[7d4fbcd] | 572 | return(time(NULL)-g->starttime); |
---|
| 573 | } |
---|
| 574 | |
---|
[8742840] | 575 | time_t owl_global_get_lastinputtime(const owl_global *g) { |
---|
[7f792c1] | 576 | return(g->lastinputtime); |
---|
| 577 | } |
---|
| 578 | |
---|
[eebef19] | 579 | void owl_global_set_lastinputtime(owl_global *g, time_t time) { |
---|
| 580 | g->lastinputtime = time; |
---|
[7f792c1] | 581 | } |
---|
| 582 | |
---|
[8742840] | 583 | time_t owl_global_get_idletime(const owl_global *g) { |
---|
[7f792c1] | 584 | return(time(NULL)-g->lastinputtime); |
---|
| 585 | } |
---|
| 586 | |
---|
[8742840] | 587 | const char *owl_global_get_hostname(const owl_global *g) { |
---|
[a8938c7] | 588 | if (g->thishost) return(g->thishost); |
---|
| 589 | return(""); |
---|
[61e79a9] | 590 | } |
---|
| 591 | |
---|
[7d4fbcd] | 592 | /* userclue */ |
---|
| 593 | |
---|
| 594 | void owl_global_set_userclue(owl_global *g, int clue) { |
---|
| 595 | g->userclue=clue; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | void owl_global_add_userclue(owl_global *g, int clue) { |
---|
| 599 | g->userclue|=clue; |
---|
| 600 | } |
---|
| 601 | |
---|
[8742840] | 602 | int owl_global_get_userclue(const owl_global *g) { |
---|
[7d4fbcd] | 603 | return(g->userclue); |
---|
| 604 | } |
---|
| 605 | |
---|
[8742840] | 606 | int owl_global_is_userclue(const owl_global *g, int clue) { |
---|
[7d4fbcd] | 607 | if (g->userclue & clue) return(1); |
---|
| 608 | return(0); |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | /* viewwin */ |
---|
| 612 | |
---|
| 613 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
| 614 | return(&(g->vw)); |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | |
---|
| 618 | /* vert offset */ |
---|
| 619 | |
---|
[8742840] | 620 | int owl_global_get_curmsg_vert_offset(const owl_global *g) { |
---|
[7d4fbcd] | 621 | return(g->curmsg_vert_offset); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
| 625 | g->curmsg_vert_offset=i; |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | /* startup args */ |
---|
| 629 | |
---|
[e19eb97] | 630 | void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) { |
---|
[a8938c7] | 631 | int i, len; |
---|
| 632 | |
---|
| 633 | if (g->startupargs) owl_free(g->startupargs); |
---|
| 634 | |
---|
| 635 | len=0; |
---|
| 636 | for (i=0; i<argc; i++) { |
---|
[591e6aa7] | 637 | len+=strlen(argv[i])+5; |
---|
[a8938c7] | 638 | } |
---|
[34509d5] | 639 | g->startupargs=owl_malloc(len+5); |
---|
[7d4fbcd] | 640 | |
---|
| 641 | strcpy(g->startupargs, ""); |
---|
| 642 | for (i=0; i<argc; i++) { |
---|
[b9cb41b] | 643 | sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]); |
---|
[7d4fbcd] | 644 | } |
---|
| 645 | g->startupargs[strlen(g->startupargs)-1]='\0'; |
---|
| 646 | } |
---|
| 647 | |
---|
[8742840] | 648 | const char *owl_global_get_startupargs(const owl_global *g) { |
---|
[a8938c7] | 649 | if (g->startupargs) return(g->startupargs); |
---|
| 650 | return(""); |
---|
[7d4fbcd] | 651 | } |
---|
| 652 | |
---|
| 653 | /* history */ |
---|
| 654 | |
---|
[10b866d] | 655 | owl_history *owl_global_get_msg_history(owl_global *g) { |
---|
| 656 | return(&(g->msghist)); |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | owl_history *owl_global_get_cmd_history(owl_global *g) { |
---|
| 660 | return(&(g->cmdhist)); |
---|
[7d4fbcd] | 661 | } |
---|
| 662 | |
---|
| 663 | /* filterlist */ |
---|
[129e609] | 664 | typedef struct _owl_global_filter_ent { /* noproto */ |
---|
| 665 | owl_global *g; |
---|
| 666 | owl_filter *f; |
---|
| 667 | } owl_global_filter_ent; |
---|
[7d4fbcd] | 668 | |
---|
[8742840] | 669 | owl_filter *owl_global_get_filter(const owl_global *g, const char *name) { |
---|
[129e609] | 670 | owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name); |
---|
| 671 | if (e) return e->f; |
---|
| 672 | return NULL; |
---|
| 673 | } |
---|
[7d4fbcd] | 674 | |
---|
[5294cbf] | 675 | static void owl_global_delete_filter_ent(void *data) |
---|
| 676 | { |
---|
[129e609] | 677 | owl_global_filter_ent *e = data; |
---|
| 678 | e->g->filterlist = g_list_remove(e->g->filterlist, e->f); |
---|
| 679 | owl_filter_delete(e->f); |
---|
| 680 | owl_free(e); |
---|
[7d4fbcd] | 681 | } |
---|
| 682 | |
---|
| 683 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
[129e609] | 684 | owl_global_filter_ent *e = owl_malloc(sizeof *e); |
---|
| 685 | e->g = g; |
---|
| 686 | e->f = f; |
---|
| 687 | |
---|
| 688 | owl_dict_insert_element(&(g->filters), owl_filter_get_name(f), |
---|
[5294cbf] | 689 | e, owl_global_delete_filter_ent); |
---|
[129e609] | 690 | g->filterlist = g_list_append(g->filterlist, f); |
---|
[7d4fbcd] | 691 | } |
---|
| 692 | |
---|
[e19eb97] | 693 | void owl_global_remove_filter(owl_global *g, const char *name) { |
---|
[129e609] | 694 | owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name); |
---|
| 695 | if (e) |
---|
[5294cbf] | 696 | owl_global_delete_filter_ent(e); |
---|
[7d4fbcd] | 697 | } |
---|
| 698 | |
---|
| 699 | /* nextmsgid */ |
---|
| 700 | |
---|
| 701 | int owl_global_get_nextmsgid(owl_global *g) { |
---|
| 702 | return(g->nextmsgid++); |
---|
| 703 | } |
---|
| 704 | |
---|
| 705 | /* current view */ |
---|
| 706 | |
---|
| 707 | owl_view *owl_global_get_current_view(owl_global *g) { |
---|
| 708 | return(&(g->current_view)); |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | /* has colors */ |
---|
| 712 | |
---|
[8742840] | 713 | int owl_global_get_hascolors(const owl_global *g) { |
---|
[7d4fbcd] | 714 | if (g->hascolors) return(1); |
---|
| 715 | return(0); |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | /* color pairs */ |
---|
| 719 | |
---|
[8742840] | 720 | int owl_global_get_colorpairs(const owl_global *g) { |
---|
[7d4fbcd] | 721 | return(g->colorpairs); |
---|
| 722 | } |
---|
| 723 | |
---|
[8fa9562] | 724 | owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) { |
---|
| 725 | return(&(g->cpmgr)); |
---|
| 726 | } |
---|
| 727 | |
---|
[7d4fbcd] | 728 | /* puntlist */ |
---|
| 729 | |
---|
| 730 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 731 | return(&(g->puntlist)); |
---|
| 732 | } |
---|
| 733 | |
---|
[c08c70a] | 734 | int owl_global_message_is_puntable(owl_global *g, const owl_message *m) { |
---|
[77bced3] | 735 | const owl_list *pl; |
---|
[7d4fbcd] | 736 | int i, j; |
---|
| 737 | |
---|
| 738 | pl=owl_global_get_puntlist(g); |
---|
| 739 | j=owl_list_get_size(pl); |
---|
| 740 | for (i=0; i<j; i++) { |
---|
| 741 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
| 742 | } |
---|
| 743 | return(0); |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | int owl_global_should_followlast(owl_global *g) { |
---|
[9e5c9f3] | 747 | const owl_view *v; |
---|
[7d4fbcd] | 748 | |
---|
| 749 | if (!owl_global_is__followlast(g)) return(0); |
---|
| 750 | |
---|
| 751 | v=owl_global_get_current_view(g); |
---|
| 752 | |
---|
| 753 | if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1); |
---|
| 754 | return(0); |
---|
| 755 | } |
---|
[1fd0b25] | 756 | |
---|
[8742840] | 757 | int owl_global_is_search_active(const owl_global *g) { |
---|
[41c9a96] | 758 | if (owl_regex_is_set(&g->search_re)) return(1); |
---|
[1fd0b25] | 759 | return(0); |
---|
| 760 | } |
---|
| 761 | |
---|
[89b2daf] | 762 | void owl_global_set_search_re(owl_global *g, const owl_regex *re) { |
---|
[41c9a96] | 763 | if (owl_regex_is_set(&g->search_re)) { |
---|
[5cbc929] | 764 | owl_regex_cleanup(&g->search_re); |
---|
[41c9a96] | 765 | owl_regex_init(&g->search_re); |
---|
| 766 | } |
---|
| 767 | if (re != NULL) |
---|
| 768 | owl_regex_copy(re, &g->search_re); |
---|
[1fd0b25] | 769 | } |
---|
| 770 | |
---|
[8742840] | 771 | const owl_regex *owl_global_get_search_re(const owl_global *g) { |
---|
[41c9a96] | 772 | return &g->search_re; |
---|
[1fd0b25] | 773 | } |
---|
[700c712] | 774 | |
---|
[0e5afa2] | 775 | void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) { |
---|
[700c712] | 776 | g->newmsgproc_pid=i; |
---|
| 777 | } |
---|
| 778 | |
---|
[0e5afa2] | 779 | pid_t owl_global_get_newmsgproc_pid(const owl_global *g) { |
---|
[700c712] | 780 | return(g->newmsgproc_pid); |
---|
| 781 | } |
---|
| 782 | |
---|
[d09e5a1] | 783 | /* AIM stuff */ |
---|
| 784 | |
---|
[8742840] | 785 | int owl_global_is_aimloggedin(const owl_global *g) |
---|
[6a415e9] | 786 | { |
---|
[d09e5a1] | 787 | if (g->aim_loggedin) return(1); |
---|
| 788 | return(0); |
---|
| 789 | } |
---|
| 790 | |
---|
[8742840] | 791 | const char *owl_global_get_aim_screenname(const owl_global *g) |
---|
[6a415e9] | 792 | { |
---|
[a352335c] | 793 | if (owl_global_is_aimloggedin(g)) { |
---|
| 794 | return (g->aim_screenname); |
---|
| 795 | } |
---|
| 796 | return(""); |
---|
[d09e5a1] | 797 | } |
---|
| 798 | |
---|
[8742840] | 799 | const char *owl_global_get_aim_screenname_for_filters(const owl_global *g) |
---|
[81655f8] | 800 | { |
---|
| 801 | if (owl_global_is_aimloggedin(g)) { |
---|
| 802 | return (g->aim_screenname_for_filters); |
---|
| 803 | } |
---|
| 804 | return(""); |
---|
| 805 | } |
---|
| 806 | |
---|
[e19eb97] | 807 | void owl_global_set_aimloggedin(owl_global *g, const char *screenname) |
---|
[6a415e9] | 808 | { |
---|
[65b2173] | 809 | char *sn_escaped; |
---|
[e19eb97] | 810 | const char *quote; |
---|
[d09e5a1] | 811 | g->aim_loggedin=1; |
---|
| 812 | if (g->aim_screenname) owl_free(g->aim_screenname); |
---|
[81655f8] | 813 | if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters); |
---|
[d09e5a1] | 814 | g->aim_screenname=owl_strdup(screenname); |
---|
[81655f8] | 815 | sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 816 | quote = owl_getquoting(sn_escaped); |
---|
[9f4e3f8] | 817 | g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote); |
---|
[81655f8] | 818 | owl_free(sn_escaped); |
---|
[d09e5a1] | 819 | } |
---|
| 820 | |
---|
[6a415e9] | 821 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
| 822 | { |
---|
[d09e5a1] | 823 | g->aim_loggedin=0; |
---|
| 824 | } |
---|
| 825 | |
---|
[8742840] | 826 | int owl_global_is_doaimevents(const owl_global *g) |
---|
[a352335c] | 827 | { |
---|
| 828 | if (g->aim_doprocessing) return(1); |
---|
| 829 | return(0); |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | void owl_global_set_doaimevents(owl_global *g) |
---|
| 833 | { |
---|
| 834 | g->aim_doprocessing=1; |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | void owl_global_set_no_doaimevents(owl_global *g) |
---|
| 838 | { |
---|
| 839 | g->aim_doprocessing=0; |
---|
| 840 | } |
---|
| 841 | |
---|
[6a415e9] | 842 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
| 843 | { |
---|
[d09e5a1] | 844 | return(&(g->aimsess)); |
---|
| 845 | } |
---|
| 846 | |
---|
[c15bbfb] | 847 | aim_conn_t *owl_global_get_bosconn(owl_global *g) |
---|
| 848 | { |
---|
| 849 | return(&(g->bosconn)); |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn) |
---|
[6a415e9] | 853 | { |
---|
[c15bbfb] | 854 | g->bosconn=*conn; |
---|
[d09e5a1] | 855 | } |
---|
| 856 | |
---|
| 857 | /* message queue */ |
---|
| 858 | |
---|
[6a415e9] | 859 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
| 860 | { |
---|
[20aced3] | 861 | g_queue_push_tail(g->messagequeue, m); |
---|
[d09e5a1] | 862 | } |
---|
| 863 | |
---|
| 864 | /* pop off the first message and return it. Return NULL if the queue |
---|
| 865 | * is empty. The caller should free the message after using it, if |
---|
| 866 | * necessary. |
---|
| 867 | */ |
---|
[13a3c1db] | 868 | owl_message *owl_global_messagequeue_popmsg(owl_global *g) |
---|
[6a415e9] | 869 | { |
---|
[d09e5a1] | 870 | owl_message *out; |
---|
| 871 | |
---|
[20aced3] | 872 | if (g_queue_is_empty(g->messagequeue)) |
---|
| 873 | return NULL; |
---|
| 874 | out = g_queue_pop_head(g->messagequeue); |
---|
| 875 | return out; |
---|
[d09e5a1] | 876 | } |
---|
| 877 | |
---|
[6a415e9] | 878 | int owl_global_messagequeue_pending(owl_global *g) |
---|
| 879 | { |
---|
[20aced3] | 880 | return !g_queue_is_empty(g->messagequeue); |
---|
[d09e5a1] | 881 | } |
---|
[aa5f725] | 882 | |
---|
[6a415e9] | 883 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
| 884 | { |
---|
[aa5f725] | 885 | return(&(g->buddylist)); |
---|
| 886 | } |
---|
| 887 | |
---|
[bd3f232] | 888 | /* style */ |
---|
| 889 | |
---|
| 890 | /* Return the style with name 'name'. If it does not exist return |
---|
| 891 | * NULL */ |
---|
[8742840] | 892 | const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name) |
---|
[bd3f232] | 893 | { |
---|
[f1e629d] | 894 | return owl_dict_find_element(&(g->styledict), name); |
---|
| 895 | } |
---|
| 896 | |
---|
| 897 | /* creates a list and fills it in with keys. duplicates the keys, |
---|
| 898 | * so they will need to be freed by the caller. */ |
---|
[8742840] | 899 | int owl_global_get_style_names(const owl_global *g, owl_list *l) { |
---|
[f1e629d] | 900 | return owl_dict_get_keys(&(g->styledict), l); |
---|
[bd3f232] | 901 | } |
---|
| 902 | |
---|
[cf83b7a] | 903 | void owl_global_add_style(owl_global *g, owl_style *s) |
---|
| 904 | { |
---|
[f1fc47f] | 905 | /* |
---|
| 906 | * If we're redefining the current style, make sure to update |
---|
| 907 | * pointers to it. |
---|
| 908 | */ |
---|
| 909 | if(g->current_view.style |
---|
| 910 | && !strcmp(owl_style_get_name(g->current_view.style), |
---|
| 911 | owl_style_get_name(s))) |
---|
| 912 | g->current_view.style = s; |
---|
| 913 | owl_dict_insert_element(&(g->styledict), owl_style_get_name(s), |
---|
[516c27e] | 914 | s, (void (*)(void *))owl_style_delete); |
---|
[bd3f232] | 915 | } |
---|
[cf83b7a] | 916 | |
---|
[09489b89] | 917 | void owl_global_set_haveaim(owl_global *g) |
---|
| 918 | { |
---|
| 919 | g->haveaim=1; |
---|
| 920 | } |
---|
| 921 | |
---|
[8742840] | 922 | int owl_global_is_haveaim(const owl_global *g) |
---|
[09489b89] | 923 | { |
---|
| 924 | if (g->haveaim) return(1); |
---|
| 925 | return(0); |
---|
| 926 | } |
---|
| 927 | |
---|
[b7bb454] | 928 | void owl_global_set_ignore_aimlogin(owl_global *g) |
---|
| 929 | { |
---|
| 930 | g->ignoreaimlogin = 1; |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | void owl_global_unset_ignore_aimlogin(owl_global *g) |
---|
| 934 | { |
---|
| 935 | g->ignoreaimlogin = 0; |
---|
| 936 | } |
---|
| 937 | |
---|
[8742840] | 938 | int owl_global_is_ignore_aimlogin(const owl_global *g) |
---|
[b7bb454] | 939 | { |
---|
| 940 | return g->ignoreaimlogin; |
---|
| 941 | } |
---|
| 942 | |
---|
[09489b89] | 943 | void owl_global_set_havezephyr(owl_global *g) |
---|
| 944 | { |
---|
| 945 | g->havezephyr=1; |
---|
| 946 | } |
---|
| 947 | |
---|
[8742840] | 948 | int owl_global_is_havezephyr(const owl_global *g) |
---|
[09489b89] | 949 | { |
---|
| 950 | if (g->havezephyr) return(1); |
---|
| 951 | return(0); |
---|
| 952 | } |
---|
[de03334] | 953 | |
---|
[ec6ff52] | 954 | owl_errqueue *owl_global_get_errqueue(owl_global *g) |
---|
| 955 | { |
---|
| 956 | return(&(g->errqueue)); |
---|
| 957 | } |
---|
[c9e72d1] | 958 | |
---|
| 959 | void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo) |
---|
| 960 | { |
---|
| 961 | g->got_err_signal = signum; |
---|
| 962 | if (siginfo) { |
---|
| 963 | g->err_signal_info = *siginfo; |
---|
| 964 | } else { |
---|
[7892963] | 965 | siginfo_t si; |
---|
| 966 | memset(&si, 0, sizeof(si)); |
---|
| 967 | g->err_signal_info = si; |
---|
[c9e72d1] | 968 | } |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo) |
---|
| 972 | { |
---|
| 973 | int signum; |
---|
| 974 | if (siginfo && g->got_err_signal) { |
---|
| 975 | *siginfo = g->err_signal_info; |
---|
| 976 | } |
---|
| 977 | signum = g->got_err_signal; |
---|
| 978 | g->got_err_signal = 0; |
---|
| 979 | return signum; |
---|
| 980 | } |
---|
| 981 | |
---|
[5a95b69] | 982 | |
---|
| 983 | owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) |
---|
| 984 | { |
---|
| 985 | return(&(g->zbuddies)); |
---|
| 986 | } |
---|
[8232149] | 987 | |
---|
[f25812b] | 988 | GList **owl_global_get_zaldlist(owl_global *g) |
---|
| 989 | { |
---|
| 990 | return &(g->zaldlist); |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | int owl_global_get_pseudologin_notify(owl_global *g) |
---|
| 994 | { |
---|
| 995 | return g->pseudologin_notify; |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | void owl_global_set_pseudologin_notify(owl_global *g, int notify) |
---|
| 999 | { |
---|
| 1000 | g->pseudologin_notify = notify; |
---|
| 1001 | } |
---|
| 1002 | |
---|
[8232149] | 1003 | struct termios *owl_global_get_startup_tio(owl_global *g) |
---|
| 1004 | { |
---|
| 1005 | return(&(g->startup_tio)); |
---|
| 1006 | } |
---|
[8e401cae] | 1007 | |
---|
[df0138f] | 1008 | owl_list *owl_global_get_io_dispatch_list(owl_global *g) |
---|
| 1009 | { |
---|
| 1010 | return &(g->io_dispatch_list); |
---|
| 1011 | } |
---|
| 1012 | |
---|
[4f2166b] | 1013 | owl_list *owl_global_get_psa_list(owl_global *g) |
---|
| 1014 | { |
---|
| 1015 | return &(g->psa_list); |
---|
| 1016 | } |
---|
| 1017 | |
---|
[58d1f8a] | 1018 | GList **owl_global_get_timerlist(owl_global *g) |
---|
[b7bb454] | 1019 | { |
---|
[58d1f8a] | 1020 | return &(g->timerlist); |
---|
[b7bb454] | 1021 | } |
---|
[adee9cc] | 1022 | |
---|
[8742840] | 1023 | int owl_global_is_interrupted(const owl_global *g) { |
---|
[0cb6c26] | 1024 | return g->interrupted; |
---|
[adee9cc] | 1025 | } |
---|
| 1026 | |
---|
| 1027 | void owl_global_set_interrupted(owl_global *g) { |
---|
| 1028 | g->interrupted = 1; |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | void owl_global_unset_interrupted(owl_global *g) { |
---|
| 1032 | g->interrupted = 0; |
---|
| 1033 | } |
---|
[04b16f8] | 1034 | |
---|
| 1035 | void owl_global_setup_default_filters(owl_global *g) |
---|
| 1036 | { |
---|
| 1037 | int i; |
---|
| 1038 | static const struct { |
---|
| 1039 | const char *name; |
---|
| 1040 | const char *desc; |
---|
| 1041 | } filters[] = { |
---|
| 1042 | { "personal", |
---|
| 1043 | "private ^true$ and ( not type ^zephyr$ or " |
---|
| 1044 | "( class ^message and ( instance ^personal$ or instance ^urgent$ ) ) )" }, |
---|
| 1045 | { "trash", |
---|
| 1046 | "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" }, |
---|
| 1047 | { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" }, |
---|
| 1048 | { "ping", "opcode ^ping$" }, |
---|
| 1049 | { "auto", "opcode ^auto$" }, |
---|
| 1050 | { "login", "not login ^none$" }, |
---|
| 1051 | { "reply-lockout", "class ^noc or class ^mail$" }, |
---|
| 1052 | { "out", "direction ^out$" }, |
---|
| 1053 | { "aim", "type ^aim$" }, |
---|
| 1054 | { "zephyr", "type ^zephyr$" }, |
---|
| 1055 | { "none", "false" }, |
---|
| 1056 | { "all", "true" }, |
---|
| 1057 | { NULL, NULL } |
---|
| 1058 | }; |
---|
| 1059 | |
---|
| 1060 | owl_function_debugmsg("startup: creating default filters"); |
---|
| 1061 | |
---|
| 1062 | for (i = 0; filters[i].name != NULL; i++) |
---|
| 1063 | owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name, |
---|
| 1064 | filters[i].desc)); |
---|
| 1065 | } |
---|