calltree.c 16.1 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
2
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
3
 *  Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info>
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
5
6
7
 *                                                                              
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
9
10
11
12
13
14
15
16
17
18
19
20
21
 *  (at your option) any later version.
 *                                                                                
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *                                                                              
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtk.h>
22
#include <actions.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
23
24
#include <calltree.h>
#include <calllist.h>
25
#include <menus.h>
26
#include <dbus.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
27
28

GtkListStore * store;
29
30
GtkWidget *view;

31

32
GtkWidget   * toolbar;
Emmanuel Milou's avatar
Emmanuel Milou committed
33
GtkToolItem * pickupButton;
34
35
36
37
38
GtkToolItem * callButton;
GtkToolItem * hangupButton;
GtkToolItem * holdButton;
GtkToolItem * transfertButton;
GtkToolItem * unholdButton;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
39
guint transfertButtonConnId; //The button toggled signal connection ID
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
40

41

42
43
44
/**
 * Show popup menu
 */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
45
static gboolean            
46
47
48
49
50
51
52
popup_menu (GtkWidget *widget,
            gpointer   user_data)
{
  show_popup_menu(widget, NULL);
  return TRUE;
}            
            
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
53
54
55
56
57
58
59
60
61
62
static gboolean
button_pressed(GtkWidget* widget, GdkEventButton *event, gpointer user_data)
{
  if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
  {
    show_popup_menu(widget,  event);
    return TRUE;
  }
  return FALSE;
}
63
/**
64
 * Make a call
65
 */
66
	static void 
67
call_button( GtkWidget *widget, gpointer   data )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
68
{
Emmanuel Milou's avatar
Emmanuel Milou committed
69
70
71
72
	if(call_list_get_size()>0)
		sflphone_pick_up();
	else
		sflphone_new_call();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
73
74
75
76
}

/**
 * Pick up
77
*/
78
/*	static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
79
pick_up( GtkWidget *widget, gpointer   data )
80
{
81
	sflphone_pick_up();
82
}*/
83
84

/**
85
 * Hang up the line
86
 */
87
	static void 
88
hang_up( GtkWidget *widget, gpointer   data )
89
{
90
	sflphone_hang_up();
91
92
93
}

/**
94
 * Hold the line
95
 */
96
	static void 
97
hold( GtkWidget *widget, gpointer   data )
98
{
99
	sflphone_on_hold();
100
101
102
103
104
}

/**
 * Transfert the line
 */
105
	static void 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
106
transfert  (GtkToggleToolButton *toggle_tool_button,
107
		gpointer             user_data)
108
{
109
110
111
112
113
114
115
116
117
	gboolean up = gtk_toggle_tool_button_get_active(toggle_tool_button);
	if(up)
	{
		sflphone_set_transfert();
	}
	else
	{
		sflphone_unset_transfert();
	}
118
119
}

120
121
122
/**
 * Unhold call
 */
123
	static void 
124
125
unhold( GtkWidget *widget, gpointer   data )
{
126
	sflphone_off_hold();
127
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
128

129
	void 
130
toolbar_update_buttons ()
131
{
132

133
134
135
136
137
138
139
140
141
142
	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);
	g_object_ref(holdButton);
	g_object_ref(unholdButton);
	gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(holdButton));
	gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(unholdButton));
	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), holdButton, 3);
Emmanuel Milou's avatar
Emmanuel Milou committed
143
144
145
146
147
	g_object_ref(callButton);
	g_object_ref(pickupButton);
	gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(callButton));
        gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(pickupButton));
        gtk_toolbar_insert(GTK_TOOLBAR(toolbar), callButton, 0);
148
	
149

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
150
	gtk_signal_handler_block(GTK_OBJECT(transfertButton),transfertButtonConnId);
151
152
153
	gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(transfertButton), FALSE);
	gtk_signal_handler_unblock(transfertButton, transfertButtonConnId);

