]> sjero.net Git - linphone/blob - gtk/conference.c
new ui improvements more contact oriented :
[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 static GtkWidget *create_conference_label(void){
31         GtkWidget *box=gtk_hbox_new(FALSE,0);
32         gtk_box_pack_start(GTK_BOX(box),gtk_image_new_from_stock(GTK_STOCK_ADD,GTK_ICON_SIZE_MENU),FALSE,FALSE,0);
33         gtk_box_pack_end(GTK_BOX(box),gtk_label_new(_("Conference")),TRUE,FALSE,0);
34         gtk_widget_show_all(box);
35         return box;
36 }
37
38 static void init_local_participant(GtkWidget *participant){
39         GtkWidget *sound_meter;
40         GtkWidget *button=linphone_gtk_get_widget(participant,"conference_control");
41         gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(participant,"callee_name_label")),_("Me"));
42         sound_meter=linphone_gtk_get_widget(participant,"sound_indicator");
43         linphone_gtk_enable_mute_button(GTK_BUTTON(button),TRUE);
44         g_signal_connect(G_OBJECT(button),"clicked",(GCallback)linphone_gtk_mute_clicked,NULL);
45         gtk_widget_show(button);
46         linphone_gtk_init_audio_meter(sound_meter, (get_volume_t) linphone_core_get_conference_local_input_volume, linphone_gtk_get_core());
47 }
48
49 static GtkWidget *get_conference_tab(GtkWidget *mw){
50         GtkWidget *box=(GtkWidget*)g_object_get_data(G_OBJECT(mw),"conference_tab");
51         GtkWidget *conf_frame=(GtkWidget*)g_object_get_data(G_OBJECT(mw),"conf_frame");
52         if(conf_frame!=NULL){
53                 if (box==NULL){
54                         GtkWidget *conf_box=linphone_gtk_get_widget(conf_frame,"conf_box");
55                         box=gtk_vbox_new(FALSE,0);
56                         GtkWidget *participant=linphone_gtk_create_widget("main","callee_frame");
57                         gtk_box_set_homogeneous(GTK_BOX(box),TRUE);
58                         init_local_participant(participant);
59                         gtk_box_pack_start(GTK_BOX(box),participant,FALSE,FALSE,PADDING_PIXELS);
60                         gtk_widget_show(box);
61                         g_object_set_data(G_OBJECT(mw),"conference_tab",box);
62                         gtk_box_pack_start(GTK_BOX(conf_box),box,FALSE,FALSE,PADDING_PIXELS);
63                 }
64         }
65         return box;
66 }
67
68 static GtkWidget *find_conferencee_from_call(LinphoneCall *call){
69         GtkWidget *mw=linphone_gtk_get_main_window();
70         get_conference_tab(mw);
71         GtkWidget *conf_frame=(GtkWidget *)g_object_get_data(G_OBJECT(mw),"conf_frame");
72         GtkWidget *conf_box=linphone_gtk_get_widget(conf_frame,"conf_box");
73         GList *elem;
74         GtkWidget *ret=NULL;
75         if (call!=NULL){
76                 GList *l=gtk_container_get_children(GTK_CONTAINER(conf_box));
77                 for(elem=l;elem!=NULL;elem=elem->next){
78                         GtkWidget *frame=(GtkWidget*)elem->data;
79                         if (call==g_object_get_data(G_OBJECT(frame),"call")){
80                                 ret=frame;
81                                 break;
82                         }
83                 }
84                 g_list_free(l);
85         }
86         //g_message("find_conferencee_from_call(): found widget %p for call %p",ret,call);
87         return ret;
88 }
89
90 void linphone_gtk_set_in_conference(LinphoneCall *call){
91         GtkWidget *mw=linphone_gtk_get_main_window();
92         GtkWidget *viewswitch=linphone_gtk_get_widget(mw,"viewswitch");
93         GtkWidget *conf_frame=(GtkWidget *)g_object_get_data(G_OBJECT(mw),"conf_frame");
94         g_object_set_data(G_OBJECT(mw),"is_conf",GINT_TO_POINTER(TRUE));
95         if(conf_frame==NULL){
96                 conf_frame=linphone_gtk_create_widget("main","conf_frame");
97                 GtkWidget *button_conf=linphone_gtk_get_widget(conf_frame,"terminate_conf");
98                 GtkWidget *image=create_pixmap("stopcall-red.png");
99                 gtk_button_set_image(GTK_BUTTON(button_conf),image);
100                 g_signal_connect_swapped(G_OBJECT(button_conf),"clicked",(GCallback)linphone_gtk_terminate_call,NULL);
101                 g_object_set_data(G_OBJECT(mw),"conf_frame",(gpointer)conf_frame);
102                 gtk_notebook_append_page(GTK_NOTEBOOK(viewswitch),conf_frame,
103                                       create_conference_label());
104         }
105         GtkWidget *participant=find_conferencee_from_call(call);        
106         GtkWidget *conf_box=linphone_gtk_get_widget(conf_frame,"conf_box");
107         if (participant==NULL){
108                 const LinphoneAddress *addr=linphone_call_get_remote_address(call);
109                 participant=linphone_gtk_create_widget("main","callee_frame");
110                 GtkWidget *sound_meter;
111                 gchar *markup;
112                 if (linphone_address_get_display_name(addr)!=NULL){
113                         markup=g_strdup_printf("<b>%s</b>",linphone_address_get_display_name(addr));
114                 }else{
115                         char *tmp=linphone_address_as_string_uri_only(addr);
116                         markup=g_strdup_printf("%s",tmp);
117                         ms_free(tmp);
118                 }
119                 gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(participant,"callee_name_label")),markup);
120                 g_free(markup);
121                 sound_meter=linphone_gtk_get_widget(participant,"sound_indicator");
122                 linphone_gtk_init_audio_meter(sound_meter, (get_volume_t) linphone_call_get_play_volume, call); 
123                 gtk_box_pack_start(GTK_BOX(conf_box),participant,FALSE,FALSE,PADDING_PIXELS);
124                 g_object_set_data_full(G_OBJECT(participant),"call",linphone_call_ref(call),(GDestroyNotify)linphone_call_unref);
125                 gtk_notebook_set_current_page(GTK_NOTEBOOK(viewswitch),
126                 gtk_notebook_page_num(GTK_NOTEBOOK(viewswitch),conf_frame));
127         }
128 }
129
130 void linphone_gtk_terminate_conference_participant(LinphoneCall *call){
131         GtkWidget *frame=find_conferencee_from_call(call);
132         if (frame){
133                 gtk_widget_set_sensitive(frame,FALSE);
134         }
135 }
136
137 void linphone_gtk_unset_from_conference(LinphoneCall *call){
138         GtkWidget *mw=linphone_gtk_get_main_window();
139         GtkWidget *conf_frame=(GtkWidget *)g_object_get_data(G_OBJECT(mw),"conf_frame");
140         GtkWidget *conf_box=linphone_gtk_get_widget(conf_frame,"conf_box");
141         GtkWidget *frame;
142         if (conf_box==NULL) return; /*conference tab already destroyed*/
143         frame=find_conferencee_from_call(call);
144         GList *children;
145         if (frame){
146                 gtk_widget_destroy(frame);
147         }
148         children=gtk_container_get_children(GTK_CONTAINER(conf_box));
149         if (g_list_length(children)==2){
150                 /*the conference is terminated */
151                 gtk_widget_destroy(conf_box);
152                 g_object_set_data(G_OBJECT(mw),"conference_tab",NULL);          
153         }
154         gtk_widget_destroy(conf_frame);
155         g_list_free(children);
156         g_object_set_data(G_OBJECT(mw),"is_conf",GINT_TO_POINTER(FALSE));
157         g_object_set_data(G_OBJECT(mw),"conf_frame",NULL);
158 }