Mercurial > pidgin
comparison libpurple/idle.c @ 17723:c02305ee715a
propagate from branch 'im.pidgin.pidgin' (head 62e9d17cd37551991c5040ce6ca48e6d7578dde3)
to branch 'org.maemo.garage.pidgin.pidgin.pidgin-create-window' (head 369bca3c0c736b247092848177aeaa6fd0f3a25c)
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sat, 19 May 2007 08:24:46 +0000 |
parents | bf27ef68e81a |
children | b27e535cce50 f2d8658b3a86 |
comparison
equal
deleted
inserted
replaced
17721:68f634d5f5f5 | 17723:c02305ee715a |
---|---|
90 purple_account_get_username(account)); | 90 purple_account_get_username(account)); |
91 purple_presence_set_idle(presence, FALSE, 0); | 91 purple_presence_set_idle(presence, FALSE, 0); |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 static int no_away = 0; | |
95 static gint time_until_next_idle_event; | 96 static gint time_until_next_idle_event; |
96 /* | 97 /* |
97 * This function should be called when you think your idle state | 98 * This function should be called when you think your idle state |
98 * may have changed. Maybe you're over the 10-minute mark and | 99 * may have changed. Maybe you're over the 10-minute mark and |
99 * Purple should start reporting idle time to the server. Maybe | 100 * Purple should start reporting idle time to the server. Maybe |
119 gboolean auto_away; | 120 gboolean auto_away; |
120 const gchar *idle_reporting; | 121 const gchar *idle_reporting; |
121 gboolean report_idle; | 122 gboolean report_idle; |
122 GList *l; | 123 GList *l; |
123 gint away_seconds = 0; | 124 gint away_seconds = 0; |
124 static int no_away = 0; | 125 gint idle_recheck_interval; |
125 | 126 |
126 purple_signal_emit(purple_blist_get_handle(), "update-idle"); | 127 purple_signal_emit(purple_blist_get_handle(), "update-idle"); |
127 | 128 |
128 idle_reporting = purple_prefs_get_string("/purple/away/idle_reporting"); | 129 idle_reporting = purple_prefs_get_string("/purple/away/idle_reporting"); |
129 report_idle = TRUE; | 130 report_idle = TRUE; |
130 if (!strcmp(idle_reporting, "system") && | 131 if (!strcmp(idle_reporting, "system") && |
131 (idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) | 132 (idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) |
132 { | 133 { |
133 /* Use system idle time (mouse or keyboard movement, etc.) */ | 134 /* Use system idle time (mouse or keyboard movement, etc.) */ |
134 time_idle = idle_ui_ops->get_time_idle(); | 135 time_idle = idle_ui_ops->get_time_idle(); |
136 idle_recheck_interval = 60; | |
135 } | 137 } |
136 else if (!strcmp(idle_reporting, "purple")) | 138 else if (!strcmp(idle_reporting, "purple")) |
137 { | 139 { |
138 /* Use 'Purple idle' */ | 140 /* Use 'Purple idle' */ |
139 time_idle = time(NULL) - last_active_time; | 141 time_idle = time(NULL) - last_active_time; |
142 idle_recheck_interval = 0; | |
140 } | 143 } |
141 else | 144 else |
142 { | 145 { |
143 /* Don't report idle time */ | 146 /* Don't report idle time */ |
144 time_idle = 0; | 147 time_idle = 0; |
148 /* Auto-away stuff */ | 151 /* Auto-away stuff */ |
149 auto_away = purple_prefs_get_bool("/purple/away/away_when_idle"); | 152 auto_away = purple_prefs_get_bool("/purple/away/away_when_idle"); |
150 | 153 |
151 /* If we're not reporting idle, we can still do auto-away. | 154 /* If we're not reporting idle, we can still do auto-away. |
152 * First try "system" and if that isn't possible, use "purple" */ | 155 * First try "system" and if that isn't possible, use "purple" */ |
153 if (!report_idle && auto_away) { | 156 if (!report_idle) |
154 if ((idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) | 157 { |
155 time_idle = idle_ui_ops->get_time_idle(); | 158 if (auto_away) |
159 { | |
160 if ((idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) | |
161 { | |
162 time_idle = idle_ui_ops->get_time_idle(); | |
163 idle_recheck_interval = 60; | |
164 } | |
165 else | |
166 { | |
167 time_idle = time(NULL) - last_active_time; | |
168 idle_recheck_interval = 0; | |
169 } | |
170 } | |
156 else | 171 else |
157 time_idle = time(NULL) - last_active_time; | 172 { |
158 } | 173 if (!no_away) |
159 | 174 { |
160 time_until_next_idle_event = IDLEMARK - time_idle; /* reasonable start upperbound */ | 175 purple_savedstatus_set_idleaway(FALSE); |
176 no_away = 1; | |
177 } | |
178 time_until_next_idle_event = 0; | |
179 return; | |
180 } | |
181 } | |
182 | |
183 time_until_next_idle_event = IDLEMARK - time_idle; | |
184 if (time_until_next_idle_event < 0) | |
185 { | |
186 /* If we're already idle, check again as appropriate. */ | |
187 time_until_next_idle_event = idle_recheck_interval; | |
188 } | |
161 | 189 |
162 if (auto_away || !no_away) | 190 if (auto_away || !no_away) |
163 away_seconds = 60 * purple_prefs_get_int("/purple/away/mins_before_away"); | 191 away_seconds = 60 * purple_prefs_get_int("/purple/away/mins_before_away"); |
164 | 192 |
165 if (auto_away && time_idle > away_seconds) | 193 if (auto_away && time_idle > away_seconds) |
166 { | 194 { |
167 purple_savedstatus_set_idleaway(TRUE); | 195 purple_savedstatus_set_idleaway(TRUE); |
168 no_away = 0; | 196 no_away = 0; |
169 if (time_idle < away_seconds && (away_seconds - time_idle) < time_until_next_idle_event) | |
170 time_until_next_idle_event = away_seconds - time_idle; | |
171 } | 197 } |
172 else if (!no_away && time_idle < away_seconds) | 198 else if (!no_away && time_idle < away_seconds) |
173 { | 199 { |
174 purple_savedstatus_set_idleaway(FALSE); | 200 purple_savedstatus_set_idleaway(FALSE); |
175 no_away = 1; | 201 no_away = 1; |
176 if (time_idle < away_seconds && (away_seconds - time_idle) < time_until_next_idle_event) | 202 if (time_until_next_idle_event == 0 || (away_seconds - time_idle) < time_until_next_idle_event) |
177 time_until_next_idle_event = away_seconds - time_idle; | 203 time_until_next_idle_event = away_seconds - time_idle; |
178 } | 204 } |
179 | 205 |
180 /* Idle reporting stuff */ | 206 /* Idle reporting stuff */ |
181 if (report_idle && (time_idle >= IDLEMARK)) | 207 if (report_idle && (time_idle >= IDLEMARK)) |
189 else if (!report_idle || (time_idle < IDLEMARK)) | 215 else if (!report_idle || (time_idle < IDLEMARK)) |
190 { | 216 { |
191 while (idled_accts != NULL) | 217 while (idled_accts != NULL) |
192 set_account_unidle(idled_accts->data); | 218 set_account_unidle(idled_accts->data); |
193 } | 219 } |
194 | |
195 if (time_until_next_idle_event < 0) | |
196 time_until_next_idle_event = IDLEMARK; | |
197 } | 220 } |
198 | 221 |
199 | 222 |
200 /* | 223 /* |
201 * Check idle and set the timer to fire at the next idle-worth event | 224 * Check idle and set the timer to fire at the next idle-worth event |
202 */ | 225 */ |
203 static gint | 226 static gint |
204 check_idleness_timer() | 227 check_idleness_timer() |
205 { | 228 { |
206 check_idleness(); | 229 check_idleness(); |
207 idle_timer = purple_timeout_add(1000 * (time_until_next_idle_event + 1), check_idleness_timer, NULL); | 230 if (time_until_next_idle_event == 0) |
231 idle_timer = 0; | |
232 else | |
233 idle_timer = purple_timeout_add(1000 * (time_until_next_idle_event + 1), check_idleness_timer, NULL); | |
208 return FALSE; | 234 return FALSE; |
209 } | 235 } |
210 | 236 |
211 static void | 237 static void |
212 im_msg_sent_cb(PurpleAccount *account, const char *receiver, | 238 im_msg_sent_cb(PurpleAccount *account, const char *receiver, |
230 | 256 |
231 account = purple_connection_get_account(gc); | 257 account = purple_connection_get_account(gc); |
232 set_account_unidle(account); | 258 set_account_unidle(account); |
233 } | 259 } |
234 | 260 |
261 static void | |
262 idle_reporting_cb(const char *name, PurplePrefType type, gconstpointer val, gpointer data) | |
263 { | |
264 if (idle_timer) | |
265 purple_timeout_remove(idle_timer); | |
266 idle_timer = 0; | |
267 check_idleness_timer(); | |
268 } | |
269 | |
235 void | 270 void |
236 purple_idle_touch() | 271 purple_idle_touch() |
237 { | 272 { |
238 time(&last_active_time); | 273 time(&last_active_time); |
274 if (!no_away) | |
275 { | |
276 if (idle_timer) | |
277 purple_timeout_remove(idle_timer); | |
278 idle_timer = 0; | |
279 check_idleness_timer(); | |
280 } | |
239 } | 281 } |
240 | 282 |
241 void | 283 void |
242 purple_idle_set(time_t time) | 284 purple_idle_set(time_t time) |
243 { | 285 { |
278 PURPLE_CALLBACK(signing_on_cb), NULL); | 320 PURPLE_CALLBACK(signing_on_cb), NULL); |
279 purple_signal_connect(purple_connections_get_handle(), "signing-off", | 321 purple_signal_connect(purple_connections_get_handle(), "signing-off", |
280 purple_idle_get_handle(), | 322 purple_idle_get_handle(), |
281 PURPLE_CALLBACK(signing_off_cb), NULL); | 323 PURPLE_CALLBACK(signing_off_cb), NULL); |
282 | 324 |
325 purple_prefs_connect_callback(purple_idle_get_handle(), "/purple/away/idle_reporting", | |
326 idle_reporting_cb, NULL); | |
327 | |
283 purple_idle_touch(); | 328 purple_idle_touch(); |
284 } | 329 } |
285 | 330 |
286 void | 331 void |
287 purple_idle_uninit() | 332 purple_idle_uninit() |
288 { | 333 { |
289 purple_signals_disconnect_by_handle(purple_idle_get_handle()); | 334 purple_signals_disconnect_by_handle(purple_idle_get_handle()); |
335 purple_prefs_disconnect_by_handle(purple_idle_get_handle()); | |
290 | 336 |
291 /* Remove the idle timer */ | 337 /* Remove the idle timer */ |
292 if (idle_timer > 0) | 338 if (idle_timer > 0) |
293 purple_timeout_remove(idle_timer); | 339 purple_timeout_remove(idle_timer); |
294 idle_timer = 0; | 340 idle_timer = 0; |