# HG changeset patch
# Node ID 3bbd7c175d78
# Parent  973533570200
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -1584,10 +1584,11 @@
 
 void purple_blist_remove_group(PurpleGroup *group)
 {
+	PurpleAccountManager *manager = NULL;
 	PurpleBuddyListClass *klass = NULL;
 	PurpleBuddyListPrivate *priv = NULL;
 	PurpleBlistNode *node;
-	GList *l;
+	GList *accounts = NULL;
 	gchar* key;
 
 	g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist));
@@ -1630,13 +1631,12 @@
 			PURPLE_BLIST_NODE(group));
 
 	/* Remove the group from all accounts that are online */
-	for (l = purple_connections_get_all(); l != NULL; l = l->next)
-	{
-		PurpleConnection *gc = (PurpleConnection *)l->data;
+	manager = purple_account_manager_get_default();
+	accounts = purple_account_manager_get_connected(manager);
+	while(accounts != NULL) {
+		purple_account_remove_group(accounts->data, group);
 
-		if(purple_connection_get_state(gc) == PURPLE_CONNECTION_STATE_CONNECTED) {
-			purple_account_remove_group(purple_connection_get_account(gc), group);
-		}
+		accounts = g_list_delete_link(accounts, accounts);
 	}
 
 	/* Delete the node */
diff --git a/libpurple/idle.c b/libpurple/idle.c
--- a/libpurple/idle.c
+++ b/libpurple/idle.c
@@ -21,12 +21,14 @@
  *
  */
 
+#include "idle.h"
+
 #include "connection.h"
 #include "conversations.h"
 #include "debug.h"
 #include "eventloop.h"
-#include "idle.h"
 #include "prefs.h"
+#include "purpleaccountmanager.h"
 #include "savedstatuses.h"
 #include "signals.h"
 
@@ -199,13 +201,16 @@
 	}
 
 	/* Idle reporting stuff */
-	if (report_idle && (time_idle >= idle_poll_seconds))
-	{
-		GList *l;
-		for (l = purple_connections_get_all(); l != NULL; l = l->next)
-		{
-			PurpleConnection *gc = l->data;
-			set_account_idle(purple_connection_get_account(gc), time_idle);
+	if(report_idle && (time_idle >= idle_poll_seconds)) {
+		PurpleAccountManager *manager = NULL;
+		GList *accounts = NULL;
+
+		manager = purple_account_manager_get_default();
+		accounts = purple_account_manager_get_connected(manager);
+		while(accounts != NULL) {
+			set_account_idle(accounts->data, time_idle);
+
+			accounts = g_list_delete_link(accounts, accounts);
 		}
 	}
 	else if (!report_idle || (time_idle < idle_poll_seconds ))
diff --git a/libpurple/purpleaccountmanager.h b/libpurple/purpleaccountmanager.h
--- a/libpurple/purpleaccountmanager.h
+++ b/libpurple/purpleaccountmanager.h
@@ -46,10 +46,8 @@
 
 /**
  * PurpleAccountManager:
- * @get_idle_time: vfunc to get the time that the user interface has been idle.
  *
- * An interface that a user interface can implement to let the core determine
- * idle times.
+ * A manager that keeps track of all [class@Purple.Account]s.
  *
  * Since: 3.0.0
  */
@@ -137,6 +135,19 @@
 GList *purple_account_manager_get_disabled(PurpleAccountManager *manager);
 
 /**
+ * purple_account_manager_get_connected:
+ * @manager: The instance.
+ *
+ * Gets a list of all accounts that are currently connected.
+ *
+ * Returns: (transfer container) (element-type PurpleAccount): The list of all
+ *          connected accounts.
+ *
+ * Since: 3.0.0
+ */
+GList *purple_account_manager_get_connected(PurpleAccountManager *manager);
+
+/**
  * purple_account_manager_find_by_id:
  * @manager: The account manager instance.
  * @id: The id of the account.
diff --git a/libpurple/purpleaccountmanager.c b/libpurple/purpleaccountmanager.c
--- a/libpurple/purpleaccountmanager.c
+++ b/libpurple/purpleaccountmanager.c
@@ -257,6 +257,27 @@
 	return disabled;
 }
 
+GList *
+purple_account_manager_get_connected(PurpleAccountManager *manager) {
+	GList *connected = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
+
+	for(guint index = 0; index < manager->accounts->len; index++) {
+		PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
+		PurpleConnection *connection = NULL;
+
+		connection = purple_account_get_connection(account);
+		if(PURPLE_IS_CONNECTION(connection) &&
+		   PURPLE_CONNECTION_IS_CONNECTED(connection))
+		{
+			connected = g_list_append(connected, account);
+		}
+	}
+
+	return connected;
+}
+
 void
 purple_account_manager_reorder(PurpleAccountManager *manager,
                                PurpleAccount *account,
diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -26,6 +26,7 @@
 #include "purplemarkup.h"
 #include "request.h"
 #include "debug.h"
+#include "purpleaccountmanager.h"
 #include "purplekeyvaluepair.h"
 
 static PurpleRequestUiOps *request_ui_ops = NULL;
@@ -1743,10 +1744,14 @@
 
 	field = purple_request_field_new(id, text, PURPLE_REQUEST_FIELD_ACCOUNT);
 
-	if (account == NULL && purple_connections_get_all() != NULL)
-	{
-		account = purple_connection_get_account(
-			(PurpleConnection *)purple_connections_get_all()->data);
+	if(account == NULL) {
+		PurpleAccountManager *manager = purple_account_manager_get_default();
+		GList *accounts = purple_account_manager_get_connected(manager);
+
+		if(accounts != NULL) {
+			account = accounts->data;
+			g_list_free(accounts);
+		}
 	}
 
 	purple_request_field_account_set_default_value(field, account);
@@ -1789,19 +1794,23 @@
 
 	field->u.account.show_all = show_all;
 
-	if (!show_all)
-	{
+	if(!show_all) {
+		PurpleAccountManager *manager = purple_account_manager_get_default();
+		GList *accounts = purple_account_manager_get_connected(manager);
+
 		if (purple_account_is_connected(field->u.account.default_account))
 		{
 			purple_request_field_account_set_default_value(field,
-				(PurpleAccount *)purple_connections_get_all()->data);
+			                                               accounts->data);
 		}
 
 		if (purple_account_is_connected(field->u.account.account))
 		{
 			purple_request_field_account_set_value(field,
-				(PurpleAccount *)purple_connections_get_all()->data);
+			                                       accounts->data);
 		}
+
+		g_list_free(accounts);
 	}
 }
 
