comparison plugins/autorecon.c @ 151:c754e5ae442a

[gaim-migrate @ 161] Implemented "save state" - if you were away, and you get kicked off, it signs you back on, and sets you as being away with the away message you had been using. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 23 Apr 2000 23:46:20 +0000
parents c09b48f8f7f4
children d96b511972fe
comparison
equal deleted inserted replaced
150:d4e99c17e399 151:c754e5ae442a
1 /* TODO: save state
2 * I'm not at my computer right now, so I'm not going to bother
3 * writing it, but if someone wants to before I get back (hint,
4 * hint), go for it. Here's how to do it.
5 *
6 * First, add a global "state", which is either 'away' or not.
7 *
8 * In gaim_plugin_init, set state, and add two more signal
9 * handlers: event_away and event_back, and if you can't figure
10 * out what you're supposed to do for them, you shouldn't be
11 * editing this plugin.
12 *
13 * In the reconnect function, if "state" was away, then reset
14 * the away message. You may have to remember the away message
15 * on your own; I haven't checked yet to see if there's a global
16 * that remembers it that isn't erased on signoff/signon.
17 *
18 * Anyway, that should be it.
19 */
20
21 #define GAIM_PLUGINS 1 #define GAIM_PLUGINS
22 #include "gaim.h" 2 #include "gaim.h"
23 #include <gtk/gtk.h> 3 #include <gtk/gtk.h>
24 4
5 extern GtkWidget *imaway;
6
25 static int recon; 7 static int recon;
8 static int away_state;
9 static int forced_off = 0;
10 static struct away_message *last_away;
26 11
27 char *name() { 12 char *name() {
28 return "Auto Reconnect"; 13 return "Auto Reconnect";
29 } 14 }
30 15
34 19
35 extern void dologin(GtkWidget *, GtkWidget *); 20 extern void dologin(GtkWidget *, GtkWidget *);
36 21
37 void do_signon() { 22 void do_signon() {
38 dologin(NULL, NULL); 23 dologin(NULL, NULL);
39 if (query_state() != STATE_OFFLINE) { 24 if (blist) {
40 gtk_timeout_remove(recon); 25 gtk_timeout_remove(recon);
26 forced_off = 0;
27 if (away_state)
28 do_away_message(NULL, last_away);
41 return; 29 return;
42 } 30 }
43 } 31 }
44 32
45 void reconnect(void *m) { 33 void reconnect(void *m) {
46 recon = gtk_timeout_add(2000, (GtkFunction)do_signon, NULL); 34 recon = gtk_timeout_add(2000, (GtkFunction)do_signon, NULL);
35 forced_off = 1;
36 }
37
38 void away_toggle(void *m) {
39 if ((int)m == 1) {
40 last_away = awaymessage;
41 away_state = 1;
42 } else if (!forced_off)
43 away_state = 0;
47 } 44 }
48 45
49 void gaim_plugin_init(void *handle) { 46 void gaim_plugin_init(void *handle) {
47 if (imaway) {
48 away_state = 1;
49 last_away = awaymessage;
50 } else
51 away_state = 0;
52
53 gaim_signal_connect(handle, event_away, away_toggle, (void *)1);
54 gaim_signal_connect(handle, event_back, away_toggle, (void *)0);
50 gaim_signal_connect(handle, event_signoff, reconnect, NULL); 55 gaim_signal_connect(handle, event_signoff, reconnect, NULL);
51 } 56 }