calltree.c 14.1 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
 *                                                                              
 *  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
 *  the Free Software Foundation; either version 2 of the License, or
 *  (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>
21
#include <actions.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
22
23
#include <calltree.h>
#include <calllist.h>
24
#include <dbus.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
25
26

GtkListStore * store;
27
28
GtkWidget *view;

29
GtkWidget * callButton;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
30
GtkWidget * pickupButton;
31
GtkWidget * hangupButton;
32
GtkWidget * holdButton;
33
GtkWidget * transfertButton;
34
GtkWidget * unholdButton;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
35

36
/**
37
 * Make a call
38
39
 */
static void 
40
call_button( GtkWidget *widget, gpointer   data )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
41
42
43
44
45
46
47
48
49
{
  sflphone_new_call();
}

/**
 * Pick up
 */
static void 
pick_up( GtkWidget *widget, gpointer   data )
50
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
51
  sflphone_pick_up();
52
53
54
}

/**
55
 * Hang up the line
56
57
 */
static void 
58
hang_up( GtkWidget *widget, gpointer   data )
59
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
60
  sflphone_hang_up();
61
62
63
}

/**
64
 * Hold the line
65
66
 */
static void 
67
hold( GtkWidget *widget, gpointer   data )
68
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
69
  sflphone_on_hold();
70
71
72
73
74
75
76
77
}

/**
 * Transfert the line
 */
static void 
transfert( GtkWidget *widget, gpointer   data )
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
78
  sflphone_set_transfert();
79
80
}

81
82
83
84
85
86
/**
 * Unhold call
 */
static void 
unhold( GtkWidget *widget, gpointer   data )
{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
87
  sflphone_off_hold();
88
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
89

90
91
92
93
void 
update_buttons ()
{
  gtk_widget_set_sensitive( GTK_WIDGET(callButton),       FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
94
  gtk_widget_set_sensitive( GTK_WIDGET(pickupButton),     FALSE);
95
96
97
98
  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);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
99
	
100
	call_t * selectedCall = call_get_selected();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
101
	if (selectedCall)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
102
	{
103
    switch(selectedCall->state) 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
104
105
  	{
  	  case CALL_STATE_INCOMING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
106
        gtk_widget_set_sensitive( GTK_WIDGET(pickupButton),     TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
107
108
109
110
111
        gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
        break;
      case CALL_STATE_HOLD:
    	  gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(unholdButton),     TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
112
        gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
113
114
115
116
117
        break;
      case CALL_STATE_RINGING:
    	  gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
        break;
      case CALL_STATE_DIALING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
118
        gtk_widget_set_sensitive( GTK_WIDGET(pickupButton),     TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
119
        gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
120
        gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
121
122
123
124
125
126
        break;
      case CALL_STATE_CURRENT:
        gtk_widget_show( hangupButton );
        gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(holdButton),       TRUE);
        gtk_widget_set_sensitive( GTK_WIDGET(transfertButton),  TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
127
        gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
128
129
130
131
132
133
        break;
      case CALL_STATE_BUSY:
      case CALL_STATE_FAILURE:
        gtk_widget_set_sensitive( GTK_WIDGET(hangupButton),     TRUE);
        break; 
  	  default:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
134
  	    g_warning("Should not happen!");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
135
136
137
  	    break;
  	}
  }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
138
139
140
141
  else 
  {
    gtk_widget_set_sensitive( GTK_WIDGET(callButton),       TRUE);
  }
142
143
144
145
146
147
148
149
150
151
152
}
/* 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;
  
153
	val.g_type = 0;
154
155
	gtk_tree_model_get_value (model, &iter, 2, &val);
	
156
	call_select((call_t*) g_value_get_pointer(&val));
157
  g_value_unset(&val);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
158
  
159
  update_buttons();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
160
161
}

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* A row is activated when it is double clicked */
void  row_activated(GtkTreeView       *tree_view,
                    GtkTreePath       *path,
                    GtkTreeViewColumn *column,
                    void * foo) 
{
  call_t * selectedCall = call_get_selected();
	if (selectedCall)
	{
    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:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
188
  	    g_warning("Should not happen!");
189
190
191
192
  	    break;
  	}
  }
}                    
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
193
194
195
196
197
198
199
200
201
202

GtkWidget * 
create_call_tree (){
  GtkWidget *ret;
	GtkWidget *sw;
  GtkWidget *hbox;
	GtkWidget *image;
	GtkCellRenderer *rend;
	GtkTreeViewColumn *col;
	GtkTreeSelection *sel;
203
	
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
204
205
206
207
	ret = gtk_vbox_new(FALSE, 10); 
	gtk_container_set_border_width (GTK_CONTAINER (ret), 0);

	sw = gtk_scrolled_window_new( NULL, NULL);
208
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
209
210
211
212
213
214
215
216
217
218
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);

	store = gtk_list_store_new (3, 
	  GDK_TYPE_PIXBUF,// Icon 
	  G_TYPE_STRING,  // Description
	  G_TYPE_POINTER  // Pointer to the Object
	  );


	view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store));
