From adef4b7fed1d3555723b7e223781f6caa1a8e015 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 10:28:04 +0100 Subject: Add API to get the protocol and cm name from a account --- libempathy/empathy-account.c | 55 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index e0a8e756b..3bae8f5b5 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -73,6 +73,10 @@ struct _EmpathyAccountPriv glong connect_time; McAccount *mc_account; + McProfile *mc_profile; + + gchar *cm_name; + gchar *proto_name; }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) @@ -236,6 +240,10 @@ empathy_account_dispose (GObject *object) g_object_unref (priv->connection); priv->connection = NULL; + if (priv->mc_profile != NULL) + g_object_unref (priv->mc_profile); + priv->mc_profile = NULL; + /* release any references held by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL) G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object); @@ -244,6 +252,11 @@ empathy_account_dispose (GObject *object) void empathy_account_finalize (GObject *object) { + EmpathyAccountPriv *priv = GET_PRIV (object); + + g_free (priv->cm_name); + g_free (priv->proto_name); + /* free any data held directly by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL) G_OBJECT_CLASS (empathy_account_parent_class)->finalize (object); @@ -320,6 +333,22 @@ empathy_account_is_valid (EmpathyAccount *account) return mc_account_is_complete (priv->mc_account); } +const gchar * +empathy_account_get_connection_manager (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + return priv->cm_name; +} + +const gchar * +empathy_account_get_protocol (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + return priv->proto_name; +} + void empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { @@ -409,23 +438,34 @@ empathy_account_set_display_name (EmpathyAccount *account, mc_account_set_display_name (priv->mc_account, display_name); } -McProfile * -empathy_account_get_profile (EmpathyAccount *account) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_get_profile (priv->mc_account); -} - EmpathyAccount * _empathy_account_new (McAccount *mc_account) { EmpathyAccount *account; EmpathyAccountPriv *priv; + McProfile *profile; + McProtocol *protocol; + account = g_object_new (EMPATHY_TYPE_ACCOUNT, NULL); priv = GET_PRIV (account); priv->mc_account = mc_account; + profile = mc_account_get_profile (mc_account); + protocol = mc_profile_get_protocol (profile); + + if (protocol != NULL) + { + McManager *manager = mc_protocol_get_manager (protocol); + + priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); + priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); + + g_object_unref (protocol); + g_object_unref (manager); + } + g_object_unref (profile); + return account; } @@ -571,5 +611,6 @@ McAccount * _empathy_account_get_mc_account (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); + return priv->mc_account; } -- cgit v1.2.3 From ddcb104dfa874375ea17cac4de2f273af7327fc4 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 5 Jul 2009 10:43:50 +0100 Subject: Get the icon name from the account object directly --- libempathy/empathy-account.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 3bae8f5b5..c6a2184f9 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -77,6 +77,7 @@ struct _EmpathyAccountPriv gchar *cm_name; gchar *proto_name; + gchar *icon_name; }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) @@ -256,6 +257,7 @@ empathy_account_finalize (GObject *object) g_free (priv->cm_name); g_free (priv->proto_name); + g_free (priv->icon_name); /* free any data held directly by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL) @@ -349,6 +351,14 @@ empathy_account_get_protocol (EmpathyAccount *account) return priv->proto_name; } +const gchar * +empathy_account_get_icon_name (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + return priv->icon_name; +} + void empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { @@ -460,6 +470,7 @@ _empathy_account_new (McAccount *mc_account) priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); + priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); g_object_unref (protocol); g_object_unref (manager); -- cgit v1.2.3 From 96fad6a1159582a3e8792dd3308ce1fbeb178234 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 8 Jul 2009 11:35:43 +0100 Subject: Initial port of Account and AccountManager to MC5 --- libempathy/empathy-account.c | 368 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 300 insertions(+), 68 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index c6a2184f9..010990d7a 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -18,20 +18,25 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - #include #include +#include #include +#include +#include +#include +#include #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include #include "empathy-account.h" -#include "empathy-account-priv.h" #include "empathy-utils.h" #include "empathy-marshal.h" +#define UNIQUE_NAME_PREFIX "/org/freedesktop/Telepathy/Account/" + /* signals */ enum { STATUS_CHANGED, @@ -45,10 +50,12 @@ static guint signals[LAST_SIGNAL]; enum { PROP_ENABLED = 1, PROP_PRESENCE, + PROP_READY, PROP_CONNECTION_STATUS, PROP_CONNECTION_STATUS_REASON, PROP_CONNECTION, PROP_UNIQUE_NAME, + PROP_DBUS_DAEMON, PROP_DISPLAY_NAME }; @@ -69,19 +76,28 @@ struct _EmpathyAccountPriv TpConnectionPresenceType presence; gboolean enabled; + gboolean valid; + gboolean ready; /* Timestamp when the connection got connected in seconds since the epoch */ glong connect_time; - McAccount *mc_account; - McProfile *mc_profile; - gchar *cm_name; gchar *proto_name; gchar *icon_name; + + gchar *unique_name; + gchar *display_name; + TpDBusDaemon *dbus; + + TpAccount *account; + GHashTable *parameters; }; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) +static void _empathy_account_set_connection (EmpathyAccount *account, + TpConnection *connection); + static void empathy_account_init (EmpathyAccount *obj) { @@ -95,6 +111,32 @@ empathy_account_init (EmpathyAccount *obj) priv->status = TP_CONNECTION_STATUS_DISCONNECTED; } +static void +empathy_account_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + switch (prop_id) + { + case PROP_ENABLED: + empathy_account_set_enabled (account, g_value_get_boolean (value)); + break; + case PROP_UNIQUE_NAME: + priv->unique_name = g_value_dup_string (value); + break; + case PROP_DBUS_DAEMON: + priv->dbus = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void empathy_account_get_property (GObject *object, guint prop_id, @@ -109,6 +151,9 @@ empathy_account_get_property (GObject *object, case PROP_ENABLED: g_value_set_boolean (value, priv->enabled); break; + case PROP_READY: + g_value_set_boolean (value, priv->enabled); + break; case PROP_PRESENCE: g_value_set_uint (value, priv->presence); break; @@ -130,12 +175,208 @@ empathy_account_get_property (GObject *object, g_value_set_string (value, empathy_account_get_display_name (account)); break; + case PROP_DBUS_DAEMON: + g_value_set_string (value, + empathy_account_get_display_name (account)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } +static void +empathy_account_update (EmpathyAccount *account, GHashTable *properties) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + const gchar *conn_path; + GValueArray *arr; + TpConnectionStatus old_s = priv->status; + TpConnectionPresenceType old_p = priv->presence; + + if (g_hash_table_lookup (properties, "ConnectionStatus") != NULL) + priv->status = tp_asv_get_int32 (properties, "ConnectionStatus", NULL); + + if (g_hash_table_lookup (properties, "ConnectionStatusReason") != NULL) + priv->reason = tp_asv_get_int32 (properties, + "ConnectionStatusReason", NULL); + + if (g_hash_table_lookup (properties, "CurrentPresence") != NULL) + { + arr = tp_asv_get_boxed (properties, "CurrentPresence", + TP_STRUCT_TYPE_SIMPLE_PRESENCE); + priv->presence = g_value_get_uint (g_value_array_get_nth (arr, 0)); + } + + if (g_hash_table_lookup (properties, "DisplayName") != NULL) + priv->display_name = + g_strdup (tp_asv_get_string (properties, "DisplayName")); + + if (g_hash_table_lookup (properties, "Enabled") != NULL) + empathy_account_set_enabled (account, + tp_asv_get_boolean (properties, "Enabled", NULL)); + + if (g_hash_table_lookup (properties, "Valid") != NULL) + priv->valid = tp_asv_get_boolean (properties, "Valid", NULL); + + if (g_hash_table_lookup (properties, "Parameters") != NULL) + { + GHashTable *parameters; + + parameters = tp_asv_get_boxed (properties, "Parameters", + TP_HASH_TYPE_STRING_VARIANT_MAP); + + priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, + parameters); + } + + if (!priv->ready) + { + priv->ready = TRUE; + g_object_notify (G_OBJECT (account), "ready"); + } + + if (priv->status != old_s) + { + if (priv->status == TP_CONNECTION_STATUS_CONNECTED) + { + GTimeVal val; + g_get_current_time (&val); + + priv->connect_time = val.tv_sec; + } + + g_signal_emit (account, signals[STATUS_CHANGED], 0, + old_s, priv->status, priv->reason); + + g_object_notify (G_OBJECT (account), "status"); + } + + if (priv->presence != old_p) + { + g_signal_emit (account, signals[PRESENCE_CHANGED], 0, + old_p, priv->presence); + g_object_notify (G_OBJECT (account), "presence"); + } + + if (g_hash_table_lookup (properties, "Connection") != NULL) + { + conn_path = tp_asv_get_object_path (properties, "Connection"); + + if (tp_strdiff (conn_path, "/") && priv->connection == NULL) + { + TpConnection *conn; + GError *error = NULL; + conn = tp_connection_new (priv->dbus, NULL, conn_path, &error); + + if (conn == NULL) + { + DEBUG ("Failed to create a new TpConnection: %s", + error->message); + g_error_free (error); + } + + _empathy_account_set_connection (account, conn); + } + } +} + +static void +empathy_account_properties_changed (TpAccount *proxy, + GHashTable *properties, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (!priv->ready) + return; + + empathy_account_update (account, properties); +} + +static void +empathy_account_got_all_cb (TpProxy *proxy, + GHashTable *properties, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + + if (error != NULL) + { + printf ("Unhappy\n"); + return; + } + + empathy_account_update (account, properties); +} + +static gboolean +empathy_account_parse_unique_name (const gchar *bus_name, + gchar **protocol, gchar **manager) +{ + const gchar *proto, *proto_end; + const gchar *cm, *cm_end; + + g_return_val_if_fail ( + g_str_has_prefix (bus_name, UNIQUE_NAME_PREFIX), FALSE); + + cm = bus_name + strlen (UNIQUE_NAME_PREFIX); + + for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++) + /* pass */; + + if (*cm_end == '\0') + return FALSE; + + if (cm_end == '\0') + return FALSE; + + proto = cm_end + 1; + + for (proto_end = proto; *proto_end != '/' && *proto_end != '\0'; proto_end++) + /* pass */; + + if (*proto_end == '\0') + return FALSE; + + if (protocol != NULL) + *protocol = g_strndup (proto, proto_end - proto); + + if (manager != NULL) + *manager = g_strndup (cm, cm_end - cm); + + return TRUE; +} + +static void +empathy_account_constructed (GObject *object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL); + + empathy_account_parse_unique_name (priv->unique_name, + &(priv->proto_name), &(priv->cm_name)); + + priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); + + tp_cli_account_connect_to_account_property_changed (priv->account, + empathy_account_properties_changed, + NULL, NULL, object, NULL); + + tp_cli_dbus_properties_call_get_all (priv->account, -1, + TP_IFACE_ACCOUNT, + empathy_account_got_all_cb, + NULL, + NULL, + G_OBJECT (account)); +} + static void empathy_account_dispose (GObject *object); static void empathy_account_finalize (GObject *object); @@ -147,15 +388,24 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) g_type_class_add_private (empathy_account_class, sizeof (EmpathyAccountPriv)); + object_class->set_property = empathy_account_set_property; object_class->get_property = empathy_account_get_property; object_class->dispose = empathy_account_dispose; object_class->finalize = empathy_account_finalize; + object_class->constructed = empathy_account_constructed; g_object_class_install_property (object_class, PROP_ENABLED, g_param_spec_boolean ("enabled", "Enabled", "Whether this account is enabled or not", FALSE, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_READY, + g_param_spec_boolean ("ready", + "Ready", + "Whether this account is ready to be used", + FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_PRESENCE, @@ -197,7 +447,14 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) "UniqueName", "The accounts unique name", NULL, - G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_DBUS_DAEMON, + g_param_spec_object ("dbus-daemon", + "dbus-daemon", + "The Tp Dbus daemon on which this account exists", + TP_TYPE_DBUS_DAEMON, + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_DISPLAY_NAME, g_param_spec_string ("display-name", @@ -241,10 +498,6 @@ empathy_account_dispose (GObject *object) g_object_unref (priv->connection); priv->connection = NULL; - if (priv->mc_profile != NULL) - g_object_unref (priv->mc_profile); - priv->mc_profile = NULL; - /* release any references held by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL) G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object); @@ -258,6 +511,7 @@ empathy_account_finalize (GObject *object) g_free (priv->cm_name); g_free (priv->proto_name); g_free (priv->icon_name); + g_free (priv->display_name); /* free any data held directly by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL) @@ -310,7 +564,7 @@ empathy_account_get_unique_name (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_get_unique_name (priv->mc_account); + return priv->unique_name; } /** @@ -324,15 +578,16 @@ empathy_account_get_display_name (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_get_display_name (priv->mc_account); + return priv->display_name; } gboolean empathy_account_is_valid (EmpathyAccount *account) { - EmpathyAccountPriv *priv = GET_PRIV (account); + //EmpathyAccountPriv *priv = GET_PRIV (account); - return mc_account_is_complete (priv->mc_account); + /* FIXME */ + return FALSE; } const gchar * @@ -359,14 +614,6 @@ empathy_account_get_icon_name (EmpathyAccount *account) return priv->icon_name; } -void -empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - - mc_account_set_enabled (priv->mc_account, enabled); -} - gboolean empathy_account_is_enabled (EmpathyAccount *account) { @@ -378,39 +625,33 @@ empathy_account_is_enabled (EmpathyAccount *account) void empathy_account_unset_param (EmpathyAccount *account, const gchar *param) { - EmpathyAccountPriv *priv = GET_PRIV (account); + //EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_unset_param (priv->mc_account, param); + //mc_account_unset_param (priv->mc_account, param); } -gchar * +const gchar * empathy_account_get_param_string (EmpathyAccount *account, const gchar *param) { EmpathyAccountPriv *priv = GET_PRIV (account); - gchar *value = NULL; - mc_account_get_param_string (priv->mc_account, param, &value); - return value; + return tp_asv_get_string (priv->parameters, param); } gint empathy_account_get_param_int (EmpathyAccount *account, const gchar *param) { EmpathyAccountPriv *priv = GET_PRIV (account); - int value; - mc_account_get_param_int (priv->mc_account, param, &value); - return value; + return tp_asv_get_int32 (priv->parameters, param, NULL); } gboolean empathy_account_get_param_boolean (EmpathyAccount *account, const gchar *param) { EmpathyAccountPriv *priv = GET_PRIV (account); - gboolean value; - mc_account_get_param_boolean (priv->mc_account, param, &value); - return value; + return tp_asv_get_boolean (priv->parameters, param, NULL); } void @@ -418,8 +659,8 @@ empathy_account_set_param_string (EmpathyAccount *account, const gchar *param, const gchar *value) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_param_string (priv->mc_account, param, value); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_param_string (priv->mc_account, param, value); } void @@ -427,8 +668,8 @@ empathy_account_set_param_int (EmpathyAccount *account, const gchar *param, gint value) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_param_int (priv->mc_account, param, value); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_param_int (priv->mc_account, param, value); } void @@ -436,18 +677,29 @@ empathy_account_set_param_boolean (EmpathyAccount *account, const gchar *param, gboolean value) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_param_boolean (priv->mc_account, param, value); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_param_boolean (priv->mc_account, param, value); } void empathy_account_set_display_name (EmpathyAccount *account, const gchar *display_name) { - EmpathyAccountPriv *priv = GET_PRIV (account); - mc_account_set_display_name (priv->mc_account, display_name); + //EmpathyAccountPriv *priv = GET_PRIV (account); + //mc_account_set_display_name (priv->mc_account, display_name); } + +EmpathyAccount * +empathy_account_new (TpDBusDaemon *dbus, const gchar *unique_name) +{ + return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT, + "dbus-daemon", dbus, + "unique-name", unique_name, + NULL)); +} + +#if 0 EmpathyAccount * _empathy_account_new (McAccount *mc_account) { @@ -470,7 +722,6 @@ _empathy_account_new (McAccount *mc_account) priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); - priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); g_object_unref (protocol); g_object_unref (manager); @@ -493,30 +744,8 @@ _empathy_account_set_status (EmpathyAccount *account, priv->status = status; priv->presence = presence; - if (priv->status != old_s) - { - if (priv->status == TP_CONNECTION_STATUS_CONNECTED) - { - GTimeVal val; - g_get_current_time (&val); - - priv->connect_time = val.tv_sec; - } - - priv->reason = reason; - g_signal_emit (account, signals[STATUS_CHANGED], 0, - old_s, priv->status, reason); - - g_object_notify (G_OBJECT (account), "status"); - } - - if (priv->presence != old_p) - { - g_signal_emit (account, signals[PRESENCE_CHANGED], 0, - old_p, priv->presence); - g_object_notify (G_OBJECT (account), "presence"); - } } +#endif static void empathy_account_connection_ready_cb (TpConnection *connection, @@ -568,7 +797,7 @@ _empathy_account_connection_invalidated_cb (TpProxy *self, g_object_notify (G_OBJECT (account), "connection"); } -void +static void _empathy_account_set_connection (EmpathyAccount *account, TpConnection *connection) { @@ -599,6 +828,7 @@ _empathy_account_set_connection (EmpathyAccount *account, G_CALLBACK (_empathy_account_connection_invalidated_cb), account); + DEBUG ("Readying connection for %s", priv->unique_name); /* notify a change in the connection property when it's ready */ tp_connection_call_when_ready (priv->connection, empathy_account_connection_ready_cb, account); @@ -606,7 +836,7 @@ _empathy_account_set_connection (EmpathyAccount *account, } void -_empathy_account_set_enabled (EmpathyAccount *account, +empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { EmpathyAccountPriv *priv = GET_PRIV (account); @@ -618,6 +848,7 @@ _empathy_account_set_enabled (EmpathyAccount *account, g_object_notify (G_OBJECT (account), "enabled"); } +#if 0 McAccount * _empathy_account_get_mc_account (EmpathyAccount *account) { @@ -625,3 +856,4 @@ _empathy_account_get_mc_account (EmpathyAccount *account) return priv->mc_account; } +#endif -- cgit v1.2.3 From 6389342273e991e9b4c17d15fe82b709801a6983 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 8 Jul 2009 16:18:56 +0100 Subject: Add api to set the requested presence --- libempathy/empathy-account.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 010990d7a..d965fac62 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -848,6 +848,49 @@ empathy_account_set_enabled (EmpathyAccount *account, g_object_notify (G_OBJECT (account), "enabled"); } +static void +empathy_account_requested_presence_cb (TpProxy *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + if (error) + DEBUG (":( : %s", error->message); +} + + +void +empathy_account_request_presence (EmpathyAccount *account, + TpConnectionPresenceType type, + const gchar *status, + const gchar *message) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + GValue value = {0, }; + GValueArray *arr; + + g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE); + g_value_take_boxed (&value, dbus_g_type_specialized_construct + (TP_STRUCT_TYPE_SIMPLE_PRESENCE)); + arr = (GValueArray *) g_value_get_boxed (&value); + + g_value_set_uint (arr->values, type); + g_value_set_static_string (arr->values + 1, status); + g_value_set_static_string (arr->values + 2, message); + + tp_cli_dbus_properties_call_set (TP_PROXY (priv->account), + -1, + TP_IFACE_ACCOUNT, + "RequestedPresence", + &value, + empathy_account_requested_presence_cb, + NULL, + NULL, + G_OBJECT (account)); + + g_value_unset (&value); +} + #if 0 McAccount * _empathy_account_get_mc_account (EmpathyAccount *account) -- cgit v1.2.3 From aafc27b739884d4c9e5fe0d9cabee52445eaa4ba Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 14:53:29 +0100 Subject: Keep track of ``global'' presence of all accounts --- libempathy/empathy-account.c | 69 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 15 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index d965fac62..5bfa38765 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -27,6 +27,7 @@ #include #include #include +#include #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include @@ -50,6 +51,8 @@ static guint signals[LAST_SIGNAL]; enum { PROP_ENABLED = 1, PROP_PRESENCE, + PROP_STATUS, + PROP_STATUS_MESSAGE, PROP_READY, PROP_CONNECTION_STATUS, PROP_CONNECTION_STATUS_REASON, @@ -71,9 +74,12 @@ struct _EmpathyAccountPriv TpConnection *connection; guint connection_invalidated_id; - TpConnectionStatus status; + TpConnectionStatus connection_status; TpConnectionStatusReason reason; + TpConnectionPresenceType presence; + gchar *status; + gchar *message; gboolean enabled; gboolean valid; @@ -108,7 +114,7 @@ empathy_account_init (EmpathyAccount *obj) obj->priv = priv; - priv->status = TP_CONNECTION_STATUS_DISCONNECTED; + priv->connection_status = TP_CONNECTION_STATUS_DISCONNECTED; } static void @@ -157,8 +163,14 @@ empathy_account_get_property (GObject *object, case PROP_PRESENCE: g_value_set_uint (value, priv->presence); break; + case PROP_STATUS: + g_value_set_string (value, priv->status); + break; + case PROP_STATUS_MESSAGE: + g_value_set_string (value, priv->message); + break; case PROP_CONNECTION_STATUS: - g_value_set_uint (value, priv->status); + g_value_set_uint (value, priv->connection_status); break; case PROP_CONNECTION_STATUS_REASON: g_value_set_uint (value, priv->reason); @@ -191,11 +203,12 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) EmpathyAccountPriv *priv = GET_PRIV (account); const gchar *conn_path; GValueArray *arr; - TpConnectionStatus old_s = priv->status; - TpConnectionPresenceType old_p = priv->presence; + TpConnectionStatus old_s = priv->connection_status; + gboolean presence_changed = FALSE; if (g_hash_table_lookup (properties, "ConnectionStatus") != NULL) - priv->status = tp_asv_get_int32 (properties, "ConnectionStatus", NULL); + priv->connection_status = + tp_asv_get_int32 (properties, "ConnectionStatus", NULL); if (g_hash_table_lookup (properties, "ConnectionStatusReason") != NULL) priv->reason = tp_asv_get_int32 (properties, @@ -203,9 +216,16 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) if (g_hash_table_lookup (properties, "CurrentPresence") != NULL) { + presence_changed = TRUE; arr = tp_asv_get_boxed (properties, "CurrentPresence", TP_STRUCT_TYPE_SIMPLE_PRESENCE); priv->presence = g_value_get_uint (g_value_array_get_nth (arr, 0)); + + g_free (priv->status); + priv->status = g_value_dup_string (g_value_array_get_nth (arr, 1)); + + g_free (priv->message); + priv->message = g_value_dup_string (g_value_array_get_nth (arr, 2)); } if (g_hash_table_lookup (properties, "DisplayName") != NULL) @@ -236,9 +256,9 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) g_object_notify (G_OBJECT (account), "ready"); } - if (priv->status != old_s) + if (priv->connection_status != old_s) { - if (priv->status == TP_CONNECTION_STATUS_CONNECTED) + if (priv->connection_status == TP_CONNECTION_STATUS_CONNECTED) { GTimeVal val; g_get_current_time (&val); @@ -247,16 +267,18 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) } g_signal_emit (account, signals[STATUS_CHANGED], 0, - old_s, priv->status, priv->reason); + old_s, priv->connection_status, priv->reason); g_object_notify (G_OBJECT (account), "status"); } - if (priv->presence != old_p) + if (presence_changed) { g_signal_emit (account, signals[PRESENCE_CHANGED], 0, - old_p, priv->presence); + priv->presence, priv->status, priv->message); g_object_notify (G_OBJECT (account), "presence"); + g_object_notify (G_OBJECT (account), "status"); + g_object_notify (G_OBJECT (account), "status-message"); } if (g_hash_table_lookup (properties, "Connection") != NULL) @@ -417,8 +439,22 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) TP_CONNECTION_PRESENCE_TYPE_UNSET, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + g_object_class_install_property (object_class, PROP_STATUS, + g_param_spec_string ("status", + "Status", + "The Status string of the account", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + + g_object_class_install_property (object_class, PROP_STATUS_MESSAGE, + g_param_spec_string ("status-message", + "status-message", + "The Status message string of the account", + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + g_object_class_install_property (object_class, PROP_CONNECTION_STATUS, - g_param_spec_uint ("status", + g_param_spec_uint ("connection-status", "ConnectionStatus", "The accounts connections status type", 0, @@ -474,8 +510,8 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, - _empathy_marshal_VOID__UINT_UINT, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); + _empathy_marshal_VOID__UINT_STRING_STRING, + G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); } void @@ -508,6 +544,9 @@ empathy_account_finalize (GObject *object) { EmpathyAccountPriv *priv = GET_PRIV (object); + g_free (priv->status); + g_free (priv->message); + g_free (priv->cm_name); g_free (priv->proto_name); g_free (priv->icon_name); @@ -524,7 +563,7 @@ empathy_account_is_just_connected (EmpathyAccount *account) EmpathyAccountPriv *priv = GET_PRIV (account); GTimeVal val; - if (priv->status != TP_CONNECTION_STATUS_CONNECTED) + if (priv->connection_status != TP_CONNECTION_STATUS_CONNECTED) return FALSE; g_get_current_time (&val); -- cgit v1.2.3 From 17b571acbdbe5219c9b7c468006dda616cb7bb0a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 15 Jul 2009 18:18:27 +0100 Subject: Check the right variable for setting the ready property --- libempathy/empathy-account.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5bfa38765..a93d548e3 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -158,7 +158,7 @@ empathy_account_get_property (GObject *object, g_value_set_boolean (value, priv->enabled); break; case PROP_READY: - g_value_set_boolean (value, priv->enabled); + g_value_set_boolean (value, priv->ready); break; case PROP_PRESENCE: g_value_set_uint (value, priv->presence); -- cgit v1.2.3 From e4c629b216459740a76cb51b329be445c6a86a3e Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 19 Jul 2009 14:45:31 +0100 Subject: remove dead code --- libempathy/empathy-account.c | 58 -------------------------------------------- 1 file changed, 58 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index a93d548e3..ef377427d 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -738,54 +738,6 @@ empathy_account_new (TpDBusDaemon *dbus, const gchar *unique_name) NULL)); } -#if 0 -EmpathyAccount * -_empathy_account_new (McAccount *mc_account) -{ - EmpathyAccount *account; - EmpathyAccountPriv *priv; - McProfile *profile; - McProtocol *protocol; - - - account = g_object_new (EMPATHY_TYPE_ACCOUNT, NULL); - priv = GET_PRIV (account); - priv->mc_account = mc_account; - - profile = mc_account_get_profile (mc_account); - protocol = mc_profile_get_protocol (profile); - - if (protocol != NULL) - { - McManager *manager = mc_protocol_get_manager (protocol); - - priv->proto_name = g_strdup (mc_protocol_get_name (protocol)); - priv->cm_name = g_strdup (mc_manager_get_unique_name (manager)); - - g_object_unref (protocol); - g_object_unref (manager); - } - g_object_unref (profile); - - return account; -} - -void -_empathy_account_set_status (EmpathyAccount *account, - TpConnectionStatus status, - TpConnectionStatusReason reason, - TpConnectionPresenceType presence) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - TpConnectionStatus old_s = priv->status; - TpConnectionPresenceType old_p = priv->presence; - - priv->status = status; - priv->presence = presence; - -} -#endif - static void empathy_account_connection_ready_cb (TpConnection *connection, const GError *error, @@ -929,13 +881,3 @@ empathy_account_request_presence (EmpathyAccount *account, g_value_unset (&value); } - -#if 0 -McAccount * -_empathy_account_get_mc_account (EmpathyAccount *account) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - - return priv->mc_account; -} -#endif -- cgit v1.2.3 From b81f5d599018df2378b489f080b5a2a64a8f9c9a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:48:58 +0100 Subject: Remove the API to change the account parameters one by one --- libempathy/empathy-account.c | 67 ++++++-------------------------------------- 1 file changed, 8 insertions(+), 59 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index ef377427d..91edaed66 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -653,79 +653,28 @@ empathy_account_get_icon_name (EmpathyAccount *account) return priv->icon_name; } -gboolean -empathy_account_is_enabled (EmpathyAccount *account) +const GHashTable * +empathy_account_get_parameters (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return priv->enabled; -} - -void -empathy_account_unset_param (EmpathyAccount *account, const gchar *param) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - - //mc_account_unset_param (priv->mc_account, param); + return priv->parameters; } -const gchar * -empathy_account_get_param_string (EmpathyAccount *account, const gchar *param) -{ - EmpathyAccountPriv *priv = GET_PRIV (account); - - return tp_asv_get_string (priv->parameters, param); -} - -gint -empathy_account_get_param_int (EmpathyAccount *account, const gchar *param) +gboolean +empathy_account_is_enabled (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return tp_asv_get_int32 (priv->parameters, param, NULL); + return priv->enabled; } gboolean -empathy_account_get_param_boolean (EmpathyAccount *account, const gchar *param) +empathy_account_is_ready (EmpathyAccount *account) { EmpathyAccountPriv *priv = GET_PRIV (account); - return tp_asv_get_boolean (priv->parameters, param, NULL); -} - -void -empathy_account_set_param_string (EmpathyAccount *account, - const gchar *param, - const gchar *value) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_param_string (priv->mc_account, param, value); -} - -void -empathy_account_set_param_int (EmpathyAccount *account, - const gchar *param, - gint value) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_param_int (priv->mc_account, param, value); -} - -void -empathy_account_set_param_boolean (EmpathyAccount *account, - const gchar *param, - gboolean value) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_param_boolean (priv->mc_account, param, value); -} - -void -empathy_account_set_display_name (EmpathyAccount *account, - const gchar *display_name) -{ - //EmpathyAccountPriv *priv = GET_PRIV (account); - //mc_account_set_display_name (priv->mc_account, display_name); + return priv->ready; } -- cgit v1.2.3 From 10b85cf1e8161c7f3392f50dc329c89f3bb87512 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:50:43 +0100 Subject: Add API to Update an accounts parameters --- libempathy/empathy-account.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 91edaed66..5ad3ef464 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -830,3 +830,54 @@ empathy_account_request_presence (EmpathyAccount *account, g_value_unset (&value); } + +static void +empathy_account_updated_cb (TpAccount *proxy, + const gchar **reconnect_required, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + + if (error != NULL) + { + g_simple_async_result_set_from_error (result, (GError *)error); + } + + g_simple_async_result_complete (result); + g_object_unref (G_OBJECT (result)); +} + +void +empathy_account_update_settings_async (EmpathyAccount *account, + const GHashTable *parameters, const gchar **unset_parameters, + GAsyncReadyCallback callback, gpointer user_data) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account), + callback, user_data, empathy_account_update_settings_finish); + + tp_cli_account_call_update_parameters (priv->account, + -1, + (GHashTable *)parameters, + unset_parameters, + empathy_account_updated_cb, + result, + NULL, + G_OBJECT (account)); +} + +gboolean +empathy_account_update_settings_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (account), empathy_account_update_settings_finish), FALSE); + + return TRUE; +} -- cgit v1.2.3 From aeb06b95274c6c22501c752b9fb8864af6f1bc29 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 16:54:05 +0100 Subject: Make empathy_account_set_enable call out over d-bus --- libempathy/empathy-account.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5ad3ef464..21ece6f0d 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -233,8 +233,14 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) g_strdup (tp_asv_get_string (properties, "DisplayName")); if (g_hash_table_lookup (properties, "Enabled") != NULL) - empathy_account_set_enabled (account, - tp_asv_get_boolean (properties, "Enabled", NULL)); + { + gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL); + if (priv->enabled != enabled) + { + priv->enabled = enabled; + g_object_notify (G_OBJECT (account), "enabled"); + } + } if (g_hash_table_lookup (properties, "Valid") != NULL) priv->valid = tp_asv_get_boolean (properties, "Valid", NULL); @@ -327,6 +333,9 @@ empathy_account_got_all_cb (TpProxy *proxy, { EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + DEBUG ("Got initial set of properties for %s", + empathy_account_get_unique_name (account)); + if (error != NULL) { printf ("Unhappy\n"); @@ -780,12 +789,25 @@ empathy_account_set_enabled (EmpathyAccount *account, gboolean enabled) { EmpathyAccountPriv *priv = GET_PRIV (account); + GValue value = {0, }; if (priv->enabled == enabled) return; - priv->enabled = enabled; - g_object_notify (G_OBJECT (account), "enabled"); + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, enabled); + + tp_cli_dbus_properties_call_set (TP_PROXY (priv->account), + -1, + TP_IFACE_ACCOUNT, + "Enabled", + &value, + NULL, + NULL, + NULL, + NULL); + + g_value_unset (&value); } static void -- cgit v1.2.3 From 7ba6375cdfa00bc0871e4958076398e82f92c2b5 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 18:02:47 +0100 Subject: Unescape _ and _2d in the protocol from mission-control --- libempathy/empathy-account.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 21ece6f0d..4cd96e393 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -345,6 +345,41 @@ empathy_account_got_all_cb (TpProxy *proxy, empathy_account_update (account, properties); } +static gchar * +empathy_account_unescape_protocol (const gchar *protocol, gssize len) +{ + gchar *result, *escape; + /* Bad implementation might accidentally use tp_escape_as_identifier, + * which escapes - in the wrong way... */ + if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL) + { + GString *str; + const gchar *input; + + str = g_string_new (""); + input = protocol; + do { + g_string_append_len (str, input, escape - input); + g_string_append_c (str, '-'); + + len -= escape - input + 3; + input = escape + 3; + } while ((escape = g_strstr_len (input, len, "_2d")) != NULL); + + g_string_append_len (str, input, len); + + result = g_string_free (str, FALSE); + } + else + { + result = g_strndup (protocol, len); + } + + g_strdelimit (result, "_", '-'); + + return result; +} + static gboolean empathy_account_parse_unique_name (const gchar *bus_name, gchar **protocol, gchar **manager) @@ -375,7 +410,9 @@ empathy_account_parse_unique_name (const gchar *bus_name, return FALSE; if (protocol != NULL) - *protocol = g_strndup (proto, proto_end - proto); + { + *protocol = empathy_account_unescape_protocol (proto, proto_end - proto); + } if (manager != NULL) *manager = g_strndup (cm, cm_end - cm); -- cgit v1.2.3 From 183bea15838e2ad9dc16f6d86eedb820831a8d7f Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 18:06:47 +0100 Subject: Coding style fixes --- libempathy/empathy-account.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 4cd96e393..5727a8a25 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -901,7 +901,7 @@ empathy_account_updated_cb (TpAccount *proxy, if (error != NULL) { - g_simple_async_result_set_from_error (result, (GError *)error); + g_simple_async_result_set_from_error (result, (GError *) error); } g_simple_async_result_complete (result); @@ -910,7 +910,7 @@ empathy_account_updated_cb (TpAccount *proxy, void empathy_account_update_settings_async (EmpathyAccount *account, - const GHashTable *parameters, const gchar **unset_parameters, + GHashTable *parameters, const gchar **unset_parameters, GAsyncReadyCallback callback, gpointer user_data) { EmpathyAccountPriv *priv = GET_PRIV (account); @@ -919,7 +919,7 @@ empathy_account_update_settings_async (EmpathyAccount *account, tp_cli_account_call_update_parameters (priv->account, -1, - (GHashTable *)parameters, + parameters, unset_parameters, empathy_account_updated_cb, result, -- cgit v1.2.3 From 067e77dceb1e0c01f33ce4c743e88c7214403b8a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:02:37 +0100 Subject: Add removed signal on EmpathyAccount --- libempathy/empathy-account.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5727a8a25..51dd26316 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -42,6 +42,7 @@ enum { STATUS_CHANGED, PRESENCE_CHANGED, + REMOVED, LAST_SIGNAL }; @@ -84,6 +85,7 @@ struct _EmpathyAccountPriv gboolean enabled; gboolean valid; gboolean ready; + gboolean removed; /* Timestamp when the connection got connected in seconds since the epoch */ glong connect_time; @@ -324,6 +326,22 @@ empathy_account_properties_changed (TpAccount *proxy, empathy_account_update (account, properties); } +static void +empathy_account_removed_cb (TpAccount *proxy, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->removed) + return; + + priv->removed = TRUE; + + g_signal_emit (account, signals[REMOVED], 0); +} + static void empathy_account_got_all_cb (TpProxy *proxy, GHashTable *properties, @@ -420,6 +438,21 @@ empathy_account_parse_unique_name (const gchar *bus_name, return TRUE; } +static void +account_invalidated_cb (TpProxy *proxy, guint domain, gint code, + gchar *message, gpointer user_data) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (user_data); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->removed) + return; + + priv->removed = TRUE; + + g_signal_emit (account, signals[REMOVED], 0); +} + static void empathy_account_constructed (GObject *object) { @@ -428,6 +461,9 @@ empathy_account_constructed (GObject *object) priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL); + g_signal_connect (priv->account, "invalidated", + G_CALLBACK (account_invalidated_cb), object); + empathy_account_parse_unique_name (priv->unique_name, &(priv->proto_name), &(priv->cm_name)); @@ -437,6 +473,10 @@ empathy_account_constructed (GObject *object) empathy_account_properties_changed, NULL, NULL, object, NULL); + tp_cli_account_connect_to_removed (priv->account, + empathy_account_removed_cb, + NULL, NULL, object, NULL); + tp_cli_dbus_properties_call_get_all (priv->account, -1, TP_IFACE_ACCOUNT, empathy_account_got_all_cb, @@ -558,6 +598,13 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) 0, NULL, NULL, _empathy_marshal_VOID__UINT_STRING_STRING, G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); + + signals[REMOVED] = g_signal_new ("removed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } void -- cgit v1.2.3 From 2e87bc47e7c03fa0d2145b2c3904df545b941a76 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:11:50 +0100 Subject: Add api to remove accounts --- libempathy/empathy-account.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 51dd26316..8d4909586 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -987,3 +987,51 @@ empathy_account_update_settings_finish (EmpathyAccount *account, return TRUE; } + +static void +empathy_account_remove_cb (TpAccount *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data); + + if (error != NULL) + { + g_simple_async_result_set_from_error (result, (GError *) error); + } + + g_simple_async_result_complete (result); + g_object_unref (G_OBJECT (result)); +} + +void +empathy_account_remove_async (EmpathyAccount *account, + GAsyncReadyCallback callback, gpointer user_data) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account), + callback, user_data, empathy_account_remove_finish); + + tp_cli_account_call_remove (priv->account, + -1, + empathy_account_remove_cb, + result, + NULL, + G_OBJECT (account)); +} + +gboolean +empathy_account_remove_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (account), empathy_account_update_settings_finish), FALSE); + + return TRUE; +} + -- cgit v1.2.3 From 6d2d940c7946eafb807e325af4c87a03570ef383 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:27:43 +0100 Subject: Correctly implement empathy_account_is_valid --- libempathy/empathy-account.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 8d4909586..cc982aea7 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -716,10 +716,9 @@ empathy_account_get_display_name (EmpathyAccount *account) gboolean empathy_account_is_valid (EmpathyAccount *account) { - //EmpathyAccountPriv *priv = GET_PRIV (account); + EmpathyAccountPriv *priv = GET_PRIV (account); - /* FIXME */ - return FALSE; + return priv->valid; } const gchar * -- cgit v1.2.3 From 1bcccdbc977cc35af2edccc9b222d53a63a8c0b6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 16:46:24 +0200 Subject: Add a utility function to may protocols to their icons --- libempathy/empathy-account.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index cc982aea7..db2ca1f56 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -467,7 +467,7 @@ empathy_account_constructed (GObject *object) empathy_account_parse_unique_name (priv->unique_name, &(priv->proto_name), &(priv->cm_name)); - priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name); + priv->icon_name = empathy_protocol_icon_name (priv->proto_name); tp_cli_account_connect_to_account_property_changed (priv->account, empathy_account_properties_changed, -- cgit v1.2.3 From bb2d63c7d3964a3cd68e6667a19907aa72bb686b Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Wed, 29 Jul 2009 19:28:56 +0200 Subject: Unref the connection if it fails to become ready or is invalidated --- libempathy/empathy-account.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index db2ca1f56..5cf489769 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -607,6 +607,21 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) G_TYPE_NONE, 0); } +static void +empathy_account_free_connection (EmpathyAccount *account) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->connection_invalidated_id != 0) + g_signal_handler_disconnect (priv->connection, + priv->connection_invalidated_id); + priv->connection_invalidated_id = 0; + + if (priv->connection != NULL) + g_object_unref (priv->connection); + priv->connection = NULL; +} + void empathy_account_dispose (GObject *object) { @@ -618,14 +633,7 @@ empathy_account_dispose (GObject *object) priv->dispose_has_run = TRUE; - if (priv->connection_invalidated_id != 0) - g_signal_handler_disconnect (priv->connection, - priv->connection_invalidated_id); - priv->connection_invalidated_id = 0; - - if (priv->connection != NULL) - g_object_unref (priv->connection); - priv->connection = NULL; + empathy_account_free_connection (self); /* release any references held by the object here */ if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL) @@ -785,13 +793,12 @@ empathy_account_connection_ready_cb (TpConnection *connection, gpointer user_data) { EmpathyAccount *account = EMPATHY_ACCOUNT (user_data); - EmpathyAccountPriv *priv = GET_PRIV (account); if (error != NULL) { DEBUG ("(%s) Connection failed to become ready: %s", empathy_account_get_unique_name (account), error->message); - priv->connection = NULL; + empathy_account_free_connection (account); } else { -- cgit v1.2.3 From e3ed5ba84d20da177070d4708bca4bdb9d0ee149 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 24 Jul 2009 15:52:29 +0200 Subject: Implement _set_display_name --- libempathy/empathy-account.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index cc982aea7..bb55abed7 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -32,6 +32,8 @@ #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include +#include + #include "empathy-account.h" #include "empathy-utils.h" #include "empathy-marshal.h" @@ -987,6 +989,63 @@ empathy_account_update_settings_finish (EmpathyAccount *account, return TRUE; } +static void +account_display_name_set_cb (TpProxy *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + g_simple_async_result_set_from_error (result, (GError *) error); + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +void +empathy_account_set_display_name_async (EmpathyAccount *account, + const char *display_name, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + GValue value = {0, }; + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (display_name == NULL) + { + g_simple_async_report_error_in_idle (G_OBJECT (account), + callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, + _("Can't set an empty display name")); + return; + } + + result = g_simple_async_result_new (G_OBJECT (account), callback, + user_data, empathy_account_set_display_name_finish); + + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, display_name); + + tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT, + "DisplayName", &value, account_display_name_set_cb, result, NULL, + G_OBJECT (account)); +} + +gboolean +empathy_account_set_display_name_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error) || + !g_simple_async_result_is_valid (result, G_OBJECT (account), + empathy_account_set_display_name_finish)) + return FALSE; + + return TRUE; +} + static void empathy_account_remove_cb (TpAccount *proxy, const GError *error, -- cgit v1.2.3 From f54c1834d7a8dc0de0f6f4c1ae60910a38944d05 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 19:30:25 +0200 Subject: add some slightly nicer debug messages --- libempathy/empathy-account.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5cf489769..4585d33cf 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -356,7 +356,8 @@ empathy_account_got_all_cb (TpProxy *proxy, if (error != NULL) { - printf ("Unhappy\n"); + DEBUG ("Failed to get the initial set of account properties: %s", + error->message); return; } @@ -907,7 +908,7 @@ empathy_account_requested_presence_cb (TpProxy *proxy, GObject *weak_object) { if (error) - DEBUG (":( : %s", error->message); + DEBUG ("Failed to set the requested presence: %s", error->message); } -- cgit v1.2.3 From 87070d25c5f2d9a0ecba73e8ce913eca7f183c79 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Jul 2009 19:35:03 +0200 Subject: Fix some coding style issues --- libempathy/empathy-account.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 4585d33cf..df948b69c 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -200,7 +200,8 @@ empathy_account_get_property (GObject *object, } static void -empathy_account_update (EmpathyAccount *account, GHashTable *properties) +empathy_account_update (EmpathyAccount *account, + GHashTable *properties) { EmpathyAccountPriv *priv = GET_PRIV (account); const gchar *conn_path; @@ -401,7 +402,7 @@ empathy_account_unescape_protocol (const gchar *protocol, gssize len) static gboolean empathy_account_parse_unique_name (const gchar *bus_name, - gchar **protocol, gchar **manager) + gchar **protocol, gchar **manager) { const gchar *proto, *proto_end; const gchar *cm, *cm_end; @@ -780,7 +781,8 @@ empathy_account_is_ready (EmpathyAccount *account) EmpathyAccount * -empathy_account_new (TpDBusDaemon *dbus, const gchar *unique_name) +empathy_account_new (TpDBusDaemon *dbus, + const gchar *unique_name) { return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT, "dbus-daemon", dbus, -- cgit v1.2.3 From ad9ed2451356457afaceddc7d0dc6b8b74a83bf6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 16:36:51 +0100 Subject: Plug some leaks --- libempathy/empathy-account.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index ffb6e6786..ae17f8d6a 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -234,8 +234,11 @@ empathy_account_update (EmpathyAccount *account, } if (g_hash_table_lookup (properties, "DisplayName") != NULL) - priv->display_name = - g_strdup (tp_asv_get_string (properties, "DisplayName")); + { + g_free (priv->display_name); + priv->display_name = + g_strdup (tp_asv_get_string (properties, "DisplayName")); + } if (g_hash_table_lookup (properties, "Enabled") != NULL) { @@ -257,6 +260,9 @@ empathy_account_update (EmpathyAccount *account, parameters = tp_asv_get_boxed (properties, "Parameters", TP_HASH_TYPE_STRING_VARIANT_MAP); + if (priv->parameters != NULL) + g_hash_table_unref (priv->parameters); + priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP, parameters); } -- cgit v1.2.3 From cc4b0254397717079f7d53391560952a8b1992a5 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 16:40:24 +0100 Subject: Notify when display-name is updated --- libempathy/empathy-account.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index ae17f8d6a..b82080ee0 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -238,6 +238,7 @@ empathy_account_update (EmpathyAccount *account, g_free (priv->display_name); priv->display_name = g_strdup (tp_asv_get_string (properties, "DisplayName")); + g_object_notify (G_OBJECT (account), "display-name"); } if (g_hash_table_lookup (properties, "Enabled") != NULL) -- cgit v1.2.3 From 955e5f31d9cf3056777ceaf321b8ed4dc33b06cd Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 17 Aug 2009 17:55:33 +0100 Subject: rename status-reason to connection-status-reason and notify connection-status{-reason,} when changes happen --- libempathy/empathy-account.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index b82080ee0..7d89f20fc 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -287,7 +287,8 @@ empathy_account_update (EmpathyAccount *account, g_signal_emit (account, signals[STATUS_CHANGED], 0, old_s, priv->connection_status, priv->reason); - g_object_notify (G_OBJECT (account), "status"); + g_object_notify (G_OBJECT (account), "connection-status"); + g_object_notify (G_OBJECT (account), "connection-status-reason"); } if (presence_changed) @@ -560,7 +561,7 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON, - g_param_spec_uint ("status-reason", + g_param_spec_uint ("connection-status-reason", "ConnectionStatusReason", "The account connections status reason", 0, -- cgit v1.2.3 From 27e11ea6e41c5b2498307d581caa751936de30f1 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 18 Aug 2009 19:33:10 +0100 Subject: replace UNIQUE_NAME_PREFIX by TP_ACCOUNT_OBJECT_PATH_BASE --- libempathy/empathy-account.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 7d89f20fc..623a324e8 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -28,6 +28,7 @@ #include #include #include +#include #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT #include @@ -38,8 +39,6 @@ #include "empathy-utils.h" #include "empathy-marshal.h" -#define UNIQUE_NAME_PREFIX "/org/freedesktop/Telepathy/Account/" - /* signals */ enum { STATUS_CHANGED, @@ -418,9 +417,9 @@ empathy_account_parse_unique_name (const gchar *bus_name, const gchar *cm, *cm_end; g_return_val_if_fail ( - g_str_has_prefix (bus_name, UNIQUE_NAME_PREFIX), FALSE); + g_str_has_prefix (bus_name, TP_ACCOUNT_OBJECT_PATH_BASE), FALSE); - cm = bus_name + strlen (UNIQUE_NAME_PREFIX); + cm = bus_name + strlen (TP_ACCOUNT_OBJECT_PATH_BASE); for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++) /* pass */; -- cgit v1.2.3 From 8bd008f556dcab022cceb2eaceb3080cb7198efc Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 20 Aug 2009 20:29:26 +0100 Subject: Add API to get teh TpConnection for an account on a certain path --- libempathy/empathy-account.c | 90 +++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 31 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 623a324e8..445576b63 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -105,7 +105,7 @@ struct _EmpathyAccountPriv #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount) static void _empathy_account_set_connection (EmpathyAccount *account, - TpConnection *connection); + const gchar *path); static void empathy_account_init (EmpathyAccount *obj) @@ -205,7 +205,6 @@ empathy_account_update (EmpathyAccount *account, GHashTable *properties) { EmpathyAccountPriv *priv = GET_PRIV (account); - const gchar *conn_path; GValueArray *arr; TpConnectionStatus old_s = priv->connection_status; gboolean presence_changed = FALSE; @@ -301,23 +300,10 @@ empathy_account_update (EmpathyAccount *account, if (g_hash_table_lookup (properties, "Connection") != NULL) { - conn_path = tp_asv_get_object_path (properties, "Connection"); + const gchar *conn_path = + tp_asv_get_object_path (properties, "Connection"); - if (tp_strdiff (conn_path, "/") && priv->connection == NULL) - { - TpConnection *conn; - GError *error = NULL; - conn = tp_connection_new (priv->dbus, NULL, conn_path, &error); - - if (conn == NULL) - { - DEBUG ("Failed to create a new TpConnection: %s", - error->message); - g_error_free (error); - } - - _empathy_account_set_connection (account, conn); - } + _empathy_account_set_connection (account, conn_path); } } @@ -704,6 +690,35 @@ empathy_account_get_connection (EmpathyAccount *account) return NULL; } +/** + * empathy_account_get_connection_for: + * @account: a #EmpathyAccount + * @patch: the path to connection object for #EmpathyAccount + * + * Get the connection of the account on path. This function does not return a + * new ref. It is not guaranteed that the returned connection object is ready + * + * Returns: the connection of the account. + **/ +TpConnection * +empathy_account_get_connection_for (EmpathyAccount *account, + const gchar *path) +{ + EmpathyAccountPriv *priv = GET_PRIV (account); + + /* double-check that the object path is valid */ + if (!tp_dbus_check_valid_object_path (path, NULL)) + return NULL; + + /* Should be a full object path, not the special "/" value */ + if (strlen (path) == 1) + return NULL; + + _empathy_account_set_connection (account, path); + + return priv->connection; +} + /** * empathy_account_get_unique_name: * @account: a #EmpathyAccount @@ -850,18 +865,20 @@ _empathy_account_connection_invalidated_cb (TpProxy *self, static void _empathy_account_set_connection (EmpathyAccount *account, - TpConnection *connection) + const gchar *path) { EmpathyAccountPriv *priv = GET_PRIV (account); - if (priv->connection == connection) - return; + if (priv->connection != NULL) + { + const gchar *current; - /* Connection already set, don't set the new one */ - if (connection != NULL && priv->connection != NULL) - return; + current = tp_proxy_get_object_path (priv->connection); + if (!tp_strdiff (current, path)) + return; + } - if (connection == NULL) + if (priv->connection != NULL) { g_signal_handler_disconnect (priv->connection, priv->connection_invalidated_id); @@ -869,21 +886,32 @@ _empathy_account_set_connection (EmpathyAccount *account, g_object_unref (priv->connection); priv->connection = NULL; - g_object_notify (G_OBJECT (account), "connection"); } - else + + if (tp_strdiff ("/", path)) { - priv->connection = g_object_ref (connection); + GError *error = NULL; + priv->connection = tp_connection_new (priv->dbus, NULL, path, &error); + + if (priv->connection == NULL) + { + DEBUG ("Failed to create a new TpConnection: %s", + error->message); + g_error_free (error); + } + priv->connection_invalidated_id = g_signal_connect (priv->connection, "invalidated", - G_CALLBACK (_empathy_account_connection_invalidated_cb), - account); + G_CALLBACK (_empathy_account_connection_invalidated_cb), + account); DEBUG ("Readying connection for %s", priv->unique_name); /* notify a change in the connection property when it's ready */ tp_connection_call_when_ready (priv->connection, - empathy_account_connection_ready_cb, account); + empathy_account_connection_ready_cb, account); } + + g_object_notify (G_OBJECT (account), "connection"); } void -- cgit v1.2.3 From 4b3de48f8648402437053f01296ff596cfdbf38a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 17:14:55 +0100 Subject: Don't hook up to invalidated when creating the connection failed --- libempathy/empathy-account.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 445576b63..914ae6141 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -899,16 +899,17 @@ _empathy_account_set_connection (EmpathyAccount *account, error->message); g_error_free (error); } - - priv->connection_invalidated_id = g_signal_connect (priv->connection, - "invalidated", - G_CALLBACK (_empathy_account_connection_invalidated_cb), - account); - - DEBUG ("Readying connection for %s", priv->unique_name); - /* notify a change in the connection property when it's ready */ - tp_connection_call_when_ready (priv->connection, - empathy_account_connection_ready_cb, account); + else + { + priv->connection_invalidated_id = g_signal_connect (priv->connection, + "invalidated", + G_CALLBACK (_empathy_account_connection_invalidated_cb), account); + + DEBUG ("Readying connection for %s", priv->unique_name); + /* notify a change in the connection property when it's ready */ + tp_connection_call_when_ready (priv->connection, + empathy_account_connection_ready_cb, account); + } } g_object_notify (G_OBJECT (account), "connection"); -- cgit v1.2.3 From fd8e9c5dc2584055177c7a79021cdd53ca431c22 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 21 Aug 2009 17:23:48 +0100 Subject: Rename empathy_account_get_connection_for to empathy_account_get_connection_for_path --- libempathy/empathy-account.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 914ae6141..5a6b31f0a 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -691,7 +691,7 @@ empathy_account_get_connection (EmpathyAccount *account) } /** - * empathy_account_get_connection_for: + * empathy_account_get_connection_for_path: * @account: a #EmpathyAccount * @patch: the path to connection object for #EmpathyAccount * @@ -701,7 +701,7 @@ empathy_account_get_connection (EmpathyAccount *account) * Returns: the connection of the account. **/ TpConnection * -empathy_account_get_connection_for (EmpathyAccount *account, +empathy_account_get_connection_for_path (EmpathyAccount *account, const gchar *path) { EmpathyAccountPriv *priv = GET_PRIV (account); -- cgit v1.2.3 From 23d4544855656cfdc9cf65ed94801191002e86ce Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 6 Aug 2009 21:13:09 +0200 Subject: Make the set_enabled API async --- libempathy/empathy-account.c | 57 +++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5a6b31f0a..2dd662874 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -132,7 +132,8 @@ empathy_account_set_property (GObject *object, switch (prop_id) { case PROP_ENABLED: - empathy_account_set_enabled (account, g_value_get_boolean (value)); + empathy_account_set_enabled_async (account, + g_value_get_boolean (value), NULL, NULL); break; case PROP_UNIQUE_NAME: priv->unique_name = g_value_dup_string (value); @@ -915,30 +916,58 @@ _empathy_account_set_connection (EmpathyAccount *account, g_object_notify (G_OBJECT (account), "connection"); } +static void +account_enabled_set_cb (TpProxy *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + g_simple_async_result_set_from_error (result, (GError *) error); + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +gboolean +empathy_account_set_enabled_finish (EmpathyAccount *account, + GAsyncResult *result, + GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error) || + !g_simple_async_result_is_valid (result, G_OBJECT (account), + empathy_account_set_enabled_finish)) + return FALSE; + + return TRUE; +} + void -empathy_account_set_enabled (EmpathyAccount *account, - gboolean enabled) +empathy_account_set_enabled_async (EmpathyAccount *account, + gboolean enabled, + GAsyncReadyCallback callback, + gpointer user_data) { EmpathyAccountPriv *priv = GET_PRIV (account); GValue value = {0, }; + GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account), + callback, user_data, empathy_account_set_enabled_finish); if (priv->enabled == enabled) - return; + { + g_simple_async_result_complete_in_idle (result); + return; + } g_value_init (&value, G_TYPE_BOOLEAN); g_value_set_boolean (&value, enabled); tp_cli_dbus_properties_call_set (TP_PROXY (priv->account), - -1, - TP_IFACE_ACCOUNT, - "Enabled", - &value, - NULL, - NULL, - NULL, - NULL); - - g_value_unset (&value); + -1, TP_IFACE_ACCOUNT, "Enabled", &value, + account_enabled_set_cb, result, NULL, G_OBJECT (account)); } static void -- cgit v1.2.3 From 50a7def3f5ba311a0e5f8725d6ccaa1215742db6 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 23 Aug 2009 14:51:18 +0100 Subject: Return the correct object when querying the dbus-daemon property --- libempathy/empathy-account.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libempathy/empathy-account.c') diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 2dd662874..091950880 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -192,8 +192,7 @@ empathy_account_get_property (GObject *object, empathy_account_get_display_name (account)); break; case PROP_DBUS_DAEMON: - g_value_set_string (value, - empathy_account_get_display_name (account)); + g_value_set_object (value, priv->dbus); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); -- cgit v1.2.3