Commit 6cf5a4e8 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Add email address request when creating a sflphone.org account


Signed-off-by: default avatarCyrille Béraud <cyrille.béraud@savoirfairelinux.com>
parent 7d458ece
......@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string.h>
......@@ -46,10 +46,7 @@ static gint forward_page_func( gint current_page , gpointer data );
static GtkWidget* create_vbox(GtkAssistantPageType type, const gchar *title, const gchar *section);
void prefill_sip(void) ;
void
set_account_type( GtkWidget* widget , gpointer data UNUSED )
{
void set_account_type( GtkWidget* widget , gpointer data UNUSED ) {
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget )) ){
account_type = _SIP;
}else{
......@@ -58,9 +55,7 @@ set_account_type( GtkWidget* widget , gpointer data UNUSED )
}
void set_sflphone_org( GtkWidget* widget , gpointer data UNUSED ) {
use_sflphone_org = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))?1:0) ;
g_print("SET SFLPHONEORG : %d\n", use_sflphone_org);
}
......@@ -69,8 +64,7 @@ void set_sflphone_org( GtkWidget* widget , gpointer data UNUSED ) {
* Callback when the close button of the dialog is clicked
* Action : close the assistant widget and get back to sflphone main window
*/
static void close_callback( void )
{
static void close_callback( void ) {
gtk_widget_destroy(wiz->assistant);
g_free(wiz); wiz = NULL;
}
......@@ -79,8 +73,7 @@ static void close_callback( void )
* Callback when the cancel button of the dialog is clicked
* Action : close the assistant widget and get back to sflphone main window
*/
static void cancel_callback( void )
{
static void cancel_callback( void ) {
gtk_widget_destroy(wiz->assistant);
g_free(wiz); wiz = NULL;
}
......@@ -89,16 +82,12 @@ static void cancel_callback( void )
* Callback when the button apply is clicked
* Action : Set the account parameters with the entries values and called dbus_add_account
*/
static void
sip_apply_callback( void )
{
static void sip_apply_callback( void ) {
if(use_sflphone_org){
prefill_sip();
account_type = _SIP;
}
if( account_type == _SIP )
{
g_print("SIP APPLY CALLBACK\n");
if( account_type == _SIP ) {
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ALIAS), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_alias))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("TRUE"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup("888"));
......@@ -106,12 +95,11 @@ sip_apply_callback( void )
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_HOSTNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_server))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_password))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_USERNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_username))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), g_strdup((gchar *)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->enable))? "TRUE":"FALSE"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), g_strdup((gchar *)(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->enable))? "TRUE":"FALSE")));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->addr))));
dbus_add_account( current );
account_list_set_current_id( current->accountID );
g_print( "ACCOUNT ID = %s\n" , current->accountID );
}
}
......@@ -119,12 +107,8 @@ sip_apply_callback( void )
* Callback when the button apply is clicked
* Action : Set the account parameters with the entries values and called dbus_add_account
*/
static void
iax_apply_callback( void )
{
if( account_type == _IAX)
{
g_print("IAX APPLY CALLBACK\n");
static void iax_apply_callback( void ) {
if( account_type == _IAX) {
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ALIAS), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_alias))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("TRUE"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup("888"));
......@@ -132,29 +116,25 @@ iax_apply_callback( void )
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_USERNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_HOSTNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
dbus_add_account( current );
account_list_set_current_id( current->accountID );
g_print( "ACCOUNT ID = %s\n" , current->accountID );
}
}
void
enable_stun( GtkWidget* widget )
{
void enable_stun( GtkWidget* widget ) {
gtk_widget_set_sensitive( GTK_WIDGET( wiz->addr ), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
}
void
build_wizard( void )
{
if(!wiz){
void build_wizard( void ) {
if (wiz)
return ;
wiz = ( struct _wizard* )g_malloc( sizeof( struct _wizard));
current = g_new0(account_t, 1);
current->properties = g_hash_table_new(NULL, g_str_equal);
//current ->accountID = "test";
wiz->assistant = gtk_assistant_new( );
gtk_window_set_title( GTK_WINDOW(wiz->assistant), _("SFLphone account configuration wizard") );
gtk_window_set_position(GTK_WINDOW(wiz->assistant), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(wiz->assistant), 200 , 200);
......@@ -165,22 +145,20 @@ if(!wiz){
build_sip_account_configuration();
build_nat_settings();
build_iax_account_configuration();
build_email_configuration();
build_summary();
// build_registration_error();
g_signal_connect(G_OBJECT(wiz->assistant), "close" , G_CALLBACK(close_callback), NULL);
g_signal_connect(G_OBJECT(wiz->assistant), "cancel" , G_CALLBACK(cancel_callback), NULL);
gtk_widget_show_all(wiz->assistant);
gtk_assistant_set_forward_page_func( GTK_ASSISTANT( wiz->assistant ), (GtkAssistantPageFunc) forward_page_func , NULL , NULL );
gtk_assistant_update_buttons_state(GTK_ASSISTANT(wiz->assistant));
}
}
GtkWidget*
build_intro()
{
GtkWidget* build_intro() {
GtkWidget *label;
wiz->intro = create_vbox( GTK_ASSISTANT_PAGE_INTRO , _("SFLphone 0.9.3") , _("Welcome to SFLphone!"));
......@@ -194,9 +172,7 @@ build_intro()
return wiz->intro;
}
GtkWidget*
build_select_account()
{
GtkWidget* build_select_account() {
GtkWidget* sip;
GtkWidget* iax;
......@@ -214,8 +190,7 @@ build_select_account()
}
GtkWidget* build_sfl_or_account()
{
GtkWidget* build_sfl_or_account() {
GtkWidget* sfl;
GtkWidget* cus;
......@@ -231,9 +206,7 @@ GtkWidget* build_sfl_or_account()
}
GtkWidget*
build_sip_account_configuration( void )
{
GtkWidget* build_sip_account_configuration( void ) {
GtkWidget* table;
GtkWidget* label;
GtkWidget* image;
......@@ -286,9 +259,29 @@ build_sip_account_configuration( void )
return wiz->sip_account;
}
GtkWidget*
build_iax_account_configuration( void )
{
GtkWidget* build_email_configuration( void ) {
GtkWidget* label;
GtkWidget* table;
wiz->email = create_vbox( GTK_ASSISTANT_PAGE_CONTENT , _("Optional Email Address ") , _("This email address will be use to send your voicemail messages"));
table = gtk_table_new ( 4, 2 , FALSE/* homogeneous */);
gtk_table_set_row_spacings( GTK_TABLE(table), 10);
gtk_table_set_col_spacings( GTK_TABLE(table), 10);
gtk_box_pack_start( GTK_BOX(wiz->email) , table , TRUE, TRUE, 0);
// email field
label = gtk_label_new_with_mnemonic (_("_Email"));
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->mailbox = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->mailbox);
gtk_table_attach ( GTK_TABLE( table ), wiz->mailbox, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
return wiz->email;
}
GtkWidget* build_iax_account_configuration( void ) {
GtkWidget* label;
GtkWidget* table;
GtkWidget* image;
......@@ -344,9 +337,7 @@ build_iax_account_configuration( void )
return wiz->iax_account;
}
GtkWidget*
build_nat_settings( void )
{
GtkWidget* build_nat_settings( void ) {
GtkWidget* label;
GtkWidget* table;
......@@ -379,9 +370,7 @@ build_nat_settings( void )
return wiz->nat;
}
GtkWidget*
build_summary()
{
GtkWidget* build_summary() {
GtkWidget *label;
wiz->summary = create_vbox( GTK_ASSISTANT_PAGE_SUMMARY , _("Account Registration") , _("Congratulations!"));
......@@ -394,9 +383,7 @@ build_summary()
return wiz->summary;
}
GtkWidget*
build_registration_error()
{
GtkWidget* build_registration_error() {
GtkWidget *label;
wiz->reg_failed = create_vbox( GTK_ASSISTANT_PAGE_SUMMARY , "Account Registration" , "Registration error");
......@@ -407,7 +394,6 @@ build_registration_error()
gtk_box_pack_start(GTK_BOX(wiz->reg_failed), label, FALSE, TRUE, 0);
return wiz->reg_failed;
}
void set_sip_infos_sentivite(gboolean b) {
......@@ -419,8 +405,10 @@ void set_sip_infos_sentivite(gboolean b) {
void prefill_sip(void) {
if (use_sflphone_org == 1) {
char alias[400];
rest_account ra = get_rest_account(SFLPHONE_ORG_SERVER);
char alias[300];
char *email;
email = (char *)gtk_entry_get_text (GTK_ENTRY(wiz->mailbox) );
rest_account ra = get_rest_account(SFLPHONE_ORG_SERVER,email);
if (ra.success) {
set_sip_infos_sentivite(FALSE);
strcpy(alias,ra.user);
......@@ -434,20 +422,19 @@ void prefill_sip(void) {
}
}
typedef enum
{
typedef enum {
PAGE_INTRO,
PAGE_SFL,
PAGE_TYPE,
PAGE_SIP,
PAGE_STUN,
PAGE_IAX,
PAGE_EMAIL,
PAGE_SUMMARY
} assistant_state;
static gint forward_page_func( gint current_page , gpointer data) {
gint next_page = 0;
g_print("CURRENT PAGE %d\n", current_page);
switch( current_page ){
case PAGE_INTRO:
......@@ -455,7 +442,7 @@ static gint forward_page_func( gint current_page , gpointer data) {
break;
case PAGE_SFL:
if (use_sflphone_org) {
next_page = PAGE_STUN;
next_page = PAGE_EMAIL;
} else
next_page = PAGE_TYPE;
break;
......@@ -467,9 +454,9 @@ static gint forward_page_func( gint current_page , gpointer data) {
next_page = PAGE_IAX;
break;
case PAGE_SIP:
if (use_sflphone_org ) {
}
next_page = PAGE_STUN;
break;
case PAGE_EMAIL:
next_page = PAGE_STUN;
break;
case PAGE_STUN:
......@@ -479,20 +466,16 @@ static gint forward_page_func( gint current_page , gpointer data) {
next_page = PAGE_SUMMARY;
break;
case PAGE_SUMMARY:
g_print("XXXXXXXXXXXXXXXXXXXXXX\n");
next_page = PAGE_SUMMARY;
break;
default:
next_page = -1;
}
g_print("NEXT PAGE : %d\n",next_page);
return next_page;
}
static GtkWidget*
create_vbox(GtkAssistantPageType type, const gchar *title, const gchar *section)
{
static GtkWidget* create_vbox(GtkAssistantPageType type, const gchar *title, const gchar *section) {
GtkWidget *vbox;
GtkWidget *label;
gchar *str;
......
......@@ -41,6 +41,7 @@ struct _wizard
GtkWidget *account_type;
GtkWidget *protocols;
GtkWidget *sip;
GtkWidget *email;
GtkWidget *iax;
/** Page 2 - SIP account creation */
GtkWidget *sip_account;
......@@ -100,6 +101,7 @@ GtkWidget* build_nat_settings( void );
GtkWidget* build_iax_account_configuration( void );
GtkWidget* build_summary( void );
GtkWidget* build_registration_error( void );
GtkWidget* build_email_configuration( void );
GtkWidget* build_sfl_or_account (void);
/**
......
......@@ -99,12 +99,14 @@ int req(char *host, int port, char *req, char *ret) {
return 0;
}
rest_account get_rest_account(char *host) {
rest_account get_rest_account(char *host,char *email) {
char ret[4096];
rest_account ra;
bzero(ret, sizeof(ret));
printf("HOST: %s\n", host);
if (req(host, 80, "GET /rest/accountcreator", ret) != -1) {
strcpy(ret,"GET /rest/accountcreator?email=");
strcat(ret, email);
if (req(host, 80, ret, ret) != -1) {
strcpy(ra.user, strtok(ret, "\n"));
strcpy(ra.passwd, strtok(NULL, "\n"));\
ra.success = 1;
......@@ -120,7 +122,7 @@ rest_account get_rest_account(char *host) {
#ifdef BUILD_EXAMPLE
int main (void) {
rest_account acc = get_rest_account("sip.sflphone.org");
rest_account acc = get_rest_account("sip.sflphone.org","email@email.com");
if (acc.success) {
puts(acc.user);
puts(acc.passwd);
......
/*
* Copyright (C) 2009 Jean Schurger <jean@schurger.org>
* and Savoir-Faire Linux inc.
* Copyright (C) 2009 Savoir-faire Linux inc.
* Author Jean Schurger <jean.schurger@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -24,4 +24,4 @@ typedef struct {
char passwd[200];
} rest_account;
rest_account get_rest_account(char *host);
rest_account get_rest_account(char *host, char *email);
......@@ -11,7 +11,7 @@ include('include/header.php');
<tbody>
<tr>
<td >
<h5>SAVOIR-FAIRE LINUX - À MONTRÉAL</h5>
<h5>SAVOIR-FAIRE LINUX - IN MONTREAL</h5>
<p>7275 Saint Urbain Bureau 306</p>
<p>Montréal (Québec) H2R 2Y5</p>
<p>Tél. (514) 276-5468</p>
......@@ -22,7 +22,7 @@ include('include/header.php');
</td >
<td >
<h5>À QUÉBEC :</h5>
<h5>IN QUEBEC :</h5>
<p>275, rue du Parvis </p>
<p>Bureau 310 </p>
<p>Québec (Québec) G1K 6G7 </p>
......@@ -34,7 +34,7 @@ include('include/header.php');
</tr>
<tr>
<td >
<h5>À OTTAWA / Gatineau :</h5>
<h5>IN OTTAWA / Gatineau :</h5>
<p>151, rue Slater</p>
<p>Bureau 504</p>
<p>Ottawa, ON, K1P 5H3</p>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment