Fri, 25 Mar 2022 02:51:58 -0500
Replace PURPLE_CALLBACK by G_CALLBACK
Another straight search-and-replace for 'easy' review.
Testing Done:
Compile only.
Reviewed at https://reviews.imfreedom.org/r/1371/
| 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 | ||
| 24 | #include "connection.h" | |
|
41137
3c1574216aed
Now that the History API is here, remove the purple logging api
Gary Kramlich <grim@reaperworld.com>
parents:
41136
diff
changeset
|
25 | #include "conversations.h" |
| 12272 | 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 "prefs.h" | |
| 30 | #include "savedstatuses.h" | |
| 31 | #include "signals.h" | |
| 32 | ||
| 33 | typedef enum | |
| 34 | { | |
| 15884 | 35 | PURPLE_IDLE_NOT_AWAY = 0, |
| 36 | PURPLE_IDLE_AUTO_AWAY, | |
| 37 | PURPLE_IDLE_AWAY_BUT_NOT_AUTO_AWAY | |
| 12272 | 38 | |
| 15884 | 39 | } PurpleAutoAwayState; |
| 12272 | 40 | |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
41 | static PurpleIdleUi *idle_ui = NULL; |
| 12272 | 42 | |
|
35462
901dfa763f15
Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents:
26891
diff
changeset
|
43 | /* |
| 12272 | 44 | * This is needed for the I'dle Mak'er plugin to work correctly. We |
| 45 | * use it to determine if we're the ones who set our accounts idle | |
| 46 | * 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
|
47 | * 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
|
48 | * 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
|
49 | * user returns. |
| 12272 | 50 | */ |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
51 | static GList *idled_accts = NULL; |
| 12272 | 52 | |
| 53 | static guint idle_timer = 0; | |
| 54 | ||
| 55 | static time_t last_active_time = 0; | |
| 56 | ||
| 57 | static void | |
| 15884 | 58 | set_account_idle(PurpleAccount *account, int time_idle) |
| 12272 | 59 | { |
| 15884 | 60 | PurplePresence *presence; |
| 12272 | 61 | |
| 15884 | 62 | presence = purple_account_get_presence(account); |
| 12272 | 63 | |
| 15884 | 64 | if (purple_presence_is_idle(presence)) |
| 12272 | 65 | /* This account is already idle! */ |
| 66 | return; | |
| 67 | ||
| 15884 | 68 | purple_debug_info("idle", "Setting %s idle %d seconds\n", |
| 69 | purple_account_get_username(account), time_idle); | |
| 70 | purple_presence_set_idle(presence, TRUE, time(NULL) - time_idle); | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
71 | idled_accts = g_list_prepend(idled_accts, account); |
| 12272 | 72 | } |
| 73 | ||
| 74 | static void | |
| 15884 | 75 | set_account_unidle(PurpleAccount *account) |
| 12272 | 76 | { |
| 15884 | 77 | PurplePresence *presence; |
| 12272 | 78 | |
| 15884 | 79 | presence = purple_account_get_presence(account); |
| 12272 | 80 | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
81 | idled_accts = g_list_remove(idled_accts, account); |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
82 | |
| 15884 | 83 | if (!purple_presence_is_idle(presence)) |
| 12272 | 84 | /* This account is already unidle! */ |
| 85 | return; | |
| 86 | ||
| 15884 | 87 | purple_debug_info("idle", "Setting %s unidle\n", |
| 88 | purple_account_get_username(account)); | |
| 89 | purple_presence_set_idle(presence, FALSE, 0); | |
| 12272 | 90 | } |
| 91 | ||
| 17130 | 92 | |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
93 | static gboolean no_away = FALSE; |
| 17130 | 94 | static gint time_until_next_idle_event; |
| 12272 | 95 | /* |
| 96 | * This function should be called when you think your idle state | |
| 97 | * may have changed. Maybe you're over the 10-minute mark and | |
| 15884 | 98 | * Purple should start reporting idle time to the server. Maybe |
| 12272 | 99 | * you've returned from being idle. Maybe your auto-away message |
| 100 | * should be set. | |
| 101 | * | |
| 102 | * 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
|
103 | * 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
|
104 | * Purple starts. It is also called when you send an IM, a chat, etc. |
| 12272 | 105 | * |
| 106 | * This function has 3 sections. | |
| 107 | * 1. Get your idle time. It will query XScreenSaver or Windows | |
| 15884 | 108 | * or use the Purple idle time. Whatever. |
| 12272 | 109 | * 2. Set or unset your auto-away message. |
| 110 | * 3. Report your current idle time to the IM server. | |
| 111 | */ | |
| 17130 | 112 | |
| 113 | static void | |
| 114 | check_idleness(void) | |
| 12272 | 115 | { |
|
35382
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
26891
diff
changeset
|
116 | time_t time_idle = 0; |
| 12272 | 117 | gboolean auto_away; |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
118 | const gchar *idle_reporting; |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
119 | gboolean report_idle = TRUE; |
| 17130 | 120 | gint away_seconds = 0; |
|
17536
b04036df5ac6
Compiler be quiet! Fixes this compile warning:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17349
diff
changeset
|
121 | 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
|
122 | gint idle_poll_seconds = purple_prefs_get_int("/purple/away/mins_before_away") * 60; |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
123 | gboolean set = FALSE; |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
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 | |
|
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
|
130 | if (purple_strequal(idle_reporting, "system") && |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
131 | PURPLE_IS_IDLE_UI(idle_ui)) |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
132 | { |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
133 | time_t new_idle = purple_idle_ui_get_idle_time(idle_ui); |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
134 | |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
135 | if(new_idle > 0) { |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
136 | /* Use system idle time (mouse or keyboard movement, etc.) */ |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
137 | time_idle = new_idle; |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
138 | idle_recheck_interval = 1; |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
139 | set = TRUE; |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
140 | } |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
141 | } |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
142 | |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
143 | if(!set && purple_strequal(idle_reporting, "purple")) { |
| 15884 | 144 | /* Use 'Purple idle' */ |
| 12272 | 145 | 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
|
146 | idle_recheck_interval = 0; |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
147 | } else { |
|
12573
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
148 | /* Don't report idle time */ |
|
1fc347b54974
[gaim-migrate @ 14895]
Mark Doliner <markdoliner@pidgin.im>
parents:
12412
diff
changeset
|
149 | report_idle = FALSE; |
| 12272 | 150 | |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
151 | /* 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
|
152 | * First try "system" and if that isn't possible, use "purple" */ |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
153 | if(auto_away) { |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
154 | if(PURPLE_IS_IDLE_UI(idle_ui)) { |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
155 | time_t new_idle = purple_idle_ui_get_idle_time(idle_ui); |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
156 | |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
157 | if(new_idle > 0) { |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
158 | time_idle = new_idle; |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
159 | idle_recheck_interval = 1; |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
160 | |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
161 | set = TRUE; |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
162 | } |
|
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 | } |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
164 | |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
165 | if(!set) { |
|
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
|
166 | 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
|
167 | 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
|
168 | } |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
169 | } else { |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
170 | if(!no_away) { |
|
19569
dcc2a321208e
Prevent recursive idle handling loop. Patch from 'Gambit'
Sean Egan <seanegan@pidgin.im>
parents:
18949
diff
changeset
|
171 | 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
|
172 | 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
|
173 | } |
|
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
|
174 | 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
|
175 | 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
|
176 | } |
|
14999
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
177 | } |
|
7b3992f19766
[gaim-migrate @ 17709]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
178 | |
|
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
|
179 | 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
|
180 | 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
|
181 | { |
|
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
|
182 | /* 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
|
183 | 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
|
184 | } |
| 17130 | 185 | |
| 186 | if (auto_away || !no_away) | |
| 187 | away_seconds = 60 * purple_prefs_get_int("/purple/away/mins_before_away"); | |
| 188 | ||
| 189 | if (auto_away && time_idle > away_seconds) | |
| 12272 | 190 | { |
| 15884 | 191 | purple_savedstatus_set_idleaway(TRUE); |
|
17579
4c3e8468d487
Clean up the idle checking callback slightly.
Daniel Atallah <datallah@pidgin.im>
parents:
17536
diff
changeset
|
192 | no_away = FALSE; |
| 12272 | 193 | } |
|
26891
0570b1cdf470
Adjust some idle handling code to fix "wedging" idle reporting into never
Paul Aurich <darkrain42@pidgin.im>
parents:
25888
diff
changeset
|
194 | else if (purple_savedstatus_is_idleaway() && time_idle < away_seconds) |
| 12272 | 195 | { |
| 15884 | 196 | 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
|
197 | if (time_until_next_idle_event == 0 || (away_seconds - time_idle) < time_until_next_idle_event) |
| 17130 | 198 | time_until_next_idle_event = away_seconds - time_idle; |
| 12272 | 199 | } |
| 200 | ||
| 201 | /* 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
|
202 | if (report_idle && (time_idle >= idle_poll_seconds)) |
| 12272 | 203 | { |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
204 | GList *l; |
| 15884 | 205 | 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
|
206 | { |
| 15884 | 207 | PurpleConnection *gc = l->data; |
| 208 | set_account_idle(purple_connection_get_account(gc), time_idle); | |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
209 | } |
| 12272 | 210 | } |
|
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
|
211 | else if (!report_idle || (time_idle < idle_poll_seconds )) |
| 12272 | 212 | { |
|
12825
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
213 | while (idled_accts != NULL) |
|
0989792c930b
[gaim-migrate @ 15173]
Mark Doliner <markdoliner@pidgin.im>
parents:
12573
diff
changeset
|
214 | set_account_unidle(idled_accts->data); |
| 12272 | 215 | } |
| 17130 | 216 | } |
| 12272 | 217 | |
| 17130 | 218 | /* |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
25859
diff
changeset
|
219 | * Check idle and set the timer to fire at the next idle-worth event |
| 17130 | 220 | */ |
|
22108
cb9819851163
Squash some compiler warnings, some from my -Wstrict-prototypes fixing.
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
221 | 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
|
222 | check_idleness_timer(void) |
| 17130 | 223 | { |
| 224 | 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
|
225 | 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
|
226 | 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
|
227 | 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
|
228 | { |
|
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 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
|
230 | * +1 more for g_timeout_add_seconds rounding. */ |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36081
diff
changeset
|
231 | idle_timer = g_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
|
232 | } |
| 17130 | 233 | return FALSE; |
| 12272 | 234 | } |
| 235 | ||
| 236 | static void | |
|
36081
6764e037a308
Switch sent-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35597
diff
changeset
|
237 | im_msg_sent_cb(PurpleAccount *account, PurpleMessage *msg, void *data) |
| 12272 | 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); |
|
23196
ee37c234be19
applied changes from 7f7111ed9e5924db9e740ad354fce8fb82445b1e
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22958
diff
changeset
|
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) |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36081
diff
changeset
|
263 | g_source_remove(idle_timer); |
|
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
|
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) |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36081
diff
changeset
|
275 | g_source_remove(idle_timer); |
|
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
|
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 | ||
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
287 | void |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
288 | purple_idle_set_ui(PurpleIdleUi *ui) { |
|
41160
d12bedb8b662
Check that we have a PurpleIdleUi if we weren't passed null
Gary Kramlich <grim@reaperworld.com>
parents:
41137
diff
changeset
|
289 | g_return_if_fail(ui == NULL || PURPLE_IS_IDLE_UI(ui)); |
|
d12bedb8b662
Check that we have a PurpleIdleUi if we weren't passed null
Gary Kramlich <grim@reaperworld.com>
parents:
41137
diff
changeset
|
290 | |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
291 | g_clear_object(&idle_ui); |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
292 | idle_ui = ui; |
| 35572 | 293 | } |
| 294 | ||
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
295 | PurpleIdleUi * |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
296 | purple_idle_get_ui(void) { |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
297 | return idle_ui; |
| 12272 | 298 | } |
| 299 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12272
diff
changeset
|
300 | 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
|
301 | purple_idle_get_handle(void) |
| 12272 | 302 | { |
| 303 | static int handle; | |
| 304 | ||
| 305 | return &handle; | |
| 306 | } | |
| 307 | ||
|
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
|
308 | 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
|
309 | { |
|
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
|
310 | 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
|
311 | |
|
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
|
312 | /* +1 more for g_timeout_add_seconds rounding. */ |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36081
diff
changeset
|
313 | idle_timer = g_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
|
314 | |
|
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
|
315 | 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
|
316 | |
|
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
|
317 | 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
|
318 | } |
|
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
|
319 | |
|
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
|
320 | |
| 12272 | 321 | void |
| 15884 | 322 | purple_idle_init() |
| 12272 | 323 | { |
| 15884 | 324 | purple_signal_connect(purple_conversations_get_handle(), "sent-im-msg", |
| 325 | purple_idle_get_handle(), | |
|
41314
0dc72eacd8bf
Replace PURPLE_CALLBACK by G_CALLBACK
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41160
diff
changeset
|
326 | G_CALLBACK(im_msg_sent_cb), NULL); |
| 15884 | 327 | purple_signal_connect(purple_connections_get_handle(), "signing-on", |
| 328 | purple_idle_get_handle(), | |
|
41314
0dc72eacd8bf
Replace PURPLE_CALLBACK by G_CALLBACK
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41160
diff
changeset
|
329 | G_CALLBACK(signing_on_cb), NULL); |
| 15884 | 330 | purple_signal_connect(purple_connections_get_handle(), "signing-off", |
| 331 | purple_idle_get_handle(), | |
|
41314
0dc72eacd8bf
Replace PURPLE_CALLBACK by G_CALLBACK
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41160
diff
changeset
|
332 | G_CALLBACK(signing_off_cb), NULL); |
| 12272 | 333 | |
|
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
|
334 | 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
|
335 | 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
|
336 | |
|
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
|
337 | /* 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
|
338 | * and potentially try to change the status before the UI is initialized */ |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36081
diff
changeset
|
339 | g_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
|
340 | |
| 12272 | 341 | } |
| 342 | ||
| 343 | void | |
| 15884 | 344 | purple_idle_uninit() |
| 12272 | 345 | { |
| 15884 | 346 | 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
|
347 | purple_prefs_disconnect_by_handle(purple_idle_get_handle()); |
| 12272 | 348 | |
| 349 | /* Remove the idle timer */ | |
| 350 | if (idle_timer > 0) | |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36081
diff
changeset
|
351 | g_source_remove(idle_timer); |
| 12272 | 352 | idle_timer = 0; |
|
41136
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
353 | |
|
5397330041d6
Replace PurpleIdleUiOps with the PurpleIdleUi Interface
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
354 | g_clear_object(&idle_ui); |
| 12272 | 355 | } |