calltree.c 12.3 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
21
22
23
24
25
26
27
/*
 *  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>
#include <calltree.h>
#include <calllist.h>

GtkListStore * store;
GtkWidget * acceptButton;
GtkWidget * refuseButton;
GtkWidget * unholdButton;
28
29
30
31
GtkWidget * holdButton;
GtkWidget * callButton;
GtkWidget * hangupButton;
GtkWidget * transfertButton;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
32
33
34

call_t * selectedCall;

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

/**
 * Hold the line
 */
static void 
hold( GtkWidget *widget, gpointer   data )
{
  call_t * c = (call_t*) call_list_get_by_state (CALL_STATE_CURRENT);
  if(c)
  {
    dbus_hold (c);
  }
  
  
}

/**
 * Make a call
 */
static void 
place_call( GtkWidget *widget, gpointer   data )
{
  call_t * c = (call_t*) call_list_get_by_state (CALL_STATE_DIALING);
  if(c)
  {
    sflphone_place_call(c);
  }
}

/**
 * Hang up the line
 */
static void 
hang_up( GtkWidget *widget, gpointer   data )
{
  call_t * c = (call_t*) call_list_get_by_state (CALL_STATE_CURRENT);
  if(c)
  {
    dbus_hang_up(c);
  }
}


/**
 * Transfert the line
 */
static void 
transfert( GtkWidget *widget, gpointer   data )
{
  call_t * c = (call_t*) call_list_get_by_state (CALL_STATE_CURRENT);
  if(c)
  {
    dbus_transfert(c,"124");
  }
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* 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);
	
	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);
      
    }
    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);
    }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    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);*/
    }
    else if (selectedCall->state == CALL_STATE_CURRENT)
    {
      //gtk_widget_hide( callButton  );
      /* Hack : if hangupButton is put on the window in create_screen()
       * the hbox will request space for 4 buttons making the window larger than needed */
      //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);
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
	  
	}
  
}

/**
 * Accept incoming call
 */
static void 
accept( GtkWidget *widget, gpointer   data )
{
  if(selectedCall)
  {
    dbus_accept(selectedCall);
  }
}

/**
 * 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;
	GtkTreeViewColumn *col;
	GtkTreeSelection *sel;
	GtkTargetEntry te[2] = {{"text/uri-list", 0, 1},{"STRING", 0, 2}};

	ret = gtk_vbox_new(FALSE, 10); 
	gtk_container_set_border_width (GTK_CONTAINER (ret), 0);

	sw = gtk_scrolled_window_new( NULL, NULL);
202
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
203
204
205
206
207
208
209
210
211
212
213
	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
	  G_TYPE_POINTER  // Pointer to the Object
	  );


	view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store));
214
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
	
	/*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,
							"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 */     
  hbox = gtk_hbutton_box_new ();       
  gtk_button_box_set_spacing ( hbox, 10);
  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);
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
                    
  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");
  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*/);
  g_signal_connect (G_OBJECT (callButton), "clicked",
                    G_CALLBACK (place_call), NULL);

  hangupButton = gtk_button_new_with_label ("Hang up");
  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*/);
  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);
  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);
  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);
  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*/);
  g_signal_connect (G_OBJECT (transfertButton), "clicked",
                    G_CALLBACK (transfert), NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
311
312

  
313
  
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
  gtk_box_pack_start (GTK_BOX (ret), hbox, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/);
 
	gtk_widget_show(ret); 
	
	return ret;
	
}

void 
update_call_tree ()
{
  GdkPixbuf *pixbuf;
	GtkTreeIter iter;

	gtk_list_store_clear(store);
  int i;
	for( i = 0; i < call_list_get_size(); i++)
	{
    call_t  * c = call_list_get_nth (i);
333
    if (c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
334
    {
335
336
337
338
      gchar * markup;
      if (c->state == CALL_STATE_CURRENT)
  		{
  		  markup = g_markup_printf_escaped("<big><b>%s</b></big>\n"
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
339
340
341
  						    "%s", 
  						    call_get_name(c), 
  						    call_get_number(c));
342
343
344
345
346
347
348
349
350
  		}
  		else 
  		{
  		  markup = g_markup_printf_escaped("<b>%s</b>\n"
  						    "%s", 
  						    call_get_name(c), 
  						    call_get_number(c));
  		}
  		
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
351
352
353
354
355
356
357
358
359
360
  		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);
  		}
361
362
363
364
365
366
367
368
  	  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);
  		}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  	  //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);
  		
  	}
    
  } 
  
392
393
394
395
396
397
398
  gtk_widget_set_sensitive( GTK_WIDGET(acceptButton),     FALSE);
  gtk_widget_set_sensitive( GTK_WIDGET(refuseButton),     FALSE);
  gtk_widget_set_sensitive( GTK_WIDGET(unholdButton),     FALSE);
  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);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
399
400
	//return row_ref;
}