incall_view.c 25 KB
Newer Older
smorlat's avatar
smorlat committed
1
/*
smorlat's avatar
smorlat committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
linphone, gtk-glade interface.
Copyright (C) 2009  Simon MORLAT (simon.morlat@linphone.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
/*
smorlat's avatar
smorlat committed
20 21 22 23 24 25 26 27 28 29 30 31
*  C Implementation: incall_frame
*
* Description: 
*
*
* Author: Simon Morlat <simon.morlat@linphone.org>, (C) 2009
*
*
*/

#include "linphone.h"

smorlat's avatar
smorlat committed
32

smorlat's avatar
smorlat committed
33 34 35 36 37 38
gboolean linphone_gtk_use_in_call_view(){
	static int val=-1;
	if (val==-1) val=linphone_gtk_get_ui_config_int("use_incall_view",1);
	return val;
}

39
LinphoneCall *linphone_gtk_get_currently_displayed_call(gboolean *is_conf){
40 41
	LinphoneCore *lc=linphone_gtk_get_core();
	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 46 47 48 49 50 51
	if (!linphone_gtk_use_in_call_view() || ms_list_size(calls)==1){
		if (calls) return (LinphoneCall*)calls->data;
	}else{
		int idx=gtk_notebook_get_current_page (notebook);
		GtkWidget *page=gtk_notebook_get_nth_page(notebook,idx);
		if (page!=NULL){
			LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(page),"call");
52 53 54 55 56 57 58
			if (call==NULL){
				if (page==g_object_get_data(G_OBJECT(main_window),"conference_tab")){
					if (is_conf)
						*is_conf=TRUE;
					return NULL;
				}
			}
59 60
			return call;
		}
61
	}
62
	return NULL;
smorlat's avatar
smorlat committed
63 64
}

65 66 67 68
static GtkWidget *make_tab_header(int number){
	GtkWidget *w=gtk_hbox_new (FALSE,0);
	GtkWidget *i=create_pixmap ("status-green.png");
	GtkWidget *l;
69
	gchar *text=g_strdup_printf(_("Call #%i"),number);
70 71 72 73 74 75 76
	l=gtk_label_new (text);
	gtk_box_pack_start (GTK_BOX(w),i,FALSE,FALSE,0);
	gtk_box_pack_end(GTK_BOX(w),l,TRUE,TRUE,0);
	gtk_widget_show_all(w);
	return w;
}

77 78 79 80
static void linphone_gtk_in_call_set_animation_image(GtkWidget *callview, const char *image_name, gboolean is_stock){
	GtkWidget *container=linphone_gtk_get_widget(callview,"in_call_animation");
	GList *elem=gtk_container_get_children(GTK_CONTAINER(container));
	GtkWidget *image;
Simon Morlat's avatar
Simon Morlat committed
81 82 83 84 85
	
	if (!is_stock){
		if (image_name==NULL){
			gtk_widget_hide(container);
		}
86
		image=create_pixmap(image_name);
Simon Morlat's avatar
Simon Morlat committed
87
	}else
88 89 90 91 92
		image=gtk_image_new_from_stock(image_name,GTK_ICON_SIZE_DIALOG);
	if (elem)
		gtk_widget_destroy((GtkWidget*)elem->data);
	gtk_widget_show(image);
	gtk_container_add(GTK_CONTAINER(container),image);
Simon Morlat's avatar
Simon Morlat committed
93
	gtk_widget_show_all(container);
94 95 96
}

static void linphone_gtk_in_call_set_animation_spinner(GtkWidget *callview){
jehan's avatar
jehan committed
97
#if GTK_CHECK_VERSION(2,20,0)
98 99 100 101 102 103 104
	GtkWidget *container=linphone_gtk_get_widget(callview,"in_call_animation");
	GList *elem=gtk_container_get_children(GTK_CONTAINER(container));
	GtkWidget *spinner=gtk_spinner_new();
	if (elem)
		gtk_widget_destroy((GtkWidget*)elem->data);
	gtk_widget_show(spinner);
	gtk_container_add(GTK_CONTAINER(container),spinner);
Simon Morlat's avatar
Simon Morlat committed
105
	gtk_widget_set_size_request(spinner, 20,20);
106
	gtk_spinner_start(GTK_SPINNER(spinner));
jehan's avatar
jehan committed
107
#endif
108 109 110
}


