[ekiga/ds-gsettings3] Simplified Opal::Bank code thanks new Settings wrappers.



commit 20042c762f4cb661ac7ccbc5728fcfe7714f7b35
Author: Damien Sandras <dsandras beip be>
Date:   Mon Oct 7 19:53:13 2013 +0200

    Simplified Opal::Bank code thanks new Settings wrappers.
    
    Using C++ code is better when possible.

 lib/ekiga-settings.h                     |   25 +++++++++++++++++++++++++
 lib/engine/components/opal/opal-bank.cpp |   26 +++++++++++---------------
 lib/engine/components/opal/opal-bank.h   |    3 ++-
 3 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/lib/ekiga-settings.h b/lib/ekiga-settings.h
index 968a7cb..ad7a6f4 100644
--- a/lib/ekiga-settings.h
+++ b/lib/ekiga-settings.h
@@ -129,6 +129,31 @@ public:
       g_settings_set_boolean (gsettings, key.c_str (), i);
     }
 
+    std::list<std::string> get_string_list (const std::string & key)
+    {
+      gchar **values = g_settings_get_strv (gsettings, key.c_str ());
+      std::list<std::string> result;
+
+      for (int i = 0 ; values && values[i] != NULL ; i++)
+       result.push_back (values[i]);
+
+      return result;
+    }
+
+    void set_string_list (const std::string & key, const std::list<std::string> & list)
+    {
+      gchar **values = (gchar**) g_malloc (sizeof (gchar*) * (list.size() + 1));
+      int i = 0;
+      for (std::list<std::string>::const_iterator it = list.begin ();
+          it != list.end ();
+          it++)
+       values[i++] = g_strdup (it->c_str ());
+      values[i++] = NULL;
+
+      g_settings_set_strv (gsettings, key.c_str (), values);
+      g_strfreev (values);
+    }
+
     boost::signals2::signal<void(std::string)> changed;
 
 private:
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 6549334..258538f 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -55,11 +55,13 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
   audiooutput_core(core.get<Ekiga::AudioOutputCore> ("audiooutput-core")),
   opal_component(core.get<CallManager> ("opal-component"))
 {
-  gchar **accounts = NULL;
-  protocols_settings = g_settings_new (PROTOCOLS_SCHEMA);
+  std::list<std::string> accounts;
+  protocols_settings = new Ekiga::Settings (PROTOCOLS_SCHEMA);
 
-  accounts = g_settings_get_strv (protocols_settings, "accounts-list");
-  for (int i = 0 ; accounts[i] != NULL ; i++) {
+  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,
@@ -67,14 +69,13 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
                                                 personal_details,
                                                 audiooutput_core,
                                                 opal_component,
-                                                (char *)accounts[i]));
+                                                (*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)));
   }
-  g_strfreev (accounts);
 
   sip_endpoint->registration_event.connect (boost::bind(&Opal::Bank::on_registration_event, this, _1, _2, 
_3));
   sip_endpoint->mwi_event.connect (boost::bind(&Opal::Bank::on_mwi_event, this, _1, _2));
@@ -93,7 +94,7 @@ Opal::Bank::~Bank ()
   // is already gone!
   Ekiga::RefLister<Opal::Account>::remove_all_objects ();
 
-  g_clear_object (&protocols_settings);
+  delete protocols_settings;
 }
 
 bool
@@ -316,18 +317,13 @@ Opal::Bank::find_account (const std::string& aor)
 void
 Opal::Bank::save () const
 {
-  int i = 0;
-  gchar** accounts = NULL;
-
-  accounts = (gchar**) g_malloc (sizeof (gchar*) * (size() + 1));
+  std::list<std::string> accounts;
   for (const_iterator it = begin ();
        it != end ();
        it++)
-    accounts[i++] = g_strdup ((*it)->as_string ().c_str ());
-  accounts[i++] = NULL;
+    accounts.push_back ((*it)->as_string ());
 
-  g_settings_set_strv (protocols_settings, "accounts-list", accounts);
-  g_strfreev (accounts);
+  protocols_settings->set_string_list ("accounts-list", accounts);
 }
 
 void
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index 1ce6e3a..163ebbd 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -42,6 +42,7 @@
 #include "presence-core.h"
 
 #include "opal-account.h"
+#include "ekiga-settings.h"
 
 namespace Opal
 {
@@ -142,7 +143,7 @@ private:
 
     void update_sip_endpoint_aor_map ();
 
-    GSettings *protocols_settings;
+    Ekiga::Settings *protocols_settings;
   };
 
   /**


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