# HG changeset patch # User Mikael Berthe # Date 1121461733 -3600 # Node ID da138cdebf04af36c51402f7e89932da9fa5f371 # Parent 59193965f2cb2a1b30df931332bc7ce8b0848640 Implement auto-away mode diff -r 59193965f2cb -r da138cdebf04 mcabber/mcabberrc.example --- a/mcabber/mcabberrc.example Fri Jul 15 19:12:50 2005 +0100 +++ b/mcabber/mcabberrc.example Fri Jul 15 22:08:53 2005 +0100 @@ -24,6 +24,11 @@ # in the roster. #hide_offline_buddies = 0 +# Set the auto-away timeout, in seconds. If set to a value >0, +# mcabber will change your status to away if no real activity is detected +# (command, message, move in the buddylist...) +#set autoaway = 0 + # History logging # You can save the messages history: set logging = 1 # You can load (read) the messages history: set load_logs = 1 @@ -52,7 +57,7 @@ #message_dnd = Please do not disturb #message_notavail = I'm not available #message_away = I'm away -#message_autoaway = Auto-away (Not yet implemented) +#message_autoaway = Auto-away # The colors # Colors are: black, red, green, yellow, blue, magenta, cyan, white diff -r 59193965f2cb -r da138cdebf04 mcabber/src/main.c --- a/mcabber/src/main.c Fri Jul 15 19:12:50 2005 +0100 +++ b/mcabber/src/main.c Fri Jul 15 22:08:53 2005 +0100 @@ -268,6 +268,7 @@ /* The refresh is really an ugly hack, but we need to call doupdate() from time to time to catch the RESIZE events, because getch keep returning ERR until a real key is pressed :-( + However, it allows us to handle an autoaway check here... */ if (key != ERR) { ret = process_key(key); @@ -275,6 +276,7 @@ } else if (refresh++ > 1) { doupdate(); refresh = 0; + scr_CheckAutoAway(FALSE); } if (key != KEY_RESIZE) diff -r 59193965f2cb -r da138cdebf04 mcabber/src/screen.c --- a/mcabber/src/screen.c Fri Jul 15 19:12:50 2005 +0100 +++ b/mcabber/src/screen.c Fri Jul 15 22:08:53 2005 +0100 @@ -69,6 +69,7 @@ static char *multiline; int update_roster; int utf8_mode = 0; +static bool Autoaway; static char inputLine[INPUTLINE_LENGTH+1]; static char *ptr_inputline; @@ -484,6 +485,47 @@ return; } +void inline set_autoaway(bool setaway) +{ + static enum imstatus oldstatus; + Autoaway = setaway; + + if (setaway) { + const char *msg; + oldstatus = jb_getstatus(); + msg = settings_opt_get("message_autoaway"); + if (!msg) msg = MSG_AUTOAWAY; + jb_setstatus(away, msg); + } else { + // Back + jb_setstatus(oldstatus, NULL); + } +} + +// Check if we should enter/leave automatic away status +void scr_CheckAutoAway(bool activity) +{ + static time_t LastActivity; + enum imstatus cur_st; + unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); + + if (Autoaway && activity) set_autoaway(FALSE); + if (!autoaway_timeout) return; + if (!LastActivity || activity) time(&LastActivity); + + cur_st = jb_getstatus(); + // Auto-away is disabled for the following states + if ((cur_st == away) || (cur_st == notavail) || (cur_st == invisible)) + return; + + if (!activity) { + time_t now; + time(&now); + if (!Autoaway && (now > LastActivity + autoaway_timeout)) + set_autoaway(TRUE); + } +} + // scr_DrawMainWindow() // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. // @@ -1554,6 +1596,7 @@ break; case '\n': // Enter case 15: // Ctrl-o ("accept-line-and-down-history") + scr_CheckAutoAway(TRUE); if (process_line(inputLine)) return 255; // Add line to history @@ -1595,9 +1638,11 @@ } break; case KEY_PPAGE: + scr_CheckAutoAway(TRUE); scr_RosterUp(); break; case KEY_NPAGE: + scr_CheckAutoAway(TRUE); scr_RosterDown(); break; case KEY_HOME: @@ -1626,6 +1671,7 @@ scr_ScrollDown(); break; case 17: // Ctrl-q + scr_CheckAutoAway(TRUE); scr_RosterUnreadMessage(1); // next unread message break; case 20: // Ctrl-t @@ -1635,6 +1681,7 @@ readline_backward_kill_word(); break; case 27: // ESC + scr_CheckAutoAway(TRUE); currentWindow = NULL; chatmode = FALSE; if (current_buddy) @@ -1645,6 +1692,7 @@ break; case 12: // Ctrl-l case KEY_RESIZE: + scr_CheckAutoAway(TRUE); scr_Resize(); break; default: @@ -1652,6 +1700,7 @@ const gchar *boundcmd = isbound(key); if (boundcmd) { gchar *cmd = g_strdup_printf("/%s", boundcmd); + scr_CheckAutoAway(TRUE); if (process_command(cmd)) return 255; g_free(cmd); diff -r 59193965f2cb -r da138cdebf04 mcabber/src/screen.h --- a/mcabber/src/screen.h Fri Jul 15 19:12:50 2005 +0100 +++ b/mcabber/src/screen.h Fri Jul 15 22:08:53 2005 +0100 @@ -45,6 +45,8 @@ int process_key(int); +void scr_CheckAutoAway(bool activity); + // For commands... void scr_RosterTop(void); void scr_RosterBottom(void);