*/
#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"
+#include <tp-account-widgets/tpaw-pixbuf-utils.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);
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,
static void
empathy_account_chooser_init (EmpathyAccountChooser *self)
{
- EmpathyAccountChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ TpSimpleClientFactory *factory;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
- self->priv = priv;
- priv->set_active_item = FALSE;
- priv->account_manually_set = FALSE;
- priv->filter = NULL;
- priv->filter_data = NULL;
+ self->priv->set_active_item = FALSE;
+ self->priv->account_manually_set = FALSE;
+ self->priv->filter = NULL;
+ self->priv->filter_data = NULL;
+
+ self->priv->manager = tp_account_manager_dup ();
- priv->manager = tp_account_manager_dup ();
+ tp_g_signal_connect_object (self->priv->manager, "account-validity-changed",
+ G_CALLBACK (account_chooser_account_validity_changed_cb), self, 0);
- 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);
+ 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
return result;
}
+static void
+account_connection_notify_cb (TpAccount *account,
+ GParamSpec *spec,
+ EmpathyAccountChooser *self)
+{
+ update_account (self, account);
+}
+
static void
account_manager_prepared_cb (GObject *source_object,
GAsyncResult *result,
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))
return;
}
- accounts = tp_account_manager_get_valid_accounts (manager);
+ accounts = tp_account_manager_dup_valid_accounts (manager);
for (l = accounts; l != NULL; l = l->next)
{
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 (accounts);
+ 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);
+ }
- priv->ready = TRUE;
+ self->priv->ready = TRUE;
g_signal_emit (self, signals[READY], 0);
}
account_chooser_constructed (GObject *object)
{
EmpathyAccountChooser *self = (EmpathyAccountChooser *) object;
- EmpathyAccountChooserPriv *priv;
GtkListStore *store;
GtkCellRenderer *renderer;
GtkComboBox *combobox;
- priv = GET_PRIV (self);
+ if (G_OBJECT_CLASS (empathy_account_chooser_parent_class)->constructed)
+ G_OBJECT_CLASS
+ (empathy_account_chooser_parent_class)->constructed (object);
/* Set up combo box with new store */
combobox = GTK_COMBO_BOX (self);
NULL);
/* Populate accounts */
- tp_proxy_prepare_async (priv->manager, NULL, account_manager_prepared_cb,
- self);
+ tp_proxy_prepare_async (self->priv->manager, NULL,
+ account_manager_prepared_cb, self);
g_object_unref (store);
}
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);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = account_chooser_constructed;
- object_class->finalize = account_chooser_finalize;
+ object_class->dispose = account_chooser_dispose;
object_class->get_property = account_chooser_get_property;
object_class->set_property = account_chooser_set_property;
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
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);
store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
icon_name = tp_account_get_icon_name (account);
- pixbuf = empathy_pixbuf_from_icon_name (icon_name,
+ pixbuf = tpaw_pixbuf_from_icon_name (icon_name,
GTK_ICON_SIZE_BUTTON);
gtk_list_store_set (store, iter,
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;
-}