]> sjero.net Git - linphone/blob - gtk/loginframe.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / gtk / loginframe.c
1 /*
2 linphone, gtk-glade interface.
3 Copyright (C) 2009  Simon MORLAT (simon.morlat@linphone.org)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20 #include "linphone.h"
21
22 void linphone_gtk_login_frame_connect_clicked(GtkWidget *button);
23 void linphone_gtk_exit_login_frame(void);
24
25 enum {
26         NetworkKindAdsl,
27         NetworkKindOpticalFiber
28 };
29
30 static void do_login(SipSetupContext *ssctx, const char *identity, const char * passwd){
31         if (sip_setup_context_login_account(ssctx,identity,passwd)==0){
32         }
33 }
34
35 static gboolean do_login_noprompt(LinphoneProxyConfig *cfg){
36         SipSetupContext *ssctx=linphone_proxy_config_get_sip_setup_context(cfg);
37         LinphoneAddress *addr;
38         const char *username;
39         char *tmp;
40         if (ssctx==NULL) return TRUE;/*not ready ?*/
41         username=linphone_gtk_get_ui_config ("login_username",NULL);
42         if (username==NULL) {
43                 linphone_gtk_set_ui_config_int("automatic_login",0);
44                 linphone_gtk_show_login_frame(cfg);
45                 return FALSE;
46         }
47         addr=linphone_address_new(linphone_proxy_config_get_identity(cfg));
48         linphone_address_set_username(addr,username);
49         tmp=linphone_address_as_string (addr);
50         do_login(ssctx,tmp,NULL);
51         linphone_address_destroy(addr);
52         linphone_gtk_load_identities();
53         return FALSE;
54 }
55
56 void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg){
57         GtkWidget *mw=linphone_gtk_get_main_window();
58         GtkWidget *label=linphone_gtk_get_widget(mw,"login_label");
59         const LinphoneAuthInfo *ai;
60         gchar *str;
61         LinphoneAddress *from;
62         LinphoneCore *lc=linphone_gtk_get_core();
63         int nettype;
64         const char *passwd=NULL;
65
66         
67         if (linphone_core_get_download_bandwidth(lc)==512 &&
68                 linphone_core_get_upload_bandwidth(lc)==512)
69                 nettype=NetworkKindOpticalFiber;
70         else nettype=NetworkKindAdsl;
71         gtk_combo_box_set_active(GTK_COMBO_BOX(linphone_gtk_get_widget(mw,"login_internet_kind")),nettype);
72         //gtk_combo_box_set_active(GTK_COMBO_BOX(linphone_gtk_get_widget(mw,"internet_kind")),nettype);
73         
74         if (linphone_gtk_get_ui_config_int("automatic_login",0) ){
75                 g_timeout_add(250,(GSourceFunc)do_login_noprompt,cfg);
76                 return;
77         }
78
79         {
80                 const char *login_image=linphone_gtk_get_ui_config("login_image",NULL);
81                 if (login_image){
82                         GdkPixbuf *pbuf=create_pixbuf (login_image);
83                         gtk_image_set_from_pixbuf (GTK_IMAGE(linphone_gtk_get_widget(mw,"login_image")),
84                                                    pbuf);
85                         g_object_unref(G_OBJECT(pbuf));
86                 }
87         }
88
89         gtk_widget_hide(linphone_gtk_get_widget(mw,"disconnect_item"));
90         gtk_widget_hide(linphone_gtk_get_widget(mw,"main_frame"));
91         gtk_widget_show(linphone_gtk_get_widget(mw,"login_frame"));
92         gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"options_menu"),FALSE);
93         str=g_strdup_printf(_("Please enter login information for %s"),linphone_proxy_config_get_domain(cfg));
94         gtk_label_set_text(GTK_LABEL(label),str);
95         g_object_set_data(G_OBJECT(mw),"login_proxy_config",cfg);
96         g_free(str);
97
98         from=linphone_address_new(linphone_proxy_config_get_identity(cfg));
99         if (linphone_address_get_username(from)[0]=='?'){
100                 const char *username=linphone_gtk_get_ui_config ("login_username",NULL);
101                 if (username)
102                         linphone_address_set_username(from,username);
103         }
104         
105         ai=linphone_core_find_auth_info(lc,linphone_proxy_config_get_domain(cfg),linphone_address_get_username(from));
106         /*display the last entered username, if not '?????'*/
107         if (linphone_address_get_username(from)[0]!='?')
108                 gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(mw,"login_username")),
109                         linphone_address_get_username(from));
110         if (ai) passwd=linphone_auth_info_get_passwd(ai);
111         gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(mw,"login_password")),
112                 passwd!=NULL ? passwd : "");
113         
114         linphone_address_destroy(from);
115 }
116
117 void linphone_gtk_exit_login_frame(void){
118         GtkWidget *mw=linphone_gtk_get_main_window();
119         gtk_widget_show(linphone_gtk_get_widget(mw,"main_frame"));
120         gtk_widget_hide(linphone_gtk_get_widget(mw,"login_frame"));
121         gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"options_menu"),TRUE);
122         gtk_widget_show(linphone_gtk_get_widget(mw,"disconnect_item"));
123 }
124
125 void linphone_gtk_logout_clicked(){
126         LinphoneCore *lc=linphone_gtk_get_core();
127         LinphoneProxyConfig *cfg=NULL;
128         linphone_core_get_default_proxy(lc,&cfg);
129         if (cfg){
130                 SipSetupContext *ss=linphone_proxy_config_get_sip_setup_context(cfg);
131                 if (ss){
132                         sip_setup_context_logout(ss);
133                         linphone_gtk_set_ui_config_int("automatic_login",FALSE);
134                         linphone_gtk_show_login_frame(cfg);
135                 }
136         }
137 }
138
139
140
141 void linphone_gtk_login_frame_connect_clicked(GtkWidget *button){
142         GtkWidget *mw=gtk_widget_get_toplevel(button);
143         const char *username;
144         const char *password;
145         char *identity;
146         gboolean autologin;
147         LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)g_object_get_data(G_OBJECT(mw),"login_proxy_config");
148         LinphoneAddress *from;
149         SipSetupContext *ssctx=linphone_proxy_config_get_sip_setup_context(cfg);
150
151         username=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(mw,"login_username")));
152         password=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(mw,"login_password")));
153
154         if (username==NULL || username[0]=='\0')
155                 return;
156
157         autologin=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(mw,"automatic_login")));
158         linphone_gtk_set_ui_config_int("automatic_login",autologin);
159         linphone_gtk_set_ui_config("login_username",username);
160
161         from=linphone_address_new(linphone_proxy_config_get_identity(cfg));
162         linphone_address_set_username(from,username);
163         identity=linphone_address_as_string(from);
164         do_login(ssctx,identity,password);
165         /*we need to refresh the identities since the proxy config may have changed.*/
166         linphone_gtk_load_identities();
167 }
168
169 void linphone_gtk_internet_kind_changed(GtkWidget *combo){
170         int netkind_id=gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
171         LinphoneCore *lc=linphone_gtk_get_core();
172         if (netkind_id==NetworkKindAdsl){
173                 linphone_core_set_upload_bandwidth(lc,256);
174                 linphone_core_set_download_bandwidth(lc,512);
175         }else if (netkind_id==NetworkKindOpticalFiber){
176                 linphone_core_set_upload_bandwidth(lc,512);
177                 linphone_core_set_download_bandwidth(lc,512);
178         }
179 }