[ekiga] Added code to migrate the ekiga.net configuration from 3.0 to 3.2 (fixing bug #577881)



commit 508d3ac2e85cc95ee540f6d48bb680cc5aaa0d0a
Author: Julien Puydt <jpuydt gnome org>
Date:   Tue Apr 28 18:43:15 2009 +0200

    Added code to migrate the ekiga.net configuration from 3.0 to 3.2 (fixing bug #577881)
    
    This required adding a should_add_ekiga_net_book variable to avoid getting duplicates
---
 lib/engine/components/ldap/ldap-source.cpp |   55 +++++++++++++++++++++++++++-
 lib/engine/components/ldap/ldap-source.h   |    3 ++
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/lib/engine/components/ldap/ldap-source.cpp b/lib/engine/components/ldap/ldap-source.cpp
index 689c522..a29e249 100644
--- a/lib/engine/components/ldap/ldap-source.cpp
+++ b/lib/engine/components/ldap/ldap-source.cpp
@@ -48,7 +48,8 @@
 
 #define KEY "/apps/" PACKAGE_NAME "/contacts/ldap_servers"
 
-OPENLDAP::Source::Source (Ekiga::ServiceCore &_core): core(_core), doc()
+OPENLDAP::Source::Source (Ekiga::ServiceCore &_core):
+  core(_core), doc(), should_add_ekiga_net_book(false)
 {
   xmlNodePtr root;
   gchar *c_raw = gm_conf_get_string (KEY);
@@ -69,6 +70,8 @@ OPENLDAP::Source::Source (Ekiga::ServiceCore &_core): core(_core), doc()
       xmlDocSetRootElement (doc.get (), root);
     }
 
+    migrate_from_3_0_0 ();
+
     for (xmlNodePtr child = root->children ;
 	 child != NULL ;
 	 child = child->next)
@@ -84,8 +87,11 @@ OPENLDAP::Source::Source (Ekiga::ServiceCore &_core): core(_core), doc()
     root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
     xmlDocSetRootElement (doc.get (), root);
 
-    new_ekiga_net_book ();
+    should_add_ekiga_net_book = true;
   }
+
+  if (should_add_ekiga_net_book)
+    new_ekiga_net_book ();
 }
 
 OPENLDAP::Source::~Source ()
@@ -220,3 +226,48 @@ OPENLDAP::Source::save ()
 
   xmlFree (buffer);
 }
+
+void
+OPENLDAP::Source::migrate_from_3_0_0 ()
+{
+  gboolean found = false;
+  xmlNodePtr root = xmlDocGetRootElement (doc.get ()); // can't be NULL
+
+  for (xmlNodePtr server = root->children ;
+       server != NULL && !found;
+       server = server->next) {
+
+    if (server->type == XML_ELEMENT_NODE
+	&& server->name != NULL
+	&& xmlStrEqual (BAD_CAST "server", server->name)) {
+
+      for (xmlNodePtr child = server->children;
+	   child != NULL && !found;
+	   child = child->next) {
+
+	if (child->type == XML_ELEMENT_NODE
+	    && child->name != NULL
+	    && xmlStrEqual (BAD_CAST "hostname", child->name)) {
+
+	  // if it has a hostname, it's already an old config item
+	  xmlChar* xml_str = xmlNodeGetContent (child);
+	  if (xml_str != NULL) {
+
+	    if (xmlStrEqual (BAD_CAST "ekiga.net", xml_str)) {
+
+	      // ok, that's the one : let's get rid of it!
+	      found = true;
+	      xmlUnlinkNode (server);
+	      xmlFreeNode (server);
+	    }
+	    xmlFree (xml_str);
+	  }
+	}
+      }
+    }
+  }
+
+  // eh, we removed it, but we should add it back!
+  if (found)
+    should_add_ekiga_net_book = true;
+}
diff --git a/lib/engine/components/ldap/ldap-source.h b/lib/engine/components/ldap/ldap-source.h
index ea6fab2..3cc1418 100644
--- a/lib/engine/components/ldap/ldap-source.h
+++ b/lib/engine/components/ldap/ldap-source.h
@@ -94,6 +94,9 @@ namespace OPENLDAP
 
     void on_new_book_form_submitted (bool submitted,
 				     Ekiga::Form &result);
+
+    gboolean should_add_ekiga_net_book;
+    void migrate_from_3_0_0 ();
   };
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]