[ekiga/jp-opal-roster] Opal::Bank: finally made it use an XML document, and fixed a few compilation errors



commit 031a3e22a9a3797ac2da63eb96ad4a107701c5b3
Author: Julien Puydt <jpuydt free fr>
Date:   Sat Oct 26 18:43:55 2013 +0200

    Opal::Bank: finally made it use an XML document, and fixed a few compilation errors

 lib/engine/components/opal/opal-bank.cpp |   74 ++++++++++++++++++-----------
 lib/engine/components/opal/opal-bank.h   |    3 +
 2 files changed, 49 insertions(+), 28 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 9562424..c2e14b9 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -61,23 +61,34 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
   std::list<std::string> accounts;
   protocols_settings = new Ekiga::Settings (PROTOCOLS_SCHEMA);
 
-  accounts = protocols_settings->get_string_list ("accounts-list");
-  for (std::list<std::string>::const_iterator it = accounts.begin ();
-       it != accounts.end ();
-       it++) {
-
-    boost::shared_ptr<Account> account
-      = boost::shared_ptr<Account> (new Account (sip_endpoint,
-                                                notification_core,
-                                                personal_details,
-                                                audiooutput_core,
-                                                opal_component,
-                                                (*it)));
-
-    add_account (account);
-    Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
-    Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref 
(presence_received)));
-    Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref 
(status_received)));
+  const std::string raw = protocols_settings->get_string ("accounts");
+
+  doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc);
+  if (!doc)
+    doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
+
+  node = xmlDocGetRootElement (doc.get ());
+  if (node == NULL) {
+
+    node = xmlNewDocNode (doc.get (), NULL, BAD_CAST "accounts", NULL);
+    xmlDocSetRootElement (doc.get (), node);
+  }
+
+  for (xmlNodePtr child = node->children; child != NULL; child = child->next) {
+
+    if (child->type == XML_ELEMENT_NODE
+       && child->name != NULL
+       && xmlStrEqual(BAD_CAST "account", child->name)) {
+
+      boost::shared_ptr<Account> account(new Account (sip_endpoint, presence_core, notification_core,
+                                                     personal_details, audiooutput_core, opal_component,
+                                                     boost::bind(&Opal::Bank::existing_groups, this), 
child));
+
+      add_account (account);
+      Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
+      Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref 
(presence_received)));
+      Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref 
(status_received)));
+    }
   }
 
   sip_endpoint->registration_event.connect (boost::bind(&Opal::Bank::on_registration_event, this, _1, _2, 
_3));
@@ -273,7 +284,7 @@ Opal::Bank::on_new_account_form_submitted (bool submitted,
 
 
 void
-Opal::Bank::add (Account::Type acc_type,
+Opal::Bank::add (G_GNUC_UNUSED Account::Type acc_type,
                 std::string name,
                 std::string host,
                 std::string user,
@@ -282,15 +293,21 @@ Opal::Bank::add (Account::Type acc_type,
                 bool enabled,
                 unsigned timeout)
 {
+  xmlNodePtr child = Opal::Account::build_node (name, host, user, auth_user, password, enabled, timeout);
+
+  xmlAddChild (node, child);
+
+  save ();
+
   AccountPtr account
     = AccountPtr(new Opal::Account (sip_endpoint,
+                                   presence_core,
                                    notification_core,
                                    personal_details,
                                    audiooutput_core,
-                                   opal_component, acc_type, name,
-                                   host, user, auth_user,
-                                   password, enabled,
-                                   timeout));
+                                   opal_component,
+                                   boost::bind(&Opal::Bank::existing_groups, this),
+                                   child));
   add_account (account);
   Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
   Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref 
(presence_received)));
@@ -331,13 +348,14 @@ Opal::Bank::find_account (const std::string& aor)
 void
 Opal::Bank::save () const
 {
-  std::list<std::string> accounts;
-  for (const_iterator it = begin ();
-       it != end ();
-       it++)
-    accounts.push_back ((*it)->as_string ());
+  xmlChar *buffer = NULL;
+  int doc_size = 0;
+
+  xmlDocDumpMemory (doc.get (), &buffer, &doc_size);
+
+  protocols_settings->set_string ("accounts", (const char*)buffer);
 
-  protocols_settings->set_string_list ("accounts-list", accounts);
+  xmlFree (buffer);
 }
 
 
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index 76903fa..f96ca11 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -123,6 +123,9 @@ private:
     boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core;
     boost::shared_ptr<CallManager> opal_component;
 
+    boost::shared_ptr<xmlDoc> doc;
+    xmlNodePtr node;
+
     bool populate_menu_helper (const std::string fullname,
                               const std::string& uri,
                               Ekiga::MenuBuilder& builder);


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