From 8e7534d1ba560b011aac13ebd496d33e49d3b04c Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandresavard@msavard.(none)>
Date: Fri, 17 Jun 2011 14:59:16 -0400
Subject: [PATCH] #6183: Serialize conference participant phone number and
 account

---
 sflphone-client-gnome/src/actions.c           |  25 ++-
 sflphone-client-gnome/src/conference_obj.c    |  32 +++-
 sflphone-client-gnome/src/contacts/calllist.h |   1 +
 .../src/contacts/conferencelist.c             | 145 +++++++++++++-----
 .../src/contacts/conferencelist.h             |  27 ++--
 sflphone-client-gnome/src/dbus/dbus.c         |  11 +-
 sflphone-client-gnome/src/imwindow.c          |   4 +-
 sflphone-client-gnome/src/widget/imwidget.c   |   6 +-
 8 files changed, 183 insertions(+), 68 deletions(-)

diff --git a/sflphone-client-gnome/src/actions.c b/sflphone-client-gnome/src/actions.c
index 54a801752e..efc2508b28 100644
--- a/sflphone-client-gnome/src/actions.c
+++ b/sflphone-client-gnome/src/actions.c
@@ -337,7 +337,8 @@ gboolean sflphone_init (GError **error)
 
     account_list_init ();
     codec_capabilities_load ();
-    conferencelist_init ();
+    conferencelist_init (current_calls);
+    conferencelist_init (history);
 
     // Fetch the configured accounts
     sflphone_fill_account_list ();
@@ -1261,7 +1262,7 @@ void sflphone_fill_conference_list (void)
 
             conf->_confID = g_strdup (conf_id);
 
-            conferencelist_add (conf);
+            conferencelist_add (current_calls, conf);
             calltree_add_conference (current_calls, conf);
         }
     }
@@ -1336,6 +1337,7 @@ void sflphone_save_history (void)
     gint size;
     gint i;
     QueueElement *current;
+    conference_obj_t *conf;
     GHashTable *result = NULL;
     gchar *key, *value;
 
@@ -1361,6 +1363,7 @@ void sflphone_save_history (void)
  	    else {
 		ERROR("SFLphone: Error: Unknown type for serialization");
             }
+
             g_hash_table_replace (result, (gpointer) key, (gpointer) value);
         } 
 	else {
@@ -1368,6 +1371,24 @@ void sflphone_save_history (void)
         }
     }
 
+    size = conferencelist_get_size(history);
+    DEBUG("Conference list size %d", size);
+
+    while(size > 0) {
+	conf = conferencelist_pop_head(history);
+	size = conferencelist_get_size(history);
+
+        if(conf) {
+	    DEBUG("Serialize conference");
+	    value = serialize_history_conference_entry(conf);
+	    key = convert_timestamp_to_gchar(conf->_time_start);
+        }
+	else {
+	    WARN("SFLphone: Warning: %dth element is NULL", i);
+        }
+	g_hash_table_replace(result, (gpointer)key, (gpointer)value);	
+    }
+
     dbus_set_history (result);
 
     // Decrement the reference count
diff --git a/sflphone-client-gnome/src/conference_obj.c b/sflphone-client-gnome/src/conference_obj.c
index 401dbe4c41..cf5255fdb5 100644
--- a/sflphone-client-gnome/src/conference_obj.c
+++ b/sflphone-client-gnome/src/conference_obj.c
@@ -28,11 +28,16 @@
  *  as that of the covered work.
  */
 
-#include <callable_obj.h>
-#include <sflphone_const.h>
 #include <time.h>
 
+#include "callable_obj.h"
+#include "sflphone_const.h"
+
+#include "calltab.h"
+#include "calllist.h"
+
 static void set_conference_timestamp (time_t *);
