Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 322:da138cdebf04
Implement auto-away mode
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 15 Jul 2005 22:08:53 +0100 |
parents | 1ceb68eb2fc1 |
children | ff6fb51bfd78 |
comparison
equal
deleted
inserted
replaced
321:59193965f2cb | 322:da138cdebf04 |
---|---|
67 static int chatmode; | 67 static int chatmode; |
68 static int multimode; | 68 static int multimode; |
69 static char *multiline; | 69 static char *multiline; |
70 int update_roster; | 70 int update_roster; |
71 int utf8_mode = 0; | 71 int utf8_mode = 0; |
72 static bool Autoaway; | |
72 | 73 |
73 static char inputLine[INPUTLINE_LENGTH+1]; | 74 static char inputLine[INPUTLINE_LENGTH+1]; |
74 static char *ptr_inputline; | 75 static char *ptr_inputline; |
75 static short int inputline_offset; | 76 static short int inputline_offset; |
76 static int completion_started; | 77 static int completion_started; |
482 refresh(); | 483 refresh(); |
483 endwin(); | 484 endwin(); |
484 return; | 485 return; |
485 } | 486 } |
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 == away) || (cur_st == notavail) || (cur_st == invisible)) | |
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 } | |
527 } | |
528 | |
487 // scr_DrawMainWindow() | 529 // scr_DrawMainWindow() |
488 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. | 530 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. |
489 // | 531 // |
490 // I think it could be improved a _lot_ but I'm really not an ncurses | 532 // I think it could be improved a _lot_ but I'm really not an ncurses |
491 // expert... :-\ Mikael. | 533 // expert... :-\ Mikael. |
1552 scr_handle_tab(); | 1594 scr_handle_tab(); |
1553 check_offset(0); | 1595 check_offset(0); |
1554 break; | 1596 break; |
1555 case '\n': // Enter | 1597 case '\n': // Enter |
1556 case 15: // Ctrl-o ("accept-line-and-down-history") | 1598 case 15: // Ctrl-o ("accept-line-and-down-history") |
1599 scr_CheckAutoAway(TRUE); | |
1557 if (process_line(inputLine)) | 1600 if (process_line(inputLine)) |
1558 return 255; | 1601 return 255; |
1559 // Add line to history | 1602 // Add line to history |
1560 scr_cmdhisto_addline(inputLine); | 1603 scr_cmdhisto_addline(inputLine); |
1561 // Reset the line | 1604 // Reset the line |
1593 strcpy(inputLine, l); | 1636 strcpy(inputLine, l); |
1594 } | 1637 } |
1595 } | 1638 } |
1596 break; | 1639 break; |
1597 case KEY_PPAGE: | 1640 case KEY_PPAGE: |
1641 scr_CheckAutoAway(TRUE); | |
1598 scr_RosterUp(); | 1642 scr_RosterUp(); |
1599 break; | 1643 break; |
1600 case KEY_NPAGE: | 1644 case KEY_NPAGE: |
1645 scr_CheckAutoAway(TRUE); | |
1601 scr_RosterDown(); | 1646 scr_RosterDown(); |
1602 break; | 1647 break; |
1603 case KEY_HOME: | 1648 case KEY_HOME: |
1604 case 1: | 1649 case 1: |
1605 ptr_inputline = inputLine; | 1650 ptr_inputline = inputLine; |
1624 break; | 1669 break; |
1625 case 14: // Ctrl-n | 1670 case 14: // Ctrl-n |
1626 scr_ScrollDown(); | 1671 scr_ScrollDown(); |
1627 break; | 1672 break; |
1628 case 17: // Ctrl-q | 1673 case 17: // Ctrl-q |
1674 scr_CheckAutoAway(TRUE); | |
1629 scr_RosterUnreadMessage(1); // next unread message | 1675 scr_RosterUnreadMessage(1); // next unread message |
1630 break; | 1676 break; |
1631 case 20: // Ctrl-t | 1677 case 20: // Ctrl-t |
1632 readline_transpose_chars(); | 1678 readline_transpose_chars(); |
1633 break; | 1679 break; |
1634 case 23: // Ctrl-w | 1680 case 23: // Ctrl-w |
1635 readline_backward_kill_word(); | 1681 readline_backward_kill_word(); |
1636 break; | 1682 break; |
1637 case 27: // ESC | 1683 case 27: // ESC |
1684 scr_CheckAutoAway(TRUE); | |
1638 currentWindow = NULL; | 1685 currentWindow = NULL; |
1639 chatmode = FALSE; | 1686 chatmode = FALSE; |
1640 if (current_buddy) | 1687 if (current_buddy) |
1641 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | 1688 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
1642 top_panel(chatPanel); | 1689 top_panel(chatPanel); |
1643 top_panel(inputPanel); | 1690 top_panel(inputPanel); |
1644 update_panels(); | 1691 update_panels(); |
1645 break; | 1692 break; |
1646 case 12: // Ctrl-l | 1693 case 12: // Ctrl-l |
1647 case KEY_RESIZE: | 1694 case KEY_RESIZE: |
1695 scr_CheckAutoAway(TRUE); | |
1648 scr_Resize(); | 1696 scr_Resize(); |
1649 break; | 1697 break; |
1650 default: | 1698 default: |
1651 { | 1699 { |
1652 const gchar *boundcmd = isbound(key); | 1700 const gchar *boundcmd = isbound(key); |
1653 if (boundcmd) { | 1701 if (boundcmd) { |
1654 gchar *cmd = g_strdup_printf("/%s", boundcmd); | 1702 gchar *cmd = g_strdup_printf("/%s", boundcmd); |
1703 scr_CheckAutoAway(TRUE); | |
1655 if (process_command(cmd)) | 1704 if (process_command(cmd)) |
1656 return 255; | 1705 return 255; |
1657 g_free(cmd); | 1706 g_free(cmd); |
1658 } else { | 1707 } else { |
1659 scr_LogPrint("Unknown key=%d", key); | 1708 scr_LogPrint("Unknown key=%d", key); |