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(){
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 (!linphone_gtk_use_in_call_view() || ms_list_size(calls)==1){
45 if (calls) return (LinphoneCall*)calls->data;
47 int idx=gtk_notebook_get_current_page (notebook);
48 GtkWidget *page=gtk_notebook_get_nth_page(notebook,idx);
50 LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(page),"call");
57 static GtkWidget *make_tab_header(int number){
58 GtkWidget *w=gtk_hbox_new (FALSE,0);
59 GtkWidget *i=create_pixmap ("status-green.png");
61 gchar *text=g_strdup_printf("Call %i",number);
62 l=gtk_label_new (text);
63 gtk_box_pack_start (GTK_BOX(w),i,FALSE,FALSE,0);
64 gtk_box_pack_end(GTK_BOX(w),l,TRUE,TRUE,0);
65 gtk_widget_show_all(w);
69 void linphone_gtk_create_in_call_view(LinphoneCall *call){
70 GtkWidget *call_view=linphone_gtk_create_widget("main","in_call_frame");
71 GtkWidget *main_window=linphone_gtk_get_main_window ();
72 GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
73 static int call_index=1;
76 if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){
77 /*this is the only call at this time */
80 g_object_set_data(G_OBJECT(call_view),"call",call);
81 linphone_call_set_user_pointer (call,call_view);
82 linphone_call_ref(call);
83 gtk_notebook_append_page (notebook,call_view,make_tab_header(call_index));
84 gtk_widget_show(call_view);
85 idx = gtk_notebook_page_num(notebook, call_view);
86 gtk_notebook_set_current_page(notebook, idx);
88 linphone_gtk_enable_hold_button (call,FALSE,TRUE);
89 linphone_gtk_enable_mute_button(
90 GTK_BUTTON(linphone_gtk_get_widget(call_view,"incall_mute")),FALSE);
93 void linphone_gtk_remove_in_call_view(LinphoneCall *call){
94 GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer (call);
95 GtkWidget *main_window=linphone_gtk_get_main_window ();
96 GtkWidget *nb=linphone_gtk_get_widget(main_window,"viewswitch");
98 g_return_if_fail(w!=NULL);
99 idx=gtk_notebook_page_num(GTK_NOTEBOOK(nb),w);
100 gtk_notebook_remove_page (GTK_NOTEBOOK(nb),idx);
101 gtk_widget_destroy(w);
102 linphone_call_set_user_pointer (call,NULL);
103 linphone_call_unref(call);
104 gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), 0);
107 static void display_peer_name_in_label(GtkWidget *label, const LinphoneAddress *from){
108 const char *displayname=NULL;
111 displayname=linphone_address_get_display_name(from);
112 id=linphone_address_as_string_uri_only(from);
114 if (displayname!=NULL){
115 uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>",
118 uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
119 gtk_label_set_markup(GTK_LABEL(label),uri_label);
123 void linphone_gtk_in_call_view_set_calling(LinphoneCall *call){
124 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
125 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
126 GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
127 GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
128 GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
129 GdkPixbufAnimation *pbuf=create_pixbuf_animation("calling_anim.gif");
131 gtk_label_set_markup(GTK_LABEL(status),_("<b>Calling...</b>"));
132 display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
134 gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
136 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
137 g_object_unref(G_OBJECT(pbuf));
138 }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_FIND,GTK_ICON_SIZE_DIALOG);
141 void linphone_gtk_in_call_view_set_incoming(LinphoneCall *call, bool_t with_pause){
142 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
143 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
144 GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
145 GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
146 GdkPixbufAnimation *pbuf=create_pixbuf_animation("calling_anim.gif");
147 GtkWidget *answer_button;
149 gtk_label_set_markup(GTK_LABEL(status),_("<b>Incoming call</b>"));
150 gtk_widget_show_all(linphone_gtk_get_widget(callview,"answer_decline_panel"));
151 gtk_widget_hide(linphone_gtk_get_widget(callview,"duration_frame"));
152 gtk_widget_hide(linphone_gtk_get_widget(callview,"mute_pause_buttons"));
153 display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
155 answer_button=linphone_gtk_get_widget(callview,"accept_call");
156 gtk_button_set_image(GTK_BUTTON(answer_button),
157 create_pixmap (linphone_gtk_get_ui_config("start_call_icon","startcall-green.png")));
159 gtk_button_set_label(GTK_BUTTON(answer_button),
160 _("Pause all calls\nand answer"));
161 }else gtk_button_set_label(GTK_BUTTON(answer_button),_("Answer"));
162 gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(callview,"decline_call")),
163 create_pixmap (linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png")));
166 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
167 g_object_unref(G_OBJECT(pbuf));
168 }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_EXECUTE,GTK_ICON_SIZE_DIALOG);
171 void linphone_gtk_in_call_view_set_in_call(LinphoneCall *call){
172 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
173 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
174 GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
175 GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
176 GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
177 GdkPixbufAnimation *pbuf=create_pixbuf_animation("incall_anim.gif");
179 display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
181 gtk_widget_show(linphone_gtk_get_widget(callview,"duration_frame"));
182 gtk_widget_show(linphone_gtk_get_widget(callview,"mute_pause_buttons"));
183 gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
184 gtk_label_set_markup(GTK_LABEL(status),_("<b>In call</b>"));
186 gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
188 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
189 g_object_unref(G_OBJECT(pbuf));
190 }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_EXECUTE,GTK_ICON_SIZE_DIALOG);
191 linphone_gtk_enable_mute_button(
192 GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),TRUE);
195 void linphone_gtk_in_call_view_set_paused(LinphoneCall *call){
196 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
197 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
198 GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
199 gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
200 gtk_label_set_markup(GTK_LABEL(status),_("<b>Paused call</b>"));
201 gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_MEDIA_PAUSE,GTK_ICON_SIZE_DIALOG);
204 void linphone_gtk_in_call_view_update_duration(LinphoneCall *call){
205 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
206 GtkWidget *duration_label=linphone_gtk_get_widget(callview,"in_call_duration");
207 int duration=linphone_call_get_duration(call);
209 int seconds=duration%60;
210 int minutes=(duration/60)%60;
211 int hours=duration/3600;
212 snprintf(tmp,sizeof(tmp)-1,_("%02i::%02i::%02i"),hours,minutes,seconds);
213 gtk_label_set_text(GTK_LABEL(duration_label),tmp);
216 static gboolean in_call_view_terminated(LinphoneCall *call){
217 linphone_gtk_remove_in_call_view(call);
221 void linphone_gtk_in_call_view_terminate(LinphoneCall *call, const char *error_msg){
222 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
223 GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
224 GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
225 GdkPixbuf *pbuf=create_pixbuf(linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"));
228 gtk_label_set_markup(GTK_LABEL(status),_("<b>Call ended.</b>"));
230 char *msg=g_markup_printf_escaped("<span color=\"red\"><b>%s</b></span>",error_msg);
231 gtk_label_set_markup(GTK_LABEL(status),msg);
235 gtk_image_set_from_pixbuf(GTK_IMAGE(animation),pbuf);
236 g_object_unref(G_OBJECT(pbuf));
238 gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
239 linphone_gtk_enable_mute_button(
240 GTK_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),FALSE);
241 linphone_gtk_enable_hold_button(call,FALSE,TRUE);
242 g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,call);
245 void linphone_gtk_draw_mute_button(GtkButton *button, gboolean active){
246 g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
248 GtkWidget *image=create_pixmap("mic_muted.png");
249 gtk_button_set_label(GTK_BUTTON(button),_("Unmute"));
251 gtk_button_set_image(GTK_BUTTON(button),image);
252 gtk_widget_show(image);
255 GtkWidget *image=create_pixmap("mic_active.png");
256 gtk_button_set_label(GTK_BUTTON(button),_("Mute"));
258 gtk_button_set_image(GTK_BUTTON(button),image);
259 gtk_widget_show(image);
264 void linphone_gtk_mute_clicked(GtkButton *button){
265 int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
266 linphone_core_mute_mic(linphone_gtk_get_core(),!active);
267 linphone_gtk_draw_mute_button(button,!active);
270 void linphone_gtk_enable_mute_button(GtkButton *button, gboolean sensitive)
272 gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
273 linphone_gtk_draw_mute_button(button,FALSE);
276 void linphone_gtk_draw_hold_button(GtkButton *button, gboolean active){
277 g_object_set_data(G_OBJECT(button),"active",GINT_TO_POINTER(active));
279 GtkWidget *image=create_pixmap("hold_off.png");
280 gtk_button_set_label(GTK_BUTTON(button),_("Resume"));
282 gtk_button_set_image(GTK_BUTTON(button),image);
283 gtk_widget_show(image);
286 GtkWidget *image=create_pixmap("hold_on.png");
287 gtk_button_set_label(GTK_BUTTON(button),_("Pause"));
289 gtk_button_set_image(GTK_BUTTON(button),image);
290 gtk_widget_show(image);
295 void linphone_gtk_hold_clicked(GtkButton *button){
296 int active=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"active"));
297 LinphoneCall *call=linphone_gtk_get_currently_displayed_call ();
300 linphone_core_pause_call(linphone_gtk_get_core(),call);
304 linphone_core_resume_call(linphone_gtk_get_core(),call);
308 void linphone_gtk_enable_hold_button(LinphoneCall *call, gboolean sensitive, gboolean holdon){
309 GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer (call);
311 g_return_if_fail(callview!=NULL);
312 button=linphone_gtk_get_widget(callview,"hold_call");
313 gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
314 linphone_gtk_draw_hold_button(GTK_BUTTON(button),!holdon);