~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to gnome/linphone.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "linphone.h"
26
26
#include "support.h"
27
27
#include "interface.h"
 
28
#include "callbacks.h"
 
29
#include "gui_utils.h"
 
30
#include "lpconfig.h"
28
31
 
29
32
 
30
33
LinphoneGnomeUI *uiobj=NULL;
 
34
#define get_uiobj() (uiobj)
 
35
#define get_core() (uiobj->core)
 
36
#define get_friend_list() (&uiobj->main_window.friendlist)
31
37
 
32
38
void linphone_gnome_ui_init(LinphoneGnomeUI *ui,LinphoneCore *core)
33
39
{
35
41
        memset(ui,0,sizeof(LinphoneGnomeUI));
36
42
        ui->core=core;
37
43
        uiobj=ui;
 
44
        ui->main_window.shown_once=FALSE;
 
45
}
 
46
 
 
47
static void restore_uri_history(GtkEntry *uribar, LpConfig *cfg){
 
48
        char key[20];
 
49
        int i;
 
50
        GtkEntryCompletion *gep=gtk_entry_completion_new();
 
51
        GtkListStore *model=gtk_list_store_new(1,G_TYPE_STRING);
 
52
        for (i=0;;i++){
 
53
                const char *uri;
 
54
                snprintf(key,sizeof(key),"uri%i",i);
 
55
                uri=lp_config_get_string(cfg,"GtkUi",key,NULL);
 
56
                if (uri!=NULL) {
 
57
                        GtkTreeIter iter;
 
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);
 
61
                }
 
62
                else break;
 
63
        }
 
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);
 
67
}
 
68
 
 
69
void linphone_gnome_save_uri_history(LinphoneGnomeUI *ui){
 
70
        char key[20];
 
71
        int i=0;
 
72
        char *uri=NULL;
 
73
        GtkTreeIter iter;
 
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;
 
78
        do {
 
79
                gtk_tree_model_get(model,&iter,0,&uri,-1);
 
80
                if (uri) {
 
81
                        snprintf(key,sizeof(key),"uri%i",i);
 
82
                        lp_config_set_string(cfg,"GtkUi",key,uri);
 
83
                        g_free(uri);
 
84
                }else break;
 
85
                i++;
 
86
                if (i>5) break;
 
87
        }while(gtk_tree_model_iter_next(model,&iter));
38
88
}
39
89
 
40
90
void main_window_create(LinphoneGnomeUI *obj)
41
91
{
42
92
        GtkWidget *child;
43
93
        GtkWidget *window;
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"));
 
106
#endif
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);
57
 
        
 
110
        obj->main_window.window=window;
58
111
}
59
112
 
60
113
void linphone_gnome_ui_show(LinphoneGnomeUI *ui)
61
114
{
62
 
        GtkWidget *win,*child;
63
115
        if (ui->main_window.window==NULL){
64
116
                main_window_create(ui);
65
117
                
66
118
        }
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;
70
121
}
71
122
 
72
123
void linphone_gnome_ui_hide(LinphoneGnomeUI *ui)
81
132
        ui->main_window.window=NULL;
82
133
}
83
134
 
84
 
 
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)
86
136
{
87
137
        GtkWidget *dialog;
88
138
        
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)
 
142
        {
 
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,
 
149
                                GTK_BUTTONS_YES_NO,
 
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),
 
154
                           G_OBJECT (dialog));
 
155
                /* actually show the box */
 
156
                gtk_widget_show(dialog);
 
157
#endif
 
158
        }
 
159
        else
 
160
        {
 
161
                dialog = gtk_message_dialog_new (GTK_WINDOW(ui->main_window.window),
92
162
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
93
163
                                  type,
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);
 
171
        }
101
172
        if (!linphone_core_is_in_main_thread(ui->core)) gdk_threads_leave();
102
173
}
103
174
 
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)
106
177
{
107
178
        LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
108
179
        linphone_gnome_ui_display_something(ui,GTK_MESSAGE_INFO,message);
109
180
}
110
181
 
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)
 
185
{
 
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 ?"));
 
192
        else
 
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 ?"));
 
196
}
 
197
#endif
 
198
 
 
199
void linphone_gnome_display_warning(LinphoneCore *lc, const char *warning)
112
200
{
113
201
        LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
114
202
        linphone_gnome_ui_display_something(ui,GTK_MESSAGE_WARNING,warning);
115
203
}
116
204
 
117
 
void linphone_gnome_display_status(LinphoneCore *lc,char *status)
 
205
void linphone_gnome_display_status(LinphoneCore *lc, const char *status)
118
206
{
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();
 
211
        
124
212
}
125
213
 
126
 
void linphone_gnome_inv_recv(LinphoneCore *lc,char *from)
 
214
void linphone_gnome_inv_recv(LinphoneCore *lc,const char *from)
127
215
{
128
216
        LinphoneGnomeUI *ui=(LinphoneGnomeUI*)lc->data;
 
217
        gchar *title;
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);
 
222
        g_free(title);
133
223
}
134
224
 
135
225
void linphone_gnome_show(LinphoneCore *lc)
138
228
        linphone_gnome_ui_show(ui);
139
229
}
140
230
 
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)
142
232
{
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();
 
235
}
 
236
 
 
237
 
 
238
 
 
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);
 
242
}
 
