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 g_return_val_if_fail (self != NULL, NULL);
94 g_return_val_if_fail (account != NULL, NULL);
95 g_return_val_if_fail (iter != NULL, NULL);
97 data = g_slice_new0 (FilterResultCallbackData);
98 data->self = g_object_ref (self);
99 data->account = g_object_ref (account);
100 data->iter = gtk_tree_iter_copy (iter);
106 filter_result_callback_data_free (FilterResultCallbackData *data)
108 g_object_unref (data->self);
109 g_object_unref (data->account);
110 gtk_tree_iter_free (data->iter);
111 g_slice_free (FilterResultCallbackData, data);
114 /* Distinguishes between store entries which are actually accounts, and special
115 * items like the "All" entry and the separator below it, so they can be sorted
116 * correctly. Higher-numbered entries will sort earlier.
127 COL_ACCOUNT_ENABLED, /* Usually tied to connected state */
128 COL_ACCOUNT_ROW_TYPE,
133 static void account_chooser_account_validity_changed_cb (
134 TpAccountManager *manager,
137 EmpathyAccountChooser *self);
138 static void account_chooser_account_add_foreach (TpAccount *account,
139 EmpathyAccountChooser *self);
140 static void account_chooser_account_removed_cb (TpAccountManager *manager,
142 EmpathyAccountChooser *self);
143 static void account_chooser_account_remove_foreach (TpAccount *account,
144 EmpathyAccountChooser *self);
145 static void account_chooser_update_iter (EmpathyAccountChooser *self,
147 static void account_chooser_status_changed_cb (TpAccount *account,
151 gchar *dbus_error_name,
154 static gboolean account_chooser_separator_func (GtkTreeModel *model,
156 EmpathyAccountChooser *self);
157 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
160 SetAccountData *data);
161 static void update_account (EmpathyAccountChooser *self,
163 static gboolean select_account (EmpathyAccountChooser *self,
176 static guint signals[LAST_SIGNAL] = { 0 };
178 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser,
182 empathy_account_chooser_init (EmpathyAccountChooser *self)
184 TpSimpleClientFactory *factory;
186 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
187 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
189 self->priv->set_active_item = FALSE;
190 self->priv->account_manually_set = FALSE;
191 self->priv->filter = NULL;
192 self->priv->filter_data = NULL;
194 self->priv->manager = tp_account_manager_dup ();
196 tp_g_signal_connect_object (self->priv->manager, "account-validity-changed",
197 G_CALLBACK (account_chooser_account_validity_changed_cb), self, 0);
199 tp_g_signal_connect_object (self->priv->manager, "account-removed",
200 G_CALLBACK (account_chooser_account_removed_cb), self, 0);
202 /* Make sure we'll have the capabilities feature on TpAccount's connection */
203 factory = tp_proxy_get_factory (self->priv->manager);
205 tp_simple_client_factory_add_account_features_varargs (factory,
206 TP_ACCOUNT_FEATURE_CONNECTION, NULL);
207 tp_simple_client_factory_add_connection_features_varargs (factory,
208 TP_CONNECTION_FEATURE_CAPABILITIES, NULL);
212 account_cmp (GtkTreeModel *model,
217 RowType a_type, b_type;
218 gboolean a_enabled, b_enabled;
219 gchar *a_text, *b_text;
222 gtk_tree_model_get (model, a,
223 COL_ACCOUNT_ENABLED, &a_enabled,
224 COL_ACCOUNT_ROW_TYPE, &a_type,
226 gtk_tree_model_get (model, b,
227 COL_ACCOUNT_ENABLED, &b_enabled,
228 COL_ACCOUNT_ROW_TYPE, &b_type,
231 /* This assumes that we have at most one of each special row type. */
232 if (a_type != b_type)
233 /* Display higher-numbered special row types first. */
234 return (b_type - a_type);
236 /* Enabled accounts are displayed first */
237 if (a_enabled != b_enabled)
238 return a_enabled ? -1: 1;
240 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
241 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
243 if (a_text == b_text)
245 else if (a_text == NULL)
247 else if (b_text == NULL)
250 result = g_ascii_strcasecmp (a_text, b_text);
259 account_connection_notify_cb (TpAccount *account,
261 EmpathyAccountChooser *self)
263 update_account (self, account);
267 account_manager_prepared_cb (GObject *source_object,
268 GAsyncResult *result,
272 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
273 EmpathyAccountChooser *self = user_data;
274 GError *error = NULL;
276 if (!tp_proxy_prepare_finish (manager, result, &error))
278 DEBUG ("Failed to prepare account manager: %s", error->message);
279 g_error_free (error);
283 accounts = tp_account_manager_dup_valid_accounts (manager);
285 for (l = accounts; l != NULL; l = l->next)
287 TpAccount *account = l->data;
289 account_chooser_account_add_foreach (account, self);
291 tp_g_signal_connect_object (account, "status-changed",
292 G_CALLBACK (account_chooser_status_changed_cb),
295 /* We generally use the TpConnection from the account to filter it so,
296 * just relying on the account status is not enough. In some case we the
297 * status change can be notified while the TpConnection is still
299 tp_g_signal_connect_object (account, "notify::connection",
300 G_CALLBACK (account_connection_notify_cb),
304 g_list_free_full (accounts, g_object_unref);
306 if (self->priv->select_when_ready != NULL)
308 select_account (self, self->priv->select_when_ready);
310 g_clear_object (&self->priv->select_when_ready);
313 self->priv->ready = TRUE;
314 g_signal_emit (self, signals[READY], 0);
318 account_chooser_constructed (GObject *object)
320 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
322 GtkCellRenderer *renderer;
323 GtkComboBox *combobox;
325 /* Set up combo box with new store */
326 combobox = GTK_COMBO_BOX (self);
328 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
330 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
331 GDK_TYPE_PIXBUF, /* Image */
332 G_TYPE_STRING, /* Name */
333 G_TYPE_BOOLEAN, /* Enabled */
334 G_TYPE_UINT, /* Row type */
337 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
338 account_cmp, self, NULL);
339 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
340 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
342 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
344 renderer = gtk_cell_renderer_pixbuf_new ();
345 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
346 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
347 "pixbuf", COL_ACCOUNT_IMAGE,
348 "sensitive", COL_ACCOUNT_ENABLED,
351 renderer = gtk_cell_renderer_text_new ();
352 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
353 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
354 "text", COL_ACCOUNT_TEXT,
355 "sensitive", COL_ACCOUNT_ENABLED,
358 /* Populate accounts */
359 tp_proxy_prepare_async (self->priv->manager, NULL,
360 account_manager_prepared_cb, self);
362 g_object_unref (store);
367 account_chooser_dispose (GObject *object)
369 EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
371 g_clear_object (&self->priv->manager);
372 g_clear_object (&self->priv->select_when_ready);
374 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
378 account_chooser_get_property (GObject *object,
383 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
387 case PROP_HAS_ALL_OPTION:
388 g_value_set_boolean (value, self->priv->has_all_option);
391 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
397 account_chooser_set_property (GObject *object,
404 case PROP_HAS_ALL_OPTION:
405 empathy_account_chooser_set_has_all_option (
406 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
409 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
415 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
417 GObjectClass *object_class = G_OBJECT_CLASS (klass);
419 object_class->constructed = account_chooser_constructed;
420 object_class->dispose = account_chooser_dispose;
421 object_class->get_property = account_chooser_get_property;
422 object_class->set_property = account_chooser_set_property;
425 * EmpathyAccountChooser:has-all-option:
427 * Have an additional option in the list to mean all accounts.
429 g_object_class_install_property (object_class,
431 g_param_spec_boolean ("has-all-option",
433 "Have a separate option in the list to mean ALL accounts",
438 g_signal_new ("ready",
439 G_OBJECT_CLASS_TYPE (object_class),
443 g_cclosure_marshal_generic,
447 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
451 * empathy_account_chooser_new:
453 * Creates a new #EmpathyAccountChooser.
455 * Return value: A new #EmpathyAccountChooser
458 empathy_account_chooser_new (void)
462 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
468 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
474 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
476 g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
478 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
479 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
482 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
484 return type == ROW_ALL;
488 * empathy_account_chooser_dup_account:
489 * @self: an #EmpathyAccountChooser
491 * Returns the account which is currently selected in the chooser or %NULL
492 * if there is no account selected. The #TpAccount returned should be
493 * unrefed with g_object_unref() when finished with.
495 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
498 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
504 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
506 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
507 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
510 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
516 * empathy_account_chooser_get_connection:
517 * @self: an #EmpathyAccountChooser
519 * Returns a borrowed reference to the #TpConnection associated with the
520 * account currently selected. The caller must reference the returned object
521 * with g_object_ref() if it will be kept
523 * Return value: a borrowed reference to the #TpConnection associated with the
524 * account curently selected.
527 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
530 TpConnection *connection;
532 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
534 account = empathy_account_chooser_dup_account (self);
536 /* if the returned account is NULL, then the account manager probably
537 * hasn't been prepared yet. It should be safe to return NULL here
542 connection = tp_account_get_connection (account);
543 g_object_unref (account);
549 select_account (EmpathyAccountChooser *self,
552 GtkComboBox *combobox;
557 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
559 combobox = GTK_COMBO_BOX (self);
560 model = gtk_combo_box_get_model (combobox);
561 gtk_combo_box_get_active_iter (combobox, &iter);
564 data.account = account;
567 gtk_tree_model_foreach (model,
568 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
571 self->priv->account_manually_set = data.set;
577 * empathy_account_chooser_set_account:
578 * @self: an #EmpathyAccountChooser
579 * @account: a #TpAccount
581 * Sets the currently selected account to @account, if it exists in the list.
583 * Return value: whether the chooser was set to @account.
586 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
589 if (self->priv->ready)
590 return select_account (self, account);
592 /* Account chooser is not ready yet, we'll try selecting the account once it
594 g_clear_object (&self->priv->select_when_ready);
597 self->priv->select_when_ready = g_object_ref (account);
603 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
605 GtkComboBox *combobox;
609 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
611 g_return_if_fail (self->priv->has_all_option);
613 combobox = GTK_COMBO_BOX (self);
614 model = gtk_combo_box_get_model (combobox);
616 if (gtk_tree_model_get_iter_first (model, &iter))
618 /* 'All accounts' is the first row */
619 gtk_combo_box_set_active_iter (combobox, &iter);
620 self->priv->account_manually_set = TRUE;
625 * empathy_account_chooser_get_has_all_option:
626 * @self: an #EmpathyAccountChooser
628 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
629 * property set to true.
631 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
635 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
637 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
639 return self->priv->has_all_option;
643 * empathy_account_chooser_set_has_all_option:
644 * @self: an #EmpathyAccountChooser
645 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
648 * Sets the #EmpathyAccountChooser:has-all-option property.
651 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
652 gboolean has_all_option)
654 GtkComboBox *combobox;
659 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
661 if (self->priv->has_all_option == has_all_option)
664 combobox = GTK_COMBO_BOX (self);
665 model = gtk_combo_box_get_model (combobox);
666 store = GTK_LIST_STORE (model);
668 self->priv->has_all_option = has_all_option;
671 * The first 2 options are the ALL and separator
676 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
677 (GtkTreeViewRowSeparatorFunc)
678 account_chooser_separator_func,
682 gtk_list_store_prepend (store, &iter);
683 gtk_list_store_set (store, &iter,
684 COL_ACCOUNT_TEXT, NULL,
685 COL_ACCOUNT_ENABLED, TRUE,
686 COL_ACCOUNT_POINTER, NULL,
687 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
690 gtk_list_store_prepend (store, &iter);
691 gtk_list_store_set (store, &iter,
692 COL_ACCOUNT_TEXT, _("All accounts"),
693 COL_ACCOUNT_ENABLED, TRUE,
694 COL_ACCOUNT_POINTER, NULL,
695 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
700 if (gtk_tree_model_get_iter_first (model, &iter))
702 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
703 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
706 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
707 (GtkTreeViewRowSeparatorFunc)
713 g_object_notify (G_OBJECT (self), "has-all-option");
717 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
720 EmpathyAccountChooser *self)
723 account_chooser_account_add_foreach (account, self);
725 account_chooser_account_remove_foreach (account, self);
729 account_chooser_account_add_foreach (TpAccount *account,
730 EmpathyAccountChooser *self)
733 GtkComboBox *combobox;
737 combobox = GTK_COMBO_BOX (self);
738 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
740 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
741 gtk_list_store_insert_with_values (store, &iter, position,
742 COL_ACCOUNT_POINTER, account,
745 account_chooser_update_iter (self, &iter);
749 account_chooser_account_removed_cb (TpAccountManager *manager,
751 EmpathyAccountChooser *self)
753 account_chooser_account_remove_foreach (account, self);
764 account_chooser_find_account_foreach (GtkTreeModel *model,
769 FindAccountData *data = user_data;
773 gtk_tree_model_get (model, iter,
774 COL_ACCOUNT_POINTER, &account,
775 COL_ACCOUNT_ROW_TYPE, &type,
778 if (type != ROW_ACCOUNT)
781 if (account == data->account)
784 *(data->iter) = *iter;
785 g_object_unref (account);
790 g_object_unref (account);
796 account_chooser_find_account (EmpathyAccountChooser *self,
801 GtkComboBox *combobox;
802 FindAccountData data;
804 combobox = GTK_COMBO_BOX (self);
805 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
807 data.account = account;
809 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
810 account_chooser_find_account_foreach,
817 account_chooser_account_remove_foreach (TpAccount *account,
818 EmpathyAccountChooser *self)
821 GtkComboBox *combobox;
824 combobox = GTK_COMBO_BOX (self);
825 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
827 if (account_chooser_find_account (self, account, &iter))
828 gtk_list_store_remove (store, &iter);
832 account_chooser_filter_ready_cb (gboolean is_enabled,
835 FilterResultCallbackData *fr_data = data;
836 EmpathyAccountChooser *self;
840 GtkComboBox *combobox;
841 const gchar *icon_name;
844 self = fr_data->self;
845 account = fr_data->account;
846 iter = fr_data->iter;
847 combobox = GTK_COMBO_BOX (self);
848 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
850 icon_name = tp_account_get_icon_name (account);
851 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
852 GTK_ICON_SIZE_BUTTON);
854 gtk_list_store_set (store, iter,
855 COL_ACCOUNT_IMAGE, pixbuf,
856 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
857 COL_ACCOUNT_ENABLED, is_enabled,
861 g_object_unref (pixbuf);
863 /* set first connected account as active account */
864 if (self->priv->account_manually_set == FALSE &&
865 self->priv->set_active_item == FALSE && is_enabled)
867 self->priv->set_active_item = TRUE;
868 gtk_combo_box_set_active_iter (combobox, iter);
871 filter_result_callback_data_free (fr_data);
875 account_chooser_update_iter (EmpathyAccountChooser *self,
879 GtkComboBox *combobox;
881 FilterResultCallbackData *data;
883 combobox = GTK_COMBO_BOX (self);
884 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
886 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
887 COL_ACCOUNT_POINTER, &account,
890 /* Skip rows without account associated */
894 data = filter_result_callback_data_new (self, account, iter);
896 if (self->priv->filter)
897 self->priv->filter (account, account_chooser_filter_ready_cb,
898 (gpointer) data, self->priv->filter_data);
900 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
902 g_object_unref (account);
906 update_account (EmpathyAccountChooser *self,
911 if (account_chooser_find_account (self, account, &iter))
912 account_chooser_update_iter (self, &iter);
916 account_chooser_status_changed_cb (TpAccount *account,
920 gchar *dbus_error_name,
924 EmpathyAccountChooser *self = user_data;
926 update_account (self, account);
930 account_chooser_separator_func (GtkTreeModel *model,
932 EmpathyAccountChooser *self)
936 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
937 return (row_type == ROW_SEPARATOR);
941 account_chooser_set_account_foreach (GtkTreeModel *model,
944 SetAccountData *data)
949 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
951 equal = (data->account == account);
954 g_object_unref (account);
958 GtkComboBox *combobox;
960 combobox = GTK_COMBO_BOX (data->self);
961 gtk_combo_box_set_active_iter (combobox, iter);
970 account_chooser_filter_foreach (GtkTreeModel *model,
975 account_chooser_update_iter (self, iter);
980 empathy_account_chooser_refilter (EmpathyAccountChooser *self)
984 self->priv->set_active_item = FALSE;
985 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
986 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
990 * empathy_account_chooser_set_filter:
991 * @self: an #EmpathyAccountChooser
993 * @user_data: data to pass to @filter, or %NULL
995 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
996 * of the filter are visible in the @self.
999 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
1000 EmpathyAccountChooserFilterFunc filter,
1003 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
1005 self->priv->filter = filter;
1006 self->priv->filter_data = user_data;
1008 /* Refilter existing data */
1009 empathy_account_chooser_refilter (self);
1013 * EmpathyAccountChooserFilterFunc:
1014 * @account: a #TpAccount
1015 * @user_data: user data, or %NULL
1017 * A function which decides whether the account indicated by @account
1020 * Return value: whether the account indicated by @account is visible.
1024 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
1026 return self->priv->ready;
1030 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
1034 account = empathy_account_chooser_dup_account (self);
1035 if (account == NULL)
1038 g_object_unref (account);
1044 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
1046 return self->priv->manager;
1049 /* Pre-defined filters */
1052 * empathy_account_chooser_filter_is_connected:
1053 * @account: a #TpAccount
1054 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1055 * @callback_data: data passed to the @callback
1056 * @user_data: user data or %NULL
1058 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1059 * empathy_account_chooser_set_filter() and only show connected accounts.
1061 * Returns (via the callback) TRUE is @account is connected
1064 empathy_account_chooser_filter_is_connected (TpAccount *account,
1065 EmpathyAccountChooserFilterResultCallback callback,
1066 gpointer callback_data,
1069 gboolean is_connected =
1070 tp_account_get_connection_status (account, NULL)
1071 == TP_CONNECTION_STATUS_CONNECTED;
1073 callback (is_connected, callback_data);
1077 * empathy_account_chooser_filter_supports_multichat:
1078 * @account: a #TpAccount
1079 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1080 * @callback_data: data passed to the @callback
1081 * @user_data: user data or %NULL
1083 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1084 * support multiuser text chat and are connected.
1086 * Returns (via the callback) TRUE if @account both supports muc and
1090 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1091 EmpathyAccountChooserFilterResultCallback callback,
1092 gpointer callback_data,
1095 TpConnection *connection;
1096 gboolean supported = FALSE;
1097 TpCapabilities *caps;
1099 /* check if CM supports multiuser text chat */
1100 connection = tp_account_get_connection (account);
1101 if (connection == NULL)
1104 caps = tp_connection_get_capabilities (connection);
1108 supported = tp_capabilities_supports_text_chatrooms (caps);
1111 callback (supported, callback_data);