154
	call_t * selectedCall = call_get_selected();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
155
	if (selectedCall)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
156
	{
157
158
159
		switch(selectedCall->state) 
		{
			case CALL_STATE_INCOMING:
Emmanuel Milou's avatar
Emmanuel Milou committed
160
				gtk_widget_set_sensitive( GTK_WIDGET(pickupButton),     TRUE);
161
				gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),	TRUE);
Emmanuel Milou's avatar
Emmanuel Milou committed
162
				g_object_ref(callButton);	
Emmanuel Milou's avatar
Emmanuel Milou committed
163
				gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(callButton));
Emmanuel Milou's avatar
Emmanuel Milou committed
164
				gtk_toolbar_insert(GTK_TOOLBAR(toolbar), pickupButton, 0);
165
166
167
168
169
170
171
172
173
174
175
				break;
			case CALL_STATE_HOLD:
				gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(unholdButton),     TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
				g_object_ref(holdButton);
				gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(holdButton));
				gtk_toolbar_insert(GTK_TOOLBAR(toolbar), unholdButton, 3);
				break;
			case CALL_STATE_RINGING:
				gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
176
				gtk_widget_set_sensitive( GTK_WIDGET(callButton),     TRUE);
177
178
179
				break;
			case CALL_STATE_DIALING:
				gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
Emmanuel Milou's avatar
Emmanuel Milou committed
180
181
182
183
184
				//gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(pickupButton),       TRUE);
				g_object_ref(callButton);
				gtk_container_remove(GTK_CONTAINER(toolbar), GTK_WIDGET(callButton));
				gtk_toolbar_insert(GTK_TOOLBAR(toolbar), pickupButton, 0);
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
				break;
			case CALL_STATE_CURRENT:
				gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(holdButton),       TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(transfertButton),  TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
				break;
			case CALL_STATE_BUSY:
			case CALL_STATE_FAILURE:
				gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
				break; 
			case CALL_STATE_TRANSFERT:
				gtk_signal_handler_block(GTK_OBJECT(transfertButton),transfertButtonConnId);
				gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(transfertButton), TRUE);
				gtk_signal_handler_unblock(transfertButton, transfertButtonConnId);
				gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(holdButton),       TRUE);
				gtk_widget_set_sensitive( GTK_WIDGET(transfertButton),  TRUE);
				break;
			default:
				g_warning("Should not happen!");
				break;
		}
	}
	else 
	{
		if( account_list_get_size() > 0 )
		{
			gtk_widget_set_sensitive( GTK_WIDGET(callButton), TRUE);
		}
		else
		{
			gtk_widget_set_sensitive( GTK_WIDGET(callButton), FALSE);
		}
	}
221
222
}
/* Call back when the user click on a call in the list */
223
	static void 
224
225
226
227
selected(GtkTreeSelection *sel, GtkTreeModel *model) 
{
	GtkTreeIter  iter;
	GValue val;
228

229
230
	if (! gtk_tree_selection_get_selected (sel, &model, &iter))
		return;
231

232
	val.g_type = 0;
233
	gtk_tree_model_get_value (model, &iter, 2, &val);
234

235
	call_select((call_t*) g_value_get_pointer(&val));
236
237
238
	g_value_unset(&val);

	toolbar_update_buttons();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
239
240
}

241
242
/* A row is activated when it is double clicked */
void  row_activated(GtkTreeView       *tree_view,
243
244
245
		GtkTreePath       *path,
		GtkTreeViewColumn *column,
		void * foo) 
246
{
247
	call_t * selectedCall = call_get_selected();
248
249
	if (selectedCall)
	{
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
		switch(selectedCall->state)  
		{
			case CALL_STATE_INCOMING:
				dbus_accept(selectedCall);
				break;
			case CALL_STATE_HOLD:
				dbus_unhold(selectedCall);
				break;
			case CALL_STATE_RINGING:
			case CALL_STATE_CURRENT:
			case CALL_STATE_BUSY:
			case CALL_STATE_FAILURE:
				break;
			case CALL_STATE_DIALING:
				sflphone_place_call (selectedCall);
				break;
			default:
				g_warning("Should not happen!");
				break;
		}
	}
271
}                  
272

