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 <libempathy/empathy-utils.h>
33 #include "empathy-ui-utils.h"
34 #include "empathy-account-chooser.h"
36 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
37 #include <libempathy/empathy-debug.h>
40 * SECTION:empathy-account-chooser
41 * @title:EmpathyAccountChooser
42 * @short_description: A widget used to choose from a list of accounts
43 * @include: libempathy-gtk/empathy-account-chooser.h
45 * #EmpathyAccountChooser is a widget which extends #GtkComboBox to provide
46 * a chooser of available accounts.
50 * EmpathyAccountChooser:
51 * @parent: parent object
53 * Widget which extends #GtkComboBox to provide a chooser of available accounts.
56 struct _EmpathyAccountChooserPriv
58 TpAccountManager *manager;
59 gboolean set_active_item;
60 gboolean account_manually_set;
61 gboolean has_all_option;
62 EmpathyAccountChooserFilterFunc filter;
66 TpAccount *select_when_ready;
71 EmpathyAccountChooser *self;
78 EmpathyAccountChooser *self;
81 } FilterResultCallbackData;
83 static FilterResultCallbackData *
84 filter_result_callback_data_new (EmpathyAccountChooser *self,
88 FilterResultCallbackData *data;
90 g_return_val_if_fail (self != NULL, NULL);
91 g_return_val_if_fail (account != NULL, NULL);
92 g_return_val_if_fail (iter != NULL, NULL);
94 data = g_slice_new0 (FilterResultCallbackData);
95 data->self = g_object_ref (self);
96 data->account = g_object_ref (account);
97 data->iter = gtk_tree_iter_copy (iter);
103 filter_result_callback_data_free (FilterResultCallbackData *data)
105 g_object_unref (data->self);
106 g_object_unref (data->account);
107 gtk_tree_iter_free (data->iter);
108 g_slice_free (FilterResultCallbackData, data);
111 /* Distinguishes between store entries which are actually accounts, and special
112 * items like the "All" entry and the separator below it, so they can be sorted
113 * correctly. Higher-numbered entries will sort earlier.
124 COL_ACCOUNT_ENABLED, /* Usually tied to connected state */
125 COL_ACCOUNT_ROW_TYPE,
130 static void account_chooser_account_validity_changed_cb (
131 TpAccountManager *manager,
134 EmpathyAccountChooser *self);
135 static void account_chooser_account_add_foreach (TpAccount *account,
136 EmpathyAccountChooser *self);
137 static void account_chooser_account_removed_cb (TpAccountManager *manager,
139 EmpathyAccountChooser *self);
140 static void account_chooser_account_remove_foreach (TpAccount *account,
141 EmpathyAccountChooser *self);
142 static void account_chooser_update_iter (EmpathyAccountChooser *self,
144 static void account_chooser_status_changed_cb (TpAccount *account,
148 gchar *dbus_error_name,
151 static gboolean account_chooser_separator_func (GtkTreeModel *model,
153 EmpathyAccountChooser *self);
154 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
157 SetAccountData *data);
158 static void update_account (EmpathyAccountChooser *self,
160 static gboolean select_account (EmpathyAccountChooser *self,
173 static guint signals[LAST_SIGNAL] = { 0 };
175 G_DEFINE_TYPE (EmpathyAccountChooser, empathy_account_chooser,
179 empathy_account_chooser_init (EmpathyAccountChooser *self)
181 TpSimpleClientFactory *factory;
183 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
184 EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
186 self->priv->set_active_item = FALSE;
187 self->priv->account_manually_set = FALSE;
188 self->priv->filter = NULL;
189 self->priv->filter_data = NULL;
191 self->priv->manager = tp_account_manager_dup ();
193 tp_g_signal_connect_object (self->priv->manager, "account-validity-changed",
194 G_CALLBACK (account_chooser_account_validity_changed_cb), self, 0);
196 tp_g_signal_connect_object (self->priv->manager, "account-removed",
197 G_CALLBACK (account_chooser_account_removed_cb), self, 0);
199 /* Make sure we'll have the capabilities feature on TpAccount's connection */
200 factory = tp_proxy_get_factory (self->priv->manager);
202 tp_simple_client_factory_add_account_features_varargs (factory,
203 TP_ACCOUNT_FEATURE_CONNECTION, NULL);
204 tp_simple_client_factory_add_connection_features_varargs (factory,
205 TP_CONNECTION_FEATURE_CAPABILITIES, NULL);
209 account_cmp (GtkTreeModel *model,
214 RowType a_type, b_type;
215 gboolean a_enabled, b_enabled;
216 gchar *a_text, *b_text;
219 gtk_tree_model_get (model, a,
220 COL_ACCOUNT_ENABLED, &a_enabled,
221 COL_ACCOUNT_ROW_TYPE, &a_type,
223 gtk_tree_model_get (model, b,
224 COL_ACCOUNT_ENABLED, &b_enabled,
225 COL_ACCOUNT_ROW_TYPE, &b_type,
228 /* This assumes that we have at most one of each special row type. */
229 if (a_type != b_type)
230 /* Display higher-numbered special row types first. */
231 return (b_type - a_type);
233 /* Enabled accounts are displayed first */
234 if (a_enabled != b_enabled)
235 return a_enabled ? -1: 1;
237 gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
238 gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
240 if (a_text == b_text)
242 else if (a_text == NULL)
244 else if (b_text == NULL)
247 result = g_ascii_strcasecmp (a_text, b_text);
256 account_connection_notify_cb (TpAccount *account,
258 EmpathyAccountChooser *self)
260 update_account (self, account);
264 account_manager_prepared_cb (GObject *source_object,
265 GAsyncResult *result,
269 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
270 EmpathyAccountChooser *self = user_data;
271 GError *error = NULL;
273 if (!tp_proxy_prepare_finish (manager, result, &error))
275 DEBUG ("Failed to prepare account manager: %s", error->message);
276 g_error_free (error);
280 accounts = tp_account_manager_dup_valid_accounts (manager);
282 for (l = accounts; l != NULL; l = l->next)
284 TpAccount *account = l->data;
286 account_chooser_account_add_foreach (account, self);
288 tp_g_signal_connect_object (account, "status-changed",
289 G_CALLBACK (account_chooser_status_changed_cb),
292 /* We generally use the TpConnection from the account to filter it so,
293 * just relying on the account status is not enough. In some case we the
294 * status change can be notified while the TpConnection is still
296 tp_g_signal_connect_object (account, "notify::connection",
297 G_CALLBACK (account_connection_notify_cb),
301 g_list_free_full (accounts, g_object_unref);
303 if (self->priv->select_when_ready != NULL)
305 select_account (self, self->priv->select_when_ready);
307 g_clear_object (&self->priv->select_when_ready);
310 self->priv->ready = TRUE;
311 g_signal_emit (self, signals[READY], 0);
315 account_chooser_constructed (GObject *object)
317 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
319 GtkCellRenderer *renderer;
320 GtkComboBox *combobox;
322 /* Set up combo box with new store */
323 combobox = GTK_COMBO_BOX (self);
325 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
327 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
328 GDK_TYPE_PIXBUF, /* Image */
329 G_TYPE_STRING, /* Name */
330 G_TYPE_BOOLEAN, /* Enabled */
331 G_TYPE_UINT, /* Row type */
334 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
335 account_cmp, self, NULL);
336 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
337 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
339 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
341 renderer = gtk_cell_renderer_pixbuf_new ();
342 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
343 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
344 "pixbuf", COL_ACCOUNT_IMAGE,
345 "sensitive", COL_ACCOUNT_ENABLED,
348 renderer = gtk_cell_renderer_text_new ();
349 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
350 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
351 "text", COL_ACCOUNT_TEXT,
352 "sensitive", COL_ACCOUNT_ENABLED,
355 /* Populate accounts */
356 tp_proxy_prepare_async (self->priv->manager, NULL,
357 account_manager_prepared_cb, self);
359 g_object_unref (store);
364 account_chooser_dispose (GObject *object)
366 EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
368 g_clear_object (&self->priv->manager);
369 g_clear_object (&self->priv->select_when_ready);
371 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
375 account_chooser_get_property (GObject *object,
380 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
384 case PROP_HAS_ALL_OPTION:
385 g_value_set_boolean (value, self->priv->has_all_option);
388 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
394 account_chooser_set_property (GObject *object,
401 case PROP_HAS_ALL_OPTION:
402 empathy_account_chooser_set_has_all_option (
403 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
406 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
412 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
414 GObjectClass *object_class = G_OBJECT_CLASS (klass);
416 object_class->constructed = account_chooser_constructed;
417 object_class->dispose = account_chooser_dispose;
418 object_class->get_property = account_chooser_get_property;
419 object_class->set_property = account_chooser_set_property;
422 * EmpathyAccountChooser:has-all-option:
424 * Have an additional option in the list to mean all accounts.
426 g_object_class_install_property (object_class,
428 g_param_spec_boolean ("has-all-option",
430 "Have a separate option in the list to mean ALL accounts",
435 g_signal_new ("ready",
436 G_OBJECT_CLASS_TYPE (object_class),
440 g_cclosure_marshal_generic,
444 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
448 * empathy_account_chooser_new:
450 * Creates a new #EmpathyAccountChooser.
452 * Return value: A new #EmpathyAccountChooser
455 empathy_account_chooser_new (void)
459 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
465 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
471 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
473 g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
475 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
476 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
479 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
481 return type == ROW_ALL;
485 * empathy_account_chooser_dup_account:
486 * @self: an #EmpathyAccountChooser
488 * Returns the account which is currently selected in the chooser or %NULL
489 * if there is no account selected. The #TpAccount returned should be
490 * unrefed with g_object_unref() when finished with.
492 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
495 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
501 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
503 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
504 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
507 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
513 * empathy_account_chooser_get_connection:
514 * @self: an #EmpathyAccountChooser
516 * Returns a borrowed reference to the #TpConnection associated with the
517 * account currently selected. The caller must reference the returned object
518 * with g_object_ref() if it will be kept
520 * Return value: a borrowed reference to the #TpConnection associated with the
521 * account curently selected.
524 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
527 TpConnection *connection;
529 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
531 account = empathy_account_chooser_dup_account (self);
533 /* if the returned account is NULL, then the account manager probably
534 * hasn't been prepared yet. It should be safe to return NULL here
539 connection = tp_account_get_connection (account);
540 g_object_unref (account);
546 select_account (EmpathyAccountChooser *self,
549 GtkComboBox *combobox;
554 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
556 combobox = GTK_COMBO_BOX (self);
557 model = gtk_combo_box_get_model (combobox);
558 gtk_combo_box_get_active_iter (combobox, &iter);
561 data.account = account;
564 gtk_tree_model_foreach (model,
565 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
568 self->priv->account_manually_set = data.set;
574 * empathy_account_chooser_set_account:
575 * @self: an #EmpathyAccountChooser
576 * @account: a #TpAccount
578 * Sets the currently selected account to @account, if it exists in the list.
580 * Return value: whether the chooser was set to @account.
583 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
586 if (self->priv->ready)
587 return select_account (self, account);
589 /* Account chooser is not ready yet, we'll try selecting the account once it
591 g_clear_object (&self->priv->select_when_ready);
594 self->priv->select_when_ready = g_object_ref (account);
600 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
602 GtkComboBox *combobox;
606 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
608 g_return_if_fail (self->priv->has_all_option);
610 combobox = GTK_COMBO_BOX (self);
611 model = gtk_combo_box_get_model (combobox);
613 if (gtk_tree_model_get_iter_first (model, &iter))
615 /* 'All accounts' is the first row */
616 gtk_combo_box_set_active_iter (combobox, &iter);
617 self->priv->account_manually_set = TRUE;
622 * empathy_account_chooser_get_has_all_option:
623 * @self: an #EmpathyAccountChooser
625 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
626 * property set to true.
628 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
632 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
634 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
636 return self->priv->has_all_option;
640 * empathy_account_chooser_set_has_all_option:
641 * @self: an #EmpathyAccountChooser
642 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
645 * Sets the #EmpathyAccountChooser:has-all-option property.
648 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
649 gboolean has_all_option)
651 GtkComboBox *combobox;
656 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
658 if (self->priv->has_all_option == has_all_option)
661 combobox = GTK_COMBO_BOX (self);
662 model = gtk_combo_box_get_model (combobox);
663 store = GTK_LIST_STORE (model);
665 self->priv->has_all_option = has_all_option;
668 * The first 2 options are the ALL and separator
673 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
674 (GtkTreeViewRowSeparatorFunc)
675 account_chooser_separator_func,
679 gtk_list_store_prepend (store, &iter);
680 gtk_list_store_set (store, &iter,
681 COL_ACCOUNT_TEXT, NULL,
682 COL_ACCOUNT_ENABLED, TRUE,
683 COL_ACCOUNT_POINTER, NULL,
684 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
687 gtk_list_store_prepend (store, &iter);
688 gtk_list_store_set (store, &iter,
689 COL_ACCOUNT_TEXT, _("All accounts"),
690 COL_ACCOUNT_ENABLED, TRUE,
691 COL_ACCOUNT_POINTER, NULL,
692 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
697 if (gtk_tree_model_get_iter_first (model, &iter))
699 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
700 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
703 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
704 (GtkTreeViewRowSeparatorFunc)
710 g_object_notify (G_OBJECT (self), "has-all-option");
714 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
717 EmpathyAccountChooser *self)
720 account_chooser_account_add_foreach (account, self);
722 account_chooser_account_remove_foreach (account, self);
726 account_chooser_account_add_foreach (TpAccount *account,
727 EmpathyAccountChooser *self)
730 GtkComboBox *combobox;
734 combobox = GTK_COMBO_BOX (self);
735 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
737 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
738 gtk_list_store_insert_with_values (store, &iter, position,
739 COL_ACCOUNT_POINTER, account,
742 account_chooser_update_iter (self, &iter);
746 account_chooser_account_removed_cb (TpAccountManager *manager,
748 EmpathyAccountChooser *self)
750 account_chooser_account_remove_foreach (account, self);
761 account_chooser_find_account_foreach (GtkTreeModel *model,
766 FindAccountData *data = user_data;
770 gtk_tree_model_get (model, iter,
771 COL_ACCOUNT_POINTER, &account,
772 COL_ACCOUNT_ROW_TYPE, &type,
775 if (type != ROW_ACCOUNT)
778 if (account == data->account)
781 *(data->iter) = *iter;
782 g_object_unref (account);
787 g_object_unref (account);
793 account_chooser_find_account (EmpathyAccountChooser *self,
798 GtkComboBox *combobox;
799 FindAccountData data;
801 combobox = GTK_COMBO_BOX (self);
802 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
804 data.account = account;
806 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
807 account_chooser_find_account_foreach,
814 account_chooser_account_remove_foreach (TpAccount *account,
815 EmpathyAccountChooser *self)
818 GtkComboBox *combobox;
821 combobox = GTK_COMBO_BOX (self);
822 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
824 if (account_chooser_find_account (self, account, &iter))
825 gtk_list_store_remove (store, &iter);
829 account_chooser_filter_ready_cb (gboolean is_enabled,
832 FilterResultCallbackData *fr_data = data;
833 EmpathyAccountChooser *self;
837 GtkComboBox *combobox;
838 const gchar *icon_name;
841 self = fr_data->self;
842 account = fr_data->account;
843 iter = fr_data->iter;
844 combobox = GTK_COMBO_BOX (self);
845 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
847 icon_name = tp_account_get_icon_name (account);
848 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
849 GTK_ICON_SIZE_BUTTON);
851 gtk_list_store_set (store, iter,
852 COL_ACCOUNT_IMAGE, pixbuf,
853 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
854 COL_ACCOUNT_ENABLED, is_enabled,
858 g_object_unref (pixbuf);
860 /* set first connected account as active account */
861 if (self->priv->account_manually_set == FALSE &&
862 self->priv->set_active_item == FALSE && is_enabled)
864 self->priv->set_active_item = TRUE;
865 gtk_combo_box_set_active_iter (combobox, iter);
868 filter_result_callback_data_free (fr_data);
872 account_chooser_update_iter (EmpathyAccountChooser *self,
876 GtkComboBox *combobox;
878 FilterResultCallbackData *data;
880 combobox = GTK_COMBO_BOX (self);
881 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
883 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
884 COL_ACCOUNT_POINTER, &account,
887 /* Skip rows without account associated */
891 data = filter_result_callback_data_new (self, account, iter);
893 if (self->priv->filter)
894 self->priv->filter (account, account_chooser_filter_ready_cb,
895 (gpointer) data, self->priv->filter_data);
897 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
899 g_object_unref (account);
903 update_account (EmpathyAccountChooser *self,
908 if (account_chooser_find_account (self, account, &iter))
909 account_chooser_update_iter (self, &iter);
913 account_chooser_status_changed_cb (TpAccount *account,
917 gchar *dbus_error_name,
921 EmpathyAccountChooser *self = user_data;
923 update_account (self, account);
927 account_chooser_separator_func (GtkTreeModel *model,
929 EmpathyAccountChooser *self)
933 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
934 return (row_type == ROW_SEPARATOR);
938 account_chooser_set_account_foreach (GtkTreeModel *model,
941 SetAccountData *data)
946 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
948 equal = (data->account == account);
951 g_object_unref (account);
955 GtkComboBox *combobox;
957 combobox = GTK_COMBO_BOX (data->self);
958 gtk_combo_box_set_active_iter (combobox, iter);
967 account_chooser_filter_foreach (GtkTreeModel *model,
972 account_chooser_update_iter (self, iter);
977 empathy_account_chooser_refilter (EmpathyAccountChooser *self)
981 self->priv->set_active_item = FALSE;
982 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
983 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
987 * empathy_account_chooser_set_filter:
988 * @self: an #EmpathyAccountChooser
990 * @user_data: data to pass to @filter, or %NULL
992 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
993 * of the filter are visible in the @self.
996 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
997 EmpathyAccountChooserFilterFunc filter,
1000 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
1002 self->priv->filter = filter;
1003 self->priv->filter_data = user_data;
1005 /* Refilter existing data */
1006 empathy_account_chooser_refilter (self);
1010 * EmpathyAccountChooserFilterFunc:
1011 * @account: a #TpAccount
1012 * @user_data: user data, or %NULL
1014 * A function which decides whether the account indicated by @account
1017 * Return value: whether the account indicated by @account is visible.
1021 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
1023 return self->priv->ready;
1027 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
1031 account = empathy_account_chooser_dup_account (self);
1032 if (account == NULL)
1035 g_object_unref (account);
1041 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
1043 return self->priv->manager;
1046 /* Pre-defined filters */
1049 * empathy_account_chooser_filter_is_connected:
1050 * @account: a #TpAccount
1051 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1052 * @callback_data: data passed to the @callback
1053 * @user_data: user data or %NULL
1055 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1056 * empathy_account_chooser_set_filter() and only show connected accounts.
1058 * Returns (via the callback) TRUE is @account is connected
1061 empathy_account_chooser_filter_is_connected (TpAccount *account,
1062 EmpathyAccountChooserFilterResultCallback callback,
1063 gpointer callback_data,
1066 gboolean is_connected =
1067 tp_account_get_connection_status (account, NULL)
1068 == TP_CONNECTION_STATUS_CONNECTED;
1070 callback (is_connected, callback_data);
1074 * empathy_account_chooser_filter_supports_multichat:
1075 * @account: a #TpAccount
1076 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1077 * @callback_data: data passed to the @callback
1078 * @user_data: user data or %NULL
1080 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1081 * support multiuser text chat and are connected.
1083 * Returns (via the callback) TRUE if @account both supports muc and
1087 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1088 EmpathyAccountChooserFilterResultCallback callback,
1089 gpointer callback_data,
1092 TpConnection *connection;
1093 gboolean supported = FALSE;
1094 TpCapabilities *caps;
1096 /* check if CM supports multiuser text chat */
1097 connection = tp_account_get_connection (account);
1098 if (connection == NULL)
1101 caps = tp_connection_get_capabilities (connection);
1105 supported = tp_capabilities_supports_text_chatrooms (caps);
1108 callback (supported, callback_data);