Index: libgossip/gossip-protocol.c
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/gossip-protocol.c,v
retrieving revision 1.27
diff -u -p -r1.27 gossip-protocol.c
--- libgossip/gossip-protocol.c	29 Jun 2006 14:12:55 -0000	1.27
+++ libgossip/gossip-protocol.c	19 Aug 2006 20:38:50 -0000
@@ -105,9 +105,9 @@ gossip_protocol_class_init (GossipProtoc
 			      G_SIGNAL_RUN_LAST,
 			      0,
 			      NULL, NULL,
-			      libgossip_marshal_VOID__OBJECT,
+			      libgossip_marshal_VOID__INT_OBJECT,
 			      G_TYPE_NONE, 
-			      1, GOSSIP_TYPE_ACCOUNT);
+			      2, G_TYPE_INT, GOSSIP_TYPE_ACCOUNT);
 
 	signals[NEW_MESSAGE] = 
 		g_signal_new ("new-message",
Index: libgossip/gossip-session.c
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/gossip-session.c,v
retrieving revision 1.71
diff -u -p -r1.71 gossip-session.c
--- libgossip/gossip-session.c	26 Jul 2006 13:53:15 -0000	1.71
+++ libgossip/gossip-session.c	19 Aug 2006 20:38:51 -0000
@@ -85,6 +85,7 @@ static void            session_protocol_
 								  GossipAccount        *account,
 								  GossipSession        *session);
 static void            session_protocol_logged_out               (GossipProtocol       *protocol,
+								  gint                  reason,
 								  GossipAccount        *account,
 								  GossipSession        *session);
 static void            session_protocol_new_message              (GossipProtocol       *protocol,
@@ -224,9 +225,9 @@ gossip_session_class_init (GossipSession
 			      G_SIGNAL_RUN_LAST,
 			      0,
 			      NULL, NULL,
-			      libgossip_marshal_VOID__OBJECT_OBJECT,
+			      libgossip_marshal_VOID__INT_OBJECT_OBJECT,
 			      G_TYPE_NONE, 
-			      2, GOSSIP_TYPE_ACCOUNT, GOSSIP_TYPE_PROTOCOL);
+			      3, G_TYPE_INT, GOSSIP_TYPE_ACCOUNT, GOSSIP_TYPE_PROTOCOL);
 
 	signals[PROTOCOL_DISCONNECTING] = 
 		g_signal_new ("protocol-disconnecting",
@@ -453,6 +454,7 @@ session_protocol_logged_in (GossipProtoc
 
 static void
 session_protocol_logged_out (GossipProtocol *protocol, 
+			     gint            reason,
 			     GossipAccount  *account,
 			     GossipSession  *session) 
 {
@@ -482,9 +484,9 @@ session_protocol_logged_out (GossipProto
 	if (priv->connecting_counter > 0) {
 		priv->connecting_counter--;
 	}
+	g_signal_emit (session, signals[PROTOCOL_DISCONNECTED], 0,
+		       reason, account, protocol);
 
-	g_signal_emit (session, signals[PROTOCOL_DISCONNECTED], 0, account, protocol);
-	
 	if (priv->connected_counter == 0) {
 		/* Last connected protocol was disconnected */
 		g_signal_emit (session, signals[DISCONNECTED], 0);
Index: libgossip/gossip-session.h
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/gossip-session.h,v
retrieving revision 1.30
diff -u -p -r1.30 gossip-session.h
--- libgossip/gossip-session.h	26 Jul 2006 13:53:15 -0000	1.30
+++ libgossip/gossip-session.h	19 Aug 2006 20:38:52 -0000
@@ -34,6 +34,11 @@
 #include "gossip-protocol.h"
 #include "gossip-vcard.h"
 
+typedef enum {
+	GOSSIP_DISCONNECT_ASKED,
+	GOSSIP_DISCONNECT_ERROR
+} GossipDisconnectReason;
+
 #define GOSSIP_TYPE_SESSION         (gossip_session_get_type ())
 #define GOSSIP_SESSION(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GOSSIP_TYPE_SESSION, GossipSession))
 #define GOSSIP_SESSION_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GOSSIP_TYPE_SESSION, GossipSessionClass))
Index: libgossip/libgossip-marshal.list
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/libgossip-marshal.list,v
retrieving revision 1.7
diff -u -p -r1.7 libgossip-marshal.list
--- libgossip/libgossip-marshal.list	2 Jun 2006 18:32:51 -0000	1.7
+++ libgossip/libgossip-marshal.list	19 Aug 2006 20:38:52 -0000
@@ -1,6 +1,7 @@
 VOID:VOID
 VOID:INT
 VOID:INT,OBJECT
+VOID:INT,OBJECT,OBJECT
 VOID:INT,OBJECT,STRING
 VOID:INT,STRING
 VOID:OBJECT
Index: protocols/jabber/gossip-jabber-chatrooms.c
===================================================================
RCS file: /cvs/gnome/gossip/protocols/jabber/gossip-jabber-chatrooms.c,v
retrieving revision 1.50
diff -u -p -r1.50 gossip-jabber-chatrooms.c
--- protocols/jabber/gossip-jabber-chatrooms.c	18 Jul 2006 17:15:25 -0000	1.50
+++ protocols/jabber/gossip-jabber-chatrooms.c	19 Aug 2006 20:38:53 -0000
@@ -66,6 +66,7 @@ typedef struct {
 } JabberChatroom;
 
 static void             jabber_chatrooms_logged_out_cb         (GossipProtocol         *jabber,
+								gint                    reason,
 								GossipAccount          *account,
 								GossipJabberChatrooms  *chatrooms);
 static JabberChatroom * jabber_chatrooms_chatroom_new          (GossipJabberChatrooms  *chatrooms,
@@ -174,6 +175,7 @@ gossip_jabber_chatrooms_finalize (Gossip
 
 static void
 jabber_chatrooms_logged_out_cb (GossipProtocol        *jabber,
+				gint                   reason,
 				GossipAccount         *account,
 				GossipJabberChatrooms *chatrooms)
 {
Index: protocols/jabber/gossip-jabber.c
===================================================================
RCS file: /cvs/gnome/gossip/protocols/jabber/gossip-jabber.c,v
retrieving revision 1.101
diff -u -p -r1.101 gossip-jabber.c
--- protocols/jabber/gossip-jabber.c	26 Jul 2006 13:53:16 -0000	1.101
+++ protocols/jabber/gossip-jabber.c	19 Aug 2006 20:38:56 -0000
@@ -30,6 +30,7 @@
 #include <libgossip/gossip-vcard.h>
 #include <libgossip/gossip-chatroom-provider.h>
 #include <libgossip/gossip-ft-provider.h>
+#include <libgossip/gossip-session.h>
 
 #include "gossip-jid.h"
 #include "gossip-jabber-chatrooms.h"
@@ -732,6 +733,7 @@ jabber_connection_open_cb (LmConnection 
 	const gchar      *jid_str;
 	gchar            *id;
 	const gchar      *resource;
+	gchar            *resource_rand;
 	gchar            *password = NULL;
 	
 	priv = GET_PRIV (jabber);
@@ -793,13 +795,17 @@ jabber_connection_open_cb (LmConnection 
 		return;
 	}
 
+	/* TODO: tweak this */
+	resource_rand = g_strdup_printf ("%s.%c", resource, g_random_int());
+
 	lm_connection_authenticate (priv->connection,
 				    id,
 				    password, 
-				    resource,
+				    resource_rand,
 				    (LmResultFunction) jabber_connection_auth_cb,
 				    jabber, NULL, NULL);
 
+	g_free (resource_rand);
 	g_free (id);
 	g_free (password);
 }
@@ -880,7 +886,8 @@ jabber_disconnect_cb (LmConnection      
 		      LmDisconnectReason  reason,
 		      GossipJabber       *jabber)
 {
-	GossipJabberPriv *priv;
+	GossipJabberPriv       *priv;
+	GossipDisconnectReason  gossip_reason;
 
 	priv = GET_PRIV (jabber);
 
@@ -895,8 +902,21 @@ jabber_disconnect_cb (LmConnection      
 					     (GHRFunc) jabber_logout_contact_foreach,
 					     jabber);
 	}
-
-	g_signal_emit_by_name (jabber, "logged-out", priv->account);
+	
+	switch (reason) {
+	case LM_DISCONNECT_REASON_OK:
+		gossip_reason = GOSSIP_DISCONNECT_ASKED;
+		break;
+	case LM_DISCONNECT_REASON_PING_TIME_OUT:
+	case LM_DISCONNECT_REASON_HUP:
+	case LM_DISCONNECT_REASON_ERROR:
+	case LM_DISCONNECT_REASON_UNKNOWN:
+		gossip_reason = GOSSIP_DISCONNECT_ERROR;
+		break;
+	default:
+		g_assert_not_reached();
+	}
+	g_signal_emit_by_name (jabber, "logged-out", gossip_reason, priv->account);
 }
 
 static LmSSLResponse 
Index: src/gossip-account-button.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-account-button.c,v
retrieving revision 1.24
diff -u -p -r1.24 gossip-account-button.c
--- src/gossip-account-button.c	5 Jul 2006 21:58:10 -0000	1.24
+++ src/gossip-account-button.c	19 Aug 2006 20:38:57 -0000
@@ -87,6 +87,7 @@ static void       account_button_protoco
 							    GossipProtocol      *protocol,
 							    GossipAccountButton *account_button);
 static void       account_button_protocol_disconnected_cb  (GossipSession       *session,
+							    gint                 reason,
 							    GossipAccount       *account,
 							    GossipProtocol      *protocol,
 							    GossipAccountButton *account_button);
@@ -581,6 +582,7 @@ account_button_protocol_connected_cb (Go
 
 static void
 account_button_protocol_disconnected_cb (GossipSession       *session,
+					 gint                 reason,
 					 GossipAccount       *account,
 					 GossipProtocol      *protocol,
 					 GossipAccountButton *account_button)
Index: src/gossip-account-chooser.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-account-chooser.c,v
retrieving revision 1.6
diff -u -p -r1.6 gossip-account-chooser.c
--- src/gossip-account-chooser.c	25 Mar 2006 20:41:40 -0000	1.6
+++ src/gossip-account-chooser.c	19 Aug 2006 20:38:58 -0000
@@ -81,6 +81,7 @@ static void     account_chooser_protocol
 							  GossipProtocol        *protocol,
 							  GossipAccountChooser  *account_chooser);
 static void     account_chooser_protocol_disconnected_cb (GossipSession         *session,
+							  gint                   reason,
 							  GossipAccount         *account,
 							  GossipProtocol        *protocol,
 							  GossipAccountChooser  *account_chooser);
@@ -404,6 +405,7 @@ account_chooser_protocol_connected_cb (G
 
 static void
 account_chooser_protocol_disconnected_cb (GossipSession        *session,
+					  gint                  reason,
 					  GossipAccount        *account,
 					  GossipProtocol       *protocol,
 					  GossipAccountChooser *account_chooser)
Index: src/gossip-accounts-dialog.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-accounts-dialog.c,v
retrieving revision 1.40
diff -u -p -r1.40 gossip-accounts-dialog.c
--- src/gossip-accounts-dialog.c	26 Jul 2006 13:39:22 -0000	1.40
+++ src/gossip-accounts-dialog.c	19 Aug 2006 20:38:59 -0000
@@ -121,6 +121,7 @@ static void           accounts_dialog_pr
 								 GossipProtocol        *protocol,
 								 GossipAccountsDialog  *dialog);
 static void           accounts_dialog_protocol_disconnected_cb  (GossipSession         *session,
+								 gint                   reason,
 								 GossipAccount         *account,
 								 GossipProtocol        *protocol,
 								 GossipAccountsDialog  *dialog);
@@ -1201,6 +1202,7 @@ accounts_dialog_protocol_connected_cb (G
 
 static void
 accounts_dialog_protocol_disconnected_cb (GossipSession        *session,
+					  gint                  reason,
 					  GossipAccount        *account,
 					  GossipProtocol       *protocol,
 					  GossipAccountsDialog *dialog)
Index: src/gossip-app.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-app.c,v
retrieving revision 1.278
diff -u -p -r1.278 gossip-app.c
--- src/gossip-app.c	18 Aug 2006 22:19:33 -0000	1.278
+++ src/gossip-app.c	19 Aug 2006 20:39:02 -0000
@@ -117,6 +117,9 @@
 /* Accels (menu shortcuts) can be configured and saved */
 #define ACCELS_FILENAME "accels.txt"
 
+/* Delay for retry to connect when disconnected (seconds) */
+#define RETRY_CONNECT_TIMEOUT 10
+
 struct _GossipAppPriv {
 	GossipSession         *session;
 
@@ -175,6 +178,7 @@ struct _GossipAppPriv {
 	
 	/* Misc */
 	guint                  size_timeout_id;
+	guint                  retry_connect_id;
 };
 
 static void            gossip_app_class_init                (GossipAppClass           *klass);
@@ -239,7 +243,9 @@ static void            app_session_proto
 							     GossipAccount            *account,
 							     GossipProtocol           *protocol,
 							     gpointer                  user_data);
+static gboolean        app_retry_connect_cb                 (gpointer data);
 static void            app_session_protocol_disconnected_cb (GossipSession            *session,
+							     gint                      reason,
 							     GossipAccount            *account,
 							     GossipProtocol           *protocol,
 							     gpointer                  user_data);
@@ -372,6 +378,10 @@ app_finalize (GObject *object)
 		g_source_remove (priv->size_timeout_id);
 	}
 
+	if (priv->retry_connect_id) {
+		g_source_remove (priv->retry_connect_id);
+	}
+
 	if (priv->tray_flash_timeout_id) {
 		g_source_remove (priv->tray_flash_timeout_id);
 	}
@@ -984,7 +994,7 @@ app_main_window_key_press_event_cb (GtkW
 
 static void 
 app_actions_quit_cb (GtkWidget *window,
-	     GossipApp *app)
+		     GossipApp *app)
 {
 	GossipAppPriv *priv;
 	
@@ -1267,16 +1277,30 @@ app_session_protocol_connected_cb (Gossi
 				 gossip_status_presets_get_default_status());
 
 	app_presence_updated ();
+	
+	if (priv->retry_connect_id) {
+		g_source_remove (priv->retry_connect_id);
+		priv->retry_connect_id = 0;
+	}
+}
+
+static gboolean
+app_retry_connect_cb (gpointer data)
+{
+	gossip_app_connect (NULL, TRUE);
+	return TRUE;
 }
 
 static void
 app_session_protocol_disconnected_cb (GossipSession  *session,
+				      gint            reason,
 				      GossipAccount  *account,
 				      GossipProtocol *protocol,
 				      gpointer        user_data)
 {
 	GossipAppPriv *priv;
 	gboolean       connecting;
+	gboolean       nm_connected = FALSE;
 
 	priv = GET_PRIV (app);
 
@@ -1295,6 +1319,16 @@ app_session_protocol_disconnected_cb (Go
  	app_connection_items_update ();
 	app_chatroom_favourite_update ();
 	app_presence_updated ();
+	
+#ifdef HAVE_DBUS
+	nm_connected = (gossip_dbus_nm_get_state (&nm_connected) && !nm_connected);
+#endif
+	if (reason != GOSSIP_DISCONNECT_ASKED && !nm_connected) {
+		/* unexpected disconnection, try to reconnect */
+		priv->retry_connect_id = g_timeout_add (RETRY_CONNECT_TIMEOUT * 1000,
+							app_retry_connect_cb,
+							NULL);
+	}
 }
 
 static void
Index: src/gossip-ft-window.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-ft-window.c,v
retrieving revision 1.13
diff -u -p -r1.13 gossip-ft-window.c
--- src/gossip-ft-window.c	27 Jul 2006 08:20:50 -0000	1.13
+++ src/gossip-ft-window.c	19 Aug 2006 20:39:03 -0000
@@ -52,6 +52,7 @@ static void ft_window_protocol_connected
 						GossipProtocol     *protocol,
 						gpointer            user_data);
 static void ft_window_protocol_disconnected_cb (GossipSession      *session,
+						gint                reason,
 						GossipAccount      *account,
 						GossipProtocol     *protocol,
 						gpointer            user_data);
@@ -128,6 +129,7 @@ ft_window_protocol_connected_cb (GossipS
 
 static void
 ft_window_protocol_disconnected_cb (GossipSession  *session,
+				    gint            reason,
 				    GossipAccount  *account,
 				    GossipProtocol *protocol,
 				    gpointer        user_data)
Index: src/gossip-group-chat.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-group-chat.c,v
retrieving revision 1.76
diff -u -p -r1.76 gossip-group-chat.c
--- src/gossip-group-chat.c	16 Aug 2006 15:26:53 -0000	1.76
+++ src/gossip-group-chat.c	19 Aug 2006 20:39:05 -0000
@@ -95,6 +95,7 @@ static void            group_chat_protoc
 							       GossipProtocol               *protocol,
 							       GossipGroupChat              *chat);
 static void            group_chat_protocol_disconnected_cb    (GossipSession                *session,
+							       gint                          reason,
 							       GossipAccount                *account,
 							       GossipProtocol               *protocol,
 							       GossipGroupChat              *chat);
@@ -360,6 +361,7 @@ group_chat_protocol_connected_cb (Gossip
 
 static void
 group_chat_protocol_disconnected_cb (GossipSession   *session,
+				     gint             reason,
 				     GossipAccount   *account,
 				     GossipProtocol  *protocol,
 				     GossipGroupChat *chat)
Index: src/gossip-notify.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-notify.c,v
retrieving revision 1.35
diff -u -p -r1.35 gossip-notify.c
--- src/gossip-notify.c	18 Aug 2006 21:49:12 -0000	1.35
+++ src/gossip-notify.c	19 Aug 2006 20:39:05 -0000
@@ -63,6 +63,7 @@ static void                notify_protoc
 							       GossipProtocol     *protocol,
 							       gpointer            user_data);
 static void                notify_protocol_disconnected_cb    (GossipSession      *session,
+							       gint                reason,
 							       GossipAccount      *account,
 							       GossipProtocol     *protocol,
 							       gpointer            user_data);
@@ -427,6 +428,7 @@ notify_disconnected_contact_foreach (Gos
 
 static void
 notify_protocol_disconnected_cb (GossipSession  *session,
+				 gint            reason,
 				 GossipAccount  *account,
 				 GossipProtocol *protocol,
 				 gpointer        user_data)
Index: src/gossip-private-chat.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-private-chat.c,v
retrieving revision 1.56
diff -u -p -r1.56 gossip-private-chat.c
--- src/gossip-private-chat.c	29 Jul 2006 12:15:59 -0000	1.56
+++ src/gossip-private-chat.c	19 Aug 2006 20:39:06 -0000
@@ -92,6 +92,7 @@ static void           private_chat_proto
 								 GossipProtocol         *protocol,
 								 GossipPrivateChat      *chat);
 static void           private_chat_protocol_disconnected_cb     (GossipSession          *session,
+								 gint                    reason,
 								 GossipAccount          *account,
 								 GossipProtocol         *protocol,
 								 GossipPrivateChat      *chat);
@@ -543,6 +544,7 @@ private_chat_protocol_connected_cb (Goss
 
 static void
 private_chat_protocol_disconnected_cb (GossipSession     *session,
+				       gint               reason,
 				       GossipAccount     *account,
 				       GossipProtocol    *protocol,
 				       GossipPrivateChat *chat)
Index: src/gossip-sound.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-sound.c,v
retrieving revision 1.26
diff -u -p -r1.26 gossip-sound.c
--- src/gossip-sound.c	21 Jul 2006 22:40:30 -0000	1.26
+++ src/gossip-sound.c	19 Aug 2006 20:39:07 -0000
@@ -95,6 +95,7 @@ sound_disconnected_contact_foreach (Goss
 
 static void
 sound_protocol_disconnected_cb (GossipSession  *session,
+				gint            reason,
 				GossipAccount  *account,
 				GossipProtocol *protocol,
 				gpointer        user_data)
Index: src/gossip-subscription-dialog.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-subscription-dialog.c,v
retrieving revision 1.15
diff -u -p -r1.15 gossip-subscription-dialog.c
--- src/gossip-subscription-dialog.c	3 Aug 2006 16:46:37 -0000	1.15
+++ src/gossip-subscription-dialog.c	19 Aug 2006 20:39:07 -0000
@@ -58,6 +58,7 @@ static void subscription_dialog_protocol
 							  GossipProtocol     *protocol, 
 							  gpointer            user_data);
 static void subscription_dialog_protocol_disconnected_cb (GossipSession      *session,
+							  gint                reason,
 							  GossipAccount      *account,
 							  GossipProtocol     *protocol,
 							  gpointer            user_data);
@@ -118,6 +119,7 @@ subscription_dialog_protocol_connected_c
 
 static void
 subscription_dialog_protocol_disconnected_cb (GossipSession  *session,
+					      gint            reason,
 					      GossipAccount  *account,
 					      GossipProtocol *protocol,
 					      gpointer        user_data)
