static gboolean
new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget               *widget,
					       GdkEventFocus           *event,
					       EmpathyNewChatroomDialog *dialog)
{
	gboolean expanded;

	expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
	if (expanded) {
		new_chatroom_dialog_browse_start (dialog);
	}
	return FALSE;
}
static void
new_chatroom_dialog_togglebutton_refresh_toggled_cb (GtkWidget               *widget,
						     EmpathyNewChatroomDialog *dialog)
{
	gboolean toggled;

	toggled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
	
	if (toggled) {
		new_chatroom_dialog_browse_start (dialog);
	} else {
		new_chatroom_dialog_browse_stop (dialog);
	}
}
static void
new_chatroom_dialog_expander_browse_activate_cb (GtkWidget               *widget,
						 EmpathyNewChatroomDialog *dialog)
{
	gboolean expanded;

	expanded = gtk_expander_get_expanded (GTK_EXPANDER (widget));
	if (expanded) {
		new_chatroom_dialog_browse_stop (dialog);
		gtk_window_set_resizable (GTK_WINDOW (dialog->window), FALSE);
	} else {
		gtk_widget_hide (dialog->viewport_error);
		gtk_widget_set_sensitive (dialog->treeview, TRUE);
		new_chatroom_dialog_browse_start (dialog);
		gtk_window_set_resizable (GTK_WINDOW (dialog->window), TRUE);
	}
}
static void
new_chatroom_dialog_entry_server_activate_cb (GtkWidget                *widget,
					      EmpathyNewChatroomDialog  *dialog)
{
	new_chatroom_dialog_browse_start (dialog);
}
static void
new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
					EmpathyNewChatroomDialog *dialog)
{
	EmpathyAccountChooser *account_chooser;
	gboolean               listing = FALSE;
	gboolean               expanded = FALSE;
	TpConnection          *connection;
	TpCapabilities *caps;

	if (dialog->room_list) {
		g_object_unref (dialog->room_list);
		dialog->room_list = NULL;
	}

	gtk_spinner_stop (GTK_SPINNER (dialog->throbber));
	gtk_widget_hide (dialog->throbber);
	new_chatroom_dialog_model_clear (dialog);

	if (dialog->account != NULL) {
		g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
		g_object_unref (dialog->account);
	}

	account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
	dialog->account = empathy_account_chooser_dup_account (account_chooser);
	connection = empathy_account_chooser_get_connection (account_chooser);
	if (dialog->account == NULL)
		goto out;

	dialog->status_changed_id = g_signal_connect (dialog->account,
		      "status-changed", G_CALLBACK (account_status_changed_cb), dialog);

	/* empathy_account_chooser_filter_supports_chatrooms ensures that the
	* account has a connection and CAPABILITIES has been prepared. */
	g_assert (connection != NULL);
	g_assert (tp_proxy_is_prepared (connection,
		TP_CONNECTION_FEATURE_CAPABILITIES));
	caps = tp_connection_get_capabilities (connection);

	if (tp_capabilities_supports_room_list (caps, NULL)) {
		/* Roomlist channels are supported */
		dialog->room_list = empathy_tp_roomlist_new (dialog->account);
	}
	else {
		dialog->room_list = NULL;
	}

	if (dialog->room_list) {
		g_signal_connect (dialog->room_list, "destroy",
				  G_CALLBACK (new_chatroom_dialog_roomlist_destroy_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "new-room",
				  G_CALLBACK (new_chatroom_dialog_new_room_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "notify::is-listing",
				  G_CALLBACK (new_chatroom_dialog_listing_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "error::start",
				  G_CALLBACK (start_listing_error_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "error::stop",
				  G_CALLBACK (stop_listing_error_cb),
				  dialog);

		expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
		if (expanded) {
			gtk_widget_hide (dialog->viewport_error);
			gtk_widget_set_sensitive (dialog->treeview, TRUE);
			new_chatroom_dialog_browse_start (dialog);
		}

		listing = empathy_tp_roomlist_is_listing (dialog->room_list);
		if (listing) {
			gtk_spinner_start (GTK_SPINNER (dialog->throbber));
			gtk_widget_show (dialog->throbber);
		}
	}

	gtk_widget_set_sensitive (dialog->expander_browse, dialog->room_list != NULL);

out:
	new_chatroom_dialog_update_widgets (dialog);
}
static void
new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
					EmpathyNewChatroomDialog *dialog)
{
	EmpathyAccountChooser *account_chooser;
	gboolean               listing = FALSE;
	gboolean               expanded = FALSE;
	TpConnection          *connection;
	EmpathyDispatcher     *dispatcher;
	GList                 *classes = NULL;

	if (dialog->room_list) {
		g_object_unref (dialog->room_list);
		dialog->room_list = NULL;
	}

	ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
	new_chatroom_dialog_model_clear (dialog);

	if (dialog->account != NULL) {
		g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
		g_object_unref (dialog->account);
	}

	account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
	dialog->account = empathy_account_chooser_dup_account (account_chooser);
	connection = empathy_account_chooser_get_connection (account_chooser);
	if (dialog->account == NULL)
		goto out;

	dialog->status_changed_id = g_signal_connect (dialog->account,
		      "status-changed", G_CALLBACK (account_status_changed_cb), dialog);

	dispatcher = empathy_dispatcher_dup_singleton ();

	if (connection != NULL) {
		classes = empathy_dispatcher_find_requestable_channel_classes (dispatcher,
			connection, TP_IFACE_CHANNEL_TYPE_ROOM_LIST,
			TP_HANDLE_TYPE_NONE, NULL);
	}

	if (classes != NULL) {
		/* Roomlist channels are supported */
		dialog->room_list = empathy_tp_roomlist_new (dialog->account);
		g_list_free (classes);
	}
	else {
		dialog->room_list = NULL;
	}

	g_object_unref (dispatcher);

	if (dialog->room_list) {
		g_signal_connect (dialog->room_list, "destroy",
				  G_CALLBACK (new_chatroom_dialog_roomlist_destroy_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "new-room",
				  G_CALLBACK (new_chatroom_dialog_new_room_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "notify::is-listing",
				  G_CALLBACK (new_chatroom_dialog_listing_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "error::start",
				  G_CALLBACK (start_listing_error_cb),
				  dialog);
		g_signal_connect (dialog->room_list, "error::stop",
				  G_CALLBACK (stop_listing_error_cb),
				  dialog);

		expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
		if (expanded) {
			gtk_widget_hide (dialog->viewport_error);
			gtk_widget_set_sensitive (dialog->treeview, TRUE);
			new_chatroom_dialog_browse_start (dialog);
		}

		listing = empathy_tp_roomlist_is_listing (dialog->room_list);
		if (listing) {
			ephy_spinner_start (EPHY_SPINNER (dialog->throbber));
		}
	}

	gtk_widget_set_sensitive (dialog->expander_browse, dialog->room_list != NULL);

out:
	new_chatroom_dialog_update_widgets (dialog);
}