Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/screen.c @ 1677:9a0ed33fb91b
Fix autoaway
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Wed, 20 Jan 2010 11:08:03 +0200 |
parents | 41c26b7d2890 |
children | 393c05fba337 |
comparison
equal
deleted
inserted
replaced
1676:96b5484423af | 1677:9a0ed33fb91b |
---|---|
121 int update_roster; | 121 int update_roster; |
122 int utf8_mode = 0; | 122 int utf8_mode = 0; |
123 static bool Curses; | 123 static bool Curses; |
124 static bool log_win_on_top; | 124 static bool log_win_on_top; |
125 static bool roster_win_on_right; | 125 static bool roster_win_on_right; |
126 static time_t LastActivity; | 126 static guint autoaway_source = 0; |
127 | 127 |
128 static char inputLine[INPUTLINE_LENGTH+1]; | 128 static char inputLine[INPUTLINE_LENGTH+1]; |
129 #if defined(WITH_ENCHANT) || defined(WITH_ASPELL) | 129 #if defined(WITH_ENCHANT) || defined(WITH_ASPELL) |
130 static char maskLine[INPUTLINE_LENGTH+1]; | 130 static char maskLine[INPUTLINE_LENGTH+1]; |
131 #endif | 131 #endif |
2195 } | 2195 } |
2196 return TRUE; | 2196 return TRUE; |
2197 } | 2197 } |
2198 #endif | 2198 #endif |
2199 | 2199 |
2200 // Check if we should enter/leave automatic away status | 2200 static gboolean scr_autoaway_timeout_callback(gpointer data) |
2201 { | |
2202 enum imstatus cur_st = xmpp_getstatus(); | |
2203 if (cur_st != available && cur_st != freeforchat) | |
2204 // Some non-user-originated status changes, let's wait more. | |
2205 // Maybe the proper fix for that will be set global variable | |
2206 // "autoaway_delayed" and check that variable in postconnect | |
2207 // hook (afaik, only source for such status changes are | |
2208 // error disconnects). | |
2209 return TRUE; | |
2210 set_autoaway(TRUE); | |
2211 // source will be destroyed after return | |
2212 autoaway_source = 0; | |
2213 return FALSE; | |
2214 } | |
2215 | |
2216 static void scr_ReinstallAutoAwayTimeout(void) | |
2217 { | |
2218 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); | |
2219 enum imstatus cur_st = xmpp_getstatus(); | |
2220 if (autoaway_source) { | |
2221 g_source_remove(autoaway_source); | |
2222 autoaway_source = 0; | |
2223 } | |
2224 if (autoaway_timeout && (cur_st == available || cur_st == freeforchat)) | |
2225 autoaway_source = g_timeout_add_seconds(autoaway_timeout, | |
2226 scr_autoaway_timeout_callback, | |
2227 NULL); | |
2228 } | |
2229 | |
2230 // Check if we should reset autoaway timeout source | |
2201 void scr_CheckAutoAway(int activity) | 2231 void scr_CheckAutoAway(int activity) |
2202 { | 2232 { |
2203 enum imstatus cur_st; | 2233 if (Autoaway && activity) { |
2204 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); | 2234 scr_ReinstallAutoAwayTimeout(); |
2205 | 2235 set_autoaway(FALSE); |
2206 if (Autoaway && activity) set_autoaway(FALSE); | 2236 } else if (activity || !autoaway_source) |
2207 if (!autoaway_timeout) return; | 2237 scr_ReinstallAutoAwayTimeout(); |
2208 if (!LastActivity || activity) time(&LastActivity); | |
2209 | |
2210 cur_st = xmpp_getstatus(); | |
2211 // Auto-away is disabled for the following states | |
2212 if ((cur_st != available) && (cur_st != freeforchat)) | |
2213 return; | |
2214 | |
2215 if (!activity) { | |
2216 time_t now; | |
2217 time(&now); | |
2218 if (!Autoaway && (now > LastActivity + (time_t)autoaway_timeout)) | |
2219 set_autoaway(TRUE); | |
2220 } | |
2221 } | 2238 } |
2222 | 2239 |
2223 // set_current_buddy(newbuddy) | 2240 // set_current_buddy(newbuddy) |
2224 // Set the current_buddy to newbuddy (if not NULL) | 2241 // Set the current_buddy to newbuddy (if not NULL) |
2225 // Lock the newbuddy, and unlock the previous current_buddy | 2242 // Lock the newbuddy, and unlock the previous current_buddy |