Migrating from GnomeDruid to GtkAssistant

This commit is contained in:
Emmanuel Milou
2008-04-27 20:03:47 -04:00
parent a460c17e07
commit 4389a3a730
6 changed files with 409 additions and 369 deletions

View File

@ -19,7 +19,7 @@ dnl Improve make variable MAKE
AC_PROG_MAKE_SET
dnl Where to find configure files
AC_CONFIG_SRCDIR([config.h.in])
dnl AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_MACRO_DIR([m4])
dnl What to generate

View File

@ -5,7 +5,7 @@ sflphone_gtk_SOURCES = \
errors.c \
dbus.c \
sflnotify.c \
druid.c \
assistant.c \
mainwindow.c \
calllist.c \
dialpad.c \
@ -23,7 +23,7 @@ sflphone_gtk_SOURCES = \
glwidget.c \
MemManager.c
noinst_HEADERS = actions.h dbus.h sflnotify.h mainwindow.h calllist.h dialpad.h codeclist.h druid.h\
noinst_HEADERS = actions.h dbus.h sflnotify.h mainwindow.h calllist.h dialpad.h codeclist.h assistant.h\
callmanager-glue.h errors.h sflphone_const.h configurationmanager-glue.h instance-glue.h menus.h calltab.h calltree.h configwindow.h \
accountlist.h accountwindow.h marshaller.h sliders.h statusicon.h
EXTRA_DIST = marshaller.list

View File

