]> sjero.net Git - linphone/blob - gtk-glade/incall_view.c
1167c5ccd30c20a77204e718aca863f027f8a464
[linphone] / gtk-glade / 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 void linphone_gtk_show_in_call_view(void){
40         GtkWidget *main_window=linphone_gtk_get_main_window();
41         GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
42         GtkWidget *in_call_frame=linphone_gtk_get_widget(main_window,"in_call_frame");
43         gint idx;
44         
45         /* Make the in call frame visible and arrange for the notebook to
46                  show that page */
47         gtk_widget_show(in_call_frame);
48         idx = gtk_notebook_page_num(notebook, in_call_frame);
49         if (idx >= 0) {
50                 gtk_notebook_set_current_page(notebook, idx);
51         }
52 }
53
54 void linphone_gtk_show_idle_view(void){
55         GtkWidget *main_window=linphone_gtk_get_main_window();
56         GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch");
57         GtkWidget *idle_frame=linphone_gtk_get_widget(main_window,"idle_frame");
58         GtkWidget *in_call_frame=linphone_gtk_get_widget(main_window,"in_call_frame");
59         gint idx;
60
61         /* Switch back to the idle frame page, maybe we should have
62                  remembered where we were in gtk_show_in_call_view() to switch
63                  back to that page of the notebook, but this should do in most
64                  cases. */
65         gtk_widget_show(idle_frame); /* Make sure it is visible... */
66         idx = gtk_notebook_page_num(notebook, idle_frame);
67         if (idx >= 0) {
68                 gtk_notebook_set_current_page(notebook, idx);
69                 gtk_widget_hide(in_call_frame);
70         }
71 }
72
73 void display_peer_name_in_label(GtkWidget *label, const char *uri){
74         LinphoneAddress *from;
75         const char *displayname=NULL;
76         char *id=NULL;
77         char *uri_label;
78
79         if (uri==NULL) {
80                 ms_error("Strange: in call with nobody ?");
81                 return;
82         }
83
84         from=linphone_address_new(uri);
85         if (from!=NULL){
86                 
87                 if (linphone_address_get_display_name(from))
88                         displayname=linphone_address_get_display_name(from);
89
90                 id=linphone_address_as_string_uri_only(from);
91
92         }else id=ms_strdup(uri);
93
94         if (displayname!=NULL)
95                 uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>", 
96                         displayname,id);
97         else
98                 uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
99         gtk_label_set_markup(GTK_LABEL(label),uri_label);
100         ms_free(id);
101         g_free(uri_label);
102         if (from!=NULL) linphone_address_destroy(from);
103 }
104
105 void linphone_gtk_in_call_view_set_calling(const char *uri){
106         GtkWidget *main_window=linphone_gtk_get_main_window();
107         GtkWidget *status=linphone_gtk_get_widget(main_window,"in_call_status");
108         GtkWidget *callee=linphone_gtk_get_widget(main_window,"in_call_uri");
109         GtkWidget *duration=linphone_gtk_get_widget(main_window,"in_call_duration");
110         GtkWidget *animation=linphone_gtk_get_widget(main_window,"in_call_animation");
111         GdkPixbufAnimation *pbuf=create_pixbuf_animation("calling_anim.gif");
112
113         gtk_label_set_markup(GTK_LABEL(status),_("<b>Calling...</b>"));
114         display_peer_name_in_label(callee,uri);
115         
116         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
117         if (pbuf!=NULL){
118                 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
119                 g_object_unref(G_OBJECT(pbuf));
120         }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_INFO,GTK_ICON_SIZE_DIALOG);
121 }
122
123 void linphone_gtk_in_call_view_set_in_call(){
124         LinphoneCore *lc=linphone_gtk_get_core();
125         GtkWidget *main_window=linphone_gtk_get_main_window();
126         GtkWidget *status=linphone_gtk_get_widget(main_window,"in_call_status");
127         GtkWidget *callee=linphone_gtk_get_widget(main_window,"in_call_uri");
128         GtkWidget *duration=linphone_gtk_get_widget(main_window,"in_call_duration");
129         GtkWidget *animation=linphone_gtk_get_widget(main_window,"in_call_animation");
130         GdkPixbufAnimation *pbuf=create_pixbuf_animation("incall_anim.gif");
131         const LinphoneAddress *uri=linphone_core_get_remote_uri(lc);
132         char *tmp=linphone_address_as_string(uri);
133         display_peer_name_in_label(callee,tmp);
134         ms_free(tmp);
135
136         gtk_label_set_markup(GTK_LABEL(status),_("<b>In call with</b>"));
137
138         gtk_label_set_text(GTK_LABEL(duration),_("00::00::00"));
139         if (pbuf!=NULL){
140                 gtk_image_set_from_animation(GTK_IMAGE(animation),pbuf);
141                 g_object_unref(G_OBJECT(pbuf));
142         }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_INFO,GTK_ICON_SIZE_DIALOG);
143         linphone_gtk_enable_mute_button(
144                 GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,"incall_mute")),TRUE);
145 }
146
147 void linphone_gtk_in_call_view_update_duration(int duration){
148         GtkWidget *main_window=linphone_gtk_get_main_window();
149         GtkWidget *duration_label=linphone_gtk_get_widget(main_window,"in_call_duration");
150         char tmp[256]={0};
151         int seconds=duration%60;
152         int minutes=(duration/60)%60;
153         int hours=duration/3600;
154         snprintf(tmp,sizeof(tmp)-1,_("%02i::%02i::%02i"),hours,minutes,seconds);
155         gtk_label_set_text(GTK_LABEL(duration_label),tmp);
156 }
157
158 static gboolean in_call_view_terminated(){
159         linphone_gtk_show_idle_view();
160         return FALSE;
161 }
162
163 void linphone_gtk_in_call_view_terminate(const char *error_msg){
164         GtkWidget *main_window=linphone_gtk_get_main_window();
165         GtkWidget *status=linphone_gtk_get_widget(main_window,"in_call_status");
166         GtkWidget *animation=linphone_gtk_get_widget(main_window,"in_call_animation");
167         GdkPixbuf *pbuf=create_pixbuf(linphone_gtk_get_ui_config("stop_call_icon","red.png"));
168
169         if (error_msg==NULL)
170                 gtk_label_set_markup(GTK_LABEL(status),_("<b>Call ended.</b>"));
171         else{
172                 char *msg=g_markup_printf_escaped("<span color=\"red\"><b>%s</b></span>",error_msg);
173                 gtk_label_set_markup(GTK_LABEL(status),msg);
174                 g_free(msg);
175         }
176         if (pbuf!=NULL){
177                 gtk_image_set_from_pixbuf(GTK_IMAGE(animation),pbuf);
178                 g_object_unref(G_OBJECT(pbuf));
179         }
180         linphone_gtk_enable_mute_button(
181                 GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,"incall_mute")),FALSE);
182         g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,NULL);
183 }
184
185 void linphone_gtk_draw_mute_button(GtkToggleButton *button, gboolean active){
186         if (active){
187                 GtkWidget *image=create_pixmap("mic_muted.png");
188                 gtk_button_set_label(GTK_BUTTON(button),_("Unmute"));
189                 if (image!=NULL) {
190                         gtk_button_set_image(GTK_BUTTON(button),image);
191                         gtk_widget_show(image);
192                 }
193         }else{
194                 GtkWidget *image=create_pixmap("mic_active.png");
195                 gtk_button_set_label(GTK_BUTTON(button),_("Mute"));
196                 if (image!=NULL) {
197                         gtk_button_set_image(GTK_BUTTON(button),image);
198                         gtk_widget_show(image);
199                 }
200         }
201 }
202
203 void linphone_gtk_mute_toggled(GtkToggleButton *button){
204         gboolean active=gtk_toggle_button_get_active(button);
205         linphone_core_mute_mic(linphone_gtk_get_core(),active);
206         linphone_gtk_draw_mute_button(button,active);
207 }
208
209 void linphone_gtk_enable_mute_button(GtkToggleButton *button, gboolean sensitive){
210         gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
211         gtk_object_set(GTK_OBJECT(button),"gtk-button-images",TRUE,NULL);
212         linphone_gtk_draw_mute_button(button,FALSE);
213 }