annotate src/idle.c @ 1755:300dcb2aa120

[gaim-migrate @ 1765] Fixed a funny typo. The Conversation->Windows tab had two frames that were both labeled IM Window ;-) committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Thu, 26 Apr 2001 22:45:02 +0000
parents 427e1409917c
children f15d449b3167
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
1 /*
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
2 * gaim
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
3 *
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
6 * This program is free software; you can redistribute it and/or modify
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
7 * it under the terms of the GNU General Public License as published by
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
9 * (at your option) any later version.
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
11 * This program is distributed in the hope that it will be useful,
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
14 * GNU General Public License for more details.
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
16 * You should have received a copy of the GNU General Public License
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
17 * along with this program; if not, write to the Free Software
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
23 #include "../config.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24 #endif
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
25 #include <time.h>
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
26 #include <stdio.h>
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
27 #include <unistd.h>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
29 #ifdef USE_SCREENSAVER
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
30 #include <X11/Xlib.h>
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
31 #include <X11/Xutil.h>
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
32 #include <X11/extensions/scrnsaver.h>
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
33 #endif /* USE_SCREENSAVER */
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
35 #include "multi.h"
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
36 #include "gaim.h"
1401
bf041349b11e [gaim-migrate @ 1411]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1367
diff changeset
37 #include "prpl.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
40 gint check_idle(struct gaim_connection *gc)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41 {
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
42 time_t t;
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
43 #ifdef USE_SCREENSAVER
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
44 static XScreenSaverInfo *mit_info = NULL;
1028
e4147c8604cc [gaim-migrate @ 1038]
Rob Flynn <gaim@robflynn.com>
parents: 1027
diff changeset
45 static Display *d = NULL;
1062
9446ac58745e [gaim-migrate @ 1072]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1058
diff changeset
46 #endif
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
47 time_t idle_time;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1141
diff changeset
49 /* Not idle, really... :) */
1058
4927ce25d8cc [gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1056
diff changeset
50 update_idle_times();
4927ce25d8cc [gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1056
diff changeset
51
4927ce25d8cc [gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1056
diff changeset
52 plugin_event(event_blist_update, 0, 0, 0, 0);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1141
diff changeset
53
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
54 time(&t);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
57 #ifdef USE_SCREENSAVER
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
58 if (report_idle == IDLE_SCREENSAVER) {
1028
e4147c8604cc [gaim-migrate @ 1038]
Rob Flynn <gaim@robflynn.com>
parents: 1027
diff changeset
59 if (!d)
e4147c8604cc [gaim-migrate @ 1038]
Rob Flynn <gaim@robflynn.com>
parents: 1027
diff changeset
60 d = XOpenDisplay((char *)NULL);
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
61 if (mit_info == NULL) {
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1141
diff changeset
62 mit_info = XScreenSaverAllocInfo();
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
63 }
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1141
diff changeset
64 XScreenSaverQueryInfo(d, DefaultRootWindow(d), mit_info);
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1141
diff changeset
65 idle_time = (mit_info->idle) / 1000;
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
66 } else
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
67 #endif /* USE_SCREENSAVER */
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
68 idle_time = t - gc->lastsent;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69
1404
96e93119268d [gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1401
diff changeset
70 if ((general_options & OPT_GEN_AUTO_AWAY) && (idle_time > (60 * auto_away)) &&
1446
38f712e75836 [gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1407
diff changeset
71 (!gc->is_auto_away)) {
1407
9f356885a77a [gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1404
diff changeset
72 debug_printf("making %s away automatically\n", gc->username);
1404
96e93119268d [gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1401
diff changeset
73 set_default_away((GtkWidget*)NULL, (gpointer)g_slist_index(away_messages, default_away));
1446
38f712e75836 [gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1407
diff changeset
74 if (!gc->away) {
38f712e75836 [gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1407
diff changeset
75 if (g_slist_length(connections) == 1)
38f712e75836 [gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1407
diff changeset
76 do_away_message(NULL, default_away);
38f712e75836 [gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1407
diff changeset
77 else
38f712e75836 [gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1407
diff changeset
78 serv_set_away(gc, GAIM_AWAY_CUSTOM, default_away->message);
1468
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
79 gc->is_auto_away = 1;
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
80 } else
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
81 gc->is_auto_away = 2;
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
82 } else if (gc->is_auto_away && idle_time < 60 * auto_away) {
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
83 if (gc->is_auto_away == 2) {
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
84 gc->is_auto_away = 0;
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
85 return;
1446
38f712e75836 [gaim-migrate @ 1456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1407
diff changeset
86 }
1468
9db35684c68c [gaim-migrate @ 1478]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1450
diff changeset
87 gc->is_auto_away = 0;
1407
9f356885a77a [gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1404
diff changeset
88 if (awaymessage == NULL) {
9f356885a77a [gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1404
diff changeset
89 debug_printf("removing auto-away message for %s\n", gc->username);
1401
bf041349b11e [gaim-migrate @ 1411]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1367
diff changeset
90 serv_set_away(gc, GAIM_AWAY_CUSTOM, NULL);
1407
9f356885a77a [gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1404
diff changeset
91 } else {
1450
024f9250ba63 [gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1446
diff changeset
92 if (g_slist_length(connections) == 1)
024f9250ba63 [gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1446
diff changeset
93 do_im_back(0, 0);
024f9250ba63 [gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1446
diff changeset
94 else {
024f9250ba63 [gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1446
diff changeset
95 debug_printf("replacing auto-away with global for %s\n", gc->username);
024f9250ba63 [gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1446
diff changeset
96 serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message);
024f9250ba63 [gaim-migrate @ 1460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1446
diff changeset
97 }
1407
9f356885a77a [gaim-migrate @ 1417]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1404
diff changeset
98 }
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
99 }
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
100
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
101
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
102 /* 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
103 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
104 server */
1367
ad346597b7b2 [gaim-migrate @ 1377]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1254
diff changeset
105 if (report_idle == IDLE_NONE) {
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
106 return TRUE;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
107 }
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
108
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1141
diff changeset
109 if (idle_time > 600 && !gc->is_idle) { /* 10 minutes! */
1029
740c6f933fe0 [gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1028
diff changeset
110 debug_printf("setting %s idle %d seconds\n", gc->username, idle_time);
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
111 serv_set_idle(gc, idle_time);
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
112 gc->is_idle = 1;
1575
427e1409917c [gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1468
diff changeset
113 system_log(log_idle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON);
1250
b5783215b245 [gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1141
diff changeset
114 } else if (idle_time < 600 && gc->is_idle) {
1029
740c6f933fe0 [gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1028
diff changeset
115 debug_printf("setting %s unidle\n", gc->username);
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
116 serv_touch_idle(gc);
1575
427e1409917c [gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1468
diff changeset
117 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
118 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
120 return TRUE;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122 }