Mercurial > hg
changeset 322:da138cdebf04
Implement auto-away mode
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 15 Jul 2005 22:08:53 +0100 |
parents | 59193965f2cb |
children | 170bfbc1f1f6 |
files | mcabber/mcabberrc.example mcabber/src/main.c mcabber/src/screen.c mcabber/src/screen.h |
diffstat | 4 files changed, 59 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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)
--- 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);