#include <string.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
-#include <glade/glade.h>
-#include <libtelepathy/tp-conn.h>
-#include <libmissioncontrol/mc-account-monitor.h>
#include <libmissioncontrol/mission-control.h>
+#include <libempathy/empathy-account-manager.h>
#include <libempathy/empathy-utils.h>
#include "empathy-ui-utils.h"
#include "empathy-account-chooser.h"
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv))
+/**
+ * SECTION:empathy-account-chooser
+ * @title:EmpathyAccountChooser
+ * @short_description: A widget used to choose from a list of accounts
+ * @include: libempathy-gtk/empathy-account-chooser.h
+ *
+ * #EmpathyAccountChooser is a widget which extends #GtkComboBox to provide
+ * a chooser of available accounts.
+ */
+
+/**
+ * EmpathyAccountChooser:
+ * @parent: parent object
+ *
+ * Widget which extends #GtkComboBox to provide a chooser of available accounts.
+ */
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountChooser)
typedef struct {
- MissionControl *mc;
- McAccountMonitor *monitor;
+ EmpathyAccountManager *manager;
gboolean set_active_item;
gboolean has_all_option;
EmpathyAccountChooserFilterFunc filter;
const GValue *value,
GParamSpec *pspec);
static void account_chooser_setup (EmpathyAccountChooser *chooser);
-static void account_chooser_account_created_cb (McAccountMonitor *monitor,
- const gchar *unique_name,
+static void account_chooser_account_created_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountChooser *chooser);
static void account_chooser_account_add_foreach (McAccount *account,
EmpathyAccountChooser *chooser);
-static void account_chooser_account_deleted_cb (McAccountMonitor *monitor,
- const gchar *unique_name,
+static void account_chooser_account_deleted_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountChooser *chooser);
static void account_chooser_account_remove_foreach (McAccount *account,
EmpathyAccountChooser *chooser);
static void account_chooser_update_iter (EmpathyAccountChooser *chooser,
GtkTreeIter *iter);
-static void account_chooser_status_changed_cb (MissionControl *mc,
- TpConnectionStatus status,
- McPresence presence,
+static void account_chooser_connection_changed_cb (EmpathyAccountManager *manager,
+ McAccount *account,
TpConnectionStatusReason reason,
- const gchar *unique_name,
+ TpConnectionStatus new_status,
+ TpConnectionStatus old_status,
EmpathyAccountChooser *chooser);
static gboolean account_chooser_separator_func (GtkTreeModel *model,
GtkTreeIter *iter,
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",
static void
empathy_account_chooser_init (EmpathyAccountChooser *chooser)
{
- EmpathyAccountChooserPriv *priv = GET_PRIV (chooser);
+ EmpathyAccountChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
+ EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserPriv);
+ chooser->priv = priv;
priv->set_active_item = FALSE;
priv->filter = NULL;
priv->filter_data = NULL;
+
+ priv->manager = empathy_account_manager_dup_singleton ();
+
+ g_signal_connect (priv->manager, "account-created",
+ G_CALLBACK (account_chooser_account_created_cb),
+ chooser);
+ g_signal_connect (priv->manager, "account-deleted",
+ G_CALLBACK (account_chooser_account_deleted_cb),
+ chooser);
+ g_signal_connect (priv->manager, "account-connection-changed",
+ G_CALLBACK (account_chooser_connection_changed_cb),
+ chooser);
+
+ account_chooser_setup (EMPATHY_ACCOUNT_CHOOSER (chooser));
}
static void
account_chooser_finalize (GObject *object)
{
- EmpathyAccountChooser *chooser;
- EmpathyAccountChooserPriv *priv;
+ EmpathyAccountChooserPriv *priv = GET_PRIV (object);
- chooser = EMPATHY_ACCOUNT_CHOOSER (object);
- priv = GET_PRIV (object);
-
- g_signal_handlers_disconnect_by_func (priv->monitor,
+ g_signal_handlers_disconnect_by_func (priv->manager,
+ account_chooser_connection_changed_cb,
+ object);
+ g_signal_handlers_disconnect_by_func (priv->manager,
account_chooser_account_created_cb,
- chooser);
- g_signal_handlers_disconnect_by_func (priv->monitor,
+ object);
+ g_signal_handlers_disconnect_by_func (priv->manager,
account_chooser_account_deleted_cb,
- chooser);
- dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
- "AccountStatusChanged",
- G_CALLBACK (account_chooser_status_changed_cb),
- chooser);
- g_object_unref (priv->mc);
- g_object_unref (priv->monitor);
+ object);
+ g_object_unref (priv->manager);
G_OBJECT_CLASS (empathy_account_chooser_parent_class)->finalize (object);
}
};
}
+/**
+ * empathy_account_chooser_new:
+ *
+ * Creates a new #EmpathyAccountChooser.
+ *
+ * Return value: A new #EmpathyAccountChooser
+ */
GtkWidget *
empathy_account_chooser_new (void)
{
- EmpathyAccountChooserPriv *priv;
- McAccountMonitor *monitor;
GtkWidget *chooser;
- monitor = mc_account_monitor_new ();
chooser = g_object_new (EMPATHY_TYPE_ACCOUNT_CHOOSER, NULL);
- priv = GET_PRIV (chooser);
-
- priv->mc = empathy_mission_control_new ();
- priv->monitor = mc_account_monitor_new ();
-
- g_signal_connect (priv->monitor, "account-created",
- G_CALLBACK (account_chooser_account_created_cb),
- chooser);
- g_signal_connect (priv->monitor, "account-deleted",
- G_CALLBACK (account_chooser_account_deleted_cb),
- chooser);
- dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged",
- G_CALLBACK (account_chooser_status_changed_cb),
- chooser, NULL);
-
- account_chooser_setup (EMPATHY_ACCOUNT_CHOOSER (chooser));
-
return chooser;
}
+/**
+ * empathy_account_chooser_dup_account:
+ * @chooser: an #EmpathyAccountChooser
+ *
+ * Returns the account which is currently selected in the chooser or %NULL
+ * if there is no account selected. The #McAccount returned should be
+ * unrefed with g_object_unref() when finished with.
+ *
+ * Return value: a new ref to the #McAccount currently selected, or %NULL.
+ */
McAccount *
-empathy_account_chooser_get_account (EmpathyAccountChooser *chooser)
+empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser)
{
EmpathyAccountChooserPriv *priv;
McAccount *account;
priv = GET_PRIV (chooser);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (chooser), &iter);
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (chooser), &iter)) {
+ return NULL;
+ }
gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
return account;
}
+/**
+ * empathy_account_chooser_get_connection:
+ * @chooser: an #EmpathyAccountChooser
+ *
+ * Returns a borrowed reference to the #TpConnection associated with the
+ * account currently selected. The caller must reference the returned object with
+ * g_object_ref() if it will be kept
+ *
+ * Return value: a borrowed reference to the #TpConnection associated with the
+ * account curently selected.
+ */
+TpConnection *
+empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser)
+{
+ EmpathyAccountChooserPriv *priv;
+ McAccount *account;
+ TpConnection *connection;
+
+ g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), NULL);
+
+ priv = GET_PRIV (chooser);
+
+ account = empathy_account_chooser_dup_account (chooser);
+ connection = empathy_account_manager_get_connection (priv->manager, account);
+ g_object_unref (account);
+
+ return connection;
+}
+
+/**
+ * empathy_account_chooser_set_account:
+ * @chooser: an #EmpathyAccountChooser
+ * @account: an #McAccount
+ *
+ * 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 *chooser,
McAccount *account)
return data.set;
}
+/**
+ * empathy_account_chooser_get_has_all_option:
+ * @chooser: an #EmpathyAccountChooser
+ *
+ * Returns whether @chooser has the #EmpathyAccountChooser:has-all-option property
+ * set to true.
+ *
+ * Return value: whether @chooser has the #EmpathyAccountChooser:has-all-option property
+ * enabled.
+ */
gboolean
empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *chooser)
{
return priv->has_all_option;
}
+/**
+ * empathy_account_chooser_set_has_all_option:
+ * @chooser: an #EmpathyAccountChooser
+ * @has_all_option: a new value for the #EmpathyAccountChooser:has-all-option property
+ *
+ * Sets the #EmpathyAccountChooser:has-all-option property.
+ */
void
empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *chooser,
gboolean has_all_option)
}
static void
-account_chooser_account_created_cb (McAccountMonitor *monitor,
- const gchar *unique_name,
+account_chooser_account_created_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountChooser *chooser)
{
- McAccount *account;
-
- account = mc_account_lookup (unique_name);
account_chooser_account_add_foreach (account, chooser);
- g_object_unref (account);
}
static void
}
static void
-account_chooser_account_deleted_cb (McAccountMonitor *monitor,
- const gchar *unique_name,
+account_chooser_account_deleted_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountChooser *chooser)
{
- McAccount *account;
-
- account = mc_account_lookup (unique_name);
account_chooser_account_remove_foreach (account, chooser);
- g_object_unref (account);
}
typedef struct {
}
static void
-account_chooser_status_changed_cb (MissionControl *mc,
- TpConnectionStatus status,
- McPresence presence,
- TpConnectionStatusReason reason,
- const gchar *unique_name,
- EmpathyAccountChooser *chooser)
+account_chooser_connection_changed_cb (EmpathyAccountManager *manager,
+ McAccount *account,
+ TpConnectionStatusReason reason,
+ TpConnectionStatus new_status,
+ TpConnectionStatus old_status,
+ EmpathyAccountChooser *chooser)
{
- McAccount *account;
- GtkTreeIter iter;
+ GtkTreeIter iter;
- account = mc_account_lookup (unique_name);
if (account_chooser_find_account (chooser, account, &iter)) {
account_chooser_update_iter (chooser, &iter);
}
- g_object_unref (account);
}
static gboolean
gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
/* Special case so we can make it possible to select the All option */
- if (!data->account && !account) {
- equal = TRUE;
- }
- else if ((data->account && !account) || (!data->account && account)) {
+ if ((data->account == NULL) != (account == NULL)) {
equal = FALSE;
+ }
+ else if (data->account == account) {
+ equal = TRUE;
} else {
equal = empathy_account_equal (data->account, account);
+ }
+
+ if (account) {
g_object_unref (account);
}
return FALSE;
}
+/**
+ * empathy_account_chooser_set_filter:
+ * @chooser: an #EmpathyAccountChooser
+ * @filter: a filter
+ * @user_data: data to pass to @filter, or %NULL
+ *
+ * Sets a filter on the @chooser so only accounts that are %TRUE in the eyes
+ * of the filter are visible in the @chooser.
+ */
void
empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser,
EmpathyAccountChooserFilterFunc filter,
gtk_tree_model_foreach (model, account_chooser_filter_foreach, chooser);
}
+/**
+ * EmpathyAccountChooserFilterFunc:
+ * @account: an #McAccount
+ * @user_data: user data, or %NULL
+ *
+ * A function which decides whether the account indicated by @account
+ * is visible.
+ *
+ * Return value: whether the account indicated by @account is visible.
+ */
+
+/**
+ * empathy_account_chooser_filter_is_connected:
+ * @account: an #McAccount
+ * @user_data: user data or %NULL
+ *
+ * A useful #EmpathyAccountChooserFilterFunc that one could pass into
+ * empathy_account_chooser_set_filter() and only show connected accounts.
+ *
+ * Return value: Whether @account is connected
+ */
gboolean
empathy_account_chooser_filter_is_connected (McAccount *account,
gpointer user_data)
g_return_val_if_fail (MC_IS_ACCOUNT (account), FALSE);
- mc = empathy_mission_control_new ();
+ mc = empathy_mission_control_dup_singleton ();
status = mission_control_get_connection_status (mc, account, NULL);
g_object_unref (mc);