111
static void linphone_gtk_transfer_call(LinphoneCall *dest_call){
112 113
	LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
	if (call) linphone_core_transfer_call_to_another(linphone_gtk_get_core(),call,dest_call);
114 115 116 117 118 119 120 121 122 123 124 125 126 127
}

static void transfer_button_clicked(GtkWidget *button, gpointer call_ref){
	GtkWidget *menu_item;
	GtkWidget *menu=gtk_menu_new();
	LinphoneCall *call=(LinphoneCall*)call_ref;
	LinphoneCore *lc=linphone_gtk_get_core();
	const MSList *elem=linphone_core_get_calls(lc);
	
	for(;elem!=NULL;elem=elem->next){
		LinphoneCall *other_call=(LinphoneCall*)elem->data;
		GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(other_call);
		if (other_call!=call){
			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 131 132 133 134 135 136 137 138 139 140 141 142 143
			menu_item=gtk_image_menu_item_new_with_label(text);
			ms_free(remote_uri);
			g_free(text);
			gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),create_pixmap("status-green.png"));
			gtk_widget_show(menu_item);
			gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item);
			g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_transfer_call,other_call);
		}
	}
	gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,
		gtk_get_current_event_time());
	gtk_widget_show(menu);
}

144 145


146 147 148 149 150 151 152 153 154 155 156 157
void linphone_gtk_enable_transfer_button(LinphoneCore *lc, gboolean value){
	const MSList *elem=linphone_core_get_calls(lc);
	for(;elem!=NULL;elem=elem->next){
		LinphoneCall *call=(LinphoneCall*)elem->data;
		GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
		GtkWidget *box=linphone_gtk_get_widget (call_view,"mute_pause_buttons");
		GtkWidget *button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"transfer");
		if (button && value==FALSE){
			gtk_widget_destroy(button);
			button=NULL;
		}else if (!button && value==TRUE){
			button=gtk_button_new_with_label (_("Transfer"));
158
			//gtk_button_set_image_position(GTK_BUTTON(button),GTK_POS_BOTTOM);
159 160 161 162 163 164 165 166 167
			gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,GTK_ICON_SIZE_BUTTON));
			g_signal_connect(G_OBJECT(button),"clicked",(GCallback)transfer_button_clicked,call);
			gtk_widget_show_all(button);
			gtk_container_add(GTK_CONTAINER(box),button);
		}
		g_object_set_data(G_OBJECT(box),"transfer",button);
	}
}

168
static void conference_button_clicked(GtkWidget *button, gpointer call_ref){
169 170
	linphone_core_add_all_to_conference(linphone_gtk_get_core());
	//linphone_core_add_to_conference(linphone_gtk_get_core(),(LinphoneCall*)call_ref);
171
	gtk_widget_set_sensitive(button,FALSE);
172 173 174 175 176 177 178 179 180 181 182 183 184 185
}

void linphone_gtk_enable_conference_button(LinphoneCore *lc, gboolean value){
	const MSList *elem=linphone_core_get_calls(lc);
	for(;elem!=NULL;elem=elem->next){
		LinphoneCall *call=(LinphoneCall*)elem->data;
		GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
		GtkWidget *box=linphone_gtk_get_widget (call_view,"mute_pause_buttons");
		GtkWidget *button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"conference");
		if (button && value==FALSE){
			gtk_widget_destroy(button);
			button=NULL;
		}else if (!button && value==TRUE){
			button=gtk_button_new_with_label (_("Conference"));
186
			//gtk_button_set_image_position(GTK_BUTTON(button),GTK_POS_BOTTOM);
187 188 189 190 191 192 193 194 195
			gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_stock (GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON));
			g_signal_connect(G_OBJECT(button),"clicked",(GCallback)conference_button_clicked,call);
			gtk_widget_show_all(button);
			gtk_container_add(GTK_CONTAINER(box),button);
		}
		g_object_set_data(G_OBJECT(box),"conference",button);
	}
}

