annotate src/idle.c @ 1145:cd96ca1aed02

[gaim-migrate @ 1155] actually to be quite honest toc has been blocking me so i have no way of knowing that the permit/deny stuff that i'm committing actually works. but i'm sure i'll get a bug report in about 3 hours or so if it's not. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 27 Nov 2000 13:18:11 +0000
parents 8f4ce8b74901
children b5783215b245
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"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
39 int auto_is_away = 0;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
40
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
41
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
42 gint check_idle(struct gaim_connection *gc)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 {
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
44 time_t t;
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
45 #ifdef USE_SCREENSAVER
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
46 static XScreenSaverInfo *mit_info = NULL;
1028
e4147c8604cc [gaim-migrate @ 1038]
Rob Flynn <gaim@robflynn.com>
parents: 1027
diff changeset
47 static Display *d = NULL;
1062
9446ac58745e [gaim-migrate @ 1072]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1058
diff changeset
48 #endif
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
49 time_t idle_time;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
51 /* Not idle, really... :) */
1058
4927ce25d8cc [gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1056
diff changeset
52 update_idle_times();
4927ce25d8cc [gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1056
diff changeset
53
4927ce25d8cc [gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1056
diff changeset
54 plugin_event(event_blist_update, 0, 0, 0, 0);
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
55
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
56 time(&t);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
59 #ifdef USE_SCREENSAVER
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
60 if (report_idle == IDLE_SCREENSAVER) {
1028
e4147c8604cc [gaim-migrate @ 1038]
Rob Flynn <gaim@robflynn.com>
parents: 1027
diff changeset
61 if (!d)
e4147c8604cc [gaim-migrate @ 1038]
Rob Flynn <gaim@robflynn.com>
parents: 1027
diff changeset
62 d = XOpenDisplay((char *)NULL);
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
63 if (mit_info == NULL) {
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
64 mit_info = XScreenSaverAllocInfo ();
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
65 }
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
66 XScreenSaverQueryInfo (d, DefaultRootWindow(d), mit_info);
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
67 idle_time = (mit_info->idle)/1000;
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
68 } else
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
69 #endif /* USE_SCREENSAVER */
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
70 idle_time = t - gc->lastsent;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
72 if ((general_options & OPT_GEN_AUTO_AWAY) &&
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
73 (idle_time > (60 * auto_away)) &&
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
74 (awaymessage == NULL) &&
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
75 (auto_is_away == 0)) {
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
76 struct away_message *a;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
77 set_default_away((GtkWidget*)NULL, (gpointer)default_away);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
78 a = g_slist_nth_data(away_messages, default_away);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
79 do_away_message((GtkWidget*)NULL, a);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
80 auto_is_away = 1;
1141
8f4ce8b74901 [gaim-migrate @ 1151]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
81 } else if (auto_is_away == 1 && idle_time < 60*auto_away) {
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
82 auto_is_away = 0;
1141
8f4ce8b74901 [gaim-migrate @ 1151]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
83 if (awaymessage != NULL)
8f4ce8b74901 [gaim-migrate @ 1151]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
84 do_im_back((GtkWidget*)NULL, (GtkWidget*)NULL);
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
85 }
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
86
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
87
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
88 /* 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
89 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
90 server */
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
91 if (report_idle == 0) {
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
92 return TRUE;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
93 }
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1062
diff changeset
94
1029
740c6f933fe0 [gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1028
diff changeset
95 if (idle_time > 600 && !gc->is_idle) { /* 10 minutes! */
740c6f933fe0 [gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1028
diff changeset
96 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
97 serv_set_idle(gc, idle_time);
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
98 gc->is_idle = 1;
1029
740c6f933fe0 [gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1028
diff changeset
99 } else if (idle_time < 600 && gc->is_idle) {
740c6f933fe0 [gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1028
diff changeset
100 debug_printf("setting %s unidle\n", gc->username);
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
101 serv_touch_idle(gc);
1029
740c6f933fe0 [gaim-migrate @ 1039]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1028
diff changeset
102 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103
1026
5bad25457843 [gaim-migrate @ 1036]
Rob Flynn <gaim@robflynn.com>
parents: 1
diff changeset
104 return TRUE;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 }