243
 
 
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);
 
251
        gtk_widget_show(d);
 
252
}
 
253
 
 
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);
 
258
        g_free(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);
 
261
        gtk_widget_show(w);
 
262
}
 
263
 
 
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");
147
267
}
148
268
 
149
269
void stub(){
150
270
}
151
271
 
 
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);
 
275
}
 
276
 
 
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);
 
279
        if (gcr==NULL){
 
280
                gcr=chatroom_new(from,cr);
 
281
        }
 
282
        gtk_widget_show(gcr);
 
283
        chatroom_append(gcr,from,msg);
 
284
}
 
285
 
152
286
LinphoneCoreVTable linphone_gnome_vtable=
153
287
{
154
288
        show: linphone_gnome_show,
155
289
        inv_recv: linphone_gnome_inv_recv,
156
 
        bye_recv : stub,
 
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,
 
299
#endif
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
162
304
};
163
305
 
164
 
static gboolean linphone_gnome_iterate(LinphoneCore *lc)
 
306
gboolean linphone_gnome_iterate(LinphoneCore *lc)
165
307
{
166
 
  linphone_core_iterate(lc);
167
 
  return TRUE;
 
308
        linphone_core_iterate(lc);
 
309
        return TRUE;
 
310
}
 
311
 
 
312
void proxy_changed(GtkWidget *combo){
 
313
        LinphoneProxyConfig *pcfg=proxy_combo_box_get_selected(combo);
 
314
        linphone_core_set_default_proxy(get_core(),pcfg);
 
315
}
 
316
 
 
317
void linphone_refresh_proxy_combo_box(GtkWidget *window){
 
318
        LinphoneCore *lc=get_core();
 
319
        GtkWidget *combo;
 
320
        const MSList *elem=linphone_core_get_proxy_config_list(lc);
 
321
        LinphoneProxyConfig *cfg=NULL;
 
322
        GtkWidget *hbox=lookup_widget(window,"proxy_hbox");
 
323
        
 
324
        linphone_core_get_default_proxy(lc,&cfg);
 
325
        
 
326
        if (elem==NULL){
 
327
                gtk_widget_hide(hbox);
 
328
                return;
 
329
        }
 
330
        combo=(GtkWidget*)g_object_get_data(G_OBJECT(hbox),"proxy");
 
331
        if (combo!=NULL){
 
332
                gtk_widget_destroy(combo);
 
333
        }
 
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);
 
340
        
168
341
}
169
342
 
170
343
void linphone_gnome_init(LinphoneGnomeUI *ui,LinphoneCore *lc)
171
344
{
 
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);
175
356
}
176
357
 
181
362
        linphone_core_uninit(lc);
182
363
        gtk_timeout_remove (ui->timeout_id);
183
364
}
 
365
 
 
366
GtkWidget *proxy_combo_box_new(LinphoneProxyConfig *selected){
 
367
        GtkWidget *combo;
 
368
        const MSList *elem;
 
369
        GtkListStore *store=gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_POINTER);
 
370
        GtkTreeIter iter;
 
371
        GtkTreeIter prxiter;
 
372
        GtkCellRenderer *renderer;
 
373
        gboolean proxy_found=FALSE;
 
374
        /* fill the store */
 
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) {
 
383
                        prxiter=iter;
 
384
                        proxy_found=TRUE;
 
385
                }
 
386
        }
 
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,
 
392
                                "text", 0,
 
393
                                NULL);
 
394
        if (proxy_found){
 
395
                gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo),&prxiter);
 
396
        }else{
 
397
                /*else select "None" */
 
398
                gtk_combo_box_set_active(GTK_COMBO_BOX(combo),0);
 
399
        }
 
400
        return combo;
 
401
}
 
402
 
 
403
LinphoneProxyConfig *proxy_combo_box_get_selected(GtkWidget *combo){
 
404
        LinphoneProxyConfig *pcfg=NULL;
 
405
        GtkTreeIter iter;
 
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);
 
409
        }
 
410
        return pcfg;
 
411
}
 
412
 
 
413
void linphone_gnome_update_call_logs(LinphoneGnomeUI *ui){
 
414
        LinphoneCore *lc=ui->core;
 
415
        GtkTextView *tv;
 
416
        GtkTextBuffer *tb;
 
417
        GtkTextIter begin,end;
 
418
        GtkTextTag *tag;
 
419
        MSList *elem;
 
420
        if (ui->logs==NULL) return;
 
421
        tv=GTK_TEXT_VIEW(lookup_widget(ui->logs,"logview"));
 
422
        tb=gtk_text_view_get_buffer(tv);
 
423
        
 
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);
 
430
                tag=NULL;
 
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);
 
435
                }
 
436
                gtk_text_buffer_insert_with_tags(tb,&end,str,-1,tag,NULL);
 
437
                gtk_text_buffer_insert(tb,&end,"\n",-1);
 
438
                
 
439
                ms_free(str);
 
440
        }
 
441
}
 
442
 
 
443
void linphone_gnome_show_call_logs_window(LinphoneGnomeUI *ui){
 
444
        if (ui->logs==NULL) {
 
445
                ui->logs=create_call_logs();
 
446
        }
 
447
        linphone_gnome_update_call_logs(ui);
 
448
        gtk_widget_show(ui->logs);
 
449
}