Commit b7b7cdbd authored by Pierre-Luc Beaudoin's avatar Pierre-Luc Beaudoin

New call tree that contains all calls.

The call tree is not cleared any more but updated.
parent 539543e4
......@@ -16,10 +16,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtk/gtk.h>
#include <string.h>
#include <actions.h>
#include <accountlist.h>
#include <gtk/gtk.h>
/**
* Terminate the gtk program
......@@ -52,10 +54,19 @@ void
sflphone_hold(call_t * c )
{
c->state = CALL_STATE_HOLD;
update_call_tree();
update_call_tree(c);
screen_clear();
}
/**
* Put the call in Ringing state
*/
void
sflphone_ringing(call_t * c )
{
c->state = CALL_STATE_RINGING;
update_call_tree(c);
}
/* Fill account list */
......@@ -121,7 +132,7 @@ void
sflphone_unhold(call_t * c )
{
c->state = CALL_STATE_CURRENT;
update_call_tree();
update_call_tree(c);
screen_set_call(c);
}
......@@ -132,7 +143,7 @@ void
sflphone_hang_up( call_t * c )
{
call_list_remove(c->callID);
update_call_tree();
update_call_tree_remove(c);
screen_clear();
}
......@@ -143,7 +154,7 @@ void
sflphone_current( call_t * c )
{
c->state = CALL_STATE_CURRENT;
update_call_tree();
update_call_tree(c);
screen_set_call(c);
}
......@@ -154,7 +165,7 @@ void
sflphone_transfert( call_t * c, gchar * to )
{
screen_clear();
update_call_tree();
update_call_tree_remove(c);
}
/**
......@@ -164,7 +175,7 @@ void
sflphone_incoming_call (call_t * c)
{
call_list_add ( c );
update_call_tree();
update_call_tree_add(c);
}
/**
* Signal Hung up
......@@ -173,7 +184,7 @@ void
sflphone_hung_up (call_t * c )
{
call_list_remove(c->callID);
update_call_tree();
update_call_tree_remove(c);
screen_clear();
}
......@@ -186,12 +197,32 @@ sflphone_keypad( guint keyval, gchar * key)
switch (keyval)
{
case 65293: /* ENTER */
case 65421: /* ENTER numpad */
sflphone_place_call(c);
break;
case 65307: /* ESCAPE */
sflphone_hang_up(c);
break;
case 65288: /* BACKSPACE */
{ /* Brackets mandatory because of local vars */
gchar * before = c->to;
if(strlen(c->to) > 1){
c->to = g_strndup(c->to, strlen(c->to) -1);
g_free(before);
g_print("TO: %s\n", c->to);
g_free(c->from);
c->from = g_strconcat("\"\" <", c->to, ">", NULL);
screen_set_call(c);
update_call_tree();
}
else if(strlen(c->to) == 1)
{
sflphone_hang_up(c);
}
}
break;
case 65289: /* TAB */
case 65513: /* ALT */
case 65507: /* CTRL */
......
......@@ -40,6 +40,8 @@ void sflphone_transfert ( call_t * c, gchar * to );
void sflphone_hold ( call_t * c);
void sflphone_ringing(call_t * c );
void sflphone_unhold ( call_t * c);
/* signals */
......
......@@ -25,7 +25,8 @@
typedef enum
{
CALL_STATE_INVALID = 0,
CALL_STATE_INCOMING,
CALL_STATE_INCOMING, /* Ringing incoming call */
CALL_STATE_RINGING, /* Ringing outgoing call */
CALL_STATE_CURRENT,
CALL_STATE_DIALING,
CALL_STATE_HOLD
......
......@@ -22,59 +22,75 @@
#include <calllist.h>
GtkListStore * store;
GtkWidget * acceptButton;
GtkWidget * refuseButton;
GtkWidget * unholdButton;
GtkWidget * holdButton;
GtkWidget *view;
GtkWidget * callButton;
GtkWidget * hangupButton;
GtkWidget * holdButton;
GtkWidget * transfertButton;
GtkWidget * unholdButton;
call_t * selectedCall;
/**
* Hold the line
* Make a call
*/
static void
hold( GtkWidget *widget, gpointer data )
call_button( GtkWidget *widget, gpointer data )
{
call_t * c = (call_t*) call_list_get_by_state (CALL_STATE_CURRENT);
if(c)
if(selectedCall)
{
dbus_hold (c);
switch(selectedCall->state)
{
case CALL_STATE_DIALING:
dbus_place_call (selectedCall);
break;
case CALL_STATE_INCOMING:
dbus_accept (selectedCall);
break;
}
}
}
/**
* Make a call
* Hang up the line
*/
static void
place_call( GtkWidget *widget, gpointer data )
hang_up( GtkWidget *widget, gpointer data )
{
call_t * c = (call_t*) call_list_get_by_state (CALL_STATE_DIALING);
if(c)
if(selectedCall)
{
sflphone_place_call(c);
switch(selectedCall->state)
{
case CALL_STATE_CURRENT:
case CALL_STATE_HOLD:
case CALL_STATE_DIALING:
dbus_hang_up (selectedCall);
break;
case CALL_STATE_INCOMING:
dbus_refuse (selectedCall);
break;
}
}
}
/**
* Hang up the line
* Hold the line
*/
static void
hang_up( GtkWidget *widget, gpointer data )
hold( GtkWidget *widget, gpointer data )
{
call_t * c = (call_t*) call_list_get_by_state (CALL_STATE_CURRENT);
if(c)
if(selectedCall)
{
dbus_hang_up(c);
switch(selectedCall->state)
{
case CALL_STATE_CURRENT:
dbus_hold (selectedCall);
break;
}
}
}
/**
* Transfert the line
*/
......@@ -88,45 +104,63 @@ transfert( GtkWidget *widget, gpointer data )
}
}
/* Call back when the user click on a call in the list */
/**
* Refuse incoming call
*/
static void
selected(GtkTreeSelection *sel, GtkTreeModel *model)
refuse( GtkWidget *widget, gpointer data )
{
GtkTreeIter iter;
GValue val;
if (! gtk_tree_selection_get_selected (sel, &model, &iter))
return;
val.g_type = G_TYPE_POINTER;
gtk_tree_model_get_value (model, &iter, 2, &val);
selectedCall = (call_t*) g_value_get_pointer(&val);
g_value_unset(&val);
if(selectedCall)
{
dbus_refuse(selectedCall);
}
}
/**
* Unhold call
*/
static void
unhold( GtkWidget *widget, gpointer data )
{
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_HOLD:
dbus_unhold (selectedCall);
break;
}
}
}
void
update_buttons ()
{
gtk_widget_set_sensitive( GTK_WIDGET(callButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(hangupButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(holdButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(transfertButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(unholdButton), FALSE);
if(selectedCall)
{
if( selectedCall->state == CALL_STATE_INCOMING)
{
gtk_widget_set_sensitive( GTK_WIDGET(acceptButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(refuseButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(unholdButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(callButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(hangupButton), TRUE);
}
else if( selectedCall->state == CALL_STATE_HOLD)
{
gtk_widget_set_sensitive( GTK_WIDGET(acceptButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(refuseButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(unholdButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(hangupButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(unholdButton), TRUE);
}
else if( selectedCall->state == CALL_STATE_RINGING)
{
gtk_widget_set_sensitive( GTK_WIDGET(hangupButton), TRUE);
}
else if(selectedCall->state == CALL_STATE_DIALING)
{
/*gtk_widget_hide( hangupButton );
gtk_widget_show( callButton );
gtk_widget_set_sensitive( GTK_WIDGET(callButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(hangupButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(holdButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(transfertButton), FALSE);*/
gtk_widget_set_sensitive( GTK_WIDGET(hangupButton), TRUE);
}
else if (selectedCall->state == CALL_STATE_CURRENT)
{
......@@ -136,14 +170,30 @@ selected(GtkTreeSelection *sel, GtkTreeModel *model)
//gtk_box_pack_start (GTK_BOX (hbox), hangupButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
//gtk_box_reorder_child(GTK_BOX (hbox), hangupButton, 0);
gtk_widget_show( hangupButton );
gtk_widget_set_sensitive( GTK_WIDGET(callButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(hangupButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(holdButton), TRUE);
gtk_widget_set_sensitive( GTK_WIDGET(transfertButton), TRUE);
}
}
}
/* Call back when the user click on a call in the list */
static void
selected(GtkTreeSelection *sel, GtkTreeModel *model)
{
GtkTreeIter iter;
GValue val;
if (! gtk_tree_selection_get_selected (sel, &model, &iter))
return;
val.g_type = G_TYPE_POINTER;
gtk_tree_model_get_value (model, &iter, 2, &val);
selectedCall = (call_t*) g_value_get_pointer(&val);
g_value_unset(&val);
update_buttons();
}
/**
......@@ -158,36 +208,13 @@ accept( GtkWidget *widget, gpointer data )
}
}
/**
* Refuse incoming call
*/
static void
refuse( GtkWidget *widget, gpointer data )
{
if(selectedCall)
{
dbus_refuse(selectedCall);
}
}
/**
* Unhold call
*/
static void
unhold( GtkWidget *widget, gpointer data )
{
if(selectedCall)
{
dbus_unhold(selectedCall);
}
}
GtkWidget *
create_call_tree (){
GtkWidget *ret;
GtkWidget *sw;
GtkWidget *hbox;
GtkWidget *view;
GtkWidget *image;
GtkWidget *bbox;
GtkCellRenderer *rend;
......@@ -199,10 +226,9 @@ create_call_tree (){
gtk_container_set_border_width (GTK_CONTAINER (ret), 0);
sw = gtk_scrolled_window_new( NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
gtk_box_pack_start(GTK_BOX(ret), sw, TRUE, TRUE, 0);
store = gtk_list_store_new (3,
GDK_TYPE_PIXBUF,// Icon
G_TYPE_STRING, // Description
......@@ -213,9 +239,6 @@ create_call_tree (){
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
/*g_signal_connect(G_OBJECT(rend), "toggled",
G_CALLBACK(module_toggled), module_store);*/
rend = gtk_cell_renderer_pixbuf_new();
col = gtk_tree_view_column_new_with_attributes ("Icon",
rend,
......@@ -238,163 +261,224 @@ create_call_tree (){
store);
/* Action button */
hbox = gtk_hbutton_box_new ();
gtk_button_box_set_spacing ( hbox, 10);
hbox = gtk_hbox_new (FALSE, 5);
gtk_button_box_set_spacing ( hbox, 5);
gtk_button_box_set_layout ( GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_START);
acceptButton = gtk_button_new_with_label ("Accept");
image = gtk_image_new_from_file( PIXMAPS_DIR "/accept.svg");
gtk_image_set_pixel_size(GTK_IMAGE(image), 16);
gtk_button_set_image(GTK_BUTTON(acceptButton), image);
gtk_widget_set_state( GTK_WIDGET(acceptButton), GTK_STATE_INSENSITIVE);
gtk_box_pack_start (GTK_BOX (hbox), acceptButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
g_signal_connect (G_OBJECT (acceptButton), "clicked",
G_CALLBACK (accept), NULL);
refuseButton = gtk_button_new_with_label ("Refuse");
image = gtk_image_new_from_file( PIXMAPS_DIR "/refuse.svg");
gtk_button_set_image(GTK_BUTTON(refuseButton), image);
gtk_widget_set_state( GTK_WIDGET(refuseButton), GTK_STATE_INSENSITIVE);
gtk_box_pack_start (GTK_BOX (hbox), refuseButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
g_signal_connect (G_OBJECT (refuseButton), "clicked",
G_CALLBACK (refuse), NULL);
unholdButton = gtk_button_new_with_label ("Unhold");
image = gtk_image_new_from_file( PIXMAPS_DIR "/unhold.svg");
gtk_button_set_image(GTK_BUTTON(unholdButton), image);
gtk_widget_set_state( GTK_WIDGET(unholdButton), GTK_STATE_INSENSITIVE);
gtk_box_pack_start (GTK_BOX (hbox), unholdButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
g_signal_connect (G_OBJECT (unholdButton), "clicked",
G_CALLBACK (unhold), NULL);
gtk_box_pack_start (GTK_BOX (ret), hbox, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
/* 2nd row */
hbox = gtk_hbutton_box_new ();
gtk_button_box_set_spacing ( GTK_BUTTON_BOX(hbox), 10);
gtk_button_box_set_layout ( GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_START);
callButton = gtk_button_new_with_label ("Call");
callButton = gtk_button_new ();
gtk_widget_set_state( GTK_WIDGET(callButton), GTK_STATE_INSENSITIVE);
image = gtk_image_new_from_file( PIXMAPS_DIR "/call.svg");
gtk_button_set_image(GTK_BUTTON(callButton), image);
//gtk_button_set_image_position( button, GTK_POS_TOP);
gtk_box_pack_start (GTK_BOX (hbox), callButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
gtk_box_pack_start (GTK_BOX (hbox), callButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
g_signal_connect (G_OBJECT (callButton), "clicked",
G_CALLBACK (place_call), NULL);
G_CALLBACK (call_button), NULL);
hangupButton = gtk_button_new_with_label ("Hang up");
hangupButton = gtk_button_new ();
gtk_widget_hide( hangupButton );
gtk_widget_set_state( GTK_WIDGET(hangupButton), GTK_STATE_INSENSITIVE);
gtk_box_pack_end (GTK_BOX (hbox), hangupButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
gtk_box_pack_start (GTK_BOX (hbox), hangupButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
image = gtk_image_new_from_file( PIXMAPS_DIR "/hang_up.svg");
gtk_button_set_image(GTK_BUTTON(hangupButton), image);
//gtk_button_set_image_position( button, GTK_POS_TOP);
g_signal_connect (G_OBJECT (hangupButton), "clicked",
G_CALLBACK (hang_up), NULL);
holdButton = gtk_button_new_with_label ("Hold");
gtk_widget_set_state( GTK_WIDGET(holdButton), GTK_STATE_INSENSITIVE);
unholdButton = gtk_button_new ();
image = gtk_image_new_from_file( PIXMAPS_DIR "/unhold.svg");
gtk_button_set_image(GTK_BUTTON(unholdButton), image);
gtk_widget_set_state( GTK_WIDGET(unholdButton), GTK_STATE_INSENSITIVE);
gtk_box_pack_end (GTK_BOX (hbox), unholdButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
g_signal_connect (G_OBJECT (unholdButton), "clicked",
G_CALLBACK (unhold), NULL);
holdButton = gtk_button_new ();
image = gtk_image_new_from_file( PIXMAPS_DIR "/hold.svg");
gtk_box_pack_end (GTK_BOX (hbox), holdButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
gtk_button_set_image(GTK_BUTTON(holdButton), image);
gtk_widget_set_state( GTK_WIDGET(holdButton), GTK_STATE_INSENSITIVE);
gtk_box_pack_end (GTK_BOX (hbox), holdButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
g_signal_connect (G_OBJECT (holdButton), "clicked",
G_CALLBACK (hold), NULL);
transfertButton = gtk_button_new_with_label ("Transfert");
gtk_widget_set_state( GTK_WIDGET(transfertButton), GTK_STATE_INSENSITIVE);
transfertButton = gtk_button_new ();
image = gtk_image_new_from_file( PIXMAPS_DIR "/transfert.svg");
gtk_button_set_image(GTK_BUTTON(transfertButton), image);
gtk_box_pack_end (GTK_BOX (hbox), transfertButton, TRUE /*expand*/, TRUE /*fill*/, 10 /*padding*/);
gtk_widget_set_state( GTK_WIDGET(transfertButton), GTK_STATE_INSENSITIVE);
gtk_box_pack_end (GTK_BOX (hbox), transfertButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
g_signal_connect (G_OBJECT (transfertButton), "clicked",
G_CALLBACK (transfert), NULL);
gtk_box_pack_start (GTK_BOX (ret), hbox, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
gtk_box_pack_start (GTK_BOX (ret), hbox, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
gtk_box_pack_start(GTK_BOX(ret), sw, TRUE, TRUE, 0);
gtk_widget_show(ret);
return ret;
}
void
update_call_tree ()
update_call_tree_remove (call_t * c)
{
GdkPixbuf *pixbuf;
GtkTreeIter iter;
GValue val;
call_t * iterCall;
val.g_type = G_TYPE_POINTER;
gtk_tree_model_get_value (GTK_TREE_MODEL(store), &iter, 2, &val);
iterCall = (call_t*) g_value_get_pointer(&val);
g_value_unset(&val);
int nbChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
int i;
for( i = 0; i < nbChild; i++)
{
if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, i))
{
val.g_type = G_TYPE_POINTER;
gtk_tree_model_get_value (GTK_TREE_MODEL(store), &iter, 2, &val);
iterCall = (call_t*) g_value_get_pointer(&val);
g_value_unset(&val);
if(iterCall == c)
{
gtk_list_store_remove(store, &iter);
}
}
}
if(selectedCall == c)
selectedCall = NULL;
update_buttons();
}
gtk_list_store_clear(store);
void
update_call_tree (call_t * c)
{
GdkPixbuf *pixbuf;
GtkTreeIter iter;
GValue val;
call_t * iterCall;
val.g_type = G_TYPE_POINTER;
gtk_tree_model_get_value (GTK_TREE_MODEL(store), &iter, 2, &val);
iterCall = (call_t*) g_value_get_pointer(&val);
g_value_unset(&val);
int nbChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
int i;
for( i = 0; i < call_list_get_size(); i++)
for( i = 0; i < nbChild; i++)
{
call_t * c = call_list_get_nth (i);
if (c)
{
gchar * markup;
if (c->state == CALL_STATE_CURRENT)
{
markup = g_markup_printf_escaped("<big><b>%s</b></big>\n"
"%s",
call_get_name(c),
call_get_number(c));
}
else
{
markup = g_markup_printf_escaped("<b>%s</b>\n"
"%s",
call_get_name(c),
call_get_number(c));
}
gtk_list_store_append (store, &iter);
if (c->state == CALL_STATE_HOLD)
{
pixbuf = gdk_pixbuf_new_from_file(PIXMAPS_DIR "/hold.svg", NULL);
}
else if (c->state == CALL_STATE_INCOMING)
{
pixbuf = gdk_pixbuf_new_from_file(PIXMAPS_DIR "/ring.svg", NULL);
}
else if (c->state == CALL_STATE_CURRENT)
{
pixbuf = gdk_pixbuf_new_from_file(PIXMAPS_DIR "/current.svg", NULL);
}
else if (c->state == CALL_STATE_DIALING)
{
pixbuf = gdk_pixbuf_new_from_file(PIXMAPS_DIR "/dial.svg", NULL);
}
//Resize it