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);
166 static guint signals[LAST_SIGNAL] = { 0 };
168 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser,
172 empathy_account_chooser_init (EmpathyAccountChooser *self)
174 TpSimpleClientFactory *factory;
176 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
177 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
179 self->priv->set_active_item = FALSE;
180 self->priv->account_manually_set = FALSE;
181 self->priv->filter = NULL;
182 self->priv->filter_data = NULL;
184 self->priv->manager = tp_account_manager_dup ();
186 tp_g_signal_connect_object (self->priv->manager, "account-validity-changed",
187 G_CALLBACK (account_chooser_account_validity_changed_cb), self, 0);
189 tp_g_signal_connect_object (self->priv->manager, "account-removed",
190 G_CALLBACK (account_chooser_account_removed_cb), self, 0);
192 /* Make sure we'll have the capabilities feature on TpAccount's connection */
193 factory = tp_proxy_get_factory (self->priv->manager);
195 tp_simple_client_factory_add_account_features_varargs (factory,
196 TP_ACCOUNT_FEATURE_CONNECTION, NULL);
197 tp_simple_client_factory_add_connection_features_varargs (factory,
198 TP_CONNECTION_FEATURE_CAPABILITIES, NULL);
202 account_cmp (GtkTreeModel *model,
207 RowType a_type, b_type;
208 gboolean a_enabled, b_enabled;
209 gchar *a_text, *b_text;
212 gtk_tree_model_get (model, a,
213 COL_ACCOUNT_ENABLED, &a_enabled,
214 COL_ACCOUNT_ROW_TYPE, &a_type,
216 gtk_tree_model_get (model, b,
217 COL_ACCOUNT_ENABLED, &b_enabled,
218 COL_ACCOUNT_ROW_TYPE, &b_type,
221 /* This assumes that we have at most one of each special row type. */
222 if (a_type != b_type)
223 /* Display higher-numbered special row types first. */
224 return (b_type - a_type);
226 /* Enabled accounts are displayed first */
227 if (a_enabled != b_enabled)
228 return a_enabled ? -1: 1;
230 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
231 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
233 if (a_text == b_text)
235 else if (a_text == NULL)
237 else if (b_text == NULL)
240 result = g_ascii_strcasecmp (a_text, b_text);
249 account_manager_prepared_cb (GObject *source_object,
250 GAsyncResult *result,
254 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
255 EmpathyAccountChooser *self = user_data;
256 GError *error = NULL;
258 if (!tp_proxy_prepare_finish (manager, result, &error))
260 DEBUG ("Failed to prepare account manager: %s", error->message);
261 g_error_free (error);
265 accounts = tp_account_manager_get_valid_accounts (manager);
267 for (l = accounts; l != NULL; l = l->next)
269 TpAccount *account = l->data;
271 account_chooser_account_add_foreach (account, self);
273 tp_g_signal_connect_object (account, "status-changed",
274 G_CALLBACK (account_chooser_status_changed_cb),
278 g_list_free (accounts);
280 self->priv->ready = TRUE;
281 g_signal_emit (self, signals[READY], 0);
285 account_chooser_constructed (GObject *object)
287 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
289 GtkCellRenderer *renderer;
290 GtkComboBox *combobox;
292 /* Set up combo box with new store */
293 combobox = GTK_COMBO_BOX (self);
295 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
297 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
298 GDK_TYPE_PIXBUF, /* Image */
299 G_TYPE_STRING, /* Name */
300 G_TYPE_BOOLEAN, /* Enabled */
301 G_TYPE_UINT, /* Row type */
304 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
305 account_cmp, self, NULL);
306 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
307 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
309 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
311 renderer = gtk_cell_renderer_pixbuf_new ();
312 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
313 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
314 "pixbuf", COL_ACCOUNT_IMAGE,
315 "sensitive", COL_ACCOUNT_ENABLED,
318 renderer = gtk_cell_renderer_text_new ();
319 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
320 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
321 "text", COL_ACCOUNT_TEXT,
322 "sensitive", COL_ACCOUNT_ENABLED,
325 /* Populate accounts */
326 tp_proxy_prepare_async (self->priv->manager, NULL,
327 account_manager_prepared_cb, self);
329 g_object_unref (store);
334 account_chooser_dispose (GObject *object)
336 EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
338 g_clear_object (&self->priv->manager);
340 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
344 account_chooser_get_property (GObject *object,
349 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
353 case PROP_HAS_ALL_OPTION:
354 g_value_set_boolean (value, self->priv->has_all_option);
357 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
363 account_chooser_set_property (GObject *object,
370 case PROP_HAS_ALL_OPTION:
371 empathy_account_chooser_set_has_all_option (
372 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
375 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
381 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
383 GObjectClass *object_class = G_OBJECT_CLASS (klass);
385 object_class->constructed = account_chooser_constructed;
386 object_class->dispose = account_chooser_dispose;
387 object_class->get_property = account_chooser_get_property;
388 object_class->set_property = account_chooser_set_property;
391 * EmpathyAccountChooser:has-all-option:
393 * Have an additional option in the list to mean all accounts.
395 g_object_class_install_property (object_class,
397 g_param_spec_boolean ("has-all-option",
399 "Have a separate option in the list to mean ALL accounts",
404 g_signal_new ("ready",
405 G_OBJECT_CLASS_TYPE (object_class),
409 g_cclosure_marshal_generic,
413 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
417 * empathy_account_chooser_new:
419 * Creates a new #EmpathyAccountChooser.
421 * Return value: A new #EmpathyAccountChooser
424 empathy_account_chooser_new (void)
428 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
434 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
440 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
442 g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
444 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
445 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
448 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
450 return type == ROW_ALL;
454 * empathy_account_chooser_dup_account:
455 * @self: an #EmpathyAccountChooser
457 * Returns the account which is currently selected in the chooser or %NULL
458 * if there is no account selected. The #TpAccount returned should be
459 * unrefed with g_object_unref() when finished with.
461 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
464 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
470 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
472 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
473 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
476 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
482 * empathy_account_chooser_get_connection:
483 * @self: an #EmpathyAccountChooser
485 * Returns a borrowed reference to the #TpConnection associated with the
486 * account currently selected. The caller must reference the returned object
487 * with g_object_ref() if it will be kept
489 * Return value: a borrowed reference to the #TpConnection associated with the
490 * account curently selected.
493 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
496 TpConnection *connection;
498 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
500 account = empathy_account_chooser_dup_account (self);
502 /* if the returned account is NULL, then the account manager probably
503 * hasn't been prepared yet. It should be safe to return NULL here
508 connection = tp_account_get_connection (account);
509 g_object_unref (account);
515 * empathy_account_chooser_set_account:
516 * @self: an #EmpathyAccountChooser
517 * @account: a #TpAccount
519 * Sets the currently selected account to @account, if it exists in the list.
521 * Return value: whether the chooser was set to @account.
524 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
527 GtkComboBox *combobox;
532 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
534 combobox = GTK_COMBO_BOX (self);
535 model = gtk_combo_box_get_model (combobox);
536 gtk_combo_box_get_active_iter (combobox, &iter);
539 data.account = account;
542 gtk_tree_model_foreach (model,
543 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
546 self->priv->account_manually_set = data.set;
552 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
554 GtkComboBox *combobox;
558 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
560 g_return_if_fail (self->priv->has_all_option);
562 combobox = GTK_COMBO_BOX (self);
563 model = gtk_combo_box_get_model (combobox);
565 if (gtk_tree_model_get_iter_first (model, &iter))
567 /* 'All accounts' is the first row */
568 gtk_combo_box_set_active_iter (combobox, &iter);
569 self->priv->account_manually_set = TRUE;
574 * empathy_account_chooser_get_has_all_option:
575 * @self: an #EmpathyAccountChooser
577 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
578 * property set to true.
580 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
584 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
586 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
588 return self->priv->has_all_option;
592 * empathy_account_chooser_set_has_all_option:
593 * @self: an #EmpathyAccountChooser
594 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
597 * Sets the #EmpathyAccountChooser:has-all-option property.
600 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
601 gboolean has_all_option)
603 GtkComboBox *combobox;
608 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
610 if (self->priv->has_all_option == has_all_option)
613 combobox = GTK_COMBO_BOX (self);
614 model = gtk_combo_box_get_model (combobox);
615 store = GTK_LIST_STORE (model);
617 self->priv->has_all_option = has_all_option;
620 * The first 2 options are the ALL and separator
625 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
626 (GtkTreeViewRowSeparatorFunc)
627 account_chooser_separator_func,
631 gtk_list_store_prepend (store, &iter);
632 gtk_list_store_set (store, &iter,
633 COL_ACCOUNT_TEXT, NULL,
634 COL_ACCOUNT_ENABLED, TRUE,
635 COL_ACCOUNT_POINTER, NULL,
636 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
639 gtk_list_store_prepend (store, &iter);
640 gtk_list_store_set (store, &iter,
641 COL_ACCOUNT_TEXT, _("All accounts"),
642 COL_ACCOUNT_ENABLED, TRUE,
643 COL_ACCOUNT_POINTER, NULL,
644 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
649 if (gtk_tree_model_get_iter_first (model, &iter))
651 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
652 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
655 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
656 (GtkTreeViewRowSeparatorFunc)
662 g_object_notify (G_OBJECT (self), "has-all-option");
666 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
669 EmpathyAccountChooser *self)
672 account_chooser_account_add_foreach (account, self);
674 account_chooser_account_remove_foreach (account, self);
678 account_chooser_account_add_foreach (TpAccount *account,
679 EmpathyAccountChooser *self)
682 GtkComboBox *combobox;
686 combobox = GTK_COMBO_BOX (self);
687 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
689 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
690 gtk_list_store_insert_with_values (store, &iter, position,
691 COL_ACCOUNT_POINTER, account,
694 account_chooser_update_iter (self, &iter);
698 account_chooser_account_removed_cb (TpAccountManager *manager,
700 EmpathyAccountChooser *self)
702 account_chooser_account_remove_foreach (account, self);
713 account_chooser_find_account_foreach (GtkTreeModel *model,
718 FindAccountData *data = user_data;
722 gtk_tree_model_get (model, iter,
723 COL_ACCOUNT_POINTER, &account,
724 COL_ACCOUNT_ROW_TYPE, &type,
727 if (type != ROW_ACCOUNT)
730 if (account == data->account)
733 *(data->iter) = *iter;
734 g_object_unref (account);
739 g_object_unref (account);
745 account_chooser_find_account (EmpathyAccountChooser *self,
750 GtkComboBox *combobox;
751 FindAccountData data;
753 combobox = GTK_COMBO_BOX (self);
754 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
756 data.account = account;
758 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
759 account_chooser_find_account_foreach,
766 account_chooser_account_remove_foreach (TpAccount *account,
767 EmpathyAccountChooser *self)
770 GtkComboBox *combobox;
773 combobox = GTK_COMBO_BOX (self);
774 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
776 if (account_chooser_find_account (self, account, &iter))
777 gtk_list_store_remove (store, &iter);
781 account_chooser_filter_ready_cb (gboolean is_enabled,
784 FilterResultCallbackData *fr_data = data;
785 EmpathyAccountChooser *self;
789 GtkComboBox *combobox;
790 const gchar *icon_name;
793 self = fr_data->self;
794 account = fr_data->account;
795 iter = fr_data->iter;
796 combobox = GTK_COMBO_BOX (self);
797 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
799 icon_name = tp_account_get_icon_name (account);
800 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
801 GTK_ICON_SIZE_BUTTON);
803 gtk_list_store_set (store, iter,
804 COL_ACCOUNT_IMAGE, pixbuf,
805 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
806 COL_ACCOUNT_ENABLED, is_enabled,
810 g_object_unref (pixbuf);
812 /* set first connected account as active account */
813 if (self->priv->account_manually_set == FALSE &&
814 self->priv->set_active_item == FALSE && is_enabled)
816 self->priv->set_active_item = TRUE;
817 gtk_combo_box_set_active_iter (combobox, iter);
820 filter_result_callback_data_free (fr_data);
824 account_chooser_update_iter (EmpathyAccountChooser *self,
828 GtkComboBox *combobox;
830 FilterResultCallbackData *data;
832 combobox = GTK_COMBO_BOX (self);
833 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
835 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
836 COL_ACCOUNT_POINTER, &account,
839 /* Skip rows without account associated */
843 data = filter_result_callback_data_new (self, account, iter);
845 if (self->priv->filter)
846 self->priv->filter (account, account_chooser_filter_ready_cb,
847 (gpointer) data, self->priv->filter_data);
849 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
851 g_object_unref (account);
855 account_chooser_status_changed_cb (TpAccount *account,
859 gchar *dbus_error_name,
863 EmpathyAccountChooser *self = user_data;
866 if (account_chooser_find_account (self, account, &iter))
867 account_chooser_update_iter (self, &iter);
871 account_chooser_separator_func (GtkTreeModel *model,
873 EmpathyAccountChooser *self)
877 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
878 return (row_type == ROW_SEPARATOR);
882 account_chooser_set_account_foreach (GtkTreeModel *model,
885 SetAccountData *data)
890 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
892 equal = (data->account == account);
895 g_object_unref (account);
899 GtkComboBox *combobox;
901 combobox = GTK_COMBO_BOX (data->self);
902 gtk_combo_box_set_active_iter (combobox, iter);
911 account_chooser_filter_foreach (GtkTreeModel *model,
916 account_chooser_update_iter (self, iter);
921 empathy_account_chooser_refilter (EmpathyAccountChooser *self)
925 self->priv->set_active_item = FALSE;
926 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
927 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
931 * empathy_account_chooser_set_filter:
932 * @self: an #EmpathyAccountChooser
934 * @user_data: data to pass to @filter, or %NULL
936 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
937 * of the filter are visible in the @self.
940 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
941 EmpathyAccountChooserFilterFunc filter,
944 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
946 self->priv->filter = filter;
947 self->priv->filter_data = user_data;
949 /* Refilter existing data */
950 empathy_account_chooser_refilter (self);
954 * EmpathyAccountChooserFilterFunc:
955 * @account: a #TpAccount
956 * @user_data: user data, or %NULL
958 * A function which decides whether the account indicated by @account
961 * Return value: whether the account indicated by @account is visible.
965 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
967 return self->priv->ready;
971 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
975 account = empathy_account_chooser_dup_account (self);
979 g_object_unref (account);
985 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
987 return self->priv->manager;
990 /* Pre-defined filters */
993 * empathy_account_chooser_filter_is_connected:
994 * @account: a #TpAccount
995 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
996 * @callback_data: data passed to the @callback
997 * @user_data: user data or %NULL
999 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1000 * empathy_account_chooser_set_filter() and only show connected accounts.
1002 * Returns (via the callback) TRUE is @account is connected
1005 empathy_account_chooser_filter_is_connected (TpAccount *account,
1006 EmpathyAccountChooserFilterResultCallback callback,
1007 gpointer callback_data,
1010 gboolean is_connected =
1011 tp_account_get_connection_status (account, NULL)
1012 == TP_CONNECTION_STATUS_CONNECTED;
1014 callback (is_connected, callback_data);
1018 * empathy_account_chooser_filter_supports_multichat:
1019 * @account: a #TpAccount
1020 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1021 * @callback_data: data passed to the @callback
1022 * @user_data: user data or %NULL
1024 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1025 * support multiuser text chat and are connected.
1027 * Returns (via the callback) TRUE if @account both supports muc and
1031 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1032 EmpathyAccountChooserFilterResultCallback callback,
1033 gpointer callback_data,
1036 TpConnection *connection;
1037 gboolean supported = FALSE;
1038 TpCapabilities *caps;
1040 /* check if CM supports multiuser text chat */
1041 connection = tp_account_get_connection (account);
1042 if (connection == NULL)
1045 caps = tp_connection_get_capabilities (connection);
1049 supported = tp_capabilities_supports_text_chatrooms (caps);
1052 callback (supported, callback_data);