Mercurial > hg
comparison mcabber/src/screen.c @ 373:af2f8ddf6a1b
Move (reorganize) functions
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 25 Jul 2005 19:40:17 +0100 |
parents | dd9e2eb52916 |
children | bd5638c21834 |
comparison
equal
deleted
inserted
replaced
372:db004de6440c | 373:af2f8ddf6a1b |
---|---|
193 FindColor(background)); | 193 FindColor(background)); |
194 break; | 194 break; |
195 } | 195 } |
196 i++; | 196 i++; |
197 } | 197 } |
198 } | |
199 | |
200 void scr_InitCurses(void) | |
201 { | |
202 initscr(); | |
203 noecho(); | |
204 raw(); | |
205 halfdelay(5); | |
206 start_color(); | |
207 use_default_colors(); | |
208 Curses = TRUE; | |
209 | |
210 ParseColors(); | |
211 | |
212 getmaxyx(stdscr, maxY, maxX); | |
213 if (maxY < LOG_WIN_HEIGHT+2) | |
214 maxY = LOG_WIN_HEIGHT+2; | |
215 inputLine[0] = 0; | |
216 ptr_inputline = inputLine; | |
217 | |
218 setlocale(LC_CTYPE, ""); | |
219 utf8_mode = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0); | |
220 | |
221 return; | |
222 } | |
223 | |
224 void scr_TerminateCurses(void) | |
225 { | |
226 if (!Curses) return; | |
227 clear(); | |
228 refresh(); | |
229 endwin(); | |
230 Curses = FALSE; | |
231 return; | |
232 } | |
233 | |
234 // scr_LogPrint(...) | |
235 // Display a message in the log window. | |
236 void scr_LogPrint(const char *fmt, ...) | |
237 { | |
238 time_t timestamp; | |
239 char *buffer; | |
240 va_list ap; | |
241 | |
242 do { | |
243 buffer = (char *) calloc(1, 1024); | |
244 } while (!buffer); | |
245 | |
246 timestamp = time(NULL); | |
247 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); | |
248 if (Curses) | |
249 wprintw(logWnd, "\n%s", buffer); | |
250 else | |
251 printf("%s", buffer); | |
252 | |
253 va_start(ap, fmt); | |
254 vsnprintf(buffer, 1024, fmt, ap); | |
255 va_end(ap); | |
256 | |
257 if (Curses) { | |
258 wprintw(logWnd, "%s", buffer); | |
259 update_panels(); | |
260 doupdate(); | |
261 } else { | |
262 printf("%s\n", buffer); | |
263 } | |
264 free(buffer); | |
198 } | 265 } |
199 | 266 |
200 static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) | 267 static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) |
201 { | 268 { |
202 int x; | 269 int x; |
388 } | 455 } |
389 | 456 |
390 scr_ShowWindow(jid); | 457 scr_ShowWindow(jid); |
391 } | 458 } |
392 | 459 |
393 | |
394 // scr_WriteInWindow() | 460 // scr_WriteInWindow() |
395 // Write some text in the winId window (this usually is a jid). | 461 // Write some text in the winId window (this usually is a jid). |
396 // Lines are splitted when they are too long to fit in the chat window. | 462 // Lines are splitted when they are too long to fit in the chat window. |
397 // If this window doesn't exist, it is created. | 463 // If this window doesn't exist, it is created. |
398 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, | 464 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, |
446 update_panels(); | 512 update_panels(); |
447 doupdate(); | 513 doupdate(); |
448 } else { | 514 } else { |
449 roster_msg_setflag(winId, TRUE); | 515 roster_msg_setflag(winId, TRUE); |
450 update_roster = TRUE; | 516 update_roster = TRUE; |
451 } | |
452 } | |
453 | |
454 void scr_InitCurses(void) | |
455 { | |
456 initscr(); | |
457 noecho(); | |
458 raw(); | |
459 halfdelay(5); | |
460 start_color(); | |
461 use_default_colors(); | |
462 Curses = TRUE; | |
463 | |
464 ParseColors(); | |
465 | |
466 getmaxyx(stdscr, maxY, maxX); | |
467 if (maxY < LOG_WIN_HEIGHT+2) | |
468 maxY = LOG_WIN_HEIGHT+2; | |
469 inputLine[0] = 0; | |
470 ptr_inputline = inputLine; | |
471 | |
472 setlocale(LC_CTYPE, ""); | |
473 utf8_mode = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0); | |
474 | |
475 return; | |
476 } | |
477 | |
478 void scr_TerminateCurses(void) | |
479 { | |
480 if (!Curses) return; | |
481 clear(); | |
482 refresh(); | |
483 endwin(); | |
484 Curses = FALSE; | |
485 return; | |
486 } | |
487 | |
488 void inline set_autoaway(bool setaway) | |
489 { | |
490 static enum imstatus oldstatus; | |
491 Autoaway = setaway; | |
492 | |
493 if (setaway) { | |
494 const char *msg; | |
495 oldstatus = jb_getstatus(); | |
496 msg = settings_opt_get("message_autoaway"); | |
497 if (!msg) msg = MSG_AUTOAWAY; | |
498 jb_setstatus(away, msg); | |
499 } else { | |
500 // Back | |
501 jb_setstatus(oldstatus, NULL); | |
502 } | |
503 } | |
504 | |
505 // Check if we should enter/leave automatic away status | |
506 void scr_CheckAutoAway(bool activity) | |
507 { | |
508 static time_t LastActivity; | |
509 enum imstatus cur_st; | |
510 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); | |
511 | |
512 if (Autoaway && activity) set_autoaway(FALSE); | |
513 if (!autoaway_timeout) return; | |
514 if (!LastActivity || activity) time(&LastActivity); | |
515 | |
516 cur_st = jb_getstatus(); | |
517 // Auto-away is disabled for the following states | |
518 if ((cur_st != available) && (cur_st != freeforchat)) | |
519 return; | |
520 | |
521 if (!activity) { | |
522 time_t now; | |
523 time(&now); | |
524 if (!Autoaway && (now > LastActivity + autoaway_timeout)) | |
525 set_autoaway(TRUE); | |
526 } | 517 } |
527 } | 518 } |
528 | 519 |
529 // scr_DrawMainWindow() | 520 // scr_DrawMainWindow() |
530 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. | 521 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. |
781 { | 772 { |
782 scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT); | 773 scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT); |
783 scr_ShowWindow(jidto); | 774 scr_ShowWindow(jidto); |
784 } | 775 } |
785 | 776 |
786 int scr_Getch(void) | 777 void inline set_autoaway(bool setaway) |
787 { | 778 { |
788 int ch; | 779 static enum imstatus oldstatus; |
789 ch = wgetch(inputWnd); | 780 Autoaway = setaway; |
790 return ch; | 781 |
782 if (setaway) { | |
783 const char *msg; | |
784 oldstatus = jb_getstatus(); | |
785 msg = settings_opt_get("message_autoaway"); | |
786 if (!msg) msg = MSG_AUTOAWAY; | |
787 jb_setstatus(away, msg); | |
788 } else { | |
789 // Back | |
790 jb_setstatus(oldstatus, NULL); | |
791 } | |
792 } | |
793 | |
794 // Check if we should enter/leave automatic away status | |
795 void scr_CheckAutoAway(bool activity) | |
796 { | |
797 static time_t LastActivity; | |
798 enum imstatus cur_st; | |
799 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); | |
800 | |
801 if (Autoaway && activity) set_autoaway(FALSE); | |
802 if (!autoaway_timeout) return; | |
803 if (!LastActivity || activity) time(&LastActivity); | |
804 | |
805 cur_st = jb_getstatus(); | |
806 // Auto-away is disabled for the following states | |
807 if ((cur_st != available) && (cur_st != freeforchat)) | |
808 return; | |
809 | |
810 if (!activity) { | |
811 time_t now; | |
812 time(&now); | |
813 if (!Autoaway && (now > LastActivity + autoaway_timeout)) | |
814 set_autoaway(TRUE); | |
815 } | |
791 } | 816 } |
792 | 817 |
793 // set_current_buddy(newbuddy) | 818 // set_current_buddy(newbuddy) |
794 // Set the current_buddy to newbuddy (if not NULL) | 819 // Set the current_buddy to newbuddy (if not NULL) |
795 // Lock the newbuddy, and unlock the previous current_buddy | 820 // Lock the newbuddy, and unlock the previous current_buddy |
1037 doupdate(); | 1062 doupdate(); |
1038 } else | 1063 } else |
1039 scr_LogPrint("Search string not found"); | 1064 scr_LogPrint("Search string not found"); |
1040 } | 1065 } |
1041 | 1066 |
1042 // scr_LogPrint(...) | |
1043 // Display a message in the log window. | |
1044 void scr_LogPrint(const char *fmt, ...) | |
1045 { | |
1046 time_t timestamp; | |
1047 char *buffer; | |
1048 va_list ap; | |
1049 | |
1050 do { | |
1051 buffer = (char *) calloc(1, 1024); | |
1052 } while (!buffer); | |
1053 | |
1054 timestamp = time(NULL); | |
1055 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); | |
1056 if (Curses) | |
1057 wprintw(logWnd, "\n%s", buffer); | |
1058 else | |
1059 printf("%s", buffer); | |
1060 | |
1061 va_start(ap, fmt); | |
1062 vsnprintf(buffer, 1024, fmt, ap); | |
1063 va_end(ap); | |
1064 | |
1065 if (Curses) { | |
1066 wprintw(logWnd, "%s", buffer); | |
1067 update_panels(); | |
1068 doupdate(); | |
1069 } else { | |
1070 printf("%s\n", buffer); | |
1071 } | |
1072 free(buffer); | |
1073 } | |
1074 | |
1075 // scr_set_chatmode() | 1067 // scr_set_chatmode() |
1076 // Public function to (un)set chatmode... | 1068 // Public function to (un)set chatmode... |
1077 inline void scr_set_chatmode(int enable) | 1069 inline void scr_set_chatmode(int enable) |
1078 { | 1070 { |
1079 chatmode = enable; | 1071 chatmode = enable; |
1439 // Same as Ctrl-g, now | 1431 // Same as Ctrl-g, now |
1440 scr_cancel_current_completion(); | 1432 scr_cancel_current_completion(); |
1441 scr_end_current_completion(); | 1433 scr_end_current_completion(); |
1442 check_offset(-1); | 1434 check_offset(-1); |
1443 refresh_inputline(); | 1435 refresh_inputline(); |
1436 } | |
1437 | |
1438 int scr_Getch(void) | |
1439 { | |
1440 int ch; | |
1441 ch = wgetch(inputWnd); | |
1442 return ch; | |
1444 } | 1443 } |
1445 | 1444 |
1446 // process_key(key) | 1445 // process_key(key) |
1447 // Handle the pressed key, in the command line (bottom). | 1446 // Handle the pressed key, in the command line (bottom). |
1448 int process_key(int key) | 1447 int process_key(int key) |