196 197 198
void linphone_gtk_create_in_call_view(LinphoneCall *call){
	GtkWidget *call_view=linphone_gtk_create_widget("main","in_call_frame");
	GtkWidget *main_window=linphone_gtk_get_main_window ();
199
	GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
200 201
	static int call_index=1;
	int idx;
Simon Morlat's avatar
Simon Morlat committed
202 203 204 205 206

	if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){
		/*this is the only call at this time */
		call_index=1;
	}
207
	g_object_set_data(G_OBJECT(call_view),"call",call);
208 209
	g_object_set_data(G_OBJECT(call_view),"call_index",GINT_TO_POINTER(call_index));

210 211 212 213 214 215 216
	linphone_call_set_user_pointer (call,call_view);
	linphone_call_ref(call);
	gtk_notebook_append_page (notebook,call_view,make_tab_header(call_index));
	gtk_widget_show(call_view);
	idx = gtk_notebook_page_num(notebook, call_view);
	gtk_notebook_set_current_page(notebook, idx);
	call_index++;
Simon Morlat's avatar
Simon Morlat committed
217 218 219
	linphone_gtk_enable_hold_button (call,FALSE,TRUE);
	linphone_gtk_enable_mute_button(
					GTK_BUTTON(linphone_gtk_get_widget(call_view,"incall_mute")),FALSE);
220
}
221

222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
static void video_button_clicked(GtkWidget *button, LinphoneCall *call){
	gboolean adding=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"adding_video"));
	LinphoneCore *lc=linphone_call_get_core(call);
	LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call));
	gtk_widget_set_sensitive(button,FALSE);
	linphone_call_params_enable_video(params,adding);
	linphone_core_update_call(lc,call,params);
	linphone_call_params_destroy(params);
}

void linphone_gtk_update_video_button(LinphoneCall *call){
	GtkWidget *call_view=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *button=linphone_gtk_get_widget(call_view,"video_button");
	const LinphoneCallParams *params=linphone_call_get_current_params(call);
	gboolean has_video=linphone_call_params_video_enabled(params);

	gtk_button_set_image(GTK_BUTTON(button),
	   gtk_image_new_from_stock(has_video ? GTK_STOCK_REMOVE : GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON));
	g_object_set_data(G_OBJECT(button),"adding_video",GINT_TO_POINTER(!has_video));
	if (!linphone_core_video_supported(linphone_call_get_core(call))){
		gtk_widget_set_sensitive(button,FALSE);
		return;
	}
	if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"signal_connected"))==0){
		g_signal_connect(G_OBJECT(button),"clicked",(GCallback)video_button_clicked,call);
		g_object_set_data(G_OBJECT(button),"signal_connected",GINT_TO_POINTER(1));
	}
	gtk_widget_set_sensitive(button,linphone_call_get_state(call)==LinphoneCallStreamsRunning);
}

