Mercurial > pidgin.yaz
changeset 17102:e7e033a38612
When using Purple idle, don't run a timer at all when idleaway. When using
system idle, check every 60 seconds.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sat, 19 May 2007 06:16:44 +0000 |
parents | 6545d21b6f5b |
children | bf27ef68e81a |
files | libpurple/idle.c |
diffstat | 1 files changed, 55 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/idle.c Sat May 19 05:56:01 2007 +0000 +++ b/libpurple/idle.c Sat May 19 06:16:44 2007 +0000 @@ -92,6 +92,7 @@ } +static int no_away = 0; static gint time_until_next_idle_event; /* * This function should be called when you think your idle state @@ -121,7 +122,7 @@ gboolean report_idle; GList *l; gint away_seconds = 0; - static int no_away = 0; + gint idle_recheck_interval; purple_signal_emit(purple_blist_get_handle(), "update-idle"); @@ -132,11 +133,13 @@ { /* Use system idle time (mouse or keyboard movement, etc.) */ time_idle = idle_ui_ops->get_time_idle(); + idle_recheck_interval = 60; } else if (!strcmp(idle_reporting, "purple")) { /* Use 'Purple idle' */ time_idle = time(NULL) - last_active_time; + idle_recheck_interval = 0; } else { @@ -150,18 +153,38 @@ /* If we're not reporting idle, we can still do auto-away. * First try "system" and if that isn't possible, use "purple" */ - if (!report_idle && auto_away) { - if ((idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) - time_idle = idle_ui_ops->get_time_idle(); + if (!report_idle) + { + if (auto_away) + { + if ((idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) + { + time_idle = idle_ui_ops->get_time_idle(); + idle_recheck_interval = 60; + } + else + { + time_idle = time(NULL) - last_active_time; + idle_recheck_interval = 0; + } + } else - time_idle = time(NULL) - last_active_time; + { + if (!no_away) + { + purple_savedstatus_set_idleaway(FALSE); + no_away = 1; + } + time_until_next_idle_event = 0; + return; + } } time_until_next_idle_event = IDLEMARK - time_idle; if (time_until_next_idle_event < 0) { - /* If we're already idle, check again in a minute. */ - time_until_next_idle_event = 60; + /* If we're already idle, check again as appropriate. */ + time_until_next_idle_event = idle_recheck_interval; } if (auto_away || !no_away) @@ -176,7 +199,7 @@ { purple_savedstatus_set_idleaway(FALSE); no_away = 1; - if ((away_seconds - time_idle) < time_until_next_idle_event) + if (time_until_next_idle_event == 0 || (away_seconds - time_idle) < time_until_next_idle_event) time_until_next_idle_event = away_seconds - time_idle; } @@ -204,7 +227,10 @@ check_idleness_timer() { check_idleness(); - idle_timer = purple_timeout_add(1000 * (time_until_next_idle_event + 1), check_idleness_timer, NULL); + if (time_until_next_idle_event == 0) + idle_timer = 0; + else + idle_timer = purple_timeout_add(1000 * (time_until_next_idle_event + 1), check_idleness_timer, NULL); return FALSE; } @@ -232,10 +258,26 @@ set_account_unidle(account); } +static void +idle_reporting_cb(const char *name, PurplePrefType type, gconstpointer val, gpointer data) +{ + if (idle_timer) + purple_timeout_remove(idle_timer); + idle_timer = 0; + check_idleness_timer(); +} + void purple_idle_touch() { time(&last_active_time); + if (!no_away) + { + if (idle_timer) + purple_timeout_remove(idle_timer); + idle_timer = 0; + check_idleness_timer(); + } } void @@ -280,6 +322,9 @@ purple_idle_get_handle(), PURPLE_CALLBACK(signing_off_cb), NULL); + purple_prefs_connect_callback(purple_idle_get_handle(), "/purple/away/idle_reporting", + idle_reporting_cb, NULL) + purple_idle_touch(); } @@ -287,6 +332,7 @@ purple_idle_uninit() { purple_signals_disconnect_by_handle(purple_idle_get_handle()); + purple_prefs_disconnect_by_handle(purple_idle_get_handle()); /* Remove the idle timer */ if (idle_timer > 0)