From 148aec74ff123cb6e85f395d78014e55e3f4eab3 Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <manu@manu-eeepc.(none)>
Date: Sun, 7 Jun 2009 12:33:58 -0400
Subject: [PATCH] [#1214] Handle empty field - remove g_print

---
 sflphone-client-gnome/src/actions.c           |  4 +--
 sflphone-client-gnome/src/callable_obj.c      |  8 ++---
 sflphone-client-gnome/src/contacts/calllist.c | 31 +++++++++++--------
 sflphone-client-gnome/src/contacts/calllist.h |  2 ++
 sflphone-client-gnome/src/main.c              |  2 ++
 sflphone-common/test/history-sample.tpl       |  6 ++++
 6 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/sflphone-client-gnome/src/actions.c b/sflphone-client-gnome/src/actions.c
index c859e45c70..823769f1e4 100644
--- a/sflphone-client-gnome/src/actions.c
+++ b/sflphone-client-gnome/src/actions.c
@@ -235,9 +235,11 @@ gboolean sflphone_init()
     else
     {
         dbus_register(getpid(), "Gtk+ Client");
+
         current_calls = calltab_init(NULL);
         contacts = calltab_init("contacts");
         history = calltab_init("history");
+
         account_list_init ();
         codec_list_init();
 
@@ -972,9 +974,7 @@ void sflphone_save_history (void)
         if (current)
         {
             value = serialize_history_entry (current);
-            g_print ("before  %i\n", current->_time_start);
             key = convert_timestamp_to_gchar (current->_time_start);
-            g_print ("after  %s\n", key);
             g_hash_table_replace(result, (gpointer) key,
                     (gpointer) value);
         }
diff --git a/sflphone-client-gnome/src/callable_obj.c b/sflphone-client-gnome/src/callable_obj.c
index 4dc8d9f85d..22a7a5a723 100644
--- a/sflphone-client-gnome/src/callable_obj.c
+++ b/sflphone-client-gnome/src/callable_obj.c
@@ -136,7 +136,6 @@ void create_history_entry_from_serialized_form (gchar *timestamp, gchar *details
 
     if ((ptr = strtok(details, delim)) != NULL) {
         do {
-            g_print ("%s\n", ptr);
             switch (token)
             {
                 case 0:
@@ -224,8 +223,6 @@ gchar* get_call_duration (callable_obj_t *obj)
     start = obj->_time_start;
     end = obj->_time_stop;
     
-    g_print ("start = %i - end = %i\n", start, end);
-
     if (start == end)
         return g_markup_printf_escaped("<small>Duration:</small> none");
 
@@ -262,7 +259,10 @@ gchar* serialize_history_entry (callable_obj_t *entry)
     // and the timestamps
     timestamp = convert_timestamp_to_gchar (entry->_time_stop);
     
-    result = g_strconcat (history_state, "|", entry->_peer_number, "|", entry->_peer_name, "|", timestamp, NULL);
+    result = g_strconcat (history_state, separator, 
+                          entry->_peer_number, separator, 
+                          g_strcasecmp (entry->_peer_name,"") ==0 ? "empty": entry->_peer_name, 
+                           separator, timestamp, NULL);
 
     return result;
 }
diff --git a/sflphone-client-gnome/src/contacts/calllist.c b/sflphone-client-gnome/src/contacts/calllist.c
index 2b9cb698be..b3cde54dcd 100644
--- a/sflphone-client-gnome/src/contacts/calllist.c
+++ b/sflphone-client-gnome/src/contacts/calllist.c
@@ -78,27 +78,32 @@ calllist_reset (calltab_t* tab)
   tab->callQueue = g_queue_new();
 }
 
-void
-calllist_add (calltab_t* tab, callable_obj_t * c)
+void calllist_add_history_entry (callable_obj_t *obj)
 {
-  if( tab == history )
-  {
     // First case: can still add calls to the list
-    if( calllist_get_size(tab) < dbus_get_max_calls() )
+    if( calllist_get_size (history) < dbus_get_max_calls() )
     {
-      g_queue_push_tail (tab->callQueue, (gpointer *) c);
-      calltree_add_call( history , c );
+      g_queue_push_tail (history->callQueue, (gpointer *) obj);
+      calltree_add_call (history, obj);
     }
     // List full -> Remove the last call from history and preprend the new call to the list
     else
     {
-      calltree_remove_call( history , (callable_obj_t*)g_queue_pop_head( tab -> callQueue ) );
-      g_queue_push_tail (tab->callQueue, (gpointer *) c);
-      calltree_add_call( history , c );
+      calltree_remove_call( history , (callable_obj_t*)g_queue_pop_head (history->callQueue ) );
+      g_queue_push_tail (history->callQueue, (gpointer *) obj);
+      calltree_add_call (history, obj);
     }
-  }
-  else
-    g_queue_push_tail (tab->callQueue, (gpointer *) c);
+}
+
+void
+calllist_add (calltab_t* tab, callable_obj_t * c)
+{
+    if( tab == history )
+    {
+        calllist_add_history_entry (c);
+    }
+    else
+        g_queue_push_tail (tab->callQueue, (gpointer *) c);
 }
 
 // TODO : sflphoneGTK : try to do this more generic
diff --git a/sflphone-client-gnome/src/contacts/calllist.h b/sflphone-client-gnome/src/contacts/calllist.h
index 4243c7b5a8..f44afdb69d 100644
--- a/sflphone-client-gnome/src/contacts/calllist.h
+++ b/sflphone-client-gnome/src/contacts/calllist.h
@@ -41,6 +41,8 @@ typedef struct {
 void
 calllist_add_contact (gchar *, gchar *, contact_type_t, GdkPixbuf *);
 
+void calllist_add_history_entry (callable_obj_t *obj);
+
 /** This function initialize a call list. */
 void
 calllist_init (calltab_t* tab);
diff --git a/sflphone-client-gnome/src/main.c b/sflphone-client-gnome/src/main.c
index 43bc4f343d..1d7f249f38 100644
--- a/sflphone-client-gnome/src/main.c
+++ b/sflphone-client-gnome/src/main.c
@@ -104,6 +104,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\n");
 
     // Get the active calls at startup    
     sflphone_fill_call_list ();
+        
+    // Load the history
     sflphone_fill_history ();
 
     /* start the main loop */
diff --git a/sflphone-common/test/history-sample.tpl b/sflphone-common/test/history-sample.tpl
index 47c3b914ec..539338a688 100644
--- a/sflphone-common/test/history-sample.tpl
+++ b/sflphone-common/test/history-sample.tpl
@@ -15,3 +15,9 @@ number=5143848557
 name=Chez wam
 timestamp_stop=775354987
 type=1
+
+[534244222]
+number=136
+name=empty
+timestamp_stop=5656534543
+type=1
-- 
GitLab