]> sjero.net Git - linphone/blobdiff - gtk/setupwizard.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / gtk / setupwizard.c
index 25cc78ffcd7b5eb34244ab039de302cb992f7d3c..f4374c539a377c7dfea70ddee820c7dbffede6f3 100644 (file)
@@ -20,15 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "linphone.h"
 #include <glib.h>
 #include <glib/gprintf.h>
-#include <pthread.h>
 static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w);
 
 static const int PASSWORD_MIN_SIZE = 6;
 static const int LOGIN_MIN_SIZE = 4;
-static int is_username_available = 0;
-static int is_email_correct = 0;
-static int is_password_correct = 0;
 
+static GtkWidget *the_assistant=NULL;
 static GdkPixbuf *ok;
 static GdkPixbuf *notok;
 
@@ -171,6 +168,10 @@ static int create_account(GtkWidget *page) {
 }
 
 static int is_account_information_correct(GtkWidget *w) {
+       int is_username_available = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_username_available"));
+       int is_email_correct = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_email_correct"));
+       int is_password_correct = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_password_correct"));
+
        if (is_username_available == 1 && is_email_correct == 1 && is_password_correct == 1) {
                return 1;
        }
@@ -185,11 +186,11 @@ static void account_email_changed(GtkEntry *entry, GtkWidget *w) {
        GtkWidget *assistant=gtk_widget_get_toplevel(w);
 
        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)) {
-               is_email_correct = 1;
+               g_object_set_data(G_OBJECT(w),"is_email_correct",GINT_TO_POINTER(1));
                gtk_image_set_from_pixbuf(isEmailOk, ok);
        }
        else {
-               is_email_correct = 0;
+               g_object_set_data(G_OBJECT(w),"is_email_correct",GINT_TO_POINTER(0));
                gtk_image_set_from_pixbuf(isEmailOk, notok);
        }
        gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
@@ -207,7 +208,7 @@ static void account_password_changed(GtkEntry *entry, GtkWidget *w) {
 
        if (gtk_entry_get_text_length(password) >= PASSWORD_MIN_SIZE &&
        g_ascii_strcasecmp(gtk_entry_get_text(password), gtk_entry_get_text(password_confirm)) == 0) {
-               is_password_correct = 1;
+               g_object_set_data(G_OBJECT(w),"is_password_correct",GINT_TO_POINTER(1));
                gtk_image_set_from_pixbuf(isPasswordOk, ok);
                gtk_label_set_text(passwordError, "");
        }
@@ -218,15 +219,50 @@ static void account_password_changed(GtkEntry *entry, GtkWidget *w) {
                else if (!g_ascii_strcasecmp(gtk_entry_get_text(password), gtk_entry_get_text(password_confirm)) == 0) {
                        gtk_label_set_text(passwordError, "Passwords don't match !");
                }
-               is_password_correct = 0;
+               g_object_set_data(G_OBJECT(w),"is_password_correct",GINT_TO_POINTER(0));
                gtk_image_set_from_pixbuf(isPasswordOk, notok);
        }
        gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
                        is_account_information_correct(w)>0);
 }
 
+gboolean update_interface_with_username_availability(gpointer *w) {
+       GtkWidget *assistant = gtk_widget_get_toplevel(GTK_WIDGET(w));
+       GtkImage* isUsernameOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"usernameOk"));
+       GtkLabel* usernameError = GTK_LABEL(g_object_get_data(G_OBJECT(w),"error"));
+       int account_existing = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_username_used"));
+
+       if (account_existing == 0) {
+               g_object_set_data(G_OBJECT(w),"is_username_available",GINT_TO_POINTER(1));
+               gtk_image_set_from_pixbuf(isUsernameOk, ok);
+               gtk_label_set_text(usernameError, "");
+       }
+       else {
+               gtk_label_set_text(usernameError, "Username is already in use !");
+               g_object_set_data(G_OBJECT(w),"is_username_available",GINT_TO_POINTER(0));
+               gtk_image_set_from_pixbuf(isUsernameOk, notok);
+       }
+
+       gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),GTK_WIDGET(w),
+                               is_account_information_correct(GTK_WIDGET(w))>0);
+
+       return FALSE;
+}
+
 void* check_username_availability(void* w) {
-       GtkWidget *assistant=gtk_widget_get_toplevel(GTK_WIDGET(w));
+       LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(GTK_WIDGET(w)));
+
+       int account_existing = linphone_account_creator_test_existence(creator);
+
+       g_object_set_data(G_OBJECT(w),"is_username_used",GINT_TO_POINTER(account_existing));
+       gdk_threads_add_idle((GSourceFunc)update_interface_with_username_availability, (void*)w);
+
+       return NULL;
+}
+
+static void account_username_changed(GtkEntry *entry, GtkWidget *w) {
+       // Verifying if username choosed is available, and if form is correctly filled, let the user go next page
+       GtkWidget *assistant = gtk_widget_get_toplevel(GTK_WIDGET(w));
        GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username"));
        GtkImage* isUsernameOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"usernameOk"));
        GtkLabel* usernameError = GTK_LABEL(g_object_get_data(G_OBJECT(w),"error"));
