]> sjero.net Git - linphone/blob - gtk/incall_view.c
conferencing improvement, works in GTK ui.
[linphone] / gtk / incall_view.c
1 /*
2 linphone, gtk-glade interface.
3 Copyright (C) 2009  Simon MORLAT (simon.morlat@linphone.org)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19 /*
20 *  C Implementation: incall_frame
21 *
22 * Description: 
23 *
24 *
25 * Author: Simon Morlat <simon.morlat@linphone.org>, (C) 2009
26 *
27 *
28 */
29
30 #include "linphone.h"
31
32
33 gboolean linphone_gtk_use_in_call_view(){
34         static int val=-1;
35         if (val==-1) val=linphone_gtk_get_ui_config_int("use_incall_view",1);
36         return val;
37 }
38
39 LinphoneCall *linphone_gtk_get_currently_displayed_call(gboolean *is_conf){
40         LinphoneCore *lc=linphone_gtk_get_core();
41         GtkWidget *main_window=linphone_gtk_get_main_window ();
42         GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
43         const MSList *calls=linphone_core_get_calls(lc);
44         if (is_conf) *is_conf=FALSE;
45         if (!linphone_gtk_use_in_call_view() || ms_list_size(calls)==1){
46                 if (calls) return (LinphoneCall*)calls->data;
47         }else{
48                 int idx=gtk_notebook_get_current_page (notebook);
49                 GtkWidget *page=gtk_notebook_get_nth_page(notebook,idx);
50                 if (page!=NULL){
51                         LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(page),"call");
52                         if (call==NULL){
53                                 if (page==g_object_get_data(G_OBJECT(main_window),"conference_tab")){
54                                         if (is_conf)
55                                                 *is_conf=TRUE;
56                                         return NULL;
57                                 }
58                         }
59                         return call;
60                 }
61         }
62         return NULL;
63 }
64
65 static GtkWidget *make_tab_header(int number){
66         GtkWidget *w=gtk_hbox_new (FALSE,0);
67         GtkWidget *i=create_pixmap ("status-green.png");
68         GtkWidget *l;
69         gchar *text=g_strdup_printf(_("Call #%i"),number);
70         l=gtk_label_new (text);
71         gtk_box_pack_start (GTK_BOX(w),i,FALSE,FALSE,0);
72         gtk_box_pack_end(GTK_BOX(w),l,TRUE,TRUE,0);
73         gtk_widget_show_all(w);
74         return w;
75 }
76
77 static void linphone_gtk_in_call_set_animation_image(GtkWidget *callview, const char *image_name, gboolean is_stock){
78         GtkWidget *container=linphone_gtk_get_widget(callview,"in_call_animation");
79         GList *elem=gtk_container_get_children(GTK_CONTAINER(container));
80         GtkWidget *image;
81         if (!is_stock)
82                 image=create_pixmap(image_name);
83         else
84                 image=gtk_image_new_from_stock(image_name,GTK_ICON_SIZE_DIALOG);
85         if (elem)
86                 gtk_widget_destroy((GtkWidget*)elem->data);
87         gtk_widget_show(image);
88         gtk_container_add(GTK_CONTAINER(container),image);
89         
90 }
91
92 static void linphone_gtk_in_call_set_animation_spinner(GtkWidget *callview){
93         GtkWidget *container=linphone_gtk_get_widget(callview,"in_call_animation");
94         GList *elem=gtk_container_get_children(GTK_CONTAINER(container));
95         GtkWidget *spinner=gtk_spinner_new();
96         if (elem)
97                 gtk_widget_destroy((GtkWidget*)elem->data);
98         gtk_widget_show(spinner);
99         gtk_container_add(GTK_CONTAINER(container),spinner);
100         gtk_spinner_start(GTK_SPINNER(spinner));
101 }
102
103
104 static void linphone_gtk_transfer_call(LinphoneCall *dest_call){
105         LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
106         if (call) linphone_core_transfer_call_to_another(linphone_gtk_get_core(),call,dest_call);
107 }
108
109 static void transfer_button_clicked(GtkWidget *button, gpointer call_ref){
110         GtkWidget *menu_item;
111         GtkWidget *menu=gtk_menu_new();
112         LinphoneCall *call=(LinphoneCall*)call_ref;
113         LinphoneCore *lc=linphone_gtk_get_core();
114         const MSList *elem=linphone_core_get_calls(lc);
115         
116         for(;elem!=NULL;elem=elem->next){
117                 LinphoneCall *other_call=(LinphoneCall*)elem->data;
118                 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(other_call);
119                 if (other_call!=call){
120                         int call_index=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(call_view),"call_index"));
121                         char *remote_uri=linphone_call_get_remote_address_as_string (other_call);
122                         char *text=g_strdup_printf(_("Transfer to call #%i with %s"),call_index,remote_uri);
123                         menu_item=gtk_image_menu_item_new_with_label(text);
124                         ms_free(remote_uri);
125                         g_free(text);
126                         gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),create_pixmap("status-green.png"));
127                         gtk_widget_show(menu_item);
128                         gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item);
129                         g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_transfer_call,other_call);
130                 }
131         }
132         gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,
133                 gtk_get_current_event_time());
134         gtk_widget_show(menu);
135 }
136
137
138
139 void linphone_gtk_enable_transfer_button(LinphoneCore *lc, gboolean value){
140         const MSList *elem=linphone_core_get_calls(lc);
141         for(;elem!=NULL;elem=elem->next){
142                 LinphoneCall *call=(LinphoneCall*)elem->data;
143                 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
144                 GtkWidget *box=linphone_gtk_get_widget (call_view,"mute_pause_buttons");
145                 GtkWidget *button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"transfer");
146                 if (button && value==FALSE){
147                         gtk_widget_destroy(button);
148                         button=NULL;
149                 }else if (!button && value==TRUE){
150                         button=gtk_button_new_with_label (_("Transfer"));
151                         //gtk_button_set_image_position(GTK_BUTTON(button),GTK_POS_BOTTOM);
152                         gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,GTK_ICON_SIZE_BUTTON));
153                         g_signal_connect(G_OBJECT(button),"clicked",(GCallback)transfer_button_clicked,call);
154                         gtk_widget_show_all(button);
155                         gtk_container_add(GTK_CONTAINER(box),button);
156                 }
157                 g_object_set_data(G_OBJECT(box),"transfer",button);
158         }
159 }
160
161 static void conference_button_clicked(GtkWidget *button, gpointer call_ref){
162         linphone_core_add_all_to_conference(linphone_gtk_get_core());
163         //linphone_core_add_to_conference(linphone_gtk_get_core(),(LinphoneCall*)call_ref);
164         gtk_widget_set_sensitive(button,FALSE);
165 }
166
167 void linphone_gtk_enable_conference_button(LinphoneCore *lc, gboolean value){
168         const MSList *elem=linphone_core_get_calls(lc);
169         for(;elem!=NULL;elem=elem->next){
170                 LinphoneCall *call=(LinphoneCall*)elem->data;
171                 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
172                 GtkWidget *box=linphone_gtk_get_widget (call_view,"mute_pause_buttons");
173                 GtkWidget *button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"conference");
174                 if (button && value==FALSE){
175                         gtk_widget_destroy(button);
176                         button=NULL;
177                 }else if (!button && value==TRUE){
178                         button=gtk_button_new_with_label (_("Conference"));
179                         //gtk_button_set_image_position(GTK_BUTTON(button),GTK_POS_BOTTOM);
180                         gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_stock (GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON));
181                         g_signal_connect(G_OBJECT(button),"clicked",(GCallback)conference_button_clicked,call);
182                         gtk_widget_show_all(button);
183                         gtk_container_add(GTK_CONTAINER(box),button);
184                 }
185                 g_object_set_data(G_OBJECT(box),"conference",button);
186         }
187 }
188
189 void linphone_gtk_create_in_call_view(LinphoneCall *call){
190         GtkWidget *call_view=linphone_gtk_create_widget("main","in_call_frame");
191         GtkWidget *main_window=linphone_gtk_get_main_window ();
192         GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
193         static int call_index=1;
194         int idx;
195
196         if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){
197                 /*this is the only call at this time */
198                 call_index=1;
199         }
200         g_object_set_data(G_OBJECT(call_view),"call",call);
201         g_object_set_data(G_OBJECT(call_view),"call_index",GINT_TO_POINTER(call_index));
202
203         linphone_call_set_user_pointer (call,call_view);
204         linphone_call_ref(call);
205         gtk_notebook_append_page (notebook,call_view,make_tab_header(call_index));
206         gtk_widget_show(call_view);
207         idx = gtk_notebook_page_num(notebook, call_view);
208         gtk_notebook_set_current_page(notebook, idx);
209         call_index++;
210         linphone_gtk_enable_hold_button (call,FALSE,TRUE);
211         linphone_gtk_enable_mute_button(
212                                         GTK_BUTTON(linphone_gtk_get_widget(call_view,"incall_mute")),FALSE);
213 }
214
215 void linphone_gtk_remove_in_call_view(LinphoneCall *call){
216         GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer (call);
217         GtkWidget *main_window=linphone_gtk_get_main_window ();
218         GtkWidget *nb=linphone_gtk_get_widget(main_window,"viewswitch");
219         gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
220         int idx;
221         g_return_if_fail(w!=NULL);
222         idx=gtk_notebook_page_num(GTK_NOTEBOOK(nb),w);
223         gtk_notebook_remove_page (GTK_NOTEBOOK(nb),idx);
224         gtk_widget_destroy(w);
225         if (in_conf){
226                 linphone_gtk_unset_from_conference(call);
227         }
228         linphone_call_set_user_pointer (call,NULL);
229         linphone_call_unref(call);
230         call=linphone_core_get_current_call(linphone_gtk_get_core());
231         if (call==NULL){
232                 if (linphone_core_is_in_conference(linphone_gtk_get_core())){
233                         /*show the conference*/
234                         gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
235                                             g_object_get_data(G_OBJECT(main_window),"conference_tab")));
236                 }else gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), 0);
237         }else{
238                 /*show the active call*/
239                 gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
240                                                                                      linphone_call_get_user_pointer(call)));
241         }
242 }
243
244 static void display_peer_name_in_label(GtkWidget *label, const LinphoneAddress *from){
245         const char *displayname=NULL;
246         const char *id;
247         char *uri_label;
248         displayname=linphone_address_get_display_name(from);
249         id=linphone_address_as_string_uri_only(from);
250         
251         if (displayname!=NULL){
252                 uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>", 
253                         displayname,id);
254         }else
255                 uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
256         gtk_label_set_markup(GTK_LABEL(label),uri_label);
257         g_free(uri_label);
258 }
259
260 void linphone_gtk_in_call_view_set_calling(LinphoneCall *call){
261         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
262         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
263         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
264         GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
265         
266         gtk_label_set_markup(GTK_LABEL(status),_("<b>Calling...</b>"));
267         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
268         
269         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
270         linphone_gtk_in_call_set_animation_spinner(callview);
271 }
272
273 void linphone_gtk_in_call_view_set_incoming(LinphoneCall *call){
274         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
275         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
276         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
277         GtkWidget *answer_button;
278         GtkWidget *image;
279
280         gtk_label_set_markup(GTK_LABEL(status),_("<b>Incoming call</b>"));
281         gtk_widget_show_all(linphone_gtk_get_widget(callview,"answer_decline_panel"));
282         gtk_widget_hide(linphone_gtk_get_widget(callview,"mute_pause_buttons"));
283         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
284
285         answer_button=linphone_gtk_get_widget(callview,"accept_call");
286         image=create_pixmap (linphone_gtk_get_ui_config("start_call_icon","startcall-green.png"));
287         gtk_button_set_label(GTK_BUTTON(answer_button),_("Answer"));
288         gtk_button_set_image(GTK_BUTTON(answer_button),image);
289         gtk_widget_show(image);
290         
291         image=create_pixmap (linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"));
292         gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(callview,"decline_call")),image);
293         gtk_widget_show(image);
294         
295         linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_DIALOG_INFO,TRUE);
296 }
297
298 static void rating_to_color(float rating, GdkColor *color){
299         const char *colorname="grey";
300         if (rating>=4.0)
301                 colorname="green";
302         else if (rating>=3.0)
303                 colorname="white";
304         else if (rating>=2.0)
305                 colorname="yellow";
306         else if (rating>=1.0)
307                 colorname="orange";
308         else if (rating>=0)
309                 colorname="red";
310         if (!gdk_color_parse(colorname,color)){
311                 g_warning("Fail to parse color %s",colorname);
312         }
313 }
314
315 static const char *rating_to_text(float rating){
316         if (rating>=4.0)
317                 return _("good");
318         if (rating>=3.0)
319                 return _("average");
320         if (rating>=2.0)
321                 return _("poor");
322         if (rating>=1.0)
323                 return _("very poor");
324         if (rating>=0)
325                 return _("too bad");
326         return _("unavailable");
327 }
328
329 static gboolean linphone_gtk_in_call_view_refresh(LinphoneCall *call){
330         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
331         GtkWidget *qi=linphone_gtk_get_widget(callview,"quality_indicator");
332         float rating=linphone_call_get_current_quality(call);
333         GdkColor color;
334         gchar tmp[50];
335         linphone_gtk_in_call_view_update_duration(call);
336         if (rating>=0){
337                 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),rating/5.0);
338                 snprintf(tmp,sizeof(tmp),"%.1f (%s)",rating,rating_to_text(rating));
339                 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),tmp);
340         }else{
341                 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),0);
342                 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),_("unavailable"));
343         }
344         rating_to_color(rating,&color);
345         gtk_widget_modify_bg(qi,GTK_STATE_NORMAL,&color);
346         return TRUE;
347 }
348
349
350
351 typedef struct _volume_ctx{
352         GtkWidget *widget;
353         get_volume_t get_volume;
354         void *data;
355         float last_value;
356 }volume_ctx_t;
357
358 #define UNSIGNIFICANT_VOLUME (-26)
359 #define SMOOTH 0.15
360
361 static gboolean update_audio_meter(volume_ctx_t *ctx){
362         float volume_db=ctx->get_volume(ctx->data);
363         float frac=(volume_db-UNSIGNIFICANT_VOLUME)/(float)(-UNSIGNIFICANT_VOLUME+3.0);
364         if (frac<0) frac=0;
365         if (frac>1.0) frac=1.0;
366         if (frac<ctx->last_value){
367                 frac=(frac*SMOOTH)+(ctx->last_value*(1-SMOOTH));
368         }
369         ctx->last_value=frac;
370         //g_message("volume_db=%f, frac=%f",volume_db,frac);
371         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ctx->widget),frac);
372         return TRUE;
373 }
374
375 static void on_audio_meter_destroy(guint task_id){
376         g_source_remove(task_id);
377 }
378
379 void linphone_gtk_init_audio_meter(GtkWidget *w, get_volume_t get_volume, void *data){
380         guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
381         if (task_id==0){
382                 volume_ctx_t *ctx=g_new(volume_ctx_t,1);
383                 ctx->widget=w;
384                 ctx->get_volume=get_volume;
385                 ctx->data=data;
386                 ctx->last_value=0;
387                 g_object_set_data_full(G_OBJECT(w),"ctx",ctx,g_free);
388                 task_id=g_timeout_add(50,(GSourceFunc)update_audio_meter,ctx);
389                 g_object_set_data_full(G_OBJECT(w),"task_id",GINT_TO_POINTER(task_id),(GDestroyNotify)on_audio_meter_destroy);
390         }
391 }
392
393 void linphone_gtk_uninit_audio_meter(GtkWidget *w){
394         guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
395         if (task_id!=0){
396                 g_object_set_data(G_OBJECT(w),"ctx",NULL);
397                 g_object_set_data(G_OBJECT(w),"task_id",NULL);
398         }
399 }
400
401 void linphone_gtk_in_call_view_enable_audio_view(LinphoneCall *call, gboolean val){
402         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
403         GtkWidget *audio_view=linphone_gtk_get_widget(callview,"incall_audioview");
404         //GtkWidget *mic=linphone_gtk_get_widget(callview,"incall_mic_icon");
405         GtkWidget *spk=linphone_gtk_get_widget(callview,"incall_spk_icon");
406         GtkWidget *mic_level=linphone_gtk_get_widget(callview,"mic_audiolevel");
407         GtkWidget *spk_level=linphone_gtk_get_widget(callview,"spk_audiolevel");
408         GdkPixbuf *pbuf;
409         //gtk_image_set_from_pixbuf(GTK_IMAGE(mic),(pbuf=create_pixbuf("mic_active.png")));
410         //g_object_unref(pbuf);
411         if (val){
412                 gtk_image_set_from_pixbuf(GTK_IMAGE(spk),(pbuf=create_pixbuf("speaker.png")));
413                 g_object_unref(pbuf);
414                 linphone_gtk_init_audio_meter(mic_level,(get_volume_t)linphone_call_get_record_volume,call);
415                 linphone_gtk_init_audio_meter(spk_level,(get_volume_t)linphone_call_get_play_volume,call);
416                 gtk_widget_show_all(audio_view);
417         }else{
418                 linphone_gtk_uninit_audio_meter(mic_level);
419                 linphone_gtk_uninit_audio_meter(spk_level);
420                 gtk_widget_hide(audio_view);
421         }
422 }
423
424 void linphone_gtk_in_call_view_set_in_call(LinphoneCall *call){
425         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
426         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
427         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
428         GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
429         guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
430         gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
431         
432         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
433
434         gtk_widget_set_visible(linphone_gtk_get_widget(callview,"mute_pause_buttons"),!in_conf);
435         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
436         gtk_label_set_markup(GTK_LABEL(status),in_conf ? _("In conference") : _("<b>In call</b>"));
437
438         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
439         linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PLAY,TRUE);
440         linphone_gtk_enable_mute_button(
441                                         GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),!in_conf);
442         if (taskid==0){
443                 taskid=g_timeout_add(250,(GSourceFunc)linphone_gtk_in_call_view_refresh,call);
444                 g_object_set_data(G_OBJECT(callview),"taskid",GINT_TO_POINTER(taskid));
445         }
446         linphone_gtk_in_call_view_enable_audio_view(call, !in_conf);
447         if (in_conf) linphone_gtk_set_in_conference(call);
448 }
449
450 void linphone_gtk_in_call_view_set_paused(LinphoneCall *call){
451         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
452         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
453         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
454         gtk_label_set_markup(GTK_LABEL(status),_("<b>Paused call</b>"));
455         linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PAUSE,TRUE);
456 }
457
458 void linphone_gtk_in_call_view_update_duration(LinphoneCall *call){
459         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
460         GtkWidget *duration_label=linphone_gtk_get_widget(callview,"in_call_duration");
461         int duration=linphone_call_get_duration(call);
462         char tmp[256]={0};
463         int seconds=duration%60;
464         int minutes=(duration/60)%60;
465         int hours=duration/3600;
466         snprintf(tmp,sizeof(tmp)-1,_("%02i::%02i::%02i"),hours,minutes,seconds);
467         gtk_label_set_text(GTK_LABEL(duration_label),tmp);
468 }
469
470 static gboolean in_call_view_terminated(LinphoneCall *call){
471         linphone_gtk_remove_in_call_view(call);
472         return FALSE;
473 }
474
475 void linphone_gtk_in_call_view_terminate(LinphoneCall *call, const char *error_msg){
476         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
477         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
478         guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
479         gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));    
480
481         if (error_msg==NULL)
482                 gtk_label_set_markup(GTK_LABEL(status),_("<b>Call ended.</b>"));
483         else{
484                 char *msg=g_markup_printf_escaped("<span color=\"red\"><b>%s</b></span>",error_msg);
485                 gtk_label_set_markup(GTK_LABEL(status),msg);
486                 g_free(msg);
487         }
488         linphone_gtk_in_call_set_animation_image(callview,
489                    linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"),FALSE);
490         
491         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
492         gtk_widget_hide(linphone_gtk_get_widget(callview,"incall_audioview"));
493         linphone_gtk_enable_mute_button(
494                 GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),FALSE);
495         linphone_gtk_enable_hold_button(call,FALSE,TRUE);
496         
497         if (taskid!=0) g_source_remove(taskid);
498         g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,call);
499         if (in_conf)
500                 linphone_gtk_terminate_conference_participant(call);
501 }
502
503 void linphone_gtk_draw_mute_button(GtkButton *button, gboolean active){
504         g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
505         if (active){
506                 GtkWidget *image=create_pixmap("mic_muted.png");
507                 /*gtk_button_set_label(GTK_BUTTON(button),_("Unmute"));*/
508                 if (image!=NULL) {
509                         gtk_button_set_image(GTK_BUTTON(button),image);
510                         gtk_widget_show(image);
511                 }
512         }else{
513                 GtkWidget *image=create_pixmap("mic_active.png");
514                 /*gtk_button_set_label(GTK_BUTTON(button),_("Mute"));*/
515                 if (image!=NULL) {
516                         gtk_button_set_image(GTK_BUTTON(button),image);
517                         gtk_widget_show(image);
518                 }
519         }
520 }
521
522 void linphone_gtk_mute_clicked(GtkButton *button){
523         int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
524         linphone_core_mute_mic(linphone_gtk_get_core(),!active);
525         linphone_gtk_draw_mute_button(button,!active);
526 }
527
528 void linphone_gtk_enable_mute_button(GtkButton *button, gboolean sensitive)
529 {
530         /*gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);*/
531         gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
532         linphone_gtk_draw_mute_button(button,FALSE);
533 }
534
535 void linphone_gtk_draw_hold_button(GtkButton *button, gboolean active){
536         g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
537         if (active){
538                 GtkWidget *image=create_pixmap("hold_off.png");
539                 gtk_button_set_label(GTK_BUTTON(button),_("Resume"));
540                 if (image!=NULL) {
541                         gtk_button_set_image(GTK_BUTTON(button),image);
542                         gtk_widget_show(image);
543                 }
544         }else{
545                 GtkWidget *image=create_pixmap("hold_on.png");
546                 gtk_button_set_label(GTK_BUTTON(button),_("Pause"));
547                 if (image!=NULL) {
548                         gtk_button_set_image(GTK_BUTTON(button),image);
549                         gtk_widget_show(image);
550                 }
551         }
552 }
553
554 void linphone_gtk_hold_clicked(GtkButton *button){
555         int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
556         LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
557         if (!call) return;
558         if(!active)
559         {
560                 linphone_core_pause_call(linphone_gtk_get_core(),call);
561         }
562         else
563         {
564                 linphone_core_resume_call(linphone_gtk_get_core(),call);
565         }
566 }
567
568 void linphone_gtk_enable_hold_button(LinphoneCall *call, gboolean sensitive, gboolean holdon){
569         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer (call);
570         GtkWidget *button;
571         g_return_if_fail(callview!=NULL);
572         button=linphone_gtk_get_widget(callview,"hold_call");
573         gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
574         gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
575         linphone_gtk_draw_hold_button(GTK_BUTTON(button),!holdon);
576 }