@ -0,0 +1,382 @@
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/
#include <assistant.h>
struct _wizard *wiz;
static int account_type;
account_t* current;
void
set_account_type( GtkWidget* widget , gpointer data )
{
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget )) ){
account_type = _SIP;
}else{
account_type = _IAX ;
}
}
static void close_callback(gpointer data)
{
gtk_widget_destroy(wiz->assistant);
}
static void cancel_callback(gpointer data)
{
gtk_widget_destroy(wiz->assistant);
}
static void
apply_callback( gpointer data )
{
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"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("SIP"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_server))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_password))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_USER), 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_entry_get_text(GTK_ENTRY(wiz->enable))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->addr))));
}
else
{
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_ALIAS), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_alias))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("TRUE"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup("888"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("IAX"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
}
dbus_add_account( current );
}
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 )
{
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 configuration wizard" );
gtk_window_set_position(GTK_WINDOW(wiz->assistant), GTK_WIN_POS_CENTER);
gtk_assistant_set_forward_page_func( GTK_ASSISTANT( wiz->assistant ), (GtkAssistantPageFunc) forward_page_func , NULL , NULL );
build_intro();
build_select_account();
build_sip_account_configuration();
build_nat_settings();
build_iax_account_configuration();
build_summary();
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_update_buttons_state(GTK_ASSISTANT(wiz->assistant));
}
GtkWidget*
build_intro()
{
GtkWidget *label;
wiz->intro = create_vbox( GTK_ASSISTANT_PAGE_INTRO , "SFLphone 0.8" , "Welcome");
label = gtk_label_new(" This installation wizard will help you configure an account.") ;
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_widget_set_size_request(GTK_WIDGET(label), 380, -1);
gtk_box_pack_start(GTK_BOX(wiz->intro), label, FALSE, TRUE, 0);
return wiz->intro;
}
GtkWidget*
build_select_account()
{
GtkWidget* sip;
GtkWidget* iax;
wiz->protocols = create_vbox( GTK_ASSISTANT_PAGE_CONTENT , "VoIP Protocols" , "Select an account type:");
sip = gtk_radio_button_new_with_label(NULL,"SIP (Session Initiation Protocol)");
gtk_box_pack_start( GTK_BOX(wiz->protocols) , sip , TRUE, TRUE, 0);
iax = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(sip), "IAX2 (InterAsterix Exchange)");
gtk_box_pack_start( GTK_BOX(wiz->protocols) , iax , TRUE, TRUE, 0);
g_signal_connect(G_OBJECT( sip ) , "clicked" , G_CALLBACK( set_account_type ) , NULL );
return wiz->protocols;
}
GtkWidget*
build_sip_account_configuration( void )
{
GtkWidget* table;
GtkWidget* label;
wiz->sip_account = create_vbox( GTK_ASSISTANT_PAGE_CONTENT , "SIP account configuration" , "Fill the following information:");
// table
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->sip_account) , table , TRUE, TRUE, 0);
// alias field
label = gtk_label_new_with_mnemonic ("_Alias");
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->sip_alias = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->sip_alias);
gtk_table_attach ( GTK_TABLE( table ), wiz->sip_alias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// server field
label = gtk_label_new_with_mnemonic ("_Host name");
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->sip_server = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->sip_server);
gtk_table_attach ( GTK_TABLE( table ), wiz->sip_server, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// username field
label = gtk_label_new_with_mnemonic ("_User name");
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->sip_username = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->sip_username);
gtk_table_attach ( GTK_TABLE( table ), wiz->sip_username, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// password field
label = gtk_label_new_with_mnemonic ("_Password");
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->sip_password = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->sip_password);
gtk_entry_set_visibility(GTK_ENTRY(wiz->sip_password), FALSE);
gtk_table_attach ( GTK_TABLE( table ), wiz->sip_password, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
current -> state = ACCOUNT_STATE_UNREGISTERED;
return wiz->sip_account;
}
GtkWidget*
build_iax_account_configuration( void )
{
GtkWidget* label;
GtkWidget* table;
wiz->iax_account = create_vbox( GTK_ASSISTANT_PAGE_CONFIRM , "IAX2 account configuration" , "Fill the following information:");
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->iax_account) , table , TRUE, TRUE, 0);
// alias field
label = gtk_label_new_with_mnemonic ("_Alias");
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->iax_alias = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->iax_alias);
gtk_table_attach ( GTK_TABLE( table ), wiz->iax_alias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// server field
label = gtk_label_new_with_mnemonic ("_Host name");
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->iax_server = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->iax_server);
gtk_table_attach ( GTK_TABLE( table ), wiz->iax_server, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// username field
label = gtk_label_new_with_mnemonic ("_User name");
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->iax_username = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->iax_username);
gtk_table_attach ( GTK_TABLE( table ), wiz->iax_username, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// password field
label = gtk_label_new_with_mnemonic ("_Password");
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->iax_password = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->iax_password);
gtk_entry_set_visibility(GTK_ENTRY(wiz->iax_password), FALSE);
gtk_table_attach ( GTK_TABLE( table ), wiz->iax_password, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
current -> state = ACCOUNT_STATE_UNREGISTERED;
g_signal_connect( G_OBJECT( wiz->assistant ) , "apply" , G_CALLBACK( apply_callback ), NULL);
return wiz->iax_account;
}
GtkWidget*
build_nat_settings( void )
{
GtkWidget* label;
GtkWidget* table;
wiz->nat = create_vbox( GTK_ASSISTANT_PAGE_CONFIRM , "Network Address Translation" , "You should probably enable this if you are behind a firewall.");
// table
table = gtk_table_new ( 2, 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->nat), table , TRUE, TRUE, 0);
// enable
wiz->enable = gtk_check_button_new_with_mnemonic("_Enabled");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wiz->enable), FALSE);
gtk_table_attach ( GTK_TABLE( table ), wiz->enable, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_set_sensitive( GTK_WIDGET( wiz->enable ) , TRUE );
g_signal_connect( G_OBJECT( GTK_TOGGLE_BUTTON(wiz->enable)) , "toggled" , G_CALLBACK( enable_stun ), NULL);
// server address
label = gtk_label_new_with_mnemonic ("_Server address");
gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5);
wiz->addr = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), wiz->addr);
gtk_table_attach ( GTK_TABLE( table ), wiz->addr, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_set_sensitive( GTK_WIDGET( wiz->addr ), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->enable)));
g_signal_connect( G_OBJECT( wiz->assistant ) , "apply" , G_CALLBACK( apply_callback ), NULL);
return wiz->nat;
}
GtkWidget*
build_summary()
{
GtkWidget *label;
wiz->summary = create_vbox( GTK_ASSISTANT_PAGE_SUMMARY , "Congratulations" , "You have been successfully registered");
label = gtk_label_new(" Answer the call!") ;
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_widget_set_size_request(GTK_WIDGET(label), 380, -1);
gtk_box_pack_start(GTK_BOX(wiz->summary), label, FALSE, TRUE, 0);
return wiz->summary;
}
void
update_account_parameters( int type )
{
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"));
if( type == _SIP ){
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("SIP"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
//g_hash_table_replace(current->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_enable))));
//g_hash_table_replace(current->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_addr))));
}
else if( type == _IAX ){
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("IAX"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
}
current -> state = ACCOUNT_STATE_UNREGISTERED;
}
static gint
forward_page_func( gint current , gpointer data )
{
switch( current ){
case 0:
return 1;
case 1:
if( account_type == _SIP)
return 2;
return 4;
case 2:
return 3;
case 3:
return 5;
case 4:
return 5;
}
}
static GtkWidget*
create_vbox(GtkAssistantPageType type, const gchar *title, const gchar *section)
{
GtkWidget *vbox;
GtkWidget *label;
GdkPixbuf *pixbuf;
gchar *str;
vbox = gtk_vbox_new(FALSE, 6);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 24);
gtk_assistant_append_page(GTK_ASSISTANT(wiz->assistant), vbox);
gtk_assistant_set_page_type(GTK_ASSISTANT(wiz->assistant), vbox, type);
str = g_strdup_printf(" %s", title);
gtk_assistant_set_page_title(GTK_ASSISTANT(wiz->assistant), vbox, str);
g_free(str);
gtk_assistant_set_page_complete(GTK_ASSISTANT(wiz->assistant), vbox, TRUE);
wiz->logo = gdk_pixbuf_new_from_file(ICON_DIR "/sflphone.png", NULL);
gtk_assistant_set_page_header_image(GTK_ASSISTANT(wiz->assistant),vbox, wiz->logo);
g_object_unref(wiz->logo);
if (section) {
label = gtk_label_new(NULL);
str = g_strdup_printf("<b>%s</b>\n", section);
gtk_label_set_markup(GTK_LABEL(label), str);
g_free(str);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
}
return vbox;
}

View File

@ -17,10 +17,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __DRUID_H
#define __DRUID_H
#ifndef __ASSISTANT_H
#define __ASSISTANT_H
#include <libgnomeui/libgnomeui.h>
#include <accountlist.h>
#include <sflphone_const.h>
@ -30,9 +29,9 @@
struct _wizard
{
GtkWidget *window;
GtkWidget *druid;
GtkWidget *assistant;
GdkPixbuf *logo;
GtkWidget *first_page;
GtkWidget *intro;
/** Page 1 - Protocol selection */
GtkWidget *account_type;
GtkWidget *protocols;
@ -40,8 +39,6 @@ struct _wizard
GtkWidget *iax;
/** Page 2 - SIP account creation */
GtkWidget *sip_account;
GtkWidget *sip_table;
GtkWidget *label;
GtkWidget *sip_alias;
GtkWidget *sip_server;
GtkWidget *sip_username;
@ -51,7 +48,6 @@ struct _wizard
GtkWidget *mailbox;
/** Page 3 - IAX account creation */
GtkWidget *iax_account;
GtkWidget *iax_table;
GtkWidget *iax_alias;
GtkWidget *iax_server;
GtkWidget *iax_username;
@ -59,10 +55,9 @@ struct _wizard
/** Page 4 - Nat detection */
GtkWidget *nat;
GtkWidget *enable;
GtkWidget *nat_table;
GtkWidget *addr;
/** Page 5 - Test registration */
GtkWidget *page_end;
GtkWidget *summary;
};
@ -73,18 +68,26 @@ struct _wizard
void set_account_state( account_state_t state );
void set_account_type( GtkWidget* widget , gpointer data );
static void cancel_callback(gpointer data);
static void close_callback(gpointer data);
static void apply_callback( gpointer data );
void enable_stun( GtkWidget *widget );
void goto_right_account( void );
void goto_accounts_page( void );
void goto_nat_page( void );
void goto_end_page( void );
void goto_sip_account_page( void );
void quit_wizard( void );
void update_account_parameters( int type );
void build_nat_window( void );
void build_sip_configuration_account( int type );
void build_iax_configuration_account( int type );
/**
* Related-pages function
*/
void build_wizard();
GtkWidget* build_intro( void );
GtkWidget* build_select_account( void );
GtkWidget* build_sip_account_configuration( void );
GtkWidget* build_nat_settings( void );
GtkWidget* build_iax_account_configuration( void );
GtkWidget* build_summary( void );
/**
* Forward function
*/
static gint forward_page_func( gint current , gpointer data );
static GtkWidget* create_vbox(GtkAssistantPageType type, const gchar *title, const gchar *section);
#endif

View File

@ -30,7 +30,7 @@
#include <marshaller.h>
#include <sliders.h>
#include <statusicon.h>
#include <druid.h>
#include <assistant.h>
#include <dbus.h>
#include <actions.h>

View File

@ -1,345 +0,0 @@
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/
#include <druid.h>
struct _wizard *wiz;
static int account_type;
account_t* current;
void
build_sip_account_configuration( void )
{
// table
wiz->sip_table = gtk_table_new ( 4, 2 , FALSE/* homogeneous */);
gtk_table_set_row_spacings( GTK_TABLE(wiz->sip_table), 10);
gtk_table_set_col_spacings( GTK_TABLE(wiz->sip_table), 10);
gtk_box_pack_start(GTK_BOX(GNOME_DRUID_PAGE_STANDARD(wiz->sip_account)->vbox),wiz->sip_table, TRUE, TRUE, 2);
// alias field
wiz->label = gtk_label_new_with_mnemonic ("_Alias");
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->sip_alias = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->sip_alias);
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->sip_alias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// server field
wiz->label = gtk_label_new_with_mnemonic ("_Host name");
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->sip_server = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->sip_server);
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->sip_server, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// username field
wiz->label = gtk_label_new_with_mnemonic ("_User name");
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->sip_username = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->sip_username);
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->sip_username, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// password field
wiz->label = gtk_label_new_with_mnemonic ("_Password");
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->sip_password = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->sip_password);
gtk_table_attach ( GTK_TABLE( wiz->sip_table ), wiz->sip_password, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
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"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("SIP"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_server))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_password))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_username))));
current -> state = ACCOUNT_STATE_UNREGISTERED;
}
void
build_iax_account_configuration( void )
{
// table
wiz->iax_table = gtk_table_new ( 4, 2 , FALSE/* homogeneous */);
gtk_table_set_row_spacings( GTK_TABLE(wiz->iax_table), 10);
gtk_table_set_col_spacings( GTK_TABLE(wiz->iax_table), 10);
gtk_box_pack_start(GTK_BOX(GNOME_DRUID_PAGE_STANDARD(wiz->iax_account)->vbox),wiz->iax_table, TRUE, TRUE, 2);
// alias field
wiz->label = gtk_label_new_with_mnemonic ("_Alias");
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->iax_alias = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->iax_alias);
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->iax_alias, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// server field
wiz->label = gtk_label_new_with_mnemonic ("_Host name");
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->iax_server = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->iax_server);
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->iax_server, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// username field
wiz->label = gtk_label_new_with_mnemonic ("_User name");
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->iax_username = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->iax_username);
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->iax_username, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
// password field
wiz->label = gtk_label_new_with_mnemonic ("_Password");
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->iax_password = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->iax_password);
gtk_table_attach ( GTK_TABLE( wiz->iax_table ), wiz->iax_password, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_ALIAS), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_alias))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("TRUE"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup("888"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("IAX"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
current -> state = ACCOUNT_STATE_UNREGISTERED;
}
void
update_account_parameters( int type )
{
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"));
if( type == _SIP ){
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("SIP"));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
//g_hash_table_replace(current->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_enable))));
//g_hash_table_replace(current->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_addr))));
}
else if( type == _IAX ){
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("IAX"));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server))));
g_hash_table_replace(current->properties, g_strdup(ACCOUNT_IAX_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password))));
}
current -> state = ACCOUNT_STATE_UNREGISTERED;
}
void
build_nat_window( void )
{
// table
wiz->nat_table = gtk_table_new ( 2, 2 , FALSE/* homogeneous */);
gtk_table_set_row_spacings( GTK_TABLE(wiz->nat_table), 10);
gtk_table_set_col_spacings( GTK_TABLE(wiz->nat_table), 10);
gtk_box_pack_start(GTK_BOX(GNOME_DRUID_PAGE_STANDARD(wiz->nat)->vbox),wiz->nat_table, TRUE, TRUE, 2);
// enable
wiz->enable = gtk_check_button_new_with_mnemonic("_Enabled");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wiz->enable), FALSE);
gtk_table_attach ( GTK_TABLE( wiz->nat_table ), wiz->enable, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_set_sensitive( GTK_WIDGET( wiz->enable ) , TRUE );
g_signal_connect( G_OBJECT( GTK_TOGGLE_BUTTON(wiz->enable)) , "toggled" , G_CALLBACK( enable_stun ), NULL);
// server address
wiz->label = gtk_label_new_with_mnemonic ("_Server address");
gtk_table_attach ( GTK_TABLE( wiz->nat_table ), wiz->label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC (wiz->label), 0, 0.5);
wiz->addr = gtk_entry_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (wiz->label), wiz->addr);
gtk_table_attach ( GTK_TABLE( wiz->nat_table ), wiz->addr, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_set_sensitive( GTK_WIDGET( wiz->addr ), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->enable)));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->enable))));
g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->addr))));
}
void
set_account_type( GtkWidget* widget , gpointer data )
{
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget )) ){
account_type = _SIP;
}else{
account_type = _IAX ;
}
}
void
enable_stun( GtkWidget* widget )
{
gtk_widget_set_sensitive( GTK_WIDGET( wiz->addr ), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
}
void
goto_right_account( void )
{
if( account_type == _SIP )
gnome_druid_set_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->sip_account));
else
gnome_druid_set_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->iax_account));
}
void
goto_accounts_page( void )
{
gnome_druid_set_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->account_type));
}
void
goto_nat_page( void )
{
gnome_druid_set_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->nat));
}
void
goto_end_page( void )
{
gnome_druid_set_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->page_end));
}
void
goto_sip_account_page( void )
{
gnome_druid_set_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->sip_account));
}
void
quit_wizard( void )
{
return;
}
void
send_registration( void )
{
dbus_add_account( current );
//sleep(1);
switch( current->state )
{
case ACCOUNT_STATE_REGISTERED:
gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->page_end )," Congratulations! \n\n You have been successfully registered. Answer the call! " );
break;
case ACCOUNT_STATE_UNREGISTERED:
gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->page_end )," You are not registered! \n\n And we don't know why! " );
break;
case ACCOUNT_STATE_ERROR_AUTH:
gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->page_end )," You are not registered! \n\n Authentification error. Please try again " );
break;
case ACCOUNT_STATE_ERROR_HOST:
gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->page_end )," You are not registered! \n\n The host name you specified is unreachable. Please try again " );
break;
case ACCOUNT_STATE_ERROR_NETWORK:
gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->page_end )," You are not registered! \n\n The network is unreachable. Check the plug " );
break;
default:
gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->page_end )," Sorry we cannot status your case " );
}
goto_end_page();
}
void
build_wizard( void )
{
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->logo = gdk_pixbuf_new_from_file(ICON_DIR "/sflphone.png", NULL);
wiz->druid = gnome_druid_new_with_window( "SFLphone" , NULL , TRUE , &wiz->window );
wiz->first_page = gnome_druid_page_edge_new( GNOME_EDGE_START );
gnome_druid_append_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->first_page ) );
gnome_druid_page_edge_set_title( GNOME_DRUID_PAGE_EDGE( wiz->first_page ), "SFLphone 0.8-5");
gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->first_page ),
" Welcome. \n\n\n This wizard will help you configure an account.\n\n\n Answer the call ! " );
/** Page 1 */
wiz->account_type = gnome_druid_page_standard_new();
gnome_druid_page_standard_set_title( GNOME_DRUID_PAGE_STANDARD( wiz->account_type), "Select a VoIP protocol");
gnome_druid_page_standard_set_logo( GNOME_DRUID_PAGE_STANDARD( wiz->account_type) , wiz->logo );
gnome_druid_append_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->account_type ));
wiz->protocols = gtk_vbox_new(FALSE , 10);
gtk_box_pack_start(GTK_BOX(GNOME_DRUID_PAGE_STANDARD(wiz->account_type)->vbox),wiz->protocols, TRUE, TRUE, 2);
wiz->sip = gtk_radio_button_new_with_label(NULL,"SIP (Session Initiation Protocol)");
gtk_box_pack_start( GTK_BOX(wiz->protocols) , wiz->sip , TRUE, TRUE, 0);
wiz->iax = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(wiz->sip), "IAX2 (InterAsterix Exchange)");
gtk_box_pack_start( GTK_BOX(wiz->protocols) , wiz->iax , TRUE, TRUE, 0);
g_signal_connect(G_OBJECT( wiz->sip ) , "clicked" , G_CALLBACK( set_account_type ) , NULL );
/** Page 2 */
wiz->sip_account = gnome_druid_page_standard_new();
gnome_druid_page_standard_set_title( GNOME_DRUID_PAGE_STANDARD( wiz->sip_account), "SIP account configuration");
gnome_druid_page_standard_set_logo( GNOME_DRUID_PAGE_STANDARD( wiz->sip_account) , wiz->logo );
gnome_druid_append_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->sip_account ));
build_sip_account_configuration( );
/** Page 3 */
wiz->iax_account = gnome_druid_page_standard_new();
gnome_druid_page_standard_set_title( GNOME_DRUID_PAGE_STANDARD( wiz->iax_account), "IAX2 account configuration");
gnome_druid_page_standard_set_logo( GNOME_DRUID_PAGE_STANDARD( wiz->iax_account) , wiz->logo );
gnome_druid_append_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->iax_account ));
build_iax_account_configuration( );
/** Page 4 */
wiz->nat = gnome_druid_page_standard_new();
gnome_druid_page_standard_set_title( GNOME_DRUID_PAGE_STANDARD( wiz->nat), "Nat detection");
gnome_druid_page_standard_set_logo( GNOME_DRUID_PAGE_STANDARD( wiz->nat) , wiz->logo );
gnome_druid_append_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->nat ));
build_nat_window();
/** Page 5 */
wiz->page_end = gnome_druid_page_edge_new( GNOME_EDGE_FINISH );
gnome_druid_page_edge_set_title( GNOME_DRUID_PAGE_EDGE( wiz->page_end), "Account Registration");
gnome_druid_page_edge_set_logo( GNOME_DRUID_PAGE_EDGE( wiz->page_end) , wiz->logo );
gnome_druid_append_page( GNOME_DRUID( wiz->druid ) , GNOME_DRUID_PAGE( wiz->page_end ));
//gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE( wiz->page_end ),
// " Congratulations! \n\n You have been successfully registered " );
/** Events */
g_signal_connect( G_OBJECT( wiz->account_type ) , "next" , G_CALLBACK( goto_right_account ) , NULL );
g_signal_connect( G_OBJECT( wiz->iax_account ) , "back" , G_CALLBACK( goto_accounts_page ), NULL );
g_signal_connect( G_OBJECT( wiz->sip_account ) , "next" , G_CALLBACK( goto_nat_page ), NULL );
g_signal_connect( G_OBJECT( wiz->iax_account ) , "next" , G_CALLBACK( goto_end_page ), NULL );
g_signal_connect( G_OBJECT( wiz->nat ) , "back" , G_CALLBACK( goto_sip_account_page ), NULL );
g_signal_connect( G_OBJECT( wiz->nat ) , "next" , G_CALLBACK( send_registration ) , NULL );
g_signal_connect( G_OBJECT( wiz->page_end ) , "finish" , G_CALLBACK( quit_wizard ), NULL );
gtk_widget_show_all(wiz->window);
}
void
set_account_state( account_state_t state )
{
g_print("state %i\n" , state);
current->state = state;
}