]> sjero.net Git - linphone/blob - gtk/incall_view.c
75060da9ab770bdf6695016f7320c50db7646301
[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         
82         if (!is_stock){
83                 if (image_name==NULL){
84                         gtk_widget_hide(container);
85                 }
86                 image=create_pixmap(image_name);
87         }else
88                 image=gtk_image_new_from_stock(image_name,GTK_ICON_SIZE_DIALOG);
89         if (elem)
90                 gtk_widget_destroy((GtkWidget*)elem->data);
91         gtk_widget_show(image);
92         gtk_container_add(GTK_CONTAINER(container),image);
93         gtk_widget_show_all(container);
94 }
95
96 static void linphone_gtk_in_call_set_animation_spinner(GtkWidget *callview){
97         GtkWidget *container=linphone_gtk_get_widget(callview,"in_call_animation");
98         GList *elem=gtk_container_get_children(GTK_CONTAINER(container));
99         GtkWidget *spinner=gtk_spinner_new();
100         if (elem)
101                 gtk_widget_destroy((GtkWidget*)elem->data);
102         gtk_widget_show(spinner);
103         gtk_container_add(GTK_CONTAINER(container),spinner);
104         gtk_widget_set_size_request(spinner, 20,20);
105         gtk_spinner_start(GTK_SPINNER(spinner));
106 }
107
108
109 static void linphone_gtk_transfer_call(LinphoneCall *dest_call){
110         LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
111         if (call) linphone_core_transfer_call_to_another(linphone_gtk_get_core(),call,dest_call);
112 }
113
114 static void transfer_button_clicked(GtkWidget *button, gpointer call_ref){
115         GtkWidget *menu_item;
116         GtkWidget *menu=gtk_menu_new();
117         LinphoneCall *call=(LinphoneCall*)call_ref;
118         LinphoneCore *lc=linphone_gtk_get_core();
119         const MSList *elem=linphone_core_get_calls(lc);
120         
121         for(;elem!=NULL;elem=elem->next){
122                 LinphoneCall *other_call=(LinphoneCall*)elem->data;
123                 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(other_call);
124                 if (other_call!=call){
125                         int call_index=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(call_view),"call_index"));
126                         char *remote_uri=linphone_call_get_remote_address_as_string (other_call);
127                         char *text=g_strdup_printf(_("Transfer to call #%i with %s"),call_index,remote_uri);
128                         menu_item=gtk_image_menu_item_new_with_label(text);
129                         ms_free(remote_uri);
130                         g_free(text);
131                         gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),create_pixmap("status-green.png"));
132                         gtk_widget_show(menu_item);
133                         gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item);
134                         g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_transfer_call,other_call);
135                 }
136         }
137         gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,
138                 gtk_get_current_event_time());
139         gtk_widget_show(menu);
140 }
141
142
143
144 void linphone_gtk_enable_transfer_button(LinphoneCore *lc, gboolean value){
145         const MSList *elem=linphone_core_get_calls(lc);
146         for(;elem!=NULL;elem=elem->next){
147                 LinphoneCall *call=(LinphoneCall*)elem->data;
148                 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
149                 GtkWidget *box=linphone_gtk_get_widget (call_view,"mute_pause_buttons");
150                 GtkWidget *button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"transfer");
151                 if (button && value==FALSE){
152                         gtk_widget_destroy(button);
153                         button=NULL;
154                 }else if (!button && value==TRUE){
155                         button=gtk_button_new_with_label (_("Transfer"));
156                         //gtk_button_set_image_position(GTK_BUTTON(button),GTK_POS_BOTTOM);
157                         gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,GTK_ICON_SIZE_BUTTON));
158                         g_signal_connect(G_OBJECT(button),"clicked",(GCallback)transfer_button_clicked,call);
159                         gtk_widget_show_all(button);
160                         gtk_container_add(GTK_CONTAINER(box),button);
161                 }
162                 g_object_set_data(G_OBJECT(box),"transfer",button);
163         }
164 }
165
166 static void conference_button_clicked(GtkWidget *button, gpointer call_ref){
167         linphone_core_add_all_to_conference(linphone_gtk_get_core());
168         //linphone_core_add_to_conference(linphone_gtk_get_core(),(LinphoneCall*)call_ref);
169         gtk_widget_set_sensitive(button,FALSE);
170 }
171
172 void linphone_gtk_enable_conference_button(LinphoneCore *lc, gboolean value){
173         const MSList *elem=linphone_core_get_calls(lc);
174         for(;elem!=NULL;elem=elem->next){
175                 LinphoneCall *call=(LinphoneCall*)elem->data;
176                 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
177                 GtkWidget *box=linphone_gtk_get_widget (call_view,"mute_pause_buttons");
178                 GtkWidget *button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"conference");
179                 if (button && value==FALSE){
180                         gtk_widget_destroy(button);
181                         button=NULL;
182                 }else if (!button && value==TRUE){
183                         button=gtk_button_new_with_label (_("Conference"));
184                         //gtk_button_set_image_position(GTK_BUTTON(button),GTK_POS_BOTTOM);
185                         gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_stock (GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON));
186                         g_signal_connect(G_OBJECT(button),"clicked",(GCallback)conference_button_clicked,call);
187                         gtk_widget_show_all(button);
188                         gtk_container_add(GTK_CONTAINER(box),button);
189                 }
190                 g_object_set_data(G_OBJECT(box),"conference",button);
191         }
192 }
193
194 void linphone_gtk_create_in_call_view(LinphoneCall *call){
195         GtkWidget *call_view=linphone_gtk_create_widget("main","in_call_frame");
196         GtkWidget *main_window=linphone_gtk_get_main_window ();
197         GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
198         static int call_index=1;
199         int idx;
200
201         if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){
202                 /*this is the only call at this time */
203                 call_index=1;
204         }
205         g_object_set_data(G_OBJECT(call_view),"call",call);
206         g_object_set_data(G_OBJECT(call_view),"call_index",GINT_TO_POINTER(call_index));
207
208         linphone_call_set_user_pointer (call,call_view);
209         linphone_call_ref(call);
210         gtk_notebook_append_page (notebook,call_view,make_tab_header(call_index));
211         gtk_widget_show(call_view);
212         idx = gtk_notebook_page_num(notebook, call_view);
213         gtk_notebook_set_current_page(notebook, idx);
214         call_index++;
215         linphone_gtk_enable_hold_button (call,FALSE,TRUE);
216         linphone_gtk_enable_mute_button(
217                                         GTK_BUTTON(linphone_gtk_get_widget(call_view,"incall_mute")),FALSE);
218 }
219
220 void linphone_gtk_remove_in_call_view(LinphoneCall *call){
221         GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer (call);
222         GtkWidget *main_window=linphone_gtk_get_main_window ();
223         GtkWidget *nb=linphone_gtk_get_widget(main_window,"viewswitch");
224         gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
225         int idx;
226         g_return_if_fail(w!=NULL);
227         idx=gtk_notebook_page_num(GTK_NOTEBOOK(nb),w);
228         gtk_notebook_remove_page (GTK_NOTEBOOK(nb),idx);
229         gtk_widget_destroy(w);
230         if (in_conf){
231                 linphone_gtk_unset_from_conference(call);
232         }
233         linphone_call_set_user_pointer (call,NULL);
234         linphone_call_unref(call);
235         call=linphone_core_get_current_call(linphone_gtk_get_core());
236         if (call==NULL){
237                 if (linphone_core_is_in_conference(linphone_gtk_get_core())){
238                         /*show the conference*/
239                         gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
240                                             g_object_get_data(G_OBJECT(main_window),"conference_tab")));
241                 }else gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), 0);
242         }else{
243                 /*show the active call*/
244                 gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
245                                                                                      linphone_call_get_user_pointer(call)));
246         }
247 }
248
249 static void display_peer_name_in_label(GtkWidget *label, const LinphoneAddress *from){
250         const char *displayname=NULL;
251         const char *id;
252         char *uri_label;
253         displayname=linphone_address_get_display_name(from);
254         id=linphone_address_as_string_uri_only(from);
255         
256         if (displayname!=NULL){
257                 uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>", 
258                         displayname,id);
259         }else
260                 uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
261         gtk_label_set_markup(GTK_LABEL(label),uri_label);
262         g_free(uri_label);
263 }
264
265 void linphone_gtk_in_call_view_set_calling(LinphoneCall *call){
266         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
267         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
268         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
269         GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
270         
271         gtk_label_set_markup(GTK_LABEL(status),_("<b>Calling...</b>"));
272         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
273         
274         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
275         linphone_gtk_in_call_set_animation_spinner(callview);
276 }
277
278 void linphone_gtk_in_call_view_set_incoming(LinphoneCall *call){
279         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
280         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
281         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
282         GtkWidget *answer_button;
283         GtkWidget *image;
284
285         gtk_label_set_markup(GTK_LABEL(status),_("<b>Incoming call</b>"));
286         gtk_widget_show_all(linphone_gtk_get_widget(callview,"answer_decline_panel"));
287         gtk_widget_hide(linphone_gtk_get_widget(callview,"mute_pause_buttons"));
288         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
289
290         answer_button=linphone_gtk_get_widget(callview,"accept_call");
291         image=create_pixmap (linphone_gtk_get_ui_config("start_call_icon","startcall-green.png"));
292         gtk_button_set_label(GTK_BUTTON(answer_button),_("Answer"));
293         gtk_button_set_image(GTK_BUTTON(answer_button),image);
294         gtk_widget_show(image);
295         
296         image=create_pixmap (linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"));
297         gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(callview,"decline_call")),image);
298         gtk_widget_show(image);
299         
300         linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_DIALOG_INFO,TRUE);
301 }
302
303 static void rating_to_color(float rating, GdkColor *color){
304         const char *colorname="grey";
305         if (rating>=4.0)
306                 colorname="green";
307         else if (rating>=3.0)
308                 colorname="white";
309         else if (rating>=2.0)
310                 colorname="yellow";
311         else if (rating>=1.0)
312                 colorname="orange";
313         else if (rating>=0)
314                 colorname="red";
315         if (!gdk_color_parse(colorname,color)){
316                 g_warning("Fail to parse color %s",colorname);
317         }
318 }
319
320 static const char *rating_to_text(float rating){
321         if (rating>=4.0)
322                 return _("good");
323         if (rating>=3.0)
324                 return _("average");
325         if (rating>=2.0)
326                 return _("poor");
327         if (rating>=1.0)
328                 return _("very poor");
329         if (rating>=0)
330                 return _("too bad");
331         return _("unavailable");
332 }
333
334 static gboolean linphone_gtk_in_call_view_refresh(LinphoneCall *call){
335         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
336         GtkWidget *qi=linphone_gtk_get_widget(callview,"quality_indicator");
337         float rating=linphone_call_get_current_quality(call);
338         GdkColor color;
339         gchar tmp[50];
340         linphone_gtk_in_call_view_update_duration(call);
341         if (rating>=0){
342                 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),rating/5.0);
343                 snprintf(tmp,sizeof(tmp),"%.1f (%s)",rating,rating_to_text(rating));
344                 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),tmp);
345         }else{
346                 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),0);
347                 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),_("unavailable"));
348         }
349         rating_to_color(rating,&color);
350         gtk_widget_modify_bg(qi,GTK_STATE_NORMAL,&color);
351         return TRUE;
352 }
353
354
355
356 typedef struct _volume_ctx{
357         GtkWidget *widget;
358         get_volume_t get_volume;
359         void *data;
360         float last_value;
361 }volume_ctx_t;
362
363 #define UNSIGNIFICANT_VOLUME (-26)
364 #define SMOOTH 0.15
365
366 static gboolean update_audio_meter(volume_ctx_t *ctx){
367         float volume_db=ctx->get_volume(ctx->data);
368         float frac=(volume_db-UNSIGNIFICANT_VOLUME)/(float)(-UNSIGNIFICANT_VOLUME+3.0);
369         if (frac<0) frac=0;
370         if (frac>1.0) frac=1.0;
371         if (frac<ctx->last_value){
372                 frac=(frac*SMOOTH)+(ctx->last_value*(1-SMOOTH));
373         }
374         ctx->last_value=frac;
375         //g_message("volume_db=%f, frac=%f",volume_db,frac);
376         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ctx->widget),frac);
377         return TRUE;
378 }
379
380 static void on_audio_meter_destroy(guint task_id){
381         g_source_remove(task_id);
382 }
383
384 void linphone_gtk_init_audio_meter(GtkWidget *w, get_volume_t get_volume, void *data){
385         guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
386         if (task_id==0){
387                 volume_ctx_t *ctx=g_new(volume_ctx_t,1);
388                 ctx->widget=w;
389                 ctx->get_volume=get_volume;
390                 ctx->data=data;
391                 ctx->last_value=0;
392                 g_object_set_data_full(G_OBJECT(w),"ctx",ctx,g_free);
393                 task_id=g_timeout_add(50,(GSourceFunc)update_audio_meter,ctx);
394                 g_object_set_data_full(G_OBJECT(w),"task_id",GINT_TO_POINTER(task_id),(GDestroyNotify)on_audio_meter_destroy);
395         }
396 }
397
398 void linphone_gtk_uninit_audio_meter(GtkWidget *w){
399         guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
400         if (task_id!=0){
401                 g_object_set_data(G_OBJECT(w),"ctx",NULL);
402                 g_object_set_data(G_OBJECT(w),"task_id",NULL);
403         }
404 }
405
406 void linphone_gtk_in_call_view_enable_audio_view(LinphoneCall *call, gboolean val){
407         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
408         GtkWidget *audio_view=linphone_gtk_get_widget(callview,"incall_audioview");
409         //GtkWidget *mic=linphone_gtk_get_widget(callview,"incall_mic_icon");
410         GtkWidget *spk=linphone_gtk_get_widget(callview,"incall_spk_icon");
411         GtkWidget *mic_level=linphone_gtk_get_widget(callview,"mic_audiolevel");
412         GtkWidget *spk_level=linphone_gtk_get_widget(callview,"spk_audiolevel");
413         GdkPixbuf *pbuf;
414         //gtk_image_set_from_pixbuf(GTK_IMAGE(mic),(pbuf=create_pixbuf("mic_active.png")));
415         //g_object_unref(pbuf);
416         if (val){
417                 gtk_image_set_from_pixbuf(GTK_IMAGE(spk),(pbuf=create_pixbuf("speaker.png")));
418                 g_object_unref(pbuf);
419                 linphone_gtk_init_audio_meter(mic_level,(get_volume_t)linphone_call_get_record_volume,call);
420                 linphone_gtk_init_audio_meter(spk_level,(get_volume_t)linphone_call_get_play_volume,call);
421                 gtk_widget_show_all(audio_view);
422         }else{
423                 linphone_gtk_uninit_audio_meter(mic_level);
424                 linphone_gtk_uninit_audio_meter(spk_level);
425                 gtk_widget_hide(audio_view);
426         }
427 }
428
429 void linphone_gtk_auth_token_verified_clicked(GtkButton *button){
430         LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
431         if (call){
432                 linphone_call_set_authentication_token_verified(call,!linphone_call_get_authentication_token_verified(call));
433         }
434 }
435
436 void linphone_gtk_in_call_view_show_encryption(LinphoneCall *call){
437         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
438         GtkWidget *encryption_box=linphone_gtk_get_widget(callview,"encryption_box");
439         GtkWidget *label=linphone_gtk_get_widget(callview,"encryption_label");
440         GtkWidget *status_icon=linphone_gtk_get_widget(callview,"encryption_status_icon");
441         GtkWidget *verify_button=linphone_gtk_get_widget(callview,"encryption_verify_button");
442         LinphoneMediaEncryption me=linphone_call_params_get_media_encryption(linphone_call_get_current_params(call));
443         bool_t verified=linphone_call_get_authentication_token_verified(call);
444         switch(me){
445                 case LinphoneMediaEncryptionSRTP:
446                         gtk_widget_show_all(encryption_box);
447                         gtk_label_set_markup(GTK_LABEL(label),_("Secured by SRTP"));
448                         gtk_widget_hide(status_icon);
449                         gtk_widget_hide(verify_button);
450                 break;
451                 case LinphoneMediaEncryptionZRTP:
452                 {
453                         gchar *text=g_strdup_printf(_("Secured by ZRTP - [auth token: %s]"),linphone_call_get_authentication_token(call));
454                         gtk_label_set_markup(GTK_LABEL(label),text);
455                         g_free(text);
456                         gtk_image_set_from_stock(GTK_IMAGE(status_icon),
457                                                   verified ? GTK_STOCK_APPLY : GTK_STOCK_DIALOG_WARNING,GTK_ICON_SIZE_MENU);
458                         gtk_button_set_label(GTK_BUTTON(verify_button),
459                                              verified ? _("Set unverified") : _("Set verified"));
460                         gtk_widget_show_all(encryption_box);
461                 }       
462                 break;
463                 default:
464                         gtk_widget_hide_all(encryption_box);
465         }
466 }
467
468 void linphone_gtk_in_call_view_set_in_call(LinphoneCall *call){
469         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
470         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
471         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
472         GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
473         guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
474         gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
475         
476         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
477
478         gtk_widget_set_visible(linphone_gtk_get_widget(callview,"mute_pause_buttons"),!in_conf);
479         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
480         gtk_label_set_markup(GTK_LABEL(status),in_conf ? _("In conference") : _("<b>In call</b>"));
481
482         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
483         linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PLAY,TRUE);
484         linphone_gtk_enable_mute_button(
485                                         GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),!in_conf);
486         if (taskid==0){
487                 taskid=g_timeout_add(250,(GSourceFunc)linphone_gtk_in_call_view_refresh,call);
488                 g_object_set_data(G_OBJECT(callview),"taskid",GINT_TO_POINTER(taskid));
489         }
490         linphone_gtk_in_call_view_enable_audio_view(call, !in_conf);
491         linphone_gtk_in_call_view_show_encryption(call);
492         if (in_conf) linphone_gtk_set_in_conference(call);
493 }
494
495 void linphone_gtk_in_call_view_set_paused(LinphoneCall *call){
496         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
497         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
498         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
499         gtk_label_set_markup(GTK_LABEL(status),_("<b>Paused call</b>"));
500         linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PAUSE,TRUE);
501 }
502
503 void linphone_gtk_in_call_view_update_duration(LinphoneCall *call){
504         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
505         GtkWidget *duration_label=linphone_gtk_get_widget(callview,"in_call_duration");
506         int duration=linphone_call_get_duration(call);
507         char tmp[256]={0};
508         int seconds=duration%60;
509         int minutes=(duration/60)%60;
510         int hours=duration/3600;
511         snprintf(tmp,sizeof(tmp)-1,_("%02i::%02i::%02i"),hours,minutes,seconds);
512         gtk_label_set_text(GTK_LABEL(duration_label),tmp);
513 }
514
515 static gboolean in_call_view_terminated(LinphoneCall *call){
516         linphone_gtk_remove_in_call_view(call);
517         return FALSE;
518 }
519
520 void linphone_gtk_in_call_view_terminate(LinphoneCall *call, const char *error_msg){
521         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
522         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
523         guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
524         gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));    
525
526         if (error_msg==NULL)
527                 gtk_label_set_markup(GTK_LABEL(status),_("<b>Call ended.</b>"));
528         else{
529                 char *msg=g_markup_printf_escaped("<span color=\"red\"><b>%s</b></span>",error_msg);
530                 gtk_label_set_markup(GTK_LABEL(status),msg);
531                 g_free(msg);
532         }
533         linphone_gtk_in_call_set_animation_image(callview,
534                    linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"),FALSE);
535         
536         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
537         gtk_widget_hide(linphone_gtk_get_widget(callview,"incall_audioview"));
538         linphone_gtk_enable_mute_button(
539                 GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),FALSE);
540         linphone_gtk_enable_hold_button(call,FALSE,TRUE);
541         
542         if (taskid!=0) g_source_remove(taskid);
543         g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,call);
544         if (in_conf)
545                 linphone_gtk_terminate_conference_participant(call);
546 }
547
548 void linphone_gtk_draw_mute_button(GtkButton *button, gboolean active){
549         g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
550         if (active){
551                 GtkWidget *image=create_pixmap("mic_muted.png");
552                 /*gtk_button_set_label(GTK_BUTTON(button),_("Unmute"));*/
553                 if (image!=NULL) {
554                         gtk_button_set_image(GTK_BUTTON(button),image);
555                         gtk_widget_show(image);
556                 }
557         }else{
558                 GtkWidget *image=create_pixmap("mic_active.png");
559                 /*gtk_button_set_label(GTK_BUTTON(button),_("Mute"));*/
560                 if (image!=NULL) {
561                         gtk_button_set_image(GTK_BUTTON(button),image);
562                         gtk_widget_show(image);
563                 }
564         }
565 }
566
567 void linphone_gtk_mute_clicked(GtkButton *button){
568         int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
569         linphone_core_mute_mic(linphone_gtk_get_core(),!active);
570         linphone_gtk_draw_mute_button(button,!active);
571 }
572
573 void linphone_gtk_enable_mute_button(GtkButton *button, gboolean sensitive)
574 {
575         /*gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);*/
576         gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
577         linphone_gtk_draw_mute_button(button,FALSE);
578 }
579
580 void linphone_gtk_draw_hold_button(GtkButton *button, gboolean active){
581         g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
582         if (active){
583                 GtkWidget *image=create_pixmap("hold_off.png");
584                 gtk_button_set_label(GTK_BUTTON(button),_("Resume"));
585                 if (image!=NULL) {
586                         gtk_button_set_image(GTK_BUTTON(button),image);
587                         gtk_widget_show(image);
588                 }
589         }else{
590                 GtkWidget *image=create_pixmap("hold_on.png");
591                 gtk_button_set_label(GTK_BUTTON(button),_("Pause"));
592                 if (image!=NULL) {
593                         gtk_button_set_image(GTK_BUTTON(button),image);
594                         gtk_widget_show(image);
595                 }
596         }
597 }
598
599 void linphone_gtk_hold_clicked(GtkButton *button){
600         int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
601         LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
602         if (!call) return;
603         if(!active)
604         {
605                 linphone_core_pause_call(linphone_gtk_get_core(),call);
606         }
607         else
608         {
609                 linphone_core_resume_call(linphone_gtk_get_core(),call);
610         }
611 }
612
613 void linphone_gtk_enable_hold_button(LinphoneCall *call, gboolean sensitive, gboolean holdon){
614         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer (call);
615         GtkWidget *button;
616         g_return_if_fail(callview!=NULL);
617         button=linphone_gtk_get_widget(callview,"hold_call");
618         gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
619         gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
620         linphone_gtk_draw_hold_button(GTK_BUTTON(button),!holdon);
621 }