2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2011 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
25 #include "empathy-account-chooser.h"
27 #include <glib/gi18n-lib.h>
28 #include <tp-account-widgets/tpaw-pixbuf-utils.h>
30 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
31 #include "empathy-debug.h"
34 * SECTION:empathy-account-chooser
35 * @title:EmpathyAccountChooser
36 * @short_description: A widget used to choose from a list of accounts
37 * @include: libempathy-gtk/empathy-account-chooser.h
39 * #EmpathyAccountChooser is a widget which extends #GtkComboBox to provide
40 * a chooser of available accounts.
44 * EmpathyAccountChooser:
45 * @parent: parent object
47 * Widget which extends #GtkComboBox to provide a chooser of available accounts.
50 struct _EmpathyAccountChooserPriv
52 TpAccountManager
*manager
;
53 gboolean set_active_item
;
54 gboolean account_manually_set
;
55 gboolean has_all_option
;
56 EmpathyAccountChooserFilterFunc filter
;
60 TpAccount
*select_when_ready
;
65 EmpathyAccountChooser
*self
;
72 EmpathyAccountChooser
*self
;
75 } FilterResultCallbackData
;
77 static FilterResultCallbackData
*
78 filter_result_callback_data_new (EmpathyAccountChooser
*self
,
82 FilterResultCallbackData
*data
;
84 g_return_val_if_fail (self
!= NULL
, NULL
);
85 g_return_val_if_fail (account
!= NULL
, NULL
);
86 g_return_val_if_fail (iter
!= NULL
, NULL
);
88 data
= g_slice_new0 (FilterResultCallbackData
);
89 data
->self
= g_object_ref (self
);
90 data
->account
= g_object_ref (account
);
91 data
->iter
= gtk_tree_iter_copy (iter
);
97 filter_result_callback_data_free (FilterResultCallbackData
*data
)
99 g_object_unref (data
->self
);
100 g_object_unref (data
->account
);
101 gtk_tree_iter_free (data
->iter
);
102 g_slice_free (FilterResultCallbackData
, data
);
105 /* Distinguishes between store entries which are actually accounts, and special
106 * items like the "All" entry and the separator below it, so they can be sorted
107 * correctly. Higher-numbered entries will sort earlier.
118 COL_ACCOUNT_ENABLED
, /* Usually tied to connected state */
119 COL_ACCOUNT_ROW_TYPE
,
124 static void account_chooser_account_validity_changed_cb (
125 TpAccountManager
*manager
,
128 EmpathyAccountChooser
*self
);
129 static void account_chooser_account_add_foreach (TpAccount
*account
,
130 EmpathyAccountChooser
*self
);
131 static void account_chooser_account_removed_cb (TpAccountManager
*manager
,
133 EmpathyAccountChooser
*self
);
134 static void account_chooser_account_remove_foreach (TpAccount
*account
,
135 EmpathyAccountChooser
*self
);
136 static void account_chooser_update_iter (EmpathyAccountChooser
*self
,
138 static void account_chooser_status_changed_cb (TpAccount
*account
,
142 gchar
*dbus_error_name
,
145 static gboolean
account_chooser_separator_func (GtkTreeModel
*model
,
147 EmpathyAccountChooser
*self
);
148 static gboolean
account_chooser_set_account_foreach (GtkTreeModel
*model
,
151 SetAccountData
*data
);
152 static void update_account (EmpathyAccountChooser
*self
,
154 static gboolean
select_account (EmpathyAccountChooser
*self
,
167 static guint signals
[LAST_SIGNAL
] = { 0 };
169 G_DEFINE_TYPE (EmpathyAccountChooser
, empathy_account_chooser
,
173 empathy_account_chooser_init (EmpathyAccountChooser
*self
)
175 TpSimpleClientFactory
*factory
;
177 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
178 EMPATHY_TYPE_ACCOUNT_CHOOSER
, EmpathyAccountChooserPriv
);
180 self
->priv
->set_active_item
= FALSE
;
181 self
->priv
->account_manually_set
= FALSE
;
182 self
->priv
->filter
= NULL
;
183 self
->priv
->filter_data
= NULL
;
185 self
->priv
->manager
= tp_account_manager_dup ();
187 tp_g_signal_connect_object (self
->priv
->manager
, "account-validity-changed",
188 G_CALLBACK (account_chooser_account_validity_changed_cb
), self
, 0);
190 tp_g_signal_connect_object (self
->priv
->manager
, "account-removed",
191 G_CALLBACK (account_chooser_account_removed_cb
), self
, 0);
193 /* Make sure we'll have the capabilities feature on TpAccount's connection */
194 factory
= tp_proxy_get_factory (self
->priv
->manager
);
196 tp_simple_client_factory_add_account_features_varargs (factory
,
197 TP_ACCOUNT_FEATURE_CONNECTION
, NULL
);
198 tp_simple_client_factory_add_connection_features_varargs (factory
,
199 TP_CONNECTION_FEATURE_CAPABILITIES
, NULL
);
203 account_cmp (GtkTreeModel
*model
,
208 RowType a_type
, b_type
;
209 gboolean a_enabled
, b_enabled
;
210 gchar
*a_text
, *b_text
;
213 gtk_tree_model_get (model
, a
,
214 COL_ACCOUNT_ENABLED
, &a_enabled
,
215 COL_ACCOUNT_ROW_TYPE
, &a_type
,
217 gtk_tree_model_get (model
, b
,
218 COL_ACCOUNT_ENABLED
, &b_enabled
,
219 COL_ACCOUNT_ROW_TYPE
, &b_type
,
222 /* This assumes that we have at most one of each special row type. */
223 if (a_type
!= b_type
)
224 /* Display higher-numbered special row types first. */
225 return (b_type
- a_type
);
227 /* Enabled accounts are displayed first */
228 if (a_enabled
!= b_enabled
)
229 return a_enabled
? -1: 1;
231 gtk_tree_model_get (model
, a
, COL_ACCOUNT_TEXT
, &a_text
, -1);
232 gtk_tree_model_get (model
, b
, COL_ACCOUNT_TEXT
, &b_text
, -1);
234 if (a_text
== b_text
)
236 else if (a_text
== NULL
)
238 else if (b_text
== NULL
)
241 result
= g_ascii_strcasecmp (a_text
, b_text
);
250 account_connection_notify_cb (TpAccount
*account
,
252 EmpathyAccountChooser
*self
)
254 update_account (self
, account
);
258 account_manager_prepared_cb (GObject
*source_object
,
259 GAsyncResult
*result
,
263 TpAccountManager
*manager
= TP_ACCOUNT_MANAGER (source_object
);
264 EmpathyAccountChooser
*self
= user_data
;
265 GError
*error
= NULL
;
267 if (!tp_proxy_prepare_finish (manager
, result
, &error
))
269 DEBUG ("Failed to prepare account manager: %s", error
->message
);
270 g_error_free (error
);
274 accounts
= tp_account_manager_dup_valid_accounts (manager
);
276 for (l
= accounts
; l
!= NULL
; l
= l
->next
)
278 TpAccount
*account
= l
->data
;
280 account_chooser_account_add_foreach (account
, self
);
282 tp_g_signal_connect_object (account
, "status-changed",
283 G_CALLBACK (account_chooser_status_changed_cb
),
286 /* We generally use the TpConnection from the account to filter it so,
287 * just relying on the account status is not enough. In some case we the
288 * status change can be notified while the TpConnection is still
290 tp_g_signal_connect_object (account
, "notify::connection",
291 G_CALLBACK (account_connection_notify_cb
),
295 g_list_free_full (accounts
, g_object_unref
);
297 if (self
->priv
->select_when_ready
!= NULL
)
299 select_account (self
, self
->priv
->select_when_ready
);
301 g_clear_object (&self
->priv
->select_when_ready
);
304 self
->priv
->ready
= TRUE
;
305 g_signal_emit (self
, signals
[READY
], 0);
309 account_chooser_constructed (GObject
*object
)
311 EmpathyAccountChooser
*self
= (EmpathyAccountChooser
*) object
;
313 GtkCellRenderer
*renderer
;
314 GtkComboBox
*combobox
;
316 /* Set up combo box with new store */
317 combobox
= GTK_COMBO_BOX (self
);
319 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox
));
321 store
= gtk_list_store_new (COL_ACCOUNT_COUNT
,
322 GDK_TYPE_PIXBUF
, /* Image */
323 G_TYPE_STRING
, /* Name */
324 G_TYPE_BOOLEAN
, /* Enabled */
325 G_TYPE_UINT
, /* Row type */
328 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store
),
329 account_cmp
, self
, NULL
);
330 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
331 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
, GTK_SORT_ASCENDING
);
333 gtk_combo_box_set_model (combobox
, GTK_TREE_MODEL (store
));
335 renderer
= gtk_cell_renderer_pixbuf_new ();
336 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox
), renderer
, FALSE
);
337 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox
), renderer
,
338 "pixbuf", COL_ACCOUNT_IMAGE
,
339 "sensitive", COL_ACCOUNT_ENABLED
,
342 renderer
= gtk_cell_renderer_text_new ();
343 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox
), renderer
, TRUE
);
344 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox
), renderer
,
345 "text", COL_ACCOUNT_TEXT
,
346 "sensitive", COL_ACCOUNT_ENABLED
,
349 /* Populate accounts */
350 tp_proxy_prepare_async (self
->priv
->manager
, NULL
,
351 account_manager_prepared_cb
, self
);
353 g_object_unref (store
);
358 account_chooser_dispose (GObject
*object
)
360 EmpathyAccountChooser
*self
= EMPATHY_ACCOUNT_CHOOSER (object
);
362 g_clear_object (&self
->priv
->manager
);
363 g_clear_object (&self
->priv
->select_when_ready
);
365 G_OBJECT_CLASS (empathy_account_chooser_parent_class
)->dispose (object
);
369 account_chooser_get_property (GObject
*object
,
374 EmpathyAccountChooser
*self
= (EmpathyAccountChooser
*) object
;
378 case PROP_HAS_ALL_OPTION
:
379 g_value_set_boolean (value
, self
->priv
->has_all_option
);
382 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
388 account_chooser_set_property (GObject
*object
,
395 case PROP_HAS_ALL_OPTION
:
396 empathy_account_chooser_set_has_all_option (
397 EMPATHY_ACCOUNT_CHOOSER (object
), g_value_get_boolean (value
));
400 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
406 empathy_account_chooser_class_init (EmpathyAccountChooserClass
*klass
)
408 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
410 object_class
->constructed
= account_chooser_constructed
;
411 object_class
->dispose
= account_chooser_dispose
;
412 object_class
->get_property
= account_chooser_get_property
;
413 object_class
->set_property
= account_chooser_set_property
;
416 * EmpathyAccountChooser:has-all-option:
418 * Have an additional option in the list to mean all accounts.
420 g_object_class_install_property (object_class
,
422 g_param_spec_boolean ("has-all-option",
424 "Have a separate option in the list to mean ALL accounts",
429 g_signal_new ("ready",
430 G_OBJECT_CLASS_TYPE (object_class
),
434 g_cclosure_marshal_generic
,
438 g_type_class_add_private (object_class
, sizeof (EmpathyAccountChooserPriv
));
442 * empathy_account_chooser_new:
444 * Creates a new #EmpathyAccountChooser.
446 * Return value: A new #EmpathyAccountChooser
449 empathy_account_chooser_new (void)
453 self
= g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER
, NULL
);
459 empathy_account_chooser_has_all_selected (EmpathyAccountChooser
*self
)
465 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), FALSE
);
467 g_return_val_if_fail (self
->priv
->has_all_option
== TRUE
, FALSE
);
469 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (self
));
470 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self
), &iter
))
473 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT_ROW_TYPE
, &type
, -1);
475 return type
== ROW_ALL
;
479 * empathy_account_chooser_dup_account:
480 * @self: an #EmpathyAccountChooser
482 * Returns the account which is currently selected in the chooser or %NULL
483 * if there is no account selected. The #TpAccount returned should be
484 * unrefed with g_object_unref() when finished with.
486 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
489 empathy_account_chooser_dup_account (EmpathyAccountChooser
*self
)
495 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), NULL
);
497 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (self
));
498 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self
), &iter
))
501 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT_POINTER
, &account
, -1);
507 * empathy_account_chooser_get_connection:
508 * @self: an #EmpathyAccountChooser
510 * Returns a borrowed reference to the #TpConnection associated with the
511 * account currently selected. The caller must reference the returned object
512 * with g_object_ref() if it will be kept
514 * Return value: a borrowed reference to the #TpConnection associated with the
515 * account curently selected.
518 empathy_account_chooser_get_connection (EmpathyAccountChooser
*self
)
521 TpConnection
*connection
;
523 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), NULL
);
525 account
= empathy_account_chooser_dup_account (self
);
527 /* if the returned account is NULL, then the account manager probably
528 * hasn't been prepared yet. It should be safe to return NULL here
533 connection
= tp_account_get_connection (account
);
534 g_object_unref (account
);
540 select_account (EmpathyAccountChooser
*self
,
543 GtkComboBox
*combobox
;
548 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), FALSE
);
550 combobox
= GTK_COMBO_BOX (self
);
551 model
= gtk_combo_box_get_model (combobox
);
552 gtk_combo_box_get_active_iter (combobox
, &iter
);
555 data
.account
= account
;
558 gtk_tree_model_foreach (model
,
559 (GtkTreeModelForeachFunc
) account_chooser_set_account_foreach
,
562 self
->priv
->account_manually_set
= data
.set
;
568 * empathy_account_chooser_set_account:
569 * @self: an #EmpathyAccountChooser
570 * @account: a #TpAccount
572 * Sets the currently selected account to @account, if it exists in the list.
574 * Return value: whether the chooser was set to @account.
577 empathy_account_chooser_set_account (EmpathyAccountChooser
*self
,
580 if (self
->priv
->ready
)
581 return select_account (self
, account
);
583 /* Account chooser is not ready yet, we'll try selecting the account once it
585 g_clear_object (&self
->priv
->select_when_ready
);
588 self
->priv
->select_when_ready
= g_object_ref (account
);
594 empathy_account_chooser_set_all (EmpathyAccountChooser
*self
)
596 GtkComboBox
*combobox
;
600 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
));
602 g_return_if_fail (self
->priv
->has_all_option
);
604 combobox
= GTK_COMBO_BOX (self
);
605 model
= gtk_combo_box_get_model (combobox
);
607 if (gtk_tree_model_get_iter_first (model
, &iter
))
609 /* 'All accounts' is the first row */
610 gtk_combo_box_set_active_iter (combobox
, &iter
);
611 self
->priv
->account_manually_set
= TRUE
;
616 * empathy_account_chooser_get_has_all_option:
617 * @self: an #EmpathyAccountChooser
619 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
620 * property set to true.
622 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
626 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser
*self
)
628 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), FALSE
);
630 return self
->priv
->has_all_option
;
634 * empathy_account_chooser_set_has_all_option:
635 * @self: an #EmpathyAccountChooser
636 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
639 * Sets the #EmpathyAccountChooser:has-all-option property.
642 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser
*self
,
643 gboolean has_all_option
)
645 GtkComboBox
*combobox
;
650 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
));
652 if (self
->priv
->has_all_option
== has_all_option
)
655 combobox
= GTK_COMBO_BOX (self
);
656 model
= gtk_combo_box_get_model (combobox
);
657 store
= GTK_LIST_STORE (model
);
659 self
->priv
->has_all_option
= has_all_option
;
662 * The first 2 options are the ALL and separator
667 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self
),
668 (GtkTreeViewRowSeparatorFunc
)
669 account_chooser_separator_func
,
673 gtk_list_store_prepend (store
, &iter
);
674 gtk_list_store_set (store
, &iter
,
675 COL_ACCOUNT_TEXT
, NULL
,
676 COL_ACCOUNT_ENABLED
, TRUE
,
677 COL_ACCOUNT_POINTER
, NULL
,
678 COL_ACCOUNT_ROW_TYPE
, ROW_SEPARATOR
,
681 gtk_list_store_prepend (store
, &iter
);
682 gtk_list_store_set (store
, &iter
,
683 COL_ACCOUNT_TEXT
, _("All accounts"),
684 COL_ACCOUNT_ENABLED
, TRUE
,
685 COL_ACCOUNT_POINTER
, NULL
,
686 COL_ACCOUNT_ROW_TYPE
, ROW_ALL
,
691 if (gtk_tree_model_get_iter_first (model
, &iter
))
693 if (gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
))
694 gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
697 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self
),
698 (GtkTreeViewRowSeparatorFunc
)
704 g_object_notify (G_OBJECT (self
), "has-all-option");
708 account_chooser_account_validity_changed_cb (TpAccountManager
*manager
,
711 EmpathyAccountChooser
*self
)
714 account_chooser_account_add_foreach (account
, self
);
716 account_chooser_account_remove_foreach (account
, self
);
720 account_chooser_account_add_foreach (TpAccount
*account
,
721 EmpathyAccountChooser
*self
)
724 GtkComboBox
*combobox
;
728 combobox
= GTK_COMBO_BOX (self
);
729 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
731 position
= gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store
), NULL
);
732 gtk_list_store_insert_with_values (store
, &iter
, position
,
733 COL_ACCOUNT_POINTER
, account
,
736 account_chooser_update_iter (self
, &iter
);
740 account_chooser_account_removed_cb (TpAccountManager
*manager
,
742 EmpathyAccountChooser
*self
)
744 account_chooser_account_remove_foreach (account
, self
);
755 account_chooser_find_account_foreach (GtkTreeModel
*model
,
760 FindAccountData
*data
= user_data
;
764 gtk_tree_model_get (model
, iter
,
765 COL_ACCOUNT_POINTER
, &account
,
766 COL_ACCOUNT_ROW_TYPE
, &type
,
769 if (type
!= ROW_ACCOUNT
)
772 if (account
== data
->account
)
775 *(data
->iter
) = *iter
;
776 g_object_unref (account
);
781 g_object_unref (account
);
787 account_chooser_find_account (EmpathyAccountChooser
*self
,
792 GtkComboBox
*combobox
;
793 FindAccountData data
;
795 combobox
= GTK_COMBO_BOX (self
);
796 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
798 data
.account
= account
;
800 gtk_tree_model_foreach (GTK_TREE_MODEL (store
),
801 account_chooser_find_account_foreach
,
808 account_chooser_account_remove_foreach (TpAccount
*account
,
809 EmpathyAccountChooser
*self
)
812 GtkComboBox
*combobox
;
815 combobox
= GTK_COMBO_BOX (self
);
816 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
818 if (account_chooser_find_account (self
, account
, &iter
))
819 gtk_list_store_remove (store
, &iter
);
823 account_chooser_filter_ready_cb (gboolean is_enabled
,
826 FilterResultCallbackData
*fr_data
= data
;
827 EmpathyAccountChooser
*self
;
831 GtkComboBox
*combobox
;
832 const gchar
*icon_name
;
835 self
= fr_data
->self
;
836 account
= fr_data
->account
;
837 iter
= fr_data
->iter
;
838 combobox
= GTK_COMBO_BOX (self
);
839 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
841 icon_name
= tp_account_get_icon_name (account
);
842 pixbuf
= tpaw_pixbuf_from_icon_name (icon_name
,
843 GTK_ICON_SIZE_BUTTON
);
845 gtk_list_store_set (store
, iter
,
846 COL_ACCOUNT_IMAGE
, pixbuf
,
847 COL_ACCOUNT_TEXT
, tp_account_get_display_name (account
),
848 COL_ACCOUNT_ENABLED
, is_enabled
,
852 g_object_unref (pixbuf
);
854 /* set first connected account as active account */
855 if (self
->priv
->account_manually_set
== FALSE
&&
856 self
->priv
->set_active_item
== FALSE
&& is_enabled
)
858 self
->priv
->set_active_item
= TRUE
;
859 gtk_combo_box_set_active_iter (combobox
, iter
);
862 filter_result_callback_data_free (fr_data
);
866 account_chooser_update_iter (EmpathyAccountChooser
*self
,
870 GtkComboBox
*combobox
;
872 FilterResultCallbackData
*data
;
874 combobox
= GTK_COMBO_BOX (self
);
875 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
877 gtk_tree_model_get (GTK_TREE_MODEL (store
), iter
,
878 COL_ACCOUNT_POINTER
, &account
,
881 /* Skip rows without account associated */
885 data
= filter_result_callback_data_new (self
, account
, iter
);
887 if (self
->priv
->filter
)
888 self
->priv
->filter (account
, account_chooser_filter_ready_cb
,
889 (gpointer
) data
, self
->priv
->filter_data
);
891 account_chooser_filter_ready_cb (TRUE
, (gpointer
) data
);
893 g_object_unref (account
);
897 update_account (EmpathyAccountChooser
*self
,
902 if (account_chooser_find_account (self
, account
, &iter
))
903 account_chooser_update_iter (self
, &iter
);
907 account_chooser_status_changed_cb (TpAccount
*account
,
911 gchar
*dbus_error_name
,
915 EmpathyAccountChooser
*self
= user_data
;
917 update_account (self
, account
);
921 account_chooser_separator_func (GtkTreeModel
*model
,
923 EmpathyAccountChooser
*self
)
927 gtk_tree_model_get (model
, iter
, COL_ACCOUNT_ROW_TYPE
, &row_type
, -1);
928 return (row_type
== ROW_SEPARATOR
);
932 account_chooser_set_account_foreach (GtkTreeModel
*model
,
935 SetAccountData
*data
)
940 gtk_tree_model_get (model
, iter
, COL_ACCOUNT_POINTER
, &account
, -1);
942 equal
= (data
->account
== account
);
945 g_object_unref (account
);
949 GtkComboBox
*combobox
;
951 combobox
= GTK_COMBO_BOX (data
->self
);
952 gtk_combo_box_set_active_iter (combobox
, iter
);
961 account_chooser_filter_foreach (GtkTreeModel
*model
,
966 account_chooser_update_iter (self
, iter
);
971 empathy_account_chooser_refilter (EmpathyAccountChooser
*self
)
975 self
->priv
->set_active_item
= FALSE
;
976 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (self
));
977 gtk_tree_model_foreach (model
, account_chooser_filter_foreach
, self
);
981 * empathy_account_chooser_set_filter:
982 * @self: an #EmpathyAccountChooser
984 * @user_data: data to pass to @filter, or %NULL
986 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
987 * of the filter are visible in the @self.
990 empathy_account_chooser_set_filter (EmpathyAccountChooser
*self
,
991 EmpathyAccountChooserFilterFunc filter
,
994 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
));
996 self
->priv
->filter
= filter
;
997 self
->priv
->filter_data
= user_data
;
999 /* Refilter existing data */
1000 empathy_account_chooser_refilter (self
);
1004 * EmpathyAccountChooserFilterFunc:
1005 * @account: a #TpAccount
1006 * @user_data: user data, or %NULL
1008 * A function which decides whether the account indicated by @account
1011 * Return value: whether the account indicated by @account is visible.
1015 empathy_account_chooser_is_ready (EmpathyAccountChooser
*self
)
1017 return self
->priv
->ready
;
1021 empathy_account_chooser_get_account (EmpathyAccountChooser
*self
)
1025 account
= empathy_account_chooser_dup_account (self
);
1026 if (account
== NULL
)
1029 g_object_unref (account
);
1035 empathy_account_chooser_get_account_manager (EmpathyAccountChooser
*self
)
1037 return self
->priv
->manager
;
1040 /* Pre-defined filters */
1043 * empathy_account_chooser_filter_is_connected:
1044 * @account: a #TpAccount
1045 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1046 * @callback_data: data passed to the @callback
1047 * @user_data: user data or %NULL
1049 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1050 * empathy_account_chooser_set_filter() and only show connected accounts.
1052 * Returns (via the callback) TRUE is @account is connected
1055 empathy_account_chooser_filter_is_connected (TpAccount
*account
,
1056 EmpathyAccountChooserFilterResultCallback callback
,
1057 gpointer callback_data
,
1060 gboolean is_connected
=
1061 tp_account_get_connection_status (account
, NULL
)
1062 == TP_CONNECTION_STATUS_CONNECTED
;
1064 callback (is_connected
, callback_data
);
1068 * empathy_account_chooser_filter_supports_multichat:
1069 * @account: a #TpAccount
1070 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1071 * @callback_data: data passed to the @callback
1072 * @user_data: user data or %NULL
1074 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1075 * support multiuser text chat and are connected.
1077 * Returns (via the callback) TRUE if @account both supports muc and
1081 empathy_account_chooser_filter_supports_chatrooms (TpAccount
*account
,
1082 EmpathyAccountChooserFilterResultCallback callback
,
1083 gpointer callback_data
,
1086 TpConnection
*connection
;
1087 gboolean supported
= FALSE
;
1088 TpCapabilities
*caps
;
1090 /* check if CM supports multiuser text chat */
1091 connection
= tp_account_get_connection (account
);
1092 if (connection
== NULL
)
1095 caps
= tp_connection_get_capabilities (connection
);
1099 supported
= tp_capabilities_supports_text_chatrooms (caps
);
1102 callback (supported
, callback_data
);