*/
#include "config.h"
-
-#include <string.h>
+#include "empathy-account-chooser.h"
#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/util.h>
-
-#include <libempathy/empathy-utils.h>
#include "empathy-ui-utils.h"
-#include "empathy-account-chooser.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
/**
* SECTION:empathy-account-chooser
* Widget which extends #GtkComboBox to provide a chooser of available accounts.
*/
-#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountChooser)
-
-typedef struct
+struct _EmpathyAccountChooserPriv
{
TpAccountManager *manager;
gboolean set_active_item;
EmpathyAccountChooserFilterFunc filter;
gpointer filter_data;
gboolean ready;
-} EmpathyAccountChooserPriv;
+
+ TpAccount *select_when_ready;
+};
typedef struct
{
{
FilterResultCallbackData *data;
+ g_return_val_if_fail (self != NULL, NULL);
+ g_return_val_if_fail (account != NULL, NULL);
+ g_return_val_if_fail (iter != NULL, NULL);
+
data = g_slice_new0 (FilterResultCallbackData);
data->self = g_object_ref (self);
data->account = g_object_ref (account);
COL_ACCOUNT_COUNT
};
-static void account_chooser_constructed (GObject *object);
-static void account_chooser_finalize (GObject *object);
-static void account_chooser_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void account_chooser_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-static void account_chooser_setup (EmpathyAccountChooser *self);
static void account_chooser_account_validity_changed_cb (
TpAccountManager *manager,
TpAccount *account,
TpAccount *account,
EmpathyAccountChooser *self);
static void account_chooser_account_remove_foreach (TpAccount *account,
- EmpathyAccountChooser*self);
+ EmpathyAccountChooser *self);
static void account_chooser_update_iter (EmpathyAccountChooser *self,
GtkTreeIter *iter);
static void account_chooser_status_changed_cb (TpAccount *account,
GtkTreePath *path,
GtkTreeIter *iter,
SetAccountData *data);
+static void update_account (EmpathyAccountChooser *self,
+ TpAccount *account);
+static gboolean select_account (EmpathyAccountChooser *self,
+ TpAccount *account);
enum {
PROP_0,
GTK_TYPE_COMBO_BOX)
static void
-empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
+empathy_account_chooser_init (EmpathyAccountChooser *self)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ TpSimpleClientFactory *factory;
- object_class->constructed = account_chooser_constructed;
- object_class->finalize = account_chooser_finalize;
- object_class->get_property = account_chooser_get_property;
- object_class->set_property = account_chooser_set_property;
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
- /**
- * EmpathyAccountChooser:has-all-option:
- *
- * Have an additional option in the list to mean all accounts.
- */
- g_object_class_install_property (object_class,
- PROP_HAS_ALL_OPTION,
- g_param_spec_boolean ("has-all-option",
- "Has All Option",
- "Have a separate option in the list to mean ALL accounts",
- FALSE,
- G_PARAM_READWRITE));
+ self->priv->set_active_item = FALSE;
+ self->priv->account_manually_set = FALSE;
+ self->priv->filter = NULL;
+ self->priv->filter_data = NULL;
- signals[READY] =
- g_signal_new ("ready",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE,
- 0);
+ self->priv->manager = tp_account_manager_dup ();
- g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
+ tp_g_signal_connect_object (self->priv->manager, "account-validity-changed",
+ G_CALLBACK (account_chooser_account_validity_changed_cb), self, 0);
+
+ tp_g_signal_connect_object (self->priv->manager, "account-removed",
+ G_CALLBACK (account_chooser_account_removed_cb), self, 0);
+
+ /* Make sure we'll have the capabilities feature on TpAccount's connection */
+ factory = tp_proxy_get_factory (self->priv->manager);
+
+ tp_simple_client_factory_add_account_features_varargs (factory,
+ TP_ACCOUNT_FEATURE_CONNECTION, NULL);
+ tp_simple_client_factory_add_connection_features_varargs (factory,
+ TP_CONNECTION_FEATURE_CAPABILITIES, NULL);
+}
+
+static gint
+account_cmp (GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer user_data)
+{
+ RowType a_type, b_type;
+ gboolean a_enabled, b_enabled;
+ gchar *a_text, *b_text;
+ gint result;
+
+ gtk_tree_model_get (model, a,
+ COL_ACCOUNT_ENABLED, &a_enabled,
+ COL_ACCOUNT_ROW_TYPE, &a_type,
+ -1);
+ gtk_tree_model_get (model, b,
+ COL_ACCOUNT_ENABLED, &b_enabled,
+ COL_ACCOUNT_ROW_TYPE, &b_type,
+ -1);
+
+ /* This assumes that we have at most one of each special row type. */
+ if (a_type != b_type)
+ /* Display higher-numbered special row types first. */
+ return (b_type - a_type);
+
+ /* Enabled accounts are displayed first */
+ if (a_enabled != b_enabled)
+ return a_enabled ? -1: 1;
+
+ gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
+ gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
+
+ if (a_text == b_text)
+ result = 0;
+ else if (a_text == NULL)
+ result = 1;
+ else if (b_text == NULL)
+ result = -1;
+ else
+ result = g_ascii_strcasecmp (a_text, b_text);
+
+ g_free (a_text);
+ g_free (b_text);
+
+ return result;
}
static void
-empathy_account_chooser_init (EmpathyAccountChooser *self)
+account_connection_notify_cb (TpAccount *account,
+ GParamSpec *spec,
+ EmpathyAccountChooser *self)
{
- EmpathyAccountChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
- EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
+ update_account (self, account);
+}
- self->priv = priv;
- priv->set_active_item = FALSE;
- priv->account_manually_set = FALSE;
- priv->filter = NULL;
- priv->filter_data = NULL;
+static void
+account_manager_prepared_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GList *accounts, *l;
+ TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
+ EmpathyAccountChooser *self = user_data;
+ GError *error = NULL;
- priv->manager = tp_account_manager_dup ();
+ if (!tp_proxy_prepare_finish (manager, result, &error))
+ {
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ return;
+ }
- g_signal_connect (priv->manager, "account-validity-changed",
- G_CALLBACK (account_chooser_account_validity_changed_cb),
- self);
- g_signal_connect (priv->manager, "account-removed",
- G_CALLBACK (account_chooser_account_removed_cb),
- self);
+ accounts = tp_account_manager_dup_valid_accounts (manager);
+
+ for (l = accounts; l != NULL; l = l->next)
+ {
+ TpAccount *account = l->data;
+
+ account_chooser_account_add_foreach (account, self);
+
+ tp_g_signal_connect_object (account, "status-changed",
+ G_CALLBACK (account_chooser_status_changed_cb),
+ self, 0);
+
+ /* We generally use the TpConnection from the account to filter it so,
+ * just relying on the account status is not enough. In some case we the
+ * status change can be notified while the TpConnection is still
+ * preparing. */
+ tp_g_signal_connect_object (account, "notify::connection",
+ G_CALLBACK (account_connection_notify_cb),
+ self, 0);
+ }
+
+ g_list_free_full (accounts, g_object_unref);
+
+ if (self->priv->select_when_ready != NULL)
+ {
+ select_account (self, self->priv->select_when_ready);
+
+ g_clear_object (&self->priv->select_when_ready);
+ }
+
+ self->priv->ready = TRUE;
+ g_signal_emit (self, signals[READY], 0);
}
static void
account_chooser_constructed (GObject *object)
{
EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
+ GtkListStore *store;
+ GtkCellRenderer *renderer;
+ GtkComboBox *combobox;
+
+ /* Set up combo box with new store */
+ combobox = GTK_COMBO_BOX (self);
+
+ gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
+
+ store = gtk_list_store_new (COL_ACCOUNT_COUNT,
+ GDK_TYPE_PIXBUF, /* Image */
+ G_TYPE_STRING, /* Name */
+ G_TYPE_BOOLEAN, /* Enabled */
+ G_TYPE_UINT, /* Row type */
+ TP_TYPE_ACCOUNT);
+
+ gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
+ account_cmp, self, NULL);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+ GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
+
+ gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
+
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
+ "pixbuf", COL_ACCOUNT_IMAGE,
+ "sensitive", COL_ACCOUNT_ENABLED,
+ NULL);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
+ "text", COL_ACCOUNT_TEXT,
+ "sensitive", COL_ACCOUNT_ENABLED,
+ NULL);
+
+ /* Populate accounts */
+ tp_proxy_prepare_async (self->priv->manager, NULL,
+ account_manager_prepared_cb, self);
+
+ g_object_unref (store);
- account_chooser_setup (self);
}
static void
-account_chooser_finalize (GObject *object)
+account_chooser_dispose (GObject *object)
{
- EmpathyAccountChooserPriv *priv = GET_PRIV (object);
+ EmpathyAccountChooser *self = EMPATHY_ACCOUNT_CHOOSER (object);
- g_signal_handlers_disconnect_by_func (priv->manager,
- account_chooser_account_validity_changed_cb,
- object);
- g_signal_handlers_disconnect_by_func (priv->manager,
- account_chooser_account_removed_cb,
- object);
- g_object_unref (priv->manager);
+ g_clear_object (&self->priv->manager);
+ g_clear_object (&self->priv->select_when_ready);
- G_OBJECT_CLASS (empathy_account_chooser_parent_class)->finalize (object);
+ G_OBJECT_CLASS (empathy_account_chooser_parent_class)->dispose (object);
}
static void
GValue *value,
GParamSpec *pspec)
{
- EmpathyAccountChooserPriv *priv;
-
- priv = GET_PRIV (object);
+ EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
switch (param_id)
{
case PROP_HAS_ALL_OPTION:
- g_value_set_boolean (value, priv->has_all_option);
+ g_value_set_boolean (value, self->priv->has_all_option);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
};
}
+static void
+empathy_account_chooser_class_init (EmpathyAccountChooserClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = account_chooser_constructed;
+ object_class->dispose = account_chooser_dispose;
+ object_class->get_property = account_chooser_get_property;
+ object_class->set_property = account_chooser_set_property;
+
+ /**
+ * EmpathyAccountChooser:has-all-option:
+ *
+ * Have an additional option in the list to mean all accounts.
+ */
+ g_object_class_install_property (object_class,
+ PROP_HAS_ALL_OPTION,
+ g_param_spec_boolean ("has-all-option",
+ "Has All Option",
+ "Have a separate option in the list to mean ALL accounts",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ signals[READY] =
+ g_signal_new ("ready",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 0);
+
+ g_type_class_add_private (object_class, sizeof (EmpathyAccountChooserPriv));
+}
+
/**
* empathy_account_chooser_new:
*
gboolean
empathy_account_chooser_has_all_selected (EmpathyAccountChooser *self)
{
- EmpathyAccountChooserPriv *priv;
GtkTreeModel *model;
GtkTreeIter iter;
RowType type;
g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
- priv = GET_PRIV (self);
-
- g_return_val_if_fail (priv->has_all_option == TRUE, FALSE);
+ g_return_val_if_fail (self->priv->has_all_option == TRUE, FALSE);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
return connection;
}
-/**
- * empathy_account_chooser_set_account:
- * @self: an #EmpathyAccountChooser
- * @account: a #TpAccount
- *
- * Sets the currently selected account to @account, if it exists in the list.
- *
- * Return value: whether the chooser was set to @account.
- */
-gboolean
-empathy_account_chooser_set_account (EmpathyAccountChooser *self,
+static gboolean
+select_account (EmpathyAccountChooser *self,
TpAccount *account)
{
- EmpathyAccountChooserPriv *priv;
GtkComboBox *combobox;
GtkTreeModel *model;
GtkTreeIter iter;
g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
- priv = GET_PRIV (self);
-
combobox = GTK_COMBO_BOX (self);
model = gtk_combo_box_get_model (combobox);
gtk_combo_box_get_active_iter (combobox, &iter);
(GtkTreeModelForeachFunc) account_chooser_set_account_foreach,
&data);
- priv->account_manually_set = data.set;
+ self->priv->account_manually_set = data.set;
return data.set;
}
+/**
+ * empathy_account_chooser_set_account:
+ * @self: an #EmpathyAccountChooser
+ * @account: a #TpAccount
+ *
+ * Sets the currently selected account to @account, if it exists in the list.
+ *
+ * Return value: whether the chooser was set to @account.
+ */
+gboolean
+empathy_account_chooser_set_account (EmpathyAccountChooser *self,
+ TpAccount *account)
+{
+ if (self->priv->ready)
+ return select_account (self, account);
+
+ /* Account chooser is not ready yet, we'll try selecting the account once it
+ * is */
+ g_clear_object (&self->priv->select_when_ready);
+
+ if (account != NULL)
+ self->priv->select_when_ready = g_object_ref (account);
+
+ return FALSE;
+}
+
void
empathy_account_chooser_set_all (EmpathyAccountChooser *self)
{
- EmpathyAccountChooserPriv *priv;
GtkComboBox *combobox;
GtkTreeModel *model;
GtkTreeIter iter;
g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
- priv = GET_PRIV (self);
-
- g_return_if_fail (priv->has_all_option);
+ g_return_if_fail (self->priv->has_all_option);
combobox = GTK_COMBO_BOX (self);
model = gtk_combo_box_get_model (combobox);
{
/* 'All accounts' is the first row */
gtk_combo_box_set_active_iter (combobox, &iter);
- priv->account_manually_set = TRUE;
+ self->priv->account_manually_set = TRUE;
}
}
gboolean
empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *self)
{
- EmpathyAccountChooserPriv *priv;
-
g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self), FALSE);
- priv = GET_PRIV (self);
-
- return priv->has_all_option;
+ return self->priv->has_all_option;
}
/**
empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *self,
gboolean has_all_option)
{
- EmpathyAccountChooserPriv *priv;
GtkComboBox *combobox;
GtkListStore *store;
GtkTreeModel *model;
g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
- priv = GET_PRIV (self);
-
- if (priv->has_all_option == has_all_option)
+ if (self->priv->has_all_option == has_all_option)
return;
combobox = GTK_COMBO_BOX (self);
model = gtk_combo_box_get_model (combobox);
store = GTK_LIST_STORE (model);
- priv->has_all_option = has_all_option;
+ self->priv->has_all_option = has_all_option;
/*
* The first 2 options are the ALL and separator
g_object_notify (G_OBJECT (self), "has-all-option");
}
-static void
-account_manager_prepared_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- GList *accounts, *l;
- TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
- EmpathyAccountChooser *self = user_data;
- EmpathyAccountChooserPriv *priv = GET_PRIV (self);
- GError *error = NULL;
-
- if (!tp_proxy_prepare_finish (manager, result, &error))
- {
- DEBUG ("Failed to prepare account manager: %s", error->message);
- g_error_free (error);
- return;
- }
-
- accounts = tp_account_manager_get_valid_accounts (manager);
-
- for (l = accounts; l != NULL; l = l->next)
- {
- TpAccount *account = l->data;
-
- account_chooser_account_add_foreach (account, self);
-
- tp_g_signal_connect_object (account, "status-changed",
- G_CALLBACK (account_chooser_status_changed_cb),
- self, 0);
- }
-
- g_list_free (accounts);
-
- priv->ready = TRUE;
- g_signal_emit (self, signals[READY], 0);
-}
-
-static gint
-account_cmp (GtkTreeModel *model,
- GtkTreeIter *a,
- GtkTreeIter *b,
- gpointer user_data)
-{
- RowType a_type, b_type;
- gboolean a_enabled, b_enabled;
- gchar *a_text, *b_text;
- gint result;
-
- gtk_tree_model_get (model, a,
- COL_ACCOUNT_ENABLED, &a_enabled,
- COL_ACCOUNT_ROW_TYPE, &a_type,
- -1);
- gtk_tree_model_get (model, b,
- COL_ACCOUNT_ENABLED, &b_enabled,
- COL_ACCOUNT_ROW_TYPE, &b_type,
- -1);
-
- /* This assumes that we have at most one of each special row type. */
- if (a_type != b_type)
- /* Display higher-numbered special row types first. */
- return (b_type - a_type);
-
- /* Enabled accounts are displayed first */
- if (a_enabled != b_enabled)
- return a_enabled ? -1: 1;
-
- gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
- gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
-
- if (a_text == b_text)
- result = 0;
- else if (a_text == NULL)
- result = 1;
- else if (b_text == NULL)
- result = -1;
- else
- result = g_ascii_strcasecmp (a_text, b_text);
-
- g_free (a_text);
- g_free (b_text);
-
- return result;
-}
-
-static void
-account_chooser_setup (EmpathyAccountChooser *self)
-{
- EmpathyAccountChooserPriv *priv;
- GtkListStore *store;
- GtkCellRenderer *renderer;
- GtkComboBox *combobox;
-
- priv = GET_PRIV (self);
-
- /* Set up combo box with new store */
- combobox = GTK_COMBO_BOX (self);
-
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
-
- store = gtk_list_store_new (COL_ACCOUNT_COUNT,
- GDK_TYPE_PIXBUF, /* Image */
- G_TYPE_STRING, /* Name */
- G_TYPE_BOOLEAN, /* Enabled */
- G_TYPE_UINT, /* Row type */
- TP_TYPE_ACCOUNT);
-
- gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
- account_cmp, self, NULL);
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
- GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
-
- gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
-
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
- "pixbuf", COL_ACCOUNT_IMAGE,
- "sensitive", COL_ACCOUNT_ENABLED,
- NULL);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
- "text", COL_ACCOUNT_TEXT,
- "sensitive", COL_ACCOUNT_ENABLED,
- NULL);
-
- /* Populate accounts */
- tp_proxy_prepare_async (priv->manager, NULL, account_manager_prepared_cb,
- self);
-
- g_object_unref (store);
-}
-
static void
account_chooser_account_validity_changed_cb (TpAccountManager *manager,
TpAccount *account,
static gboolean
account_chooser_find_account (EmpathyAccountChooser *self,
TpAccount *account,
- GtkTreeIter*iter)
+ GtkTreeIter *iter)
{
GtkListStore *store;
GtkComboBox *combobox;
{
FilterResultCallbackData *fr_data = data;
EmpathyAccountChooser *self;
- EmpathyAccountChooserPriv *priv;
TpAccount *account;
GtkTreeIter *iter;
GtkListStore *store;
GdkPixbuf *pixbuf;
self = fr_data->self;
- priv = GET_PRIV (self);
account = fr_data->account;
iter = fr_data->iter;
combobox = GTK_COMBO_BOX (self);
g_object_unref (pixbuf);
/* set first connected account as active account */
- if (priv->account_manually_set == FALSE &&
- priv->set_active_item == FALSE && is_enabled)
+ if (self->priv->account_manually_set == FALSE &&
+ self->priv->set_active_item == FALSE && is_enabled)
{
- priv->set_active_item = TRUE;
+ self->priv->set_active_item = TRUE;
gtk_combo_box_set_active_iter (combobox, iter);
}
account_chooser_update_iter (EmpathyAccountChooser *self,
GtkTreeIter *iter)
{
- EmpathyAccountChooserPriv *priv;
GtkListStore *store;
GtkComboBox *combobox;
TpAccount *account;
FilterResultCallbackData *data;
- priv = GET_PRIV (self);
-
combobox = GTK_COMBO_BOX (self);
store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
data = filter_result_callback_data_new (self, account, iter);
- if (priv->filter)
- priv->filter (account, account_chooser_filter_ready_cb,
- (gpointer) data, priv->filter_data);
+ if (self->priv->filter)
+ self->priv->filter (account, account_chooser_filter_ready_cb,
+ (gpointer) data, self->priv->filter_data);
else
account_chooser_filter_ready_cb (TRUE, (gpointer) data);
g_object_unref (account);
}
+static void
+update_account (EmpathyAccountChooser *self,
+ TpAccount *account)
+{
+ GtkTreeIter iter;
+
+ if (account_chooser_find_account (self, account, &iter))
+ account_chooser_update_iter (self, &iter);
+}
+
static void
account_chooser_status_changed_cb (TpAccount *account,
guint old_status,
gpointer user_data)
{
EmpathyAccountChooser *self = user_data;
- GtkTreeIter iter;
- if (account_chooser_find_account (self, account, &iter))
- account_chooser_update_iter (self, &iter);
+ update_account (self, account);
}
static gboolean
return FALSE;
}
+void
+empathy_account_chooser_refilter (EmpathyAccountChooser *self)
+{
+ GtkTreeModel *model;
+
+ self->priv->set_active_item = FALSE;
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+ gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
+}
+
/**
* empathy_account_chooser_set_filter:
* @self: an #EmpathyAccountChooser
EmpathyAccountChooserFilterFunc filter,
gpointer user_data)
{
- EmpathyAccountChooserPriv *priv;
- GtkTreeModel *model;
-
g_return_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (self));
- priv = GET_PRIV (self);
-
- priv->filter = filter;
- priv->filter_data = user_data;
+ self->priv->filter = filter;
+ self->priv->filter_data = user_data;
/* Refilter existing data */
- priv->set_active_item = FALSE;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
- gtk_tree_model_foreach (model, account_chooser_filter_foreach, self);
+ empathy_account_chooser_refilter (self);
}
/**
* Return value: whether the account indicated by @account is visible.
*/
+gboolean
+empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
+{
+ return self->priv->ready;
+}
+
+TpAccount *
+empathy_account_chooser_get_account (EmpathyAccountChooser *self)
+{
+ TpAccount *account;
+
+ account = empathy_account_chooser_dup_account (self);
+ if (account == NULL)
+ return NULL;
+
+ g_object_unref (account);
+
+ return account;
+}
+
+TpAccountManager *
+empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
+{
+ return self->priv->manager;
+}
+
+/* Pre-defined filters */
+
/**
* empathy_account_chooser_filter_is_connected:
* @account: a #TpAccount
out:
callback (supported, callback_data);
}
-
-gboolean
-empathy_account_chooser_is_ready (EmpathyAccountChooser *self)
-{
- EmpathyAccountChooserPriv *priv = GET_PRIV (self);
-
- return priv->ready;
-}
-
-TpAccount *
-empathy_account_chooser_get_account (EmpathyAccountChooser *self)
-{
- TpAccount *account;
-
- account = empathy_account_chooser_dup_account (self);
- if (account == NULL)
- return NULL;
-
- g_object_unref (account);
-
- return account;
-}
-
-TpAccountManager *
-empathy_account_chooser_get_account_manager (EmpathyAccountChooser *self)
-{
- EmpathyAccountChooserPriv *priv = GET_PRIV (self);
-
- return priv->manager;
-}