219
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
220
221
222
  g_signal_connect (G_OBJECT (view), "row-activated",
			  G_CALLBACK (row_activated),
			  NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
	
  rend = gtk_cell_renderer_pixbuf_new();
  col = gtk_tree_view_column_new_with_attributes ("Icon",
							rend,
							"pixbuf", 0,
							NULL);
	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",
							rend,
							"markup", 1,
							NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW(view), col);
	g_object_unref(G_OBJECT(store));
	gtk_container_add(GTK_CONTAINER(sw), view);

  sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
  g_signal_connect (G_OBJECT (sel), "changed",
			  G_CALLBACK (selected),
			  store);
  
  /* Action button */     
246
  hbox = gtk_hbox_new (FALSE, 5);       
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
247
  
248
  callButton = gtk_button_new ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
249
  image = gtk_image_new_from_file( ICONS_DIR "/call.svg");
250
251
  gtk_button_set_image(GTK_BUTTON(callButton), image);
  //gtk_button_set_image_position( button, GTK_POS_TOP);
252
  gtk_box_pack_start (GTK_BOX (hbox), callButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
253
  g_signal_connect (G_OBJECT (callButton), "clicked",
254
                    G_CALLBACK (call_button), NULL);
255

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
256
257
258
259
260
261
262
263
264
  pickupButton = gtk_button_new ();
  gtk_widget_set_state( GTK_WIDGET(pickupButton), GTK_STATE_INSENSITIVE);
  image = gtk_image_new_from_file( ICONS_DIR "/accept.svg");
  gtk_button_set_image(GTK_BUTTON(pickupButton), image);
  //gtk_button_set_image_position( button, GTK_POS_TOP);
  gtk_box_pack_start (GTK_BOX (hbox), pickupButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
  g_signal_connect (G_OBJECT (pickupButton), "clicked",
                    G_CALLBACK (pick_up), NULL);
  
265
  hangupButton = gtk_button_new ();
266
267
  gtk_widget_hide( hangupButton );
  gtk_widget_set_state( GTK_WIDGET(hangupButton), GTK_STATE_INSENSITIVE);
268
  gtk_box_pack_start (GTK_BOX (hbox), hangupButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
269
  image = gtk_image_new_from_file( ICONS_DIR "/hang_up.svg");
270
271
272
273
  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);
274
275
                      
  unholdButton = gtk_button_new ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
276
  image = gtk_image_new_from_file( ICONS_DIR "/unhold.svg");
277
278
279
280
281
282
283
  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 ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
284
  image = gtk_image_new_from_file( ICONS_DIR "/hold.svg");
285
  gtk_button_set_image(GTK_BUTTON(holdButton), image);
286
287
  gtk_widget_set_state( GTK_WIDGET(holdButton), GTK_STATE_INSENSITIVE);
  gtk_box_pack_end (GTK_BOX (hbox), holdButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
288
289
290
  g_signal_connect (G_OBJECT (holdButton), "clicked",
                    G_CALLBACK (hold), NULL);

291
  transfertButton = gtk_button_new ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
292
  image = gtk_image_new_from_file( ICONS_DIR "/transfert.svg");
293
  gtk_button_set_image(GTK_BUTTON(transfertButton), image);
294
295
  gtk_widget_set_state( GTK_WIDGET(transfertButton), GTK_STATE_INSENSITIVE);
  gtk_box_pack_end (GTK_BOX (hbox), transfertButton, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/);
296
297
  g_signal_connect (G_OBJECT (transfertButton), "clicked",
                    G_CALLBACK (transfert), NULL);
298
299
300
301
                    
  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);
	
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
302
303
304
305
306
307
	gtk_widget_show(ret); 
	
	return ret;
	
}
void 
308
update_call_tree_remove (call_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
309
310
{
	GtkTreeIter iter;
311
312
	GValue val;
	call_t * iterCall;
313
 
314
315
316
317
318
319
	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))
	  {
320
	    val.g_type = 0;
321
322
323
324
325
326
327
328
329
330
331
    	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);
      }
	  }
	}
