# HG changeset patch
# Node ID 54d516a0b9a0
# Parent  96f15115ab61
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -948,13 +948,18 @@ pidgin_blist_update_privacy_cb(PurpleBud
 }
 
 static gboolean
-chat_account_filter_func(PurpleAccount *account)
-{
-	PurpleConnection *gc = purple_account_get_connection(account);
+chat_account_filter_func(gpointer item, G_GNUC_UNUSED gpointer data) {
+	PurpleConnection *gc = NULL;
 	PurpleProtocol *protocol = NULL;
 
-	if (gc == NULL)
+	if(!PURPLE_IS_ACCOUNT(item)) {
 		return FALSE;
+	}
+
+	gc = purple_account_get_connection(PURPLE_ACCOUNT(item));
+	if(gc == NULL) {
+		return FALSE;
+	}
 
 	protocol = purple_connection_get_protocol(gc);
 
@@ -970,8 +975,9 @@ pidgin_blist_joinchat_is_showable(void)
 	for (c = purple_connections_get_all(); c != NULL; c = c->next) {
 		gc = c->data;
 
-		if (chat_account_filter_func(purple_connection_get_account(gc)))
+		if(chat_account_filter_func(purple_connection_get_account(gc), NULL)) {
 			return TRUE;
+		}
 	}
 
 	return FALSE;
@@ -980,7 +986,7 @@ pidgin_blist_joinchat_is_showable(void)
 static void
 make_blist_request_dialog(PidginBlistRequestData *data, PurpleAccount *account,
 	const char *title, const char *window_role, const char *label_text,
-	GCallback callback_func, PurpleFilterAccountFunc filter_func,
+	GCallback callback_func, GtkCustomFilterFunc filter_func,
 	GCallback response_cb)
 {
 	GtkWidget *label;
@@ -990,6 +996,7 @@ make_blist_request_dialog(PidginBlistReq
 	GtkWidget *vbox;
 	GtkWindow *blist_window;
 	GtkTreeModel *model = NULL, *filter = NULL;
+	GtkCustomFilter *custom_filter = NULL;
 	PidginBuddyList *gtkblist;
 
 	data->account = account;
@@ -1040,8 +1047,12 @@ make_blist_request_dialog(PidginBlistReq
 		gtk_combo_box_set_active(GTK_COMBO_BOX(data->account_menu), 0);
 	}
 
-	pidgin_account_chooser_set_filter_func(
-	        PIDGIN_ACCOUNT_CHOOSER(data->account_menu), filter_func);
+	custom_filter = gtk_custom_filter_new(filter_func, NULL, NULL);
+	pidgin_account_chooser_set_filter(
+	        PIDGIN_ACCOUNT_CHOOSER(data->account_menu),
+	        GTK_FILTER(custom_filter));
+	g_object_unref(custom_filter);
+
 	pidgin_add_widget_to_vbox(GTK_BOX(vbox), _("A_ccount"), data->sg, data->account_menu, TRUE, NULL);
 	g_signal_connect(data->account_menu, "changed",
 	                 G_CALLBACK(callback_func), data);
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -1385,11 +1385,24 @@ create_image_field(PurpleRequestField *f
 	return widget;
 }
 
+static gboolean
+field_custom_account_filter_cb(gpointer item, G_GNUC_UNUSED gpointer data) {
+	PurpleFilterAccountFunc func = data;
+	gboolean ret = FALSE;
+
+	if(PURPLE_IS_ACCOUNT(item)) {
+		ret = func(PURPLE_ACCOUNT(item));
+	}
+
+	return ret;
+}
+
 static GtkWidget *
 create_account_field(PurpleRequestField *field)
 {
 	GtkWidget *widget;
 	PurpleAccount *account;
+	GtkCustomFilter *custom_filter = NULL;
 
 	widget = pidgin_account_chooser_new();
 	account  = purple_request_field_account_get_default_value(field);
@@ -1415,9 +1428,15 @@ create_account_field(PurpleRequestField 
 
 	pidgin_account_chooser_set_selected(PIDGIN_ACCOUNT_CHOOSER(widget),
 	                                    account);
-	pidgin_account_chooser_set_filter_func(
+	custom_filter = gtk_custom_filter_new(
+	        field_custom_account_filter_cb,
+	        purple_request_field_account_get_filter(field),
+	        NULL);
+	pidgin_account_chooser_set_filter(
 	        PIDGIN_ACCOUNT_CHOOSER(widget),
-	        purple_request_field_account_get_filter(field));
+	        GTK_FILTER(custom_filter));
+	g_object_unref(custom_filter);
+
 	g_signal_connect(widget, "changed", G_CALLBACK(field_account_cb),
 	                 field);
 
diff --git a/pidgin/gtkroomlist.c b/pidgin/gtkroomlist.c
--- a/pidgin/gtkroomlist.c
+++ b/pidgin/gtkroomlist.c
@@ -444,13 +444,17 @@ pidgin_roomlist_query_tooltip(GtkWidget 
 	return TRUE;
 }
 
-static gboolean account_filter_func(PurpleAccount *account)
-{
-	PurpleConnection *conn = purple_account_get_connection(account);
+static gboolean
+account_filter_func(gpointer item, G_GNUC_UNUSED gpointer data) {
 	PurpleProtocol *protocol = NULL;
 
-	if (conn && PURPLE_CONNECTION_IS_CONNECTED(conn))
-		protocol = purple_connection_get_protocol(conn);
+	if(PURPLE_IS_ACCOUNT(item)) {
+		PurpleAccount *account = PURPLE_ACCOUNT(item);
+		PurpleConnection *conn = purple_account_get_connection(account);
+		if(conn && PURPLE_CONNECTION_IS_CONNECTED(conn)) {
+			protocol = purple_connection_get_protocol(conn);
+		}
+	}
 
 	return (protocol && PURPLE_PROTOCOL_IMPLEMENTS(protocol, ROOMLIST, get_list));
 }
@@ -464,8 +468,9 @@ pidgin_roomlist_is_showable(void)
 	for (c = purple_connections_get_all(); c != NULL; c = c->next) {
 		gc = c->data;
 
-		if (account_filter_func(purple_connection_get_account(gc)))
+		if(account_filter_func(purple_connection_get_account(gc), NULL)) {
 			return TRUE;
+		}
 	}
 
 	return FALSE;
@@ -517,12 +522,15 @@ static void
 pidgin_roomlist_dialog_init(PidginRoomlistDialog *self)
 {
 	GSimpleActionGroup *group = NULL;
+	GtkCustomFilter *filter = NULL;
 
 	gtk_widget_init_template(GTK_WIDGET(self));
 
-	pidgin_account_chooser_set_filter_func(
+	filter = gtk_custom_filter_new(account_filter_func, NULL, NULL);
+	pidgin_account_chooser_set_filter(
 	        PIDGIN_ACCOUNT_CHOOSER(self->account_widget),
-	        account_filter_func);
+	        GTK_FILTER(filter));
+	g_object_unref(filter);
 
 	gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(self->tree),
 	                                    _search_func, NULL, NULL);
diff --git a/pidgin/pidginaccountchooser.h b/pidgin/pidginaccountchooser.h
--- a/pidgin/pidginaccountchooser.h
+++ b/pidgin/pidginaccountchooser.h
@@ -49,17 +49,28 @@ G_DECLARE_FINAL_TYPE(PidginAccountChoose
 GtkWidget *pidgin_account_chooser_new(void);
 
 /**
- * pidgin_account_chooser_set_filter_func:
- * @chooser: The account chooser combo box.
- * @filter_func: (scope notified): A function for checking if an account should be shown. This
- *               can be %NULL to remove any filter.
+ * pidgin_account_chooser_get_filter:
+ * @chooser: The chooser.
  *
- * Set the filter function used to determine which accounts to show.
+ * Gets the filter used to determine which accounts to show.
+ *
+ * Returns: (transfer none): Returns the #GtkFilter that is currently
+ *          displayed.
  *
  * Since: 3.0.0
  */
-void pidgin_account_chooser_set_filter_func(
-        PidginAccountChooser *chooser, PurpleFilterAccountFunc filter_func);
+GtkFilter *pidgin_account_chooser_get_filter(PidginAccountChooser *chooser);
+
+/**
+ * pidgin_account_chooser_set_filter:
+ * @chooser: The chooser.
+ * @filter: The filter.
+ *
+ * Sets the current list filter for the account chooser.
+ *
+ * Since: 3.0.0
+ */
+void pidgin_account_chooser_set_filter(PidginAccountChooser *chooser, GtkFilter *filter);
 
 /**
  * pidgin_account_chooser_get_selected:
diff --git a/pidgin/pidginaccountchooser.c b/pidgin/pidginaccountchooser.c
--- a/pidgin/pidginaccountchooser.c
+++ b/pidgin/pidginaccountchooser.c
@@ -29,13 +29,14 @@
 struct _PidginAccountChooser {
 	GtkComboBox parent;
 
-	PurpleFilterAccountFunc filter_func;
+	GtkFilter *filter;
 };
 
 enum
 {
 	PROP_0,
 	PROP_ACCOUNT,
+	PROP_FILTER,
 	PROP_LAST
 };
 
@@ -64,6 +65,9 @@ pidgin_account_chooser_get_property(GObj
 		case PROP_ACCOUNT:
 			g_value_set_object(value, pidgin_account_chooser_get_selected(chooser));
 			break;
+		case PROP_FILTER:
+			g_value_set_object(value, pidgin_account_chooser_get_filter(chooser));
+			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 			break;
@@ -81,6 +85,10 @@ pidgin_account_chooser_set_property(GObj
 			pidgin_account_chooser_set_selected(chooser,
 			                                    g_value_get_object(value));
 			break;
+		case PROP_FILTER:
+			pidgin_account_chooser_set_filter(chooser,
+			                                  g_value_get_object(value));
+			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 			break;
@@ -99,7 +107,14 @@ pidgin_account_chooser_class_init(Pidgin
 
 	properties[PROP_ACCOUNT] = g_param_spec_object(
 	        "account", "Account", "The account that is currently selected.",
-	        PURPLE_TYPE_ACCOUNT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+	        PURPLE_TYPE_ACCOUNT,
+	        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+	properties[PROP_FILTER] = g_param_spec_object(
+	        "filter", "filter",
+	        "The filter to be applied on the list of accounts.",
+	        GTK_TYPE_FILTER,
+	        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
 	g_object_class_install_properties(obj_class, PROP_LAST, properties);
 
@@ -129,13 +144,22 @@ pidgin_account_chooser_new(void) {
 	return GTK_WIDGET(chooser);
 }
 
+GtkFilter *
+pidgin_account_chooser_get_filter(PidginAccountChooser *chooser) {
+	g_return_val_if_fail(PIDGIN_IS_ACCOUNT_CHOOSER(chooser), NULL);
+
+	return chooser->filter;
+}
+
 void
-pidgin_account_chooser_set_filter_func(PidginAccountChooser *chooser,
-                                       PurpleFilterAccountFunc filter_func)
+pidgin_account_chooser_set_filter(PidginAccountChooser *chooser,
+                                  GtkFilter *filter)
 {
 	g_return_if_fail(PIDGIN_IS_ACCOUNT_CHOOSER(chooser));
 
-	chooser->filter_func = filter_func;
+	if(g_set_object(&chooser->filter, filter)) {
+		g_object_notify_by_pspec(G_OBJECT(chooser), properties[PROP_FILTER]);
+	}
 }
 
 PurpleAccount *