@@ -235,17 +271,11 @@ void* check_username_availability(void* w) {
        linphone_account_creator_set_username(creator, gtk_entry_get_text(username));
 
        if (g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) {
-               int account_existing = linphone_account_creator_test_existence(creator);
-               if (account_existing == 0) {
-                       is_username_available = 1;
-                       gtk_image_set_from_pixbuf(isUsernameOk, ok);
-                       gtk_label_set_text(usernameError, "");
-               }
-               else {
-                       gtk_label_set_text(usernameError, "Username is already in use !");
-                       is_username_available = 0;
-                       gtk_image_set_from_pixbuf(isUsernameOk, notok);
-               }
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+               g_thread_create(check_username_availability, (void*)w, FALSE, NULL);
+#else
+               g_thread_new(NULL, check_username_availability, w);
+#endif
        }
        else {
                if (gtk_entry_get_text_length(username) < LOGIN_MIN_SIZE) {
@@ -254,20 +284,12 @@ void* check_username_availability(void* w) {
                else if (!g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) {
                        gtk_label_set_text(usernameError, "Unauthorized username");
                }
-               is_username_available = 0;
+               g_object_set_data(G_OBJECT(w),"is_username_available",GINT_TO_POINTER(0));
                gtk_image_set_from_pixbuf(isUsernameOk, notok);
-       }
-
-       gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
-                       is_account_information_correct(w)>0);
-
-       return NULL;
-}
 
-static void account_username_changed(GtkEntry *entry, GtkWidget *w) {
-       // Verifying if username choosed is available, and if form is correctly filled, let the user go next page
-       pthread_t thread;
-       pthread_create(&thread, NULL, check_username_availability, (void*)w);
+               gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
+                               is_account_information_correct(w)>0);
+       }
 }
 
 static GtkWidget *create_account_information_page() {
@@ -379,7 +401,7 @@ static int is_account_validated(GtkWidget *page) {
 }
 
 static void linphone_gtk_assistant_closed(GtkWidget *w){
-       gtk_widget_destroy(w);
+       linphone_gtk_close_assistant();
 }
 
 static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page){
@@ -404,7 +426,6 @@ static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page
                gchar domain[128];
                g_snprintf(domain, sizeof(domain), "\"%s\"", creator->domain + 4);
                LinphoneAuthInfo *info=linphone_auth_info_new(username, username, creator->password, NULL, domain);
-               g_free(username);
                linphone_core_add_auth_info(linphone_gtk_get_core(),info);
 
                if (linphone_core_add_proxy_config(linphone_gtk_get_core(),cfg)==-1)
@@ -412,6 +433,18 @@ static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page
 
                linphone_core_set_default_proxy(linphone_gtk_get_core(),cfg);
                linphone_gtk_load_identities();
+
+               // If account created on sip.linphone.org, we configure linphone to use TLS by default
+               g_warning("Domain : %s", creator->domain);
+               if (strcmp(creator->domain, "sip:sip.linphone.org") == 0) {
+                       LCSipTransports tr;
+                       LinphoneCore* lc = linphone_gtk_get_core();
+                       linphone_core_get_sip_transports(lc,&tr);
+                       tr.tls_port = tr.udp_port + tr.tcp_port + tr.tls_port;
+                       tr.udp_port = 0;
+                       tr.tcp_port = 0;
+                       linphone_core_set_sip_transports(lc,&tr);
+               }
        }
 }
 
@@ -499,8 +532,17 @@ static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w){
        return (LinphoneAccountCreator*)g_object_get_data(G_OBJECT(w),"creator");
 }
 
-GtkWidget * linphone_gtk_create_assistant(void){
-       GtkWidget *w=gtk_assistant_new();
+void linphone_gtk_close_assistant(void){
+       if(the_assistant==NULL)
+               return;
+       gtk_widget_destroy(the_assistant);      
+       the_assistant = NULL;
+}
+
+void linphone_gtk_show_assistant(void){
+       if(the_assistant!=NULL)
+               return;
+       GtkWidget *w=the_assistant=gtk_assistant_new();
        gtk_window_set_resizable (GTK_WINDOW(w), FALSE);
 
        ok = create_pixbuf(linphone_gtk_get_ui_config("ok","ok.png"));
@@ -565,6 +607,5 @@ GtkWidget * linphone_gtk_create_assistant(void){
        g_signal_connect(G_OBJECT(w),"prepare",(GCallback)linphone_gtk_assistant_prepare,NULL);
 
        gtk_widget_show(w);
-
-       return w;
 }
+