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;
69 TpAccount *select_when_ready;
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);
157 static void update_account (EmpathyAccountChooser *self,
159 static gboolean select_account (EmpathyAccountChooser *self,
172 static guint signals[LAST_SIGNAL] = { 0 };
174 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser,
178 empathy_account_chooser_init (EmpathyAccountChooser *self)
180 TpSimpleClientFactory *factory;
182 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
183 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
185 self->priv->set_active_item = FALSE;
186 self->priv->account_manually_set = FALSE;
187 self->priv->filter = NULL;
188 self->priv->filter_data = NULL;
190 self->priv->manager = tp_account_manager_dup ();
192 tp_g_signal_connect_object (self->priv->manager, "account-validity-changed",
193 G_CALLBACK (account_chooser_account_validity_changed_cb), self, 0);
195 tp_g_signal_connect_object (self->priv->manager, "account-removed",
196 G_CALLBACK (account_chooser_account_removed_cb), self, 0);
198 /* Make sure we'll have the capabilities feature on TpAccount's connection */
199 factory = tp_proxy_get_factory (self->priv->manager);
201 tp_simple_client_factory_add_account_features_varargs (factory,
202 TP_ACCOUNT_FEATURE_CONNECTION, NULL);
203 tp_simple_client_factory_add_connection_features_varargs (factory,
204 TP_CONNECTION_FEATURE_CAPABILITIES, NULL);
208 account_cmp (GtkTreeModel *model,
213 RowType a_type, b_type;
214 gboolean a_enabled, b_enabled;
215 gchar *a_text, *b_text;
218 gtk_tree_model_get (model, a,
219 COL_ACCOUNT_ENABLED, &a_enabled,
220 COL_ACCOUNT_ROW_TYPE, &a_type,
222 gtk_tree_model_get (model, b,
223 COL_ACCOUNT_ENABLED, &b_enabled,
224 COL_ACCOUNT_ROW_TYPE, &b_type,
227 /* This assumes that we have at most one of each special row type. */
228 if (a_type != b_type)
229 /* Display higher-numbered special row types first. */
230 return (b_type - a_type);
232 /* Enabled accounts are displayed first */
233 if (a_enabled != b_enabled)
234 return a_enabled ? -1: 1;
236 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
237 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
239 if (a_text == b_text)
241 else if (a_text == NULL)
243 else if (b_text == NULL)
246 result = g_ascii_strcasecmp (a_text, b_text);
255 account_connection_notify_cb (TpAccount *account,
257 EmpathyAccountChooser *self)
259 update_account (self, account);
263 account_manager_prepared_cb (GObject *source_object,
264 GAsyncResult *result,
268 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
269 EmpathyAccountChooser *self = user_data;
270 GError *error = NULL;
272 if (!tp_proxy_prepare_finish (manager, result, &error))
274 DEBUG ("Failed to prepare account manager: %s", error->message);
275 g_error_free (error);
279 accounts = tp_account_manager_get_valid_accounts (manager);
281 for (l = accounts; l != NULL; l = l->next)
283 TpAccount *account = l->data;
285 account_chooser_account_add_foreach (account, self);
287 tp_g_signal_connect_object (account, "status-changed",
288 G_CALLBACK (account_chooser_status_changed_cb),
291 /* We generally use the TpConnection from the account to filter it so,
292 * just relying on the account status is not enough. In some case we the
293 * status change can be notified while the TpConnection is still
295 tp_g_signal_connect_object (account, "notify::connection",
296 G_CALLBACK (account_connection_notify_cb),
300 g_list_free (accounts);
302 if (self->priv->select_when_ready != NULL)
304 select_account (self, self->priv->select_when_ready);
306 g_clear_object (&self->priv->select_when_ready);
309 self->priv->ready = TRUE;
310 g_signal_emit (self, signals[READY], 0);
314 account_chooser_constructed (GObject *object)
316 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
318 GtkCellRenderer *renderer;
319 GtkComboBox *combobox;
321 /* Set up combo box with new store */
322 combobox = GTK_COMBO_BOX (self);
324 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
326 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
327 GDK_TYPE_PIXBUF, /* Image */
328 G_TYPE_STRING, /* Name */
329 G_TYPE_BOOLEAN, /* Enabled */
330 G_TYPE_UINT, /* Row type */
333 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
334 account_cmp, self, NULL);
335 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
336 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
338 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
340 renderer = gtk_cell_renderer_pixbuf_new ();
341 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
342 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
343 "pixbuf", COL_ACCOUNT_IMAGE,
344 "sensitive", COL_ACCOUNT_ENABLED,
347 renderer = gtk_cell_renderer_text_new ();
348 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
349 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
350 "text", COL_ACCOUNT_TEXT,
351 "sensitive", COL_ACCOUNT_ENABLED,
354 /* Populate accounts */
355 tp_proxy_prepare_async (self->priv->manager, NULL,
356 account_manager_prepared_cb, self);
358 g_object_unref (store);
363 account_chooser_dispose (GObject *object)
365 EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
367 g_clear_object (&self->priv->manager);
368 g_clear_object (&self->priv->select_when_ready);
370 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
374 account_chooser_get_property (GObject *object,
379 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
383 case PROP_HAS_ALL_OPTION:
384 g_value_set_boolean (value, self->priv->has_all_option);
387 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
393 account_chooser_set_property (GObject *object,
400 case PROP_HAS_ALL_OPTION:
401 empathy_account_chooser_set_has_all_option (
402 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
405 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
411 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
413 GObjectClass *object_class = G_OBJECT_CLASS (klass);
415 object_class->constructed = account_chooser_constructed;
416 object_class->dispose = account_chooser_dispose;
417 object_class->get_property = account_chooser_get_property;
418 object_class->set_property = account_chooser_set_property;
421 * EmpathyAccountChooser:has-all-option:
423 * Have an additional option in the list to mean all accounts.
425 g_object_class_install_property (object_class,
427 g_param_spec_boolean ("has-all-option",
429 "Have a separate option in the list to mean ALL accounts",
434 g_signal_new ("ready",
435 G_OBJECT_CLASS_TYPE (object_class),
439 g_cclosure_marshal_generic,
443 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
447 * empathy_account_chooser_new:
449 * Creates a new #EmpathyAccountChooser.
451 * Return value: A new #EmpathyAccountChooser
454 empathy_account_chooser_new (void)
458 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
464 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
470 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
472 g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
474 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
475 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
478 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
480 return type == ROW_ALL;
484 * empathy_account_chooser_dup_account:
485 * @self: an #EmpathyAccountChooser
487 * Returns the account which is currently selected in the chooser or %NULL
488 * if there is no account selected. The #TpAccount returned should be
489 * unrefed with g_object_unref() when finished with.
491 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
494 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
500 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
502 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
503 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
506 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
512 * empathy_account_chooser_get_connection:
513 * @self: an #EmpathyAccountChooser
515 * Returns a borrowed reference to the #TpConnection associated with the
516 * account currently selected. The caller must reference the returned object
517 * with g_object_ref() if it will be kept
519 * Return value: a borrowed reference to the #TpConnection associated with the
520 * account curently selected.
523 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
526 TpConnection *connection;
528 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
530 account = empathy_account_chooser_dup_account (self);
532 /* if the returned account is NULL, then the account manager probably
533 * hasn't been prepared yet. It should be safe to return NULL here
538 connection = tp_account_get_connection (account);
539 g_object_unref (account);
545 select_account (EmpathyAccountChooser *self,
548 GtkComboBox *combobox;
553 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
555 combobox = GTK_COMBO_BOX (self);
556 model = gtk_combo_box_get_model (combobox);
557 gtk_combo_box_get_active_iter (combobox, &iter);
560 data.account = account;
563 gtk_tree_model_foreach (model,
564 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
567 self->priv->account_manually_set = data.set;
573 * empathy_account_chooser_set_account:
574 * @self: an #EmpathyAccountChooser
575 * @account: a #TpAccount
577 * Sets the currently selected account to @account, if it exists in the list.
579 * Return value: whether the chooser was set to @account.
582 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
585 if (self->priv->ready)
586 return select_account (self, account);
588 /* Account chooser is not ready yet, we'll try selecting the account once it
590 g_clear_object (&self->priv->select_when_ready);
593 self->priv->select_when_ready = g_object_ref (account);
599 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
601 GtkComboBox *combobox;
605 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
607 g_return_if_fail (self->priv->has_all_option);
609 combobox = GTK_COMBO_BOX (self);
610 model = gtk_combo_box_get_model (combobox);
612 if (gtk_tree_model_get_iter_first (model, &iter))
614 /* 'All accounts' is the first row */
615 gtk_combo_box_set_active_iter (combobox, &iter);
616 self->priv->account_manually_set = TRUE;
621 * empathy_account_chooser_get_has_all_option:
622 * @self: an #EmpathyAccountChooser
624 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
625 * property set to true.
627 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
631 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
633 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
635 return self->priv->has_all_option;
639 * empathy_account_chooser_set_has_all_option:
640 * @self: an #EmpathyAccountChooser
641 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
644 * Sets the #EmpathyAccountChooser:has-all-option property.
647 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
648 gboolean has_all_option)
650 GtkComboBox *combobox;
655 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
657 if (self->priv->has_all_option == has_all_option)
660 combobox = GTK_COMBO_BOX (self);
661 model = gtk_combo_box_get_model (combobox);
662 store = GTK_LIST_STORE (model);
664 self->priv->has_all_option = has_all_option;
667 * The first 2 options are the ALL and separator
672 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
673 (GtkTreeViewRowSeparatorFunc)
674 account_chooser_separator_func,
678 gtk_list_store_prepend (store, &iter);
679 gtk_list_store_set (store, &iter,
680 COL_ACCOUNT_TEXT, NULL,
681 COL_ACCOUNT_ENABLED, TRUE,
682 COL_ACCOUNT_POINTER, NULL,
683 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
686 gtk_list_store_prepend (store, &iter);
687 gtk_list_store_set (store, &iter,
688 COL_ACCOUNT_TEXT, _("All accounts"),
689 COL_ACCOUNT_ENABLED, TRUE,
690 COL_ACCOUNT_POINTER, NULL,
691 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
696 if (gtk_tree_model_get_iter_first (model, &iter))
698 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
699 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
702 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
703 (GtkTreeViewRowSeparatorFunc)
709 g_object_notify (G_OBJECT (self), "has-all-option");
713 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
716 EmpathyAccountChooser *self)
719 account_chooser_account_add_foreach (account, self);
721 account_chooser_account_remove_foreach (account, self);
725 account_chooser_account_add_foreach (TpAccount *account,
726 EmpathyAccountChooser *self)
729 GtkComboBox *combobox;
733 combobox = GTK_COMBO_BOX (self);
734 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
736 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
737 gtk_list_store_insert_with_values (store, &iter, position,
738 COL_ACCOUNT_POINTER, account,
741 account_chooser_update_iter (self, &iter);
745 account_chooser_account_removed_cb (TpAccountManager *manager,
747 EmpathyAccountChooser *self)
749 account_chooser_account_remove_foreach (account, self);
760 account_chooser_find_account_foreach (GtkTreeModel *model,
765 FindAccountData *data = user_data;
769 gtk_tree_model_get (model, iter,
770 COL_ACCOUNT_POINTER, &account,
771 COL_ACCOUNT_ROW_TYPE, &type,
774 if (type != ROW_ACCOUNT)
777 if (account == data->account)
780 *(data->iter) = *iter;
781 g_object_unref (account);
786 g_object_unref (account);
792 account_chooser_find_account (EmpathyAccountChooser *self,
797 GtkComboBox *combobox;
798 FindAccountData data;
800 combobox = GTK_COMBO_BOX (self);
801 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
803 data.account = account;
805 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
806 account_chooser_find_account_foreach,
813 account_chooser_account_remove_foreach (TpAccount *account,
814 EmpathyAccountChooser *self)
817 GtkComboBox *combobox;
820 combobox = GTK_COMBO_BOX (self);
821 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
823 if (account_chooser_find_account (self, account, &iter))
824 gtk_list_store_remove (store, &iter);
828 account_chooser_filter_ready_cb (gboolean is_enabled,
831 FilterResultCallbackData *fr_data = data;
832 EmpathyAccountChooser *self;
836 GtkComboBox *combobox;
837 const gchar *icon_name;
840 self = fr_data->self;
841 account = fr_data->account;
842 iter = fr_data->iter;
843 combobox = GTK_COMBO_BOX (self);
844 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
846 icon_name = tp_account_get_icon_name (account);
847 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
848 GTK_ICON_SIZE_BUTTON);
850 gtk_list_store_set (store, iter,
851 COL_ACCOUNT_IMAGE, pixbuf,
852 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
853 COL_ACCOUNT_ENABLED, is_enabled,
857 g_object_unref (pixbuf);
859 /* set first connected account as active account */
860 if (self->priv->account_manually_set == FALSE &&
861 self->priv->set_active_item == FALSE && is_enabled)
863 self->priv->set_active_item = TRUE;
864 gtk_combo_box_set_active_iter (combobox, iter);
867 filter_result_callback_data_free (fr_data);
871 account_chooser_update_iter (EmpathyAccountChooser *self,
875 GtkComboBox *combobox;
877 FilterResultCallbackData *data;
879 combobox = GTK_COMBO_BOX (self);
880 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
882 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
883 COL_ACCOUNT_POINTER, &account,
886 /* Skip rows without account associated */
890 data = filter_result_callback_data_new (self, account, iter);
892 if (self->priv->filter)
893 self->priv->filter (account, account_chooser_filter_ready_cb,
894 (gpointer) data, self->priv->filter_data);
896 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
898 g_object_unref (account);
902 update_account (EmpathyAccountChooser *self,
907 if (account_chooser_find_account (self, account, &iter))
908 account_chooser_update_iter (self, &iter);
912 account_chooser_status_changed_cb (TpAccount *account,
916 gchar *dbus_error_name,
920 EmpathyAccountChooser *self = user_data;
922 update_account (self, account);
926 account_chooser_separator_func (GtkTreeModel *model,
928 EmpathyAccountChooser *self)
932 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
933 return (row_type == ROW_SEPARATOR);
937 account_chooser_set_account_foreach (GtkTreeModel *model,
940 SetAccountData *data)
945 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
947 equal = (data->account == account);
950 g_object_unref (account);
954 GtkComboBox *combobox;
956 combobox = GTK_COMBO_BOX (data->self);
957 gtk_combo_box_set_active_iter (combobox, iter);
966 account_chooser_filter_foreach (GtkTreeModel *model,
971 account_chooser_update_iter (self, iter);
976 empathy_account_chooser_refilter (EmpathyAccountChooser *self)
980 self->priv->set_active_item = FALSE;
981 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
982 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
986 * empathy_account_chooser_set_filter:
987 * @self: an #EmpathyAccountChooser
989 * @user_data: data to pass to @filter, or %NULL
991 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
992 * of the filter are visible in the @self.
995 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
996 EmpathyAccountChooserFilterFunc filter,
999 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
1001 self->priv->filter = filter;
1002 self->priv->filter_data = user_data;
1004 /* Refilter existing data */
1005 empathy_account_chooser_refilter (self);
1009 * EmpathyAccountChooserFilterFunc:
1010 * @account: a #TpAccount
1011 * @user_data: user data, or %NULL
1013 * A function which decides whether the account indicated by @account
1016 * Return value: whether the account indicated by @account is visible.
1020 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
1022 return self->priv->ready;
1026 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
1030 account = empathy_account_chooser_dup_account (self);
1031 if (account == NULL)
1034 g_object_unref (account);
1040 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
1042 return self->priv->manager;
1045 /* Pre-defined filters */
1048 * empathy_account_chooser_filter_is_connected:
1049 * @account: a #TpAccount
1050 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1051 * @callback_data: data passed to the @callback
1052 * @user_data: user data or %NULL
1054 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1055 * empathy_account_chooser_set_filter() and only show connected accounts.
1057 * Returns (via the callback) TRUE is @account is connected
1060 empathy_account_chooser_filter_is_connected (TpAccount *account,
1061 EmpathyAccountChooserFilterResultCallback callback,
1062 gpointer callback_data,
1065 gboolean is_connected =
1066 tp_account_get_connection_status (account, NULL)
1067 == TP_CONNECTION_STATUS_CONNECTED;
1069 callback (is_connected, callback_data);
1073 * empathy_account_chooser_filter_supports_multichat:
1074 * @account: a #TpAccount
1075 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1076 * @callback_data: data passed to the @callback
1077 * @user_data: user data or %NULL
1079 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1080 * support multiuser text chat and are connected.
1082 * Returns (via the callback) TRUE if @account both supports muc and
1086 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1087 EmpathyAccountChooserFilterResultCallback callback,
1088 gpointer callback_data,
1091 TpConnection *connection;
1092 gboolean supported = FALSE;
1093 TpCapabilities *caps;
1095 /* check if CM supports multiuser text chat */
1096 connection = tp_account_get_connection (account);
1097 if (connection == NULL)
1100 caps = tp_connection_get_capabilities (connection);
1104 supported = tp_capabilities_supports_text_chatrooms (caps);
1107 callback (supported, callback_data);