telepathy-gabble: vcard-manager: split up gargantuan edit_info_apply()
Will Thompson
wjt at kemper.freedesktop.org
Thu Dec 6 09:37:23 PST 2012
Module: telepathy-gabble
Branch: master
Commit: 2deced34fe350538fceb9ca8775f0cd8f91ddc15
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=2deced34fe350538fceb9ca8775f0cd8f91ddc15
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Mon Nov 26 16:43:43 2012 +0000
vcard-manager: split up gargantuan edit_info_apply()
---
src/vcard-manager.c | 91 ++++++++++++++++++++++++++++-----------------------
1 files changed, 50 insertions(+), 41 deletions(-)
diff --git a/src/vcard-manager.c b/src/vcard-manager.c
index 932dcbe..5beea7d 100644
--- a/src/vcard-manager.c
+++ b/src/vcard-manager.c
@@ -1049,62 +1049,71 @@ gabble_vcard_manager_replace_is_significant (GabbleVCardManagerEditInfo *info,
static WockyNode *vcard_copy (WockyNode *parent, WockyNode *src,
const gchar *exclude, gboolean *exclude_mattered);
-static WockyStanza *
-gabble_vcard_manager_edit_info_apply (GabbleVCardManagerEditInfo *info,
+/* SET_ALIAS is shorthand for a REPLACE operation or nothing */
+static gboolean
+resolve_set_alias_edit (
+ GabbleVCardManagerEditInfo *info,
WockyNode *old_vcard,
GabbleVCardManager *vcard_manager)
{
- WockyStanza *msg;
- WockyNode *vcard_node;
- WockyNode *node;
- GList *iter;
- gboolean maybe_changed = FALSE;
GabbleConnection *conn = vcard_manager->priv->connection;
TpBaseConnection *base = (TpBaseConnection *) conn;
- if (info->edit_type == GABBLE_VCARD_EDIT_SET_ALIAS)
+ g_assert (info->element_name == NULL);
+
+ if (gabble_vcard_manager_can_use_vcard_field (vcard_manager, "NICKNAME"))
+ {
+ info->element_name = g_strdup ("NICKNAME");
+ }
+ else
{
- /* SET_ALIAS is shorthand for a REPLACE operation or nothing */
+ /* Google Talk servers won't let us set a NICKNAME; recover by
+ * setting the FN */
+ info->element_name = g_strdup ("FN");
+ }
- g_assert (info->element_name == NULL);
+ if (info->element_value == NULL)
+ {
+ /* We're just trying to fix a possibly-incomplete SetContactInfo() */
+ WockyNode *node = wocky_node_get_child (old_vcard, info->element_name);
+ gchar *alias;
- if (gabble_vcard_manager_can_use_vcard_field (vcard_manager, "NICKNAME"))
- {
- info->element_name = g_strdup ("NICKNAME");
- }
- else
- {
- /* Google Talk servers won't let us set a NICKNAME; recover by
- * setting the FN */
- info->element_name = g_strdup ("FN");
- }
+ /* If the user has set this field explicitly via SetContactInfo(),
+ * that takes precedence */
+ if (node != NULL)
+ return FALSE;
- if (info->element_value == NULL)
+ if (_gabble_connection_get_cached_alias (conn,
+ tp_base_connection_get_self_handle (base),
+ &alias) < GABBLE_CONNECTION_ALIAS_FROM_VCARD)
{
- /* We're just trying to fix a possibly-incomplete SetContactInfo() -
- * */
- gchar *alias;
-
- node = wocky_node_get_child (old_vcard, info->element_name);
+ /* not good enough to want to put it in the vCard */
+ g_free (alias);
+ return FALSE;
+ }
- /* If the user has set this field explicitly via SetContactInfo(),
- * that takes precedence */
- if (node != NULL)
- return NULL;
+ info->element_value = alias;
+ }
- if (_gabble_connection_get_cached_alias (conn,
- tp_base_connection_get_self_handle (base),
- &alias) < GABBLE_CONNECTION_ALIAS_FROM_VCARD)
- {
- /* not good enough to want to put it in the vCard */
- g_free (alias);
- return NULL;
- }
+ info->edit_type = GABBLE_VCARD_EDIT_REPLACE;
+ return TRUE;
+}
- info->element_value = alias;
- }
+static WockyStanza *
+gabble_vcard_manager_edit_info_apply (GabbleVCardManagerEditInfo *info,
+ WockyNode *old_vcard,
+ GabbleVCardManager *vcard_manager)
+{
+ WockyStanza *msg;
+ WockyNode *vcard_node;
+ WockyNode *node;
+ GList *iter;
+ gboolean maybe_changed = FALSE;
- info->edit_type = GABBLE_VCARD_EDIT_REPLACE;
+ if (info->edit_type == GABBLE_VCARD_EDIT_SET_ALIAS)
+ {
+ if (!resolve_set_alias_edit (info, old_vcard, vcard_manager))
+ return NULL;
}
if (info->edit_type == GABBLE_VCARD_EDIT_APPEND ||
More information about the telepathy-commits
mailing list