From 49aa761bbc3be644646131d9f9958e05c156e20f Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Wed, 23 Apr 2008 14:21:56 -0400
Subject: [PATCH] Add new states for history calls

The history takes in consideration all the outgoing and incoming calls
You can't call back every calls from history tab (those you don't hang up on)
---
 sflphone-gtk/src/actions.c    | 27 ++++++++++++--------
 sflphone-gtk/src/calllist.h   | 15 ++++++++++-
 sflphone-gtk/src/calltree.c   | 47 +++++++++++++++++++++++++++++++++--
 sflphone-gtk/src/mainwindow.c |  5 ----
 4 files changed, 75 insertions(+), 19 deletions(-)

diff --git a/sflphone-gtk/src/actions.c b/sflphone-gtk/src/actions.c
index a684cd3231..b69ae8ec52 100644
--- a/sflphone-gtk/src/actions.c
+++ b/sflphone-gtk/src/actions.c
@@ -227,14 +227,14 @@ sflphone_hang_up()
 			case CALL_STATE_FAILURE:
 				dbus_hang_up (selectedCall);
 				selectedCall->state = CALL_STATE_DIALING;
-				call_list_add(history, selectedCall);
-				update_call_tree_add(history, selectedCall);
+				//call_list_add(history, selectedCall);
+				//update_call_tree_add(history, selectedCall);
 				break;
 			case CALL_STATE_INCOMING:  
 				dbus_refuse (selectedCall);
 				selectedCall->state = CALL_STATE_DIALING;
-				call_list_add(history, selectedCall);
-				update_call_tree_add(history, selectedCall);
+				//call_list_add(history, selectedCall);
+				//update_call_tree_add(history, selectedCall);
 				break;
 			case CALL_STATE_TRANSFERT:  
 				dbus_hang_up (selectedCall);
@@ -372,9 +372,11 @@ sflphone_unset_transfert()
 void
 sflphone_incoming_call (call_t * c) 
 {
-	call_list_add ( current_calls,c );
-	//status_icon_unminimize();
-	update_call_tree_add(current_calls,c);
+	c->history_state = INCOMING;
+	call_list_add ( current_calls, c );
+	call_list_add( history, c );
+	update_call_tree_add( current_calls , c );
+	update_call_tree_add( history , c );
 	update_menus();
 }
 
@@ -478,7 +480,6 @@ sflphone_keypad( guint keyval, gchar * key)
 	call_t * c = call_get_selected(current_calls);
 	if(c)
 	{
-
 		switch(c->state) 
 		{
 			case CALL_STATE_DIALING: // Currently dialing => edit number
@@ -582,7 +583,7 @@ sflphone_keypad( guint keyval, gchar * key)
  } 
 
 /*
- * Place a call with the default account.
+ * Place a call with the current account.
  * If there is no default account selected, place a call with the first 
  * registered account of the account list
  * Else, popup an error message
@@ -618,9 +619,9 @@ sflphone_place_call ( call_t * c )
 	}
 	else
 	{
-	  // No current accounts have been setup. 
+	  // Current account is not registered 
 	  // So we place a call with the first registered account
-	  // And we change the current account
+	  // And we switch the current account
 	  current = account_list_get_by_state( ACCOUNT_STATE_REGISTERED );
 	  c -> accountID = current -> accountID;
 	  dbus_place_call(c);
@@ -642,6 +643,10 @@ sflphone_place_call ( call_t * c )
 	account_list_set_current_id( c-> accountID );
       }
     }
+	// Update history
+	c->history_state = OUTGOING;
+	call_list_add(history, c);
+	update_call_tree_add(history, c);
   }
 }
 
diff --git a/sflphone-gtk/src/calllist.h b/sflphone-gtk/src/calllist.h
index 9465b93768..a0381ca12b 100644
--- a/sflphone-gtk/src/calllist.h
+++ b/sflphone-gtk/src/calllist.h
@@ -49,6 +49,17 @@ typedef enum
    CALL_STATE_TRANSFERT       
 } call_state_t;
 
+/**
+ * @enum history_state
+ * This enum have all the state a call can take in the history
+ */
+typedef enum
+{
+  NONE,
+  INCOMING,
+  OUTGOING,
+  MISSED
+} history_state_t;
 
 /** @struct call_t
   * @brief Call information.
@@ -64,8 +75,10 @@ typedef struct  {
   gchar * from;
   /** The number we are calling.  Only used when dialing out */
   gchar * to;
-  /* The current state of the call */
+  /** The current state of the call */
   call_state_t state;
+  /** The history state */
+  history_state_t history_state;
 } call_t;
 
 typedef struct {
diff --git a/sflphone-gtk/src/calltree.c b/sflphone-gtk/src/calltree.c
index 1f3754097a..0f45d111e1 100644
--- a/sflphone-gtk/src/calltree.c
+++ b/sflphone-gtk/src/calltree.c
@@ -152,6 +152,7 @@ toggle_history(GtkToggleToolButton *toggle_tool_button,
 	sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (active_calltree->view));
 	g_signal_emit_by_name(sel, "changed");
 	toolbar_update_buttons();
+
 }
 
   static void
