# HG changeset patch
# Node ID 8d25f8d8ece8d99b7a87bd7b47e51dff70806f70
# Parent  0b6c779d054d035209be3c0489de1f7b8d86226b
diff --git a/protocols/bonjour/purplebonjourconnection.c b/protocols/bonjour/purplebonjourconnection.c
--- a/protocols/bonjour/purplebonjourconnection.c
+++ b/protocols/bonjour/purplebonjourconnection.c
@@ -46,9 +46,6 @@
 	g_return_val_if_fail(PURPLE_BONJOUR_IS_CONNECTION(purple_connection),
 	                     FALSE);
 
-	purple_connection_set_state(purple_connection,
-	                            PURPLE_CONNECTION_STATE_CONNECTING);
-
 	connection = PURPLE_BONJOUR_CONNECTION(purple_connection);
 	cancellable = purple_connection_get_cancellable(purple_connection);
 	account = purple_connection_get_account(purple_connection);
@@ -60,8 +57,7 @@
 
 	/* Eventually, we will do something before this, but we can go straight to
 	 * connected for now. */
-	purple_connection_set_state(purple_connection,
-	                            PURPLE_CONNECTION_STATE_CONNECTED);
+	purple_account_connected(account);
 
 	return TRUE;
 }
diff --git a/protocols/demo/purpledemoconnection.c b/protocols/demo/purpledemoconnection.c
--- a/protocols/demo/purpledemoconnection.c
+++ b/protocols/demo/purpledemoconnection.c
@@ -44,7 +44,7 @@
 	purple_contact_info_set_id(info, username);
 	purple_contact_info_set_username(info, username);
 
-	purple_connection_set_state(connection, PURPLE_CONNECTION_STATE_CONNECTED);
+	purple_account_connected(account);
 
 	purple_demo_contacts_load(account);
 
diff --git a/protocols/ircv3/purpleircv3connection.c b/protocols/ircv3/purpleircv3connection.c
--- a/protocols/ircv3/purpleircv3connection.c
+++ b/protocols/ircv3/purpleircv3connection.c
@@ -539,17 +539,13 @@
                                    gpointer data)
 {
 	PurpleConnection *connection = data;
-	PurpleConnectionState state = PURPLE_CONNECTION_STATE_DISCONNECTED;
 	IbisClient *client = IBIS_CLIENT(source);
 
-	/* We don't consider the account connected until registration has finished,
-	 * but we are for sure connecting when the ibis client is connected.
-	 */
-	if(ibis_client_get_connected(client)) {
-		state = PURPLE_CONNECTION_STATE_CONNECTING;
+	if(!ibis_client_get_connected(client)) {
+		PurpleAccount *account = purple_connection_get_account(connection);
+
+		purple_account_disconnect(account);
 	}
-
-	purple_connection_set_state(connection, state);
 }
 
 static void
@@ -565,8 +561,7 @@
 
 		account = purple_connection_get_account(connection);
 		if(!purple_account_is_connected(account)) {
-			purple_connection_set_state(connection,
-			                            PURPLE_CONNECTION_STATE_CONNECTED);
+			purple_account_connected(account);
 		}
 
 		/* Once reconnected, we need to rejoin any channels that the
diff --git a/protocols/xmpp/purplexmppconnection.c b/protocols/xmpp/purplexmppconnection.c
--- a/protocols/xmpp/purplexmppconnection.c
+++ b/protocols/xmpp/purplexmppconnection.c
@@ -42,26 +42,25 @@
 purple_xmpp_connection_connect_cb(GObject *source, GAsyncResult *result,
                                   gpointer data)
 {
-	PurpleXmppConnection *connection = data;
+	PurpleXmppConnection *xmpp_connection = data;
+	PurpleAccount *account = NULL;
+	PurpleConnection *connection = data;
 	XemeOutputStream *output = NULL;
 	GError *error = NULL;
 
 	output = xeme_connection_connect_finish(XEME_CONNECTION(source), result,
 	                                        &error);
+
+	account = purple_connection_get_account(connection);
 	if(error != NULL) {
-		PurpleAccount *account = NULL;
-
-		account = purple_connection_get_account(PURPLE_CONNECTION(connection));
-
 		purple_account_disconnect_with_error(account, error);
 
 		return;
 	}
 
-	connection->output = output;
+	xmpp_connection->output = output;
 
-	purple_connection_set_state(PURPLE_CONNECTION(connection),
-	                            PURPLE_CONNECTION_STATE_CONNECTED);
+	purple_account_connected(account);
 }
 
 /******************************************************************************
@@ -86,9 +85,6 @@
 
 	g_return_val_if_fail(PURPLE_XMPP_IS_CONNECTION(purple_connection), FALSE);
 
-	purple_connection_set_state(purple_connection,
-	                            PURPLE_CONNECTION_STATE_CONNECTING);
-
 	connection = PURPLE_XMPP_CONNECTION(purple_connection);
 	cancellable = purple_connection_get_cancellable(purple_connection);
 	account = purple_connection_get_account(purple_connection);
