Sun, 23 Feb 2014 01:43:21 +0530
Use g_free as UiOps structures GBoxed free function
| 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19569
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 12272 | 21 | * |
| 22 | */ | |
| 23 | #include "internal.h" | |
| 24 | ||
| 25 | #include "connection.h" | |
| 26 | #include "debug.h" | |
|
22351
6ca0640b3d31
Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <markdoliner@pidgin.im>
parents:
22108
diff
changeset
|
27 | #include "eventloop.h" |
| 12272 | 28 | #include "idle.h" |
| 29 | #include "log.h" | |
| 30 | #include "prefs.h" | |
| 31 | #include "savedstatuses.h" | |
| 32 | #include "signals.h" | |
| 33 | ||
| 34 | typedef enum | |
| 35 | { | |
| 15884 | 36 | PURPLE_IDLE_NOT_AWAY = 0, |
| 37 | PURPLE_IDLE_AUTO_AWAY, | |
| 38 | PURPLE_IDLE_AWAY_BUT_NOT_AUTO_AWAY | |
| 12272 | 39 | |
| 15884 | 40 | } PurpleAutoAwayState; |
| 12272 | 41 | |
| 15884 | 42 | static PurpleIdleUiOps *idle_ui_ops = NULL; |
| 12272 | 43 | |
|
35462
901dfa763f15
Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents:
26891
diff
changeset
|
44 | /* |
| 12272 | 45 | * This is needed for the I'dle Mak'er plugin to work correctly. We |
| 46 | * use it to determine if we're the ones who set our accounts idle | |
| 47 | * 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
|
48 | * 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
|
49 | * 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
|
50 | * user returns. |
| 12272 | 51 | */ |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
52 | static GList *idled_accts = NULL; |
| 12272 | 53 | |
| 54 | static guint idle_timer = 0; | |
| 55 | ||
| 56 | static time_t last_active_time = 0; | |
| 57 | ||
| 58 | static void | |
| 15884 | 59 | set_account_idle(PurpleAccount *account, int time_idle) |
| 12272 | 60 | { |
| 15884 | 61 | PurplePresence *presence; |
| 12272 | 62 | |
| 15884 | 63 | presence = purple_account_get_presence(account); |
| 12272 | 64 | |
| 15884 | 65 | if (purple_presence_is_idle(presence)) |
| 12272 | 66 | /* This account is already idle! */ |
| 67 | return; | |
| 68 | ||
| 15884 | 69 | purple_debug_info("idle", "Setting %s idle %d seconds\n", |
| 70 | purple_account_get_username(account), time_idle); | |
| 71 | purple_presence_set_idle(presence, TRUE, time(NULL) - time_idle); | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
72 | idled_accts = g_list_prepend(idled_accts, account); |
| 12272 | 73 | } |
| 74 | ||
| 75 | static void | |
| 15884 | 76 | set_account_unidle(PurpleAccount *account) |
| 12272 | 77 | { |
| 15884 | 78 | PurplePresence *presence; |
| 12272 | 79 | |
| 15884 | 80 | presence = purple_account_get_presence(account); |
| 12272 | 81 | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
82 | idled_accts = g_list_remove(idled_accts, account); |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
83 | |
| 15884 | 84 | if (!purple_presence_is_idle(presence)) |
| 12272 | 85 | /* This account is already unidle! */ |
| 86 | return; | |
| 87 | ||
| 15884 | 88 | purple_debug_info("idle", "Setting %s unidle\n", |
| 89 | purple_account_get_username(account)); | |
| 90 | purple_presence_set_idle(presence, FALSE, 0); | |
| 12272 | 91 | } |
| 92 | ||
| 17130 | 93 | |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
94 | static gboolean no_away = FALSE; |
| 17130 | 95 | static gint time_until_next_idle_event; |
| 12272 | 96 | /* |
| 97 | * This function should be called when you think your idle state | |
| 98 | * may have changed. Maybe you're over the 10-minute mark and | |
| 15884 | 99 | * Purple should start reporting idle time to the server. Maybe |
| 12272 | 100 | * you've returned from being idle. Maybe your auto-away message |
| 101 | * should be set. | |
| 102 | * | |
| 103 | * 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
|
104 | * 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
|
105 | * Purple starts. It is also called when you send an IM, a chat, etc. |
| 12272 | 106 | * |
| 107 | * This function has 3 sections. | |
| 108 | * 1. Get your idle time. It will query XScreenSaver or Windows | |
| 15884 | 109 | * or use the Purple idle time. Whatever. |
| 12272 | 110 | * 2. Set or unset your auto-away message. |
| 111 | * 3. Report your current idle time to the IM server. | |
| 112 | */ | |
| 17130 | 113 | |
| 114 | static void | |
| 115 | check_idleness(void) | |
| 12272 | 116 | { |
|
35382
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
26891
diff
changeset
|
117 | time_t time_idle = 0; |
| 12272 | 118 | gboolean auto_away; |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
119 | const gchar *idle_reporting; |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
120 | gboolean report_idle = TRUE; |
| 17130 | 121 | gint away_seconds = 0; |
|
17536
b04036df5ac6
Compiler be quiet! Fixes this compile warning:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17349
diff
changeset
|
122 | gint idle_recheck_interval = 0; |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
123 | gint idle_poll_seconds = purple_prefs_get_int("/purple/away/mins_before_away") * 60; |
| 15884 | 124 | purple_signal_emit(purple_blist_get_handle(), "update-idle"); |
| 12272 | 125 | |
|
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
|
126 | 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
|
127 | 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
|
128 | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
23196
diff
changeset
|
129 | if (purple_strequal(idle_reporting, "system") && |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
130 | (idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL)) |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
131 | { |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
132 | /* Use system idle time (mouse or keyboard movement, etc.) */ |
| 12272 | 133 | time_idle = idle_ui_ops->get_time_idle(); |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
134 | idle_recheck_interval = 1; |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
135 | } |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
23196
diff
changeset
|
136 | else if (purple_strequal(idle_reporting, "purple")) |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
137 | { |
| 15884 | 138 | /* Use 'Purple idle' */ |
| 12272 | 139 | 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
|
140 | idle_recheck_interval = 0; |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
141 | } |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
142 | else |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
143 | { |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
144 | /* Don't report idle time */ |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
145 | report_idle = FALSE; |
| 12272 | 146 | |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
147 | /* 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
|
148 | * 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
|
149 | 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
|
150 | { |
|
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 ((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
|
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 | time_idle = idle_ui_ops->get_time_idle(); |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
154 | idle_recheck_interval = 1; |
|
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
|
155 | } |
|
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 | 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
|
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 | 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
|
159 | 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
|
160 | } |
|
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 | } |
|
14999
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
162 | 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
|
163 | { |
|
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
|
164 | 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
|
165 | { |
|
19569
dcc2a321208e
Prevent recursive idle handling loop. Patch from 'Gambit'
Sean Egan <seanegan@pidgin.im>
parents:
18949
diff
changeset
|
166 | 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
|
167 | purple_savedstatus_set_idleaway(FALSE); |
|
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 | } |
|
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
|
169 | 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
|
170 | 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
|
171 | } |
|
14999
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
172 | } |
|
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
173 | |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
174 | time_until_next_idle_event = idle_poll_seconds - time_idle; |
|
17161
c4e7791b276f
Move the time_until_next_idle_event < 0 check to clarify.
Richard Laager <rlaager@pidgin.im>
parents:
17160
diff
changeset
|
175 | 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
|
176 | { |
|
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
|
177 | /* 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
|
178 | 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
|
179 | } |
| 17130 | 180 | |
| 181 | if (auto_away || !no_away) | |
| 182 | away_seconds = 60 * purple_prefs_get_int("/purple/away/mins_before_away"); | |
| 183 | ||
| 184 | if (auto_away && time_idle > away_seconds) | |
| 12272 | 185 | { |
| 15884 | 186 | purple_savedstatus_set_idleaway(TRUE); |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
187 | no_away = FALSE; |
| 12272 | 188 | } |
|
26891
0570b1cdf470
Adjust some idle handling code to fix "wedging" idle reporting into never
Paul Aurich <darkrain42@pidgin.im>
parents:
25888
diff
changeset
|
189 | else if (purple_savedstatus_is_idleaway() && time_idle < away_seconds) |
| 12272 | 190 | { |
| 15884 | 191 | 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
|
192 | if (time_until_next_idle_event == 0 || (away_seconds - time_idle) < time_until_next_idle_event) |
| 17130 | 193 | time_until_next_idle_event = away_seconds - time_idle; |
| 12272 | 194 | } |
| 195 | ||
| 196 | /* Idle reporting stuff */ | |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
197 | if (report_idle && (time_idle >= idle_poll_seconds)) |
| 12272 | 198 | { |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
199 | GList *l; |
| 15884 | 200 | 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
|
201 | { |
| 15884 | 202 | PurpleConnection *gc = l->data; |
| 203 | set_account_idle(purple_connection_get_account(gc), time_idle); | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
204 | } |
| 12272 | 205 | } |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
206 | else if (!report_idle || (time_idle < idle_poll_seconds )) |
| 12272 | 207 | { |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
208 | while (idled_accts != NULL) |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
209 | set_account_unidle(idled_accts->data); |
| 12272 | 210 | } |
| 17130 | 211 | } |
| 12272 | 212 | |
| 17130 | 213 | |
| 214 | /* | |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
25859
diff
changeset
|
215 | * Check idle and set the timer to fire at the next idle-worth event |
| 17130 | 216 | */ |
|
22108
cb9819851163
Squash some compiler warnings, some from my -Wstrict-prototypes fixing.
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
217 | static gboolean |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
218 | check_idleness_timer(void) |
| 17130 | 219 | { |
| 220 | 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
|
221 | 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
|
222 | 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
|
223 | 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
|
224 | { |
|
a8c10d130374
Raise the timeouts one second so they'll work every time (for certain) with
Richard Laager <rlaager@pidgin.im>
parents:
18068
diff
changeset
|
225 | /* +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
|
226 | * +1 more for g_timeout_add_seconds rounding. */ |
|
22108
cb9819851163
Squash some compiler warnings, some from my -Wstrict-prototypes fixing.
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
227 | idle_timer = purple_timeout_add_seconds(time_until_next_idle_event + 2, (GSourceFunc)check_idleness_timer, NULL); |
|
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
|
228 | } |
| 17130 | 229 | return FALSE; |
| 12272 | 230 | } |
| 231 | ||
| 232 | static void | |
| 15884 | 233 | im_msg_sent_cb(PurpleAccount *account, const char *receiver, |
| 12272 | 234 | const char *message, void *data) |
| 235 | { | |
| 236 | /* Check our idle time after an IM is sent */ | |
| 237 | check_idleness(); | |
| 238 | } | |
| 239 | ||
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
240 | static void |
| 15884 | 241 | signing_on_cb(PurpleConnection *gc, void *data) |
| 14189 | 242 | { |
| 243 | /* When signing on a new account, check if the account should be idle */ | |
| 244 | check_idleness(); | |
| 245 | } | |
| 246 | ||
| 247 | static void | |
| 15884 | 248 | signing_off_cb(PurpleConnection *gc, void *data) |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
249 | { |
| 15884 | 250 | PurpleAccount *account; |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
251 | |
| 15884 | 252 | account = purple_connection_get_account(gc); |
|
23196
ee37c234be19
applied changes from 7f7111ed9e5924db9e740ad354fce8fb82445b1e
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22958
diff
changeset
|
253 | set_account_unidle(account); |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
254 | } |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
255 | |
|
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
|
256 | 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
|
257 | 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
|
258 | { |
|
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 | 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
|
260 | 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
|
261 | 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
|
262 | 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
|
263 | } |
|
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 | |
| 12272 | 265 | void |
| 15884 | 266 | purple_idle_touch() |
| 12272 | 267 | { |
| 268 | 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
|
269 | 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
|
270 | { |
|
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
|
271 | 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
|
272 | 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
|
273 | 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
|
274 | 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
|
275 | } |
| 12272 | 276 | } |
| 277 | ||
| 278 | void | |
| 15884 | 279 | purple_idle_set(time_t time) |
| 12272 | 280 | { |
| 281 | last_active_time = time; | |
| 282 | } | |
| 283 | ||
| 35572 | 284 | static PurpleIdleUiOps * |
| 285 | purple_idle_ui_ops_copy(PurpleIdleUiOps *ops) | |
| 286 | { | |
| 287 | PurpleIdleUiOps *ops_new; | |
| 288 | ||
| 289 | g_return_val_if_fail(ops != NULL, NULL); | |
| 290 | ||
| 291 | ops_new = g_new(PurpleIdleUiOps, 1); | |
| 292 | *ops_new = *ops; | |
| 293 | ||
| 294 | return ops_new; | |
| 295 | } | |
| 296 | ||
| 297 | GType | |
| 298 | purple_idle_ui_ops_get_type(void) | |
| 299 | { | |
| 300 | static GType type = 0; | |
| 301 | ||
| 302 | if (type == 0) { | |
| 303 | type = g_boxed_type_register_static("PurpleIdleUiOps", | |
| 304 | (GBoxedCopyFunc)purple_idle_ui_ops_copy, | |
|
35597
7fcfcf147b99
Use g_free as UiOps structures GBoxed free function
Ankit Vani <a@nevitus.org>
parents:
35572
diff
changeset
|
305 | (GBoxedFreeFunc)g_free); |
| 35572 | 306 | } |
| 307 | ||
| 308 | return type; | |
| 309 | } | |
| 310 | ||
| 12272 | 311 | void |
| 15884 | 312 | purple_idle_set_ui_ops(PurpleIdleUiOps *ops) |
| 12272 | 313 | { |
| 314 | idle_ui_ops = ops; | |
| 315 | } | |
| 316 | ||
| 15884 | 317 | PurpleIdleUiOps * |
| 318 | purple_idle_get_ui_ops(void) | |
| 12272 | 319 | { |
| 320 | return idle_ui_ops; | |
| 321 | } | |
| 322 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12272
diff
changeset
|
323 | static void * |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
324 | purple_idle_get_handle(void) |
| 12272 | 325 | { |
| 326 | static int handle; | |
| 327 | ||
| 328 | return &handle; | |
| 329 | } | |
| 330 | ||
|
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
|
331 | 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
|
332 | { |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
333 | int idle_poll_minutes = purple_prefs_get_int("/purple/away/mins_before_away"); |
|
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
334 | |
|
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
335 | /* +1 more for g_timeout_add_seconds rounding. */ |
|
22108
cb9819851163
Squash some compiler warnings, some from my -Wstrict-prototypes fixing.
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
336 | idle_timer = purple_timeout_add_seconds((idle_poll_minutes * 60) + 2, (GSourceFunc)check_idleness_timer, NULL); |
|
18949
7ba397b0f34e
Fix idle reporting as discussed on devel@. Poll as needed when we're not idle, and poll frequently (once every three seconds) when we are. Fixes #1357
Sean Egan <seanegan@pidgin.im>
parents:
18191
diff
changeset
|
337 | |
|
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
|
338 | 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
|
339 | |
|
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
|
340 | 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
|
341 | } |
|
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
|
342 | |
|
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
|
343 | |
| 12272 | 344 | void |
| 15884 | 345 | purple_idle_init() |
| 12272 | 346 | { |
| 15884 | 347 | purple_signal_connect(purple_conversations_get_handle(), "sent-im-msg", |
| 348 | purple_idle_get_handle(), | |
| 349 | PURPLE_CALLBACK(im_msg_sent_cb), NULL); | |
| 350 | purple_signal_connect(purple_connections_get_handle(), "signing-on", | |
| 351 | purple_idle_get_handle(), | |
| 352 | PURPLE_CALLBACK(signing_on_cb), NULL); | |
| 353 | purple_signal_connect(purple_connections_get_handle(), "signing-off", | |
| 354 | purple_idle_get_handle(), | |
| 355 | PURPLE_CALLBACK(signing_off_cb), NULL); | |
| 12272 | 356 | |
|
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
|
357 | 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
|
358 | 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
|
359 | |
|
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
|
360 | /* 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
|
361 | * and potentially try to change the status before the UI is initialized */ |
|
22351
6ca0640b3d31
Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <markdoliner@pidgin.im>
parents:
22108
diff
changeset
|
362 | purple_timeout_add(0, _do_purple_idle_touch_cb, NULL); |
|
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
|
363 | |
| 12272 | 364 | } |
| 365 | ||
| 366 | void | |
| 15884 | 367 | purple_idle_uninit() |
| 12272 | 368 | { |
| 15884 | 369 | 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
|
370 | purple_prefs_disconnect_by_handle(purple_idle_get_handle()); |
| 12272 | 371 | |
| 372 | /* Remove the idle timer */ | |
| 373 | if (idle_timer > 0) | |
| 15884 | 374 | purple_timeout_remove(idle_timer); |
| 12272 | 375 | idle_timer = 0; |
| 376 | } |