annotate src/idle.c @ 14151:8856312371cb

[gaim-migrate @ 16796] Fix bug #1541223 committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 16 Aug 2006 18:55:17 +0000
parents a8a033a89ee0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /*
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * gaim
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 * source distribution.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 * (at your option) any later version.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 * GNU General Public License for more details.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 #include "internal.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25 #include "connection.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26 #include "debug.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
27 #include "idle.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 #include "log.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 #include "prefs.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30 #include "savedstatuses.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 #include "signals.h"
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 #define IDLEMARK 600 /* 10 minutes! */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34 #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 typedef enum
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 GAIM_IDLE_NOT_AWAY = 0,
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39 GAIM_IDLE_AUTO_AWAY,
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40 GAIM_IDLE_AWAY_BUT_NOT_AUTO_AWAY
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 } GaimAutoAwayState;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44 static GaimIdleUiOps *idle_ui_ops = NULL;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46 /**
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
47 * This is needed for the I'dle Mak'er plugin to work correctly. We
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 * use it to determine if we're the ones who set our accounts idle
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 * or if someone else did it (the I'dle Mak'er plugin, for example).
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
50 * Basically we just keep track of which accounts were set idle by us,
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
51 * and then we'll only set these specific accounts unidle when the
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
52 * user returns.
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 */
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
54 static GList *idled_accts = NULL;
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 static guint idle_timer = 0;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 static time_t last_active_time = 0;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 static void
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
61 set_account_idle(GaimAccount *account, int time_idle)
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 GaimPresence *presence;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65 presence = gaim_account_get_presence(account);
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 if (gaim_presence_is_idle(presence))
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68 /* This account is already idle! */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 return;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71 gaim_debug_info("idle", "Setting %s idle %d seconds\n",
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 gaim_account_get_username(account), time_idle);
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73 gaim_presence_set_idle(presence, TRUE, time(NULL) - time_idle);
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
74 idled_accts = g_list_prepend(idled_accts, account);
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 static void
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
78 set_account_unidle(GaimAccount *account)
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 GaimPresence *presence;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 presence = gaim_account_get_presence(account);
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
84 idled_accts = g_list_remove(idled_accts, account);
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
85
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 if (!gaim_presence_is_idle(presence))
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87 /* This account is already unidle! */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 return;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 gaim_debug_info("idle", "Setting %s unidle\n",
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 gaim_account_get_username(account));
13722
4997b8b66206 [gaim-migrate @ 16131]
Mark Doliner <mark@kingant.net>
parents: 13667
diff changeset
92 gaim_presence_set_idle(presence, FALSE, 0);
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95 /*
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 * This function should be called when you think your idle state
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 * may have changed. Maybe you're over the 10-minute mark and
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98 * Gaim should start reporting idle time to the server. Maybe
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 * you've returned from being idle. Maybe your auto-away message
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 * should be set.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 * There is no harm to calling this many many times, other than
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103 * it will be kinda slow. This is called every 5 seconds by a
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 * timer set when Gaim starts. It is also called when
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 * you send an IM, a chat, etc.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 * This function has 3 sections.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 * 1. Get your idle time. It will query XScreenSaver or Windows
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 * or use the Gaim idle time. Whatever.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 * 2. Set or unset your auto-away message.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 * 3. Report your current idle time to the IM server.
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 static gint
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 check_idleness()
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 time_t time_idle;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117 gboolean auto_away;
12573
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
118 const gchar *idle_reporting;
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 gboolean report_idle;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120 GList *l;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 gaim_signal_emit(gaim_blist_get_handle(), "update-idle");
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123
12573
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
124 idle_reporting = gaim_prefs_get_string("/core/away/idle_reporting");
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
125 report_idle = TRUE;
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
126 if (!strcmp(idle_reporting, "system") &&
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
127 (idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL))
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
128 {
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
129 /* Use system idle time (mouse or keyboard movement, etc.) */
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130 time_idle = idle_ui_ops->get_time_idle();
12573
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
131 }
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
132 else if (!strcmp(idle_reporting, "gaim"))
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
133 {
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
134 /* Use 'Gaim idle' */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 time_idle = time(NULL) - last_active_time;
12573
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
136 }
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
137 else
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
138 {
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
139 /* Don't report idle time */
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
140 time_idle = 0;
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
141 report_idle = FALSE;
200f22ca4890 [gaim-migrate @ 14895]
Mark Doliner <mark@kingant.net>
parents: 12412
diff changeset
142 }
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
144 /* Auto-away stuff */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
145 auto_away = gaim_prefs_get_bool("/core/away/away_when_idle");
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 if (auto_away &&
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147 (time_idle > (60 * gaim_prefs_get_int("/core/away/mins_before_away"))))
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148 {
14128
a8a033a89ee0 [gaim-migrate @ 16766]
Mark Doliner <mark@kingant.net>
parents: 14127
diff changeset
149 gaim_savedstatus_set_idleaway(TRUE);
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
150 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151 else if (time_idle < 60 * gaim_prefs_get_int("/core/away/mins_before_away"))
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152 {
14128
a8a033a89ee0 [gaim-migrate @ 16766]
Mark Doliner <mark@kingant.net>
parents: 14127
diff changeset
153 gaim_savedstatus_set_idleaway(FALSE);
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
154 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
155
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156 /* Idle reporting stuff */
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
157 if (report_idle && (time_idle >= IDLEMARK))
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159 for (l = gaim_connections_get_all(); l != NULL; l = l->next)
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
160 {
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
161 GaimConnection *gc = l->data;
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
162 set_account_idle(gaim_connection_get_account(gc), time_idle);
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
163 }
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 }
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
165 else if (!report_idle || (time_idle < IDLEMARK))
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 {
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
167 while (idled_accts != NULL)
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
168 set_account_unidle(idled_accts->data);
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171 return TRUE;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
172 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
173
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
174 static void
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
175 im_msg_sent_cb(GaimAccount *account, const char *receiver,
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
176 const char *message, void *data)
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
177 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
178 /* Check our idle time after an IM is sent */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
179 check_idleness();
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
181
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
182 static void
14127
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
183 signing_on_cb(GaimConnection *gc, void *data)
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
184 {
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
185 /* When signing on a new account, check if the account should be idle */
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
186 check_idleness();
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
187 }
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
188
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
189 static void
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
190 signing_off_cb(GaimConnection *gc, void *data)
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
191 {
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
192 GaimAccount *account;
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
193
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
194 account = gaim_connection_get_account(gc);
14127
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
195 set_account_unidle(account);
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
196 }
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
197
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198 void
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 gaim_idle_touch()
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 time(&last_active_time);
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
202 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
204 void
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
205 gaim_idle_set(time_t time)
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
206 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
207 last_active_time = time;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210 void
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211 gaim_idle_set_ui_ops(GaimIdleUiOps *ops)
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
213 idle_ui_ops = ops;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
214 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
216 GaimIdleUiOps *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
217 gaim_idle_get_ui_ops(void)
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
218 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 return idle_ui_ops;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
221
12412
a88ca6da0b38 [gaim-migrate @ 14719]
Richard Laager <rlaager@wiktel.com>
parents: 12272
diff changeset
222 static void *
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
223 gaim_idle_get_handle()
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
224 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225 static int handle;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227 return &handle;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
228 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230 void
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231 gaim_idle_init()
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233 /* Add the timer to check if we're idle */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 idle_timer = gaim_timeout_add(IDLE_CHECK_INTERVAL * 1000, check_idleness, NULL);
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
235
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
236 gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg",
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237 gaim_idle_get_handle(),
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
238 GAIM_CALLBACK(im_msg_sent_cb), NULL);
14127
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
239 gaim_signal_connect(gaim_connections_get_handle(), "signing-on",
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
240 gaim_idle_get_handle(),
9a4b76c288aa [gaim-migrate @ 16765]
Mark Doliner <mark@kingant.net>
parents: 13722
diff changeset
241 GAIM_CALLBACK(signing_on_cb), NULL);
12825
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
242 gaim_signal_connect(gaim_connections_get_handle(), "signing-off",
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
243 gaim_idle_get_handle(),
bd80fb1e8406 [gaim-migrate @ 15173]
Mark Doliner <mark@kingant.net>
parents: 12573
diff changeset
244 GAIM_CALLBACK(signing_off_cb), NULL);
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 gaim_idle_touch();
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247 }
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249 void
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250 gaim_idle_uninit()
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251 {
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252 gaim_signals_disconnect_by_handle(gaim_idle_get_handle());
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
253
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 /* Remove the idle timer */
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
255 if (idle_timer > 0)
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 gaim_timeout_remove(idle_timer);
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 idle_timer = 0;
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 }