changeset 9546:ebbe4390f75b

[gaim-migrate @ 10375] " Added the ability to remember your away message if you're disconnected and then reconnected." --Yosef Radchenko Date: 2004-07-14 22:02 Sender: lschiere Logged In: YES user_id=28833 has this been tested with multiple accounts? Date: 2004-07-14 22:49 Sender: jonrad Logged In: YES user_id=1083867 If you asking whether this was tested with multiple accounts logged in at the same time, then yes. If you're asking whether this was tested on multiple protocols, then no. I've tested it on oscar. Also, I compiled it on my FreeBSD machine and didn't get a chance to compile on any other OSes, but conceptually it should work fine on others (But of course, when dealing with computers, nothing works as it is meant to). Date: 2004-07-14 22:54 Sender: jonrad Logged In: YES user_id=1083867 Also, if you comment out lines 119 and 120: if (gc->want_to_die) g_hash_table_remove(awayStates, aaccount); Then it keeps the away information even if you purposesly disconnected (As opposed to now, which only restores your away state if you were kicked off the network or whatever) Thats helpful if you want to test it. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 16 Jul 2004 13:50:20 +0000
parents 2157c9af1330
children 095f7d66c7f1
files ChangeLog plugins/autorecon.c
diffstat 2 files changed, 70 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jul 16 12:20:20 2004 +0000
+++ b/ChangeLog	Fri Jul 16 13:50:20 2004 +0000
@@ -1,5 +1,10 @@
 Gaim: The Pimpin' Penguin IM Client that's good for the soul!
 
+version 0.81cvs:
+	New Features:
+	* The autorecon plugin will somewhat remember state information(Yosef
+	  Radchenko)
+
 version 0.80 (07/15/2004):
 	New Features:
 	* Ability to send files from the conversation window (Daniel Atallah)
--- a/plugins/autorecon.c	Fri Jul 16 12:20:20 2004 +0000
+++ b/plugins/autorecon.c	Fri Jul 16 13:50:20 2004 +0000
@@ -12,18 +12,29 @@
 #define INITIAL 8000
 #define MAXTIME 2048000
 
-
 typedef struct {
 	int delay;
 	guint timeout;
 } GaimAutoRecon;
 
+/*
+   I use a struct here, but the visible/invisible isn't yet supported
+   in this plugin, so this is more for future implementation of those 
+   features 
+*/
+typedef struct {
+	const char *state;
+	const char *message;
+} GaimAwayState;
+
 static GHashTable *hash = NULL;
+static GHashTable *awayStates = NULL;
 
 
 #define AUTORECON_OPT  "/plugins/core/autorecon"
 #define OPT_HIDE_CONNECTED   AUTORECON_OPT "/hide_connected_error"
 #define OPT_HIDE_CONNECTING  AUTORECON_OPT "/hide_connecting_error"
+#define OPT_RESTORE_STATE    AUTORECON_OPT "/restore_state"
 
 
 /* storage of original (old_ops) and modified (new_ops) ui ops to allow us to
@@ -104,8 +115,38 @@
 	} else if (info != NULL) {
 		g_hash_table_remove(hash, account);
 	}
+
+	if (gc->wants_to_die) 
+		g_hash_table_remove(awayStates, account);
 }
 
+static void save_state(GaimAccount *account, const char *state, const char *message) {
+	//Saves whether the account is back/away/visible/invisible
+
+        GaimAwayState *info;
+
+	if (!strcmp(state,GAIM_AWAY_CUSTOM)) {
+        	info = g_new0(GaimAwayState, 1);
+        	info->state = state;
+        	info->message = message;
+
+        	g_hash_table_insert(awayStates, account, info);
+	} else if(!strcmp(state,"Back")) 
+		g_hash_table_remove(awayStates, account);
+}
+
+static void restore_state(GaimConnection *gc, void *m) {
+	//Restore the state to what it was before the disconnect
+        GaimAwayState *info;
+        GaimAccount *account;
+
+        g_return_if_fail(gc != NULL && gaim_prefs_get_bool(OPT_RESTORE_STATE));
+        account = gaim_connection_get_account(gc);
+
+        info = g_hash_table_lookup(awayStates, account);
+        if (info)
+                serv_set_away(gc, info->state, info->message);
+}
 
 static void
 free_auto_recon(gpointer data)
@@ -143,9 +184,18 @@
 	hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
 			free_auto_recon);
 
+	awayStates = g_hash_table_new(g_int_hash, g_int_equal);
+
 	gaim_signal_connect(gaim_connections_get_handle(), "signed-off",
 			plugin, GAIM_CALLBACK(reconnect), NULL);
 
+	gaim_signal_connect(gaim_connections_get_handle(), "signed-on",
+			plugin, GAIM_CALLBACK(restore_state), NULL);
+
+	gaim_signal_connect(gaim_accounts_get_handle(), "account-away",
+			plugin, GAIM_CALLBACK(save_state), NULL);
+
+
 	return TRUE;
 }
 
@@ -155,10 +205,19 @@
 {
 	gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off",
 			plugin, GAIM_CALLBACK(reconnect));
+
+	gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on",
+			plugin, GAIM_CALLBACK(restore_state));
+	
+	gaim_signal_disconnect(gaim_accounts_get_handle(), "account-away",
+			plugin, GAIM_CALLBACK(save_state));
 	
 	g_hash_table_destroy(hash);
 	hash = NULL;
 
+	g_hash_table_destroy(awayStates);
+	awayStates = NULL;
+
 	gaim_connections_set_ui_ops(old_ops);
 	g_free(new_ops);
 	old_ops = new_ops = NULL;
@@ -182,6 +241,10 @@
 		_("Hide Login Errors"));
 	gaim_plugin_pref_frame_add(frame, pref);
 
+	pref = gaim_plugin_pref_new_with_name_and_label(OPT_RESTORE_STATE,
+		_("Restore Away State On Reconnent"));
+	gaim_plugin_pref_frame_add(frame, pref);
+
 	return frame;
 }
 
@@ -227,6 +290,7 @@
 	gaim_prefs_add_none(AUTORECON_OPT);
 	gaim_prefs_add_bool(OPT_HIDE_CONNECTED, FALSE);
 	gaim_prefs_add_bool(OPT_HIDE_CONNECTING, FALSE);
+	gaim_prefs_add_bool(OPT_RESTORE_STATE, TRUE);
 }
 
 GAIM_INIT_PLUGIN(autorecon, init_plugin, info)