]> sjero.net Git - linphone/blob - gtk/conference.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / gtk / conference.c
1 /***************************************************************************
2  *            gtk/conference.c
3  *
4  *  Mon Sep 12, 2011
5  *  Copyright  2011  Belledonne Communications
6  *  Author: Simon Morlat
7  *  Email simon dot morlat at linphone dot org
8  ****************************************************************************/
9
10 /*
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #include "linphone.h"
27
28 #define PADDING_PIXELS 4
29
30 /*
31  * conferencee_box = a vbox where participants are added or removed
32  * conf_frame = the conference tab
33  */
34
35 static GtkWidget *create_conference_label(void){
36         GtkWidget *box=gtk_hbox_new(FALSE,0);
37         gtk_box_pack_start(GTK_BOX(box),gtk_image_new_from_stock(GTK_STOCK_ADD,GTK_ICON_SIZE_MENU),FALSE,FALSE,0);
38         gtk_box_pack_end(GTK_BOX(box),gtk_label_new(_("Conference")),TRUE,FALSE,0);
39         gtk_widget_show_all(box);
40         return box;
41 }
42
43 static void init_local_participant(GtkWidget *participant){
44         GtkWidget *sound_meter;
45         GtkWidget *button=linphone_gtk_get_widget(participant,"conference_control");
46         gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(participant,"callee_name_label")),_("Me"));
47         sound_meter=linphone_gtk_get_widget(participant,"sound_indicator");
48         linphone_gtk_enable_mute_button(GTK_BUTTON(button),TRUE);
49         g_signal_connect(G_OBJECT(button),"clicked",(GCallback)linphone_gtk_mute_clicked,NULL);
50         gtk_widget_show(button);
51         linphone_gtk_init_audio_meter(sound_meter, (get_volume_t) linphone_core_get_conference_local_input_volume, linphone_gtk_get_core());
52 }
53
54 static GtkWidget *get_conferencee_box(GtkWidget *mw){
55         GtkWidget *box=(GtkWidget*)g_object_get_data(G_OBJECT(mw),"conferencee_box");
56         return box;
57 }
58
59 static GtkWidget *find_conferencee_from_call(LinphoneCall *call){
60         GtkWidget *mw=linphone_gtk_get_main_window();
61         GtkWidget *conferencee_box=get_conferencee_box(mw);
62         GList *elem;
63         GtkWidget *ret=NULL;
64         
65         if (conferencee_box==NULL) return NULL;
66         
67         if (call!=NULL){
68                 GList *l=gtk_container_get_children(GTK_CONTAINER(conferencee_box));
69                 for(elem=l;elem!=NULL;elem=elem->next){
70                         GtkWidget *frame=(GtkWidget*)elem->data;
71                         if (call==g_object_get_data(G_OBJECT(frame),"call")){
72                                 ret=frame;
73                                 break;
74                         }
75                 }
76                 g_list_free(l);
77         }
78         //g_message("find_conferencee_from_call(): found widget %p for call %p",ret,call);
79         return ret;
80 }
81
82 static GtkWidget * create_conference_panel(void){
83         GtkWidget *mw=linphone_gtk_get_main_window();
84         GtkWidget *conf_frame=linphone_gtk_create_widget("main","conf_frame");
85         GtkWidget *conf_box=linphone_gtk_get_widget(conf_frame,"conf_box");
86         GtkWidget *button_conf=linphone_gtk_get_widget(conf_frame,"terminate_conf");
87         GtkWidget *image=create_pixmap("stopcall-small.png");
88         GtkWidget *box;
89         GtkWidget *viewswitch=linphone_gtk_get_widget(mw,"viewswitch");
90         
91         gtk_button_set_image(GTK_BUTTON(button_conf),image);
92         g_signal_connect_swapped(G_OBJECT(button_conf),"clicked",(GCallback)linphone_gtk_terminate_call,NULL);
93         g_object_set_data(G_OBJECT(mw),"conf_frame",(gpointer)conf_frame);
94         
95         box=gtk_vbox_new(FALSE,0);
96         GtkWidget *participant=linphone_gtk_create_widget("main","callee_frame");
97         gtk_widget_show(participant);
98         gtk_box_set_homogeneous(GTK_BOX(box),TRUE);
99         init_local_participant(participant);
100         gtk_box_pack_start(GTK_BOX(box),participant,FALSE,FALSE,PADDING_PIXELS);
101         gtk_widget_show(box);
102         g_object_set_data(G_OBJECT(mw),"conferencee_box",box);
103         gtk_box_pack_start(GTK_BOX(conf_box),box,FALSE,FALSE,PADDING_PIXELS);
104         
105         gtk_notebook_append_page(GTK_NOTEBOOK(viewswitch),conf_frame,
106                                 create_conference_label());
107         return conf_frame;
108 }
109
110 void linphone_gtk_set_in_conference(LinphoneCall *call){
111         GtkWidget *mw=linphone_gtk_get_main_window();
112         GtkWidget *conf_frame=(GtkWidget *)g_object_get_data(G_OBJECT(mw),"conf_frame");
113         GtkWidget *viewswitch=linphone_gtk_get_widget(mw,"viewswitch");
114         
115         if(conf_frame==NULL){
116                 conf_frame=create_conference_panel();
117         }
118         GtkWidget *participant=find_conferencee_from_call(call);
119         
120         if (participant==NULL){
121                 /*create and add it */
122                 GtkWidget *conferencee_box=get_conferencee_box(mw);
123                 GtkWidget *sound_meter;
124                 const LinphoneAddress *addr=linphone_call_get_remote_address(call);
125                 gchar *markup;
126                 
127                 participant=linphone_gtk_create_widget("main","callee_frame");
128                 gtk_widget_show(participant);
129                 if (linphone_address_get_display_name(addr)!=NULL){
130                         markup=g_strdup_printf("<b>%s</b>",linphone_address_get_display_name(addr));
131                 }else{
132                         char *tmp=linphone_address_as_string_uri_only(addr);
133                         markup=g_strdup_printf("%s",tmp);
134                         ms_free(tmp);
135                 }
136                 gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(participant,"callee_name_label")),markup);
137                 g_free(markup);
138                 sound_meter=linphone_gtk_get_widget(participant,"sound_indicator");
139                 linphone_gtk_init_audio_meter(sound_meter, (get_volume_t) linphone_call_get_play_volume, call);
140                 gtk_box_pack_start(GTK_BOX(conferencee_box),participant,FALSE,FALSE,PADDING_PIXELS);
141                 g_object_set_data_full(G_OBJECT(participant),"call",linphone_call_ref(call),(GDestroyNotify)linphone_call_unref);
142                 gtk_notebook_set_current_page(GTK_NOTEBOOK(viewswitch),
143                         gtk_notebook_page_num(GTK_NOTEBOOK(viewswitch),conf_frame));
144         }
145 }
146
147 void linphone_gtk_terminate_conference_participant(LinphoneCall *call){
148         GtkWidget *frame=find_conferencee_from_call(call);
149         if (frame){
150                 gtk_widget_set_sensitive(frame,FALSE);
151         }
152 }
153
154 void linphone_gtk_unset_from_conference(LinphoneCall *call){
155         GtkWidget *frame=find_conferencee_from_call(call);
156         
157         if (frame){
158                 GtkWidget *mw=linphone_gtk_get_main_window();
159                 GtkWidget *conf_frame=(GtkWidget *)g_object_get_data(G_OBJECT(mw),"conf_frame");
160                 GtkWidget *conferencee_box=g_object_get_data(G_OBJECT(mw),"conferencee_box");
161                 GList *children;
162                 
163                 g_message("Removing a participant from conference");
164                 gtk_widget_destroy(frame);
165                 children=gtk_container_get_children(GTK_CONTAINER(conferencee_box));
166                 if (g_list_length(children)==1){ /* only local participant */
167                         /*the conference is terminated */
168                         g_message("The conference is terminated");
169                         g_object_set_data(G_OBJECT(mw),"conferencee_box",NULL);
170                         gtk_widget_destroy(conf_frame);
171                         g_object_set_data(G_OBJECT(mw),"conf_frame",NULL);
172                 }
173                 g_list_free(children);
174         }
175 }
176
177