252 253 254 255
void linphone_gtk_remove_in_call_view(LinphoneCall *call){
	GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer (call);
	GtkWidget *main_window=linphone_gtk_get_main_window ();
	GtkWidget *nb=linphone_gtk_get_widget(main_window,"viewswitch");
256
	gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
257 258 259 260 261
	int idx;
	g_return_if_fail(w!=NULL);
	idx=gtk_notebook_page_num(GTK_NOTEBOOK(nb),w);
	gtk_notebook_remove_page (GTK_NOTEBOOK(nb),idx);
	gtk_widget_destroy(w);
262 263 264
	if (in_conf){
		linphone_gtk_unset_from_conference(call);
	}
265 266
	linphone_call_set_user_pointer (call,NULL);
	linphone_call_unref(call);
267 268 269 270 271 272 273 274 275 276 277 278
	call=linphone_core_get_current_call(linphone_gtk_get_core());
	if (call==NULL){
		if (linphone_core_is_in_conference(linphone_gtk_get_core())){
			/*show the conference*/
			gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
		                            g_object_get_data(G_OBJECT(main_window),"conference_tab")));
		}else gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), 0);
	}else{
		/*show the active call*/
		gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),gtk_notebook_page_num(GTK_NOTEBOOK(nb),
		                                                                     linphone_call_get_user_pointer(call)));
	}
smorlat's avatar
smorlat committed
279 280
}

281
static void display_peer_name_in_label(GtkWidget *label, const LinphoneAddress *from){
282
	const char *displayname=NULL;
283
	const char *id;
smorlat's avatar
smorlat committed
284
	char *uri_label;
285 286 287
	displayname=linphone_address_get_display_name(from);
	id=linphone_address_as_string_uri_only(from);
	
288
	if (displayname!=NULL){
smorlat's avatar
smorlat committed
289 290
		uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>", 
			displayname,id);
291
	}else
smorlat's avatar
smorlat committed
292 293 294 295 296
		uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
	gtk_label_set_markup(GTK_LABEL(label),uri_label);
	g_free(uri_label);
}

297 298 299 300 301 302
void linphone_gtk_in_call_view_set_calling(LinphoneCall *call){
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
	GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
	GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
	
smorlat's avatar
smorlat committed
303
	gtk_label_set_markup(GTK_LABEL(status),_("<b>Calling...</b>"));
304
	display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
smorlat's avatar
smorlat committed
305
	
306
	gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
307
	linphone_gtk_in_call_set_animation_spinner(callview);
smorlat's avatar
smorlat committed
308 309
}

310
void linphone_gtk_in_call_view_set_incoming(LinphoneCall *call){
311 312 313
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
	GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
Simon Morlat's avatar
Simon Morlat committed
314
	GtkWidget *answer_button;
Simon Morlat's avatar
Simon Morlat committed
315
	GtkWidget *image;
316 317 318

	gtk_label_set_markup(GTK_LABEL(status),_("<b>Incoming call</b>"));
	gtk_widget_show_all(linphone_gtk_get_widget(callview,"answer_decline_panel"));
Simon Morlat's avatar
Simon Morlat committed
319
	gtk_widget_hide(linphone_gtk_get_widget(callview,"mute_pause_buttons"));
320 321
	display_peer_name_in_label(callee,linphone_call_get_remote_address (call));

Simon Morlat's avatar
Simon Morlat committed
322
	answer_button=linphone_gtk_get_widget(callview,"accept_call");
Simon Morlat's avatar
Simon Morlat committed
323
	image=create_pixmap (linphone_gtk_get_ui_config("start_call_icon","startcall-green.png"));
324
	gtk_button_set_label(GTK_BUTTON(answer_button),_("Answer"));
Simon Morlat's avatar
Simon Morlat committed
325 326 327 328 329 330
	gtk_button_set_image(GTK_BUTTON(answer_button),image);
	gtk_widget_show(image);
	
	image=create_pixmap (linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"));
	gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(callview,"decline_call")),image);
	gtk_widget_show(image);
331
	
332
	linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_DIALOG_INFO,TRUE);
333 334
}

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
static void rating_to_color(float rating, GdkColor *color){
	const char *colorname="grey";
	if (rating>=4.0)
		colorname="green";
	else if (rating>=3.0)
		colorname="white";
	else if (rating>=2.0)
		colorname="yellow";
	else if (rating>=1.0)
		colorname="orange";
	else if (rating>=0)
		colorname="red";
	if (!gdk_color_parse(colorname,color)){
		g_warning("Fail to parse color %s",colorname);
	}
}

