1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
29 #include <glib/gi18n-lib.h>
32 #include <telepathy-glib/account-manager.h>
33 #include <telepathy-glib/util.h>
35 #include <libempathy/empathy-utils.h>
37 #include "empathy-ui-utils.h"
38 #include "empathy-account-chooser.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
41 #include <libempathy/empathy-debug.h>
44 * SECTION:empathy-account-chooser
45 * @title:EmpathyAccountChooser
46 * @short_description: A widget used to choose from a list of accounts
47 * @include: libempathy-gtk/empathy-account-chooser.h
49 * #EmpathyAccountChooser is a widget which extends #GtkComboBox to provide
50 * a chooser of available accounts.
54 * EmpathyAccountChooser:
55 * @parent: parent object
57 * Widget which extends #GtkComboBox to provide a chooser of available accounts.
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountChooser)
62 TpAccountManager *manager;
63 gboolean set_active_item;
64 gboolean account_manually_set;
65 gboolean has_all_option;
66 EmpathyAccountChooserFilterFunc filter;
69 } EmpathyAccountChooserPriv;
72 EmpathyAccountChooser *chooser;
78 EmpathyAccountChooser *chooser;
81 } FilterResultCallbackData;
83 static FilterResultCallbackData *
84 filter_result_callback_data_new (EmpathyAccountChooser *chooser,
88 FilterResultCallbackData *data;
90 data = g_slice_new0 (FilterResultCallbackData);
91 data->chooser = g_object_ref (chooser);
92 data->account = g_object_ref (account);
93 data->iter = gtk_tree_iter_copy (iter);
99 filter_result_callback_data_free (FilterResultCallbackData *data)
101 g_object_unref (data->chooser);
102 g_object_unref (data->account);
103 gtk_tree_iter_free (data->iter);
104 g_slice_free (FilterResultCallbackData, data);
107 /* Distinguishes between store entries which are actually accounts, and special
108 * items like the "All" entry and the separator below it, so they can be sorted
109 * correctly. Higher-numbered entries will sort earlier.
120 COL_ACCOUNT_ENABLED, /* Usually tied to connected state */
121 COL_ACCOUNT_ROW_TYPE,
126 static void account_chooser_constructed (GObject *object);
127 static void account_chooser_finalize (GObject *object);
128 static void account_chooser_get_property (GObject *object,
132 static void account_chooser_set_property (GObject *object,
136 static void account_chooser_setup (EmpathyAccountChooser *chooser);
137 static void account_chooser_account_validity_changed_cb (TpAccountManager *manager,
140 EmpathyAccountChooser *chooser);
141 static void account_chooser_account_add_foreach (TpAccount *account,
142 EmpathyAccountChooser *chooser);
143 static void account_chooser_account_removed_cb (TpAccountManager *manager,
145 EmpathyAccountChooser *chooser);
146 static void account_chooser_account_remove_foreach (TpAccount *account,
147 EmpathyAccountChooser *chooser);
148 static void account_chooser_update_iter (EmpathyAccountChooser *chooser,
150 static void account_chooser_status_changed_cb (TpAccount *account,
154 gchar *dbus_error_name,
157 static gboolean account_chooser_separator_func (GtkTreeModel *model,
159 EmpathyAccountChooser *chooser);
160 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
163 SetAccountData *data);
175 static guint signals[LAST_SIGNAL] = { 0 };
177 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser, GTK_TYPE_COMBO_BOX);
180 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
182 GObjectClass *object_class = G_OBJECT_CLASS (klass);
184 object_class->constructed = account_chooser_constructed;
185 object_class->finalize = account_chooser_finalize;
186 object_class->get_property = account_chooser_get_property;
187 object_class->set_property = account_chooser_set_property;
190 * EmpathyAccountChooser:has-all-option:
192 * Have an additional option in the list to mean all accounts.
194 g_object_class_install_property (object_class,
196 g_param_spec_boolean ("has-all-option",
198 "Have a separate option in the list to mean ALL accounts",
203 g_signal_new ("ready",
204 G_OBJECT_CLASS_TYPE (object_class),
208 g_cclosure_marshal_VOID__VOID,
212 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
216 empathy_account_chooser_init (EmpathyAccountChooser *chooser)
218 EmpathyAccountChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
219 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
221 chooser->priv = priv;
222 priv->set_active_item = FALSE;
223 priv->account_manually_set = FALSE;
225 priv->filter_data = NULL;
227 priv->manager = tp_account_manager_dup ();
229 g_signal_connect (priv->manager, "account-validity-changed",
230 G_CALLBACK (account_chooser_account_validity_changed_cb),
232 g_signal_connect (priv->manager, "account-removed",
233 G_CALLBACK (account_chooser_account_removed_cb),
238 account_chooser_constructed (GObject *object)
240 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
242 account_chooser_setup (self);
246 account_chooser_finalize (GObject *object)
248 EmpathyAccountChooserPriv *priv = GET_PRIV (object);
250 g_signal_handlers_disconnect_by_func (priv->manager,
251 account_chooser_account_validity_changed_cb,
253 g_signal_handlers_disconnect_by_func (priv->manager,
254 account_chooser_account_removed_cb,
256 g_object_unref (priv->manager);
258 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->finalize (object);
262 account_chooser_get_property (GObject *object,
267 EmpathyAccountChooserPriv *priv;
269 priv = GET_PRIV (object);
272 case PROP_HAS_ALL_OPTION:
273 g_value_set_boolean (value, priv->has_all_option);
276 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
282 account_chooser_set_property (GObject *object,
288 case PROP_HAS_ALL_OPTION:
289 empathy_account_chooser_set_has_all_option (EMPATHY_ACCOUNT_CHOOSER (object),
290 g_value_get_boolean (value));
293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
299 * empathy_account_chooser_new:
301 * Creates a new #EmpathyAccountChooser.
303 * Return value: A new #EmpathyAccountChooser
306 empathy_account_chooser_new (void)
310 chooser = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
316 * empathy_account_chooser_dup_account:
317 * @chooser: an #EmpathyAccountChooser
319 * Returns the account which is currently selected in the chooser or %NULL
320 * if there is no account selected. The #TpAccount returned should be
321 * unrefed with g_object_unref() when finished with.
323 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
326 empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser)
332 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), NULL);
334 model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
335 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (chooser), &iter)) {
339 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
345 * empathy_account_chooser_get_connection:
346 * @chooser: an #EmpathyAccountChooser
348 * Returns a borrowed reference to the #TpConnection associated with the
349 * account currently selected. The caller must reference the returned object with
350 * g_object_ref() if it will be kept
352 * Return value: a borrowed reference to the #TpConnection associated with the
353 * account curently selected.
356 empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser)
359 TpConnection *connection;
361 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), NULL);
363 account = empathy_account_chooser_dup_account (chooser);
365 /* if the returned account is NULL, then the account manager probably
366 * hasn't been prepared yet. It should be safe to return NULL here
368 if (account == NULL) {
372 connection = tp_account_get_connection (account);
373 g_object_unref (account);
379 * empathy_account_chooser_set_account:
380 * @chooser: an #EmpathyAccountChooser
381 * @account: a #TpAccount
383 * Sets the currently selected account to @account, if it exists in the list.
385 * Return value: whether the chooser was set to @account.
388 empathy_account_chooser_set_account (EmpathyAccountChooser *chooser,
391 EmpathyAccountChooserPriv *priv;
392 GtkComboBox *combobox;
397 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), FALSE);
399 priv = GET_PRIV (chooser);
401 combobox = GTK_COMBO_BOX (chooser);
402 model = gtk_combo_box_get_model (combobox);
403 gtk_combo_box_get_active_iter (combobox, &iter);
405 data.chooser = chooser;
406 data.account = account;
408 gtk_tree_model_foreach (model,
409 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
412 priv->account_manually_set = data.set;
418 * empathy_account_chooser_get_has_all_option:
419 * @chooser: an #EmpathyAccountChooser
421 * Returns whether @chooser has the #EmpathyAccountChooser:has-all-option property
424 * Return value: whether @chooser has the #EmpathyAccountChooser:has-all-option property
428 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *chooser)
430 EmpathyAccountChooserPriv *priv;
432 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), FALSE);
434 priv = GET_PRIV (chooser);
436 return priv->has_all_option;
440 * empathy_account_chooser_set_has_all_option:
441 * @chooser: an #EmpathyAccountChooser
442 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option property
444 * Sets the #EmpathyAccountChooser:has-all-option property.
447 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *chooser,
448 gboolean has_all_option)
450 EmpathyAccountChooserPriv *priv;
451 GtkComboBox *combobox;
456 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser));
458 priv = GET_PRIV (chooser);
460 if (priv->has_all_option == has_all_option) {
464 combobox = GTK_COMBO_BOX (chooser);
465 model = gtk_combo_box_get_model (combobox);
466 store = GTK_LIST_STORE (model);
468 priv->has_all_option = has_all_option;
471 * The first 2 options are the ALL and separator
474 if (has_all_option) {
475 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
476 (GtkTreeViewRowSeparatorFunc)
477 account_chooser_separator_func,
481 gtk_list_store_prepend (store, &iter);
482 gtk_list_store_set (store, &iter,
483 COL_ACCOUNT_TEXT, NULL,
484 COL_ACCOUNT_ENABLED, TRUE,
485 COL_ACCOUNT_POINTER, NULL,
486 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
489 gtk_list_store_prepend (store, &iter);
490 gtk_list_store_set (store, &iter,
491 COL_ACCOUNT_TEXT, _("All"),
492 COL_ACCOUNT_ENABLED, TRUE,
493 COL_ACCOUNT_POINTER, NULL,
494 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
497 if (gtk_tree_model_get_iter_first (model, &iter)) {
498 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter)) {
499 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
503 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
504 (GtkTreeViewRowSeparatorFunc)
510 g_object_notify (G_OBJECT (chooser), "has-all-option");
514 account_manager_prepared_cb (GObject *source_object,
515 GAsyncResult *result,
519 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
520 EmpathyAccountChooser *chooser = user_data;
521 EmpathyAccountChooserPriv *priv = GET_PRIV (chooser);
522 GError *error = NULL;
524 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
525 DEBUG ("Failed to prepare account manager: %s", error->message);
526 g_error_free (error);
530 accounts = tp_account_manager_get_valid_accounts (manager);
532 for (l = accounts; l != NULL; l = l->next) {
533 TpAccount *account = l->data;
535 account_chooser_account_add_foreach (account, chooser);
537 tp_g_signal_connect_object (account, "status-changed",
538 G_CALLBACK (account_chooser_status_changed_cb),
542 g_list_free (accounts);
545 g_signal_emit (chooser, signals[READY], 0);
549 account_cmp (GtkTreeModel *model,
554 RowType a_type, b_type;
555 gboolean a_enabled, b_enabled;
556 gchar *a_text, *b_text;
559 gtk_tree_model_get (model, a,
560 COL_ACCOUNT_ENABLED, &a_enabled,
561 COL_ACCOUNT_ROW_TYPE, &a_type,
563 gtk_tree_model_get (model, b,
564 COL_ACCOUNT_ENABLED, &b_enabled,
565 COL_ACCOUNT_ROW_TYPE, &b_type,
568 /* This assumes that we have at most one of each special row type. */
569 if (a_type != b_type) {
570 /* Display higher-numbered special row types first. */
571 return (b_type - a_type);
574 /* Enabled accounts are displayed first */
575 if (a_enabled != b_enabled)
576 return a_enabled ? -1: 1;
578 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
579 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
581 if (a_text == b_text)
583 else if (a_text == NULL)
585 else if (b_text == NULL)
588 result = g_ascii_strcasecmp (a_text, b_text);
597 account_chooser_setup (EmpathyAccountChooser *chooser)
599 EmpathyAccountChooserPriv *priv;
601 GtkCellRenderer *renderer;
602 GtkComboBox *combobox;
604 priv = GET_PRIV (chooser);
606 /* Set up combo box with new store */
607 combobox = GTK_COMBO_BOX (chooser);
609 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
611 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
612 GDK_TYPE_PIXBUF, /* Image */
613 G_TYPE_STRING, /* Name */
614 G_TYPE_BOOLEAN, /* Enabled */
615 G_TYPE_UINT, /* Row type */
618 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
619 account_cmp, chooser, NULL);
620 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
621 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
623 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
625 renderer = gtk_cell_renderer_pixbuf_new ();
626 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
627 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
628 "pixbuf", COL_ACCOUNT_IMAGE,
629 "sensitive", COL_ACCOUNT_ENABLED,
632 renderer = gtk_cell_renderer_text_new ();
633 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
634 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
635 "text", COL_ACCOUNT_TEXT,
636 "sensitive", COL_ACCOUNT_ENABLED,
639 /* Populate accounts */
640 tp_account_manager_prepare_async (priv->manager, NULL,
641 account_manager_prepared_cb, chooser);
643 g_object_unref (store);
647 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
650 EmpathyAccountChooser *chooser)
653 account_chooser_account_add_foreach (account, chooser);
655 account_chooser_account_remove_foreach (account, chooser);
660 account_chooser_account_add_foreach (TpAccount *account,
661 EmpathyAccountChooser *chooser)
664 GtkComboBox *combobox;
668 combobox = GTK_COMBO_BOX (chooser);
669 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
671 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
672 gtk_list_store_insert_with_values (store, &iter, position,
673 COL_ACCOUNT_POINTER, account,
675 account_chooser_update_iter (chooser, &iter);
679 account_chooser_account_removed_cb (TpAccountManager *manager,
681 EmpathyAccountChooser *chooser)
683 account_chooser_account_remove_foreach (account, chooser);
693 account_chooser_find_account_foreach (GtkTreeModel *model,
698 FindAccountData *data = user_data;
701 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
703 if (account == data->account) {
705 *(data->iter) = *iter;
706 g_object_unref (account);
711 g_object_unref (account);
717 account_chooser_find_account (EmpathyAccountChooser *chooser,
722 GtkComboBox *combobox;
723 FindAccountData data;
725 combobox = GTK_COMBO_BOX (chooser);
726 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
728 data.account = account;
730 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
731 account_chooser_find_account_foreach,
738 account_chooser_account_remove_foreach (TpAccount *account,
739 EmpathyAccountChooser *chooser)
742 GtkComboBox *combobox;
745 combobox = GTK_COMBO_BOX (chooser);
746 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
748 if (account_chooser_find_account (chooser, account, &iter)) {
749 gtk_list_store_remove (store, &iter);
754 account_chooser_filter_ready_cb (gboolean is_enabled,
757 FilterResultCallbackData *fr_data = data;
758 EmpathyAccountChooser *chooser;
759 EmpathyAccountChooserPriv *priv;
763 GtkComboBox *combobox;
764 const gchar *icon_name;
767 chooser = fr_data->chooser;
768 priv = GET_PRIV (chooser);
769 account = fr_data->account;
770 iter = fr_data->iter;
771 combobox = GTK_COMBO_BOX (chooser);
772 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
774 icon_name = tp_account_get_icon_name (account);
775 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
776 GTK_ICON_SIZE_BUTTON);
778 gtk_list_store_set (store, iter,
779 COL_ACCOUNT_IMAGE, pixbuf,
780 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
781 COL_ACCOUNT_ENABLED, is_enabled,
785 g_object_unref (pixbuf);
787 /* set first connected account as active account */
788 if (priv->account_manually_set == FALSE &&
789 priv->set_active_item == FALSE && is_enabled) {
790 priv->set_active_item = TRUE;
791 gtk_combo_box_set_active_iter (combobox, iter);
794 filter_result_callback_data_free (fr_data);
798 account_chooser_update_iter (EmpathyAccountChooser *chooser,
801 EmpathyAccountChooserPriv *priv;
803 GtkComboBox *combobox;
805 FilterResultCallbackData *data;
807 priv = GET_PRIV (chooser);
809 combobox = GTK_COMBO_BOX (chooser);
810 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
812 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
813 COL_ACCOUNT_POINTER, &account,
816 /* Skip rows without account associated */
820 data = filter_result_callback_data_new (chooser, account, iter);
823 priv->filter (account, account_chooser_filter_ready_cb,
824 (gpointer) data, priv->filter_data);
826 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
828 g_object_unref (account);
832 account_chooser_status_changed_cb (TpAccount *account,
836 gchar *dbus_error_name,
840 EmpathyAccountChooser *chooser = user_data;
843 if (account_chooser_find_account (chooser, account, &iter)) {
844 account_chooser_update_iter (chooser, &iter);
849 account_chooser_separator_func (GtkTreeModel *model,
851 EmpathyAccountChooser *chooser)
855 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
856 return (row_type == ROW_SEPARATOR);
860 account_chooser_set_account_foreach (GtkTreeModel *model,
863 SetAccountData *data)
868 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
870 equal = (data->account == account);
873 g_object_unref (account);
877 GtkComboBox *combobox;
879 combobox = GTK_COMBO_BOX (data->chooser);
880 gtk_combo_box_set_active_iter (combobox, iter);
889 account_chooser_filter_foreach (GtkTreeModel *model,
894 account_chooser_update_iter (chooser, iter);
899 * empathy_account_chooser_set_filter:
900 * @chooser: an #EmpathyAccountChooser
902 * @user_data: data to pass to @filter, or %NULL
904 * Sets a filter on the @chooser so only accounts that are %TRUE in the eyes
905 * of the filter are visible in the @chooser.
908 empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser,
909 EmpathyAccountChooserFilterFunc filter,
912 EmpathyAccountChooserPriv *priv;
915 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser));
917 priv = GET_PRIV (chooser);
919 priv->filter = filter;
920 priv->filter_data = user_data;
922 /* Refilter existing data */
923 priv->set_active_item = FALSE;
924 model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
925 gtk_tree_model_foreach (model, account_chooser_filter_foreach, chooser);
929 * EmpathyAccountChooserFilterFunc:
930 * @account: a #TpAccount
931 * @user_data: user data, or %NULL
933 * A function which decides whether the account indicated by @account
936 * Return value: whether the account indicated by @account is visible.
940 * empathy_account_chooser_filter_is_connected:
941 * @account: a #TpAccount
942 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
943 * @callback_data: data passed to the @callback
944 * @user_data: user data or %NULL
946 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
947 * empathy_account_chooser_set_filter() and only show connected accounts.
949 * Returns (via the callback) TRUE is @account is connected
952 empathy_account_chooser_filter_is_connected (
954 EmpathyAccountChooserFilterResultCallback callback,
955 gpointer callback_data,
958 gboolean is_connected =
959 tp_account_get_connection_status (account, NULL)
960 == TP_CONNECTION_STATUS_CONNECTED;
961 callback (is_connected, callback_data);
965 EmpathyAccountChooserFilterResultCallback callback;
967 } FilterCallbackData;
970 conn_prepared_cb (GObject *conn,
971 GAsyncResult *result,
974 FilterCallbackData *data = user_data;
975 GError *myerr = NULL;
976 TpCapabilities *caps;
978 if (!tp_proxy_prepare_finish (conn, result, &myerr)) {
979 data->callback (FALSE, data->user_data);
980 g_slice_free (FilterCallbackData, data);
984 caps = tp_connection_get_capabilities (TP_CONNECTION (conn));
985 data->callback (tp_capabilities_supports_text_chatrooms (caps),
988 g_slice_free (FilterCallbackData, data);
992 * empathy_account_chooser_filter_supports_multichat:
993 * @account: a #TpAccount
994 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
995 * @callback_data: data passed to the @callback
996 * @user_data: user data or %NULL
998 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
999 * support multiuser text chat and are connected.
1001 * Returns (via the callback) TRUE if @account both supports muc and is connected
1004 empathy_account_chooser_filter_supports_chatrooms (
1006 EmpathyAccountChooserFilterResultCallback callback,
1007 gpointer callback_data,
1010 TpConnection *connection;
1011 FilterCallbackData *cb_data;
1012 GQuark features[] = { TP_CONNECTION_FEATURE_CAPABILITIES, 0 };
1014 if (tp_account_get_connection_status (account, NULL) !=
1015 TP_CONNECTION_STATUS_CONNECTED) {
1016 callback (FALSE, callback_data);
1020 /* check if CM supports multiuser text chat */
1021 connection = tp_account_get_connection (account);
1022 if (connection == NULL) {
1023 callback (FALSE, callback_data);
1027 cb_data = g_slice_new0 (FilterCallbackData);
1028 cb_data->callback = callback;
1029 cb_data->user_data = callback_data;
1031 tp_proxy_prepare_async (connection, features, conn_prepared_cb,
1036 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
1038 EmpathyAccountChooserPriv *priv = GET_PRIV (self);
1044 empathy_account_chooser_get_account (EmpathyAccountChooser *chooser)
1048 account = empathy_account_chooser_dup_account (chooser);
1049 if (account == NULL)
1052 g_object_unref (account);