+static void conference_add_participant_number(const gchar *, conference_obj_t *);
 
 static void set_conference_timestamp (time_t *timestamp) 
 {
@@ -127,11 +132,25 @@ void conference_add_participant (const gchar* call_id, conference_obj_t* conf)
 {
     // store the new participant list after appending participant id
     conf->participant_list = g_slist_append (conf->participant_list, (gpointer) g_strdup(call_id));
+
+    // store the phone number of this participant
+    conference_add_participant_number(call_id, conf);
 }
 
+static
 void conference_add_participant_number(const gchar *call_id, conference_obj_t *conf)
 {
-    conf->participant_number = g_slist_append(conf->participant_number, (gpointer) g_strdup(call_id));
+    gchar *number_account;
+
+    callable_obj_t *call = calllist_get_call(current_calls, call_id); 
+    if(call == NULL) {
+	ERROR("Conference: Error: Could not find");
+	return;
+    }
+    
+    number_account = g_strconcat(call->_peer_number, ",", call->_accountID, NULL);
+
+    conf->participant_number = g_slist_append(conf->participant_number, (gpointer) number_account);
 }
 
 void conference_remove_participant (const gchar* call_id, conference_obj_t* conf)
@@ -195,7 +214,10 @@ gchar *serialize_history_conference_entry(conference_obj_t *entry)
 	if(tmp == NULL) {
             WARN("Conference: Peer number is NULL in conference list");
         }
-        g_strconcat(numberstr, tmp, ",");
+        numberstr = g_strconcat(numberstr, tmp, ";", NULL);
+	
+
+	DEBUG("Print: %s concat: %s", tmp, numberstr);
     }
 
     result = g_strconcat("2188", separator,
@@ -207,5 +229,5 @@ gchar *serialize_history_conference_entry(conference_obj_t *entry)
 			NULL); 
   	
 
-    return "";
+    return result;
 }
diff --git a/sflphone-client-gnome/src/contacts/calllist.h b/sflphone-client-gnome/src/contacts/calllist.h
index 5288275bc5..ce814c4251 100644
--- a/sflphone-client-gnome/src/contacts/calllist.h
+++ b/sflphone-client-gnome/src/contacts/calllist.h
@@ -59,6 +59,7 @@ typedef struct {
 
     // Calllist vars
     GQueue* callQueue;
+    GQueue* conferenceQueue;
     gint selectedType;
     callable_obj_t* selectedCall;
     conference_obj_t* selectedConf;
diff --git a/sflphone-client-gnome/src/contacts/conferencelist.c b/sflphone-client-gnome/src/contacts/conferencelist.c
index 6cba64c070..5ecb86cab8 100644
--- a/sflphone-client-gnome/src/contacts/conferencelist.c
+++ b/sflphone-client-gnome/src/contacts/conferencelist.c
@@ -30,10 +30,12 @@
 
 #include <conferencelist.h>
 
+#include "logger.h"
+
 static gint is_confID_confstruct(gconstpointer, gconstpointer);
+static gchar *generate_conf_id (void);
 
-static
-gint is_confID_confstruct (gconstpointer a, gconstpointer b)
+static gint is_confID_confstruct (gconstpointer a, gconstpointer b)
 {
     conference_obj_t * c = (conference_obj_t*) a;
 
@@ -44,89 +46,154 @@ gint is_confID_confstruct (gconstpointer a, gconstpointer b)
     }
 }
 
-gchar*
-generate_conf_id (void)
+static gchar *generate_conf_id (void)
 {
     gchar *conf_id;
 
     conf_id = g_new0 (gchar, 30);
     g_sprintf (conf_id, "%d", rand());
+    
     return conf_id;
 }
 
 
-void
-conferencelist_init()
+void conferencelist_init(calltab_t *tab)
 {
-    conferenceQueue = g_queue_new ();
+    if(tab == NULL) {
+	ERROR("ConferenceList: Error: Call tab is NULL");
+	return;
+    }
+
+    tab->conferenceQueue = g_queue_new ();
 }
 
 
-void
-conferencelist_clean()
+void conferencelist_clean(calltab_t *tab)
 {
-    g_queue_free (conferenceQueue);
+    if(tab == NULL) {
+    	ERROR("ConferenceList: Error: Calltab tab is NULL");
+	return;
+    }
+
+    g_queue_free (tab->conferenceQueue);
 }
 
 
