| 1 #define GAIM_PLUGINS |
1 #define GAIM_PLUGINS |
| 2 #include "gaim.h" |
2 #include "gaim.h" |
| 3 #include "prpl.h" |
3 #include "prpl.h" |
| 4 #include <gtk/gtk.h> |
4 #include <gtk/gtk.h> |
| 5 |
|
| 6 extern GtkWidget *imaway; |
|
| 7 |
|
| 8 static int away_state; |
|
| 9 static int forced_off = 0; |
|
| 10 static char *last_away = NULL; |
|
| 11 GSList *reconnects = NULL; |
|
| 12 GSList *recontim = NULL; |
|
| 13 |
5 |
| 14 char *name() { |
6 char *name() { |
| 15 return "Auto Reconnect"; |
7 return "Auto Reconnect"; |
| 16 } |
8 } |
| 17 |
9 |
| 18 char *description() { |
10 char *description() { |
| 19 return "When AOL kicks you off, this auto-reconnects you."; |
11 return "When you are kicked offline, this reconnects you."; |
| 20 } |
12 } |
| 21 |
13 |
| 22 static void now_online(struct gaim_connection *gc, void *m) { |
14 static gboolean do_signon(struct aim_user *u) { |
| 23 gint place; |
15 if (!g_list_index(aim_users, u)) |
| 24 guint recon; |
16 return FALSE; |
| 25 if (!g_slist_find(reconnects, gc->user)) |
|
| 26 return; |
|
| 27 place = g_slist_index(reconnects, gc->user); |
|
| 28 recon = (guint)g_slist_nth(recontim, place); |
|
| 29 reconnects = g_slist_remove(reconnects, gc->user); |
|
| 30 recontim = g_slist_remove(recontim, (void *)recon); |
|
| 31 if (away_state) serv_set_away(gc, GAIM_AWAY_CUSTOM, last_away); |
|
| 32 } |
|
| 33 |
|
| 34 static void do_signon(struct aim_user *u) { |
|
| 35 gint place; |
|
| 36 guint recon; |
|
| 37 place = g_slist_index(reconnects, u); |
|
| 38 recon = (guint)g_slist_nth(recontim, place); |
|
| 39 gtk_timeout_remove(recon); |
|
| 40 forced_off = 0; |
|
| 41 serv_login(u); |
17 serv_login(u); |
| |
18 return FALSE; |
| 42 } |
19 } |
| 43 |
20 |
| 44 static void reconnect(struct gaim_connection *gc, void *m) { |
21 static void reconnect(struct gaim_connection *gc, void *m) { |
| 45 guint recon; |
22 if (gc->wants_to_die) |
| 46 if (g_slist_find(reconnects, gc->user)) |
23 gtk_timeout_add(8000, (GtkFunction)do_signon, gc->user); |
| 47 return; |
|
| 48 recon = gtk_timeout_add(8000, (GtkFunction)do_signon, gc->user); |
|
| 49 reconnects = g_slist_append(reconnects, gc->user); |
|
| 50 recontim = g_slist_append(recontim, (void *)recon); |
|
| 51 forced_off = 1; |
|
| 52 } |
|
| 53 |
|
| 54 static void away_toggle(struct gaim_connection *gc, char *state, char *message, gpointer data) { |
|
| 55 if (gc->away) { |
|
| 56 if (last_away) |
|
| 57 g_free(last_away); |
|
| 58 last_away = g_strdup(gc->away); |
|
| 59 away_state = 1; |
|
| 60 } else if (!forced_off) |
|
| 61 away_state = 0; |
|
| 62 } |
24 } |
| 63 |
25 |
| 64 char *gaim_plugin_init(GModule *handle) { |
26 char *gaim_plugin_init(GModule *handle) { |
| 65 if (awaymessage) { |
|
| 66 away_state = 1; |
|
| 67 last_away = g_strdup(awaymessage->message); |
|
| 68 } else |
|
| 69 away_state = 0; |
|
| 70 |
|
| 71 gaim_signal_connect(handle, event_away, away_toggle, NULL); |
|
| 72 gaim_signal_connect(handle, event_signoff, reconnect, NULL); |
27 gaim_signal_connect(handle, event_signoff, reconnect, NULL); |
| 73 gaim_signal_connect(handle, event_signon, now_online, NULL); |
|
| 74 |
28 |
| 75 return NULL; |
29 return NULL; |
| 76 } |
30 } |
| 77 |
|
| 78 void gaim_plugin_remove() { |
|
| 79 g_free(last_away); |
|
| 80 } |
|