332
	call_t * selectedCall = call_get_selected();
333
	if(selectedCall == c)
334
	  call_select(NULL);
335
336
	update_buttons();
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
337

338
339
340
341
342
343
344
345
346
void 
update_call_tree (call_t * c)
{
  GdkPixbuf *pixbuf;
  GtkTreeIter iter;
	GValue val;
	call_t * iterCall;
	
	int nbChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
347
  int i;
348
	for( i = 0; i < nbChild; i++)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
349
	{
350
351
	  if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, i))
	  {
352
	    val.g_type = 0;
353
354
355
356
357
358
    	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)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
359
      {
360
361
        // Existing call in the list
        gchar * markup;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
362
363
364
365
366
367
368
369
370
371
372
        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"
373
374
375
    						    "%s", 
    						    call_get_name(c), 
    						    call_get_number(c));
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
376
377
        }
        
378
    		    		
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
379
    		switch(c->state)
380
    		{
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
381
      		case CALL_STATE_HOLD:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
382
      		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/hold.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
383
384
      		  break;
      		case CALL_STATE_RINGING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
385
      		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/ring.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
386
387
      		  break;
      		case CALL_STATE_CURRENT:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
388
      		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/current.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
389
390
      		  break;
      		case CALL_STATE_DIALING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
391
      		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/dial.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
392
393
      		  break;
      		case CALL_STATE_FAILURE:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
394
      		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/fail.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
395
396
      		  break;
      		case CALL_STATE_BUSY:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
397
      		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/busy.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
398
      		  break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
399
400
401
      		case CALL_STATE_TRANSFERT:
      		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/transfert.svg", NULL);
      		  break;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
402
      		default:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
403
      		  g_warning("Should not happen!");
404
    		}
405
406
    	  //Resize it
        if(pixbuf)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
407
        {
408
409
410
411
          if(gdk_pixbuf_get_width(pixbuf) > 32 || gdk_pixbuf_get_height(pixbuf) > 32)
          {
            pixbuf =  gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_BILINEAR);
          }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
412
        }
413
    		gtk_list_store_set(store, &iter,
414
415
416
    				  0, pixbuf, // Icon
  		        1, markup, // Description
  		        -1);
417
418
419
420
421
422
    				   
    		if (pixbuf != NULL)
    			g_object_unref(G_OBJECT(pixbuf));
        
      } 
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
423
424
    
  } 
425
  update_buttons();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
426
	//return row_ref;
427
428
429
430
431
432
433
434

}

void 
update_call_tree_add (call_t * c)
{
  GdkPixbuf *pixbuf;
	GtkTreeIter iter;
435
	GtkTreeSelection* sel;
436
437
438

  // New call in the list
  gchar * markup;
439
  markup = g_markup_printf_escaped("<b>%s</b>\n"
440
441
442
  				    "%s", 
  				    call_get_name(c), 
  				    call_get_number(c));
443
  
444
445
  gtk_list_store_append (store, &iter);

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
446
447
448
  switch(c->state)
	{
		case CALL_STATE_INCOMING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
449
		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/ring.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
450
451
		  break;
		case CALL_STATE_DIALING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
452
		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/dial.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
453
454
		  break;
		case CALL_STATE_RINGING:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
455
		  pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/ring.svg", NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
456
457
		  break;
		default:
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
458
		  g_warning("Should not happen!");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
459
460
	}
	
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
  //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);
479
480
  sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
  gtk_tree_selection_select_iter(GTK_TREE_SELECTION(sel), &iter);
481
  update_buttons();
482
	//return row_ref;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
483
}