telepathy-gabble: vcard-manager: copy vcards using WockyNodeTree.

Will Thompson wjt at kemper.freedesktop.org
Thu Dec 6 09:37:23 PST 2012


Module: telepathy-gabble
Branch: master
Commit: b4604cc6017a7426f716ac4664ccd82b10bad1aa
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=b4604cc6017a7426f716ac4664ccd82b10bad1aa

Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Mon Nov 26 15:11:25 2012 +0000

vcard-manager: copy vcards using WockyNodeTree.

This is actually less efficient than what was there before, because it
copies the tree twice. I think this is symptomatic of Gabble's edit
representation being wrong.

---

 src/vcard-manager.c |   46 ++++++++++++++++++++--------------------------
 1 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/src/vcard-manager.c b/src/vcard-manager.c
index de17c45..932dcbe 100644
--- a/src/vcard-manager.c
+++ b/src/vcard-manager.c
@@ -1147,7 +1147,6 @@ gabble_vcard_manager_edit_info_apply (GabbleVCardManagerEditInfo *info,
       if (node != NULL)
         vcard_copy (vcard_node, node, NULL, NULL);
 
-      /* Yes, we can do this: "WockyNode" is really a WockyNode */
       if (wocky_node_equal (old_vcard, vcard_node))
         {
           /* nothing actually happened, forget it */
@@ -1198,37 +1197,32 @@ gabble_vcard_manager_edit_info_apply (GabbleVCardManagerEditInfo *info,
   return msg;
 }
 
-/* Loudmouth hates me. The feelings are mutual.
- *
- * Note that this function doesn't copy any attributes other than
- * xmlns, because LM provides no way to iterate over attributes. Thanks, LM. */
 static WockyNode *
 vcard_copy (WockyNode *parent,
     WockyNode *src,
     const gchar *exclude,
     gboolean *exclude_mattered)
 {
-    WockyNode *new = wocky_node_add_child_with_content_ns_q (parent, src->name,
-        src->content, src->ns);
-    WockyNodeIter i;
-    WockyNode *child;
-
-    wocky_node_iter_init (&i, src, NULL, NULL);
-    while (wocky_node_iter_next (&i, &child))
-      {
-
-        if (tp_strdiff (child->name, exclude))
-          {
-            vcard_copy (new, child, NULL, NULL);
-          }
-        else
-          {
-            if (exclude_mattered != NULL)
-              *exclude_mattered = TRUE;
-          }
-      }
-
-    return new;
+  WockyNodeTree *copy = wocky_node_tree_new_from_node (src);
+  /* FIXME: this copies 'src' a second time. */
+  WockyNode *new = wocky_node_add_node_tree (parent, copy);
+
+  g_object_unref (copy);
+
+  if (exclude != NULL)
+    {
+      WockyNodeIter i;
+      WockyNode *excluded;
+
+      wocky_node_iter_init (&i, new, exclude, NULL);
+      while (wocky_node_iter_next (&i, &excluded))
+        {
+          *exclude_mattered = TRUE;
+          wocky_node_iter_remove (&i);
+        }
+    }
+
+  return new;
 }
 
 static void



More information about the telepathy-commits mailing list