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_account_validity_changed_cb (
130 TpAccountManager *manager,
133 EmpathyAccountChooser *self);
134 static void account_chooser_account_add_foreach (TpAccount *account,
135 EmpathyAccountChooser *self);
136 static void account_chooser_account_removed_cb (TpAccountManager *manager,
138 EmpathyAccountChooser *self);
139 static void account_chooser_account_remove_foreach (TpAccount *account,
140 EmpathyAccountChooser*self);
141 static void account_chooser_update_iter (EmpathyAccountChooser *self,
143 static void account_chooser_status_changed_cb (TpAccount *account,
147 gchar *dbus_error_name,
150 static gboolean account_chooser_separator_func (GtkTreeModel *model,
152 EmpathyAccountChooser *self);
153 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
156 SetAccountData *data);
168 static guint signals[LAST_SIGNAL] = { 0 };
170 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser,
174 empathy_account_chooser_init (EmpathyAccountChooser *self)
176 EmpathyAccountChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
177 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
180 priv->set_active_item = FALSE;
181 priv->account_manually_set = FALSE;
183 priv->filter_data = NULL;
185 priv->manager = tp_account_manager_dup ();
187 g_signal_connect (priv->manager, "account-validity-changed",
188 G_CALLBACK (account_chooser_account_validity_changed_cb),
190 g_signal_connect (priv->manager, "account-removed",
191 G_CALLBACK (account_chooser_account_removed_cb),
196 account_cmp (GtkTreeModel *model,
201 RowType a_type, b_type;
202 gboolean a_enabled, b_enabled;
203 gchar *a_text, *b_text;
206 gtk_tree_model_get (model, a,
207 COL_ACCOUNT_ENABLED, &a_enabled,
208 COL_ACCOUNT_ROW_TYPE, &a_type,
210 gtk_tree_model_get (model, b,
211 COL_ACCOUNT_ENABLED, &b_enabled,
212 COL_ACCOUNT_ROW_TYPE, &b_type,
215 /* This assumes that we have at most one of each special row type. */
216 if (a_type != b_type)
217 /* Display higher-numbered special row types first. */
218 return (b_type - a_type);
220 /* Enabled accounts are displayed first */
221 if (a_enabled != b_enabled)
222 return a_enabled ? -1: 1;
224 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
225 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
227 if (a_text == b_text)
229 else if (a_text == NULL)
231 else if (b_text == NULL)
234 result = g_ascii_strcasecmp (a_text, b_text);
243 account_manager_prepared_cb (GObject *source_object,
244 GAsyncResult *result,
248 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
249 EmpathyAccountChooser *self = user_data;
250 EmpathyAccountChooserPriv *priv = GET_PRIV (self);
251 GError *error = NULL;
253 if (!tp_proxy_prepare_finish (manager, result, &error))
255 DEBUG ("Failed to prepare account manager: %s", error->message);
256 g_error_free (error);
260 accounts = tp_account_manager_get_valid_accounts (manager);
262 for (l = accounts; l != NULL; l = l->next)
264 TpAccount *account = l->data;
266 account_chooser_account_add_foreach (account, self);
268 tp_g_signal_connect_object (account, "status-changed",
269 G_CALLBACK (account_chooser_status_changed_cb),
273 g_list_free (accounts);
276 g_signal_emit (self, signals[READY], 0);
280 account_chooser_constructed (GObject *object)
282 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
283 EmpathyAccountChooserPriv *priv;
285 GtkCellRenderer *renderer;
286 GtkComboBox *combobox;
288 priv = GET_PRIV (self);
290 /* Set up combo box with new store */
291 combobox = GTK_COMBO_BOX (self);
293 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
295 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
296 GDK_TYPE_PIXBUF, /* Image */
297 G_TYPE_STRING, /* Name */
298 G_TYPE_BOOLEAN, /* Enabled */
299 G_TYPE_UINT, /* Row type */
302 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
303 account_cmp, self, NULL);
304 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
305 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
307 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
309 renderer = gtk_cell_renderer_pixbuf_new ();
310 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
311 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
312 "pixbuf", COL_ACCOUNT_IMAGE,
313 "sensitive", COL_ACCOUNT_ENABLED,
316 renderer = gtk_cell_renderer_text_new ();
317 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
318 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
319 "text", COL_ACCOUNT_TEXT,
320 "sensitive", COL_ACCOUNT_ENABLED,
323 /* Populate accounts */
324 tp_proxy_prepare_async (priv->manager, NULL, account_manager_prepared_cb,
327 g_object_unref (store);
332 account_chooser_finalize (GObject *object)
334 EmpathyAccountChooserPriv *priv = GET_PRIV (object);
336 g_signal_handlers_disconnect_by_func (priv->manager,
337 account_chooser_account_validity_changed_cb,
339 g_signal_handlers_disconnect_by_func (priv->manager,
340 account_chooser_account_removed_cb,
342 g_object_unref (priv->manager);
344 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->finalize (object);
348 account_chooser_get_property (GObject *object,
353 EmpathyAccountChooserPriv *priv;
355 priv = GET_PRIV (object);
359 case PROP_HAS_ALL_OPTION:
360 g_value_set_boolean (value, priv->has_all_option);
363 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
369 account_chooser_set_property (GObject *object,
376 case PROP_HAS_ALL_OPTION:
377 empathy_account_chooser_set_has_all_option (
378 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
381 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
387 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
389 GObjectClass *object_class = G_OBJECT_CLASS (klass);
391 object_class->constructed = account_chooser_constructed;
392 object_class->finalize = account_chooser_finalize;
393 object_class->get_property = account_chooser_get_property;
394 object_class->set_property = account_chooser_set_property;
397 * EmpathyAccountChooser:has-all-option:
399 * Have an additional option in the list to mean all accounts.
401 g_object_class_install_property (object_class,
403 g_param_spec_boolean ("has-all-option",
405 "Have a separate option in the list to mean ALL accounts",
410 g_signal_new ("ready",
411 G_OBJECT_CLASS_TYPE (object_class),
415 g_cclosure_marshal_generic,
419 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
423 * empathy_account_chooser_new:
425 * Creates a new #EmpathyAccountChooser.
427 * Return value: A new #EmpathyAccountChooser
430 empathy_account_chooser_new (void)
434 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
440 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
442 EmpathyAccountChooserPriv *priv;
447 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
449 priv = GET_PRIV (self);
451 g_return_val_if_fail (priv->has_all_option == TRUE, FALSE);
453 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
454 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
457 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
459 return type == ROW_ALL;
463 * empathy_account_chooser_dup_account:
464 * @self: an #EmpathyAccountChooser
466 * Returns the account which is currently selected in the chooser or %NULL
467 * if there is no account selected. The #TpAccount returned should be
468 * unrefed with g_object_unref() when finished with.
470 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
473 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
479 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
481 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
482 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
485 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
491 * empathy_account_chooser_get_connection:
492 * @self: an #EmpathyAccountChooser
494 * Returns a borrowed reference to the #TpConnection associated with the
495 * account currently selected. The caller must reference the returned object
496 * with g_object_ref() if it will be kept
498 * Return value: a borrowed reference to the #TpConnection associated with the
499 * account curently selected.
502 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
505 TpConnection *connection;
507 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
509 account = empathy_account_chooser_dup_account (self);
511 /* if the returned account is NULL, then the account manager probably
512 * hasn't been prepared yet. It should be safe to return NULL here
517 connection = tp_account_get_connection (account);
518 g_object_unref (account);
524 * empathy_account_chooser_set_account:
525 * @self: an #EmpathyAccountChooser
526 * @account: a #TpAccount
528 * Sets the currently selected account to @account, if it exists in the list.
530 * Return value: whether the chooser was set to @account.
533 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
536 EmpathyAccountChooserPriv *priv;
537 GtkComboBox *combobox;
542 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
544 priv = GET_PRIV (self);
546 combobox = GTK_COMBO_BOX (self);
547 model = gtk_combo_box_get_model (combobox);
548 gtk_combo_box_get_active_iter (combobox, &iter);
551 data.account = account;
554 gtk_tree_model_foreach (model,
555 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
558 priv->account_manually_set = data.set;
564 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
566 EmpathyAccountChooserPriv *priv;
567 GtkComboBox *combobox;
571 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
573 priv = GET_PRIV (self);
575 g_return_if_fail (priv->has_all_option);
577 combobox = GTK_COMBO_BOX (self);
578 model = gtk_combo_box_get_model (combobox);
580 if (gtk_tree_model_get_iter_first (model, &iter))
582 /* 'All accounts' is the first row */
583 gtk_combo_box_set_active_iter (combobox, &iter);
584 priv->account_manually_set = TRUE;
589 * empathy_account_chooser_get_has_all_option:
590 * @self: an #EmpathyAccountChooser
592 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
593 * property set to true.
595 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
599 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
601 EmpathyAccountChooserPriv *priv;
603 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
605 priv = GET_PRIV (self);
607 return priv->has_all_option;
611 * empathy_account_chooser_set_has_all_option:
612 * @self: an #EmpathyAccountChooser
613 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
616 * Sets the #EmpathyAccountChooser:has-all-option property.
619 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
620 gboolean has_all_option)
622 EmpathyAccountChooserPriv *priv;
623 GtkComboBox *combobox;
628 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
630 priv = GET_PRIV (self);
632 if (priv->has_all_option == has_all_option)
635 combobox = GTK_COMBO_BOX (self);
636 model = gtk_combo_box_get_model (combobox);
637 store = GTK_LIST_STORE (model);
639 priv->has_all_option = has_all_option;
642 * The first 2 options are the ALL and separator
647 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
648 (GtkTreeViewRowSeparatorFunc)
649 account_chooser_separator_func,
653 gtk_list_store_prepend (store, &iter);
654 gtk_list_store_set (store, &iter,
655 COL_ACCOUNT_TEXT, NULL,
656 COL_ACCOUNT_ENABLED, TRUE,
657 COL_ACCOUNT_POINTER, NULL,
658 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
661 gtk_list_store_prepend (store, &iter);
662 gtk_list_store_set (store, &iter,
663 COL_ACCOUNT_TEXT, _("All accounts"),
664 COL_ACCOUNT_ENABLED, TRUE,
665 COL_ACCOUNT_POINTER, NULL,
666 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
671 if (gtk_tree_model_get_iter_first (model, &iter))
673 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
674 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
677 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
678 (GtkTreeViewRowSeparatorFunc)
684 g_object_notify (G_OBJECT (self), "has-all-option");
688 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
691 EmpathyAccountChooser *self)
694 account_chooser_account_add_foreach (account, self);
696 account_chooser_account_remove_foreach (account, self);
700 account_chooser_account_add_foreach (TpAccount *account,
701 EmpathyAccountChooser *self)
704 GtkComboBox *combobox;
708 combobox = GTK_COMBO_BOX (self);
709 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
711 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
712 gtk_list_store_insert_with_values (store, &iter, position,
713 COL_ACCOUNT_POINTER, account,
716 account_chooser_update_iter (self, &iter);
720 account_chooser_account_removed_cb (TpAccountManager *manager,
722 EmpathyAccountChooser *self)
724 account_chooser_account_remove_foreach (account, self);
735 account_chooser_find_account_foreach (GtkTreeModel *model,
740 FindAccountData *data = user_data;
744 gtk_tree_model_get (model, iter,
745 COL_ACCOUNT_POINTER, &account,
746 COL_ACCOUNT_ROW_TYPE, &type,
749 if (type != ROW_ACCOUNT)
752 if (account == data->account)
755 *(data->iter) = *iter;
756 g_object_unref (account);
761 g_object_unref (account);
767 account_chooser_find_account (EmpathyAccountChooser *self,
772 GtkComboBox *combobox;
773 FindAccountData data;
775 combobox = GTK_COMBO_BOX (self);
776 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
778 data.account = account;
780 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
781 account_chooser_find_account_foreach,
788 account_chooser_account_remove_foreach (TpAccount *account,
789 EmpathyAccountChooser *self)
792 GtkComboBox *combobox;
795 combobox = GTK_COMBO_BOX (self);
796 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
798 if (account_chooser_find_account (self, account, &iter))
799 gtk_list_store_remove (store, &iter);
803 account_chooser_filter_ready_cb (gboolean is_enabled,
806 FilterResultCallbackData *fr_data = data;
807 EmpathyAccountChooser *self;
808 EmpathyAccountChooserPriv *priv;
812 GtkComboBox *combobox;
813 const gchar *icon_name;
816 self = fr_data->self;
817 priv = GET_PRIV (self);
818 account = fr_data->account;
819 iter = fr_data->iter;
820 combobox = GTK_COMBO_BOX (self);
821 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
823 icon_name = tp_account_get_icon_name (account);
824 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
825 GTK_ICON_SIZE_BUTTON);
827 gtk_list_store_set (store, iter,
828 COL_ACCOUNT_IMAGE, pixbuf,
829 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
830 COL_ACCOUNT_ENABLED, is_enabled,
834 g_object_unref (pixbuf);
836 /* set first connected account as active account */
837 if (priv->account_manually_set == FALSE &&
838 priv->set_active_item == FALSE && is_enabled)
840 priv->set_active_item = TRUE;
841 gtk_combo_box_set_active_iter (combobox, iter);
844 filter_result_callback_data_free (fr_data);
848 account_chooser_update_iter (EmpathyAccountChooser *self,
851 EmpathyAccountChooserPriv *priv;
853 GtkComboBox *combobox;
855 FilterResultCallbackData *data;
857 priv = GET_PRIV (self);
859 combobox = GTK_COMBO_BOX (self);
860 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
862 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
863 COL_ACCOUNT_POINTER, &account,
866 /* Skip rows without account associated */
870 data = filter_result_callback_data_new (self, account, iter);
873 priv->filter (account, account_chooser_filter_ready_cb,
874 (gpointer) data, priv->filter_data);
876 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
878 g_object_unref (account);
882 account_chooser_status_changed_cb (TpAccount *account,
886 gchar *dbus_error_name,
890 EmpathyAccountChooser *self = user_data;
893 if (account_chooser_find_account (self, account, &iter))
894 account_chooser_update_iter (self, &iter);
898 account_chooser_separator_func (GtkTreeModel *model,
900 EmpathyAccountChooser *self)
904 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
905 return (row_type == ROW_SEPARATOR);
909 account_chooser_set_account_foreach (GtkTreeModel *model,
912 SetAccountData *data)
917 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
919 equal = (data->account == account);
922 g_object_unref (account);
926 GtkComboBox *combobox;
928 combobox = GTK_COMBO_BOX (data->self);
929 gtk_combo_box_set_active_iter (combobox, iter);
938 account_chooser_filter_foreach (GtkTreeModel *model,
943 account_chooser_update_iter (self, iter);
948 * empathy_account_chooser_set_filter:
949 * @self: an #EmpathyAccountChooser
951 * @user_data: data to pass to @filter, or %NULL
953 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
954 * of the filter are visible in the @self.
957 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
958 EmpathyAccountChooserFilterFunc filter,
961 EmpathyAccountChooserPriv *priv;
964 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
966 priv = GET_PRIV (self);
968 priv->filter = filter;
969 priv->filter_data = user_data;
971 /* Refilter existing data */
972 priv->set_active_item = FALSE;
973 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
974 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
978 * EmpathyAccountChooserFilterFunc:
979 * @account: a #TpAccount
980 * @user_data: user data, or %NULL
982 * A function which decides whether the account indicated by @account
985 * Return value: whether the account indicated by @account is visible.
989 * empathy_account_chooser_filter_is_connected:
990 * @account: a #TpAccount
991 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
992 * @callback_data: data passed to the @callback
993 * @user_data: user data or %NULL
995 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
996 * empathy_account_chooser_set_filter() and only show connected accounts.
998 * Returns (via the callback) TRUE is @account is connected
1001 empathy_account_chooser_filter_is_connected (TpAccount *account,
1002 EmpathyAccountChooserFilterResultCallback callback,
1003 gpointer callback_data,
1006 gboolean is_connected =
1007 tp_account_get_connection_status (account, NULL)
1008 == TP_CONNECTION_STATUS_CONNECTED;
1010 callback (is_connected, callback_data);
1014 * empathy_account_chooser_filter_supports_multichat:
1015 * @account: a #TpAccount
1016 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1017 * @callback_data: data passed to the @callback
1018 * @user_data: user data or %NULL
1020 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1021 * support multiuser text chat and are connected.
1023 * Returns (via the callback) TRUE if @account both supports muc and
1027 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1028 EmpathyAccountChooserFilterResultCallback callback,
1029 gpointer callback_data,
1032 TpConnection *connection;
1033 gboolean supported = FALSE;
1034 TpCapabilities *caps;
1036 /* check if CM supports multiuser text chat */
1037 connection = tp_account_get_connection (account);
1038 if (connection == NULL)
1041 caps = tp_connection_get_capabilities (connection);
1045 supported = tp_capabilities_supports_text_chatrooms (caps);
1048 callback (supported, callback_data);
1052 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
1054 EmpathyAccountChooserPriv *priv = GET_PRIV (self);
1060 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
1064 account = empathy_account_chooser_dup_account (self);
1065 if (account == NULL)
1068 g_object_unref (account);
1074 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
1076 EmpathyAccountChooserPriv *priv = GET_PRIV (self);
1078 return priv->manager;