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;
27 static int is_username_available = 0;
28 static int is_email_correct = 0;
29 static int is_password_correct = 0;
32 static GdkPixbuf *notok;
34 static GtkWidget *create_intro(){
35 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
36 GtkWidget *label=gtk_label_new(_("Welcome !\nThis assistant will help you to use a SIP account for your calls."));
37 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
38 g_object_set_data(G_OBJECT(vbox),"label",label);
39 gtk_widget_show_all(vbox);
43 static GtkWidget *create_setup_signin_choice(){
44 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
45 GtkWidget *t1=gtk_radio_button_new_with_label(NULL,_("Create an account on linphone.org"));
46 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"));
47 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"));
48 gtk_box_pack_start (GTK_BOX (vbox), t1, TRUE, TRUE, 2);
49 gtk_box_pack_start (GTK_BOX (vbox), t2, TRUE, TRUE, 2);
50 gtk_box_pack_start (GTK_BOX (vbox), t3, TRUE, TRUE, 2);
51 gtk_widget_show_all(vbox);
52 g_object_set_data(G_OBJECT(vbox),"create_account",t1);
53 g_object_set_data(G_OBJECT(vbox),"setup_linphone_account",t2);
54 g_object_set_data(G_OBJECT(vbox),"setup_account",t3);
58 static int all_account_information_entered(GtkWidget *w) {
59 GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
60 GtkEntry* domain = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"domain"));
62 if (gtk_entry_get_text_length(username) > 0 &&
63 gtk_entry_get_text_length(domain) > 0 &&
64 g_regex_match_simple("^(sip:)?[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$", gtk_entry_get_text(username), 0, 0) &&
65 g_regex_match_simple("^(sip:)?([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$", gtk_entry_get_text(domain), 0, 0)) {
71 static void account_informations_changed(GtkEntry *entry, GtkWidget *w) {
72 GtkWidget *assistant=gtk_widget_get_toplevel(w);
73 GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
74 GtkEntry* domain = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"domain"));
76 const gchar *needle = "@";
77 if (entry == username && g_strrstr(gtk_entry_get_text(username), needle) != NULL) {
78 gtk_entry_set_text(domain, g_strrstr(gtk_entry_get_text(username), needle)+1);
81 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
82 all_account_information_entered(w)>0);
85 static void linphone_account_informations_changed(GtkEntry *entry, GtkWidget *w) {
86 GtkWidget *assistant=gtk_widget_get_toplevel(w);
87 GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
89 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
90 gtk_entry_get_text_length(username) >= LOGIN_MIN_SIZE);
93 static GtkWidget *create_linphone_account_informations_page() {
94 GtkWidget *vbox=gtk_table_new(3, 2, TRUE);
95 GtkWidget *label=gtk_label_new(_("Enter your linphone.org username"));
98 gdk_color_parse ("red", &color);
99 GtkWidget *labelEmpty=gtk_label_new(NULL);
100 gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color);
102 GtkWidget *labelUsername=gtk_label_new(_("Username:"));
103 GtkWidget *entryUsername=gtk_entry_new();
104 GtkWidget *labelPassword=gtk_label_new(_("Password:"));
105 GtkWidget *entryPassword=gtk_entry_new();
106 gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
108 gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1);
109 gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2);
110 gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 1, 2);
111 gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3);
112 gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3);
114 gtk_widget_show_all(vbox);
115 g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
116 g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
117 g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty);
118 g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)linphone_account_informations_changed,vbox);
122 static GtkWidget *create_account_informations_page() {
123 GtkWidget *vbox=gtk_table_new(6, 2, FALSE);
124 GtkWidget *label=gtk_label_new(_("Enter your account informations"));
127 gdk_color_parse ("red", &color);
128 GtkWidget *labelEmpty=gtk_label_new(NULL);
129 gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color);
131 GtkWidget *labelUsername=gtk_label_new(_("Identity:"));
132 GtkWidget *labelUsernameExemple=gtk_label_new(_("example: user@sip.linphone.org"));
133 GtkWidget *labelPassword=gtk_label_new(_("Password:"));
134 GtkWidget *entryPassword=gtk_entry_new();
135 gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
136 GtkWidget *labelDomain=gtk_label_new(_("Proxy:"));
137 GtkWidget *labelDomainExemple=gtk_label_new(_("example: sip.linphone.org"));
138 GtkWidget *labelRoute=gtk_label_new(_("Route (optional):"));
139 GtkWidget *entryUsername=gtk_entry_new();
140 GtkWidget *entryDomain=gtk_entry_new();
141 GtkWidget *entryRoute=gtk_entry_new();
143 GtkWidget *vbox1=gtk_vbox_new(FALSE, 1);
144 gtk_box_pack_start (GTK_BOX (vbox1), entryUsername, TRUE, TRUE, 1);
145 gtk_box_pack_start (GTK_BOX (vbox1), labelUsernameExemple, TRUE, TRUE, 1);
146 GtkWidget *vbox2=gtk_vbox_new(FALSE, 1);
147 gtk_box_pack_start (GTK_BOX (vbox2), entryDomain, TRUE, TRUE, 1);
148 gtk_box_pack_start (GTK_BOX (vbox2), labelDomainExemple, TRUE, TRUE, 1);
149 gtk_table_set_row_spacing(GTK_TABLE(vbox), 1, 10);
150 gtk_table_set_row_spacing(GTK_TABLE(vbox), 3, 5);
152 gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1);
153 gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2);
154 gtk_table_attach_defaults(GTK_TABLE(vbox), vbox1, 1, 2, 1, 2);
155 gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3);
156 gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3);
157 gtk_table_attach_defaults(GTK_TABLE(vbox), labelDomain, 0, 1, 3, 4);
158 gtk_table_attach_defaults(GTK_TABLE(vbox), vbox2, 1, 2, 3, 4);
159 gtk_table_attach_defaults(GTK_TABLE(vbox), labelRoute, 0, 1, 4, 5);
160 gtk_table_attach_defaults(GTK_TABLE(vbox), entryRoute, 1, 2, 4, 5);
161 gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmpty, 0, 2, 5, 6);
162 gtk_widget_show_all(vbox);
164 g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
165 g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
166 g_object_set_data(G_OBJECT(vbox),"domain",entryDomain);
167 g_object_set_data(G_OBJECT(vbox),"route",entryRoute);
168 g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty);
169 g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_informations_changed,vbox);
170 g_signal_connect(G_OBJECT(entryDomain),"changed",(GCallback)account_informations_changed,vbox);
171 g_signal_connect(G_OBJECT(entryRoute),"changed",(GCallback)account_informations_changed,vbox);
176 static int create_account(GtkWidget *page) {
177 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page));
178 LinphoneProxyConfig *res=linphone_account_creator_validate(creator);
180 if (!g_regex_match_simple("^sip:[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}@sip.linphone.org$",creator->username, 0, 0)) {
182 g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", creator->username);
183 linphone_account_creator_set_username(creator, identity);
184 linphone_account_creator_set_domain(creator, "sip:sip.linphone.org");
191 static int is_account_information_correct(GtkWidget *w) {
192 if (is_username_available == 1 && is_email_correct == 1 && is_password_correct == 1) {
198 static void account_email_changed(GtkEntry *entry, GtkWidget *w) {
199 // Verifying if email entered is correct, and if form is correctly filled, let the user go next page
201 GtkEntry* email = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"email"));
202 GtkImage* isEmailOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"emailOk"));
203 GtkWidget *assistant=gtk_widget_get_toplevel(w);
205 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)) {
206 is_email_correct = 1;
207 gtk_image_set_from_pixbuf(isEmailOk, ok);
210 is_email_correct = 0;
211 gtk_image_set_from_pixbuf(isEmailOk, notok);
213 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
214 is_account_information_correct(w)>0);
217 static void account_password_changed(GtkEntry *entry, GtkWidget *w) {
218 // Verifying if passwords entered match, and if form is correctly filled, let the user go next page
220 GtkEntry* password = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"password"));
221 GtkImage* isPasswordOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"passwordOk"));
222 GtkEntry* password_confirm = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"password_confirm"));
223 GtkWidget *assistant=gtk_widget_get_toplevel(w);
225 if (gtk_entry_get_text_length(password) >= PASSWORD_MIN_SIZE &&
226 g_ascii_strcasecmp(gtk_entry_get_text(password), gtk_entry_get_text(password_confirm)) == 0) {
227 is_password_correct = 1;
228 gtk_image_set_from_pixbuf(isPasswordOk, ok);
231 is_password_correct = 0;
232 gtk_image_set_from_pixbuf(isPasswordOk, notok);
234 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
235 is_account_information_correct(w)>0);
238 static void account_username_changed(GtkEntry *entry, GtkWidget *w) {
239 // Verifying if username choosed is available, and if form is correctly filled, let the user go next page
241 GtkWidget *assistant=gtk_widget_get_toplevel(w);
242 GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
243 GtkImage* isUsernameOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"usernameOk"));
245 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant);
246 linphone_account_creator_set_username(creator, gtk_entry_get_text(username));
247 if (g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$", gtk_entry_get_text(username), 0, 0)
248 && linphone_account_creator_test_existence(creator) == 0) {
249 is_username_available = 1;
250 gtk_image_set_from_pixbuf(isUsernameOk, ok);
253 is_username_available = 0;
254 gtk_image_set_from_pixbuf(isUsernameOk, notok);
257 gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
258 is_account_information_correct(w)>0);
261 static GtkWidget *create_account_information_page() {
262 GtkWidget *vbox=gtk_table_new(7, 3, FALSE);
264 GtkWidget *label=gtk_label_new(_("(*) Required fields"));
265 GtkWidget *labelUsername=gtk_label_new(_("Username: (*)"));
266 GtkWidget *isUsernameOk=gtk_image_new_from_pixbuf(notok);
267 GtkWidget *labelPassword=gtk_label_new(_("Password: (*)"));
268 GtkWidget *isPasswordOk=gtk_image_new_from_pixbuf(notok);
269 GtkWidget *labelEmail=gtk_label_new(_("Email: (*)"));
270 GtkWidget *isEmailOk=gtk_image_new_from_pixbuf(notok);
271 GtkWidget *labelPassword2=gtk_label_new(_("Confirm your password: (*)"));
272 GtkWidget *entryUsername=gtk_entry_new();
273 GtkWidget *entryPassword=gtk_entry_new();
274 gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE);
275 GtkWidget *entryEmail=gtk_entry_new();
276 GtkWidget *entryPassword2=gtk_entry_new();
277 gtk_entry_set_visibility(GTK_ENTRY(entryPassword2), FALSE);
278 GtkWidget *checkNewsletter=gtk_check_button_new_with_label("Keep me informed with linphone updates");
280 GtkWidget *passwordVbox1=gtk_vbox_new(FALSE,2);
281 GtkWidget *passwordVbox2=gtk_vbox_new(FALSE,2);
282 gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword, TRUE, FALSE, 2);
283 gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword2, TRUE, FALSE, 2);
284 gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword, TRUE, FALSE, 2);
285 gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword2, TRUE, FALSE, 2);
287 gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 3, 0, 1);
288 gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmail, 0, 1, 1, 2);
289 gtk_table_attach_defaults(GTK_TABLE(vbox), entryEmail, 1, 2, 1, 2);
290 gtk_table_attach_defaults(GTK_TABLE(vbox), isEmailOk, 2, 3, 1, 2);
291 gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 2, 3);
292 gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 2, 3);
293 gtk_table_attach_defaults(GTK_TABLE(vbox), isUsernameOk, 2, 3, 2, 3);
294 gtk_table_attach_defaults(GTK_TABLE(vbox), passwordVbox1, 0, 1, 3, 4);
295 gtk_table_attach_defaults(GTK_TABLE(vbox), passwordVbox2, 1, 2, 3, 4);
296 gtk_table_attach_defaults(GTK_TABLE(vbox), isPasswordOk, 2, 3, 3, 4);
297 gtk_table_attach_defaults(GTK_TABLE(vbox), checkNewsletter, 0, 3, 5, 6);
299 gtk_widget_show_all(vbox);
300 g_object_set_data(G_OBJECT(vbox),"username",entryUsername);
301 g_object_set_data(G_OBJECT(vbox),"password",entryPassword);
302 g_object_set_data(G_OBJECT(vbox),"email",entryEmail);
303 g_object_set_data(G_OBJECT(vbox),"usernameOk",isUsernameOk);
304 g_object_set_data(G_OBJECT(vbox),"passwordOk",isPasswordOk);
305 g_object_set_data(G_OBJECT(vbox),"emailOk",isEmailOk);
306 g_object_set_data(G_OBJECT(vbox),"password_confirm",entryPassword2);
307 g_object_set_data(G_OBJECT(vbox),"newsletter",checkNewsletter);
308 g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_username_changed,vbox);
309 g_signal_connect(G_OBJECT(entryPassword),"changed",(GCallback)account_password_changed,vbox);
310 g_signal_connect(G_OBJECT(entryEmail),"changed",(GCallback)account_email_changed,vbox);
311 g_signal_connect(G_OBJECT(entryPassword2),"changed",(GCallback)account_password_changed,vbox);
316 static GtkWidget *create_confirmation_page(){
317 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
318 GtkWidget *label=gtk_label_new(NULL);
319 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
320 g_object_set_data(G_OBJECT(vbox),"label",label);
321 gtk_widget_show_all(vbox);
326 static GtkWidget *create_error_page(){
327 GtkWidget *vbox=gtk_table_new(2, 1, FALSE);
328 GtkWidget *label=gtk_label_new(_("Error, account not validated, username already used or server unreachable.\nPlease go back and try again."));
330 gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100);
332 g_object_set_data(G_OBJECT(vbox),"label",label);
333 gtk_widget_show_all(vbox);
337 static GtkWidget *create_finish_page(){
338 GtkWidget *vbox=gtk_vbox_new(FALSE,2);
339 GtkWidget *label=gtk_label_new(_("Thank you. Your account is now configured and ready for use."));
340 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2);
341 gtk_widget_show_all(vbox);
345 static GtkWidget *wait_for_activation() {
346 GtkWidget *vbox=gtk_table_new(2, 1, FALSE);
347 GtkWidget *label=gtk_label_new(_("Please validate your account by clicking on the link we just sent you by email.\n"
348 "Then come back here and press Next button."));
350 gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100);
352 g_object_set_data(G_OBJECT(vbox),"label",label);
353 gtk_widget_show_all(vbox);
357 static int is_account_validated(GtkWidget *page) {
358 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page));
359 return linphone_account_creator_test_validation(creator);
362 static void linphone_gtk_assistant_closed(GtkWidget *w){
363 gtk_widget_destroy(w);
366 static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page){
367 int pagenum=gtk_assistant_get_current_page(GTK_ASSISTANT(assistant));
370 gtk_assistant_commit(GTK_ASSISTANT(assistant));
371 } else if (pagenum == gtk_assistant_get_n_pages(GTK_ASSISTANT(assistant)) - 1) {
372 // Saving the account and making it default
373 LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant);
374 LinphoneProxyConfig *cfg=linphone_proxy_config_new();
375 linphone_proxy_config_set_identity(cfg, creator->username);
376 linphone_proxy_config_set_server_addr(cfg, creator->domain);
377 linphone_proxy_config_set_route(cfg, creator->route);
378 linphone_proxy_config_expires(cfg, 3600);
379 linphone_proxy_config_enable_publish(cfg, FALSE);
380 linphone_proxy_config_enable_register(cfg, TRUE);
382 gchar *username = creator->username + 4;
383 const gchar *needle = "@";
384 username = g_strndup(username, (g_strrstr(username, needle) - username));
386 g_snprintf(domain, sizeof(domain), "\"%s\"", creator->domain + 4);
387 LinphoneAuthInfo *info=linphone_auth_info_new(username, username, creator->password, NULL, domain);
389 linphone_core_add_auth_info(linphone_gtk_get_core(),info);
391 if (linphone_core_add_proxy_config(linphone_gtk_get_core(),cfg)==-1)
394 linphone_core_set_default_proxy(linphone_gtk_get_core(),cfg);
395 linphone_gtk_load_identities();
399 static int linphone_gtk_assistant_forward(int curpage, gpointer data){
400 GtkWidget *w=(GtkWidget*)data;
401 GtkWidget *box=gtk_assistant_get_nth_page(GTK_ASSISTANT(w),curpage);
403 GtkWidget *create_button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"create_account");
404 GtkWidget *setup_linphone_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_linphone_account");
405 GtkWidget *setup_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_account");
407 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(create_button))) {
408 curpage += 3; // Going to P33
410 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_linphone_account))) {
411 curpage += 2; // Going to P32
413 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_account))) {
414 curpage += 1; // Going to P31
417 else if (curpage == 2) { // Account's informations entered
418 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
419 if (!g_regex_match_simple("^sip:[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))), 0, 0)) {
421 g_snprintf(identity, sizeof(identity), "sip:%s", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
422 linphone_account_creator_set_username(c, identity);
424 linphone_account_creator_set_username(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
427 if (!g_regex_match_simple("^sip:([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain"))), 0, 0)) {
429 g_snprintf(proxy, sizeof(proxy), "sip:%s", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain"))));
430 linphone_account_creator_set_domain(c, proxy);
432 linphone_account_creator_set_domain(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain"))));
434 linphone_account_creator_set_route(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"route"))));
435 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
436 curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page
438 else if (curpage == 3) { // Linphone Account's informations entered
439 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
441 g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
442 linphone_account_creator_set_username(c, identity);
443 linphone_account_creator_set_domain(c, "sip:sip.linphone.org");
444 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
445 curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page
447 else if (curpage == 4) { // Password & Email entered
448 LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w);
449 linphone_account_creator_set_username(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))));
450 linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password"))));
451 linphone_account_creator_set_email(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"email"))));
452 linphone_account_creator_set_suscribe(c,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(box),"newsletter"))));
453 if (create_account(w) == 1) {
455 } else { // Error when attempting to create the account
459 else if (curpage == 5) { // Waiting for account validation
460 if (is_account_validated(w) == 1) {
461 curpage += 2; // Going to the last page
472 static LinphoneAccountCreator * linphone_gtk_assistant_init(GtkWidget *w){
474 LinphoneCore *lc=linphone_gtk_get_core();
475 for(elem=linphone_core_get_sip_setups(lc);elem!=NULL;elem=elem->next){
476 SipSetup *ss=(SipSetup*)elem->data;
477 if (sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_ACCOUNT_MANAGER){
478 LinphoneAccountCreator *creator=linphone_account_creator_new(lc,ss->name);
479 g_object_set_data(G_OBJECT(w),"creator",creator);
486 static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w){
487 return (LinphoneAccountCreator*)g_object_get_data(G_OBJECT(w),"creator");
490 GtkWidget * linphone_gtk_create_assistant(void){
491 GtkWidget *w=gtk_assistant_new();
492 gtk_window_set_resizable (GTK_WINDOW(w), FALSE);
494 ok = create_pixbuf(linphone_gtk_get_ui_config("ok","ok.png"));
495 notok = create_pixbuf(linphone_gtk_get_ui_config("notok","notok.png"));
497 GtkWidget *p1=create_intro();
498 GtkWidget *p2=create_setup_signin_choice();
499 GtkWidget *p31=create_account_informations_page();
500 GtkWidget *p32=create_linphone_account_informations_page();
501 GtkWidget *p33=create_account_information_page();
502 //GtkWidget *confirm=create_confirmation_page();
503 GtkWidget *validate=wait_for_activation();
504 GtkWidget *error=create_error_page();
505 GtkWidget *end=create_finish_page();
507 linphone_gtk_assistant_init(w);
508 gtk_assistant_append_page(GTK_ASSISTANT(w),p1);
509 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p1,GTK_ASSISTANT_PAGE_INTRO);
510 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p1,_("Welcome to the account setup assistant"));
511 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p1,TRUE);
513 gtk_assistant_append_page(GTK_ASSISTANT(w),p2);
514 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p2,GTK_ASSISTANT_PAGE_CONTENT);
515 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p2,_("Account setup assistant"));
516 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p2,TRUE);
518 gtk_assistant_append_page(GTK_ASSISTANT(w),p31);
519 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p31,GTK_ASSISTANT_PAGE_CONFIRM);
520 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p31,FALSE);
521 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p31,_("Configure your account (step 1/1)"));
523 gtk_assistant_append_page(GTK_ASSISTANT(w),p32);
524 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p32,GTK_ASSISTANT_PAGE_CONFIRM);
525 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p32,FALSE);
526 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p32,_("Enter your sip username (step 1/1)"));
528 gtk_assistant_append_page(GTK_ASSISTANT(w),p33);
529 gtk_assistant_set_page_type(GTK_ASSISTANT(w),p33,GTK_ASSISTANT_PAGE_CONFIRM);
530 gtk_assistant_set_page_title(GTK_ASSISTANT(w),p33,_("Enter account information (step 1/2)"));
532 /*gtk_assistant_append_page(GTK_ASSISTANT(w),confirm);
533 gtk_assistant_set_page_type(GTK_ASSISTANT(w),confirm,GTK_ASSISTANT_PAGE_CONFIRM);
534 gtk_assistant_set_page_title(GTK_ASSISTANT(w),confirm,_("Confirmation (step 2/2)"));
535 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),confirm,TRUE);*/
537 gtk_assistant_append_page(GTK_ASSISTANT(w),validate);
538 gtk_assistant_set_page_type(GTK_ASSISTANT(w),validate,GTK_ASSISTANT_PAGE_CONTENT);
539 gtk_assistant_set_page_title(GTK_ASSISTANT(w),validate,_("Validation (step 2/2)"));
540 gtk_assistant_set_page_complete(GTK_ASSISTANT(w),validate,TRUE);
542 gtk_assistant_append_page(GTK_ASSISTANT(w),error);
543 gtk_assistant_set_page_type(GTK_ASSISTANT(w),error,GTK_ASSISTANT_PAGE_CONTENT);
544 gtk_assistant_set_page_title(GTK_ASSISTANT(w),error,_("Error"));
546 gtk_assistant_append_page(GTK_ASSISTANT(w),end);
547 gtk_assistant_set_page_type(GTK_ASSISTANT(w),end,GTK_ASSISTANT_PAGE_SUMMARY);
548 gtk_assistant_set_page_title(GTK_ASSISTANT(w),end,_("Terminating"));
550 gtk_assistant_set_forward_page_func(GTK_ASSISTANT(w),linphone_gtk_assistant_forward,w,NULL);
551 g_signal_connect(G_OBJECT(w),"close",(GCallback)linphone_gtk_assistant_closed,NULL);
552 g_signal_connect(G_OBJECT(w),"cancel",(GCallback)linphone_gtk_assistant_closed,NULL);
553 g_signal_connect(G_OBJECT(w),"prepare",(GCallback)linphone_gtk_assistant_prepare,NULL);