static const char *rating_to_text(float rating){
	if (rating>=4.0)
		return _("good");
	if (rating>=3.0)
		return _("average");
	if (rating>=2.0)
		return _("poor");
	if (rating>=1.0)
		return _("very poor");
	if (rating>=0)
		return _("too bad");
	return _("unavailable");
}

static gboolean linphone_gtk_in_call_view_refresh(LinphoneCall *call){
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *qi=linphone_gtk_get_widget(callview,"quality_indicator");
	float rating=linphone_call_get_current_quality(call);
	GdkColor color;
	gchar tmp[50];
	linphone_gtk_in_call_view_update_duration(call);
	if (rating>=0){
		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),rating/5.0);
		snprintf(tmp,sizeof(tmp),"%.1f (%s)",rating,rating_to_text(rating));
		gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),tmp);
	}else{
		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(qi),0);
		gtk_progress_bar_set_text(GTK_PROGRESS_BAR(qi),_("unavailable"));
	}
	rating_to_color(rating,&color);
	gtk_widget_modify_bg(qi,GTK_STATE_NORMAL,&color);
	return TRUE;
}

386

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

typedef struct _volume_ctx{
	GtkWidget *widget;
	get_volume_t get_volume;
	void *data;
	float last_value;
}volume_ctx_t;

#define UNSIGNIFICANT_VOLUME (-26)
#define SMOOTH 0.15

static gboolean update_audio_meter(volume_ctx_t *ctx){
	float volume_db=ctx->get_volume(ctx->data);
	float frac=(volume_db-UNSIGNIFICANT_VOLUME)/(float)(-UNSIGNIFICANT_VOLUME+3.0);
	if (frac<0) frac=0;
	if (frac>1.0) frac=1.0;
	if (frac<ctx->last_value){
		frac=(frac*SMOOTH)+(ctx->last_value*(1-SMOOTH));
	}
	ctx->last_value=frac;
	//g_message("volume_db=%f, frac=%f",volume_db,frac);
	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ctx->widget),frac);
	return TRUE;
}

static void on_audio_meter_destroy(guint task_id){
	g_source_remove(task_id);
}

void linphone_gtk_init_audio_meter(GtkWidget *w, get_volume_t get_volume, void *data){
	guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
	if (task_id==0){
		volume_ctx_t *ctx=g_new(volume_ctx_t,1);
		ctx->widget=w;
		ctx->get_volume=get_volume;
		ctx->data=data;
		ctx->last_value=0;
		g_object_set_data_full(G_OBJECT(w),"ctx",ctx,g_free);
		task_id=g_timeout_add(50,(GSourceFunc)update_audio_meter,ctx);
		g_object_set_data_full(G_OBJECT(w),"task_id",GINT_TO_POINTER(task_id),(GDestroyNotify)on_audio_meter_destroy);
	}
}

430 431 432 433 434 435 436 437 438
void linphone_gtk_uninit_audio_meter(GtkWidget *w){
	guint task_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"task_id"));
	if (task_id!=0){
		g_object_set_data(G_OBJECT(w),"ctx",NULL);
		g_object_set_data(G_OBJECT(w),"task_id",NULL);
	}
}

