Mercurial > pidgin.yaz
annotate plugins/autorecon.c @ 1595:f281f4d94973
[gaim-migrate @ 1605]
implement ctl-tab/[/]
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 16 Mar 2001 20:58:55 +0000 |
parents | 96e93119268d |
children | b367beee6448 |
rev | line source |
---|---|
99 | 1 #define GAIM_PLUGINS |
2 #include "gaim.h" | |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
3 #include "prpl.h" |
99 | 4 #include <gtk/gtk.h> |
5 | |
151
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
6 extern GtkWidget *imaway; |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
7 |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
8 static int away_state; |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
9 static int forced_off = 0; |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
10 static char *last_away = NULL; |
1378
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
11 GSList *reconnects = NULL; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
12 GSList *recontim = NULL; |
99 | 13 |
14 char *name() { | |
15 return "Auto Reconnect"; | |
16 } | |
17 | |
18 char *description() { | |
19 return "When AOL kicks you off, this auto-reconnects you."; | |
20 } | |
21 | |
1378
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
22 static void now_online(struct gaim_connection *gc, void *m) { |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
23 gint place; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
24 guint recon; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
25 if (!g_slist_find(reconnects, gc->user)) |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
26 return; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
27 place = g_slist_index(reconnects, gc->user); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
28 recon = (guint)g_slist_nth(recontim, place); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
29 reconnects = g_slist_remove(reconnects, gc->user); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
30 recontim = g_slist_remove(recontim, (void *)recon); |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
31 if (away_state) serv_set_away(gc, GAIM_AWAY_CUSTOM, last_away); |
99 | 32 } |
33 | |
1378
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
34 static void do_signon(struct aim_user *u) { |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
35 gint place; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
36 guint recon; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
37 place = g_slist_index(reconnects, u); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
38 recon = (guint)g_slist_nth(recontim, place); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
39 gtk_timeout_remove(recon); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
40 forced_off = 0; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
41 serv_login(u); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
42 } |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
43 |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
44 static void reconnect(struct gaim_connection *gc, void *m) { |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
45 guint recon; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
46 if (g_slist_find(reconnects, gc->user)) |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
47 return; |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
48 recon = gtk_timeout_add(8000, (GtkFunction)do_signon, gc->user); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
49 reconnects = g_slist_append(reconnects, gc->user); |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
50 recontim = g_slist_append(recontim, (void *)recon); |
151
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
51 forced_off = 1; |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
52 } |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
53 |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
54 static void away_toggle(struct gaim_connection *gc, char *state, char *message, gpointer data) { |
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
55 if (gc->away) { |
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
56 if (last_away) |
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
57 g_free(last_away); |
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
58 last_away = g_strdup(gc->away); |
151
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
59 away_state = 1; |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
60 } else if (!forced_off) |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
61 away_state = 0; |
99 | 62 } |
63 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1030
diff
changeset
|
64 char *gaim_plugin_init(GModule *handle) { |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
65 if (awaymessage) { |
151
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
66 away_state = 1; |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
67 last_away = g_strdup(awaymessage->message); |
151
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
68 } else |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
69 away_state = 0; |
c754e5ae442a
[gaim-migrate @ 161]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
148
diff
changeset
|
70 |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
71 gaim_signal_connect(handle, event_away, away_toggle, NULL); |
99 | 72 gaim_signal_connect(handle, event_signoff, reconnect, NULL); |
1378
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
73 gaim_signal_connect(handle, event_signon, now_online, NULL); |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1030
diff
changeset
|
74 |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1030
diff
changeset
|
75 return NULL; |
99 | 76 } |
1404
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
77 |
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
78 void gaim_plugin_remove() { |
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
79 g_free(last_away); |
96e93119268d
[gaim-migrate @ 1414]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1378
diff
changeset
|
80 } |