2 linphone, gtk-glade interface.
3 Copyright (C) 2008 Simon MORLAT (simon.morlat@linphone.org)
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.
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.
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.
22 #include <glib/gprintf.h>
23 static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w);
25 static const int PASSWORD_MIN_SIZE = 6;
26 static const int LOGIN_MIN_SIZE = 4;
29 static GdkPixbuf *notok;
31 static GtkWidget *create_intro(){
32 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
33 GtkWidget *label=gtk_label_new(_("Welcome !\nThis assistant will help you to use a SIP account for your calls."));
34 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
35 g_object_set_data(G_OBJECT(vbox),"label",label);
36 gtk_widget_show_all(vbox);
40 static GtkWidget *create_setup_signin_choice(){
41 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
42 GtkWidget *t1=gtk_radio_button_new_with_label(NULL,_("Create an account on linphone.org"));
43 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"));
44 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"));
45 gtk_box_pack_start (GTK_BOX (vbox), t1, TRUE, TRUE, 2);
46 gtk_box_pack_start (GTK_BOX (vbox), t2, TRUE, TRUE, 2);
47 gtk_box_pack_start (GTK_BOX (vbox), t3, TRUE, TRUE, 2);
48 gtk_widget_show_all(vbox);
49 g_object_set_data(G_OBJECT(vbox),"create_account",t1);
50 g_object_set_data(G_OBJECT(vbox),"setup_linphone_account",t2);
51 g_object_set_data(G_OBJECT(vbox),"setup_account",t3);
55 static int all_account_information_entered(GtkWidget *w) {
56 GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
57 GtkEntry* domain = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"domain"));
59 if (gtk_entry_get_text_length(username) > 0 &&
60 gtk_entry_get_text_length(domain) > 0 &&
61 g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$", gtk_entry_get_text(username), 0, 0) &&
62 g_regex_match_simple("^(sip:)?([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$", gtk_entry_get_text(domain), 0, 0)) {
68 static void account_informations_changed(GtkEntry *entry, GtkWidget *w) {
69 GtkWidget *assistant=gtk_widget_get_toplevel(w);
70 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
71 all_account_information_entered(w)>0);
74 static void linphone_account_informations_changed(GtkEntry *entry, GtkWidget *w) {
75 GtkWidget *assistant=gtk_widget_get_toplevel(w);
76 GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
78 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
79 gtk_entry_get_text_length(username) >= LOGIN_MIN_SIZE);
82 static GtkWidget *create_linphone_account_informations_page() {
83 GtkWidget *vbox=gtk_table_new(3, 2, TRUE);
84 GtkWidget *label=gtk_label_new(_("Enter your linphone.org username"));
87 gdk_color_parse ("red", &color);
88 GtkWidget *labelEmpty=gtk_label_new(NULL);
89 gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color);
91 GtkWidget *labelUsername=gtk_label_new(_("Username:"));
92 GtkWidget *entryUsername=gtk_entry_new();
93 GtkWidget *labelPassword=gtk_label_new(_("Password:"));
94 GtkWidget *entryPassword=gtk_entry_new();
95 gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
97 gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1);
98 gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2);
99 gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 1, 2);
100 gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3);
101 gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3);
103 gtk_widget_show_all(vbox);
104 g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
105 g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
106 g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty);
107 g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)linphone_account_informations_changed,vbox);
111 static GtkWidget *create_account_informations_page() {
112 GtkWidget *vbox=gtk_table_new(6, 2, FALSE);
113 GtkWidget *label=gtk_label_new(_("Enter your account informations"));
116 gdk_color_parse ("red", &color);
117 GtkWidget *labelEmpty=gtk_label_new(NULL);
118 gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color);
120 GtkWidget *labelUsername=gtk_label_new(_("Username*"));
121 GtkWidget *labelPassword=gtk_label_new(_("Password*"));
122 GtkWidget *entryPassword=gtk_entry_new();
123 gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
124 GtkWidget *labelDomain=gtk_label_new(_("Domain*"));
125 GtkWidget *labelProxy=gtk_label_new(_("Proxy"));
126 GtkWidget *entryUsername=gtk_entry_new();
127 GtkWidget *entryDomain=gtk_entry_new();
128 GtkWidget *entryRoute=gtk_entry_new();
130 gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1);
131 gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2);
132 gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 1, 2);
133 gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3);
134 gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3);
135 gtk_table_attach_defaults(GTK_TABLE(vbox), labelDomain, 0, 1, 3, 4);
136 gtk_table_attach_defaults(GTK_TABLE(vbox), entryDomain, 1, 2, 3, 4);
137 gtk_table_attach_defaults(GTK_TABLE(vbox), labelProxy, 0, 1, 4, 5);
138 gtk_table_attach_defaults(GTK_TABLE(vbox), entryRoute, 1, 2, 4, 5);
139 gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmpty, 0, 2, 5, 6);
140 gtk_widget_show_all(vbox);
142 g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
143 g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
144 g_object_set_data(G_OBJECT(vbox),"domain",entryDomain);
145 g_object_set_data(G_OBJECT(vbox),"proxy",entryRoute);
146 g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty);
147 g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_informations_changed,vbox);
148 g_signal_connect(G_OBJECT(entryDomain),"changed",(GCallback)account_informations_changed,vbox);
149 g_signal_connect(G_OBJECT(entryRoute),"changed",(GCallback)account_informations_changed,vbox);
154 static int create_account(GtkWidget *page) {
155 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page));
156 LinphoneProxyConfig *res=linphone_account_creator_validate(creator);
158 if (!g_regex_match_simple("^sip:[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}@sip.linphone.org$",creator->username, 0, 0)) {
160 g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", creator->username);
161 linphone_account_creator_set_username(creator, identity);
162 linphone_account_creator_set_domain(creator, "sip:sip.linphone.org");
169 static int is_account_information_correct(GtkWidget *w) {
170 int is_username_available = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_username_available"));
171 int is_email_correct = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_email_correct"));
172 int is_password_correct = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_password_correct"));
174 if (is_username_available == 1 && is_email_correct == 1 && is_password_correct == 1) {
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
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);
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 g_object_set_data(G_OBJECT(w),"is_email_correct",GINT_TO_POINTER(1));
189 gtk_image_set_from_pixbuf(isEmailOk, ok);
192 g_object_set_data(G_OBJECT(w),"is_email_correct",GINT_TO_POINTER(0));
193 gtk_image_set_from_pixbuf(isEmailOk, notok);
195 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
196 is_account_information_correct(w)>0);
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
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"));
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 g_object_set_data(G_OBJECT(w),"is_password_correct",GINT_TO_POINTER(1));
211 gtk_image_set_from_pixbuf(isPasswordOk, ok);
212 gtk_label_set_text(passwordError, "");
215 if (gtk_entry_get_text_length(password) < PASSWORD_MIN_SIZE) {
216 gtk_label_set_text(passwordError, "Password is too short !");
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 !");
221 g_object_set_data(G_OBJECT(w),"is_password_correct",GINT_TO_POINTER(0));
222 gtk_image_set_from_pixbuf(isPasswordOk, notok);
224 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
225 is_account_information_correct(w)>0);
228 gboolean update_interface_with_username_availability(gpointer *w) {
229 GtkWidget *assistant = gtk_widget_get_toplevel(GTK_WIDGET(w));
230 GtkImage* isUsernameOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"usernameOk"));
231 GtkLabel* usernameError = GTK_LABEL(g_object_get_data(G_OBJECT(w),"error"));
232 int account_existing = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_username_used"));
234 if (account_existing == 0) {
235 g_object_set_data(G_OBJECT(w),"is_username_available",GINT_TO_POINTER(1));
236 gtk_image_set_from_pixbuf(isUsernameOk, ok);
237 gtk_label_set_text(usernameError, "");
240 gtk_label_set_text(usernameError, "Username is already in use !");
241 g_object_set_data(G_OBJECT(w),"is_username_available",GINT_TO_POINTER(0));
242 gtk_image_set_from_pixbuf(isUsernameOk, notok);
245 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),GTK_WIDGET(w),
246 is_account_information_correct(GTK_WIDGET(w))>0);
251 void* check_username_availability(void* w) {
252 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(GTK_WIDGET(w)));
254 int account_existing = linphone_account_creator_test_existence(creator);
256 g_object_set_data(G_OBJECT(w),"is_username_used",GINT_TO_POINTER(account_existing));
257 gdk_threads_add_idle((GSourceFunc)update_interface_with_username_availability, (void*)w);
262 static void account_username_changed(GtkEntry *entry, GtkWidget *w) {
263 // Verifying if username choosed is available, and if form is correctly filled, let the user go next page
264 GtkWidget *assistant = gtk_widget_get_toplevel(GTK_WIDGET(w));
265 GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
266 GtkImage* isUsernameOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"usernameOk"));
267 GtkLabel* usernameError = GTK_LABEL(g_object_get_data(G_OBJECT(w),"error"));
269 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant);
270 linphone_account_creator_set_username(creator, gtk_entry_get_text(username));
272 if (g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) {
273 #if !GLIB_CHECK_VERSION(2, 31, 0)
274 g_thread_create(check_username_availability, (void*)w, FALSE, NULL);
276 g_thread_new(NULL, check_username_availability, w);
280 if (gtk_entry_get_text_length(username) < LOGIN_MIN_SIZE) {
281 gtk_label_set_text(usernameError, "Username is too short");
283 else if (!g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) {
284 gtk_label_set_text(usernameError, "Unauthorized username");
286 g_object_set_data(G_OBJECT(w),"is_username_available",GINT_TO_POINTER(0));
287 gtk_image_set_from_pixbuf(isUsernameOk, notok);
289 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
290 is_account_information_correct(w)>0);
294 static GtkWidget *create_account_information_page() {
295 GtkWidget *vbox=gtk_table_new(7, 3, FALSE);
297 GtkWidget *label=gtk_label_new(_("(*) Required fields"));
298 GtkWidget *labelUsername=gtk_label_new(_("Username: (*)"));
299 GtkWidget *isUsernameOk=gtk_image_new_from_pixbuf(notok);
300 GtkWidget *labelPassword=gtk_label_new(_("Password: (*)"));
301 GtkWidget *isPasswordOk=gtk_image_new_from_pixbuf(notok);
302 GtkWidget *labelEmail=gtk_label_new(_("Email: (*)"));
303 GtkWidget *isEmailOk=gtk_image_new_from_pixbuf(notok);
304 GtkWidget *labelPassword2=gtk_label_new(_("Confirm your password: (*)"));
305 GtkWidget *entryUsername=gtk_entry_new();
306 GtkWidget *entryPassword=gtk_entry_new();
307 gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
308 GtkWidget *entryEmail=gtk_entry_new();
309 GtkWidget *entryPassword2=gtk_entry_new();
310 gtk_entry_set_visibility(GTK_ENTRY(entryPassword2), FALSE);
311 GtkWidget *checkNewsletter=gtk_check_button_new_with_label("Keep me informed with linphone updates");
314 gdk_color_parse ("red", &color);
315 GtkWidget *labelError=gtk_label_new(NULL);
316 gtk_widget_modify_fg(labelError, GTK_STATE_NORMAL, &color);
318 GtkWidget *passwordVbox1=gtk_vbox_new(FALSE,2);
319 GtkWidget *passwordVbox2=gtk_vbox_new(FALSE,2);
320 gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword, TRUE, FALSE, 2);
321 gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword2, TRUE, FALSE, 2);
322 gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword, TRUE, FALSE, 2);
323 gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword2, TRUE, FALSE, 2);
325 gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 3, 0, 1);
326 gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmail, 0, 1, 1, 2);
327 gtk_table_attach_defaults(GTK_TABLE(vbox), entryEmail, 1, 2, 1, 2);
328 gtk_table_attach_defaults(GTK_TABLE(vbox), isEmailOk, 2, 3, 1, 2);
329 gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 2, 3);
330 gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 2, 3);
331 gtk_table_attach_defaults(GTK_TABLE(vbox), isUsernameOk, 2, 3, 2, 3);
332 gtk_table_attach_defaults(GTK_TABLE(vbox), passwordVbox1, 0, 1, 3, 4);
333 gtk_table_attach_defaults(GTK_TABLE(vbox), passwordVbox2, 1, 2, 3, 4);
334 gtk_table_attach_defaults(GTK_TABLE(vbox), isPasswordOk, 2, 3, 3, 4);
335 gtk_table_attach_defaults(GTK_TABLE(vbox), labelError, 1, 4, 5, 6);
336 gtk_table_attach_defaults(GTK_TABLE(vbox), checkNewsletter, 0, 3, 6, 7);
338 gtk_widget_show_all(vbox);
339 g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
340 g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
341 g_object_set_data(G_OBJECT(vbox),"email",entryEmail);
342 g_object_set_data(G_OBJECT(vbox),"usernameOk",isUsernameOk);
343 g_object_set_data(G_OBJECT(vbox),"passwordOk",isPasswordOk);
344 g_object_set_data(G_OBJECT(vbox),"emailOk",isEmailOk);
345 g_object_set_data(G_OBJECT(vbox),"password_confirm",entryPassword2);
346 g_object_set_data(G_OBJECT(vbox),"newsletter",checkNewsletter);
347 g_object_set_data(G_OBJECT(vbox),"error",labelError);
348 g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_username_changed,vbox);
349 g_signal_connect(G_OBJECT(entryPassword),"changed",(GCallback)account_password_changed,vbox);
350 g_signal_connect(G_OBJECT(entryEmail),"changed",(GCallback)account_email_changed,vbox);
351 g_signal_connect(G_OBJECT(entryPassword2),"changed",(GCallback)account_password_changed,vbox);
356 static GtkWidget *create_confirmation_page(){
357 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
358 GtkWidget *label=gtk_label_new(NULL);
359 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
360 g_object_set_data(G_OBJECT(vbox),"label",label);
361 gtk_widget_show_all(vbox);
366 static GtkWidget *create_error_page(){
367 GtkWidget *vbox=gtk_table_new(2, 1, FALSE);
368 GtkWidget *label=gtk_label_new(_("Error, account not validated, username already used or server unreachable.\nPlease go back and try again."));
370 gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100);
372 g_object_set_data(G_OBJECT(vbox),"label",label);
373 gtk_widget_show_all(vbox);
377 static GtkWidget *create_finish_page(){
378 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
379 GtkWidget *label=gtk_label_new(_("Thank you. Your account is now configured and ready for use."));
380 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
381 gtk_widget_show_all(vbox);
385 static GtkWidget *wait_for_activation() {
386 GtkWidget *vbox=gtk_table_new(2, 1, FALSE);
387 GtkWidget *label=gtk_label_new(_("Please validate your account by clicking on the link we just sent you by email.\n"
388 "Then come back here and press Next button."));
390 gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100);
392 g_object_set_data(G_OBJECT(vbox),"label",label);
393 gtk_widget_show_all(vbox);
397 static int is_account_validated(GtkWidget *page) {
398 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page));
399 return linphone_account_creator_test_validation(creator);
402 static void linphone_gtk_assistant_closed(GtkWidget *w){
403 gtk_widget_destroy(w);
406 static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page){
407 int pagenum=gtk_assistant_get_current_page(GTK_ASSISTANT(assistant));
410 gtk_assistant_commit(GTK_ASSISTANT(assistant));
411 } else if (pagenum == gtk_assistant_get_n_pages(GTK_ASSISTANT(assistant)) - 1) {
412 // Saving the account and making it default
413 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant);
414 LinphoneProxyConfig *cfg=linphone_proxy_config_new();
415 linphone_proxy_config_set_identity(cfg, creator->username);
416 linphone_proxy_config_set_server_addr(cfg, creator->domain);
417 linphone_proxy_config_set_route(cfg, creator->route);
418 linphone_proxy_config_expires(cfg, 3600);
419 linphone_proxy_config_enable_publish(cfg, FALSE);
420 linphone_proxy_config_enable_register(cfg, TRUE);
422 gchar *username = creator->username + 4;
423 const gchar *needle = "@";
424 username = g_strndup(username, (g_strrstr(username, needle) - username));
426 g_snprintf(domain, sizeof(domain), "\"%s\"", creator->domain + 4);
427 LinphoneAuthInfo *info=linphone_auth_info_new(username, username, creator->password, NULL, domain);
428 linphone_core_add_auth_info(linphone_gtk_get_core(),info);
430 if (linphone_core_add_proxy_config(linphone_gtk_get_core(),cfg)==-1)
433 linphone_core_set_default_proxy(linphone_gtk_get_core(),cfg);
434 linphone_gtk_load_identities();
436 // If account created on sip.linphone.org, we configure linphone to use TLS by default
437 g_warning("Domain : %s", creator->domain);
438 if (strcmp(creator->domain, "sip:sip.linphone.org") == 0) {
440 LinphoneCore* lc = linphone_gtk_get_core();
441 linphone_core_get_sip_transports(lc,&tr);
442 tr.tls_port = tr.udp_port + tr.tcp_port + tr.tls_port;
445 linphone_core_set_sip_transports(lc,&tr);
450 static int linphone_gtk_assistant_forward(int curpage, gpointer data){
451 GtkWidget *w=(GtkWidget*)data;
452 GtkWidget *box=gtk_assistant_get_nth_page(GTK_ASSISTANT(w),curpage);
454 GtkWidget *create_button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"create_account");
455 GtkWidget *setup_linphone_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_linphone_account");
456 GtkWidget *setup_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_account");
458 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(create_button))) {
459 curpage += 3; // Going to P33
461 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_linphone_account))) {
462 curpage += 2; // Going to P32
464 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_account))) {
465 curpage += 1; // Going to P31
468 else if (curpage == 2) { // Account's informations entered
469 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
471 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"))));
474 g_snprintf(proxy, sizeof(proxy), "sip:%s", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain"))));
476 linphone_account_creator_set_username(c, identity);
477 linphone_account_creator_set_domain(c, proxy);
478 linphone_account_creator_set_route(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"proxy"))));
479 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
480 curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page
482 else if (curpage == 3) { // Linphone Account's informations entered
483 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
485 g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
486 linphone_account_creator_set_username(c, identity);
487 linphone_account_creator_set_domain(c, "sip:sip.linphone.org");
488 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
489 curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page
491 else if (curpage == 4) { // Password & Email entered
492 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
493 linphone_account_creator_set_username(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
494 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
495 linphone_account_creator_set_email(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"email"))));
496 linphone_account_creator_set_suscribe(c,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(box),"newsletter"))));
497 if (create_account(w) == 1) {
499 } else { // Error when attempting to create the account
503 else if (curpage == 5) { // Waiting for account validation
504 if (is_account_validated(w) == 1) {
505 curpage += 2; // Going to the last page
516 static LinphoneAccountCreator * linphone_gtk_assistant_init(GtkWidget *w){
518 LinphoneCore *lc=linphone_gtk_get_core();
519 for(elem=linphone_core_get_sip_setups(lc);elem!=NULL;elem=elem->next){
520 SipSetup *ss=(SipSetup*)elem->data;
521 if (sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_ACCOUNT_MANAGER){
522 LinphoneAccountCreator *creator=linphone_account_creator_new(lc,ss->name);
523 g_object_set_data(G_OBJECT(w),"creator",creator);
530 static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w){
531 return (LinphoneAccountCreator*)g_object_get_data(G_OBJECT(w),"creator");
534 GtkWidget * linphone_gtk_create_assistant(void){
535 GtkWidget *w=gtk_assistant_new();
536 gtk_window_set_resizable (GTK_WINDOW(w), FALSE);
538 ok = create_pixbuf(linphone_gtk_get_ui_config("ok","ok.png"));
539 notok = create_pixbuf(linphone_gtk_get_ui_config("notok","notok.png"));
541 GtkWidget *p1=create_intro();
542 GtkWidget *p2=create_setup_signin_choice();
543 GtkWidget *p31=create_account_informations_page();
544 GtkWidget *p32=create_linphone_account_informations_page();
545 GtkWidget *p33=create_account_information_page();
546 //GtkWidget *confirm=create_confirmation_page();
547 GtkWidget *validate=wait_for_activation();
548 GtkWidget *error=create_error_page();
549 GtkWidget *end=create_finish_page();
551 linphone_gtk_assistant_init(w);
552 gtk_assistant_append_page(GTK_ASSISTANT(w),p1);
553 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p1,GTK_ASSISTANT_PAGE_INTRO);
554 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p1,_("Welcome to the account setup assistant"));
555 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p1,TRUE);
557 gtk_assistant_append_page(GTK_ASSISTANT(w),p2);
558 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p2,GTK_ASSISTANT_PAGE_CONTENT);
559 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p2,_("Account setup assistant"));
560 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p2,TRUE);
562 gtk_assistant_append_page(GTK_ASSISTANT(w),p31);
563 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p31,GTK_ASSISTANT_PAGE_CONFIRM);
564 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p31,FALSE);
565 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p31,_("Configure your account (step 1/1)"));
567 gtk_assistant_append_page(GTK_ASSISTANT(w),p32);
568 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p32,GTK_ASSISTANT_PAGE_CONFIRM);
569 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p32,FALSE);
570 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p32,_("Enter your sip username (step 1/1)"));
572 gtk_assistant_append_page(GTK_ASSISTANT(w),p33);
573 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p33,GTK_ASSISTANT_PAGE_CONFIRM);
574 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p33,_("Enter account information (step 1/2)"));
576 /*gtk_assistant_append_page(GTK_ASSISTANT(w),confirm);
577 gtk_assistant_set_page_type(GTK_ASSISTANT(w),confirm,GTK_ASSISTANT_PAGE_CONFIRM);
578 gtk_assistant_set_page_title(GTK_ASSISTANT(w),confirm,_("Confirmation (step 2/2)"));
579 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),confirm,TRUE);*/
581 gtk_assistant_append_page(GTK_ASSISTANT(w),validate);
582 gtk_assistant_set_page_type(GTK_ASSISTANT(w),validate,GTK_ASSISTANT_PAGE_CONTENT);
583 gtk_assistant_set_page_title(GTK_ASSISTANT(w),validate,_("Validation (step 2/2)"));
584 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),validate,TRUE);
586 gtk_assistant_append_page(GTK_ASSISTANT(w),error);
587 gtk_assistant_set_page_type(GTK_ASSISTANT(w),error,GTK_ASSISTANT_PAGE_CONTENT);
588 gtk_assistant_set_page_title(GTK_ASSISTANT(w),error,_("Error"));
590 gtk_assistant_append_page(GTK_ASSISTANT(w),end);
591 gtk_assistant_set_page_type(GTK_ASSISTANT(w),end,GTK_ASSISTANT_PAGE_SUMMARY);
592 gtk_assistant_set_page_title(GTK_ASSISTANT(w),end,_("Terminating"));
594 gtk_assistant_set_forward_page_func(GTK_ASSISTANT(w),linphone_gtk_assistant_forward,w,NULL);
595 g_signal_connect(G_OBJECT(w),"close",(GCallback)linphone_gtk_assistant_closed,NULL);
596 g_signal_connect(G_OBJECT(w),"cancel",(GCallback)linphone_gtk_assistant_closed,NULL);
597 g_signal_connect(G_OBJECT(w),"prepare",(GCallback)linphone_gtk_assistant_prepare,NULL);