]> sjero.net Git - linphone/blob - gtk/setupwizard.c
Wizard merged
[linphone] / gtk / setupwizard.c
1 /*
2 linphone, gtk-glade interface.
3 Copyright (C) 2008  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 #include <glib.h>
22 #include <glib/gprintf.h>
23 #include <pthread.h>
24 static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w);
25
26 static const int PASSWORD_MIN_SIZE = 6;
27 static const int LOGIN_MIN_SIZE = 4;
28 static int is_username_available = 0;
29 static int is_email_correct = 0;
30 static int is_password_correct = 0;
31
32 static GdkPixbuf *ok;
33 static GdkPixbuf *notok;
34
35 static GtkWidget *create_intro(){
36         GtkWidget *vbox=gtk_vbox_new(FALSE,2);
37         GtkWidget *label=gtk_label_new(_("Welcome !\nThis assistant will help you to use a SIP account for your calls."));
38         gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
39         g_object_set_data(G_OBJECT(vbox),"label",label);
40         gtk_widget_show_all(vbox);
41         return vbox;
42 }
43
44 static GtkWidget *create_setup_signin_choice(){
45         GtkWidget *vbox=gtk_vbox_new(FALSE,2);
46         GtkWidget *t1=gtk_radio_button_new_with_label(NULL,_("Create an account on linphone.org"));
47         GtkWidget *t2=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1),_("I have already a linphone.org account and I just want to use it"));
48         GtkWidget *t3=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1),_("I have already a sip account and I just want to use it"));
49         gtk_box_pack_start (GTK_BOX (vbox), t1, TRUE, TRUE, 2);
50         gtk_box_pack_start (GTK_BOX (vbox), t2, TRUE, TRUE, 2);
51         gtk_box_pack_start (GTK_BOX (vbox), t3, TRUE, TRUE, 2);
52         gtk_widget_show_all(vbox);
53         g_object_set_data(G_OBJECT(vbox),"create_account",t1);
54         g_object_set_data(G_OBJECT(vbox),"setup_linphone_account",t2);
55         g_object_set_data(G_OBJECT(vbox),"setup_account",t3);
56         return vbox;
57 }
58
59 static int all_account_information_entered(GtkWidget *w) {
60         GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
61         GtkEntry* domain = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"domain"));
62
63         if (gtk_entry_get_text_length(username) > 0 &&
64         gtk_entry_get_text_length(domain) > 0 &&
65         g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$", gtk_entry_get_text(username), 0, 0) &&
66         g_regex_match_simple("^(sip:)?([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$", gtk_entry_get_text(domain), 0, 0)) {
67                 return 1;
68         }
69         return 0;
70 }
71
72 static void account_informations_changed(GtkEntry *entry, GtkWidget *w) {
73         GtkWidget *assistant=gtk_widget_get_toplevel(w);
74         gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
75                 all_account_information_entered(w)>0);
76 }
77
78 static void linphone_account_informations_changed(GtkEntry *entry, GtkWidget *w) {
79         GtkWidget *assistant=gtk_widget_get_toplevel(w);
80         GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
81
82         gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
83                 gtk_entry_get_text_length(username) >= LOGIN_MIN_SIZE);
84 }
85
86 static GtkWidget *create_linphone_account_informations_page() {
87         GtkWidget *vbox=gtk_table_new(3, 2, TRUE);
88         GtkWidget *label=gtk_label_new(_("Enter your linphone.org username"));
89
90         GdkColor color;
91         gdk_color_parse ("red", &color);
92         GtkWidget *labelEmpty=gtk_label_new(NULL);
93         gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color);
94
95         GtkWidget *labelUsername=gtk_label_new(_("Username:"));
96         GtkWidget *entryUsername=gtk_entry_new();
97         GtkWidget *labelPassword=gtk_label_new(_("Password:"));
98         GtkWidget *entryPassword=gtk_entry_new();
99         gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
100
101         gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1);
102         gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2);
103         gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 1, 2);
104         gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3);
105         gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3);
106
107         gtk_widget_show_all(vbox);
108         g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
109         g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
110         g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty);
111         g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)linphone_account_informations_changed,vbox);
112         return vbox;
113 }
114
115 static GtkWidget *create_account_informations_page() {
116         GtkWidget *vbox=gtk_table_new(6, 2, FALSE);
117         GtkWidget *label=gtk_label_new(_("Enter your account informations"));
118
119         GdkColor color;
120         gdk_color_parse ("red", &color);
121         GtkWidget *labelEmpty=gtk_label_new(NULL);
122         gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color);
123
124         GtkWidget *labelUsername=gtk_label_new(_("Username*"));
125         GtkWidget *labelPassword=gtk_label_new(_("Password*"));
126         GtkWidget *entryPassword=gtk_entry_new();
127         gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
128         GtkWidget *labelDomain=gtk_label_new(_("Domain*"));
129         GtkWidget *labelProxy=gtk_label_new(_("Proxy"));
130         GtkWidget *entryUsername=gtk_entry_new();
131         GtkWidget *entryDomain=gtk_entry_new();
132         GtkWidget *entryRoute=gtk_entry_new();
133
134         gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1);
135         gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2);
136         gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 1, 2);
137         gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3);
138         gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3);
139         gtk_table_attach_defaults(GTK_TABLE(vbox), labelDomain, 0, 1, 3, 4);
140         gtk_table_attach_defaults(GTK_TABLE(vbox), entryDomain, 1, 2, 3, 4);
141         gtk_table_attach_defaults(GTK_TABLE(vbox), labelProxy, 0, 1, 4, 5);
142         gtk_table_attach_defaults(GTK_TABLE(vbox), entryRoute, 1, 2, 4, 5);
143         gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmpty, 0, 2, 5, 6);
144         gtk_widget_show_all(vbox);
145
146         g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
147         g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
148         g_object_set_data(G_OBJECT(vbox),"domain",entryDomain);
149         g_object_set_data(G_OBJECT(vbox),"proxy",entryRoute);
150         g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty);
151         g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_informations_changed,vbox);
152         g_signal_connect(G_OBJECT(entryDomain),"changed",(GCallback)account_informations_changed,vbox);
153         g_signal_connect(G_OBJECT(entryRoute),"changed",(GCallback)account_informations_changed,vbox);
154
155         return vbox;
156 }
157
158 static int create_account(GtkWidget *page) {
159         LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page));
160         LinphoneProxyConfig *res=linphone_account_creator_validate(creator);
161         if (res) {
162                 if (!g_regex_match_simple("^sip:[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}@sip.linphone.org$",creator->username, 0, 0)) {
163                         gchar identity[128];
164                         g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", creator->username);
165                         linphone_account_creator_set_username(creator, identity);
166                         linphone_account_creator_set_domain(creator, "sip:sip.linphone.org");
167                 }
168                 return 1;
169         }
170         return 0;
171 }
172
173 static int is_account_information_correct(GtkWidget *w) {
174         if (is_username_available == 1 && is_email_correct == 1 && is_password_correct == 1) {
175                 return 1;
176         }
177         return 0;
178 }
179
180 static void account_email_changed(GtkEntry *entry, GtkWidget *w) {
181         // Verifying if email entered is correct, and if form is correctly filled, let the user go next page
182
183         GtkEntry* email = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"email"));
184         GtkImage* isEmailOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"emailOk"));
185         GtkWidget *assistant=gtk_widget_get_toplevel(w);
186
187         if (g_regex_match_simple("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$", gtk_entry_get_text(email), 0, 0)) {
188                 is_email_correct = 1;
189                 gtk_image_set_from_pixbuf(isEmailOk, ok);
190         }
191         else {
192                 is_email_correct = 0;
193                 gtk_image_set_from_pixbuf(isEmailOk, notok);
194         }
195         gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
196                         is_account_information_correct(w)>0);
197 }
198
199 static void account_password_changed(GtkEntry *entry, GtkWidget *w) {
200         // Verifying if passwords entered match, and if form is correctly filled, let the user go next page
201
202         GtkEntry* password = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"password"));
203         GtkImage* isPasswordOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"passwordOk"));
204         GtkEntry* password_confirm = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"password_confirm"));
205         GtkWidget *assistant=gtk_widget_get_toplevel(w);
206         GtkLabel* passwordError = GTK_LABEL(g_object_get_data(G_OBJECT(w),"error"));
207
208         if (gtk_entry_get_text_length(password) >= PASSWORD_MIN_SIZE &&
209         g_ascii_strcasecmp(gtk_entry_get_text(password), gtk_entry_get_text(password_confirm)) == 0) {
210                 is_password_correct = 1;
211                 gtk_image_set_from_pixbuf(isPasswordOk, ok);
212                 gtk_label_set_text(passwordError, "");
213         }
214         else {
215                 if (gtk_entry_get_text_length(password) < PASSWORD_MIN_SIZE) {
216                         gtk_label_set_text(passwordError, "Password is too short !");
217                 }
218                 else if (!g_ascii_strcasecmp(gtk_entry_get_text(password), gtk_entry_get_text(password_confirm)) == 0) {
219                         gtk_label_set_text(passwordError, "Passwords don't match !");
220                 }
221                 is_password_correct = 0;
222                 gtk_image_set_from_pixbuf(isPasswordOk, notok);
223         }
224         gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
225                         is_account_information_correct(w)>0);
226 }
227
228 void* check_username_availability(void* w) {
229         GtkWidget *assistant=gtk_widget_get_toplevel(GTK_WIDGET(w));
230         GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
231         GtkImage* isUsernameOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"usernameOk"));
232         GtkLabel* usernameError = GTK_LABEL(g_object_get_data(G_OBJECT(w),"error"));
233
234         LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant);
235         linphone_account_creator_set_username(creator, gtk_entry_get_text(username));
236
237         if (g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) {
238                 int account_existing = linphone_account_creator_test_existence(creator);
239                 if (account_existing == 0) {
240                         is_username_available = 1;
241                         gtk_image_set_from_pixbuf(isUsernameOk, ok);
242                         gtk_label_set_text(usernameError, "");
243                 }
244                 else {
245                         gtk_label_set_text(usernameError, "Username is already in use !");
246                         is_username_available = 0;
247                         gtk_image_set_from_pixbuf(isUsernameOk, notok);
248                 }
249         }
250         else {
251                 if (gtk_entry_get_text_length(username) < LOGIN_MIN_SIZE) {
252                         gtk_label_set_text(usernameError, "Username is too short");
253                 }
254                 else if (!g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) {
255                         gtk_label_set_text(usernameError, "Unauthorized username");
256                 }
257                 is_username_available = 0;
258                 gtk_image_set_from_pixbuf(isUsernameOk, notok);
259         }
260
261         gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
262                         is_account_information_correct(w)>0);
263
264         return NULL;
265 }
266
267 static void account_username_changed(GtkEntry *entry, GtkWidget *w) {
268         // Verifying if username choosed is available, and if form is correctly filled, let the user go next page
269         pthread_t thread;
270         pthread_create(&thread, NULL, check_username_availability, (void*)w);
271 }
272
273 static GtkWidget *create_account_information_page() {
274         GtkWidget *vbox=gtk_table_new(7, 3, FALSE);
275
276         GtkWidget *label=gtk_label_new(_("(*) Required fields"));
277         GtkWidget *labelUsername=gtk_label_new(_("Username: (*)"));
278         GtkWidget *isUsernameOk=gtk_image_new_from_pixbuf(notok);
279         GtkWidget *labelPassword=gtk_label_new(_("Password: (*)"));
280         GtkWidget *isPasswordOk=gtk_image_new_from_pixbuf(notok);
281         GtkWidget *labelEmail=gtk_label_new(_("Email: (*)"));
282         GtkWidget *isEmailOk=gtk_image_new_from_pixbuf(notok);
283         GtkWidget *labelPassword2=gtk_label_new(_("Confirm your password: (*)"));
284         GtkWidget *entryUsername=gtk_entry_new();
285         GtkWidget *entryPassword=gtk_entry_new();
286         gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
287         GtkWidget *entryEmail=gtk_entry_new();
288         GtkWidget *entryPassword2=gtk_entry_new();
289         gtk_entry_set_visibility(GTK_ENTRY(entryPassword2), FALSE);
290         GtkWidget *checkNewsletter=gtk_check_button_new_with_label("Keep me informed with linphone updates");
291
292         GdkColor color;
293         gdk_color_parse ("red", &color);
294         GtkWidget *labelError=gtk_label_new(NULL);
295         gtk_widget_modify_fg(labelError, GTK_STATE_NORMAL, &color);
296
297         GtkWidget *passwordVbox1=gtk_vbox_new(FALSE,2);
298         GtkWidget *passwordVbox2=gtk_vbox_new(FALSE,2);
299         gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword, TRUE, FALSE, 2);
300         gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword2, TRUE, FALSE, 2);
301         gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword, TRUE, FALSE, 2);
302         gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword2, TRUE, FALSE, 2);
303
304         gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 3, 0, 1);
305         gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmail, 0, 1, 1, 2);
306         gtk_table_attach_defaults(GTK_TABLE(vbox), entryEmail, 1, 2, 1, 2);
307         gtk_table_attach_defaults(GTK_TABLE(vbox), isEmailOk, 2, 3, 1, 2);
308         gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 2, 3);
309         gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 2, 3);
310         gtk_table_attach_defaults(GTK_TABLE(vbox), isUsernameOk, 2, 3, 2, 3);
311         gtk_table_attach_defaults(GTK_TABLE(vbox), passwordVbox1, 0, 1, 3, 4);
312         gtk_table_attach_defaults(GTK_TABLE(vbox), passwordVbox2, 1, 2, 3, 4);
313         gtk_table_attach_defaults(GTK_TABLE(vbox), isPasswordOk, 2, 3, 3, 4);
314         gtk_table_attach_defaults(GTK_TABLE(vbox), labelError, 1, 4, 5, 6);
315         gtk_table_attach_defaults(GTK_TABLE(vbox), checkNewsletter, 0, 3, 6, 7);
316
317         gtk_widget_show_all(vbox);
318         g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
319         g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
320         g_object_set_data(G_OBJECT(vbox),"email",entryEmail);
321         g_object_set_data(G_OBJECT(vbox),"usernameOk",isUsernameOk);
322         g_object_set_data(G_OBJECT(vbox),"passwordOk",isPasswordOk);
323         g_object_set_data(G_OBJECT(vbox),"emailOk",isEmailOk);
324         g_object_set_data(G_OBJECT(vbox),"password_confirm",entryPassword2);
325         g_object_set_data(G_OBJECT(vbox),"newsletter",checkNewsletter);
326         g_object_set_data(G_OBJECT(vbox),"error",labelError);
327         g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_username_changed,vbox);
328         g_signal_connect(G_OBJECT(entryPassword),"changed",(GCallback)account_password_changed,vbox);
329         g_signal_connect(G_OBJECT(entryEmail),"changed",(GCallback)account_email_changed,vbox);
330         g_signal_connect(G_OBJECT(entryPassword2),"changed",(GCallback)account_password_changed,vbox);
331         return vbox;
332 }
333
334 /*
335 static GtkWidget *create_confirmation_page(){
336         GtkWidget *vbox=gtk_vbox_new(FALSE,2);
337         GtkWidget *label=gtk_label_new(NULL);
338         gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
339         g_object_set_data(G_OBJECT(vbox),"label",label);
340         gtk_widget_show_all(vbox);
341         return vbox;
342 }
343 */
344
345 static GtkWidget *create_error_page(){
346         GtkWidget *vbox=gtk_table_new(2, 1, FALSE);
347         GtkWidget *label=gtk_label_new(_("Error, account not validated, username already used or server unreachable.\nPlease go back and try again."));
348
349         gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100);
350
351         g_object_set_data(G_OBJECT(vbox),"label",label);
352         gtk_widget_show_all(vbox);
353         return vbox;
354 }
355
356 static GtkWidget *create_finish_page(){
357         GtkWidget *vbox=gtk_vbox_new(FALSE,2);
358         GtkWidget *label=gtk_label_new(_("Thank you. Your account is now configured and ready for use."));
359         gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
360         gtk_widget_show_all(vbox);
361         return vbox;
362 }
363
364 static GtkWidget *wait_for_activation() {
365         GtkWidget *vbox=gtk_table_new(2, 1, FALSE);
366         GtkWidget *label=gtk_label_new(_("Please validate your account by clicking on the link we just sent you by email.\n"
367                         "Then come back here and press Next button."));
368
369         gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100);
370
371         g_object_set_data(G_OBJECT(vbox),"label",label);
372         gtk_widget_show_all(vbox);
373         return vbox;
374 }
375
376 static int is_account_validated(GtkWidget *page) {
377         LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page));
378         return linphone_account_creator_test_validation(creator);
379 }
380
381 static void linphone_gtk_assistant_closed(GtkWidget *w){
382         gtk_widget_destroy(w);
383 }
384
385 static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page){
386         int pagenum=gtk_assistant_get_current_page(GTK_ASSISTANT(assistant));
387
388         if (pagenum == 5) {
389                 gtk_assistant_commit(GTK_ASSISTANT(assistant));
390         } else if (pagenum == gtk_assistant_get_n_pages(GTK_ASSISTANT(assistant)) - 1) {
391                 // Saving the account and making it default
392                 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant);
393                 LinphoneProxyConfig *cfg=linphone_proxy_config_new();
394                 linphone_proxy_config_set_identity(cfg, creator->username);
395                 linphone_proxy_config_set_server_addr(cfg, creator->domain);
396                 linphone_proxy_config_set_route(cfg, creator->route);
397                 linphone_proxy_config_expires(cfg, 3600);
398                 linphone_proxy_config_enable_publish(cfg, FALSE);
399                 linphone_proxy_config_enable_register(cfg, TRUE);
400
401                 gchar *username = creator->username + 4;
402                 const gchar *needle = "@";
403                 username = g_strndup(username, (g_strrstr(username, needle) - username));
404                 gchar domain[128];
405                 g_snprintf(domain, sizeof(domain), "\"%s\"", creator->domain + 4);
406                 LinphoneAuthInfo *info=linphone_auth_info_new(username, username, creator->password, NULL, domain);
407                 linphone_core_add_auth_info(linphone_gtk_get_core(),info);
408
409                 if (linphone_core_add_proxy_config(linphone_gtk_get_core(),cfg)==-1)
410                         return;
411
412                 linphone_core_set_default_proxy(linphone_gtk_get_core(),cfg);
413                 linphone_gtk_load_identities();
414
415                 // If account created on sip.linphone.org, we configure linphone to use TLS by default
416                 g_warning("Domain : %s", creator->domain);
417                 if (strcmp(creator->domain, "sip:sip.linphone.org") == 0) {
418                         LCSipTransports tr;
419                         LinphoneCore* lc = linphone_gtk_get_core();
420                         linphone_core_get_sip_transports(lc,&tr);
421                         tr.tls_port = tr.udp_port + tr.tcp_port + tr.tls_port;
422                         tr.udp_port = 0;
423                         tr.tcp_port = 0;
424                         linphone_core_set_sip_transports(lc,&tr);
425                 }
426         }
427 }
428
429 static int linphone_gtk_assistant_forward(int curpage, gpointer data){
430         GtkWidget *w=(GtkWidget*)data;
431         GtkWidget *box=gtk_assistant_get_nth_page(GTK_ASSISTANT(w),curpage);
432         if (curpage==1){
433                 GtkWidget *create_button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"create_account");
434                 GtkWidget *setup_linphone_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_linphone_account");
435                 GtkWidget *setup_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_account");
436
437                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(create_button))) {
438                         curpage += 3; // Going to P33
439                 }
440                 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_linphone_account))) {
441                         curpage += 2; // Going to P32
442                 }
443                 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_account))) {
444                         curpage += 1; // Going to P31
445                 }
446         }
447         else if (curpage == 2) { // Account's informations entered
448                 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
449                 gchar identity[128];
450                 g_snprintf(identity, sizeof(identity), "sip:%s@%s", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))), gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain"))));
451
452                 gchar proxy[128];
453                 g_snprintf(proxy, sizeof(proxy), "sip:%s", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain"))));
454
455                 linphone_account_creator_set_username(c, identity);
456                 linphone_account_creator_set_domain(c, proxy);
457                 linphone_account_creator_set_route(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"proxy"))));
458                 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
459                 curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page
460         }
461         else if (curpage == 3) { // Linphone Account's informations entered
462                 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
463                 gchar identity[128];
464                 g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
465                 linphone_account_creator_set_username(c, identity);
466                 linphone_account_creator_set_domain(c, "sip:sip.linphone.org");
467                 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
468                 curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page
469         }
470         else if (curpage == 4) { // Password & Email entered
471                 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
472                 linphone_account_creator_set_username(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
473                 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
474                 linphone_account_creator_set_email(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"email"))));
475                 linphone_account_creator_set_suscribe(c,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(box),"newsletter"))));
476                 if (create_account(w) == 1) {
477                         curpage += 1;
478                 } else { // Error when attempting to create the account
479                         curpage += 2;
480                 }
481         }
482         else if (curpage == 5) { // Waiting for account validation
483                 if (is_account_validated(w) == 1) {
484                         curpage += 2; // Going to the last page
485                 } else {
486                         curpage += 1;
487                 }
488         }
489         else {
490                 curpage += 1;
491         }
492         return curpage;
493 }
494
495 static LinphoneAccountCreator * linphone_gtk_assistant_init(GtkWidget *w){
496         const MSList *elem;
497         LinphoneCore *lc=linphone_gtk_get_core();
498         for(elem=linphone_core_get_sip_setups(lc);elem!=NULL;elem=elem->next){
499                 SipSetup *ss=(SipSetup*)elem->data;
500                 if (sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_ACCOUNT_MANAGER){
501                         LinphoneAccountCreator *creator=linphone_account_creator_new(lc,ss->name);
502                         g_object_set_data(G_OBJECT(w),"creator",creator);
503                         return creator;
504                 }
505         }
506         return NULL;
507 }
508
509 static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w){
510         return (LinphoneAccountCreator*)g_object_get_data(G_OBJECT(w),"creator");
511 }
512
513 GtkWidget * linphone_gtk_create_assistant(void){
514         GtkWidget *w=gtk_assistant_new();
515         gtk_window_set_resizable (GTK_WINDOW(w), FALSE);
516
517         ok = create_pixbuf(linphone_gtk_get_ui_config("ok","ok.png"));
518         notok = create_pixbuf(linphone_gtk_get_ui_config("notok","notok.png"));
519
520         GtkWidget *p1=create_intro();
521         GtkWidget *p2=create_setup_signin_choice();
522         GtkWidget *p31=create_account_informations_page();
523         GtkWidget *p32=create_linphone_account_informations_page();
524         GtkWidget *p33=create_account_information_page();
525         //GtkWidget *confirm=create_confirmation_page();
526         GtkWidget *validate=wait_for_activation();
527         GtkWidget *error=create_error_page();
528         GtkWidget *end=create_finish_page();
529         
530         linphone_gtk_assistant_init(w);
531         gtk_assistant_append_page(GTK_ASSISTANT(w),p1);
532         gtk_assistant_set_page_type(GTK_ASSISTANT(w),p1,GTK_ASSISTANT_PAGE_INTRO);
533         gtk_assistant_set_page_title(GTK_ASSISTANT(w),p1,_("Welcome to the account setup assistant"));
534         gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p1,TRUE);
535
536         gtk_assistant_append_page(GTK_ASSISTANT(w),p2);
537         gtk_assistant_set_page_type(GTK_ASSISTANT(w),p2,GTK_ASSISTANT_PAGE_CONTENT);
538         gtk_assistant_set_page_title(GTK_ASSISTANT(w),p2,_("Account setup assistant"));
539         gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p2,TRUE);
540
541         gtk_assistant_append_page(GTK_ASSISTANT(w),p31);
542         gtk_assistant_set_page_type(GTK_ASSISTANT(w),p31,GTK_ASSISTANT_PAGE_CONFIRM);
543         gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p31,FALSE);
544         gtk_assistant_set_page_title(GTK_ASSISTANT(w),p31,_("Configure your account (step 1/1)"));
545
546         gtk_assistant_append_page(GTK_ASSISTANT(w),p32);
547         gtk_assistant_set_page_type(GTK_ASSISTANT(w),p32,GTK_ASSISTANT_PAGE_CONFIRM);
548         gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p32,FALSE);
549         gtk_assistant_set_page_title(GTK_ASSISTANT(w),p32,_("Enter your sip username (step 1/1)"));
550
551         gtk_assistant_append_page(GTK_ASSISTANT(w),p33);
552         gtk_assistant_set_page_type(GTK_ASSISTANT(w),p33,GTK_ASSISTANT_PAGE_CONFIRM);
553         gtk_assistant_set_page_title(GTK_ASSISTANT(w),p33,_("Enter account information (step 1/2)"));
554
555         /*gtk_assistant_append_page(GTK_ASSISTANT(w),confirm);
556         gtk_assistant_set_page_type(GTK_ASSISTANT(w),confirm,GTK_ASSISTANT_PAGE_CONFIRM);
557         gtk_assistant_set_page_title(GTK_ASSISTANT(w),confirm,_("Confirmation (step 2/2)"));
558         gtk_assistant_set_page_complete(GTK_ASSISTANT(w),confirm,TRUE);*/
559
560         gtk_assistant_append_page(GTK_ASSISTANT(w),validate);
561         gtk_assistant_set_page_type(GTK_ASSISTANT(w),validate,GTK_ASSISTANT_PAGE_CONTENT);
562         gtk_assistant_set_page_title(GTK_ASSISTANT(w),validate,_("Validation (step 2/2)"));
563         gtk_assistant_set_page_complete(GTK_ASSISTANT(w),validate,TRUE);
564
565         gtk_assistant_append_page(GTK_ASSISTANT(w),error);
566         gtk_assistant_set_page_type(GTK_ASSISTANT(w),error,GTK_ASSISTANT_PAGE_CONTENT);
567         gtk_assistant_set_page_title(GTK_ASSISTANT(w),error,_("Error"));
568
569         gtk_assistant_append_page(GTK_ASSISTANT(w),end);
570         gtk_assistant_set_page_type(GTK_ASSISTANT(w),end,GTK_ASSISTANT_PAGE_SUMMARY);
571         gtk_assistant_set_page_title(GTK_ASSISTANT(w),end,_("Terminating"));
572
573         gtk_assistant_set_forward_page_func(GTK_ASSISTANT(w),linphone_gtk_assistant_forward,w,NULL);
574         g_signal_connect(G_OBJECT(w),"close",(GCallback)linphone_gtk_assistant_closed,NULL);
575         g_signal_connect(G_OBJECT(w),"cancel",(GCallback)linphone_gtk_assistant_closed,NULL);
576         g_signal_connect(G_OBJECT(w),"prepare",(GCallback)linphone_gtk_assistant_prepare,NULL);
577
578         gtk_widget_show(w);
579
580         return w;
581 }