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>
25 #include "empathy-account-chooser.h"
27 #include <glib/gi18n-lib.h>
29 #include "empathy-ui-utils.h"
31 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
32 #include "empathy-debug.h"
35 * SECTION:empathy-account-chooser
36 * @title:EmpathyAccountChooser
37 * @short_description: A widget used to choose from a list of accounts
38 * @include: libempathy-gtk/empathy-account-chooser.h
40 * #EmpathyAccountChooser is a widget which extends #GtkComboBox to provide
41 * a chooser of available accounts.
45 * EmpathyAccountChooser:
46 * @parent: parent object
48 * Widget which extends #GtkComboBox to provide a chooser of available accounts.
51 struct _EmpathyAccountChooserPriv
53 TpAccountManager *manager;
54 gboolean set_active_item;
55 gboolean account_manually_set;
56 gboolean has_all_option;
57 EmpathyAccountChooserFilterFunc filter;
61 TpAccount *select_when_ready;
66 EmpathyAccountChooser *self;
73 EmpathyAccountChooser *self;
76 } FilterResultCallbackData;
78 static FilterResultCallbackData *
79 filter_result_callback_data_new (EmpathyAccountChooser *self,
83 FilterResultCallbackData *data;
85 g_return_val_if_fail (self != NULL, NULL);
86 g_return_val_if_fail (account != NULL, NULL);
87 g_return_val_if_fail (iter != NULL, NULL);
89 data = g_slice_new0 (FilterResultCallbackData);
90 data->self = g_object_ref (self);
91 data->account = g_object_ref (account);
92 data->iter = gtk_tree_iter_copy (iter);
98 filter_result_callback_data_free (FilterResultCallbackData *data)
100 g_object_unref (data->self);
101 g_object_unref (data->account);
102 gtk_tree_iter_free (data->iter);
103 g_slice_free (FilterResultCallbackData, data);
106 /* Distinguishes between store entries which are actually accounts, and special
107 * items like the "All" entry and the separator below it, so they can be sorted
108 * correctly. Higher-numbered entries will sort earlier.
119 COL_ACCOUNT_ENABLED, /* Usually tied to connected state */
120 COL_ACCOUNT_ROW_TYPE,
125 static void account_chooser_account_validity_changed_cb (
126 TpAccountManager *manager,
129 EmpathyAccountChooser *self);
130 static void account_chooser_account_add_foreach (TpAccount *account,
131 EmpathyAccountChooser *self);
132 static void account_chooser_account_removed_cb (TpAccountManager *manager,
134 EmpathyAccountChooser *self);
135 static void account_chooser_account_remove_foreach (TpAccount *account,
136 EmpathyAccountChooser *self);
137 static void account_chooser_update_iter (EmpathyAccountChooser *self,
139 static void account_chooser_status_changed_cb (TpAccount *account,
143 gchar *dbus_error_name,
146 static gboolean account_chooser_separator_func (GtkTreeModel *model,
148 EmpathyAccountChooser *self);
149 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
152 SetAccountData *data);
153 static void update_account (EmpathyAccountChooser *self,
155 static gboolean select_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_connection_notify_cb (TpAccount *account,
253 EmpathyAccountChooser *self)
255 update_account (self, account);
259 account_manager_prepared_cb (GObject *source_object,
260 GAsyncResult *result,
264 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
265 EmpathyAccountChooser *self = user_data;
266 GError *error = NULL;
268 if (!tp_proxy_prepare_finish (manager, result, &error))
270 DEBUG ("Failed to prepare account manager: %s", error->message);
271 g_error_free (error);
275 accounts = tp_account_manager_dup_valid_accounts (manager);
277 for (l = accounts; l != NULL; l = l->next)
279 TpAccount *account = l->data;
281 account_chooser_account_add_foreach (account, self);
283 tp_g_signal_connect_object (account, "status-changed",
284 G_CALLBACK (account_chooser_status_changed_cb),
287 /* We generally use the TpConnection from the account to filter it so,
288 * just relying on the account status is not enough. In some case we the
289 * status change can be notified while the TpConnection is still
291 tp_g_signal_connect_object (account, "notify::connection",
292 G_CALLBACK (account_connection_notify_cb),
296 g_list_free_full (accounts, g_object_unref);
298 if (self->priv->select_when_ready != NULL)
300 select_account (self, self->priv->select_when_ready);
302 g_clear_object (&self->priv->select_when_ready);
305 self->priv->ready = TRUE;
306 g_signal_emit (self, signals[READY], 0);
310 account_chooser_constructed (GObject *object)
312 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
314 GtkCellRenderer *renderer;
315 GtkComboBox *combobox;
317 /* Set up combo box with new store */
318 combobox = GTK_COMBO_BOX (self);
320 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
322 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
323 GDK_TYPE_PIXBUF, /* Image */
324 G_TYPE_STRING, /* Name */
325 G_TYPE_BOOLEAN, /* Enabled */
326 G_TYPE_UINT, /* Row type */
329 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
330 account_cmp, self, NULL);
331 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
332 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
334 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
336 renderer = gtk_cell_renderer_pixbuf_new ();
337 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
338 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
339 "pixbuf", COL_ACCOUNT_IMAGE,
340 "sensitive", COL_ACCOUNT_ENABLED,
343 renderer = gtk_cell_renderer_text_new ();
344 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
345 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
346 "text", COL_ACCOUNT_TEXT,
347 "sensitive", COL_ACCOUNT_ENABLED,
350 /* Populate accounts */
351 tp_proxy_prepare_async (self->priv->manager, NULL,
352 account_manager_prepared_cb, self);
354 g_object_unref (store);
359 account_chooser_dispose (GObject *object)
361 EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
363 g_clear_object (&self->priv->manager);
364 g_clear_object (&self->priv->select_when_ready);
366 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
370 account_chooser_get_property (GObject *object,
375 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
379 case PROP_HAS_ALL_OPTION:
380 g_value_set_boolean (value, self->priv->has_all_option);
383 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
389 account_chooser_set_property (GObject *object,
396 case PROP_HAS_ALL_OPTION:
397 empathy_account_chooser_set_has_all_option (
398 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
401 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
407 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
409 GObjectClass *object_class = G_OBJECT_CLASS (klass);
411 object_class->constructed = account_chooser_constructed;
412 object_class->dispose = account_chooser_dispose;
413 object_class->get_property = account_chooser_get_property;
414 object_class->set_property = account_chooser_set_property;
417 * EmpathyAccountChooser:has-all-option:
419 * Have an additional option in the list to mean all accounts.
421 g_object_class_install_property (object_class,
423 g_param_spec_boolean ("has-all-option",
425 "Have a separate option in the list to mean ALL accounts",
430 g_signal_new ("ready",
431 G_OBJECT_CLASS_TYPE (object_class),
435 g_cclosure_marshal_generic,
439 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
443 * empathy_account_chooser_new:
445 * Creates a new #EmpathyAccountChooser.
447 * Return value: A new #EmpathyAccountChooser
450 empathy_account_chooser_new (void)
454 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
460 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
466 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
468 g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
470 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
471 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
474 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
476 return type == ROW_ALL;
480 * empathy_account_chooser_dup_account:
481 * @self: an #EmpathyAccountChooser
483 * Returns the account which is currently selected in the chooser or %NULL
484 * if there is no account selected. The #TpAccount returned should be
485 * unrefed with g_object_unref() when finished with.
487 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
490 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
496 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
498 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
499 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
502 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
508 * empathy_account_chooser_get_connection:
509 * @self: an #EmpathyAccountChooser
511 * Returns a borrowed reference to the #TpConnection associated with the
512 * account currently selected. The caller must reference the returned object
513 * with g_object_ref() if it will be kept
515 * Return value: a borrowed reference to the #TpConnection associated with the
516 * account curently selected.
519 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
522 TpConnection *connection;
524 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
526 account = empathy_account_chooser_dup_account (self);
528 /* if the returned account is NULL, then the account manager probably
529 * hasn't been prepared yet. It should be safe to return NULL here
534 connection = tp_account_get_connection (account);
535 g_object_unref (account);
541 select_account (EmpathyAccountChooser *self,
544 GtkComboBox *combobox;
549 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
551 combobox = GTK_COMBO_BOX (self);
552 model = gtk_combo_box_get_model (combobox);
553 gtk_combo_box_get_active_iter (combobox, &iter);
556 data.account = account;
559 gtk_tree_model_foreach (model,
560 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
563 self->priv->account_manually_set = data.set;
569 * empathy_account_chooser_set_account:
570 * @self: an #EmpathyAccountChooser
571 * @account: a #TpAccount
573 * Sets the currently selected account to @account, if it exists in the list.
575 * Return value: whether the chooser was set to @account.
578 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
581 if (self->priv->ready)
582 return select_account (self, account);
584 /* Account chooser is not ready yet, we'll try selecting the account once it
586 g_clear_object (&self->priv->select_when_ready);
589 self->priv->select_when_ready = g_object_ref (account);
595 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
597 GtkComboBox *combobox;
601 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
603 g_return_if_fail (self->priv->has_all_option);
605 combobox = GTK_COMBO_BOX (self);
606 model = gtk_combo_box_get_model (combobox);
608 if (gtk_tree_model_get_iter_first (model, &iter))
610 /* 'All accounts' is the first row */
611 gtk_combo_box_set_active_iter (combobox, &iter);
612 self->priv->account_manually_set = TRUE;
617 * empathy_account_chooser_get_has_all_option:
618 * @self: an #EmpathyAccountChooser
620 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
621 * property set to true.
623 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
627 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
629 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
631 return self->priv->has_all_option;
635 * empathy_account_chooser_set_has_all_option:
636 * @self: an #EmpathyAccountChooser
637 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
640 * Sets the #EmpathyAccountChooser:has-all-option property.
643 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
644 gboolean has_all_option)
646 GtkComboBox *combobox;
651 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
653 if (self->priv->has_all_option == has_all_option)
656 combobox = GTK_COMBO_BOX (self);
657 model = gtk_combo_box_get_model (combobox);
658 store = GTK_LIST_STORE (model);
660 self->priv->has_all_option = has_all_option;
663 * The first 2 options are the ALL and separator
668 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
669 (GtkTreeViewRowSeparatorFunc)
670 account_chooser_separator_func,
674 gtk_list_store_prepend (store, &iter);
675 gtk_list_store_set (store, &iter,
676 COL_ACCOUNT_TEXT, NULL,
677 COL_ACCOUNT_ENABLED, TRUE,
678 COL_ACCOUNT_POINTER, NULL,
679 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
682 gtk_list_store_prepend (store, &iter);
683 gtk_list_store_set (store, &iter,
684 COL_ACCOUNT_TEXT, _("All accounts"),
685 COL_ACCOUNT_ENABLED, TRUE,
686 COL_ACCOUNT_POINTER, NULL,
687 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
692 if (gtk_tree_model_get_iter_first (model, &iter))
694 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
695 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
698 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
699 (GtkTreeViewRowSeparatorFunc)
705 g_object_notify (G_OBJECT (self), "has-all-option");
709 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
712 EmpathyAccountChooser *self)
715 account_chooser_account_add_foreach (account, self);
717 account_chooser_account_remove_foreach (account, self);
721 account_chooser_account_add_foreach (TpAccount *account,
722 EmpathyAccountChooser *self)
725 GtkComboBox *combobox;
729 combobox = GTK_COMBO_BOX (self);
730 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
732 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
733 gtk_list_store_insert_with_values (store, &iter, position,
734 COL_ACCOUNT_POINTER, account,
737 account_chooser_update_iter (self, &iter);
741 account_chooser_account_removed_cb (TpAccountManager *manager,
743 EmpathyAccountChooser *self)
745 account_chooser_account_remove_foreach (account, self);
756 account_chooser_find_account_foreach (GtkTreeModel *model,
761 FindAccountData *data = user_data;
765 gtk_tree_model_get (model, iter,
766 COL_ACCOUNT_POINTER, &account,
767 COL_ACCOUNT_ROW_TYPE, &type,
770 if (type != ROW_ACCOUNT)
773 if (account == data->account)
776 *(data->iter) = *iter;
777 g_object_unref (account);
782 g_object_unref (account);
788 account_chooser_find_account (EmpathyAccountChooser *self,
793 GtkComboBox *combobox;
794 FindAccountData data;
796 combobox = GTK_COMBO_BOX (self);
797 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
799 data.account = account;
801 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
802 account_chooser_find_account_foreach,
809 account_chooser_account_remove_foreach (TpAccount *account,
810 EmpathyAccountChooser *self)
813 GtkComboBox *combobox;
816 combobox = GTK_COMBO_BOX (self);
817 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
819 if (account_chooser_find_account (self, account, &iter))
820 gtk_list_store_remove (store, &iter);
824 account_chooser_filter_ready_cb (gboolean is_enabled,
827 FilterResultCallbackData *fr_data = data;
828 EmpathyAccountChooser *self;
832 GtkComboBox *combobox;
833 const gchar *icon_name;
836 self = fr_data->self;
837 account = fr_data->account;
838 iter = fr_data->iter;
839 combobox = GTK_COMBO_BOX (self);
840 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
842 icon_name = tp_account_get_icon_name (account);
843 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
844 GTK_ICON_SIZE_BUTTON);
846 gtk_list_store_set (store, iter,
847 COL_ACCOUNT_IMAGE, pixbuf,
848 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
849 COL_ACCOUNT_ENABLED, is_enabled,
853 g_object_unref (pixbuf);
855 /* set first connected account as active account */
856 if (self->priv->account_manually_set == FALSE &&
857 self->priv->set_active_item == FALSE && is_enabled)
859 self->priv->set_active_item = TRUE;
860 gtk_combo_box_set_active_iter (combobox, iter);
863 filter_result_callback_data_free (fr_data);
867 account_chooser_update_iter (EmpathyAccountChooser *self,
871 GtkComboBox *combobox;
873 FilterResultCallbackData *data;
875 combobox = GTK_COMBO_BOX (self);
876 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
878 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
879 COL_ACCOUNT_POINTER, &account,
882 /* Skip rows without account associated */
886 data = filter_result_callback_data_new (self, account, iter);
888 if (self->priv->filter)
889 self->priv->filter (account, account_chooser_filter_ready_cb,
890 (gpointer) data, self->priv->filter_data);
892 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
894 g_object_unref (account);
898 update_account (EmpathyAccountChooser *self,
903 if (account_chooser_find_account (self, account, &iter))
904 account_chooser_update_iter (self, &iter);
908 account_chooser_status_changed_cb (TpAccount *account,
912 gchar *dbus_error_name,
916 EmpathyAccountChooser *self = user_data;
918 update_account (self, account);
922 account_chooser_separator_func (GtkTreeModel *model,
924 EmpathyAccountChooser *self)
928 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
929 return (row_type == ROW_SEPARATOR);
933 account_chooser_set_account_foreach (GtkTreeModel *model,
936 SetAccountData *data)
941 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
943 equal = (data->account == account);
946 g_object_unref (account);
950 GtkComboBox *combobox;
952 combobox = GTK_COMBO_BOX (data->self);
953 gtk_combo_box_set_active_iter (combobox, iter);
962 account_chooser_filter_foreach (GtkTreeModel *model,
967 account_chooser_update_iter (self, iter);
972 empathy_account_chooser_refilter (EmpathyAccountChooser *self)
976 self->priv->set_active_item = FALSE;
977 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
978 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
982 * empathy_account_chooser_set_filter:
983 * @self: an #EmpathyAccountChooser
985 * @user_data: data to pass to @filter, or %NULL
987 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
988 * of the filter are visible in the @self.
991 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
992 EmpathyAccountChooserFilterFunc filter,
995 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
997 self->priv->filter = filter;
998 self->priv->filter_data = user_data;
1000 /* Refilter existing data */
1001 empathy_account_chooser_refilter (self);
1005 * EmpathyAccountChooserFilterFunc:
1006 * @account: a #TpAccount
1007 * @user_data: user data, or %NULL
1009 * A function which decides whether the account indicated by @account
1012 * Return value: whether the account indicated by @account is visible.
1016 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
1018 return self->priv->ready;
1022 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
1026 account = empathy_account_chooser_dup_account (self);
1027 if (account == NULL)
1030 g_object_unref (account);
1036 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
1038 return self->priv->manager;
1041 /* Pre-defined filters */
1044 * empathy_account_chooser_filter_is_connected:
1045 * @account: a #TpAccount
1046 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1047 * @callback_data: data passed to the @callback
1048 * @user_data: user data or %NULL
1050 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1051 * empathy_account_chooser_set_filter() and only show connected accounts.
1053 * Returns (via the callback) TRUE is @account is connected
1056 empathy_account_chooser_filter_is_connected (TpAccount *account,
1057 EmpathyAccountChooserFilterResultCallback callback,
1058 gpointer callback_data,
1061 gboolean is_connected =
1062 tp_account_get_connection_status (account, NULL)
1063 == TP_CONNECTION_STATUS_CONNECTED;
1065 callback (is_connected, callback_data);
1069 * empathy_account_chooser_filter_supports_multichat:
1070 * @account: a #TpAccount
1071 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1072 * @callback_data: data passed to the @callback
1073 * @user_data: user data or %NULL
1075 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1076 * support multiuser text chat and are connected.
1078 * Returns (via the callback) TRUE if @account both supports muc and
1082 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1083 EmpathyAccountChooserFilterResultCallback callback,
1084 gpointer callback_data,
1087 TpConnection *connection;
1088 gboolean supported = FALSE;
1089 TpCapabilities *caps;
1091 /* check if CM supports multiuser text chat */
1092 connection = tp_account_get_connection (account);
1093 if (connection == NULL)
1096 caps = tp_connection_get_capabilities (connection);
1100 supported = tp_capabilities_supports_text_chatrooms (caps);
1103 callback (supported, callback_data);