Mercurial > pidgin.yaz
annotate src/idle.c @ 5632:b88734ca07b2
[gaim-migrate @ 6039]
those silly brits
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 01 Jun 2003 06:02:52 +0000 |
parents | 6500a6c8d679 |
children | c6a30e1868ae |
rev | line source |
---|---|
1026 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
1 | 5 * |
1026 | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
1 | 10 * |
1026 | 11 * This program is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
1 | 15 * |
1026 | 16 * You should have received a copy of the GNU General Public License |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
1 | 19 * |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1952
diff
changeset
|
23 #include <config.h> |
1 | 24 #endif |
1026 | 25 #include <time.h> |
26 #include <stdio.h> | |
27 #include <unistd.h> | |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
28 #include <string.h> |
1 | 29 |
1026 | 30 #ifdef USE_SCREENSAVER |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
31 #ifndef _WIN32 |
1026 | 32 #include <X11/Xlib.h> |
33 #include <X11/Xutil.h> | |
34 #include <X11/extensions/scrnsaver.h> | |
2115
3ce77b547cf2
[gaim-migrate @ 2125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2114
diff
changeset
|
35 #include <gdk/gdkx.h> |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
36 #else |
4536
ba99d30afc14
[gaim-migrate @ 4815]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4201
diff
changeset
|
37 #include "idletrack.h" |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
38 #endif |
1026 | 39 #endif /* USE_SCREENSAVER */ |
1 | 40 |
4608 | 41 #include "gaim.h" |
5615
6500a6c8d679
[gaim-migrate @ 6022]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
42 #include "connection.h" |
1026 | 43 #include "multi.h" |
1401
bf041349b11e
[gaim-migrate @ 1411]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1367
diff
changeset
|
44 #include "prpl.h" |
5548 | 45 #include "prefs.h" |
1 | 46 |
4536
ba99d30afc14
[gaim-migrate @ 4815]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4201
diff
changeset
|
47 #define IDLEMARK 600 /* 10 minutes! */ |
1 | 48 |
2381
427ccd7dfdd2
[gaim-migrate @ 2394]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
49 gint check_idle(gpointer data) |
1 | 50 { |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
51 const char *report_idle; |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
52 GaimConnection *gc = data; |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
53 GaimAccount *account; |
1026 | 54 time_t t; |
55 #ifdef USE_SCREENSAVER | |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
56 #ifndef _WIN32 |
1026 | 57 static XScreenSaverInfo *mit_info = NULL; |
1062
9446ac58745e
[gaim-migrate @ 1072]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1058
diff
changeset
|
58 #endif |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
59 #endif |
4201
511c2b63caa4
[gaim-migrate @ 4432]
Christian Hammond <chipx86@chipx86.com>
parents:
3905
diff
changeset
|
60 int idle_time; |
1 | 61 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
62 account = gaim_connection_get_account(gc); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
63 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
64 gaim_event_broadcast(event_blist_update); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1141
diff
changeset
|
65 |
1026 | 66 time(&t); |
1 | 67 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
68 report_idle = gaim_prefs_get_string("/gaim/gtk/idle/reporting_method"); |
1 | 69 |
1026 | 70 #ifdef USE_SCREENSAVER |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
71 if (!strcmp(report_idle, "system")) { |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
72 #ifndef _WIN32 |
2115
3ce77b547cf2
[gaim-migrate @ 2125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2114
diff
changeset
|
73 int event_base, error_base; |
3ce77b547cf2
[gaim-migrate @ 2125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2114
diff
changeset
|
74 if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) { |
2114
c582116e8463
[gaim-migrate @ 2124]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
75 if (mit_info == NULL) { |
c582116e8463
[gaim-migrate @ 2124]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
76 mit_info = XScreenSaverAllocInfo(); |
c582116e8463
[gaim-migrate @ 2124]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
77 } |
2115
3ce77b547cf2
[gaim-migrate @ 2125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2114
diff
changeset
|
78 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info); |
2114
c582116e8463
[gaim-migrate @ 2124]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
79 idle_time = (mit_info->idle) / 1000; |
c582116e8463
[gaim-migrate @ 2124]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
80 } else |
c582116e8463
[gaim-migrate @ 2124]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
81 idle_time = 0; |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
82 #else |
4536
ba99d30afc14
[gaim-migrate @ 4815]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4201
diff
changeset
|
83 idle_time = (GetTickCount() - wgaim_get_lastactive()) / 1000; |
3905
3e508dd31b76
[gaim-migrate @ 4058]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3517
diff
changeset
|
84 #endif |
1026 | 85 } else |
86 #endif /* USE_SCREENSAVER */ | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
87 idle_time = t - gc->last_sent_time; |
1 | 88 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
89 if (gaim_prefs_get_bool("/core/away/away_when_idle") && |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
90 (idle_time > (60 * auto_away)) && (!gc->is_auto_away)) { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
91 |
1446
38f712e75836
[gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1407
diff
changeset
|
92 if (!gc->away) { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
93 gaim_debug(GAIM_DEBUG_INFO, "idle", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
94 "Making %s away automatically\n", |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
95 gaim_account_get_username(account)); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
96 if (g_list_length(gaim_connections_get_all()) == 1) |
1446
38f712e75836
[gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1407
diff
changeset
|
97 do_away_message(NULL, default_away); |
1895
e65b9942f649
[gaim-migrate @ 1905]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1885
diff
changeset
|
98 else if (default_away) |
1446
38f712e75836
[gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1407
diff
changeset
|
99 serv_set_away(gc, GAIM_AWAY_CUSTOM, default_away->message); |
1468
9db35684c68c
[gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1450
diff
changeset
|
100 gc->is_auto_away = 1; |
1952
39df68320a82
[gaim-migrate @ 1962]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1895
diff
changeset
|
101 set_default_away(NULL, (gpointer)g_slist_index(away_messages, default_away)); |
1468
9db35684c68c
[gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1450
diff
changeset
|
102 } else |
9db35684c68c
[gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1450
diff
changeset
|
103 gc->is_auto_away = 2; |
9db35684c68c
[gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1450
diff
changeset
|
104 } else if (gc->is_auto_away && idle_time < 60 * auto_away) { |
9db35684c68c
[gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1450
diff
changeset
|
105 if (gc->is_auto_away == 2) { |
9db35684c68c
[gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1450
diff
changeset
|
106 gc->is_auto_away = 0; |
1815
f15d449b3167
[gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1575
diff
changeset
|
107 return TRUE; |
1446
38f712e75836
[gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1407
diff
changeset
|
108 } |
1468
9db35684c68c
[gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1450
diff
changeset
|
109 gc->is_auto_away = 0; |
1407
9f356885a77a
[gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1404
diff
changeset
|
110 if (awaymessage == NULL) { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
111 gaim_debug(GAIM_DEBUG_INFO, "idle", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
112 "Removing auto-away message for %s\n", gaim_account_get_username(account)); |
1401
bf041349b11e
[gaim-migrate @ 1411]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1367
diff
changeset
|
113 serv_set_away(gc, GAIM_AWAY_CUSTOM, NULL); |
1407
9f356885a77a
[gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1404
diff
changeset
|
114 } else { |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
115 if (g_list_length(gaim_connections_get_all()) == 1) |
1450
024f9250ba63
[gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1446
diff
changeset
|
116 do_im_back(0, 0); |
024f9250ba63
[gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1446
diff
changeset
|
117 else { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
118 gaim_debug(GAIM_DEBUG_INFO, "idle", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
119 "Replacing auto-away with global for %s\n", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
120 gaim_account_get_username(account)); |
1450
024f9250ba63
[gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1446
diff
changeset
|
121 serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message); |
024f9250ba63
[gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1446
diff
changeset
|
122 } |
1407
9f356885a77a
[gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1404
diff
changeset
|
123 } |
1109
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
124 } |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
125 |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
126 |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
127 /* If we're not reporting idle times to the server, still use Gaim |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
128 usage for auto-away, but quit here so we don't report to the |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
129 server */ |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
130 |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5548
diff
changeset
|
131 if (!strcmp(report_idle, "none")) |
1109
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
132 return TRUE; |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1062
diff
changeset
|
133 |
4547
1f19b66c5d84
[gaim-migrate @ 4826]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4536
diff
changeset
|
134 if (idle_time >= IDLEMARK && !gc->is_idle) { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
135 gaim_debug(GAIM_DEBUG_INFO, "idle", "Setting %s idle %d seconds\n", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
136 gaim_account_get_username(account), idle_time); |
1026 | 137 serv_set_idle(gc, idle_time); |
138 gc->is_idle = 1; | |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1468
diff
changeset
|
139 system_log(log_idle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); |
4536
ba99d30afc14
[gaim-migrate @ 4815]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4201
diff
changeset
|
140 } else if (idle_time < IDLEMARK && gc->is_idle) { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
141 gaim_debug(GAIM_DEBUG_INFO, "idle", "Setting %s unidle\n", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
142 gaim_account_get_username(account)); |
1026 | 143 serv_touch_idle(gc); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1468
diff
changeset
|
144 system_log(log_unidle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); |
1029
740c6f933fe0
[gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1028
diff
changeset
|
145 } |
1 | 146 |
1026 | 147 return TRUE; |
1 | 148 |
149 } |