From 78e1b135433ba8449d3e42349c52ef16cce6c44d Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Wed, 9 Jun 2010 18:07:21 +0300 Subject: [PATCH 1/3] connection-manager: add sipe to list of known protocols --- src/connection-manager.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/connection-manager.c b/src/connection-manager.c index f7ce779..d18f407 100644 --- a/src/connection-manager.c +++ b/src/connection-manager.c @@ -62,6 +62,7 @@ static HazeProtocolInfo known_protocol_info[] = { { "msn", "prpl-msn", NULL, "" }, { "qq", "prpl-qq", NULL, "" }, { "sametime", "prpl-meanwhile", NULL, "" }, + { "sipe", "prpl-sipe", NULL, "" }, { "yahoo", "prpl-yahoo", NULL, "local_charset:charset" }, { "yahoojp", "prpl-yahoojp", NULL, "local_charset:charset" }, { "zephyr", "prpl-zephyr", NULL, "encoding:charset" }, -- 1.7.0.1 From 9b0c561e379ed2dabae9618a517d81ade2793c91 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Wed, 9 Jun 2010 18:55:23 +0300 Subject: [PATCH 2/3] connection-manager: add translation for PurpleAccountUserSplits In order to be backward compatible this will only be used for known protocols that provide "usersplitX:abcde" mapping. Added usersplit mapping for sipe protocol. --- src/connection-manager.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-) diff --git a/src/connection-manager.c b/src/connection-manager.c index d18f407..729f08b 100644 --- a/src/connection-manager.c +++ b/src/connection-manager.c @@ -62,7 +62,7 @@ static HazeProtocolInfo known_protocol_info[] = { { "msn", "prpl-msn", NULL, "" }, { "qq", "prpl-qq", NULL, "" }, { "sametime", "prpl-meanwhile", NULL, "" }, - { "sipe", "prpl-sipe", NULL, "" }, + { "sipe", "prpl-sipe", NULL, "usersplit1:login" }, { "yahoo", "prpl-yahoo", NULL, "local_charset:charset" }, { "yahoojp", "prpl-yahoojp", NULL, "local_charset:charset" }, { "zephyr", "prpl-zephyr", NULL, "encoding:charset" }, @@ -155,6 +155,42 @@ _param_filter_string_list (const TpCMParamSpec *paramspec, return FALSE; } +/* + * Adds two separate fields for each PurpleAccountUserSplit + */ +static void _translate_protocol_usersplits (HazeProtocolInfo *hpi, + GHashTable *parameter_map, + GArray *paramspecs) +{ + guint j, count = 0; + GList *l = hpi->prpl_info->user_splits; + + while (l != NULL) + { + count += 2; + l = l->next; + } + + /* first user split is covered by "account" */ + for (j = 1; j < count; j++) + { + gchar *usersplit = g_strdup_printf("usersplit%d", j); + gchar *name = g_strdup (g_hash_table_lookup (parameter_map, usersplit)); + TpCMParamSpec usersplit_spec = { + NULL, DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, + TP_CONN_MGR_PARAM_FLAG_REQUIRED, NULL, 0, NULL, NULL, + (gpointer) NULL, NULL + }; + + if (name == NULL) + name = usersplit; + usersplit_spec.name = name; + usersplit_spec.setter_data = usersplit; + + g_array_append_val (paramspecs, usersplit_spec); + } +} + /* Populates a TpCMParamSpec from a PurpleAccountOption, possibly renaming the * parameter as specified in parameter_map. paramspec is assumed to be zeroed out. * Returns TRUE on success, and FALSE if paramspec could not be populated (and @@ -324,6 +360,11 @@ _build_paramspecs (HazeProtocolInfo *hpi) /* TODO: local-xmpp shouldn't have an account parameter */ g_array_append_val (paramspecs, account_spec); + /* Translate user splits for protocols that have a mapping */ + if (hpi->prpl_info->user_splits && + g_hash_table_lookup (parameter_map, "usersplit1")) + _translate_protocol_usersplits(hpi, parameter_map, paramspecs); + /* Password parameter: */ if (!(hpi->prpl_info->options & OPT_PROTO_NO_PASSWORD)) { -- 1.7.0.1 From 70913c3e1005f2ed1e4d3556ba2de8a99cb7e5a8 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Wed, 9 Jun 2010 20:50:37 +0300 Subject: [PATCH 3/3] connection: generate user name from user splits If a protocol has PurpleAccountUserSplits and "userplitX" parameters then merge them together to generate the real user name for the Purple account. This completes the PurpleAccountUserSplits support. Now it should be possible for Maemo/MeeGo Account Setup UI to show multiple entry fields instead of hacking around the problem that "," is not a legal character. --- src/connection-manager.c | 26 ++++++++++++---------- src/connection.c | 54 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/connection-manager.c b/src/connection-manager.c index 729f08b..1a961d9 100644 --- a/src/connection-manager.c +++ b/src/connection-manager.c @@ -162,24 +162,26 @@ static void _translate_protocol_usersplits (HazeProtocolInfo *hpi, GHashTable *parameter_map, GArray *paramspecs) { - guint j, count = 0; - GList *l = hpi->prpl_info->user_splits; + guint i, count; + GList *l; - while (l != NULL) - { - count += 2; - l = l->next; - } + for (count = 0, l = hpi->prpl_info->user_splits; + l != NULL; + count++, l = l->next); /* first user split is covered by "account" */ - for (j = 1; j < count; j++) + for (i = 1; i <= count; i++) { - gchar *usersplit = g_strdup_printf("usersplit%d", j); + gchar *usersplit = g_strdup_printf("usersplit%d", i); gchar *name = g_strdup (g_hash_table_lookup (parameter_map, usersplit)); TpCMParamSpec usersplit_spec = { - NULL, DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, - TP_CONN_MGR_PARAM_FLAG_REQUIRED, NULL, 0, NULL, NULL, - (gpointer) NULL, NULL + NULL, /* name */ + DBUS_TYPE_STRING_AS_STRING, + G_TYPE_STRING, + TP_CONN_MGR_PARAM_FLAG_REQUIRED, + NULL, 0, NULL, NULL, + NULL, /* setter_data */ + NULL }; if (name == NULL) diff --git a/src/connection.c b/src/connection.c index beb8e31..ae7bae8 100644 --- a/src/connection.c +++ b/src/connection.c @@ -254,6 +254,53 @@ struct _i_want_closure GHashTable *params; }; +static gchar * +_haze_connection_get_username(GHashTable *params, + PurplePluginProtocolInfo *prpl_info) +{ + const gchar *account = tp_asv_get_string (params, "account"); + gchar *username; + + if (account == NULL) + return(NULL); + + /* Does the protocol have user splits? */ + if ((prpl_info->user_splits != NULL) && + (g_hash_table_lookup (params, "usersplit1") != NULL)) + { + guint count; + GList *l; + GString *string = g_string_new(account); + + for (count = 1, l = prpl_info->user_splits; + l != NULL; + count++, l = l->next) + { + PurpleAccountUserSplit *split = l->data; + gchar *usersplit = g_strdup_printf("usersplit%d", count); + GValue *value = g_hash_table_lookup (params, usersplit); + + g_assert (G_VALUE_TYPE (value) == G_TYPE_STRING); + g_string_append_c (string, + purple_account_user_split_get_separator(split)); + g_string_append (string, g_value_get_string(value)); + + g_hash_table_remove (params, usersplit); + g_free (usersplit); + } + + username = g_string_free(string, FALSE); + } + else + { + username = g_strdup(account); + } + + g_hash_table_remove (params, "account"); + + return(username); +} + static void _set_option (const PurpleAccountOption *option, struct _i_want_closure *context) @@ -307,12 +354,13 @@ haze_connection_create_account (HazeConnection *self, GHashTable *params = priv->parameters; PurplePluginProtocolInfo *prpl_info = priv->protocol_info->prpl_info; const gchar *prpl_id = priv->protocol_info->prpl_id; - const gchar *username, *password; + gchar *username; + const gchar *password; struct _i_want_closure context; g_return_val_if_fail (self->account == NULL, FALSE); - username = tp_asv_get_string (params, "account"); + username = _haze_connection_get_username(params, prpl_info); g_assert (username != NULL); if (purple_accounts_find (username, prpl_id) != NULL) @@ -323,8 +371,8 @@ haze_connection_create_account (HazeConnection *self, } self->account = purple_account_new (username, priv->protocol_info->prpl_id); + g_free(username); purple_accounts_add (self->account); - g_hash_table_remove (params, "account"); self->account->ui_data = self; -- 1.7.0.1