273
274
275

GtkWidget * 
create_toolbar (){
276
277
278
279
280
	GtkWidget *ret;
	GtkWidget *image;

	ret = gtk_toolbar_new();
	toolbar = ret;
Emmanuel Milou's avatar
Emmanuel Milou committed
281
282
	
	gtk_toolbar_set_orientation(GTK_TOOLBAR(ret), GTK_ORIENTATION_HORIZONTAL);
283
	gtk_toolbar_set_style(GTK_TOOLBAR(ret), GTK_TOOLBAR_ICONS);
284
285

	image = gtk_image_new_from_file( ICONS_DIR "/call.svg");
Emmanuel Milou's avatar
Emmanuel Milou committed
286
	callButton = gtk_tool_button_new (image, "Place a Call");
287
	gtk_widget_set_tooltip_text(GTK_WIDGET(callButton), "Place a call");
288
289
	g_signal_connect (G_OBJECT (callButton), "clicked",
			G_CALLBACK (call_button), NULL);
290
	gtk_toolbar_insert(GTK_TOOLBAR(ret), GTK_TOOL_ITEM(callButton), -1);
291
292

	image = gtk_image_new_from_file( ICONS_DIR "/accept.svg");
Emmanuel Milou's avatar
Emmanuel Milou committed
293
	pickupButton = gtk_tool_button_new(image, "Pick up");
294
	gtk_widget_set_tooltip_text(GTK_WIDGET(pickupButton), "Pick up");
Emmanuel Milou's avatar
Emmanuel Milou committed
295
296
297
298
	gtk_widget_set_state( GTK_WIDGET(pickupButton), GTK_STATE_INSENSITIVE);
	g_signal_connect(G_OBJECT (pickupButton), "clicked", 
			G_CALLBACK (call_button), NULL);
	gtk_widget_show_all(GTK_WIDGET(pickupButton));
299
300
301

	image = gtk_image_new_from_file( ICONS_DIR "/hang_up.svg");
	hangupButton = gtk_tool_button_new (image, "Hang up");
302
	gtk_widget_set_tooltip_text(GTK_WIDGET(hangupButton), "Hang up");
303
304
305
306
307
308
309
	gtk_widget_set_state( GTK_WIDGET(hangupButton), GTK_STATE_INSENSITIVE);
	g_signal_connect (G_OBJECT (hangupButton), "clicked",
			G_CALLBACK (hang_up), NULL);
	gtk_toolbar_insert(GTK_TOOLBAR(ret), GTK_TOOL_ITEM(hangupButton), -1);  

	image = gtk_image_new_from_file( ICONS_DIR "/unhold.svg");
	unholdButton = gtk_tool_button_new (image, "Off Hold");
310
	gtk_widget_set_tooltip_text(GTK_WIDGET(unholdButton), "Off Hold");
311
312
313
314
315
316
317
	gtk_widget_set_state( GTK_WIDGET(unholdButton), GTK_STATE_INSENSITIVE);
	g_signal_connect (G_OBJECT (unholdButton), "clicked",
			G_CALLBACK (unhold), NULL);
	gtk_widget_show_all(GTK_WIDGET(unholdButton));

	image = gtk_image_new_from_file( ICONS_DIR "/hold.svg");
	holdButton =  gtk_tool_button_new (image, "On Hold");
318
	gtk_widget_set_tooltip_text(GTK_WIDGET(holdButton), "On Hold");
319
320
321
	gtk_widget_set_state( GTK_WIDGET(holdButton), GTK_STATE_INSENSITIVE);
	g_signal_connect (G_OBJECT (holdButton), "clicked",
			G_CALLBACK (hold), NULL);
322
	gtk_toolbar_insert(GTK_TOOLBAR(ret), GTK_TOOL_ITEM(holdButton), -1);
323
324
325
326

	image = gtk_image_new_from_file( ICONS_DIR "/transfert.svg");
	transfertButton = gtk_toggle_tool_button_new ();
	gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(transfertButton), image);
