#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;
}
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;
}
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,
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, "");
}
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"));
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) {
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() {
}
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){
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"));
g_signal_connect(G_OBJECT(w),"prepare",(GCallback)linphone_gtk_assistant_prepare,NULL);
gtk_widget_show(w);
-
- return w;
}
+