void linphone_gtk_in_call_view_enable_audio_view(LinphoneCall *call, gboolean val){
439 440 441 442 443 444 445 446 447
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *audio_view=linphone_gtk_get_widget(callview,"incall_audioview");
	//GtkWidget *mic=linphone_gtk_get_widget(callview,"incall_mic_icon");
	GtkWidget *spk=linphone_gtk_get_widget(callview,"incall_spk_icon");
	GtkWidget *mic_level=linphone_gtk_get_widget(callview,"mic_audiolevel");
	GtkWidget *spk_level=linphone_gtk_get_widget(callview,"spk_audiolevel");
	GdkPixbuf *pbuf;
	//gtk_image_set_from_pixbuf(GTK_IMAGE(mic),(pbuf=create_pixbuf("mic_active.png")));
	//g_object_unref(pbuf);
448 449 450 451 452 453 454 455 456
	if (val){
		gtk_image_set_from_pixbuf(GTK_IMAGE(spk),(pbuf=create_pixbuf("speaker.png")));
		g_object_unref(pbuf);
		linphone_gtk_init_audio_meter(mic_level,(get_volume_t)linphone_call_get_record_volume,call);
		linphone_gtk_init_audio_meter(spk_level,(get_volume_t)linphone_call_get_play_volume,call);
		gtk_widget_show_all(audio_view);
	}else{
		linphone_gtk_uninit_audio_meter(mic_level);
		linphone_gtk_uninit_audio_meter(spk_level);
457
		gtk_widget_hide(audio_view);
458
	}
459 460
}

Simon Morlat's avatar
Simon Morlat committed
461 462 463 464 465 466 467 468
void linphone_gtk_auth_token_verified_clicked(GtkButton *button){
	LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
	if (call){
		linphone_call_set_authentication_token_verified(call,!linphone_call_get_authentication_token_verified(call));
	}
}

void linphone_gtk_in_call_view_show_encryption(LinphoneCall *call){
Simon Morlat's avatar
Simon Morlat committed
469 470 471
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *encryption_box=linphone_gtk_get_widget(callview,"encryption_box");
	GtkWidget *label=linphone_gtk_get_widget(callview,"encryption_label");
Simon Morlat's avatar
Simon Morlat committed
472 473
	GtkWidget *status_icon=linphone_gtk_get_widget(callview,"encryption_status_icon");
	GtkWidget *verify_button=linphone_gtk_get_widget(callview,"encryption_verify_button");
Simon Morlat's avatar
Simon Morlat committed
474
	LinphoneMediaEncryption me=linphone_call_params_get_media_encryption(linphone_call_get_current_params(call));
Simon Morlat's avatar
Simon Morlat committed
475
	bool_t verified=linphone_call_get_authentication_token_verified(call);
Simon Morlat's avatar
Simon Morlat committed
476 477
	switch(me){
		case LinphoneMediaEncryptionSRTP:
Simon Morlat's avatar
Simon Morlat committed
478
			gtk_widget_show_all(encryption_box);
Simon Morlat's avatar
Simon Morlat committed
479
			gtk_label_set_markup(GTK_LABEL(label),_("Secured by SRTP"));
Simon Morlat's avatar
Simon Morlat committed
480 481
			gtk_widget_hide(status_icon);
			gtk_widget_hide(verify_button);
Simon Morlat's avatar
Simon Morlat committed
482 483 484 485 486 487
		break;
		case LinphoneMediaEncryptionZRTP:
		{
			gchar *text=g_strdup_printf(_("Secured by ZRTP - [auth token: %s]"),linphone_call_get_authentication_token(call));
			gtk_label_set_markup(GTK_LABEL(label),text);
			g_free(text);
Simon Morlat's avatar
Simon Morlat committed
488 489 490 491
			gtk_image_set_from_stock(GTK_IMAGE(status_icon),
			                          verified ? GTK_STOCK_APPLY : GTK_STOCK_DIALOG_WARNING,GTK_ICON_SIZE_MENU);
			gtk_button_set_label(GTK_BUTTON(verify_button),
			                     verified ? _("Set unverified") : _("Set verified"));
Simon Morlat's avatar
Simon Morlat committed
492 493 494 495
			gtk_widget_show_all(encryption_box);
		}	
		break;
		default:
Simon Morlat's avatar
Simon Morlat committed
496
			gtk_widget_hide_all(encryption_box);
Simon Morlat's avatar
Simon Morlat committed
497 498 499
	}
}

500 501 502 503 504
void linphone_gtk_in_call_view_set_in_call(LinphoneCall *call){
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
	GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
	GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
505
	guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
506
	gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));
