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;
72 EmpathyAccountChooser *self;
79 EmpathyAccountChooser *self;
82 } FilterResultCallbackData;
84 static FilterResultCallbackData *
85 filter_result_callback_data_new (EmpathyAccountChooser *self,
89 FilterResultCallbackData *data;
91 data = g_slice_new0 (FilterResultCallbackData);
92 data->self = g_object_ref (self);
93 data->account = g_object_ref (account);
94 data->iter = gtk_tree_iter_copy (iter);
100 filter_result_callback_data_free (FilterResultCallbackData *data)
102 g_object_unref (data->self);
103 g_object_unref (data->account);
104 gtk_tree_iter_free (data->iter);
105 g_slice_free (FilterResultCallbackData, data);
108 /* Distinguishes between store entries which are actually accounts, and special
109 * items like the "All" entry and the separator below it, so they can be sorted
110 * correctly. Higher-numbered entries will sort earlier.
121 COL_ACCOUNT_ENABLED, /* Usually tied to connected state */
122 COL_ACCOUNT_ROW_TYPE,
127 static void account_chooser_account_validity_changed_cb (
128 TpAccountManager *manager,
131 EmpathyAccountChooser *self);
132 static void account_chooser_account_add_foreach (TpAccount *account,
133 EmpathyAccountChooser *self);
134 static void account_chooser_account_removed_cb (TpAccountManager *manager,
136 EmpathyAccountChooser *self);
137 static void account_chooser_account_remove_foreach (TpAccount *account,
138 EmpathyAccountChooser*self);
139 static void account_chooser_update_iter (EmpathyAccountChooser *self,
141 static void account_chooser_status_changed_cb (TpAccount *account,
145 gchar *dbus_error_name,
148 static gboolean account_chooser_separator_func (GtkTreeModel *model,
150 EmpathyAccountChooser *self);
151 static gboolean account_chooser_set_account_foreach (GtkTreeModel *model,
154 SetAccountData *data);
155 static void update_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_get_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 (accounts);
298 self->priv->ready = TRUE;
299 g_signal_emit (self, signals[READY], 0);
303 account_chooser_constructed (GObject *object)
305 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
307 GtkCellRenderer *renderer;
308 GtkComboBox *combobox;
310 /* Set up combo box with new store */
311 combobox = GTK_COMBO_BOX (self);
313 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
315 store = gtk_list_store_new (COL_ACCOUNT_COUNT,
316 GDK_TYPE_PIXBUF, /* Image */
317 G_TYPE_STRING, /* Name */
318 G_TYPE_BOOLEAN, /* Enabled */
319 G_TYPE_UINT, /* Row type */
322 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
323 account_cmp, self, NULL);
324 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
325 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
327 gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
329 renderer = gtk_cell_renderer_pixbuf_new ();
330 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
331 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
332 "pixbuf", COL_ACCOUNT_IMAGE,
333 "sensitive", COL_ACCOUNT_ENABLED,
336 renderer = gtk_cell_renderer_text_new ();
337 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
338 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
339 "text", COL_ACCOUNT_TEXT,
340 "sensitive", COL_ACCOUNT_ENABLED,
343 /* Populate accounts */
344 tp_proxy_prepare_async (self->priv->manager, NULL,
345 account_manager_prepared_cb, self);
347 g_object_unref (store);
352 account_chooser_dispose (GObject *object)
354 EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
356 g_clear_object (&self->priv->manager);
358 G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
362 account_chooser_get_property (GObject *object,
367 EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
371 case PROP_HAS_ALL_OPTION:
372 g_value_set_boolean (value, self->priv->has_all_option);
375 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
381 account_chooser_set_property (GObject *object,
388 case PROP_HAS_ALL_OPTION:
389 empathy_account_chooser_set_has_all_option (
390 EMPATHY_ACCOUNT_CHOOSER (object), g_value_get_boolean (value));
393 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
399 empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
401 GObjectClass *object_class = G_OBJECT_CLASS (klass);
403 object_class->constructed = account_chooser_constructed;
404 object_class->dispose = account_chooser_dispose;
405 object_class->get_property = account_chooser_get_property;
406 object_class->set_property = account_chooser_set_property;
409 * EmpathyAccountChooser:has-all-option:
411 * Have an additional option in the list to mean all accounts.
413 g_object_class_install_property (object_class,
415 g_param_spec_boolean ("has-all-option",
417 "Have a separate option in the list to mean ALL accounts",
422 g_signal_new ("ready",
423 G_OBJECT_CLASS_TYPE (object_class),
427 g_cclosure_marshal_generic,
431 g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
435 * empathy_account_chooser_new:
437 * Creates a new #EmpathyAccountChooser.
439 * Return value: A new #EmpathyAccountChooser
442 empathy_account_chooser_new (void)
446 self = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
452 empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
458 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
460 g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
462 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
463 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
466 gtk_tree_model_get (model, &iter, COL_ACCOUNT_ROW_TYPE, &type, -1);
468 return type == ROW_ALL;
472 * empathy_account_chooser_dup_account:
473 * @self: an #EmpathyAccountChooser
475 * Returns the account which is currently selected in the chooser or %NULL
476 * if there is no account selected. The #TpAccount returned should be
477 * unrefed with g_object_unref() when finished with.
479 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
482 empathy_account_chooser_dup_account (EmpathyAccountChooser *self)
488 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
490 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
491 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
494 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
500 * empathy_account_chooser_get_connection:
501 * @self: an #EmpathyAccountChooser
503 * Returns a borrowed reference to the #TpConnection associated with the
504 * account currently selected. The caller must reference the returned object
505 * with g_object_ref() if it will be kept
507 * Return value: a borrowed reference to the #TpConnection associated with the
508 * account curently selected.
511 empathy_account_chooser_get_connection (EmpathyAccountChooser *self)
514 TpConnection *connection;
516 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), NULL);
518 account = empathy_account_chooser_dup_account (self);
520 /* if the returned account is NULL, then the account manager probably
521 * hasn't been prepared yet. It should be safe to return NULL here
526 connection = tp_account_get_connection (account);
527 g_object_unref (account);
533 * empathy_account_chooser_set_account:
534 * @self: an #EmpathyAccountChooser
535 * @account: a #TpAccount
537 * Sets the currently selected account to @account, if it exists in the list.
539 * Return value: whether the chooser was set to @account.
542 empathy_account_chooser_set_account (EmpathyAccountChooser *self,
545 GtkComboBox *combobox;
550 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
552 combobox = GTK_COMBO_BOX (self);
553 model = gtk_combo_box_get_model (combobox);
554 gtk_combo_box_get_active_iter (combobox, &iter);
557 data.account = account;
560 gtk_tree_model_foreach (model,
561 (GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
564 self->priv->account_manually_set = data.set;
570 empathy_account_chooser_set_all (EmpathyAccountChooser *self)
572 GtkComboBox *combobox;
576 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
578 g_return_if_fail (self->priv->has_all_option);
580 combobox = GTK_COMBO_BOX (self);
581 model = gtk_combo_box_get_model (combobox);
583 if (gtk_tree_model_get_iter_first (model, &iter))
585 /* 'All accounts' is the first row */
586 gtk_combo_box_set_active_iter (combobox, &iter);
587 self->priv->account_manually_set = TRUE;
592 * empathy_account_chooser_get_has_all_option:
593 * @self: an #EmpathyAccountChooser
595 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
596 * property set to true.
598 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
602 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
604 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
606 return self->priv->has_all_option;
610 * empathy_account_chooser_set_has_all_option:
611 * @self: an #EmpathyAccountChooser
612 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
615 * Sets the #EmpathyAccountChooser:has-all-option property.
618 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
619 gboolean has_all_option)
621 GtkComboBox *combobox;
626 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
628 if (self->priv->has_all_option == has_all_option)
631 combobox = GTK_COMBO_BOX (self);
632 model = gtk_combo_box_get_model (combobox);
633 store = GTK_LIST_STORE (model);
635 self->priv->has_all_option = has_all_option;
638 * The first 2 options are the ALL and separator
643 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
644 (GtkTreeViewRowSeparatorFunc)
645 account_chooser_separator_func,
649 gtk_list_store_prepend (store, &iter);
650 gtk_list_store_set (store, &iter,
651 COL_ACCOUNT_TEXT, NULL,
652 COL_ACCOUNT_ENABLED, TRUE,
653 COL_ACCOUNT_POINTER, NULL,
654 COL_ACCOUNT_ROW_TYPE, ROW_SEPARATOR,
657 gtk_list_store_prepend (store, &iter);
658 gtk_list_store_set (store, &iter,
659 COL_ACCOUNT_TEXT, _("All accounts"),
660 COL_ACCOUNT_ENABLED, TRUE,
661 COL_ACCOUNT_POINTER, NULL,
662 COL_ACCOUNT_ROW_TYPE, ROW_ALL,
667 if (gtk_tree_model_get_iter_first (model, &iter))
669 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
670 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
673 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
674 (GtkTreeViewRowSeparatorFunc)
680 g_object_notify (G_OBJECT (self), "has-all-option");
684 account_chooser_account_validity_changed_cb (TpAccountManager *manager,
687 EmpathyAccountChooser *self)
690 account_chooser_account_add_foreach (account, self);
692 account_chooser_account_remove_foreach (account, self);
696 account_chooser_account_add_foreach (TpAccount *account,
697 EmpathyAccountChooser *self)
700 GtkComboBox *combobox;
704 combobox = GTK_COMBO_BOX (self);
705 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
707 position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
708 gtk_list_store_insert_with_values (store, &iter, position,
709 COL_ACCOUNT_POINTER, account,
712 account_chooser_update_iter (self, &iter);
716 account_chooser_account_removed_cb (TpAccountManager *manager,
718 EmpathyAccountChooser *self)
720 account_chooser_account_remove_foreach (account, self);
731 account_chooser_find_account_foreach (GtkTreeModel *model,
736 FindAccountData *data = user_data;
740 gtk_tree_model_get (model, iter,
741 COL_ACCOUNT_POINTER, &account,
742 COL_ACCOUNT_ROW_TYPE, &type,
745 if (type != ROW_ACCOUNT)
748 if (account == data->account)
751 *(data->iter) = *iter;
752 g_object_unref (account);
757 g_object_unref (account);
763 account_chooser_find_account (EmpathyAccountChooser *self,
768 GtkComboBox *combobox;
769 FindAccountData data;
771 combobox = GTK_COMBO_BOX (self);
772 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
774 data.account = account;
776 gtk_tree_model_foreach (GTK_TREE_MODEL (store),
777 account_chooser_find_account_foreach,
784 account_chooser_account_remove_foreach (TpAccount *account,
785 EmpathyAccountChooser *self)
788 GtkComboBox *combobox;
791 combobox = GTK_COMBO_BOX (self);
792 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
794 if (account_chooser_find_account (self, account, &iter))
795 gtk_list_store_remove (store, &iter);
799 account_chooser_filter_ready_cb (gboolean is_enabled,
802 FilterResultCallbackData *fr_data = data;
803 EmpathyAccountChooser *self;
807 GtkComboBox *combobox;
808 const gchar *icon_name;
811 self = fr_data->self;
812 account = fr_data->account;
813 iter = fr_data->iter;
814 combobox = GTK_COMBO_BOX (self);
815 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
817 icon_name = tp_account_get_icon_name (account);
818 pixbuf = empathy_pixbuf_from_icon_name (icon_name,
819 GTK_ICON_SIZE_BUTTON);
821 gtk_list_store_set (store, iter,
822 COL_ACCOUNT_IMAGE, pixbuf,
823 COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
824 COL_ACCOUNT_ENABLED, is_enabled,
828 g_object_unref (pixbuf);
830 /* set first connected account as active account */
831 if (self->priv->account_manually_set == FALSE &&
832 self->priv->set_active_item == FALSE && is_enabled)
834 self->priv->set_active_item = TRUE;
835 gtk_combo_box_set_active_iter (combobox, iter);
838 filter_result_callback_data_free (fr_data);
842 account_chooser_update_iter (EmpathyAccountChooser *self,
846 GtkComboBox *combobox;
848 FilterResultCallbackData *data;
850 combobox = GTK_COMBO_BOX (self);
851 store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
853 gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
854 COL_ACCOUNT_POINTER, &account,
857 /* Skip rows without account associated */
861 data = filter_result_callback_data_new (self, account, iter);
863 if (self->priv->filter)
864 self->priv->filter (account, account_chooser_filter_ready_cb,
865 (gpointer) data, self->priv->filter_data);
867 account_chooser_filter_ready_cb (TRUE, (gpointer) data);
869 g_object_unref (account);
873 update_account (EmpathyAccountChooser *self,
878 if (account_chooser_find_account (self, account, &iter))
879 account_chooser_update_iter (self, &iter);
883 account_chooser_status_changed_cb (TpAccount *account,
887 gchar *dbus_error_name,
891 EmpathyAccountChooser *self = user_data;
893 update_account (self, account);
897 account_chooser_separator_func (GtkTreeModel *model,
899 EmpathyAccountChooser *self)
903 gtk_tree_model_get (model, iter, COL_ACCOUNT_ROW_TYPE, &row_type, -1);
904 return (row_type == ROW_SEPARATOR);
908 account_chooser_set_account_foreach (GtkTreeModel *model,
911 SetAccountData *data)
916 gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
918 equal = (data->account == account);
921 g_object_unref (account);
925 GtkComboBox *combobox;
927 combobox = GTK_COMBO_BOX (data->self);
928 gtk_combo_box_set_active_iter (combobox, iter);
937 account_chooser_filter_foreach (GtkTreeModel *model,
942 account_chooser_update_iter (self, iter);
947 empathy_account_chooser_refilter (EmpathyAccountChooser *self)
951 self->priv->set_active_item = FALSE;
952 model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
953 gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
957 * empathy_account_chooser_set_filter:
958 * @self: an #EmpathyAccountChooser
960 * @user_data: data to pass to @filter, or %NULL
962 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
963 * of the filter are visible in the @self.
966 empathy_account_chooser_set_filter (EmpathyAccountChooser *self,
967 EmpathyAccountChooserFilterFunc filter,
970 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
972 self->priv->filter = filter;
973 self->priv->filter_data = user_data;
975 /* Refilter existing data */
976 empathy_account_chooser_refilter (self);
980 * EmpathyAccountChooserFilterFunc:
981 * @account: a #TpAccount
982 * @user_data: user data, or %NULL
984 * A function which decides whether the account indicated by @account
987 * Return value: whether the account indicated by @account is visible.
991 empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
993 return self->priv->ready;
997 empathy_account_chooser_get_account (EmpathyAccountChooser *self)
1001 account = empathy_account_chooser_dup_account (self);
1002 if (account == NULL)
1005 g_object_unref (account);
1011 empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
1013 return self->priv->manager;
1016 /* Pre-defined filters */
1019 * empathy_account_chooser_filter_is_connected:
1020 * @account: a #TpAccount
1021 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1022 * @callback_data: data passed to the @callback
1023 * @user_data: user data or %NULL
1025 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1026 * empathy_account_chooser_set_filter() and only show connected accounts.
1028 * Returns (via the callback) TRUE is @account is connected
1031 empathy_account_chooser_filter_is_connected (TpAccount *account,
1032 EmpathyAccountChooserFilterResultCallback callback,
1033 gpointer callback_data,
1036 gboolean is_connected =
1037 tp_account_get_connection_status (account, NULL)
1038 == TP_CONNECTION_STATUS_CONNECTED;
1040 callback (is_connected, callback_data);
1044 * empathy_account_chooser_filter_supports_multichat:
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 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1051 * support multiuser text chat and are connected.
1053 * Returns (via the callback) TRUE if @account both supports muc and
1057 empathy_account_chooser_filter_supports_chatrooms (TpAccount *account,
1058 EmpathyAccountChooserFilterResultCallback callback,
1059 gpointer callback_data,
1062 TpConnection *connection;
1063 gboolean supported = FALSE;
1064 TpCapabilities *caps;
1066 /* check if CM supports multiuser text chat */
1067 connection = tp_account_get_connection (account);
1068 if (connection == NULL)
1071 caps = tp_connection_get_capabilities (connection);
1075 supported = tp_capabilities_supports_text_chatrooms (caps);
1078 callback (supported, callback_data);