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