comparison src/idle.c @ 12825:bd80fb1e8406

[gaim-migrate @ 15173] This fixes a problem Bleeter told me about where 1. Set yourself idle using the idle maker 2. Wait 10 minutes, for Gaim's built-in idle tracker to kick in and do nothing 3. When you return your computer and Gaim's built-in idle tracker detects that you are back, it will incorrectly set you to unidle committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 11 Jan 2006 06:16:33 +0000
parents 200f22ca4890
children b76c6de0c3b5
comparison
equal deleted inserted replaced
12824:7b8e885c1be3 12825:bd80fb1e8406
45 45
46 /** 46 /**
47 * This is needed for the I'dle Mak'er plugin to work correctly. We 47 * This is needed for the I'dle Mak'er plugin to work correctly. We
48 * use it to determine if we're the ones who set our accounts idle 48 * use it to determine if we're the ones who set our accounts idle
49 * or if someone else did it (the I'dle Mak'er plugin, for example). 49 * or if someone else did it (the I'dle Mak'er plugin, for example).
50 * If our accounts are marked as idle and have_set_idle is FALSE and 50 * Basically we just keep track of which accounts were set idle by us,
51 * the user moves the mouse, then we will NOT unidle our accounts. 51 * and then we'll only set these specific accounts unidle when the
52 * user returns.
52 */ 53 */
53 static gboolean have_set_idle = FALSE; 54 static GList *idled_accts = NULL;
54 55
55 static guint idle_timer = 0; 56 static guint idle_timer = 0;
56 57
57 static time_t last_active_time = 0; 58 static time_t last_active_time = 0;
58 59
116 gaim_savedstatus_activate_for_account(saved_status, account); 117 gaim_savedstatus_activate_for_account(saved_status, account);
117 } 118 }
118 } 119 }
119 120
120 static void 121 static void
121 set_account_idle(GaimConnection *gc, int time_idle) 122 set_account_idle(GaimAccount *account, int time_idle)
122 { 123 {
123 GaimAccount *account;
124 GaimPresence *presence; 124 GaimPresence *presence;
125 125
126 account = gaim_connection_get_account(gc);
127 presence = gaim_account_get_presence(account); 126 presence = gaim_account_get_presence(account);
128 127
129 if (gaim_presence_is_idle(presence)) 128 if (gaim_presence_is_idle(presence))
130 /* This account is already idle! */ 129 /* This account is already idle! */
131 return; 130 return;
132 131
133 gaim_debug_info("idle", "Setting %s idle %d seconds\n", 132 gaim_debug_info("idle", "Setting %s idle %d seconds\n",
134 gaim_account_get_username(account), time_idle); 133 gaim_account_get_username(account), time_idle);
135 gaim_presence_set_idle(presence, TRUE, time(NULL) - time_idle); 134 gaim_presence_set_idle(presence, TRUE, time(NULL) - time_idle);
136 } 135 idled_accts = g_list_prepend(idled_accts, account);
137 136 }
138 static void 137
139 set_account_unidle(GaimConnection *gc) 138 static void
140 { 139 set_account_unidle(GaimAccount *account)
141 GaimAccount *account; 140 {
142 GaimPresence *presence; 141 GaimPresence *presence;
143 142
144 account = gaim_connection_get_account(gc);
145 presence = gaim_account_get_presence(account); 143 presence = gaim_account_get_presence(account);
144
145 idled_accts = g_list_remove(idled_accts, account);
146 146
147 if (!gaim_presence_is_idle(presence)) 147 if (!gaim_presence_is_idle(presence))
148 /* This account is already unidle! */ 148 /* This account is already unidle! */
149 return; 149 return;
150 150
215 for (l = gaim_connections_get_all(); l != NULL; l = l->next) 215 for (l = gaim_connections_get_all(); l != NULL; l = l->next)
216 unset_account_autoaway(l->data); 216 unset_account_autoaway(l->data);
217 } 217 }
218 218
219 /* Idle reporting stuff */ 219 /* Idle reporting stuff */
220 if (report_idle && (time_idle >= IDLEMARK) && !have_set_idle) 220 if (report_idle && (time_idle >= IDLEMARK))
221 { 221 {
222 for (l = gaim_connections_get_all(); l != NULL; l = l->next) 222 for (l = gaim_connections_get_all(); l != NULL; l = l->next)
223 set_account_idle(l->data, time_idle); 223 {
224 have_set_idle = TRUE; 224 GaimConnection *gc = l->data;
225 } 225 set_account_idle(gaim_connection_get_account(gc), time_idle);
226 else if ((!report_idle || time_idle < IDLEMARK) && have_set_idle) 226 }
227 { 227 }
228 for (l = gaim_connections_get_all(); l != NULL; l = l->next) 228 else if (!report_idle || (time_idle < IDLEMARK))
229 set_account_unidle(l->data); 229 {
230 have_set_idle = FALSE; 230 while (idled_accts != NULL)
231 set_account_unidle(idled_accts->data);
231 } 232 }
232 233
233 return TRUE; 234 return TRUE;
234 } 235 }
235 236
237 im_msg_sent_cb(GaimAccount *account, const char *receiver, 238 im_msg_sent_cb(GaimAccount *account, const char *receiver,
238 const char *message, void *data) 239 const char *message, void *data)
239 { 240 {
240 /* Check our idle time after an IM is sent */ 241 /* Check our idle time after an IM is sent */
241 check_idleness(); 242 check_idleness();
243 }
244
245 static void
246 signing_off_cb(GaimConnection *gc, void *data)
247 {
248 GaimAccount *account;
249
250 account = gaim_connection_get_account(gc);
251 idled_accts = g_list_remove(idled_accts, account);
242 } 252 }
243 253
244 void 254 void
245 gaim_idle_touch() 255 gaim_idle_touch()
246 { 256 {
280 idle_timer = gaim_timeout_add(IDLE_CHECK_INTERVAL * 1000, check_idleness, NULL); 290 idle_timer = gaim_timeout_add(IDLE_CHECK_INTERVAL * 1000, check_idleness, NULL);
281 291
282 gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg", 292 gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg",
283 gaim_idle_get_handle(), 293 gaim_idle_get_handle(),
284 GAIM_CALLBACK(im_msg_sent_cb), NULL); 294 GAIM_CALLBACK(im_msg_sent_cb), NULL);
295 gaim_signal_connect(gaim_connections_get_handle(), "signing-off",
296 gaim_idle_get_handle(),
297 GAIM_CALLBACK(signing_off_cb), NULL);
285 298
286 gaim_idle_touch(); 299 gaim_idle_touch();
287 } 300 }
288 301
289 void 302 void