327
	gtk_widget_set_tooltip_text(GTK_WIDGET(transfertButton), "Transfer");
328
	gtk_tool_button_set_label(GTK_TOOL_BUTTON(transfertButton), "Transfer");
329
330
331
332
333
334
	gtk_widget_set_state( GTK_WIDGET(transfertButton), GTK_STATE_INSENSITIVE);
	transfertButtonConnId = g_signal_connect (G_OBJECT (transfertButton), "toggled",
			G_CALLBACK (transfert), NULL);
	gtk_toolbar_insert(GTK_TOOLBAR(ret), GTK_TOOL_ITEM(transfertButton), -1);  

	return ret;
335
336

}  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
337
338
339

GtkWidget * 
create_call_tree (){
340
	GtkWidget *ret;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
341
342
343
344
	GtkWidget *sw;
	GtkCellRenderer *rend;
	GtkTreeViewColumn *col;
	GtkTreeSelection *sel;
345

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
346
347
348
349
	ret = gtk_vbox_new(FALSE, 10); 
	gtk_container_set_border_width (GTK_CONTAINER (ret), 0);

	sw = gtk_scrolled_window_new( NULL, NULL);
350
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
351
352
353
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);

	store = gtk_list_store_new (3, 
354
355
356
357
			GDK_TYPE_PIXBUF,// Icon 
			G_TYPE_STRING,  // Description
			G_TYPE_POINTER  // Pointer to the Object
			);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
358
359

	view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store));
360
361
362
363
364
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
	g_signal_connect (G_OBJECT (view), "row-activated",
			G_CALLBACK (row_activated),
			NULL);