-void
-conferencelist_reset()
+void conferencelist_reset(calltab_t *tab)
 {
-    g_queue_free (conferenceQueue);
-    conferenceQueue = g_queue_new();
+    if(tab == NULL) {
+        ERROR("ConferenceList: Error: Calltab tab is NULL");
+        return;
+    }
+
+    g_queue_free (tab->conferenceQueue);
+    tab->conferenceQueue = g_queue_new();
 }
 
 
-void
-conferencelist_add (const conference_obj_t* conf)
+void conferencelist_add (calltab_t *tab, const conference_obj_t* conf)
 {
-    gchar* c = (gchar*) conferencelist_get (conf->_confID);
+    gchar* c;
+    
+    if(conf == NULL) {
+        ERROR("ConferenceList: Error: Conference is NULL");
+	return;
+    }
+
+    if(tab == NULL) {
+	ERROR("ConferenceList: Error: Tab is NULL");
+	return;
+    }
+
+    c = (gchar*) conferencelist_get (tab, conf->_confID);
 
     if (!c) {
-        g_queue_push_tail (conferenceQueue, (gpointer) conf);
+	// only add conference into the list if not already inserted
+        g_queue_push_tail (tab->conferenceQueue, (gpointer) conf);
     }
 }
 
 
-void
-conferencelist_remove (const gchar* conf)
+void conferencelist_remove (calltab_t *tab, const gchar* conf)
 {
-    gchar* c = (gchar*) conferencelist_get (conf);
+    gchar* c; 
+
+    if(conf == NULL) {
+	ERROR("ConferenceList: Error: Conf id is NULL");
+	return;
+    }
 
-    if (c) {
-        g_queue_remove (conferenceQueue, c);
+    if(tab == NULL) {
+	ERROR("ConferenceList: Error: Calltab is NULL");
+	return;
     }
+
+    c = (gchar*) conferencelist_get (tab, conf);
+
+    if(c == NULL) {
+        ERROR("ConferenceList: Error: Could not find conference %s", conf);
+	return;
+    }
+
+    g_queue_remove (tab->conferenceQueue, c);
 }
 
-conference_obj_t*
-conferencelist_get (const gchar* conf_id)
+conference_obj_t* conferencelist_get (calltab_t *tab, const gchar* conf_id)
 {
 
-    GList* c = g_queue_find_custom (conferenceQueue, conf_id, is_confID_confstruct);
+    GList* c;
 
-    if (c) {
-        return (conference_obj_t*) c->data;
-    } else {
+    if(tab == NULL) {
+	ERROR("ConferenceList: Error: Calltab is NULL");
+	return;
+    } 
+
+    c = g_queue_find_custom (tab->conferenceQueue, conf_id, is_confID_confstruct);
+
+    if(c == NULL) {
+        ERROR("ConferenceList: Error: Could not find conference %s", conf_id);
         return NULL;
     }
+
+    return (conference_obj_t*) c->data;
 }
 
 
-conference_obj_t*
-conferencelist_get_nth (guint n)
+conference_obj_t* conferencelist_get_nth (calltab_t *tab, guint n)
 {
-    GList* c = g_queue_peek_nth (conferenceQueue, n);
+    GList* c; 
 
-    if (c) {
-        return (conference_obj_t*) c->data;
-    } else {
-        return NULL;
+    if(tab == NULL) {
+        ERROR("ConferenceList: Error: Calltab is NULL");
+	return NULL;
+    }
+
+    c = g_queue_peek_nth (tab->conferenceQueue, n);
+
+    if(c == NULL) {
+	ERROR("ConferenceList: Error: Could not fetch conference %d", n);
+	return NULL;
     }
+
+    return (conference_obj_t*) c->data;
 }
 
+conference_obj_t *conferencelist_pop_head(calltab_t *tab)
+{
+    if(tab == NULL) {
+	ERROR("ConferenceList: Error: Tab is NULL");
+	return NULL;
+    }
+
+    return g_queue_pop_head(tab->conferenceQueue);
+}
 
-guint
-conferencelist_get_size ()
+guint conferencelist_get_size (calltab_t *tab)
 {
-    return g_queue_get_length (conferenceQueue);
+    if(tab == NULL) {
+        ERROR("ConferenceList: Error: Calltab is NULL");
+	return 0;
+    }
+
+    return g_queue_get_length (tab->conferenceQueue);
 }
diff --git a/sflphone-client-gnome/src/contacts/conferencelist.h b/sflphone-client-gnome/src/contacts/conferencelist.h
index a2bcc6a455..f09060b850 100644
--- a/sflphone-client-gnome/src/contacts/conferencelist.h
+++ b/sflphone-client-gnome/src/contacts/conferencelist.h
@@ -31,56 +31,59 @@
 #ifndef __CONFERENCELIST_H__
 #define __CONFERENCELIST_H__
 
-
-#include <conference_obj.h>
 #include <gtk/gtk.h>
 
+#include "conference_obj.h"
+#include "calllist.h"
+
 /** @file conferencelist.h
   * @brief A list to store conferences.
   */
 
-GQueue* conferenceQueue;
+// GQueue* conferenceQueue;
 
 /** This function initialize a conference list. */
 void
-conferencelist_init ();
+conferencelist_init (calltab_t *);
 
 /** This function empty and free the conference list. */
 void
-conferencelist_clean ();
+conferencelist_clean (calltab_t *);
 
 /** This function empty, free the conference list and allocate a new one. */
 void
-conferencelist_reset ();
+conferencelist_reset (calltab_t *);
 
 /** This function append a conference to the list.
   * @param conf The conference you want to add
   * */
 void
-conferencelist_add (const conference_obj_t* conf);
+conferencelist_add (calltab_t *, const conference_obj_t *);
 
 /** This function remove a conference from list.
   * @param callID The callID of the conference you want to remove
   */
 void
-conferencelist_remove (const gchar* conf);
+conferencelist_remove (calltab_t *, const gchar *);
 
 /** Return the number of calls in the list
   * @return The number of calls in the list */
 guint
-conferencelist_get_size ();
+conferencelist_get_size (calltab_t *);
 
 /** Return the call at the nth position in the list
   * @param n The position of the call you want
   * @return A call or NULL */
 conference_obj_t*
-conferencelist_get_nth (guint n);
+conferencelist_get_nth (calltab_t *, guint);
 
 /** Return the call corresponding to the callID
-  * @param n The callID of the call you want
+  * @param n The callID of the call  want
   * @return A call or NULL */
 conference_obj_t*
-conferencelist_get (const gchar* conf);
+conferencelist_get (calltab_t *, const gchar *);
 
+conference_obj_t*
+conferencelist_pop_head(calltab_t *);
 
 #endif
diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c
index cb46476b5c..cc38c1953d 100644
--- a/sflphone-client-gnome/src/dbus/dbus.c
+++ b/sflphone-client-gnome/src/dbus/dbus.c
@@ -167,7 +167,7 @@ incoming_message_cb (DBusGProxy *proxy UNUSED, const gchar* callID UNUSED, const
     call = calllist_get_call (current_calls, callID);
 
     // Get the conference information (if this conference exist)
-    conf = conferencelist_get (callID);
+    conf = conferencelist_get (current_calls, callID);
 
     /* First check if the call is valid */
     if (call) {
@@ -275,7 +275,7 @@ conference_changed_cb (DBusGProxy *proxy UNUSED, const gchar* confID,
     gchar* call_id;
 
     // sflphone_display_transfer_status("Transfer successfull");
-    conference_obj_t* changed_conf = conferencelist_get (confID);
+    conference_obj_t* changed_conf = conferencelist_get (current_calls, confID);
     GSList * part;
 
     DEBUG ("---------------------------- DBUS: Conference state changed: %s\n", state);
@@ -377,7 +377,8 @@ conference_created_cb (DBusGProxy *proxy UNUSED, const gchar* confID, void * foo
 
     set_timestamp(&new_conf->_time_start);
 
-    conferencelist_add (new_conf);
+    conferencelist_add (current_calls, new_conf);
+    conferencelist_add (history, new_conf);
     calltree_add_conference (current_calls, new_conf);
     calltree_add_conference (history, new_conf);
 }
@@ -387,7 +388,7 @@ conference_removed_cb (DBusGProxy *proxy UNUSED, const gchar* confID, void * foo
 {
     DEBUG ("DBUS: Conference removed %s", confID);
 
-    conference_obj_t * c = conferencelist_get (confID);
+    conference_obj_t * c = conferencelist_get (current_calls, confID);
     calltree_remove_conference (current_calls, c, NULL);
 
     GSList *participant = c->participant_list;
@@ -418,7 +419,7 @@ conference_removed_cb (DBusGProxy *proxy UNUSED, const gchar* confID, void * foo
         participant = conference_next_participant (participant);
     }
 
-    conferencelist_remove (c->_confID);
+    conferencelist_remove (current_calls, c->_confID);
 }
 
 static void
diff --git a/sflphone-client-gnome/src/imwindow.c b/sflphone-client-gnome/src/imwindow.c
index 1212d6697f..3681fa9402 100644
--- a/sflphone-client-gnome/src/imwindow.c
+++ b/sflphone-client-gnome/src/imwindow.c
@@ -203,7 +203,7 @@ im_window_add_tab (GtkWidget *widget)
 
     /* Fetch the call */
     callable_obj_t *im_widget_call = calllist_get_call (current_calls, im->call_id);
-    conference_obj_t *im_widget_conf = conferencelist_get (im->call_id);
+    conference_obj_t *im_widget_conf = conferencelist_get (current_calls, im->call_id);
 
     /* A container to include the tab label and the close button */
     GtkWidget *tab_Container = gtk_hbox_new (FALSE, 3);
@@ -275,7 +275,7 @@ im_window_remove_tab (GtkWidget *widget)
     /* Need to do some memory clean up, so that we could re-open an Im widget for this call later. */
     IMWidget *im = IM_WIDGET (widget);
     callable_obj_t *call = calllist_get_call (current_calls, im->call_id);
-    conference_obj_t *conf = conferencelist_get (im->call_id);
+    conference_obj_t *conf = conferencelist_get (current_calls, im->call_id);
 
     if (call)
         call->_im_widget = NULL;
diff --git a/sflphone-client-gnome/src/widget/imwidget.c b/sflphone-client-gnome/src/widget/imwidget.c
index 5c0d6c8bb1..5cb55eb237 100644
--- a/sflphone-client-gnome/src/widget/imwidget.c
+++ b/sflphone-client-gnome/src/widget/imwidget.c
@@ -51,7 +51,7 @@ on_frame_loading_done (GObject *gobject UNUSED, GParamSpec *pspec UNUSED, gpoint
                 break;
             case WEBKIT_LOAD_FINISHED:
                 call = calllist_get_call (current_calls, im->call_id);
-                conf = conferencelist_get (im->call_id);
+                conf = conferencelist_get (current_calls, im->call_id);
 
                 if (call)
                     im_widget_add_message (im, im->first_message_from, im->first_message, 0);
@@ -216,7 +216,7 @@ im_widget_send_message (gchar *id, const gchar *message)
 {
 
     callable_obj_t *im_widget_call = calllist_get_call (current_calls, id);
-    conference_obj_t *im_widget_conf = conferencelist_get (id);
+    conference_obj_t *im_widget_conf = conferencelist_get (current_calls, id);
 
     /* If the call has been hungup, it is not anymore in the current_calls calltab */
     if (!im_widget_call) {
@@ -396,7 +396,7 @@ im_widget_infobar (IMWidget *im)
 
     /* Fetch call/conference information */
     callable_obj_t *im_widget_call = calllist_get_call (current_calls, im->call_id);
-    conference_obj_t *im_widget_conf = conferencelist_get (im->call_id);
+    conference_obj_t *im_widget_conf = conferencelist_get (current_calls, im->call_id);
 
     /* Create the label widgets with the call information saved in the IM Widget struct */
     gchar *msg1;
-- 
GitLab