2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2011 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
28 #include <glib/gi18n-lib.h>
31 #include <telepathy-glib/account-manager.h>
32 #include <telepathy-glib/util.h>
34 #include <libempathy/empathy-utils.h>
36 #include "empathy-ui-utils.h"
37 #include "empathy-account-chooser.h"
39 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
40 #include <libempathy/empathy-debug.h>
43 * SECTION:empathy-account-chooser
44 * @title:EmpathyAccountChooser
45 * @short_description: A widget used to choose from a list of accounts
46 * @include: libempathy-gtk/empathy-account-chooser.h
48 * #EmpathyAccountChooser is a widget which extends #GtkComboBox to provide
49 * a chooser of available accounts.
53 * EmpathyAccountChooser:
54 * @parent: parent object
56 * Widget which extends #GtkComboBox to provide a chooser of available accounts.
59 struct _EmpathyAccountChooserPriv
61 TpAccountManager *manager;
62 gboolean set_active_item;
63 gboolean account_manually_set;
64 gboolean has_all_option;
65 EmpathyAccountChooserFilterFunc filter;
72 EmpathyAccountChooser *self;
79 EmpathyAccountChooser *self;
82 } FilterResultCallbackData;
84 static FilterResultCallbackData *
85 filter_result_callback_data_new (EmpathyAccountChooser *self,
89 FilterResultCallbackData *data;
91 data = g_slice_new0 (FilterResultCallbackData);
92 data->self = g_object_ref (self);
93 data->account = g_object_ref (account);
94 data->iter = gtk_tree_iter_copy (iter);
100 filter_result_callback_data_free (FilterResultCallbackData *data)
102 g_object_unref (data->self);
103 g_object_unref (data->account);
104 gtk_tree_iter_free (data->iter);
105 g_slice_free (FilterResultCallbackData, data);
108 /* Distinguishes between store entries which are actually accounts, and special
109 * items like the "All" entry and the separator below it, so they can be sorted
110 * correctly. Higher-numbered entries will sort earlier.
121 COL_ACCOUNT_ENABLED, /* Usually tied to connected state */
122 COL_ACCOUNT_ROW_TYPE,
127 static void account_chooser_account_validity_changed_cb (
128 TpAccountManager *manager,
131 EmpathyAccountChooser *self);
132 static void account_chooser_account_add_foreach (TpAccount *account,
133 EmpathyAccountChooser *self);
134 static void account_chooser_account_removed_cb (TpAccountManager *manager,
136 EmpathyAccountChooser *self);
137 static void account_chooser_account_remove_foreach (TpAccount *account,
138 EmpathyAccountChooser*self);
139 static void account_chooser_update_iter (EmpathyAccountChooser *self,
141 static void account_chooser_status_changed_cb (TpAccount *account,
145 gchar *dbus_error_name,
148 static gboolean account_chooser_separator_func (GtkTreeModel *model,
150 EmpathyAccountChooser *self);
151 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
154 SetAccountData *data);
155 static void update_account (EmpathyAccountChooser *self,
168 static guint signals[LAST_SIGNAL] = { 0 };
170 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser,
174 empathy_account_chooser_init (EmpathyAccountChooser *self)
176 TpSimpleClientFactory *factory;
178 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
179 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
181 self->priv->set_active_item = FALSE;
182 self->priv->account_manually_set = FALSE;
183 self->priv->filter = NULL;
184 self->priv->filter_data = NULL;
186 self->priv->manager = tp_account_manager_dup ();
188 tp_g_signal_connect_object (self->priv->manager, "account-validity-changed",
189 G_CALLBACK (account_chooser_account_validity_changed_cb), self, 0);
191 tp_g_signal_connect_object (self->priv->manager, "account-removed",
192 G_CALLBACK (account_chooser_account_removed_cb), self, 0);
194 /* Make sure we'll have the capabilities feature on TpAccount's connection */
195 factory = tp_proxy_get_factory (self->priv->manager);
197 tp_simple_client_factory_add_account_features_varargs (factory,
198 TP_ACCOUNT_FEATURE_CONNECTION, NULL);
199 tp_simple_client_factory_add_connection_features_varargs (factory,
200 TP_CONNECTION_FEATURE_CAPABILITIES, NULL);
204 account_cmp (GtkTreeModel *model,
209 RowType a_type, b_type;
210 gboolean a_enabled, b_enabled;
211 gchar *a_text, *b_text;
214 gtk_tree_model_get (model, a,
215 COL_ACCOUNT_ENABLED, &a_enabled,
216 COL_ACCOUNT_ROW_TYPE, &a_type,
218 gtk_tree_model_get (model, b,
219 COL_ACCOUNT_ENABLED, &b_enabled,
220 COL_ACCOUNT_ROW_TYPE, &b_type,
223 /* This assumes that we have at most one of each special row type. */
224 if (a_type != b_type)
225 /* Display higher-numbered special row types first. */
226 return (b_type - a_type);
228 /* Enabled accounts are displayed first */
229 if (a_enabled != b_enabled)
230 return a_enabled ? -1: 1;
232 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
233 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
235 if (a_text == b_text)
237 else if (a_text == NULL)
239 else if (b_text == NULL)
242 result = g_ascii_strcasecmp (a_text, b_text);
251 account_manager_prepared_cb (GObject *source_object,
252 GAsyncResult *result,
256 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
257 EmpathyAccountChooser *self = user_data;
258 GError *error = NULL;
260 if (!tp_proxy_prepare_finish (manager, result, &error))
262 DEBUG ("Failed to prepare account manager: %s", error->message);
263 g_error_free (error);
267 accounts = tp_account_manager_get_valid_accounts (manager);
269 for (l = accounts; l != NULL; l = l->next)
271 TpAccount *account = l->data;
273 account_chooser_account_add_foreach (account, self);
275 tp_g_signal_connect_object (account, "status-changed",
276 G_CALLBACK (account_chooser_status_changed_cb),
280 g_list_free (accounts);
282 self->priv->ready = TRUE;
283 g_signal_emit (self, signals[READY], 0);
287 account_chooser_constructed (GObject *object)
289 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
291 GtkCellRenderer *renderer;
292 GtkComboBox *combobox;
294 /* Set up combo box with new store */
295 combobox = GTK_COMBO_BOX (self);
297 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
299 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
300 GDK_TYPE_PIXBUF, /* Image */
301 G_TYPE_STRING, /* Name */
302 G_TYPE_BOOLEAN, /* Enabled */
303 G_TYPE_UINT, /* Row type */
306 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
307 account_cmp, self, NULL);
308 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
309 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
311 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
313 renderer = gtk_cell_renderer_pixbuf_new ();
314 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
315 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
316 "pixbuf", COL_ACCOUNT_IMAGE,
317 "sensitive", COL_ACCOUNT_ENABLED,
320 renderer = gtk_cell_renderer_text_new ();
321 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
322 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
323 "text", COL_ACCOUNT_TEXT,
324 "sensitive", COL_ACCOUNT_ENABLED,
327 /* Populate accounts */
328 tp_proxy_prepare_async (self->priv->manager, NULL,
329 account_manager_prepared_cb, self);
331 g_object_unref (store);
336 account_chooser_dispose (GObject *object)
338 EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
340 g_clear_object (&self->priv->manager);
342 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
346 account_chooser_get_property (GObject *object,
351 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
355 case PROP_HAS_ALL_OPTION:
356 g_value_set_boolean (value, self->priv->has_all_option);
359 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
365 account_chooser_set_property (GObject *object,
372 case PROP_HAS_ALL_OPTION:
373 empathy_account_chooser_set_has_all_option (
374 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
377 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
383 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
385 GObjectClass *object_class = G_OBJECT_CLASS (klass);
387 object_class->constructed = account_chooser_constructed;
388 object_class->dispose = account_chooser_dispose;
389 object_class->get_property = account_chooser_get_property;
390 object_class->set_property = account_chooser_set_property;
393 * EmpathyAccountChooser:has-all-option:
395 * Have an additional option in the list to mean all accounts.
397 g_object_class_install_property (object_class,
399 g_param_spec_boolean ("has-all-option",
401 "Have a separate option in the list to mean ALL accounts",
406 g_signal_new ("ready",
407 G_OBJECT_CLASS_TYPE (object_class),
411 g_cclosure_marshal_generic,
415 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
419 * empathy_account_chooser_new:
421 * Creates a new #EmpathyAccountChooser.
423 * Return value: A new #EmpathyAccountChooser
426 empathy_account_chooser_new (void)
430 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
436 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
442 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
444 g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
446 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
447 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
450 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
452 return type == ROW_ALL;
456 * empathy_account_chooser_dup_account:
457 * @self: an #EmpathyAccountChooser
459 * Returns the account which is currently selected in the chooser or %NULL
460 * if there is no account selected. The #TpAccount returned should be
461 * unrefed with g_object_unref() when finished with.
463 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
466 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
472 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
474 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
475 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
478 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
484 * empathy_account_chooser_get_connection:
485 * @self: an #EmpathyAccountChooser
487 * Returns a borrowed reference to the #TpConnection associated with the
488 * account currently selected. The caller must reference the returned object
489 * with g_object_ref() if it will be kept
491 * Return value: a borrowed reference to the #TpConnection associated with the
492 * account curently selected.
495 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
498 TpConnection *connection;
500 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
502 account = empathy_account_chooser_dup_account (self);
504 /* if the returned account is NULL, then the account manager probably
505 * hasn't been prepared yet. It should be safe to return NULL here
510 connection = tp_account_get_connection (account);
511 g_object_unref (account);
517 * empathy_account_chooser_set_account:
518 * @self: an #EmpathyAccountChooser
519 * @account: a #TpAccount
521 * Sets the currently selected account to @account, if it exists in the list.
523 * Return value: whether the chooser was set to @account.
526 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
529 GtkComboBox *combobox;
534 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
536 combobox = GTK_COMBO_BOX (self);
537 model = gtk_combo_box_get_model (combobox);
538 gtk_combo_box_get_active_iter (combobox, &iter);
541 data.account = account;
544 gtk_tree_model_foreach (model,
545 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
548 self->priv->account_manually_set = data.set;
554 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
556 GtkComboBox *combobox;
560 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
562 g_return_if_fail (self->priv->has_all_option);
564 combobox = GTK_COMBO_BOX (self);
565 model = gtk_combo_box_get_model (combobox);
567 if (gtk_tree_model_get_iter_first (model, &iter))
569 /* 'All accounts' is the first row */
570 gtk_combo_box_set_active_iter (combobox, &iter);
571 self->priv->account_manually_set = TRUE;
576 * empathy_account_chooser_get_has_all_option:
577 * @self: an #EmpathyAccountChooser
579 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
580 * property set to true.
582 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
586 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
588 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
590 return self->priv->has_all_option;
594 * empathy_account_chooser_set_has_all_option:
595 * @self: an #EmpathyAccountChooser
596 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
599 * Sets the #EmpathyAccountChooser:has-all-option property.
602 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
603 gboolean has_all_option)
605 GtkComboBox *combobox;
610 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
612 if (self->priv->has_all_option == has_all_option)
615 combobox = GTK_COMBO_BOX (self);
616 model = gtk_combo_box_get_model (combobox);
617 store = GTK_LIST_STORE (model);
619 self->priv->has_all_option = has_all_option;
622 * The first 2 options are the ALL and separator
627 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
628 (GtkTreeViewRowSeparatorFunc)
629 account_chooser_separator_func,
633 gtk_list_store_prepend (store, &iter);
634 gtk_list_store_set (store, &iter,
635 COL_ACCOUNT_TEXT, NULL,
636 COL_ACCOUNT_ENABLED, TRUE,
637 COL_ACCOUNT_POINTER, NULL,
638 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
641 gtk_list_store_prepend (store, &iter);
642 gtk_list_store_set (store, &iter,
643 COL_ACCOUNT_TEXT, _("All accounts"),
644 COL_ACCOUNT_ENABLED, TRUE,
645 COL_ACCOUNT_POINTER, NULL,
646 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
651 if (gtk_tree_model_get_iter_first (model, &iter))
653 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
654 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
657 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
658 (GtkTreeViewRowSeparatorFunc)
664 g_object_notify (G_OBJECT (self), "has-all-option");
668 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
671 EmpathyAccountChooser *self)
674 account_chooser_account_add_foreach (account, self);
676 account_chooser_account_remove_foreach (account, self);
680 account_chooser_account_add_foreach (TpAccount *account,
681 EmpathyAccountChooser *self)
684 GtkComboBox *combobox;
688 combobox = GTK_COMBO_BOX (self);
689 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
691 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
692 gtk_list_store_insert_with_values (store, &iter, position,
693 COL_ACCOUNT_POINTER, account,
696 account_chooser_update_iter (self, &iter);
700 account_chooser_account_removed_cb (TpAccountManager *manager,
702 EmpathyAccountChooser *self)
704 account_chooser_account_remove_foreach (account, self);
715 account_chooser_find_account_foreach (GtkTreeModel *model,
720 FindAccountData *data = user_data;
724 gtk_tree_model_get (model, iter,
725 COL_ACCOUNT_POINTER, &account,
726 COL_ACCOUNT_ROW_TYPE, &type,
729 if (type != ROW_ACCOUNT)
732 if (account == data->account)
735 *(data->iter) = *iter;
736 g_object_unref (account);
741 g_object_unref (account);
747 account_chooser_find_account (EmpathyAccountChooser *self,
752 GtkComboBox *combobox;
753 FindAccountData data;
755 combobox = GTK_COMBO_BOX (self);
756 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
758 data.account = account;
760 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
761 account_chooser_find_account_foreach,
768 account_chooser_account_remove_foreach (TpAccount *account,
769 EmpathyAccountChooser *self)
772 GtkComboBox *combobox;
775 combobox = GTK_COMBO_BOX (self);
776 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
778 if (account_chooser_find_account (self, account, &iter))
779 gtk_list_store_remove (store, &iter);
783 account_chooser_filter_ready_cb (gboolean is_enabled,
786 FilterResultCallbackData *fr_data = data;
787 EmpathyAccountChooser *self;
791 GtkComboBox *combobox;
792 const gchar *icon_name;
795 self = fr_data->self;
796 account = fr_data->account;
797 iter = fr_data->iter;
798 combobox = GTK_COMBO_BOX (self);
799 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
801 icon_name = tp_account_get_icon_name (account);
802 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
803 GTK_ICON_SIZE_BUTTON);
805 gtk_list_store_set (store, iter,
806 COL_ACCOUNT_IMAGE, pixbuf,
807 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
808 COL_ACCOUNT_ENABLED, is_enabled,
812 g_object_unref (pixbuf);
814 /* set first connected account as active account */
815 if (self->priv->account_manually_set == FALSE &&
816 self->priv->set_active_item == FALSE && is_enabled)
818 self->priv->set_active_item = TRUE;
819 gtk_combo_box_set_active_iter (combobox, iter);
822 filter_result_callback_data_free (fr_data);
826 account_chooser_update_iter (EmpathyAccountChooser *self,
830 GtkComboBox *combobox;
832 FilterResultCallbackData *data;
834 combobox = GTK_COMBO_BOX (self);
835 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
837 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
838 COL_ACCOUNT_POINTER, &account,
841 /* Skip rows without account associated */
845 data = filter_result_callback_data_new (self, account, iter);
847 if (self->priv->filter)
848 self->priv->filter (account, account_chooser_filter_ready_cb,
849 (gpointer) data, self->priv->filter_data);
851 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
853 g_object_unref (account);
857 update_account (EmpathyAccountChooser *self,
862 if (account_chooser_find_account (self, account, &iter))
863 account_chooser_update_iter (self, &iter);
867 account_chooser_status_changed_cb (TpAccount *account,
871 gchar *dbus_error_name,
875 EmpathyAccountChooser *self = user_data;
877 update_account (self, account);
881 account_chooser_separator_func (GtkTreeModel *model,
883 EmpathyAccountChooser *self)
887 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
888 return (row_type == ROW_SEPARATOR);
892 account_chooser_set_account_foreach (GtkTreeModel *model,
895 SetAccountData *data)
900 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
902 equal = (data->account == account);
905 g_object_unref (account);
909 GtkComboBox *combobox;
911 combobox = GTK_COMBO_BOX (data->self);
912 gtk_combo_box_set_active_iter (combobox, iter);
921 account_chooser_filter_foreach (GtkTreeModel *model,
926 account_chooser_update_iter (self, iter);
931 empathy_account_chooser_refilter (EmpathyAccountChooser *self)
935 self->priv->set_active_item = FALSE;
936 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
937 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
941 * empathy_account_chooser_set_filter:
942 * @self: an #EmpathyAccountChooser
944 * @user_data: data to pass to @filter, or %NULL
946 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
947 * of the filter are visible in the @self.
950 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
951 EmpathyAccountChooserFilterFunc filter,
954 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
956 self->priv->filter = filter;
957 self->priv->filter_data = user_data;
959 /* Refilter existing data */
960 empathy_account_chooser_refilter (self);
964 * EmpathyAccountChooserFilterFunc:
965 * @account: a #TpAccount
966 * @user_data: user data, or %NULL
968 * A function which decides whether the account indicated by @account
971 * Return value: whether the account indicated by @account is visible.
975 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
977 return self->priv->ready;
981 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
985 account = empathy_account_chooser_dup_account (self);
989 g_object_unref (account);
995 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
997 return self->priv->manager;
1000 /* Pre-defined filters */
1003 * empathy_account_chooser_filter_is_connected:
1004 * @account: a #TpAccount
1005 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1006 * @callback_data: data passed to the @callback
1007 * @user_data: user data or %NULL
1009 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1010 * empathy_account_chooser_set_filter() and only show connected accounts.
1012 * Returns (via the callback) TRUE is @account is connected
1015 empathy_account_chooser_filter_is_connected (TpAccount *account,
1016 EmpathyAccountChooserFilterResultCallback callback,
1017 gpointer callback_data,
1020 gboolean is_connected =
1021 tp_account_get_connection_status (account, NULL)
1022 == TP_CONNECTION_STATUS_CONNECTED;
1024 callback (is_connected, callback_data);
1028 * empathy_account_chooser_filter_supports_multichat:
1029 * @account: a #TpAccount
1030 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1031 * @callback_data: data passed to the @callback
1032 * @user_data: user data or %NULL
1034 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1035 * support multiuser text chat and are connected.
1037 * Returns (via the callback) TRUE if @account both supports muc and
1041 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1042 EmpathyAccountChooserFilterResultCallback callback,
1043 gpointer callback_data,
1046 TpConnection *connection;
1047 gboolean supported = FALSE;
1048 TpCapabilities *caps;
1050 /* check if CM supports multiuser text chat */
1051 connection = tp_account_get_connection (account);
1052 if (connection == NULL)
1055 caps = tp_connection_get_capabilities (connection);
1059 supported = tp_capabilities_supports_text_chatrooms (caps);
1062 callback (supported, callback_data);