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 if (G_OBJECT_CLASS (empathy_account_chooser_parent_class
)->constructed
)
318 (empathy_account_chooser_parent_class
)->constructed (object
);
320 /* Set up combo box with new store */
321 combobox
= GTK_COMBO_BOX (self
);
323 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox
));
325 store
= gtk_list_store_new (COL_ACCOUNT_COUNT
,
326 GDK_TYPE_PIXBUF
, /* Image */
327 G_TYPE_STRING
, /* Name */
328 G_TYPE_BOOLEAN
, /* Enabled */
329 G_TYPE_UINT
, /* Row type */
332 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store
),
333 account_cmp
, self
, NULL
);
334 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
335 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
, GTK_SORT_ASCENDING
);
337 gtk_combo_box_set_model (combobox
, GTK_TREE_MODEL (store
));
339 renderer
= gtk_cell_renderer_pixbuf_new ();
340 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox
), renderer
, FALSE
);
341 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox
), renderer
,
342 "pixbuf", COL_ACCOUNT_IMAGE
,
343 "sensitive", COL_ACCOUNT_ENABLED
,
346 renderer
= gtk_cell_renderer_text_new ();
347 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox
), renderer
, TRUE
);
348 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox
), renderer
,
349 "text", COL_ACCOUNT_TEXT
,
350 "sensitive", COL_ACCOUNT_ENABLED
,
353 /* Populate accounts */
354 tp_proxy_prepare_async (self
->priv
->manager
, NULL
,
355 account_manager_prepared_cb
, self
);
357 g_object_unref (store
);
362 account_chooser_dispose (GObject
*object
)
364 EmpathyAccountChooser
*self
= EMPATHY_ACCOUNT_CHOOSER (object
);
366 g_clear_object (&self
->priv
->manager
);
367 g_clear_object (&self
->priv
->select_when_ready
);
369 G_OBJECT_CLASS (empathy_account_chooser_parent_class
)->dispose (object
);
373 account_chooser_get_property (GObject
*object
,
378 EmpathyAccountChooser
*self
= (EmpathyAccountChooser
*) object
;
382 case PROP_HAS_ALL_OPTION
:
383 g_value_set_boolean (value
, self
->priv
->has_all_option
);
386 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
392 account_chooser_set_property (GObject
*object
,
399 case PROP_HAS_ALL_OPTION
:
400 empathy_account_chooser_set_has_all_option (
401 EMPATHY_ACCOUNT_CHOOSER (object
), g_value_get_boolean (value
));
404 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
410 empathy_account_chooser_class_init (EmpathyAccountChooserClass
*klass
)
412 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
414 object_class
->constructed
= account_chooser_constructed
;
415 object_class
->dispose
= account_chooser_dispose
;
416 object_class
->get_property
= account_chooser_get_property
;
417 object_class
->set_property
= account_chooser_set_property
;
420 * EmpathyAccountChooser:has-all-option:
422 * Have an additional option in the list to mean all accounts.
424 g_object_class_install_property (object_class
,
426 g_param_spec_boolean ("has-all-option",
428 "Have a separate option in the list to mean ALL accounts",
433 g_signal_new ("ready",
434 G_OBJECT_CLASS_TYPE (object_class
),
438 g_cclosure_marshal_generic
,
442 g_type_class_add_private (object_class
, sizeof (EmpathyAccountChooserPriv
));
446 * empathy_account_chooser_new:
448 * Creates a new #EmpathyAccountChooser.
450 * Return value: A new #EmpathyAccountChooser
453 empathy_account_chooser_new (void)
457 self
= g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER
, NULL
);
463 empathy_account_chooser_has_all_selected (EmpathyAccountChooser
*self
)
469 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), FALSE
);
471 g_return_val_if_fail (self
->priv
->has_all_option
== TRUE
, FALSE
);
473 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (self
));
474 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self
), &iter
))
477 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT_ROW_TYPE
, &type
, -1);
479 return type
== ROW_ALL
;
483 * empathy_account_chooser_dup_account:
484 * @self: an #EmpathyAccountChooser
486 * Returns the account which is currently selected in the chooser or %NULL
487 * if there is no account selected. The #TpAccount returned should be
488 * unrefed with g_object_unref() when finished with.
490 * Return value: a new ref to the #TpAccount currently selected, or %NULL.
493 empathy_account_chooser_dup_account (EmpathyAccountChooser
*self
)
499 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), NULL
);
501 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (self
));
502 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self
), &iter
))
505 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT_POINTER
, &account
, -1);
511 * empathy_account_chooser_get_connection:
512 * @self: an #EmpathyAccountChooser
514 * Returns a borrowed reference to the #TpConnection associated with the
515 * account currently selected. The caller must reference the returned object
516 * with g_object_ref() if it will be kept
518 * Return value: a borrowed reference to the #TpConnection associated with the
519 * account curently selected.
522 empathy_account_chooser_get_connection (EmpathyAccountChooser
*self
)
525 TpConnection
*connection
;
527 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), NULL
);
529 account
= empathy_account_chooser_dup_account (self
);
531 /* if the returned account is NULL, then the account manager probably
532 * hasn't been prepared yet. It should be safe to return NULL here
537 connection
= tp_account_get_connection (account
);
538 g_object_unref (account
);
544 select_account (EmpathyAccountChooser
*self
,
547 GtkComboBox
*combobox
;
552 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), FALSE
);
554 combobox
= GTK_COMBO_BOX (self
);
555 model
= gtk_combo_box_get_model (combobox
);
556 gtk_combo_box_get_active_iter (combobox
, &iter
);
559 data
.account
= account
;
562 gtk_tree_model_foreach (model
,
563 (GtkTreeModelForeachFunc
) account_chooser_set_account_foreach
,
566 self
->priv
->account_manually_set
= data
.set
;
572 * empathy_account_chooser_set_account:
573 * @self: an #EmpathyAccountChooser
574 * @account: a #TpAccount
576 * Sets the currently selected account to @account, if it exists in the list.
578 * Return value: whether the chooser was set to @account.
581 empathy_account_chooser_set_account (EmpathyAccountChooser
*self
,
584 if (self
->priv
->ready
)
585 return select_account (self
, account
);
587 /* Account chooser is not ready yet, we'll try selecting the account once it
589 g_clear_object (&self
->priv
->select_when_ready
);
592 self
->priv
->select_when_ready
= g_object_ref (account
);
598 empathy_account_chooser_set_all (EmpathyAccountChooser
*self
)
600 GtkComboBox
*combobox
;
604 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
));
606 g_return_if_fail (self
->priv
->has_all_option
);
608 combobox
= GTK_COMBO_BOX (self
);
609 model
= gtk_combo_box_get_model (combobox
);
611 if (gtk_tree_model_get_iter_first (model
, &iter
))
613 /* 'All accounts' is the first row */
614 gtk_combo_box_set_active_iter (combobox
, &iter
);
615 self
->priv
->account_manually_set
= TRUE
;
620 * empathy_account_chooser_get_has_all_option:
621 * @self: an #EmpathyAccountChooser
623 * Returns whether @self has the #EmpathyAccountChooser:has-all-option
624 * property set to true.
626 * Return value: whether @self has the #EmpathyAccountChooser:has-all-option
630 empathy_account_chooser_get_has_all_option (EmpathyAccountChooser
*self
)
632 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
), FALSE
);
634 return self
->priv
->has_all_option
;
638 * empathy_account_chooser_set_has_all_option:
639 * @self: an #EmpathyAccountChooser
640 * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option
643 * Sets the #EmpathyAccountChooser:has-all-option property.
646 empathy_account_chooser_set_has_all_option (EmpathyAccountChooser
*self
,
647 gboolean has_all_option
)
649 GtkComboBox
*combobox
;
654 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
));
656 if (self
->priv
->has_all_option
== has_all_option
)
659 combobox
= GTK_COMBO_BOX (self
);
660 model
= gtk_combo_box_get_model (combobox
);
661 store
= GTK_LIST_STORE (model
);
663 self
->priv
->has_all_option
= has_all_option
;
666 * The first 2 options are the ALL and separator
671 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self
),
672 (GtkTreeViewRowSeparatorFunc
)
673 account_chooser_separator_func
,
677 gtk_list_store_prepend (store
, &iter
);
678 gtk_list_store_set (store
, &iter
,
679 COL_ACCOUNT_TEXT
, NULL
,
680 COL_ACCOUNT_ENABLED
, TRUE
,
681 COL_ACCOUNT_POINTER
, NULL
,
682 COL_ACCOUNT_ROW_TYPE
, ROW_SEPARATOR
,
685 gtk_list_store_prepend (store
, &iter
);
686 gtk_list_store_set (store
, &iter
,
687 COL_ACCOUNT_TEXT
, _("All accounts"),
688 COL_ACCOUNT_ENABLED
, TRUE
,
689 COL_ACCOUNT_POINTER
, NULL
,
690 COL_ACCOUNT_ROW_TYPE
, ROW_ALL
,
695 if (gtk_tree_model_get_iter_first (model
, &iter
))
697 if (gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
))
698 gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
701 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self
),
702 (GtkTreeViewRowSeparatorFunc
)
708 g_object_notify (G_OBJECT (self
), "has-all-option");
712 account_chooser_account_validity_changed_cb (TpAccountManager
*manager
,
715 EmpathyAccountChooser
*self
)
718 account_chooser_account_add_foreach (account
, self
);
720 account_chooser_account_remove_foreach (account
, self
);
724 account_chooser_account_add_foreach (TpAccount
*account
,
725 EmpathyAccountChooser
*self
)
728 GtkComboBox
*combobox
;
732 combobox
= GTK_COMBO_BOX (self
);
733 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
735 position
= gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store
), NULL
);
736 gtk_list_store_insert_with_values (store
, &iter
, position
,
737 COL_ACCOUNT_POINTER
, account
,
740 account_chooser_update_iter (self
, &iter
);
744 account_chooser_account_removed_cb (TpAccountManager
*manager
,
746 EmpathyAccountChooser
*self
)
748 account_chooser_account_remove_foreach (account
, self
);
759 account_chooser_find_account_foreach (GtkTreeModel
*model
,
764 FindAccountData
*data
= user_data
;
768 gtk_tree_model_get (model
, iter
,
769 COL_ACCOUNT_POINTER
, &account
,
770 COL_ACCOUNT_ROW_TYPE
, &type
,
773 if (type
!= ROW_ACCOUNT
)
776 if (account
== data
->account
)
779 *(data
->iter
) = *iter
;
780 g_object_unref (account
);
785 g_object_unref (account
);
791 account_chooser_find_account (EmpathyAccountChooser
*self
,
796 GtkComboBox
*combobox
;
797 FindAccountData data
;
799 combobox
= GTK_COMBO_BOX (self
);
800 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
802 data
.account
= account
;
804 gtk_tree_model_foreach (GTK_TREE_MODEL (store
),
805 account_chooser_find_account_foreach
,
812 account_chooser_account_remove_foreach (TpAccount
*account
,
813 EmpathyAccountChooser
*self
)
816 GtkComboBox
*combobox
;
819 combobox
= GTK_COMBO_BOX (self
);
820 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
822 if (account_chooser_find_account (self
, account
, &iter
))
823 gtk_list_store_remove (store
, &iter
);
827 account_chooser_filter_ready_cb (gboolean is_enabled
,
830 FilterResultCallbackData
*fr_data
= data
;
831 EmpathyAccountChooser
*self
;
835 GtkComboBox
*combobox
;
836 const gchar
*icon_name
;
839 self
= fr_data
->self
;
840 account
= fr_data
->account
;
841 iter
= fr_data
->iter
;
842 combobox
= GTK_COMBO_BOX (self
);
843 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
845 icon_name
= tp_account_get_icon_name (account
);
846 pixbuf
= tpaw_pixbuf_from_icon_name (icon_name
,
847 GTK_ICON_SIZE_BUTTON
);
849 gtk_list_store_set (store
, iter
,
850 COL_ACCOUNT_IMAGE
, pixbuf
,
851 COL_ACCOUNT_TEXT
, tp_account_get_display_name (account
),
852 COL_ACCOUNT_ENABLED
, is_enabled
,
856 g_object_unref (pixbuf
);
858 /* set first connected account as active account */
859 if (self
->priv
->account_manually_set
== FALSE
&&
860 self
->priv
->set_active_item
== FALSE
&& is_enabled
)
862 self
->priv
->set_active_item
= TRUE
;
863 gtk_combo_box_set_active_iter (combobox
, iter
);
866 filter_result_callback_data_free (fr_data
);
870 account_chooser_update_iter (EmpathyAccountChooser
*self
,
874 GtkComboBox
*combobox
;
876 FilterResultCallbackData
*data
;
878 combobox
= GTK_COMBO_BOX (self
);
879 store
= GTK_LIST_STORE (gtk_combo_box_get_model (combobox
));
881 gtk_tree_model_get (GTK_TREE_MODEL (store
), iter
,
882 COL_ACCOUNT_POINTER
, &account
,
885 /* Skip rows without account associated */
889 data
= filter_result_callback_data_new (self
, account
, iter
);
891 if (self
->priv
->filter
)
892 self
->priv
->filter (account
, account_chooser_filter_ready_cb
,
893 (gpointer
) data
, self
->priv
->filter_data
);
895 account_chooser_filter_ready_cb (TRUE
, (gpointer
) data
);
897 g_object_unref (account
);
901 update_account (EmpathyAccountChooser
*self
,
906 if (account_chooser_find_account (self
, account
, &iter
))
907 account_chooser_update_iter (self
, &iter
);
911 account_chooser_status_changed_cb (TpAccount
*account
,
915 gchar
*dbus_error_name
,
919 EmpathyAccountChooser
*self
= user_data
;
921 update_account (self
, account
);
925 account_chooser_separator_func (GtkTreeModel
*model
,
927 EmpathyAccountChooser
*self
)
931 gtk_tree_model_get (model
, iter
, COL_ACCOUNT_ROW_TYPE
, &row_type
, -1);
932 return (row_type
== ROW_SEPARATOR
);
936 account_chooser_set_account_foreach (GtkTreeModel
*model
,
939 SetAccountData
*data
)
944 gtk_tree_model_get (model
, iter
, COL_ACCOUNT_POINTER
, &account
, -1);
946 equal
= (data
->account
== account
);
949 g_object_unref (account
);
953 GtkComboBox
*combobox
;
955 combobox
= GTK_COMBO_BOX (data
->self
);
956 gtk_combo_box_set_active_iter (combobox
, iter
);
965 account_chooser_filter_foreach (GtkTreeModel
*model
,
970 account_chooser_update_iter (self
, iter
);
975 empathy_account_chooser_refilter (EmpathyAccountChooser
*self
)
979 self
->priv
->set_active_item
= FALSE
;
980 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (self
));
981 gtk_tree_model_foreach (model
, account_chooser_filter_foreach
, self
);
985 * empathy_account_chooser_set_filter:
986 * @self: an #EmpathyAccountChooser
988 * @user_data: data to pass to @filter, or %NULL
990 * Sets a filter on the @self so only accounts that are %TRUE in the eyes
991 * of the filter are visible in the @self.
994 empathy_account_chooser_set_filter (EmpathyAccountChooser
*self
,
995 EmpathyAccountChooserFilterFunc filter
,
998 g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self
));
1000 self
->priv
->filter
= filter
;
1001 self
->priv
->filter_data
= user_data
;
1003 /* Refilter existing data */
1004 empathy_account_chooser_refilter (self
);
1008 * EmpathyAccountChooserFilterFunc:
1009 * @account: a #TpAccount
1010 * @user_data: user data, or %NULL
1012 * A function which decides whether the account indicated by @account
1015 * Return value: whether the account indicated by @account is visible.
1019 empathy_account_chooser_is_ready (EmpathyAccountChooser
*self
)
1021 return self
->priv
->ready
;
1025 empathy_account_chooser_get_account (EmpathyAccountChooser
*self
)
1029 account
= empathy_account_chooser_dup_account (self
);
1030 if (account
== NULL
)
1033 g_object_unref (account
);
1039 empathy_account_chooser_get_account_manager (EmpathyAccountChooser
*self
)
1041 return self
->priv
->manager
;
1044 /* Pre-defined filters */
1047 * empathy_account_chooser_filter_is_connected:
1048 * @account: a #TpAccount
1049 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1050 * @callback_data: data passed to the @callback
1051 * @user_data: user data or %NULL
1053 * A useful #EmpathyAccountChooserFilterFunc that one could pass into
1054 * empathy_account_chooser_set_filter() and only show connected accounts.
1056 * Returns (via the callback) TRUE is @account is connected
1059 empathy_account_chooser_filter_is_connected (TpAccount
*account
,
1060 EmpathyAccountChooserFilterResultCallback callback
,
1061 gpointer callback_data
,
1064 gboolean is_connected
=
1065 tp_account_get_connection_status (account
, NULL
)
1066 == TP_CONNECTION_STATUS_CONNECTED
;
1068 callback (is_connected
, callback_data
);
1072 * empathy_account_chooser_filter_supports_multichat:
1073 * @account: a #TpAccount
1074 * @callback: an #EmpathyAccountChooserFilterResultCallback accepting the result
1075 * @callback_data: data passed to the @callback
1076 * @user_data: user data or %NULL
1078 * An #EmpathyAccountChooserFilterFunc that returns accounts that both
1079 * support multiuser text chat and are connected.
1081 * Returns (via the callback) TRUE if @account both supports muc and
1085 empathy_account_chooser_filter_supports_chatrooms (TpAccount
*account
,
1086 EmpathyAccountChooserFilterResultCallback callback
,
1087 gpointer callback_data
,
1090 TpConnection
*connection
;
1091 gboolean supported
= FALSE
;
1092 TpCapabilities
*caps
;
1094 /* check if CM supports multiuser text chat */
1095 connection
= tp_account_get_connection (account
);
1096 if (connection
== NULL
)
1099 caps
= tp_connection_get_capabilities (connection
);
1103 supported
= tp_capabilities_supports_text_chatrooms (caps
);
1106 callback (supported
, callback_data
);