]> sjero.net Git - linphone/blob - gtk/conference.c
0feed47aff2213100159788f5d60daf0c652c10e
[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         if (box==NULL){
52                 box=gtk_vbox_new(FALSE,0);
53                 GtkWidget *participant=linphone_gtk_create_widget("main","callee_frame");
54                 gtk_box_set_homogeneous(GTK_BOX(box),TRUE);
55                 init_local_participant(participant);
56                 gtk_box_pack_start(GTK_BOX(box),participant,FALSE,FALSE,PADDING_PIXELS);
57                 gtk_widget_show(box);
58                 g_object_set_data(G_OBJECT(mw),"conference_tab",box);
59                 gtk_notebook_append_page(GTK_NOTEBOOK(linphone_gtk_get_widget(mw,"viewswitch")),box,
60                                          create_conference_label());
61         }
62         return box;
63 }
64
65 static GtkWidget *find_conferencee_from_call(LinphoneCall *call){
66         GtkWidget *mw=linphone_gtk_get_main_window();
67         GtkWidget *tab=get_conference_tab(mw);
68         GList *elem;
69         GtkWidget *ret=NULL;
70         if (call!=NULL){
71                 GList *l=gtk_container_get_children(GTK_CONTAINER(tab));
72                 for(elem=l;elem!=NULL;elem=elem->next){
73                         GtkWidget *frame=(GtkWidget*)elem->data;
74                         if (call==g_object_get_data(G_OBJECT(frame),"call")){
75                                 ret=frame;
76                                 break;
77                         }
78                 }
79                 g_list_free(l);
80         }
81         //g_message("find_conferencee_from_call(): found widget %p for call %p",ret,call);
82         return ret;
83 }
84
85 void linphone_gtk_set_in_conference(LinphoneCall *call){
86         GtkWidget *mw=linphone_gtk_get_main_window();
87         GtkWidget *participant=find_conferencee_from_call(call);
88         
89         if (participant==NULL){
90                 GtkWidget *tab=get_conference_tab(mw);
91                 const LinphoneAddress *addr=linphone_call_get_remote_address(call);
92                 participant=linphone_gtk_create_widget("main","callee_frame");
93                 GtkWidget *sound_meter;
94                 GtkWidget *viewswitch=linphone_gtk_get_widget(mw,"viewswitch");
95                 gchar *markup;
96                 if (linphone_address_get_display_name(addr)!=NULL){
97                         markup=g_strdup_printf("<b>%s</b>",linphone_address_get_display_name(addr));
98                 }else{
99                         char *tmp=linphone_address_as_string_uri_only(addr);
100                         markup=g_strdup_printf("%s",tmp);
101                         ms_free(tmp);
102                 }
103                 gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(participant,"callee_name_label")),markup);
104                 g_free(markup);
105                 sound_meter=linphone_gtk_get_widget(participant,"sound_indicator");
106                 linphone_gtk_init_audio_meter(sound_meter, (get_volume_t) linphone_call_get_play_volume, call);
107                 gtk_box_pack_start(GTK_BOX(tab),participant,FALSE,FALSE,PADDING_PIXELS);
108                 g_object_set_data_full(G_OBJECT(participant),"call",linphone_call_ref(call),(GDestroyNotify)linphone_call_unref);
109                 gtk_widget_show(participant);
110                 gtk_notebook_set_current_page(GTK_NOTEBOOK(viewswitch),
111                                                   gtk_notebook_page_num(GTK_NOTEBOOK(viewswitch),tab));
112         }
113 }
114
115
116
117 void linphone_gtk_terminate_conference_participant(LinphoneCall *call){
118         GtkWidget *frame=find_conferencee_from_call(call);
119         if (frame){
120                 gtk_widget_set_sensitive(frame,FALSE);
121         }
122 }
123
124 void linphone_gtk_unset_from_conference(LinphoneCall *call){
125         GtkWidget *mw=linphone_gtk_get_main_window();
126         GtkWidget *box=(GtkWidget*)g_object_get_data(G_OBJECT(mw),"conference_tab");
127         GtkWidget *frame;
128         if (box==NULL) return; /*conference tab already destroyed*/
129         frame=find_conferencee_from_call(call);
130         GList *children;
131         if (frame){
132                 gtk_widget_destroy(frame);
133         }
134         children=gtk_container_get_children(GTK_CONTAINER(box));
135         if (g_list_length(children)==2){
136                 /*the conference is terminated */
137                 gtk_widget_destroy(box);
138                 g_object_set_data(G_OBJECT(mw),"conference_tab",NULL);
139         }
140         g_list_free(children);
141 }
142