365
366
367
368
  // Connect the popup menu
	g_signal_connect (G_OBJECT (view), "popup-menu",
			G_CALLBACK (popup_menu), 
			NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
369
370
371
	g_signal_connect (G_OBJECT (view), "button-press-event",
			G_CALLBACK (button_pressed), 
			NULL);
372

373
374
375
376
377
	rend = gtk_cell_renderer_pixbuf_new();
	col = gtk_tree_view_column_new_with_attributes ("Icon",
			rend,
			"pixbuf", 0,
			NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
378
379
380
381
	gtk_tree_view_append_column (GTK_TREE_VIEW(view), col);

	rend = gtk_cell_renderer_text_new();
	col = gtk_tree_view_column_new_with_attributes ("Description",
382
383
384
			rend,
			"markup", 1,
			NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
385
386
387
388
	gtk_tree_view_append_column (GTK_TREE_VIEW(view), col);
	g_object_unref(G_OBJECT(store));
	gtk_container_add(GTK_CONTAINER(sw), view);

389
390
391
392
393
394
395
	sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
	g_signal_connect (G_OBJECT (sel), "changed",
			G_CALLBACK (selected),
			store);

	gtk_box_pack_start(GTK_BOX(ret), sw, TRUE, TRUE, 0);

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
396
	gtk_widget_show(ret); 
397

398
	toolbar_update_buttons();
399

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
400
	return ret;
401

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
402
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
403
404

void 
405
update_call_tree_remove (call_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
406
407
{
	GtkTreeIter iter;
408
409
	GValue val;
	call_t * iterCall;
410

411
	int nbChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
412
	int i;
413
414
	for( i = 0; i < nbChild; i++)
	{
415
416
417
418
419
420
421
422
423
424
425
426
427
		if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, i))
		{
			val.g_type = 0;
			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);
			}
		}
428
	}
429
	call_t * selectedCall = call_get_selected();
430
	if(selectedCall == c)
431
		call_select(NULL);
432
	toolbar_update_buttons();
433
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
434

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
435
void 
436
437
update_call_tree (call_t * c)
{
438
439
	GdkPixbuf *pixbuf;
	GtkTreeIter iter;
440
441
	GValue val;
	call_t * iterCall;
442

443
	int nbChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
444
	int i;
445
	for( i = 0; i < nbChild; i++)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
446
	{
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
		if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, i))
		{
			val.g_type = 0;
			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)
			{
				// Existing call in the list
				gchar * markup;
				if(c->state == CALL_STATE_TRANSFERT)
				{
					markup = g_markup_printf_escaped("<b>%s</b>\n"
							"%s\n<i>Transfert to:</i> %s",  
							call_get_name(c), 
							call_get_number(c), 
							c->to);
				}
				else
				{
					markup = g_markup_printf_escaped("<b>%s</b>\n"
							"%s", 
							call_get_name(c), 
							call_get_number(c));
				}


				switch(c->state)
				{
					case CALL_STATE_HOLD:
						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/hold.svg", NULL);
						break;
					case CALL_STATE_RINGING:
						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/ring.svg", NULL);
						break;
					case CALL_STATE_CURRENT:
						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);
						break;
					case CALL_STATE_FAILURE:
						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/fail.svg", NULL);
						break;
					case CALL_STATE_BUSY:
						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/busy.svg", NULL);
						break;
					case CALL_STATE_TRANSFERT:
						pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/transfert.svg", NULL);
						break;
					default:
						g_warning("Should not happen!");
				}
				//Resize it
				if(pixbuf)
				{
					if(gdk_pixbuf_get_width(pixbuf) > 32 || gdk_pixbuf_get_height(pixbuf) > 32)
					{
						pixbuf =  gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_BILINEAR);
					}
				}
				gtk_list_store_set(store, &iter,
						0, pixbuf, // Icon
						1, markup, // Description
						-1);

				if (pixbuf != NULL)
					g_object_unref(G_OBJECT(pixbuf));

			} 
		}

	} 
	toolbar_update_buttons();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
523
	//return row_ref;
524
525
526

}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
527
void 
528
529
update_call_tree_add (call_t * c)
{
530
	GdkPixbuf *pixbuf;
531
	GtkTreeIter iter;
532
	GtkTreeSelection* sel;
533

534
535
536
537
538
539
540
541
	// New call in the list
	gchar * markup;
	markup = g_markup_printf_escaped("<b>%s</b>\n"
			"%s", 
			call_get_name(c), 
			call_get_number(c));

	gtk_list_store_append (store, &iter);
542

543
	switch(c->state)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
544
545
	{
		case CALL_STATE_INCOMING:
546
547
			pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/ring.svg", NULL);
			break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
548
		case CALL_STATE_DIALING:
549
550
			pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/dial.svg", NULL);
			break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
551
		case CALL_STATE_RINGING:
552
553
			pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/ring.svg", NULL);
			break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
554
		default:
555
			g_warning("Should not happen!");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
556
	}
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578

	//Resize it
	if(pixbuf)
	{
		if(gdk_pixbuf_get_width(pixbuf) > 32 || gdk_pixbuf_get_height(pixbuf) > 32)
		{
			pixbuf =  gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_BILINEAR);
		}
	}
	gtk_list_store_set(store, &iter,
			0, pixbuf, // Icon
			1, markup, // Description
			2, c,      // Pointer
			-1);

	if (pixbuf != NULL)
		g_object_unref(G_OBJECT(pixbuf));

	//g_free(markup);
	sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
	gtk_tree_selection_select_iter(GTK_TREE_SELECTION(sel), &iter);
	toolbar_update_buttons();
579
	//return row_ref;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
580
}