35
41
memset(ui,0,sizeof(LinphoneGnomeUI));
44
ui->main_window.shown_once=FALSE;
47
static void restore_uri_history(GtkEntry *uribar, LpConfig *cfg){
50
GtkEntryCompletion *gep=gtk_entry_completion_new();
51
GtkListStore *model=gtk_list_store_new(1,G_TYPE_STRING);
54
snprintf(key,sizeof(key),"uri%i",i);
55
uri=lp_config_get_string(cfg,"GtkUi",key,NULL);
58
gtk_list_store_append(model,&iter);
59
gtk_list_store_set(model,&iter,0,uri,-1);
60
if (i==0) gtk_entry_set_text(uribar,uri);
64
gtk_entry_completion_set_model(gep,GTK_TREE_MODEL(model));
65
gtk_entry_completion_set_text_column(gep,0);
66
gtk_entry_set_completion(uribar,gep);
69
void linphone_gnome_save_uri_history(LinphoneGnomeUI *ui){
74
GtkEntry *uribar=GTK_ENTRY(ui->main_window.addressentry);
75
GtkTreeModel *model=gtk_entry_completion_get_model(gtk_entry_get_completion(uribar));
76
LpConfig *cfg=linphone_core_get_config(ui->core);
77
if (!gtk_tree_model_get_iter_first(model,&iter)) return;
79
gtk_tree_model_get(model,&iter,0,&uri,-1);
81
snprintf(key,sizeof(key),"uri%i",i);
82
lp_config_set_string(cfg,"GtkUi",key,uri);
87
}while(gtk_tree_model_iter_next(model,&iter));
40
90
void main_window_create(LinphoneGnomeUI *obj)
44
window=obj->main_window.window=create_app1 ();
94
window=create_app1 ();
45
95
gnome_window_icon_set_from_default(GTK_WINDOW(window));
46
96
obj->main_window.status_bar=lookup_widget(window,"appbar1");
47
97
obj->main_window.addressentry=lookup_widget(window,"addressentry");
48
98
obj->main_window.optioncontrols=lookup_widget(window,"optioncontrols");
49
99
obj->main_window.dtmfentry=lookup_widget(window,"dtmf_entry");
100
obj->main_window.callbutton=lookup_widget(window,"callbutton");
50
101
child=lookup_widget(window,"showmore");
51
102
/* hide the optionnal controls at startup */
52
103
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child),0);
104
#ifndef VIDEO_ENABLED
105
gtk_widget_hide(lookup_widget(child,"video_enabled"));
53
107
presence_box_init(&obj->main_window.presencebox,window,obj->core);
54
108
friend_list_init(&obj->main_window.friendlist,obj->core,window);
55
set_levels(obj,linphone_core_get_rec_level(obj->core),linphone_core_get_play_level(obj->core));
56
109
g_object_set_data(G_OBJECT(window),"ui",(gpointer)obj);
110
obj->main_window.window=window;
60
113
void linphone_gnome_ui_show(LinphoneGnomeUI *ui)
62
GtkWidget *win,*child;
63
115
if (ui->main_window.window==NULL){
64
116
main_window_create(ui);
67
119
gtk_widget_show(ui->main_window.window);
68
child=lookup_widget(ui->main_window.window,"friend_list_frame");
69
gtk_widget_hide(child);
120
ui->main_window.shown_once=TRUE;
72
123
void linphone_gnome_ui_hide(LinphoneGnomeUI *ui)
81
132
ui->main_window.window=NULL;
85
void linphone_gnome_ui_display_something(LinphoneGnomeUI *ui,GtkMessageType type,char *message)
135
void linphone_gnome_ui_display_something(LinphoneGnomeUI *ui,GtkMessageType type,const gchar *message)
87
137
GtkWidget *dialog;
89
139
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_enter();
90
140
linphone_gnome_ui_show(ui);
91
dialog = gtk_message_dialog_new (GTK_WINDOW(ui->main_window.window),
141
if (type==GTK_MESSAGE_QUESTION)
143
#ifdef VINCENT_MAURY_RSVP
144
/* draw a question box. link to dialog_click callback */
145
dialog = gtk_message_dialog_new (
146
GTK_WINDOW(ui->main_window.window),
147
GTK_DIALOG_DESTROY_WITH_PARENT,
148
GTK_MESSAGE_QUESTION,
150
(const gchar*)message);
151
/* connect the click event to the callback */
152
g_signal_connect_swapped (G_OBJECT (dialog), "response",
153
G_CALLBACK (dialog_click),
155
/* actually show the box */
156
gtk_widget_show(dialog);
161
dialog = gtk_message_dialog_new (GTK_WINDOW(ui->main_window.window),
92
162
GTK_DIALOG_DESTROY_WITH_PARENT,
94
164
GTK_BUTTONS_CLOSE,
95
165
(const gchar*)message);
96
/* Destroy the dialog when the user responds to it (e.g. clicks a button) */
97
g_signal_connect_swapped (G_OBJECT (dialog), "response",
166
/* Destroy the dialog when the user responds to it (e.g. clicks a button) */
167
g_signal_connect_swapped (G_OBJECT (dialog), "response",
98
168
G_CALLBACK (gtk_widget_destroy),
99
169
G_OBJECT (dialog));
100
gtk_widget_show(dialog);
170
gtk_widget_show(dialog);
101
172
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_leave();
104
175
/* these are the LinphoneCore virtual functions */
105
void linphone_gnome_display_message(LinphoneCore *lc,char *message)
176
void linphone_gnome_display_message(LinphoneCore *lc, const char *message)
107
178
LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
108
179
linphone_gnome_ui_display_something(ui,GTK_MESSAGE_INFO,message);
111
void linphone_gnome_display_warning(LinphoneCore *lc,char *warning)
182
#ifdef VINCENT_MAURY_RSVP
183
/* Question box with yes/no answer. */
184
void linphone_gnome_display_yes_no(LinphoneCore *lc,const char *message)
186
LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
187
if (strcmp(message,"With QoS")==0)
188
/* the caller asks for QoS, this function is called because, by default,
189
* you don't use QoS ! */
190
linphone_gnome_ui_display_something(ui,GTK_MESSAGE_QUESTION,
191
_("The caller asks for resource reservation. Do you agree ?"));
193
linphone_gnome_ui_display_something(ui,GTK_MESSAGE_QUESTION,
194
_("The caller doesn't use resource reservation. \
195
Do you wish to continue anyway ?"));
199
void linphone_gnome_display_warning(LinphoneCore *lc, const char *warning)
113
201
LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
114
202
linphone_gnome_ui_display_something(ui,GTK_MESSAGE_WARNING,warning);
117
void linphone_gnome_display_status(LinphoneCore *lc,char *status)
205
void linphone_gnome_display_status(LinphoneCore *lc, const char *status)
119
207
LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
120
208
if (ui->main_window.window==NULL) return;
121
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_enter();
209
if (!ui->main_window.shown_once) return; /* avoid a gnome bug*/
122
210
gnome_appbar_push(GNOME_APPBAR(ui->main_window.status_bar),status);
123
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_leave();
126
void linphone_gnome_inv_recv(LinphoneCore *lc,char *from)
214
void linphone_gnome_inv_recv(LinphoneCore *lc,const char *from)
128
216
LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
129
218
if (ui->main_window.window==NULL) return;
130
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_enter();
131
gtk_entry_set_text(GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(ui->main_window.addressentry))),from);
132
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_leave();
219
gtk_entry_set_text(GTK_ENTRY(ui->main_window.addressentry),from);
220
title=g_strdup_printf(_("linphone - receiving call from %s"),from);
221
gtk_window_set_title(GTK_WINDOW(ui->main_window.window),title);
135
225
void linphone_gnome_show(LinphoneCore *lc)
138
228
linphone_gnome_ui_show(ui);
141
void linphone_gnome_display_url(LinphoneCore *lc, char *message, char *url)
231
void linphone_gnome_display_url(LinphoneCore *lc, const char *message, const char *url)
143
233
LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
144
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_enter();
145
234
alt_ressource_display(ui,url);
146
if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_leave();
239
void linphone_gnome_notify_received(LinphoneCore *lc,LinphoneFriend *fid, const char *from, const char *status, const char *img){
240
FriendList *fl=get_friend_list();
241
friend_list_set_friend_status(fl,fid,from,status, img);
244
void linphone_gnome_new_unknown_subscriber(LinphoneCore *lc, LinphoneFriend *lf, const char *url){
245
GtkWidget *d=create_inc_subscr_dialog();
246
gchar *text=g_strdup_printf(_("You have received a subscription from %s."
247
"This means that this person wishes to be notified of your presence information (online, busy, away...).\n"
248
"Do you agree ?"),url);
249
gtk_label_set_text(GTK_LABEL(lookup_widget(d,"subscr_label")),text);
250
g_object_set_data(G_OBJECT(d),"friend_ref",(gpointer)lf);
254
void linphone_gnome_prompt_authentication(LinphoneCore *lc, const gchar *realm, const gchar *username){
255
GtkWidget *w=create_authentication_dialog();
256
gchar *question=g_strdup_printf(_("Authentication required for realm %s"),realm);
257
gtk_label_set_text(GTK_LABEL(lookup_widget(w,"question")),question);
259
gtk_entry_set_text(GTK_ENTRY(lookup_widget(w,"realm")),realm);
260
gtk_entry_set_text(GTK_ENTRY(lookup_widget(w,"username")),username);
264
void linphone_gnome_bye_recv(LinphoneCore *lc, const char *from){
265
LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
266
gtk_window_set_title(GTK_WINDOW(ui->main_window.window),"linphone");
272
void linphone_gnome_call_log_updated(LinphoneCore *lc, LinphoneCallLog *newcl){
273
LinphoneGnomeUI *ui=(LinphoneGnomeUI *)linphone_core_get_user_data(lc);
274
linphone_gnome_update_call_logs(ui);
277
void linphone_gnome_text_received(LinphoneCore *lc,LinphoneChatRoom *cr, const char *from, const char *msg){
278
GtkWidget *gcr=(GtkWidget*)linphone_chat_room_get_user_data(cr);
280
gcr=chatroom_new(from,cr);
282
gtk_widget_show(gcr);
283
chatroom_append(gcr,from,msg);
152
286
LinphoneCoreVTable linphone_gnome_vtable=
154
288
show: linphone_gnome_show,
155
289
inv_recv: linphone_gnome_inv_recv,
290
bye_recv : linphone_gnome_bye_recv,
291
notify_recv: linphone_gnome_notify_received,
292
new_unknown_subscriber: linphone_gnome_new_unknown_subscriber,
293
auth_info_requested: linphone_gnome_prompt_authentication,
157
294
display_status : linphone_gnome_display_status,
158
295
display_message : linphone_gnome_display_message,
159
296
display_warning : linphone_gnome_display_warning,
297
#ifdef VINCENT_MAURY_RSVP
298
display_yes_no : linphone_gnome_display_yes_no,
160
300
display_url : linphone_gnome_display_url,
161
display_question : stub
301
display_question : stub,
302
call_log_updated : linphone_gnome_call_log_updated,
303
text_received: linphone_gnome_text_received
164
static gboolean linphone_gnome_iterate(LinphoneCore *lc)
306
gboolean linphone_gnome_iterate(LinphoneCore *lc)
166
linphone_core_iterate(lc);
308
linphone_core_iterate(lc);
312
void proxy_changed(GtkWidget *combo){
313
LinphoneProxyConfig *pcfg=proxy_combo_box_get_selected(combo);
314
linphone_core_set_default_proxy(get_core(),pcfg);
317
void linphone_refresh_proxy_combo_box(GtkWidget *window){
318
LinphoneCore *lc=get_core();
320
const MSList *elem=linphone_core_get_proxy_config_list(lc);
321
LinphoneProxyConfig *cfg=NULL;
322
GtkWidget *hbox=lookup_widget(window,"proxy_hbox");
324
linphone_core_get_default_proxy(lc,&cfg);
327
gtk_widget_hide(hbox);
330
combo=(GtkWidget*)g_object_get_data(G_OBJECT(hbox),"proxy");
332
gtk_widget_destroy(combo);
334
combo=proxy_combo_box_new(cfg);
335
g_object_set_data(G_OBJECT(hbox),"proxy",(gpointer)combo);
336
g_signal_connect(G_OBJECT(combo),"changed",G_CALLBACK(proxy_changed),NULL);
337
gtk_box_pack_start_defaults(GTK_BOX(hbox),combo);
338
gtk_widget_show(combo);
339
gtk_widget_show(hbox);
170
343
void linphone_gnome_init(LinphoneGnomeUI *ui,LinphoneCore *lc)
345
gchar *configfile_name =
346
g_strdup_printf ("%s/.gnome2/linphone", getenv ("HOME"));
172
347
linphone_gnome_ui_init(ui,lc);
173
linphone_core_init(lc,&linphone_gnome_vtable,NULL,(gpointer)ui);
348
linphone_gnome_ui_show(ui);
349
linphone_core_init(lc,&linphone_gnome_vtable,configfile_name,(gpointer)ui);
350
g_free(configfile_name);
351
set_levels(ui,linphone_core_get_rec_level(lc),linphone_core_get_play_level(lc),linphone_core_get_ring_level(lc));
352
/* get history of uri bar */
353
restore_uri_history(GTK_ENTRY(ui->main_window.addressentry), linphone_core_get_config(lc));
354
linphone_refresh_proxy_combo_box(ui->main_window.window);
174
355
ui->timeout_id=gtk_timeout_add(500,(GtkFunction)linphone_gnome_iterate,(gpointer)lc);
181
362
linphone_core_uninit(lc);
182
363
gtk_timeout_remove (ui->timeout_id);
366
GtkWidget *proxy_combo_box_new(LinphoneProxyConfig *selected){
369
GtkListStore *store=gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_POINTER);
372
GtkCellRenderer *renderer;
373
gboolean proxy_found=FALSE;
375
elem=linphone_core_get_proxy_config_list(get_core());
376
gtk_list_store_append(store,&iter);
377
gtk_list_store_set(store,&iter,0,_("None"),1,(gpointer)NULL,-1);
378
for(;elem!=NULL;elem=ms_list_next(elem)){
379
LinphoneProxyConfig *proxy=(LinphoneProxyConfig*)elem->data;
380
gtk_list_store_append(store,&iter);
381
gtk_list_store_set(store,&iter,0,proxy->reg_proxy,1,(gpointer)proxy,-1);
382
if (selected==proxy) {
387
combo=gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
388
g_object_unref(G_OBJECT(store));
389
renderer = gtk_cell_renderer_text_new ();
390
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
391
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
395
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo),&prxiter);
397
/*else select "None" */
398
gtk_combo_box_set_active(GTK_COMBO_BOX(combo),0);
403
LinphoneProxyConfig *proxy_combo_box_get_selected(GtkWidget *combo){
404
LinphoneProxyConfig *pcfg=NULL;
406
if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo),&iter)){
407
GtkTreeModel *model=gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
408
gtk_tree_model_get(model,&iter,1,(gpointer)&pcfg,-1);
413
void linphone_gnome_update_call_logs(LinphoneGnomeUI *ui){
414
LinphoneCore *lc=ui->core;
417
GtkTextIter begin,end;
420
if (ui->logs==NULL) return;
421
tv=GTK_TEXT_VIEW(lookup_widget(ui->logs,"logview"));
422
tb=gtk_text_view_get_buffer(tv);
424
gtk_text_buffer_get_bounds(tb,&begin,&end);
425
gtk_text_buffer_delete(tb,&begin,&end);
426
gtk_text_buffer_get_end_iter(tb,&end);
427
for (elem=linphone_core_get_call_logs(lc);elem!=NULL;elem=ms_list_next(elem)){
428
LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
429
gchar *str=linphone_call_log_to_str(cl);
431
if (cl->status==LinphoneCallMissed){
432
tag=gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(tb),"redforeground");
433
if (tag==NULL) tag = gtk_text_buffer_create_tag (tb, "redforeground",
434
"foreground", "red", NULL);
436
gtk_text_buffer_insert_with_tags(tb,&end,str,-1,tag,NULL);
437
gtk_text_buffer_insert(tb,&end,"\n",-1);
443
void linphone_gnome_show_call_logs_window(LinphoneGnomeUI *ui){
444
if (ui->logs==NULL) {
445
ui->logs=create_call_logs();
447
linphone_gnome_update_call_logs(ui);
448
gtk_widget_show(ui->logs);