507 508
	
	display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
smorlat's avatar
smorlat committed
509

510
	gtk_widget_set_visible(linphone_gtk_get_widget(callview,"mute_pause_buttons"),!in_conf);
511
	gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
512
	gtk_label_set_markup(GTK_LABEL(status),in_conf ? _("In conference") : _("<b>In call</b>"));
smorlat's avatar
smorlat committed
513

smorlat's avatar
smorlat committed
514
	gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
515
	linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PLAY,TRUE);
smorlat's avatar
smorlat committed
516
	linphone_gtk_enable_mute_button(
517
					GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),!in_conf);
518 519 520 521
	if (taskid==0){
		taskid=g_timeout_add(250,(GSourceFunc)linphone_gtk_in_call_view_refresh,call);
		g_object_set_data(G_OBJECT(callview),"taskid",GINT_TO_POINTER(taskid));
	}
522
	linphone_gtk_in_call_view_enable_audio_view(call, !in_conf);
Simon Morlat's avatar
Simon Morlat committed
523
	linphone_gtk_in_call_view_show_encryption(call);
524
	if (in_conf) linphone_gtk_set_in_conference(call);
smorlat's avatar
smorlat committed
525 526
}

Simon Morlat's avatar
Simon Morlat committed
527 528 529 530
void linphone_gtk_in_call_view_set_paused(LinphoneCall *call){
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
	gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
Simon Morlat's avatar
Simon Morlat committed
531
	gtk_label_set_markup(GTK_LABEL(status),_("<b>Paused call</b>"));
532
	linphone_gtk_in_call_set_animation_image(callview,GTK_STOCK_MEDIA_PAUSE,TRUE);
Simon Morlat's avatar
Simon Morlat committed
533 534
}

535 536 537 538
void linphone_gtk_in_call_view_update_duration(LinphoneCall *call){
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *duration_label=linphone_gtk_get_widget(callview,"in_call_duration");
	int duration=linphone_call_get_duration(call);
smorlat's avatar
smorlat committed
539 540 541 542 543 544 545 546
	char tmp[256]={0};
	int seconds=duration%60;
	int minutes=(duration/60)%60;
	int hours=duration/3600;
	snprintf(tmp,sizeof(tmp)-1,_("%02i::%02i::%02i"),hours,minutes,seconds);
	gtk_label_set_text(GTK_LABEL(duration_label),tmp);
}

547 548
static gboolean in_call_view_terminated(LinphoneCall *call){
	linphone_gtk_remove_in_call_view(call);
smorlat's avatar
smorlat committed
549 550 551
	return FALSE;
}

552 553 554
void linphone_gtk_in_call_view_terminate(LinphoneCall *call, const char *error_msg){
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
	GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
555
	guint taskid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(callview),"taskid"));
556
	gboolean in_conf=linphone_call_params_local_conference_mode(linphone_call_get_current_params(call));	
smorlat's avatar
smorlat committed
557 558 559 560 561 562 563 564

	if (error_msg==NULL)
		gtk_label_set_markup(GTK_LABEL(status),_("<b>Call ended.</b>"));
	else{
		char *msg=g_markup_printf_escaped("<span color=\"red\"><b>%s</b></span>",error_msg);
		gtk_label_set_markup(GTK_LABEL(status),msg);
		g_free(msg);
	}
565 566 567
	linphone_gtk_in_call_set_animation_image(callview,
	           linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"),FALSE);
	
568
	gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
569
	gtk_widget_hide(linphone_gtk_get_widget(callview,"incall_audioview"));
smorlat's avatar
smorlat committed
570
	linphone_gtk_enable_mute_button(
Simon Morlat's avatar
Simon Morlat committed
571 572
		GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),FALSE);
	linphone_gtk_enable_hold_button(call,FALSE,TRUE);
573
	
574
	if (taskid!=0) g_source_remove(taskid);
575
	g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,call);
