Fri, 15 Jun 2007 19:34:24 +0000
propagate from branch 'im.pidgin.pidgin.2.1.0' (head 6733196cafc60146d92a26565e0d90bd8b43a9ef)
to branch 'im.pidgin.pidgin' (head ed70e92f7c284be8ef382ca84a3b1a8780566bc3)
| 12272 | 1 | /* |
| 15884 | 2 | * purple |
| 12272 | 3 | * |
| 15884 | 4 | * Purple is the legal property of its developers, whose names are too numerous |
| 12272 | 5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | * | |
| 22 | */ | |
| 23 | #include "internal.h" | |
| 24 | ||
| 25 | #include "connection.h" | |
| 26 | #include "debug.h" | |
| 27 | #include "idle.h" | |
| 28 | #include "log.h" | |
| 29 | #include "prefs.h" | |
| 30 | #include "savedstatuses.h" | |
| 31 | #include "signals.h" | |
| 32 | ||
| 33 | #define IDLEMARK 600 /* 10 minutes! */ | |
| 34 | ||
| 35 | typedef enum | |
| 36 | { | |
| 15884 | 37 | PURPLE_IDLE_NOT_AWAY = 0, |
| 38 | PURPLE_IDLE_AUTO_AWAY, | |
| 39 | PURPLE_IDLE_AWAY_BUT_NOT_AUTO_AWAY | |
| 12272 | 40 | |
| 15884 | 41 | } PurpleAutoAwayState; |
| 12272 | 42 | |
| 15884 | 43 | static PurpleIdleUiOps *idle_ui_ops = NULL; |
| 12272 | 44 | |
| 45 | /** | |
| 46 | * This is needed for the I'dle Mak'er plugin to work correctly. We | |
| 47 | * use it to determine if we're the ones who set our accounts idle | |
| 48 | * or if someone else did it (the I'dle Mak'er plugin, for example). | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
49 | * Basically we just keep track of which accounts were set idle by us, |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
50 | * and then we'll only set these specific accounts unidle when the |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
51 | * user returns. |
| 12272 | 52 | */ |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
53 | static GList *idled_accts = NULL; |
| 12272 | 54 | |
| 55 | static guint idle_timer = 0; | |
| 56 | ||
| 57 | static time_t last_active_time = 0; | |
| 58 | ||
| 59 | static void | |
| 15884 | 60 | set_account_idle(PurpleAccount *account, int time_idle) |
| 12272 | 61 | { |
| 15884 | 62 | PurplePresence *presence; |
| 12272 | 63 | |
| 15884 | 64 | presence = purple_account_get_presence(account); |
| 12272 | 65 | |
| 15884 | 66 | if (purple_presence_is_idle(presence)) |
| 12272 | 67 | /* This account is already idle! */ |
| 68 | return; | |
| 69 | ||
| 15884 | 70 | purple_debug_info("idle", "Setting %s idle %d seconds\n", |
| 71 | purple_account_get_username(account), time_idle); | |
| 72 | purple_presence_set_idle(presence, TRUE, time(NULL) - time_idle); | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
73 | idled_accts = g_list_prepend(idled_accts, account); |
| 12272 | 74 | } |
| 75 | ||
| 76 | static void | |
| 15884 | 77 | set_account_unidle(PurpleAccount *account) |
| 12272 | 78 | { |
| 15884 | 79 | PurplePresence *presence; |
| 12272 | 80 | |
| 15884 | 81 | presence = purple_account_get_presence(account); |
| 12272 | 82 | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
83 | idled_accts = g_list_remove(idled_accts, account); |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
84 | |
| 15884 | 85 | if (!purple_presence_is_idle(presence)) |
| 12272 | 86 | /* This account is already unidle! */ |
| 87 | return; | |
| 88 | ||
| 15884 | 89 | purple_debug_info("idle", "Setting %s unidle\n", |
| 90 | purple_account_get_username(account)); | |
| 91 | purple_presence_set_idle(presence, FALSE, 0); | |
| 12272 | 92 | } |
| 93 | ||
| 17130 | 94 | |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
95 | static gboolean no_away = FALSE; |
| 17130 | 96 | static gint time_until_next_idle_event; |
| 12272 | 97 | /* |
| 98 | * This function should be called when you think your idle state | |
| 99 | * may have changed. Maybe you're over the 10-minute mark and | |
| 15884 | 100 | * Purple should start reporting idle time to the server. Maybe |
| 12272 | 101 | * you've returned from being idle. Maybe your auto-away message |
| 102 | * should be set. | |
| 103 | * | |
| 104 | * There is no harm to calling this many many times, other than | |
|
17349
c5abad45e8a7
Update a comment: We don't check idle status every 5 seconds any more.
Richard Laager <rlaager@pidgin.im>
parents:
17248
diff
changeset
|
105 | * it will be kinda slow. This is called by a timer set when |
|
c5abad45e8a7
Update a comment: We don't check idle status every 5 seconds any more.
Richard Laager <rlaager@pidgin.im>
parents:
17248
diff
changeset
|
106 | * Purple starts. It is also called when you send an IM, a chat, etc. |
| 12272 | 107 | * |
| 108 | * This function has 3 sections. | |
| 109 | * 1. Get your idle time. It will query XScreenSaver or Windows | |
| 15884 | 110 | * or use the Purple idle time. Whatever. |
| 12272 | 111 | * 2. Set or unset your auto-away message. |
| 112 | * 3. Report your current idle time to the IM server. | |
| 113 | */ | |
| 17130 | 114 | |
| 115 | static void | |
| 116 | check_idleness(void) | |
| 12272 | 117 | { |
| 118 | time_t time_idle; | |
| 119 | gboolean auto_away; | |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
120 | const gchar *idle_reporting; |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
121 | gboolean report_idle = TRUE; |
| 17130 | 122 | gint away_seconds = 0; |
|
17536
b04036df5ac6
Compiler be quiet! Fixes this compile warning:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17349
diff
changeset
|
123 | gint idle_recheck_interval = 0; |
| 12272 | 124 | |
| 15884 | 125 | purple_signal_emit(purple_blist_get_handle(), "update-idle"); |
| 12272 | 126 | |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
127 | idle_reporting = purple_prefs_get_string("/purple/away/idle_reporting"); |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
128 | auto_away = purple_prefs_get_bool("/purple/away/away_when_idle"); |
|
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
129 | |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
130 | if (!strcmp(idle_reporting, "system") && |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
131 | (idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
132 | { |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
133 | /* Use system idle time (mouse or keyboard movement, etc.) */ |
| 12272 | 134 | time_idle = idle_ui_ops->get_time_idle(); |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
135 | idle_recheck_interval = 60; |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
136 | } |
| 15884 | 137 | else if (!strcmp(idle_reporting, "purple")) |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
138 | { |
| 15884 | 139 | /* Use 'Purple idle' */ |
| 12272 | 140 | time_idle = time(NULL) - last_active_time; |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
141 | idle_recheck_interval = 0; |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
142 | } |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
143 | else |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
144 | { |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
145 | /* Don't report idle time */ |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
146 | time_idle = 0; |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
147 | report_idle = FALSE; |
| 12272 | 148 | |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
149 | /* If we're not reporting idle, we can still do auto-away. |
|
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
150 | * First try "system" and if that isn't possible, use "purple" */ |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
151 | if (auto_away) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
152 | { |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
153 | if ((idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
154 | { |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
155 | time_idle = idle_ui_ops->get_time_idle(); |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
156 | idle_recheck_interval = 60; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
157 | } |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
158 | else |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
159 | { |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
160 | time_idle = time(NULL) - last_active_time; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
161 | idle_recheck_interval = 0; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
162 | } |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
163 | } |
|
14999
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
164 | else |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
165 | { |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
166 | if (!no_away) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
167 | { |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
168 | purple_savedstatus_set_idleaway(FALSE); |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
169 | no_away = TRUE; |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
170 | } |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
171 | time_until_next_idle_event = 0; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
172 | return; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
173 | } |
|
14999
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
174 | } |
|
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
175 | |
|
17161
c4e7791b276f
Move the time_until_next_idle_event < 0 check to clarify.
Richard Laager <rlaager@pidgin.im>
parents:
17160
diff
changeset
|
176 | time_until_next_idle_event = IDLEMARK - time_idle; |
|
c4e7791b276f
Move the time_until_next_idle_event < 0 check to clarify.
Richard Laager <rlaager@pidgin.im>
parents:
17160
diff
changeset
|
177 | if (time_until_next_idle_event < 0) |
|
c4e7791b276f
Move the time_until_next_idle_event < 0 check to clarify.
Richard Laager <rlaager@pidgin.im>
parents:
17160
diff
changeset
|
178 | { |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
179 | /* If we're already idle, check again as appropriate. */ |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
180 | time_until_next_idle_event = idle_recheck_interval; |
|
17161
c4e7791b276f
Move the time_until_next_idle_event < 0 check to clarify.
Richard Laager <rlaager@pidgin.im>
parents:
17160
diff
changeset
|
181 | } |
| 17130 | 182 | |
| 183 | if (auto_away || !no_away) | |
| 184 | away_seconds = 60 * purple_prefs_get_int("/purple/away/mins_before_away"); | |
| 185 | ||
| 186 | if (auto_away && time_idle > away_seconds) | |
| 12272 | 187 | { |
| 15884 | 188 | purple_savedstatus_set_idleaway(TRUE); |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
189 | no_away = FALSE; |
| 12272 | 190 | } |
| 17130 | 191 | else if (!no_away && time_idle < away_seconds) |
| 12272 | 192 | { |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
193 | no_away = TRUE; |
| 15884 | 194 | purple_savedstatus_set_idleaway(FALSE); |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
195 | if (time_until_next_idle_event == 0 || (away_seconds - time_idle) < time_until_next_idle_event) |
| 17130 | 196 | time_until_next_idle_event = away_seconds - time_idle; |
| 12272 | 197 | } |
| 198 | ||
| 199 | /* Idle reporting stuff */ | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
200 | if (report_idle && (time_idle >= IDLEMARK)) |
| 12272 | 201 | { |
|
18121
2d8ea56b9097
Mark the return type const for the following functions. I noticed this
Richard Laager <rlaager@pidgin.im>
parents:
18110
diff
changeset
|
202 | const GList *l; |
| 15884 | 203 | for (l = purple_connections_get_all(); l != NULL; l = l->next) |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
204 | { |
| 15884 | 205 | PurpleConnection *gc = l->data; |
| 206 | set_account_idle(purple_connection_get_account(gc), time_idle); | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
207 | } |
| 12272 | 208 | } |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
209 | else if (!report_idle || (time_idle < IDLEMARK)) |
| 12272 | 210 | { |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
211 | while (idled_accts != NULL) |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
212 | set_account_unidle(idled_accts->data); |
| 12272 | 213 | } |
| 17130 | 214 | } |
| 12272 | 215 | |
| 17130 | 216 | |
| 217 | /* | |
| 218 | * Check idle and set the timer to fire at the next idle-worth event | |
| 219 | */ | |
| 220 | static gint | |
| 221 | check_idleness_timer() | |
| 222 | { | |
| 223 | check_idleness(); | |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
224 | if (time_until_next_idle_event == 0) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
225 | idle_timer = 0; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
226 | else |
|
18069
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
227 | { |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
228 | /* +1 for the boundary, |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
229 | * +1 more for g_timeout_add_seconds rounding. */ |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
230 | idle_timer = purple_timeout_add_seconds(time_until_next_idle_event + 2, check_idleness_timer, NULL); |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
231 | } |
| 17130 | 232 | return FALSE; |
| 12272 | 233 | } |
| 234 | ||
| 235 | static void | |
| 15884 | 236 | im_msg_sent_cb(PurpleAccount *account, const char *receiver, |
| 12272 | 237 | const char *message, void *data) |
| 238 | { | |
| 239 | /* Check our idle time after an IM is sent */ | |
| 240 | check_idleness(); | |
| 241 | } | |
| 242 | ||
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
243 | static void |
| 15884 | 244 | signing_on_cb(PurpleConnection *gc, void *data) |
| 14189 | 245 | { |
| 246 | /* When signing on a new account, check if the account should be idle */ | |
| 247 | check_idleness(); | |
| 248 | } | |
| 249 | ||
| 250 | static void | |
| 15884 | 251 | signing_off_cb(PurpleConnection *gc, void *data) |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
252 | { |
| 15884 | 253 | PurpleAccount *account; |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
254 | |
| 15884 | 255 | account = purple_connection_get_account(gc); |
| 14189 | 256 | set_account_unidle(account); |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
257 | } |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
258 | |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
259 | static void |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
260 | idle_reporting_cb(const char *name, PurplePrefType type, gconstpointer val, gpointer data) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
261 | { |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
262 | if (idle_timer) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
263 | purple_timeout_remove(idle_timer); |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
264 | idle_timer = 0; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
265 | check_idleness_timer(); |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
266 | } |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
267 | |
| 12272 | 268 | void |
| 15884 | 269 | purple_idle_touch() |
| 12272 | 270 | { |
| 271 | time(&last_active_time); | |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
272 | if (!no_away) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
273 | { |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
274 | if (idle_timer) |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
275 | purple_timeout_remove(idle_timer); |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
276 | idle_timer = 0; |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
277 | check_idleness_timer(); |
|
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
278 | } |
| 12272 | 279 | } |
| 280 | ||
| 281 | void | |
| 15884 | 282 | purple_idle_set(time_t time) |
| 12272 | 283 | { |
| 284 | last_active_time = time; | |
| 285 | } | |
| 286 | ||
| 287 | void | |
| 15884 | 288 | purple_idle_set_ui_ops(PurpleIdleUiOps *ops) |
| 12272 | 289 | { |
| 290 | idle_ui_ops = ops; | |
| 291 | } | |
| 292 | ||
| 15884 | 293 | PurpleIdleUiOps * |
| 294 | purple_idle_get_ui_ops(void) | |
| 12272 | 295 | { |
| 296 | return idle_ui_ops; | |
| 297 | } | |
| 298 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12272
diff
changeset
|
299 | static void * |
| 15884 | 300 | purple_idle_get_handle() |
| 12272 | 301 | { |
| 302 | static int handle; | |
| 303 | ||
| 304 | return &handle; | |
| 305 | } | |
| 306 | ||
|
17741
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
307 | static gboolean _do_purple_idle_touch_cb(gpointer data) |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
308 | { |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
309 | purple_idle_touch(); |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
310 | |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
311 | return FALSE; |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
312 | } |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
313 | |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
314 | |
| 12272 | 315 | void |
| 15884 | 316 | purple_idle_init() |
| 12272 | 317 | { |
|
18069
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
318 | /* Add the timer to check if we're idle. |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
319 | * IDLEMARK + 1 as the boundary, |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
320 | * +1 more for g_timeout_add_seconds rounding. */ |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
321 | idle_timer = purple_timeout_add_seconds((IDLEMARK + 2), check_idleness_timer, NULL); |
| 12272 | 322 | |
| 15884 | 323 | purple_signal_connect(purple_conversations_get_handle(), "sent-im-msg", |
| 324 | purple_idle_get_handle(), | |
| 325 | PURPLE_CALLBACK(im_msg_sent_cb), NULL); | |
| 326 | purple_signal_connect(purple_connections_get_handle(), "signing-on", | |
| 327 | purple_idle_get_handle(), | |
| 328 | PURPLE_CALLBACK(signing_on_cb), NULL); | |
| 329 | purple_signal_connect(purple_connections_get_handle(), "signing-off", | |
| 330 | purple_idle_get_handle(), | |
| 331 | PURPLE_CALLBACK(signing_off_cb), NULL); | |
| 12272 | 332 | |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
333 | purple_prefs_connect_callback(purple_idle_get_handle(), "/purple/away/idle_reporting", |
|
17163
8c150fc133c3
Add a missing semi-colon so this will compile.
Richard Laager <rlaager@pidgin.im>
parents:
17162
diff
changeset
|
334 | idle_reporting_cb, NULL); |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
335 | |
|
17741
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
336 | /* Initialize the idleness asynchronously so it doesn't check idleness, |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
337 | * and potentially try to change the status before the UI is initialized */ |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
338 | g_idle_add(_do_purple_idle_touch_cb, NULL); |
|
5075c0d3a19a
I think this will fix the problem that elb had where bonjour (and probably other accounts too) were signing on initially when -n was specified.
Daniel Atallah <datallah@pidgin.im>
parents:
17579
diff
changeset
|
339 | |
| 12272 | 340 | } |
| 341 | ||
| 342 | void | |
| 15884 | 343 | purple_idle_uninit() |
| 12272 | 344 | { |
| 15884 | 345 | purple_signals_disconnect_by_handle(purple_idle_get_handle()); |
|
17162
38f0cf5afda1
When using Purple idle, don't run a timer at all when idleaway. When using
Richard Laager <rlaager@pidgin.im>
parents:
17161
diff
changeset
|
346 | purple_prefs_disconnect_by_handle(purple_idle_get_handle()); |
| 12272 | 347 | |
| 348 | /* Remove the idle timer */ | |
| 349 | if (idle_timer > 0) | |
| 15884 | 350 | purple_timeout_remove(idle_timer); |
| 12272 | 351 | idle_timer = 0; |
| 352 | } |