2 linphone, gtk-glade interface.
3 Copyright (C) 2009 Simon MORLAT (simon.morlat@linphone.org)
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.
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.
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.
20 * C Implementation: incall_frame
25 * Author: Simon Morlat <simon.morlat@linphone.org>, (C) 2009
33 gboolean linphone_gtk_use_in_call_view(){
35 if (val==-1) val=linphone_gtk_get_ui_config_int("use_incall_view",1);
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;
48 int idx=gtk_notebook_get_current_page (notebook);
49 GtkWidget *page=gtk_notebook_get_nth_page(notebook,idx);
51 LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(page),"call");
53 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(main_window),"is_conf"))){
65 static GtkWidget *make_tab_header(int number){
66 GtkWidget *w=gtk_hbox_new (FALSE,0);
67 GtkWidget *i=create_pixmap ("startcall-small.png");
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);
77 void update_tab_header(LinphoneCall *call,gboolean pause){
78 GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer(call);
79 GtkWidget *main_window=linphone_gtk_get_main_window();
80 GtkNotebook *notebook=GTK_NOTEBOOK(linphone_gtk_get_widget(main_window,"viewswitch"));
81 gint call_index=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"call_index"));
82 GtkWidget *new_label=gtk_hbox_new (FALSE,0);
85 i=gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE,GTK_ICON_SIZE_SMALL_TOOLBAR);
87 i=create_pixmap ("startcall-small.png");
90 gchar *text=g_strdup_printf(_("Call #%i"),call_index);
91 l=gtk_label_new (text);
92 gtk_box_pack_start (GTK_BOX(new_label),i,FALSE,FALSE,0);
93 gtk_box_pack_end(GTK_BOX(new_label),l,TRUE,TRUE,0);
95 gtk_notebook_set_tab_label(notebook,w,new_label);
96 gtk_widget_show_all(new_label);
99 static void linphone_gtk_in_call_set_animation_image(GtkWidget *callview, const char *image_name, gboolean is_stock){
100 GtkWidget *container=linphone_gtk_get_widget(callview,"in_call_animation");
101 GList *elem=gtk_container_get_children(GTK_CONTAINER(container));
105 if (image_name==NULL){
106 gtk_widget_hide(container);
108 image=create_pixmap(image_name);
110 image=gtk_image_new_from_stock(image_name,GTK_ICON_SIZE_DND);
112 gtk_widget_destroy((GtkWidget*)elem->data);
113 gtk_widget_show(image);
114 gtk_container_add(GTK_CONTAINER(container),image);
115 gtk_widget_show_all(container);
118 static void linphone_gtk_in_call_set_animation_spinner(GtkWidget *callview){
119 #if GTK_CHECK_VERSION(2,20,0)
120 GtkWidget *container=linphone_gtk_get_widget(callview,"in_call_animation");
121 GList *elem=gtk_container_get_children(GTK_CONTAINER(container));
122 GtkWidget *spinner=gtk_spinner_new();
124 gtk_widget_destroy((GtkWidget*)elem->data);
125 gtk_widget_show(spinner);
126 gtk_container_add(GTK_CONTAINER(container),spinner);
127 gtk_widget_set_size_request(spinner, 20,20);
128 gtk_spinner_start(GTK_SPINNER(spinner));
132 static void linphone_gtk_transfer_call(LinphoneCall *dest_call){
133 LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
134 if (call) linphone_core_transfer_call_to_another(linphone_gtk_get_core(),call,dest_call);
137 void transfer_button_clicked(GtkWidget *button, gpointer call_ref){
138 GtkWidget *menu_item;
139 GtkWidget *menu=gtk_menu_new();
140 LinphoneCall *call=(LinphoneCall*)call_ref;
141 LinphoneCore *lc=linphone_gtk_get_core();
142 const MSList *elem=linphone_core_get_calls(lc);
144 for(;elem!=NULL;elem=elem->next){
145 LinphoneCall *other_call=(LinphoneCall*)elem->data;
146 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(other_call);
147 if (other_call!=call){
148 int call_index=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(call_view),"call_index"));
149 char *remote_uri=linphone_call_get_remote_address_as_string (other_call);
150 char *text=g_strdup_printf(_("Transfer to call #%i with %s"),call_index,remote_uri);
151 menu_item=gtk_image_menu_item_new_with_label(text);
154 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),create_pixmap("status-green.png"));
155 gtk_widget_show(menu_item);
156 gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item);
157 g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_transfer_call,other_call);
160 gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,
161 gtk_get_current_event_time());
162 gtk_widget_show(menu);
165 void linphone_gtk_enable_transfer_button(LinphoneCore *lc, gboolean value){
166 const MSList *elem=linphone_core_get_calls(lc);
167 for(;elem!=NULL;elem=elem->next){
168 LinphoneCall *call=(LinphoneCall*)elem->data;
169 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
170 GtkWidget *button=linphone_gtk_get_widget (call_view,"transfer_button");
172 gtk_widget_set_sensitive(button,value);
177 static void conference_button_clicked(GtkWidget *button, gpointer call_ref){
178 gtk_widget_set_sensitive(button,FALSE);
179 g_object_set_data(G_OBJECT(linphone_gtk_get_main_window()),"conf_frame",NULL);
180 linphone_core_add_all_to_conference(linphone_gtk_get_core());
181 //linphone_core_add_to_conference(linphone_gtk_get_core(),(LinphoneCall*)call_ref);
185 void linphone_gtk_enable_conference_button(LinphoneCore *lc, gboolean value){
186 const MSList *elem=linphone_core_get_calls(lc);
187 for(;elem!=NULL;elem=elem->next){
188 LinphoneCall *call=(LinphoneCall*)elem->data;
189 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
190 GtkWidget *button=linphone_gtk_get_widget (call_view,"conference_button");
192 gtk_widget_set_sensitive(button,value);
197 static void show_used_codecs(GtkWidget *callstats, LinphoneCall *call){
198 const LinphoneCallParams *params=linphone_call_get_current_params(call);
200 const PayloadType *acodec=linphone_call_params_get_used_audio_codec(params);
201 const PayloadType *vcodec=linphone_call_params_get_used_video_codec(params);
202 GtkWidget *acodec_ui=linphone_gtk_get_widget(callstats,"audio_codec");
203 GtkWidget *vcodec_ui=linphone_gtk_get_widget(callstats,"video_codec");
207 snprintf(tmp,sizeof(tmp)-1,"%s/%i/%i",acodec->mime_type,acodec->clock_rate,acodec->channels);
208 gtk_label_set_label(GTK_LABEL(acodec_ui),tmp);
209 }else gtk_label_set_label(GTK_LABEL(acodec_ui),_("Not used"));
211 gtk_label_set_label(GTK_LABEL(vcodec_ui),vcodec->mime_type);
212 }else gtk_label_set_label(GTK_LABEL(vcodec_ui),_("Not used"));
216 static const char *ice_state_to_string(LinphoneIceState ice_state){
218 case LinphoneIceStateNotActivated:
219 return _("ICE not activated");
220 case LinphoneIceStateFailed:
221 return _("ICE failed");
222 case LinphoneIceStateInProgress:
223 return _("ICE in progress");
224 case LinphoneIceStateReflexiveConnection:
225 return _("Going through one or more NATs");
226 case LinphoneIceStateHostConnection:
228 case LinphoneIceStateRelayConnection:
229 return _("Through a relay server");
234 static const char *upnp_state_to_string(LinphoneUpnpState ice_state){
236 case LinphoneUpnpStateIdle:
237 return _("uPnP not activated");
238 case LinphoneUpnpStatePending:
239 return _("uPnP in progress");
240 case LinphoneUpnpStateNotAvailable:
241 return _("uPnp not available");
242 case LinphoneUpnpStateOk:
243 return _("uPnP is running");
244 case LinphoneUpnpStateKo:
245 return _("uPnP failed");
252 static void _refresh_call_stats(GtkWidget *callstats, LinphoneCall *call){
253 const LinphoneCallStats *as=linphone_call_get_audio_stats(call);
254 const LinphoneCallStats *vs=linphone_call_get_video_stats(call);
255 const char *audio_media_connectivity = _("Direct");
256 const char *video_media_connectivity = _("Direct");
257 gchar *tmp=g_strdup_printf(_("download: %f\nupload: %f (kbit/s)"),
258 as->download_bandwidth,as->upload_bandwidth);
259 gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(callstats,"audio_bandwidth_usage")),tmp);
261 tmp=g_strdup_printf(_("download: %f\nupload: %f (kbit/s)"),
262 vs->download_bandwidth,vs->upload_bandwidth);
263 gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(callstats,"video_bandwidth_usage")),tmp);
265 if(as->upnp_state != LinphoneUpnpStateNotAvailable && as->upnp_state != LinphoneUpnpStateIdle) {
266 audio_media_connectivity = upnp_state_to_string(as->upnp_state);
267 } else if(as->ice_state != LinphoneIceStateNotActivated) {
268 audio_media_connectivity = ice_state_to_string(as->ice_state);
270 gtk_label_set_text(GTK_LABEL(linphone_gtk_get_widget(callstats,"audio_media_connectivity")),audio_media_connectivity);
271 if(vs->upnp_state != LinphoneUpnpStateNotAvailable && vs->upnp_state != LinphoneUpnpStateIdle) {
272 video_media_connectivity = upnp_state_to_string(vs->upnp_state);
273 } else if(vs->ice_state != LinphoneIceStateNotActivated) {
274 video_media_connectivity = ice_state_to_string(vs->ice_state);
276 gtk_label_set_text(GTK_LABEL(linphone_gtk_get_widget(callstats,"video_media_connectivity")),video_media_connectivity);
279 static gboolean refresh_call_stats(GtkWidget *callstats){
280 LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(callstats),"call");
281 switch (linphone_call_get_state(call)){
282 case LinphoneCallError:
283 case LinphoneCallEnd:
284 case LinphoneCallReleased:
285 gtk_widget_destroy(callstats);
288 case LinphoneCallStreamsRunning:
289 _refresh_call_stats(callstats,call);
297 static void on_call_stats_destroyed(GtkWidget *call_view){
298 GtkWidget *call_stats=(GtkWidget*)g_object_get_data(G_OBJECT(call_view),"call_stats");
299 LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(call_stats),"call");
300 g_source_remove(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(call_stats),"tid")));
301 g_object_set_data(G_OBJECT(call_view),"call_stats",NULL);
302 linphone_call_unref(call);
305 static void linphone_gtk_show_call_stats(LinphoneCall *call){
306 GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer(call);
307 GtkWidget *call_stats=(GtkWidget*)g_object_get_data(G_OBJECT(w),"call_stats");
308 if (call_stats==NULL){
310 call_stats=linphone_gtk_create_window("call_statistics");
311 g_object_set_data(G_OBJECT(w),"call_stats",call_stats);
312 g_object_set_data(G_OBJECT(call_stats),"call",linphone_call_ref(call));
313 tid=g_timeout_add(1000,(GSourceFunc)refresh_call_stats,call_stats);
314 g_object_set_data(G_OBJECT(call_stats),"tid",GINT_TO_POINTER(tid));
315 g_signal_connect_swapped(G_OBJECT(call_stats),"destroy",(GCallback)on_call_stats_destroyed,(gpointer)w);
316 show_used_codecs(call_stats,call);
317 refresh_call_stats(call_stats);
318 gtk_widget_show(call_stats);
323 void linphone_gtk_enable_video_button(LinphoneCall *call, gboolean sensitive, gboolean holdon){
324 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer (call);
326 g_return_if_fail(callview!=NULL);
327 button=linphone_gtk_get_widget(callview,"video_button");
328 gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
329 gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
332 void linphone_gtk_create_in_call_view(LinphoneCall *call){
333 GtkWidget *call_view=linphone_gtk_create_widget("main","in_call_frame");
334 GtkWidget *main_window=linphone_gtk_get_main_window ();
335 GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
336 static int call_index=1;
339 if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){
340 /*this is the only call at this time */
343 g_object_set_data(G_OBJECT(call_view),"call",call);
344 g_object_set_data(G_OBJECT(call_view),"call_index",GINT_TO_POINTER(call_index));
346 linphone_call_set_user_pointer (call,call_view);
347 linphone_call_ref(call);
348 gtk_notebook_append_page (notebook,call_view,make_tab_header(call_index));
349 gtk_widget_show(call_view);
350 idx = gtk_notebook_page_num(notebook, call_view);
351 gtk_notebook_set_current_page(notebook, idx);
353 linphone_gtk_enable_hold_button (call,FALSE,TRUE);
354 linphone_gtk_enable_video_button (call,FALSE,TRUE);
355 linphone_gtk_enable_mute_button(
356 GTK_BUTTON(linphone_gtk_get_widget(call_view,"incall_mute")),FALSE);
358 GtkWidget *transfer = linphone_gtk_get_widget(call_view,"transfer_button");
359 gtk_button_set_image(GTK_BUTTON(transfer),gtk_image_new_from_stock
360 (GTK_STOCK_GO_FORWARD,GTK_ICON_SIZE_BUTTON));
361 g_signal_connect(G_OBJECT(transfer),"clicked",(GCallback)transfer_button_clicked,call);
362 gtk_widget_hide(transfer);
364 GtkWidget *conf = linphone_gtk_get_widget(call_view,"conference_button");
365 gtk_button_set_image(GTK_BUTTON(conf),gtk_image_new_from_stock (GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON));
366 g_signal_connect(G_OBJECT(conf),"clicked",(GCallback)conference_button_clicked,call);
367 gtk_widget_hide(conf);
369 GtkWidget *button=linphone_gtk_get_widget(call_view,"terminate_call");
370 GtkWidget *image=create_pixmap("stopcall-small.png");
371 gtk_button_set_label(GTK_BUTTON(button),_("Hang up"));
372 gtk_button_set_image(GTK_BUTTON(button),image);
373 gtk_widget_show(image);
374 g_signal_connect_swapped(G_OBJECT(linphone_gtk_get_widget(call_view,"quality_indicator")),"button-press-event",(GCallback)linphone_gtk_show_call_stats,call);
377 static void video_button_clicked(GtkWidget *button, LinphoneCall *call){
378 gboolean adding=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"adding_video"));
379 LinphoneCore *lc=linphone_call_get_core(call);
380 LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call));
381 gtk_widget_set_sensitive(button,FALSE);
382 linphone_call_params_enable_video(params,adding);
383 linphone_core_update_call(lc,call,params);
384 linphone_call_params_destroy(params);
387 void linphone_gtk_update_video_button(LinphoneCall *call){
388 GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
390 const LinphoneCallParams *params=linphone_call_get_current_params(call);
391 gboolean has_video=linphone_call_params_video_enabled(params);
392 if (call_view==NULL) return;
393 button=linphone_gtk_get_widget(call_view,"video_button");
395 gtk_button_set_image(GTK_BUTTON(button),
396 gtk_image_new_from_stock(has_video ? GTK_STOCK_REMOVE : GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON));
397 g_object_set_data(G_OBJECT(button),"adding_video",GINT_TO_POINTER(!has_video));
398 if (!linphone_core_video_supported(linphone_call_get_core(call))){
399 gtk_widget_set_sensitive(button,FALSE);
402 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"signal_connected"))==0){
403 g_signal_connect(G_OBJECT(button),"clicked",(GCallback)video_button_clicked,call);
404 g_object_set_data(G_OBJECT(button),"signal_connected",GINT_TO_POINTER(1));
406 GtkWidget *conf_frame=(GtkWidget *)g_object_get_data(G_OBJECT(linphone_gtk_get_main_window()),"conf_frame");
407 gtk_widget_set_sensitive(button,linphone_call_get_state(call)==LinphoneCallStreamsRunning);
408 if(conf_frame!=NULL){
409 gtk_widget_set_sensitive(button,FALSE);
413 void linphone_gtk_remove_in_call_view(LinphoneCall *call){
414 GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer (call);
415 GtkWidget *main_window=linphone_gtk_get_main_window ();
416 GtkWidget *nb=linphone_gtk_get_widget(main_window,"viewswitch");
417 gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
419 g_return_if_fail(w!=NULL);
420 idx=gtk_notebook_page_num(GTK_NOTEBOOK(nb),w);
421 gtk_notebook_remove_page (GTK_NOTEBOOK(nb),idx);
422 gtk_widget_destroy(w);
424 linphone_gtk_unset_from_conference(call);
426 linphone_call_set_user_pointer (call,NULL);
427 linphone_call_unref(call);
428 call=linphone_core_get_current_call(linphone_gtk_get_core());
430 if (linphone_core_is_in_conference(linphone_gtk_get_core())){
431 /*show the conference*/
432 gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
433 g_object_get_data(G_OBJECT(main_window),"conf_frame")));
434 }else gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), 0);
436 /*show the active call*/
437 gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
438 linphone_call_get_user_pointer(call)));
442 static void display_peer_name_in_label(GtkWidget *label, const LinphoneAddress *from){
443 const char *displayname=NULL;
446 displayname=linphone_address_get_display_name(from);
447 id=linphone_address_as_string_uri_only(from);
449 if (displayname!=NULL){
450 uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>",
453 uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
454 gtk_label_set_markup(GTK_LABEL(label),uri_label);
458 void linphone_gtk_in_call_view_set_calling(LinphoneCall *call){
459 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
460 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
461 GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
462 GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
464 gtk_label_set_markup(GTK_LABEL(status),_("<b>Calling...</b>"));
465 display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
467 gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
468 linphone_gtk_in_call_set_animation_spinner(callview);
471 void linphone_gtk_in_call_view_set_incoming(LinphoneCall *call){
472 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
473 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
474 GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
475 GtkWidget *answer_button;
478 gtk_label_set_markup(GTK_LABEL(status),_("<b>Incoming call</b>"));
479 gtk_widget_show_all(linphone_gtk_get_widget(callview,"answer_decline_panel"));
480 gtk_widget_hide(linphone_gtk_get_widget(callview,"buttons_panel"));
481 display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
483 answer_button=linphone_gtk_get_widget(callview,"accept_call");
484 image=create_pixmap (linphone_gtk_get_ui_config("start_call_icon","startcall-small.png"));
485 gtk_button_set_label(GTK_BUTTON(answer_button),_("Answer"));
486 gtk_button_set_image(GTK_BUTTON(answer_button),image);
487 gtk_widget_show(image);
489 image=create_pixmap (linphone_gtk_get_ui_config("stop_call_icon","stopcall-small.png"));
490 gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(callview,"decline_call")),image);
491 gtk_widget_show(image);
493 linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_DIALOG_INFO,TRUE);
496 static void rating_to_color(float rating, GdkColor *color){
497 const char *colorname="grey";
500 else if (rating>=3.0)
502 else if (rating>=2.0)
504 else if (rating>=1.0)
508 if (!gdk_color_parse(colorname,color)){
509 g_warning("Fail to parse color %s",colorname);
513 static const char *rating_to_text(float rating){
521 return _("very poor");
524 return _("unavailable");
527 static gboolean linphone_gtk_in_call_view_refresh(LinphoneCall *call){
528 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
529 GtkWidget *qi=linphone_gtk_get_widget(callview,"quality_indicator");
530 float rating=linphone_call_get_current_quality(call);
533 linphone_gtk_in_call_view_update_duration(call);
535 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),rating/5.0);
536 snprintf(tmp,sizeof(tmp),"%.1f (%s)",rating,rating_to_text(rating));
537 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),tmp);
539 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),0);
540 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),_("unavailable"));
542 rating_to_color(rating,&color);
543 gtk_widget_modify_bg(qi,GTK_STATE_NORMAL,&color);
547 typedef struct _volume_ctx{
549 get_volume_t get_volume;
554 #define UNSIGNIFICANT_VOLUME (-26)
557 static gboolean update_audio_meter(volume_ctx_t *ctx){
558 float volume_db=ctx->get_volume(ctx->data);
559 float frac=(volume_db-UNSIGNIFICANT_VOLUME)/(float)(-UNSIGNIFICANT_VOLUME+3.0);
561 if (frac>1.0) frac=1.0;
562 if (frac<ctx->last_value){
563 frac=(frac*SMOOTH)+(ctx->last_value*(1-SMOOTH));
565 ctx->last_value=frac;
566 //g_message("volume_db=%f, frac=%f",volume_db,frac);
567 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ctx->widget),frac);
571 static void on_audio_meter_destroy(guint task_id){
572 g_source_remove(task_id);
575 void linphone_gtk_init_audio_meter(GtkWidget *w, get_volume_t get_volume, void *data){
576 guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
578 volume_ctx_t *ctx=g_new(volume_ctx_t,1);
580 ctx->get_volume=get_volume;
583 g_object_set_data_full(G_OBJECT(w),"ctx",ctx,g_free);
584 task_id=g_timeout_add(50,(GSourceFunc)update_audio_meter,ctx);
585 g_object_set_data_full(G_OBJECT(w),"task_id",GINT_TO_POINTER(task_id),(GDestroyNotify)on_audio_meter_destroy);
589 void linphone_gtk_uninit_audio_meter(GtkWidget *w){
590 guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
592 g_object_set_data(G_OBJECT(w),"ctx",NULL);
593 g_object_set_data(G_OBJECT(w),"task_id",NULL);
597 void linphone_gtk_in_call_view_enable_audio_view(LinphoneCall *call, gboolean val){
598 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
599 GtkWidget *audio_view=linphone_gtk_get_widget(callview,"incall_audioview");
600 GtkWidget *mic=linphone_gtk_get_widget(callview,"incall_mic_icon");
601 GtkWidget *spk=linphone_gtk_get_widget(callview,"incall_spk_icon");
602 GtkWidget *mic_level=linphone_gtk_get_widget(callview,"mic_audiolevel");
603 GtkWidget *spk_level=linphone_gtk_get_widget(callview,"spk_audiolevel");
606 gtk_image_set_from_pixbuf(GTK_IMAGE(mic),(pbuf=create_pixbuf("mic_active.png")));
607 g_object_unref(pbuf);
609 gtk_image_set_from_pixbuf(GTK_IMAGE(spk),(pbuf=create_pixbuf("speaker.png")));
610 g_object_unref(pbuf);
611 linphone_gtk_init_audio_meter(mic_level,(get_volume_t)linphone_call_get_record_volume,call);
612 linphone_gtk_init_audio_meter(spk_level,(get_volume_t)linphone_call_get_play_volume,call);
613 gtk_widget_show_all(audio_view);
615 linphone_gtk_uninit_audio_meter(mic_level);
616 linphone_gtk_uninit_audio_meter(spk_level);
617 gtk_widget_hide(audio_view);
621 void linphone_gtk_auth_token_verified_clicked(GtkButton *button){
622 LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
624 linphone_call_set_authentication_token_verified(call,!linphone_call_get_authentication_token_verified(call));
628 void linphone_gtk_in_call_view_show_encryption(LinphoneCall *call){
629 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
630 GtkWidget *encryption_box=linphone_gtk_get_widget(callview,"encryption_box");
631 GtkWidget *label=linphone_gtk_get_widget(callview,"encryption_label");
632 GtkWidget *status_icon=linphone_gtk_get_widget(callview,"encryption_status_icon");
633 GtkWidget *verify_button=linphone_gtk_get_widget(callview,"encryption_verify_button");
634 LinphoneMediaEncryption me=linphone_call_params_get_media_encryption(linphone_call_get_current_params(call));
635 bool_t verified=linphone_call_get_authentication_token_verified(call);
637 case LinphoneMediaEncryptionSRTP:
638 gtk_widget_show_all(encryption_box);
639 gtk_label_set_markup(GTK_LABEL(label),_("Secured by SRTP"));
640 gtk_widget_hide(status_icon);
641 gtk_widget_hide(verify_button);
643 case LinphoneMediaEncryptionZRTP:
645 gchar *text=g_strdup_printf(_("Secured by ZRTP - [auth token: %s]"),linphone_call_get_authentication_token(call));
646 gtk_label_set_markup(GTK_LABEL(label),text);
648 gtk_image_set_from_stock(GTK_IMAGE(status_icon),
649 verified ? GTK_STOCK_APPLY : GTK_STOCK_DIALOG_WARNING,GTK_ICON_SIZE_MENU);
650 gtk_button_set_label(GTK_BUTTON(verify_button),
651 verified ? _("Set unverified") : _("Set verified"));
652 gtk_widget_show_all(encryption_box);
656 gtk_widget_hide_all(encryption_box);
660 void linphone_gtk_in_call_view_set_in_call(LinphoneCall *call){
661 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
662 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
663 GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
664 GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
665 guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
666 gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
667 GtkWidget *call_stats=(GtkWidget*)g_object_get_data(G_OBJECT(callview),"call_stats");
669 display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
671 gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
672 gtk_label_set_markup(GTK_LABEL(status),in_conf ? _("In conference") : _("<b>In call</b>"));
674 gtk_widget_set_sensitive(linphone_gtk_get_widget(callview,"conference_button"),!in_conf);
675 gtk_widget_set_sensitive(linphone_gtk_get_widget(callview,"transfer_button"),!in_conf);
677 gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
678 linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PLAY,TRUE);
679 update_tab_header(call,FALSE);
680 linphone_gtk_enable_mute_button(
681 GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),TRUE);
684 taskid=g_timeout_add(250,(GSourceFunc)linphone_gtk_in_call_view_refresh,call);
685 g_object_set_data(G_OBJECT(callview),"taskid",GINT_TO_POINTER(taskid));
687 linphone_gtk_in_call_view_enable_audio_view(call, !in_conf);
688 linphone_gtk_in_call_view_show_encryption(call);
690 linphone_gtk_set_in_conference(call);
691 gtk_widget_set_sensitive(linphone_gtk_get_widget(callview,"incall_mute"),FALSE);
693 gtk_widget_show_all(linphone_gtk_get_widget(callview,"buttons_panel"));
694 if (!in_conf) gtk_widget_show_all(linphone_gtk_get_widget(callview,"record_hbox"));
695 else gtk_widget_hide(linphone_gtk_get_widget(callview,"record_hbox"));
696 if (call_stats) show_used_codecs(call_stats,call);
699 void linphone_gtk_in_call_view_set_paused(LinphoneCall *call){
700 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
701 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
702 gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
703 gtk_label_set_markup(GTK_LABEL(status),_("<b>Paused call</b>"));
705 linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PAUSE,TRUE);
708 void linphone_gtk_in_call_view_update_duration(LinphoneCall *call){
709 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
710 GtkWidget *duration_label=linphone_gtk_get_widget(callview,"in_call_duration");
711 int duration=linphone_call_get_duration(call);
713 int seconds=duration%60;
714 int minutes=(duration/60)%60;
715 int hours=duration/3600;
716 snprintf(tmp,sizeof(tmp)-1,_("%02i::%02i::%02i"),hours,minutes,seconds);
717 gtk_label_set_text(GTK_LABEL(duration_label),tmp);
720 static gboolean in_call_view_terminated(LinphoneCall *call){
721 linphone_gtk_remove_in_call_view(call);
725 void linphone_gtk_in_call_view_terminate(LinphoneCall *call, const char *error_msg){
726 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
727 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
728 guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
729 gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
731 if ((callview==NULL) || (status==NULL)) return;
733 gtk_label_set_markup(GTK_LABEL(status),_("<b>Call ended.</b>"));
735 char *msg=g_markup_printf_escaped("<span color=\"red\"><b>%s</b></span>",error_msg);
736 gtk_label_set_markup(GTK_LABEL(status),msg);
739 linphone_gtk_in_call_set_animation_image(callview,
740 linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"),FALSE);
742 gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
743 gtk_widget_hide(linphone_gtk_get_widget(callview,"record_hbox"));
744 gtk_widget_hide(linphone_gtk_get_widget(callview,"buttons_panel"));
745 gtk_widget_hide(linphone_gtk_get_widget(callview,"incall_audioview"));
746 linphone_gtk_enable_mute_button(
747 GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),FALSE);
748 linphone_gtk_enable_hold_button(call,FALSE,TRUE);
750 if (taskid!=0) g_source_remove(taskid);
751 g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,call);
753 linphone_gtk_terminate_conference_participant(call);
756 void linphone_gtk_in_call_view_set_transfer_status(LinphoneCall *call,LinphoneCallState cstate){
757 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
759 GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
760 const char *transfer_status="unknown";
762 case LinphoneCallOutgoingProgress:
763 transfer_status=_("Transfer in progress");
765 case LinphoneCallConnected:
766 transfer_status=_("Transfer done.");
768 case LinphoneCallError:
769 transfer_status=_("Transfer failed.");
774 gtk_label_set_text(GTK_LABEL(duration),transfer_status);
778 void linphone_gtk_draw_mute_button(GtkButton *button, gboolean active){
779 g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
781 GtkWidget *image=create_pixmap("mic_muted.png");
782 /*gtk_button_set_label(GTK_BUTTON(button),_("Unmute"));*/
784 gtk_button_set_image(GTK_BUTTON(button),image);
785 gtk_widget_show(image);
788 GtkWidget *image=create_pixmap("mic_active.png");
789 /*gtk_button_set_label(GTK_BUTTON(button),_("Mute"));*/
791 gtk_button_set_image(GTK_BUTTON(button),image);
792 gtk_widget_show(image);
797 void linphone_gtk_mute_clicked(GtkButton *button){
798 int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
799 linphone_core_mute_mic(linphone_gtk_get_core(),!active);
800 linphone_gtk_draw_mute_button(button,!active);
803 void linphone_gtk_enable_mute_button(GtkButton *button, gboolean sensitive){
804 /*gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);*/
805 gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
806 linphone_gtk_draw_mute_button(button,FALSE);
809 void linphone_gtk_draw_hold_button(GtkButton *button, gboolean active){
810 g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
812 GtkWidget *image=create_pixmap("hold_off.png");
813 gtk_button_set_label(GTK_BUTTON(button),_("Resume"));
815 gtk_button_set_image(GTK_BUTTON(button),image);
816 gtk_widget_show(image);
819 GtkWidget *image=create_pixmap("hold_on.png");
820 gtk_button_set_label(GTK_BUTTON(button),_("Pause"));
822 gtk_button_set_image(GTK_BUTTON(button),image);
823 gtk_widget_show(image);
828 void linphone_gtk_hold_clicked(GtkButton *button){
829 int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
830 LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
831 update_tab_header(call,active);
835 linphone_core_pause_call(linphone_gtk_get_core(),call);
839 linphone_core_resume_call(linphone_gtk_get_core(),call);
843 void linphone_gtk_enable_hold_button(LinphoneCall *call, gboolean sensitive, gboolean holdon){
844 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer (call);
846 g_return_if_fail(callview!=NULL);
847 update_tab_header(call,!holdon);
848 button=linphone_gtk_get_widget(callview,"hold_call");
849 gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
850 gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
851 linphone_gtk_draw_hold_button(GTK_BUTTON(button),!holdon);
854 void linphone_gtk_call_statistics_closed(GtkWidget *call_stats){
855 gtk_widget_destroy(call_stats);
858 void linphone_gtk_record_call_toggled(GtkWidget *button){
859 gboolean active=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
860 LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
861 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer (call);
862 const LinphoneCallParams *params=linphone_call_get_current_params(call);
863 const char *filepath=linphone_call_params_get_record_file(params);
864 gchar *message=g_strdup_printf(_("<small><i>Recording into %s %s</i></small>"),filepath,active ? "" : _("(Paused)"));
867 linphone_call_start_recording(call);
869 linphone_call_stop_recording(call);
871 gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(callview,"record_status")),message);