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 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountChooser)
63 TpAccountManager *manager;
64 gboolean set_active_item;
65 gboolean account_manually_set;
66 gboolean has_all_option;
67 EmpathyAccountChooserFilterFunc filter;
70 } EmpathyAccountChooserPriv;
74 EmpathyAccountChooser *self;
81 EmpathyAccountChooser *self;
84 } FilterResultCallbackData;
86 static FilterResultCallbackData *
87 filter_result_callback_data_new (EmpathyAccountChooser *self,
91 FilterResultCallbackData *data;
93 data = g_slice_new0 (FilterResultCallbackData);
94 data->self = g_object_ref (self);
95 data->account = g_object_ref (account);
96 data->iter = gtk_tree_iter_copy (iter);
102 filter_result_callback_data_free (FilterResultCallbackData *data)
104 g_object_unref (data->self);
105 g_object_unref (data->account);
106 gtk_tree_iter_free (data->iter);
107 g_slice_free (FilterResultCallbackData, data);
110 /* Distinguishes between store entries which are actually accounts, and special
111 * items like the "All" entry and the separator below it, so they can be sorted
112 * correctly. Higher-numbered entries will sort earlier.
123 COL_ACCOUNT_ENABLED, /* Usually tied to connected state */
124 COL_ACCOUNT_ROW_TYPE,
129 static void account_chooser_setup (EmpathyAccountChooser *self);
130 static void account_chooser_account_validity_changed_cb (
131 TpAccountManager *manager,
134 EmpathyAccountChooser *self);
135 static void account_chooser_account_add_foreach (TpAccount *account,
136 EmpathyAccountChooser *self);
137 static void account_chooser_account_removed_cb (TpAccountManager *manager,
139 EmpathyAccountChooser *self);
140 static void account_chooser_account_remove_foreach (TpAccount *account,
141 EmpathyAccountChooser*self);
142 static void account_chooser_update_iter (EmpathyAccountChooser *self,
144 static void account_chooser_status_changed_cb (TpAccount *account,
148 gchar *dbus_error_name,
151 static gboolean account_chooser_separator_func (GtkTreeModel *model,
153 EmpathyAccountChooser *self);
154 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
157 SetAccountData *data);
169 static guint signals[LAST_SIGNAL] = { 0 };
171 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser,
175 empathy_account_chooser_init (EmpathyAccountChooser *self)
177 EmpathyAccountChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
178 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
181 priv->set_active_item = FALSE;
182 priv->account_manually_set = FALSE;
184 priv->filter_data = NULL;
186 priv->manager = tp_account_manager_dup ();
188 g_signal_connect (priv->manager, "account-validity-changed",
189 G_CALLBACK (account_chooser_account_validity_changed_cb),
191 g_signal_connect (priv->manager, "account-removed",
192 G_CALLBACK (account_chooser_account_removed_cb),
197 account_chooser_constructed (GObject *object)
199 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
201 account_chooser_setup (self);
205 account_chooser_finalize (GObject *object)
207 EmpathyAccountChooserPriv *priv = GET_PRIV (object);
209 g_signal_handlers_disconnect_by_func (priv->manager,
210 account_chooser_account_validity_changed_cb,
212 g_signal_handlers_disconnect_by_func (priv->manager,
213 account_chooser_account_removed_cb,
215 g_object_unref (priv->manager);
217 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->finalize (object);
221 account_chooser_get_property (GObject *object,
226 EmpathyAccountChooserPriv *priv;
228 priv = GET_PRIV (object);
232 case PROP_HAS_ALL_OPTION:
233 g_value_set_boolean (value, priv->has_all_option);
236 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
242 account_chooser_set_property (GObject *object,
249 case PROP_HAS_ALL_OPTION:
250 empathy_account_chooser_set_has_all_option (
251 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
260 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
262 GObjectClass *object_class = G_OBJECT_CLASS (klass);
264 object_class->constructed = account_chooser_constructed;
265 object_class->finalize = account_chooser_finalize;
266 object_class->get_property = account_chooser_get_property;
267 object_class->set_property = account_chooser_set_property;
270 * EmpathyAccountChooser:has-all-option:
272 * Have an additional option in the list to mean all accounts.
274 g_object_class_install_property (object_class,
276 g_param_spec_boolean ("has-all-option",
278 "Have a separate option in the list to mean ALL accounts",
283 g_signal_new ("ready",
284 G_OBJECT_CLASS_TYPE (object_class),
288 g_cclosure_marshal_generic,
292 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
296 * empathy_account_chooser_new:
298 * Creates a new #EmpathyAccountChooser.
300 * Return value: A new #EmpathyAccountChooser
303 empathy_account_chooser_new (void)
307 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
313 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
315 EmpathyAccountChooserPriv *priv;
320 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
322 priv = GET_PRIV (self);
324 g_return_val_if_fail (priv->has_all_option == TRUE, FALSE);
326 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
327 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
330 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
332 return type == ROW_ALL;
336 * empathy_account_chooser_dup_account:
337 * @self: an #EmpathyAccountChooser
339 * Returns the account which is currently selected in the chooser or %NULL
340 * if there is no account selected. The #TpAccount returned should be
341 * unrefed with g_object_unref() when finished with.
343 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
346 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
352 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
354 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
355 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
358 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
364 * empathy_account_chooser_get_connection:
365 * @self: an #EmpathyAccountChooser
367 * Returns a borrowed reference to the #TpConnection associated with the
368 * account currently selected. The caller must reference the returned object
369 * with g_object_ref() if it will be kept
371 * Return value: a borrowed reference to the #TpConnection associated with the
372 * account curently selected.
375 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
378 TpConnection *connection;
380 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
382 account = empathy_account_chooser_dup_account (self);
384 /* if the returned account is NULL, then the account manager probably
385 * hasn't been prepared yet. It should be safe to return NULL here
390 connection = tp_account_get_connection (account);
391 g_object_unref (account);
397 * empathy_account_chooser_set_account:
398 * @self: an #EmpathyAccountChooser
399 * @account: a #TpAccount
401 * Sets the currently selected account to @account, if it exists in the list.
403 * Return value: whether the chooser was set to @account.
406 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
409 EmpathyAccountChooserPriv *priv;
410 GtkComboBox *combobox;
415 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
417 priv = GET_PRIV (self);
419 combobox = GTK_COMBO_BOX (self);
420 model = gtk_combo_box_get_model (combobox);
421 gtk_combo_box_get_active_iter (combobox, &iter);
424 data.account = account;
427 gtk_tree_model_foreach (model,
428 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
431 priv->account_manually_set = data.set;
437 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
439 EmpathyAccountChooserPriv *priv;
440 GtkComboBox *combobox;
444 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
446 priv = GET_PRIV (self);
448 g_return_if_fail (priv->has_all_option);
450 combobox = GTK_COMBO_BOX (self);
451 model = gtk_combo_box_get_model (combobox);
453 if (gtk_tree_model_get_iter_first (model, &iter))
455 /* 'All accounts' is the first row */
456 gtk_combo_box_set_active_iter (combobox, &iter);
457 priv->account_manually_set = TRUE;
462 * empathy_account_chooser_get_has_all_option:
463 * @self: an #EmpathyAccountChooser
465 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
466 * property set to true.
468 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
472 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
474 EmpathyAccountChooserPriv *priv;
476 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
478 priv = GET_PRIV (self);
480 return priv->has_all_option;
484 * empathy_account_chooser_set_has_all_option:
485 * @self: an #EmpathyAccountChooser
486 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
489 * Sets the #EmpathyAccountChooser:has-all-option property.
492 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
493 gboolean has_all_option)
495 EmpathyAccountChooserPriv *priv;
496 GtkComboBox *combobox;
501 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
503 priv = GET_PRIV (self);
505 if (priv->has_all_option == has_all_option)
508 combobox = GTK_COMBO_BOX (self);
509 model = gtk_combo_box_get_model (combobox);
510 store = GTK_LIST_STORE (model);
512 priv->has_all_option = has_all_option;
515 * The first 2 options are the ALL and separator
520 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
521 (GtkTreeViewRowSeparatorFunc)
522 account_chooser_separator_func,
526 gtk_list_store_prepend (store, &iter);
527 gtk_list_store_set (store, &iter,
528 COL_ACCOUNT_TEXT, NULL,
529 COL_ACCOUNT_ENABLED, TRUE,
530 COL_ACCOUNT_POINTER, NULL,
531 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
534 gtk_list_store_prepend (store, &iter);
535 gtk_list_store_set (store, &iter,
536 COL_ACCOUNT_TEXT, _("All accounts"),
537 COL_ACCOUNT_ENABLED, TRUE,
538 COL_ACCOUNT_POINTER, NULL,
539 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
544 if (gtk_tree_model_get_iter_first (model, &iter))
546 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
547 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
550 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
551 (GtkTreeViewRowSeparatorFunc)
557 g_object_notify (G_OBJECT (self), "has-all-option");
561 account_manager_prepared_cb (GObject *source_object,
562 GAsyncResult *result,
566 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
567 EmpathyAccountChooser *self = user_data;
568 EmpathyAccountChooserPriv *priv = GET_PRIV (self);
569 GError *error = NULL;
571 if (!tp_proxy_prepare_finish (manager, result, &error))
573 DEBUG ("Failed to prepare account manager: %s", error->message);
574 g_error_free (error);
578 accounts = tp_account_manager_get_valid_accounts (manager);
580 for (l = accounts; l != NULL; l = l->next)
582 TpAccount *account = l->data;
584 account_chooser_account_add_foreach (account, self);
586 tp_g_signal_connect_object (account, "status-changed",
587 G_CALLBACK (account_chooser_status_changed_cb),
591 g_list_free (accounts);
594 g_signal_emit (self, signals[READY], 0);
598 account_cmp (GtkTreeModel *model,
603 RowType a_type, b_type;
604 gboolean a_enabled, b_enabled;
605 gchar *a_text, *b_text;
608 gtk_tree_model_get (model, a,
609 COL_ACCOUNT_ENABLED, &a_enabled,
610 COL_ACCOUNT_ROW_TYPE, &a_type,
612 gtk_tree_model_get (model, b,
613 COL_ACCOUNT_ENABLED, &b_enabled,
614 COL_ACCOUNT_ROW_TYPE, &b_type,
617 /* This assumes that we have at most one of each special row type. */
618 if (a_type != b_type)
619 /* Display higher-numbered special row types first. */
620 return (b_type - a_type);
622 /* Enabled accounts are displayed first */
623 if (a_enabled != b_enabled)
624 return a_enabled ? -1: 1;
626 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
627 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
629 if (a_text == b_text)
631 else if (a_text == NULL)
633 else if (b_text == NULL)
636 result = g_ascii_strcasecmp (a_text, b_text);
645 account_chooser_setup (EmpathyAccountChooser *self)
647 EmpathyAccountChooserPriv *priv;
649 GtkCellRenderer *renderer;
650 GtkComboBox *combobox;
652 priv = GET_PRIV (self);
654 /* Set up combo box with new store */
655 combobox = GTK_COMBO_BOX (self);
657 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
659 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
660 GDK_TYPE_PIXBUF, /* Image */
661 G_TYPE_STRING, /* Name */
662 G_TYPE_BOOLEAN, /* Enabled */
663 G_TYPE_UINT, /* Row type */
666 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
667 account_cmp, self, NULL);
668 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
669 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
671 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
673 renderer = gtk_cell_renderer_pixbuf_new ();
674 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
675 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
676 "pixbuf", COL_ACCOUNT_IMAGE,
677 "sensitive", COL_ACCOUNT_ENABLED,
680 renderer = gtk_cell_renderer_text_new ();
681 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
682 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
683 "text", COL_ACCOUNT_TEXT,
684 "sensitive", COL_ACCOUNT_ENABLED,
687 /* Populate accounts */
688 tp_proxy_prepare_async (priv->manager, NULL, account_manager_prepared_cb,
691 g_object_unref (store);
695 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
698 EmpathyAccountChooser *self)
701 account_chooser_account_add_foreach (account, self);
703 account_chooser_account_remove_foreach (account, self);
707 account_chooser_account_add_foreach (TpAccount *account,
708 EmpathyAccountChooser *self)
711 GtkComboBox *combobox;
715 combobox = GTK_COMBO_BOX (self);
716 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
718 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
719 gtk_list_store_insert_with_values (store, &iter, position,
720 COL_ACCOUNT_POINTER, account,
723 account_chooser_update_iter (self, &iter);
727 account_chooser_account_removed_cb (TpAccountManager *manager,
729 EmpathyAccountChooser *self)
731 account_chooser_account_remove_foreach (account, self);
742 account_chooser_find_account_foreach (GtkTreeModel *model,
747 FindAccountData *data = user_data;
751 gtk_tree_model_get (model, iter,
752 COL_ACCOUNT_POINTER, &account,
753 COL_ACCOUNT_ROW_TYPE, &type,
756 if (type != ROW_ACCOUNT)
759 if (account == data->account)
762 *(data->iter) = *iter;
763 g_object_unref (account);
768 g_object_unref (account);
774 account_chooser_find_account (EmpathyAccountChooser *self,
779 GtkComboBox *combobox;
780 FindAccountData data;
782 combobox = GTK_COMBO_BOX (self);
783 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
785 data.account = account;
787 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
788 account_chooser_find_account_foreach,
795 account_chooser_account_remove_foreach (TpAccount *account,
796 EmpathyAccountChooser *self)
799 GtkComboBox *combobox;
802 combobox = GTK_COMBO_BOX (self);
803 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
805 if (account_chooser_find_account (self, account, &iter))
806 gtk_list_store_remove (store, &iter);
810 account_chooser_filter_ready_cb (gboolean is_enabled,
813 FilterResultCallbackData *fr_data = data;
814 EmpathyAccountChooser *self;
815 EmpathyAccountChooserPriv *priv;
819 GtkComboBox *combobox;
820 const gchar *icon_name;
823 self = fr_data->self;
824 priv = GET_PRIV (self);
825 account = fr_data->account;
826 iter = fr_data->iter;
827 combobox = GTK_COMBO_BOX (self);
828 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
830 icon_name = tp_account_get_icon_name (account);
831 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
832 GTK_ICON_SIZE_BUTTON);
834 gtk_list_store_set (store, iter,
835 COL_ACCOUNT_IMAGE, pixbuf,
836 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
837 COL_ACCOUNT_ENABLED, is_enabled,
841 g_object_unref (pixbuf);
843 /* set first connected account as active account */
844 if (priv->account_manually_set == FALSE &&
845 priv->set_active_item == FALSE && is_enabled)
847 priv->set_active_item = TRUE;
848 gtk_combo_box_set_active_iter (combobox, iter);
851 filter_result_callback_data_free (fr_data);
855 account_chooser_update_iter (EmpathyAccountChooser *self,
858 EmpathyAccountChooserPriv *priv;
860 GtkComboBox *combobox;
862 FilterResultCallbackData *data;
864 priv = GET_PRIV (self);
866 combobox = GTK_COMBO_BOX (self);
867 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
869 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
870 COL_ACCOUNT_POINTER, &account,
873 /* Skip rows without account associated */
877 data = filter_result_callback_data_new (self, account, iter);
880 priv->filter (account, account_chooser_filter_ready_cb,
881 (gpointer) data, priv->filter_data);
883 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
885 g_object_unref (account);
889 account_chooser_status_changed_cb (TpAccount *account,
893 gchar *dbus_error_name,
897 EmpathyAccountChooser *self = user_data;
900 if (account_chooser_find_account (self, account, &iter))
901 account_chooser_update_iter (self, &iter);
905 account_chooser_separator_func (GtkTreeModel *model,
907 EmpathyAccountChooser *self)
911 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
912 return (row_type == ROW_SEPARATOR);
916 account_chooser_set_account_foreach (GtkTreeModel *model,
919 SetAccountData *data)
924 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
926 equal = (data->account == account);
929 g_object_unref (account);
933 GtkComboBox *combobox;
935 combobox = GTK_COMBO_BOX (data->self);
936 gtk_combo_box_set_active_iter (combobox, iter);
945 account_chooser_filter_foreach (GtkTreeModel *model,
950 account_chooser_update_iter (self, iter);
955 * empathy_account_chooser_set_filter:
956 * @self: an #EmpathyAccountChooser
958 * @user_data: data to pass to @filter, or %NULL
960 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
961 * of the filter are visible in the @self.
964 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
965 EmpathyAccountChooserFilterFunc filter,
968 EmpathyAccountChooserPriv *priv;
971 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
973 priv = GET_PRIV (self);
975 priv->filter = filter;
976 priv->filter_data = user_data;
978 /* Refilter existing data */
979 priv->set_active_item = FALSE;
980 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
981 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
985 * EmpathyAccountChooserFilterFunc:
986 * @account: a #TpAccount
987 * @user_data: user data, or %NULL
989 * A function which decides whether the account indicated by @account
992 * Return value: whether the account indicated by @account is visible.
996 * empathy_account_chooser_filter_is_connected:
997 * @account: a #TpAccount
998 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
999 * @callback_data: data passed to the @callback
1000 * @user_data: user data or %NULL
1002 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1003 * empathy_account_chooser_set_filter() and only show connected accounts.
1005 * Returns (via the callback) TRUE is @account is connected
1008 empathy_account_chooser_filter_is_connected (TpAccount *account,
1009 EmpathyAccountChooserFilterResultCallback callback,
1010 gpointer callback_data,
1013 gboolean is_connected =
1014 tp_account_get_connection_status (account, NULL)
1015 == TP_CONNECTION_STATUS_CONNECTED;
1017 callback (is_connected, callback_data);
1021 * empathy_account_chooser_filter_supports_multichat:
1022 * @account: a #TpAccount
1023 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1024 * @callback_data: data passed to the @callback
1025 * @user_data: user data or %NULL
1027 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1028 * support multiuser text chat and are connected.
1030 * Returns (via the callback) TRUE if @account both supports muc and
1034 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1035 EmpathyAccountChooserFilterResultCallback callback,
1036 gpointer callback_data,
1039 TpConnection *connection;
1040 gboolean supported = FALSE;
1041 TpCapabilities *caps;
1043 /* check if CM supports multiuser text chat */
1044 connection = tp_account_get_connection (account);
1045 if (connection == NULL)
1048 caps = tp_connection_get_capabilities (connection);
1052 supported = tp_capabilities_supports_text_chatrooms (caps);
1055 callback (supported, callback_data);
1059 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
1061 EmpathyAccountChooserPriv *priv = GET_PRIV (self);
1067 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
1071 account = empathy_account_chooser_dup_account (self);
1072 if (account == NULL)
1075 g_object_unref (account);
1081 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
1083 EmpathyAccountChooserPriv *priv = GET_PRIV (self);
1085 return priv->manager;