576 577
	if (in_conf)
		linphone_gtk_terminate_conference_participant(call);
smorlat's avatar
smorlat committed
578
}
smorlat's avatar
smorlat committed
579

Simon Morlat's avatar
Simon Morlat committed
580 581
void linphone_gtk_draw_mute_button(GtkButton *button, gboolean active){
	g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
smorlat's avatar
smorlat committed
582 583
	if (active){
		GtkWidget *image=create_pixmap("mic_muted.png");
584
		/*gtk_button_set_label(GTK_BUTTON(button),_("Unmute"));*/
585 586 587 588
		if (image!=NULL) {
			gtk_button_set_image(GTK_BUTTON(button),image);
			gtk_widget_show(image);
		}
smorlat's avatar
smorlat committed
589 590
	}else{
		GtkWidget *image=create_pixmap("mic_active.png");
591
		/*gtk_button_set_label(GTK_BUTTON(button),_("Mute"));*/
592 593 594 595
		if (image!=NULL) {
			gtk_button_set_image(GTK_BUTTON(button),image);
			gtk_widget_show(image);
		}
smorlat's avatar
smorlat committed
596 597 598
	}
}

Simon Morlat's avatar
Simon Morlat committed
599 600 601 602
void linphone_gtk_mute_clicked(GtkButton *button){
	int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
	linphone_core_mute_mic(linphone_gtk_get_core(),!active);
	linphone_gtk_draw_mute_button(button,!active);
smorlat's avatar
smorlat committed
603 604
}

Simon Morlat's avatar
Simon Morlat committed
605
void linphone_gtk_enable_mute_button(GtkButton *button, gboolean sensitive)
606
{
607 608
	/*gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);*/
	gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
smorlat's avatar
smorlat committed
609
	linphone_gtk_draw_mute_button(button,FALSE);
smorlat's avatar
smorlat committed
610
}
611

Simon Morlat's avatar
Simon Morlat committed
612 613
void linphone_gtk_draw_hold_button(GtkButton *button, gboolean active){
	g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
614 615
	if (active){
		GtkWidget *image=create_pixmap("hold_off.png");
616
		gtk_button_set_label(GTK_BUTTON(button),_("Resume"));
617 618 619 620 621 622
		if (image!=NULL) {
			gtk_button_set_image(GTK_BUTTON(button),image);
			gtk_widget_show(image);
		}
	}else{
		GtkWidget *image=create_pixmap("hold_on.png");
623
		gtk_button_set_label(GTK_BUTTON(button),_("Pause"));
624 625 626 627 628 629 630
		if (image!=NULL) {
			gtk_button_set_image(GTK_BUTTON(button),image);
			gtk_widget_show(image);
		}
	}
}

Simon Morlat's avatar
Simon Morlat committed
631 632
void linphone_gtk_hold_clicked(GtkButton *button){
	int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
633 634
	LinphoneCall *call=linphone_gtk_get_currently_displayed_call(NULL);
	if (!call) return;
Simon Morlat's avatar
Simon Morlat committed
635
	if(!active)
636
	{
Simon Morlat's avatar
Simon Morlat committed
637
		linphone_core_pause_call(linphone_gtk_get_core(),call);
638 639 640
	}
	else
	{
641
		linphone_core_resume_call(linphone_gtk_get_core(),call);
642 643 644
	}
}

Simon Morlat's avatar
Simon Morlat committed
645 646 647 648 649
void linphone_gtk_enable_hold_button(LinphoneCall *call, gboolean sensitive, gboolean holdon){
	GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer (call);
	GtkWidget *button;
	g_return_if_fail(callview!=NULL);
	button=linphone_gtk_get_widget(callview,"hold_call");
650
	gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
651
	gtk_widget_set_visible(GTK_WIDGET(button),sensitive);
Simon Morlat's avatar
Simon Morlat committed
652
	linphone_gtk_draw_hold_button(GTK_BUTTON(button),!holdon);
653
}