]> sjero.net Git - linphone/blob - gtk/incall_view.c
Merge branch 'master' of belledonne-communications.com:linphone-private
[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(){
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;
46         }else{
47                 int idx=gtk_notebook_get_current_page (notebook);
48                 GtkWidget *page=gtk_notebook_get_nth_page(notebook,idx);
49                 if (page!=NULL){
50                         LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(page),"call");
51                         return call;
52                 }
53         }
54         return NULL;
55 }
56
57 static GtkWidget *make_tab_header(int number){
58         GtkWidget *w=gtk_hbox_new (FALSE,0);
59         GtkWidget *i=create_pixmap ("status-green.png");
60         GtkWidget *l;
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);
66         return w;
67 }
68
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;
74         int idx;
75
76         if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){
77                 /*this is the only call at this time */
78                 call_index=1;
79         }
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);
87         call_index++;
88 }
89
90 void linphone_gtk_remove_in_call_view(LinphoneCall *call){
91         GtkWidget *w=(GtkWidget*)linphone_call_get_user_pointer (call);
92         GtkWidget *main_window=linphone_gtk_get_main_window ();
93         GtkWidget *nb=linphone_gtk_get_widget(main_window,"viewswitch");
94         int idx;
95         g_return_if_fail(w!=NULL);
96         idx=gtk_notebook_page_num(GTK_NOTEBOOK(nb),w);
97         gtk_notebook_remove_page (GTK_NOTEBOOK(nb),idx);
98         gtk_widget_destroy(w);
99         linphone_call_set_user_pointer (call,NULL);
100         linphone_call_unref(call);
101         gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), 0);
102 }
103
104 static void display_peer_name_in_label(GtkWidget *label, const LinphoneAddress *from){
105         const char *displayname=NULL;
106         const char *id;
107         char *uri_label;
108         displayname=linphone_address_get_display_name(from);
109         id=linphone_address_as_string_uri_only(from);
110         
111         if (displayname!=NULL){
112                 uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>", 
113                         displayname,id);
114         }else
115                 uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
116         gtk_label_set_markup(GTK_LABEL(label),uri_label);
117         g_free(uri_label);
118 }
119
120 void linphone_gtk_in_call_view_set_calling(LinphoneCall *call){
121         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
122         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
123         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
124         GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
125         GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
126         GdkPixbufAnimation *pbuf=create_pixbuf_animation("calling_anim.gif");
127         
128         gtk_label_set_markup(GTK_LABEL(status),_("<b>Calling...</b>"));
129         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
130         
131         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
132         if (pbuf!=NULL){
133                 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
134                 g_object_unref(G_OBJECT(pbuf));
135         }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_FIND,GTK_ICON_SIZE_DIALOG);
136 }
137
138 void linphone_gtk_in_call_view_set_incoming(LinphoneCall *call, bool_t with_pause){
139         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
140         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
141         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
142         GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
143         GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
144         GdkPixbufAnimation *pbuf=create_pixbuf_animation("calling_anim.gif");
145         GtkWidget *answer_button;
146
147         gtk_label_set_markup(GTK_LABEL(status),_("<b>Incoming call</b>"));
148         gtk_widget_show_all(linphone_gtk_get_widget(callview,"answer_decline_panel"));
149         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
150
151         answer_button=linphone_gtk_get_widget(callview,"accept_call");
152         gtk_button_set_image(GTK_BUTTON(answer_button),
153                          create_pixmap (linphone_gtk_get_ui_config("start_call_icon","startcall-green.png")));
154         if (with_pause){
155                 gtk_button_set_label(GTK_BUTTON(answer_button),
156                                      _("Pause all calls\nand answer"));
157         }else gtk_button_set_label(GTK_BUTTON(answer_button),_("Answer"));
158         gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(callview,"decline_call")),
159                          create_pixmap (linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png")));
160         
161         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
162         if (pbuf!=NULL){
163                 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
164                 g_object_unref(G_OBJECT(pbuf));
165         }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_EXECUTE,GTK_ICON_SIZE_DIALOG);
166 }
167
168 void linphone_gtk_in_call_view_set_in_call(LinphoneCall *call){
169         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
170         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
171         GtkWidget *callee=linphone_gtk_get_widget(callview,"in_call_uri");
172         GtkWidget *duration=linphone_gtk_get_widget(callview,"in_call_duration");
173         GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
174         GdkPixbufAnimation *pbuf=create_pixbuf_animation("incall_anim.gif");
175         GtkWidget *holdbutton;
176         
177         display_peer_name_in_label(callee,linphone_call_get_remote_address (call));
178
179         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
180         gtk_label_set_markup(GTK_LABEL(status),_("<b>In call with</b>"));
181
182         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
183         if (pbuf!=NULL){
184                 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
185                 g_object_unref(G_OBJECT(pbuf));
186         }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_EXECUTE,GTK_ICON_SIZE_DIALOG);
187         linphone_gtk_enable_mute_button(
188                                         GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),TRUE);
189         holdbutton=linphone_gtk_get_widget(callview,"hold_call");
190         linphone_gtk_enable_hold_button(GTK_TOGGLE_BUTTON(holdbutton),TRUE);
191         g_object_set_data(G_OBJECT(holdbutton),"call",call);
192 }
193
194 void linphone_gtk_in_call_view_set_paused(LinphoneCall *call){
195         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
196         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
197         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
198         gtk_label_set_markup(GTK_LABEL(status),_("<b>Paused call with</b>"));
199 }
200
201 void linphone_gtk_in_call_view_update_duration(LinphoneCall *call){
202         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
203         GtkWidget *duration_label=linphone_gtk_get_widget(callview,"in_call_duration");
204         int duration=linphone_call_get_duration(call);
205         char tmp[256]={0};
206         int seconds=duration%60;
207         int minutes=(duration/60)%60;
208         int hours=duration/3600;
209         snprintf(tmp,sizeof(tmp)-1,_("%02i::%02i::%02i"),hours,minutes,seconds);
210         gtk_label_set_text(GTK_LABEL(duration_label),tmp);
211 }
212
213 static gboolean in_call_view_terminated(LinphoneCall *call){
214         linphone_gtk_remove_in_call_view(call);
215         return FALSE;
216 }
217
218 void linphone_gtk_in_call_view_terminate(LinphoneCall *call, const char *error_msg){
219         GtkWidget *callview=(GtkWidget*)linphone_call_get_user_pointer(call);
220         GtkWidget *status=linphone_gtk_get_widget(callview,"in_call_status");
221         GtkWidget *animation=linphone_gtk_get_widget(callview,"in_call_animation");
222         GdkPixbuf *pbuf=create_pixbuf(linphone_gtk_get_ui_config("stop_call_icon","stopcall-red.png"));
223
224         if (error_msg==NULL)
225                 gtk_label_set_markup(GTK_LABEL(status),_("<b>Call ended.</b>"));
226         else{
227                 char *msg=g_markup_printf_escaped("<span color=\"red\"><b>%s</b></span>",error_msg);
228                 gtk_label_set_markup(GTK_LABEL(status),msg);
229                 g_free(msg);
230         }
231         if (pbuf!=NULL){
232                 gtk_image_set_from_pixbuf(GTK_IMAGE(animation),pbuf);
233                 g_object_unref(G_OBJECT(pbuf));
234         }
235         gtk_widget_hide(linphone_gtk_get_widget(callview,"answer_decline_panel"));
236         linphone_gtk_enable_mute_button(
237                 GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(callview,"incall_mute")),FALSE);
238         linphone_gtk_enable_hold_button(
239                 GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(callview,"hold_call")),FALSE);
240         g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,call);
241 }
242
243 void linphone_gtk_draw_mute_button(GtkToggleButton *button, gboolean active){
244         if (active){
245                 GtkWidget *image=create_pixmap("mic_muted.png");
246                 gtk_button_set_label(GTK_BUTTON(button),_("Unmute"));
247                 if (image!=NULL) {
248                         gtk_button_set_image(GTK_BUTTON(button),image);
249                         gtk_widget_show(image);
250                 }
251         }else{
252                 GtkWidget *image=create_pixmap("mic_active.png");
253                 gtk_button_set_label(GTK_BUTTON(button),_("Mute"));
254                 if (image!=NULL) {
255                         gtk_button_set_image(GTK_BUTTON(button),image);
256                         gtk_widget_show(image);
257                 }
258         }
259 }
260
261 void linphone_gtk_mute_toggled(GtkToggleButton *button){
262         gboolean active=gtk_toggle_button_get_active(button);
263         linphone_core_mute_mic(linphone_gtk_get_core(),active);
264         linphone_gtk_draw_mute_button(button,active);
265 }
266
267 void linphone_gtk_enable_mute_button(GtkToggleButton *button, gboolean sensitive)
268 {
269         gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
270         linphone_gtk_draw_mute_button(button,FALSE);
271 }
272
273 void linphone_gtk_draw_hold_button(GtkToggleButton *button, gboolean active){
274         if (active){
275                 GtkWidget *image=create_pixmap("hold_off.png");
276                 gtk_button_set_label(GTK_BUTTON(button),_("Resume"));
277                 if (image!=NULL) {
278                         gtk_button_set_image(GTK_BUTTON(button),image);
279                         gtk_widget_show(image);
280                 }
281         }else{
282                 GtkWidget *image=create_pixmap("hold_on.png");
283                 gtk_button_set_label(GTK_BUTTON(button),_("Pause"));
284                 if (image!=NULL) {
285                         gtk_button_set_image(GTK_BUTTON(button),image);
286                         gtk_widget_show(image);
287                 }
288         }
289 }
290
291 void linphone_gtk_hold_toggled(GtkToggleButton *button){
292         gboolean active=gtk_toggle_button_get_active(button);
293         LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(button),"call");
294         if(active)
295         {
296                 linphone_core_pause_call(linphone_gtk_get_core(),call);
297         }
298         else
299         {
300                 linphone_core_resume_call(linphone_gtk_get_core(),call);
301         }
302         linphone_gtk_draw_hold_button(button,active);
303 }
304
305 void linphone_gtk_enable_hold_button(GtkToggleButton *button, gboolean sensitive){
306         gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
307         linphone_gtk_draw_hold_button(button,FALSE);
308 }