@@ -555,7 +556,14 @@ update_call_tree (calltab_t* tab, call_t * c)
 						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/current.svg", NULL);
 						break;
 					case CALL_STATE_DIALING:
-						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/dial.svg", NULL);
+						if( c->history_state == INCOMING )
+						  pixbuf = gdk_pixbuf_new_from_file( ICONS_DIR "/incoming.svg", NULL);
+						else if( c->history_state == OUTGOING )
+						  pixbuf = gdk_pixbuf_new_from_file( ICONS_DIR "/outgoing.svg", NULL);
+						else if( c->history_state == MISSED )
+						  pixbuf = gdk_pixbuf_new_from_file( ICONS_DIR "/missed.svg", NULL);
+						else
+						  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/dial.svg", NULL);
 						break;
 					case CALL_STATE_FAILURE:
 						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/fail.svg", NULL);
@@ -569,6 +577,21 @@ update_call_tree (calltab_t* tab, call_t * c)
 					default:
 						g_warning("Should not happen!");
 				}
+
+				/*switch(c->history_state)
+				{
+				  case OUTGOING:
+				    g_print("Outgoing state\n");
+				    pixbuf = gdk_pixbuf_new_from_file( ICONS_DIR "/outgoing.svg", NULL);
+				    break;
+				  case INCOMING:
+				    g_print("Incoming state\n");
+				    pixbuf = gdk_pixbuf_new_from_file( ICONS_DIR "/incoming.svg", NULL);
+				    break;
+				  default:
+				    g_print("No history state\n");  
+				    break;
+				}*/
 				//Resize it
 				if(pixbuf)
 				{
@@ -610,6 +633,8 @@ update_call_tree_add (calltab_t* tab, call_t * c)
 
 	gtk_list_store_prepend (tab->store, &iter);
 
+	if( tab == current_calls )
+	{
 	switch(c->state)
 	{
 		case CALL_STATE_INCOMING:
@@ -624,7 +649,25 @@ update_call_tree_add (calltab_t* tab, call_t * c)
 		default:
 			g_warning("Should not happen!");
 	}
-
+	}
+	else{
+	      //pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/incoming.svg", NULL);
+	  switch(c->history_state)
+	  {
+	    case INCOMING:
+	      pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/incoming.svg", NULL);
+	      break;
+	    case OUTGOING:
+	      pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/outgoing.svg", NULL);
+	      break;
+	    case MISSED:
+	      pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/missed.svg", NULL);
+	      break;
+	    default:
+	      g_warning("Should not happen!");
+	  }
+	}
+	  
 	//Resize it
 	if(pixbuf)
 	{
diff --git a/sflphone-gtk/src/mainwindow.c b/sflphone-gtk/src/mainwindow.c
index ad501f533a..872bb5f1cb 100644
--- a/sflphone-gtk/src/mainwindow.c
+++ b/sflphone-gtk/src/mainwindow.c
@@ -153,11 +153,6 @@ create_main_window ()
   
   gtk_box_pack_start (GTK_BOX (vbox), subvbox, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
  
-  //widget = create_slider("speaker");
-  //gtk_box_pack_start (GTK_BOX (subvbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
-  //widget = create_slider("mic");
-  //gtk_box_pack_start (GTK_BOX (subvbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
-
   /* Status bar */
   statusBar = gtk_statusbar_new();
   gtk_box_pack_start (GTK_BOX (vbox), statusBar, FALSE /*expand*/, TRUE /*fill*/,  0 /*padding*/);
-- 
GitLab