]> sjero.net Git - linphone/blobdiff - gtk/setupwizard.c
update ms2
[linphone] / gtk / setupwizard.c
index f15befda717b9e778ff7ec2ed28dc6114f204263..f4374c539a377c7dfea70ddee820c7dbffede6f3 100644 (file)
@@ -25,6 +25,7 @@ static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w);
 static const int PASSWORD_MIN_SIZE = 6;
 static const int LOGIN_MIN_SIZE = 4;
 
+static GtkWidget *the_assistant=NULL;
 static GdkPixbuf *ok;
 static GdkPixbuf *notok;
 
@@ -225,9 +226,43 @@ static void account_password_changed(GtkEntry *entry, GtkWidget *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) {
-       //gdk_threads_enter();
-       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"));
@@ -236,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) {
-                       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);
-               }
+#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) {
@@ -257,18 +286,10 @@ void* check_username_availability(void* w) {
                }
                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);
-       //gdk_threads_leave();
-
-       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
-       g_thread_create(check_username_availability, (void*)w, FALSE, NULL);
+               gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w,
+                               is_account_information_correct(w)>0);
+       }
 }
 
 static GtkWidget *create_account_information_page() {
@@ -380,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){
@@ -511,16 +532,22 @@ 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"));
        notok = create_pixbuf(linphone_gtk_get_ui_config("notok","notok.png"));
 
-       g_thread_init (NULL);
-       gdk_threads_init ();
-
        GtkWidget *p1=create_intro();
        GtkWidget *p2=create_setup_signin_choice();
        GtkWidget *p31=create_account_informations_page();
@@ -580,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;
 }
+