diff --git a/CMakeLists.txt b/CMakeLists.txt index 90d8d0d11..ae08d4b1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,6 @@ option(ENABLE_TUTORIALS "Enable compilation of tutorials." YES) option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES) option(ENABLE_UPNP "Build with uPnP support." YES) option(ENABLE_VIDEO "Build with video support." YES) -cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENABLE_GTK_UI" NO) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -120,9 +119,6 @@ if(ENABLE_NOTIFY) set(ENABLE_NOTIFY OFF CACHE BOOL "Enable libnotify support." FORCE) endif() endif() -if(ENABLE_ASSISTANT) - set(BUILD_WIZARD 1) -endif() find_package(Gettext) diff --git a/build/android/config.h b/build/android/config.h index 0842116ab..6d0305b77 100644 --- a/build/android/config.h +++ b/build/android/config.h @@ -7,9 +7,6 @@ /* Define if tools enabled */ /* #undef BUILD_TOOLS */ -/* Define if wizard enabled */ -/* #undef BUILD_WIZARD */ - /* Tells whether localisation is possible */ /* #undef ENABLE_NLS */ diff --git a/config.h.cmake b/config.h.cmake index 3adb3cae4..6d0015a20 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -37,7 +37,6 @@ #define PACKAGE_DATA_DIR "${PACKAGE_DATA_DIR}" #define PACKAGE_SOUND_DIR "${PACKAGE_SOUND_DIR}" -#cmakedefine BUILD_WIZARD #cmakedefine HAVE_NOTIFY4 #cmakedefine HAVE_ZLIB 1 #cmakedefine HAVE_CU_GET_SUITE 1 diff --git a/configure.ac b/configure.ac index 4db7ce12b..8df0dcd0a 100644 --- a/configure.ac +++ b/configure.ac @@ -729,31 +729,6 @@ if test "$has_sighandler_t" = "yes" ; then AC_DEFINE( HAVE_SIGHANDLER_T, 1, [Define if sighandler_t available] ) fi -AC_ARG_ENABLE(assistant, - [AS_HELP_STRING([--enable-assistant], [Turn on assistant compiling])], - [case "${enableval}" in - yes) build_wizard=true ;; - no) build_wizard=false ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-assistant) ;; - esac], - [build_wizard=check] -) - -if test "$build_wizard" != "false" ; then - PKG_CHECK_MODULES(LIBGTKWIZARD, [gtk+-2.0 >= 2.22.0],[], - [if test "$build_wizard" = "true" ; then - AC_MSG_ERROR([gtk+-2.0 < 2.22.0, assistant cannot be compiled.]) - else - build_wizard=false - fi] - ) -fi -AM_CONDITIONAL(BUILD_WIZARD, test x$build_wizard != xfalse) -if test "$build_wizard" != "false" ; then - build_wizard=true - AC_DEFINE(BUILD_WIZARD, 1, [Define if wizard enabled] ) -fi - AC_CHECK_HEADERS(libudev.h) AC_CHECK_LIB(udev,udev_new) @@ -1062,7 +1037,6 @@ echo "Linphone build configuration ended." echo "Summary of build options:" printf "* %-30s %s\n" "Video support" $video printf "* %-30s %s\n" "GTK interface" $gtk_ui -printf "* %-30s %s\n" "Account assistant" $build_wizard printf "* %-30s %s\n" "Console interface" $console_ui printf "* %-30s %s\n" "Tools" $build_tools printf "* %-30s %s\n" "Message storage" $enable_msg_storage diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index 10bef3b30..8b972bbcc 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -31,6 +31,8 @@ endif() set(SOURCE_FILES + account_creator.c + account_creator.h address.c authentication.c bellesip_sal/sal_address_impl.c @@ -105,9 +107,6 @@ if(ENABLE_TUNNEL) else() list(APPEND SOURCE_FILES linphone_tunnel_stubs.c) endif() -if(ENABLE_ASSISTANT) - list(APPEND SOURCE_FILES sipwizard.c) -endif() set(GENERATED_SOURCE_FILES ${CMAKE_CURRENT_BINARY_DIR}/liblinphone_gitversion.h diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 35dd9fec0..8130a8037 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -25,6 +25,7 @@ CLEANFILES=$(GITVERSION_FILE) linphone_includedir=$(includedir)/linphone linphone_include_HEADERS=\ + account_creator.h \ buffer.h \ call_log.h \ call_params.h \ @@ -38,11 +39,13 @@ linphone_include_HEADERS=\ lpc2xml.h \ lpconfig.h \ sipsetup.h \ - xml2lpc.h + xml2lpc.h \ + xmlrpc.h lib_LTLIBRARIES=liblinphone.la liblinphone_la_SOURCES=\ + account_creator.c \ address.c \ authentication.c \ buffer.c \ @@ -82,6 +85,7 @@ liblinphone_la_SOURCES=\ sipsetup.c sipsetup.h \ xml2lpc.c \ xml.c \ + xmlrpc.c \ vtables.c \ $(GITVERSION_FILE) @@ -102,10 +106,6 @@ liblinphone_la_SOURCES+= bellesip_sal/sal_address_impl.c \ bellesip_sal/sal_op_info.c \ bellesip_sal/sal_op_events.c -if BUILD_WIZARD -liblinphone_la_SOURCES+=sipwizard.c -endif - liblinphone_la_SOURCES+=linphone_tunnel_config.c if BUILD_TUNNEL liblinphone_la_SOURCES+=linphone_tunnel.cc TunnelManager.cc TunnelManager.hh linphone_tunnel.h @@ -181,10 +181,6 @@ COMMON_CFLAGS=\ $(SASL_CFLAGS) \ $(ZLIB_CFLAGS) -if BUILD_WIZARD -COMMON_CFLAGS+= -DBUILD_WIZARD -endif - COMMON_CFLAGS+= -DUSE_BELLESIP AM_CFLAGS=$(COMMON_CFLAGS) $(STRICT_OPTIONS_CC) diff --git a/coreapi/account_creator.c b/coreapi/account_creator.c new file mode 100644 index 000000000..800403cab --- /dev/null +++ b/coreapi/account_creator.c @@ -0,0 +1,209 @@ +/* +linphone +Copyright (C) 2010-2015 Belledonne Communications SARL + +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 2 +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "linphonecore.h" +#include "private.h" + + +struct _LinphoneAccountCreator { + LinphoneXmlRpcSession *xmlrpc_session; + LinphoneAccountCreatorCb existence_test_cb; + LinphoneAccountCreatorCb validation_test_cb; + LinphoneAccountCreatorCb validate_cb; + void *existence_test_cb_ud; + void *validation_test_cb_ud; + void *validate_cb_ud; + char *xmlrpc_url; + char *username; + char *password; + char *domain; + char *route; + char *email; + int subscribe; +}; + +LinphoneAccountCreator * linphone_account_creator_new(LinphoneCore *core, const char *xmlrpc_url) { + LinphoneAccountCreator *creator; + creator = ms_new0(LinphoneAccountCreator, 1); + creator->xmlrpc_session = linphone_xml_rpc_session_new(core, xmlrpc_url); + return creator; +} + +void linphone_account_creator_set_username(LinphoneAccountCreator *creator, const char *username) { + set_string(&creator->username, username); +} + +const char * linphone_account_creator_get_username(const LinphoneAccountCreator *creator) { + return creator->username; +} + +void linphone_account_creator_set_password(LinphoneAccountCreator *creator, const char *password){ + set_string(&creator->password, password); +} + +const char * linphone_account_creator_get_password(const LinphoneAccountCreator *creator) { + return creator->password; +} + +void linphone_account_creator_set_domain(LinphoneAccountCreator *creator, const char *domain){ + set_string(&creator->domain, domain); +} + +const char * linphone_account_creator_get_domain(const LinphoneAccountCreator *creator) { + return creator->domain; +} + +void linphone_account_creator_set_route(LinphoneAccountCreator *creator, const char *route) { + set_string(&creator->route, route); +} + +const char * linphone_account_creator_get_route(const LinphoneAccountCreator *creator) { + return creator->route; +} + +void linphone_account_creator_set_email(LinphoneAccountCreator *creator, const char *email) { + set_string(&creator->email, email); +} + +const char * linphone_account_creator_get_email(const LinphoneAccountCreator *creator) { + return creator->email; +} + +void linphone_account_creator_set_subscribe(LinphoneAccountCreator *creator, int subscribe) { + creator->subscribe = subscribe; +} + +int linphone_account_creator_get_subscribe(const LinphoneAccountCreator *creator) { + return creator->subscribe; +} + +void linphone_account_creator_set_test_existence_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorCb cb, void *user_data) { + creator->existence_test_cb = cb; + creator->existence_test_cb_ud = user_data; +} + +void linphone_account_creator_set_test_validation_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorCb cb, void *user_data) { + creator->validation_test_cb = cb; + creator->validation_test_cb_ud = user_data; +} + +void linphone_account_creator_set_validate_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorCb cb, void *user_data) { + creator->validate_cb = cb; + creator->validate_cb_ud = user_data; +} + +static void _test_existence_cb(LinphoneXmlRpcRequest *request, void *user_data) { + LinphoneAccountCreator *creator = (LinphoneAccountCreator *)user_data; + if (creator->existence_test_cb != NULL) { + LinphoneAccountCreatorStatus status = LinphoneAccountCreatorFailed; + if ((linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) + && (linphone_xml_rpc_request_get_int_response(request) == 0)) { + status = LinphoneAccountCreatorOk; + } + creator->existence_test_cb(creator, status, creator->existence_test_cb_ud); + } +} + +LinphoneAccountCreatorStatus linphone_account_creator_test_existence(LinphoneAccountCreator *creator) { + LinphoneXmlRpcRequest *request; + char *identity; + + if (!creator->username || !creator->domain) return LinphoneAccountCreatorFailed; + + identity = ms_strdup_printf("%s@%s", creator->username, creator->domain); + request = linphone_xml_rpc_request_new_with_args("check_account", LinphoneXmlRpcArgInt, + _test_existence_cb, creator, + LinphoneXmlRpcArgString, identity, + LinphoneXmlRpcArgNone); + linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request); + linphone_xml_rpc_request_unref(request); + ms_free(identity); + return LinphoneAccountCreatorOk; +} + +static void _test_validation_cb(LinphoneXmlRpcRequest *request, void *user_data) { + LinphoneAccountCreator *creator = (LinphoneAccountCreator *)user_data; + if (creator->validation_test_cb != NULL) { + LinphoneAccountCreatorStatus status = LinphoneAccountCreatorFailed; + if ((linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) + && (linphone_xml_rpc_request_get_int_response(request) == 1)) { + status = LinphoneAccountCreatorOk; + } + creator->validation_test_cb(creator, status, creator->validation_test_cb_ud); + } +} + +LinphoneAccountCreatorStatus linphone_account_creator_test_validation(LinphoneAccountCreator *creator) { + LinphoneXmlRpcRequest *request; + char *identity; + + if (!creator->username || !creator->domain) return LinphoneAccountCreatorFailed; + + identity = ms_strdup_printf("%s@%s", creator->username, creator->domain); + request = linphone_xml_rpc_request_new_with_args("check_account_validated", LinphoneXmlRpcArgInt, + _test_validation_cb, creator, + LinphoneXmlRpcArgString, identity, + LinphoneXmlRpcArgNone); + linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request); + linphone_xml_rpc_request_unref(request); + ms_free(identity); + return LinphoneAccountCreatorOk; +} + +static void _validate_cb(LinphoneXmlRpcRequest *request, void *user_data) { + LinphoneAccountCreator *creator = (LinphoneAccountCreator *)user_data; + if (creator->validate_cb != NULL) { + LinphoneAccountCreatorStatus status = LinphoneAccountCreatorFailed; + if ((linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) + && (linphone_xml_rpc_request_get_int_response(request) == 0)) { + status = LinphoneAccountCreatorOk; + } + creator->validate_cb(creator, status, creator->validate_cb_ud); + } +} + +LinphoneAccountCreatorStatus linphone_account_creator_validate(LinphoneAccountCreator *creator) { + LinphoneXmlRpcRequest *request; + char *identity; + + if (!creator->username || !creator->domain) return LinphoneAccountCreatorFailed; + + identity = ms_strdup_printf("%s@%s", creator->username, creator->domain); + request = linphone_xml_rpc_request_new_with_args("create_account", LinphoneXmlRpcArgInt, + _validate_cb, creator, + LinphoneXmlRpcArgString, identity, + LinphoneXmlRpcArgString, creator->password, + LinphoneXmlRpcArgString, creator->email, + LinphoneXmlRpcArgInt, creator->subscribe, + LinphoneXmlRpcArgNone); + linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request); + linphone_xml_rpc_request_unref(request); + ms_free(identity); + return LinphoneAccountCreatorOk; +} + +void linphone_account_creator_destroy(LinphoneAccountCreator *creator){ + linphone_xml_rpc_session_unref(creator->xmlrpc_session); + if (creator->username) ms_free(creator->username); + if (creator->password) ms_free(creator->password); + if (creator->domain) ms_free(creator->domain); + if (creator->route) ms_free(creator->route); + if (creator->email) ms_free(creator->email); + ms_free(creator); +} diff --git a/coreapi/account_creator.h b/coreapi/account_creator.h new file mode 100644 index 000000000..f4c5faef2 --- /dev/null +++ b/coreapi/account_creator.h @@ -0,0 +1,78 @@ +/* +account_creator.h +Copyright (C) 2010-2015 Belledonne Communications SARL + +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 2 +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef LINPHONE_ACCOUNT_CREATOR_H_ +#define LINPHONE_ACCOUNT_CREATOR_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup misc + * @{ + */ + +enum _LinphoneAccountCreatorStatus { + LinphoneAccountCreatorOk, + LinphoneAccountCreatorFailed +}; + +typedef enum _LinphoneAccountCreatorStatus LinphoneAccountCreatorStatus; + +typedef struct _LinphoneAccountCreator LinphoneAccountCreator; + +typedef void (*LinphoneAccountCreatorCb)(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, void *user_data); + +LINPHONE_PUBLIC LinphoneAccountCreator * linphone_account_creator_new(LinphoneCore *core, const char *xmlrpc_url); +LINPHONE_PUBLIC void linphone_account_creator_destroy(LinphoneAccountCreator *creator); + +LINPHONE_PUBLIC void linphone_account_creator_set_username(LinphoneAccountCreator *creator, const char *username); +LINPHONE_PUBLIC const char * linphone_account_creator_get_username(const LinphoneAccountCreator *creator); +LINPHONE_PUBLIC void linphone_account_creator_set_password(LinphoneAccountCreator *creator, const char *password); +LINPHONE_PUBLIC const char * linphone_account_creator_get_password(const LinphoneAccountCreator *creator); +LINPHONE_PUBLIC void linphone_account_creator_set_domain(LinphoneAccountCreator *creator, const char *domain); +LINPHONE_PUBLIC const char * linphone_account_creator_get_domain(const LinphoneAccountCreator *creator); +LINPHONE_PUBLIC void linphone_account_creator_set_route(LinphoneAccountCreator *creator, const char *route); +LINPHONE_PUBLIC const char * linphone_account_creator_get_route(const LinphoneAccountCreator *creator); +LINPHONE_PUBLIC void linphone_account_creator_set_email(LinphoneAccountCreator *creator, const char *email); +LINPHONE_PUBLIC const char * linphone_account_creator_get_email(const LinphoneAccountCreator *creator); +LINPHONE_PUBLIC void linphone_account_creator_set_subscribe(LinphoneAccountCreator *creator, int suscribre); +LINPHONE_PUBLIC int linphone_account_creator_get_subscribe(const LinphoneAccountCreator *creator); + +LINPHONE_PUBLIC void linphone_account_creator_set_test_existence_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorCb cb, void *user_data); +LINPHONE_PUBLIC void linphone_account_creator_set_test_validation_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorCb cb, void *user_data); +LINPHONE_PUBLIC void linphone_account_creator_set_validate_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorCb cb, void *user_data); + +LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_test_existence(LinphoneAccountCreator *creator); +LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_test_validation(LinphoneAccountCreator *creator); +LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_validate(LinphoneAccountCreator *creator); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* LINPHONE_ACCOUNT_CREATOR_H_ */ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index d77ea401c..e859a9af8 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -367,6 +367,7 @@ LINPHONE_PUBLIC const char* linphone_privacy_to_string(LinphonePrivacy privacy); #ifdef IN_LINPHONE +#include "account_creator.h" #include "buffer.h" #include "call_log.h" #include "call_params.h" @@ -375,6 +376,7 @@ LINPHONE_PUBLIC const char* linphone_privacy_to_string(LinphonePrivacy privacy); #include "linphonefriend.h" #include "xmlrpc.h" #else +#include "linphone/account_creator.h" #include "linphone/buffer.h" #include "linphone/call_log.h" #include "linphone/call_params.h" @@ -1179,32 +1181,6 @@ LINPHONE_PUBLIC void linphone_proxy_config_set_custom_header(LinphoneProxyConfig * @} **/ -typedef struct _LinphoneAccountCreator{ - LinphoneCore *lc; - struct _SipSetupContext *ssctx; - char *username; - char *password; - char *domain; - char *route; - char *email; - int suscribe; - bool_t succeeded; -}LinphoneAccountCreator; - -LINPHONE_PUBLIC LinphoneAccountCreator *linphone_account_creator_new(LinphoneCore *core, const char *type); -LINPHONE_PUBLIC void linphone_account_creator_set_username(LinphoneAccountCreator *obj, const char *username); -LINPHONE_PUBLIC void linphone_account_creator_set_password(LinphoneAccountCreator *obj, const char *password); -LINPHONE_PUBLIC void linphone_account_creator_set_domain(LinphoneAccountCreator *obj, const char *domain); -LINPHONE_PUBLIC void linphone_account_creator_set_route(LinphoneAccountCreator *obj, const char *route); -LINPHONE_PUBLIC void linphone_account_creator_set_email(LinphoneAccountCreator *obj, const char *email); -LINPHONE_PUBLIC void linphone_account_creator_set_suscribe(LinphoneAccountCreator *obj, int suscribre); -LINPHONE_PUBLIC const char * linphone_account_creator_get_username(LinphoneAccountCreator *obj); -LINPHONE_PUBLIC const char * linphone_account_creator_get_domain(LinphoneAccountCreator *obj); -LINPHONE_PUBLIC int linphone_account_creator_test_existence(LinphoneAccountCreator *obj); -LINPHONE_PUBLIC int linphone_account_creator_test_validation(LinphoneAccountCreator *obj); -LINPHONE_PUBLIC LinphoneProxyConfig * linphone_account_creator_validate(LinphoneAccountCreator *obj); -LINPHONE_PUBLIC void linphone_account_creator_destroy(LinphoneAccountCreator *obj); - struct _LinphoneAuthInfo; /** diff --git a/coreapi/private.h b/coreapi/private.h index 7140d8d78..fb84a4467 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -997,6 +997,8 @@ struct _LinphoneXmlRpcRequest { belle_sip_list_t *arg_list; char *content; /**< The string representation of the XML-RPC request */ char *method; + LinphoneXmlRpcResponseCb cb; + void *cb_ud; LinphoneXmlRpcStatus status; LinphoneXmlRpcArg response; }; @@ -1006,14 +1008,8 @@ BELLE_SIP_DECLARE_VPTR(LinphoneXmlRpcRequest); struct _LinphoneXmlRpcSession { belle_sip_object_t base; void *user_data; - belle_sip_list_t *arg_list; LinphoneCore *core; - LinphoneXmlRpcRequest *request; - LinphoneContent *content; char *url; - ms_cond_t cond; - ms_mutex_t cond_mutex; - ms_mutex_t mutex; }; BELLE_SIP_DECLARE_VPTR(LinphoneXmlRpcSession); diff --git a/coreapi/proxy.c b/coreapi/proxy.c index f32935f12..56c4ff750 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -1494,98 +1494,6 @@ SipSetupContext *linphone_proxy_config_get_sip_setup_context(LinphoneProxyConfig * @} **/ -LinphoneAccountCreator *linphone_account_creator_new(struct _LinphoneCore *core, const char *type){ - LinphoneAccountCreator *obj; - LinphoneProxyConfig *cfg; - SipSetup *ss=sip_setup_lookup(type); - SipSetupContext *ssctx; - if (!ss){ - return NULL; - } - if (!(sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_ACCOUNT_MANAGER)){ - ms_error("%s cannot manage accounts.",type); - return NULL; - } - obj=ms_new0(LinphoneAccountCreator,1); - cfg=linphone_core_create_proxy_config(core); - ssctx=sip_setup_context_new(ss,cfg); - obj->lc=core; - obj->ssctx=ssctx; - set_string(&obj->domain,sip_setup_context_get_domains(ssctx)[0]); - cfg->lc=core; - return obj; -} - -void linphone_account_creator_set_username(LinphoneAccountCreator *obj, const char *username){ - set_string(&obj->username,username); -} - -void linphone_account_creator_set_password(LinphoneAccountCreator *obj, const char *password){ - set_string(&obj->password,password); -} - -void linphone_account_creator_set_domain(LinphoneAccountCreator *obj, const char *domain){ - set_string(&obj->domain,domain); -} - -void linphone_account_creator_set_route(LinphoneAccountCreator *obj, const char *route) { - set_string(&obj->route,route); -} - -void linphone_account_creator_set_email(LinphoneAccountCreator *obj, const char *email) { - set_string(&obj->email,email); -} - -void linphone_account_creator_set_suscribe(LinphoneAccountCreator *obj, int suscribe) { - obj->suscribe = suscribe; -} - -const char * linphone_account_creator_get_username(LinphoneAccountCreator *obj){ - return obj->username; -} - -const char * linphone_account_creator_get_domain(LinphoneAccountCreator *obj){ - return obj->domain; -} - -int linphone_account_creator_test_existence(LinphoneAccountCreator *obj){ - SipSetupContext *ssctx=obj->ssctx; - char *uri=ms_strdup_printf("%s@%s",obj->username,obj->domain); - int err=sip_setup_context_account_exists(ssctx,uri); - ms_free(uri); - return err; -} - -int linphone_account_creator_test_validation(LinphoneAccountCreator *obj) { - SipSetupContext *ssctx=obj->ssctx; - int err=sip_setup_context_account_validated(ssctx,obj->username); - return err; -} - -LinphoneProxyConfig * linphone_account_creator_validate(LinphoneAccountCreator *obj){ - SipSetupContext *ssctx=obj->ssctx; - char *uri=ms_strdup_printf("%s@%s",obj->username,obj->domain); - int err=sip_setup_context_create_account(ssctx, uri, obj->password, obj->email, obj->suscribe); - ms_free(uri); - if (err==0) { - obj->succeeded=TRUE; - return sip_setup_context_get_proxy_config(ssctx); - } - return NULL; -} - -void linphone_account_creator_destroy(LinphoneAccountCreator *obj){ - if (obj->username) - ms_free(obj->username); - if (obj->password) - ms_free(obj->password); - if (obj->domain) - ms_free(obj->domain); - if (!obj->succeeded){ - linphone_proxy_config_destroy(sip_setup_context_get_proxy_config(obj->ssctx)); - } -} - void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cfg, void *ud) { cfg->user_data = ud; } diff --git a/coreapi/sipsetup.c b/coreapi/sipsetup.c index bf1b411e8..7c9f074d9 100644 --- a/coreapi/sipsetup.c +++ b/coreapi/sipsetup.c @@ -24,14 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "linphonecore.h" extern SipSetup linphone_sip_login; -#ifdef BUILD_WIZARD -extern SipSetup linphone_sip_wizard; -#endif static SipSetup *all_sip_setups[]={ &linphone_sip_login, -#ifdef BUILD_WIZARD - &linphone_sip_wizard, -#endif NULL }; diff --git a/coreapi/sipwizard.c b/coreapi/sipwizard.c deleted file mode 100644 index 54b03fcfb..000000000 --- a/coreapi/sipwizard.c +++ /dev/null @@ -1,189 +0,0 @@ -/* -sipwizard.c -Copyright (C) 2011 Belledonne Communication, Grenoble, France - -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 2 -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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "linphonecore.h" -#include "private.h" -#include - - -static const char *XMLRPC_URL = "https://www.linphone.org/wizard.php"; - -static void sip_wizard_init_instance(SipSetupContext *ctx){ - LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); - /*disable registration until the user logs in*/ - linphone_proxy_config_enable_register(cfg,FALSE); -} - -static void sip_wizard_uninit_instance(SipSetupContext *ctx) { - if (ctx->xmlrpc_session != NULL) { - linphone_xml_rpc_session_unref(ctx->xmlrpc_session); - ctx->xmlrpc_session = NULL; - } -} - -static const char ** sip_wizard_get_domains(SipSetupContext *ctx) { - LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); - const char **domains = (const char**) &cfg->reg_proxy; - return domains; -} - - -static int do_simple_xmlrpc_request(SipSetupContext *ctx, LinphoneXmlRpcRequest *request) { - int ret = -1; - - if (!request) { - ms_error("Fail to create XML-RPC request!"); - return -1; - } - - if (ctx->xmlrpc_session == NULL) { - ctx->xmlrpc_session = linphone_xml_rpc_session_new(ctx->cfg->lc, XMLRPC_URL); - } - if (linphone_xml_rpc_session_send_request(ctx->xmlrpc_session, request) == LinphoneXmlRpcStatusOk) { - ret = linphone_xml_rpc_request_get_int_response(request); - } - linphone_xml_rpc_request_unref(request); - - return ret; -} - -/* - * Return 1 if account already exists - * 0 if account doesn't exists - * -1 if information isn't available - */ -static int sip_wizard_account_exists(SipSetupContext *ctx, const char *identity) { - LinphoneXmlRpcRequest *request = linphone_xml_rpc_request_new_with_args("check_account", - LinphoneXmlRpcArgInt, - LinphoneXmlRpcArgString, identity, - LinphoneXmlRpcArgNone); - return do_simple_xmlrpc_request(ctx, request); -} - -static int sip_wizard_account_validated(SipSetupContext *ctx, const char *identity) { - LinphoneXmlRpcRequest *request = linphone_xml_rpc_request_new_with_args("check_account_validated", - LinphoneXmlRpcArgInt, - LinphoneXmlRpcArgString, identity, - LinphoneXmlRpcArgNone); - return do_simple_xmlrpc_request(ctx, request); -} - -static int sip_wizard_create_account(SipSetupContext *ctx, const char *identity, const char *passwd, const char *email, int subscribe) { - LinphoneXmlRpcRequest *request = linphone_xml_rpc_request_new_with_args("create_account", - LinphoneXmlRpcArgInt, - LinphoneXmlRpcArgString, identity, - LinphoneXmlRpcArgString, passwd, - LinphoneXmlRpcArgString, email, - LinphoneXmlRpcArgInt, subscribe, - LinphoneXmlRpcArgNone); - return do_simple_xmlrpc_request(ctx, request); -} - -static void guess_display_name(LinphoneAddress *from){ - const char *username=linphone_address_get_username(from); - char *dn=(char*)ms_malloc(strlen(username)+1); - const char *it; - char *wptr=dn; - bool_t begin=TRUE; - bool_t surname=FALSE; - for(it=username;*it!='\0';++it){ - if (begin){ - *wptr=toupper(*it); - begin=FALSE; - }else if (*it=='.'){ - if (surname) break; - *wptr=' '; - begin=TRUE; - surname=TRUE; - }else { - *wptr=*it; - } - wptr++; - } - *wptr='\0'; - linphone_address_set_display_name(from,dn); - ms_free(dn); -} - -static int sip_wizard_do_login(SipSetupContext * ctx, const char *uri, const char *passwd, const char *userid){ - LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); - LinphoneCore *lc=linphone_proxy_config_get_core(cfg); - LinphoneAuthInfo *auth; - LinphoneAddress *parsed_uri; - char *tmp; - - parsed_uri=linphone_address_new(uri); - if (parsed_uri==NULL){ - return -1; - } - if (linphone_address_get_display_name(parsed_uri)!=NULL){ - guess_display_name(parsed_uri); - } - tmp=linphone_address_as_string(parsed_uri); - linphone_proxy_config_set_identity(cfg,tmp); - if (passwd) { - auth=linphone_auth_info_new(linphone_address_get_username(parsed_uri),NULL,passwd,NULL,NULL,NULL); - linphone_core_add_auth_info(lc,auth); - } - linphone_proxy_config_enable_register(cfg,TRUE); - linphone_proxy_config_done(cfg); - ms_free(tmp); - linphone_address_destroy(parsed_uri); - return 0; -} - -/* a simple SipSetup built-in plugin to allow creating accounts at runtime*/ - -#ifndef _MSC_VER - -SipSetup linphone_sip_wizard={ - .name="SipWizard", - .capabilities=SIP_SETUP_CAP_ACCOUNT_MANAGER, - .init_instance=sip_wizard_init_instance, - .uninit_instance=sip_wizard_uninit_instance, - .account_exists=sip_wizard_account_exists, - .create_account=sip_wizard_create_account, - .login_account=sip_wizard_do_login, - .get_domains=sip_wizard_get_domains, - .account_validated=sip_wizard_account_validated -}; - -#else -SipSetup linphone_sip_wizard={ - "SipWizard", - SIP_SETUP_CAP_ACCOUNT_MANAGER, - 0, - NULL, - NULL, - sip_wizard_init_instance, - sip_wizard_uninit_instance, - sip_wizard_account_exists, - sip_wizard_create_account, - sip_wizard_do_login, - NULL, - NULL, - NULL, - NULL, - sip_wizard_get_domains, - NULL, - NULL, - sip_wizard_account_validated -}; - -#endif diff --git a/coreapi/xmlrpc.c b/coreapi/xmlrpc.c index 1e5731535..61a6566d1 100644 --- a/coreapi/xmlrpc.c +++ b/coreapi/xmlrpc.c @@ -116,40 +116,46 @@ static void free_arg(LinphoneXmlRpcArg *arg) { } static void process_io_error_from_post_xml_rpc_request(void *data, const belle_sip_io_error_event_t *event) { - LinphoneXmlRpcSession *session = (LinphoneXmlRpcSession *)data; - ms_error("I/O Error during XML-RPC request sending to %s", session->url); - session->request->status = LinphoneXmlRpcStatusFailed; - ms_cond_signal(&session->cond); + LinphoneXmlRpcRequest *request = (LinphoneXmlRpcRequest *)data; + ms_error("I/O Error during XML-RPC request sending"); + request->status = LinphoneXmlRpcStatusFailed; + if (request->cb != NULL) { + request->cb(request, request->cb_ud); + } + linphone_xml_rpc_request_unref(request); } static void process_auth_requested_from_post_xml_rpc_request(void *data, belle_sip_auth_event_t *event) { - LinphoneXmlRpcSession *session = (LinphoneXmlRpcSession *)data; - ms_error("Error during XML-RPC request sending to connect %s", session->url); - session->request->status = LinphoneXmlRpcStatusFailed; - ms_cond_signal(&session->cond); + LinphoneXmlRpcRequest *request = (LinphoneXmlRpcRequest *)data; + ms_error("Authentication error during XML-RPC request sending"); + request->status = LinphoneXmlRpcStatusFailed; + if (request->cb != NULL) { + request->cb(request, request->cb_ud); + } + linphone_xml_rpc_request_unref(request); } -static void parse_valid_xml_rpc_response(LinphoneXmlRpcSession *session, const char *response_body) { +static void parse_valid_xml_rpc_response(LinphoneXmlRpcRequest *request, const char *response_body) { xmlparsing_context_t *xml_ctx = linphone_xmlparsing_context_new(); xmlSetGenericErrorFunc(xml_ctx, linphone_xmlparsing_genericxml_error); - session->request->status = LinphoneXmlRpcStatusFailed; + request->status = LinphoneXmlRpcStatusFailed; xml_ctx->doc = xmlReadDoc((const unsigned char*)response_body, 0, NULL, 0); if (xml_ctx->doc != NULL) { const char *response_str; if (linphone_create_xml_xpath_context(xml_ctx) < 0) goto end; - switch (session->request->response.type) { + switch (request->response.type) { case LinphoneXmlRpcArgInt: response_str = linphone_get_xml_text_content(xml_ctx, "/methodResponse/params/param/value/int"); if (response_str != NULL) { - session->request->response.data.i = atoi(response_str); - session->request->status = LinphoneXmlRpcStatusOk; + request->response.data.i = atoi(response_str); + request->status = LinphoneXmlRpcStatusOk; } break; case LinphoneXmlRpcArgString: response_str = linphone_get_xml_text_content(xml_ctx, "/methodResponse/params/param/value/string"); if (response_str != NULL) { - session->request->response.data.s = belle_sip_strdup(response_str); - session->request->status = LinphoneXmlRpcStatusOk; + request->response.data.s = belle_sip_strdup(response_str); + request->status = LinphoneXmlRpcStatusOk; } break; default: @@ -161,43 +167,42 @@ static void parse_valid_xml_rpc_response(LinphoneXmlRpcSession *session, const c } end: linphone_xmlparsing_context_destroy(xml_ctx); - ms_cond_signal(&session->cond); + if (request->cb != NULL) { + request->cb(request, request->cb_ud); + } } -static void notify_xml_rpc_error(LinphoneXmlRpcSession *session) { - session->request->status = LinphoneXmlRpcStatusOk; - ms_cond_signal(&session->cond); +static void notify_xml_rpc_error(LinphoneXmlRpcRequest *request) { + request->status = LinphoneXmlRpcStatusOk; + if (request->cb != NULL) { + request->cb(request, request->cb_ud); + } } -/** - * Callback function called when we have a response from server during the upload of the log collection to the server (rcs5.1 recommandation) - * Note: The first post is empty and the server shall reply a 204 (No content) message, this will trigger a new post request to the server - * to upload the file. The server response to this second post is processed by this same function - * - * @param[in] data The user-defined pointer associated with the request, it contains the LinphoneCore object - * @param[in] event The response from server - */ static void process_response_from_post_xml_rpc_request(void *data, const belle_http_response_event_t *event) { - LinphoneXmlRpcSession *session = (LinphoneXmlRpcSession *)data; + LinphoneXmlRpcRequest *request = (LinphoneXmlRpcRequest *)data; /* Check the answer code */ if (event->response) { int code = belle_http_response_get_status_code(event->response); if (code == 200) { /* Valid response from the server. */ - parse_valid_xml_rpc_response(session, belle_sip_message_get_body((belle_sip_message_t *)event->response)); + parse_valid_xml_rpc_response(request, belle_sip_message_get_body((belle_sip_message_t *)event->response)); } else { - notify_xml_rpc_error(session); + notify_xml_rpc_error(request); } } + linphone_xml_rpc_request_unref(request); } -static LinphoneXmlRpcRequest * _linphone_xml_rpc_request_new(const char *method, LinphoneXmlRpcArgType return_type) { +static LinphoneXmlRpcRequest * _linphone_xml_rpc_request_new(const char *method, LinphoneXmlRpcArgType return_type, LinphoneXmlRpcResponseCb cb, void *user_data) { LinphoneXmlRpcRequest *request = belle_sip_object_new(LinphoneXmlRpcRequest); belle_sip_object_ref(request); request->status = LinphoneXmlRpcStatusPending; request->response.type = return_type; request->method = belle_sip_strdup(method); + request->cb = cb; + request->cb_ud = user_data; return request; } @@ -226,9 +231,6 @@ static void _linphone_xml_rpc_request_destroy(LinphoneXmlRpcRequest *request) { static void _linphone_xml_rpc_session_destroy(LinphoneXmlRpcSession *session) { belle_sip_free(session->url); - ms_cond_destroy(&session->cond); - ms_mutex_destroy(&session->cond_mutex); - ms_mutex_destroy(&session->mutex); } BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneXmlRpcRequest); @@ -249,19 +251,18 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneXmlRpcSession, belle_sip_object_t, ); -LinphoneXmlRpcRequest * linphone_xml_rpc_request_new(const char *method, LinphoneXmlRpcArgType return_type) { - LinphoneXmlRpcRequest *request = _linphone_xml_rpc_request_new(method, return_type); +LinphoneXmlRpcRequest * linphone_xml_rpc_request_new(const char *method, LinphoneXmlRpcArgType return_type, LinphoneXmlRpcResponseCb cb, void *user_data) { + LinphoneXmlRpcRequest *request = _linphone_xml_rpc_request_new(method, return_type, cb, user_data); format_request(request); return request; } -LinphoneXmlRpcRequest * linphone_xml_rpc_request_new_with_args(const char *method, LinphoneXmlRpcArgType return_type, ...) { +LinphoneXmlRpcRequest * linphone_xml_rpc_request_new_with_args(const char *method, LinphoneXmlRpcArgType return_type, LinphoneXmlRpcResponseCb cb, void *user_data, ...) { bool_t cont = TRUE; va_list args; LinphoneXmlRpcArgType arg_type; - LinphoneXmlRpcArg *arg = NULL; - LinphoneXmlRpcRequest *request = _linphone_xml_rpc_request_new(method, return_type); - va_start(args, return_type); + LinphoneXmlRpcRequest *request = _linphone_xml_rpc_request_new(method, return_type, cb, user_data); + va_start(args, cb); while (cont) { arg_type = va_arg(args, LinphoneXmlRpcArgType); switch (arg_type) { @@ -330,9 +331,6 @@ LinphoneXmlRpcSession * linphone_xml_rpc_session_new(LinphoneCore *core, const c belle_sip_object_ref(session); session->core = core; session->url = belle_sip_strdup(url); - ms_cond_init(&session->cond, NULL); - ms_mutex_init(&session->cond_mutex, NULL); - ms_mutex_init(&session->mutex, NULL); return session; } @@ -353,40 +351,29 @@ void linphone_xml_rpc_session_set_user_data(LinphoneXmlRpcSession *session, void session->user_data = ud; } -LinphoneXmlRpcStatus linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request) { +void linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request) { belle_http_request_listener_callbacks_t cbs = { 0 }; belle_http_request_listener_t *l; belle_generic_uri_t *uri; belle_http_request_t *req; belle_sip_memory_body_handler_t *bh; const char *data; - LinphoneXmlRpcStatus status; + LinphoneContent *content; - ms_mutex_lock(&session->mutex); - session->request = linphone_xml_rpc_request_ref(request); - session->content = linphone_content_new(); - linphone_content_set_type(session->content, "text"); - linphone_content_set_subtype(session->content,"xml"); - linphone_content_set_string_buffer(session->content, linphone_xml_rpc_request_get_content(request)); + linphone_xml_rpc_request_ref(request); + content = linphone_content_new(); + linphone_content_set_type(content, "text"); + linphone_content_set_subtype(content, "xml"); + linphone_content_set_string_buffer(content, linphone_xml_rpc_request_get_content(request)); uri = belle_generic_uri_parse(session->url); req = belle_http_request_create("POST", uri, belle_sip_header_content_type_create("text", "xml"), NULL); data = linphone_xml_rpc_request_get_content(request); - bh = belle_sip_memory_body_handler_new_copy_from_buffer(data, strlen(data), NULL, session); + bh = belle_sip_memory_body_handler_new_copy_from_buffer(data, strlen(data), NULL, NULL); belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh)); cbs.process_response = process_response_from_post_xml_rpc_request; cbs.process_io_error = process_io_error_from_post_xml_rpc_request; cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request; - l = belle_http_request_listener_create_from_callbacks(&cbs, session); + l = belle_http_request_listener_create_from_callbacks(&cbs, request); belle_http_provider_send_request(session->core->http_provider, req, l); - - ms_mutex_lock(&session->cond_mutex); - ms_cond_wait(&session->cond, &session->cond_mutex); - ms_mutex_unlock(&session->cond_mutex); - status = session->request->status; - linphone_xml_rpc_request_unref(session->request); - session->request = NULL; - linphone_content_unref(session->content); - session->content = NULL; - ms_mutex_unlock(&session->mutex); - return status; + linphone_content_unref(content); } diff --git a/coreapi/xmlrpc.h b/coreapi/xmlrpc.h index fd98f16bc..de099b3fb 100644 --- a/coreapi/xmlrpc.h +++ b/coreapi/xmlrpc.h @@ -1,5 +1,5 @@ /* -buffer.h +xmlrpc.h Copyright (C) 2010-2015 Belledonne Communications SARL This program is free software; you can redistribute it and/or @@ -59,22 +59,30 @@ typedef struct _LinphoneXmlRpcRequest LinphoneXmlRpcRequest; **/ typedef struct _LinphoneXmlRpcSession LinphoneXmlRpcSession; +typedef void (*LinphoneXmlRpcResponseCb)(LinphoneXmlRpcRequest *request, void *user_data); + /** -* Create a new LinphoneXmlRpcRequest object. -* @param[in] method The XML-RPC method to call. -* @param[in] return_type The expected XML-RPC response type. -* @return A new LinphoneXmlRpcRequest object. + * Create a new LinphoneXmlRpcRequest object. + * @param[in] method The XML-RPC method to call. + * @param[in] return_type The expected XML-RPC response type. + * @param[in] cb The callback that will be called when the XML-RPC response is received or if an error occurs. + * @param[in] user_data A user data that will be passed as a parameter to the callback. + * @return A new LinphoneXmlRpcRequest object. **/ -LINPHONE_PUBLIC LinphoneXmlRpcRequest * linphone_xml_rpc_request_new(const char *method, LinphoneXmlRpcArgType return_type); +LINPHONE_PUBLIC LinphoneXmlRpcRequest * linphone_xml_rpc_request_new(const char *method, LinphoneXmlRpcArgType return_type, + LinphoneXmlRpcResponseCb cb, void *user_data); /** * Create a new LinphoneXmlRpcRequest object giving the arguments to the method call. * @param[in] method The XML-RPC method to call. * @param[in] return_type The expected XML-RPC response type. + * @param[in] cb The callback that will be called when the XML-RPC response is received or if an error occurs. + * @param[in] user_data A user data that will be passed as a parameter to the callback. * @return A new LinphoneXmlRpcRequest object. **/ -LINPHONE_PUBLIC LinphoneXmlRpcRequest * linphone_xml_rpc_request_new_with_args(const char *method, LinphoneXmlRpcArgType return_type, ...); +LINPHONE_PUBLIC LinphoneXmlRpcRequest * linphone_xml_rpc_request_new_with_args(const char *method, LinphoneXmlRpcArgType return_type, + LinphoneXmlRpcResponseCb cb, void *user_data, ...); /** * Acquire a reference to the XML-RPC request. @@ -184,9 +192,8 @@ LINPHONE_PUBLIC void linphone_xml_rpc_session_set_user_data(LinphoneXmlRpcSessio * Send an XML-RPC request. * @param[in] session LinphoneXmlRpcSession object. * @param[in] request The LinphoneXmlRpcRequest to be sent. - * @return The status of the XML-RPC request sending. If it is LinphoneXmlRpcStatusOk, use linphone_xml_rpc_session_get_response() to get the XML-RPC response. **/ -LINPHONE_PUBLIC LinphoneXmlRpcStatus linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request); +LINPHONE_PUBLIC void linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request); /** * @} diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt index 24f811ce7..91ec2fdba 100644 --- a/gtk/CMakeLists.txt +++ b/gtk/CMakeLists.txt @@ -63,6 +63,7 @@ set(SOURCE_FILES loginframe.c main.c propertybox.c + setupwizard.c singleinstance.c status_icon.c status_notifier.c @@ -75,10 +76,6 @@ if(WIN32) list(APPEND SOURCE_FILES linphone.rc) endif() -if(ENABLE_ASSISTANT) - list(APPEND SOURCE_FILES setupwizard.c) -endif() - if(GETTEXT_FOUND) add_definitions("-DENABLE_NLS") endif() diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 32656c993..946de574b 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -53,6 +53,7 @@ linphone_SOURCES= \ singleinstance.c \ conference.c \ config-fetching.c \ + setupwizard.c \ audio_assistant.c \ videowindow.c \ status_icon.c status_icon.h \ @@ -64,11 +65,6 @@ linphone_SOURCES+= \ status_notifier.h endif -if BUILD_WIZARD -linphone_SOURCES+= \ - setupwizard.c -endif - linphone_LDADD= $(top_builddir)/coreapi/liblinphone.la \ $(LIBGTK_LIBS) $(NOTIFY1_LIBS) $(NOTIFY4_LIBS) $(LIBGTKMAC_LIBS) $(INTLLIBS) $(SQLITE3_LIBS) $(BELLESIP_LIBS) diff --git a/gtk/main.c b/gtk/main.c index c73c57ec2..6fff6bbe3 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1977,9 +1977,7 @@ static void linphone_gtk_check_soundcards(){ static void linphone_gtk_quit_core(void){ linphone_gtk_unmonitor_usb(); g_source_remove_by_user_data(linphone_gtk_get_core()); -#ifdef BUILD_WIZARD linphone_gtk_close_assistant(); -#endif linphone_gtk_set_ldap(NULL); linphone_gtk_destroy_log_window(); linphone_core_destroy(the_core); @@ -2019,12 +2017,10 @@ static gboolean on_block_termination(void){ static void linphone_gtk_init_ui(void){ linphone_gtk_init_main_window(); -#ifdef BUILD_WIZARD // Veryfing if at least one sip account is configured. If not, show wizard if (linphone_core_get_proxy_config_list(linphone_gtk_get_core()) == NULL) { linphone_gtk_show_assistant(); } -#endif if(run_audio_assistant){ linphone_gtk_show_audio_assistant(); diff --git a/gtk/main.ui b/gtk/main.ui index 48e5a61d6..df7bbc6e2 100644 --- a/gtk/main.ui +++ b/gtk/main.ui @@ -923,6 +923,7 @@ Account assistant + True False connect_image False diff --git a/gtk/password.ui b/gtk/password.ui index a355c1848..d9ce720aa 100644 --- a/gtk/password.ui +++ b/gtk/password.ui @@ -9,7 +9,6 @@ True center-on-parent dialog - False True diff --git a/gtk/propertybox.c b/gtk/propertybox.c index 6f4816ece..ff0aa9baa 100644 --- a/gtk/propertybox.c +++ b/gtk/propertybox.c @@ -1584,11 +1584,6 @@ void linphone_gtk_show_parameters(void){ gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(pb,"username")),linphone_address_get_username(contact)); linphone_address_destroy(contact); } -#ifdef BUILD_WIZARD - gtk_widget_show(linphone_gtk_get_widget(pb,"wizard")); -#else - gtk_widget_hide(linphone_gtk_get_widget(pb,"wizard")); -#endif linphone_gtk_show_sip_accounts(pb); /* CODECS CONFIG */ linphone_gtk_init_codec_list(GTK_TREE_VIEW(codec_list)); diff --git a/gtk/setupwizard.c b/gtk/setupwizard.c index 784d8984f..0de93a957 100644 --- a/gtk/setupwizard.c +++ b/gtk/setupwizard.c @@ -20,107 +20,236 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "linphone.h" #include #include -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 GtkWidget *the_assistant=NULL; -static GtkWidget *create_intro(){ - GtkWidget *vbox=gtk_vbox_new(FALSE,2); - GtkWidget *label=gtk_label_new(_("Welcome!\nThis assistant will help you to use a SIP account for your calls.")); - gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2); - g_object_set_data(G_OBJECT(vbox),"label",label); +static LinphoneAccountCreator * linphone_gtk_assistant_init(GtkWidget *w) { + LinphoneAccountCreator *creator = linphone_account_creator_new(linphone_gtk_get_core(), "https://www.linphone.org/wizard.php"); + g_object_set_data(G_OBJECT(w), "creator", creator); + return creator; +} + +static LinphoneAccountCreator * linphone_gtk_assistant_get_creator(GtkWidget *w) { + return (LinphoneAccountCreator *)g_object_get_data(G_OBJECT(w), "creator"); +} + +static void linphone_gtk_account_validate_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, void *user_data) { + GtkWidget *assistant = (GtkWidget *)user_data; + if (status == LinphoneAccountCreatorOk) { + // Go to page_6_linphone_account_validation_wait + gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 6); + } else { // Error when attempting to create the account + // Go to page_8_error + gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 8); + } +} + +static void create_account(GtkWidget *assistant) { + LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(assistant); + linphone_account_creator_set_validate_cb(creator, linphone_gtk_account_validate_cb, assistant); + linphone_account_creator_validate(creator); +} + +static void linphone_gtk_test_account_validation_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, void *user_data) { + GtkWidget *assistant = (GtkWidget *)user_data; + if (status == LinphoneAccountCreatorOk) { + // Go to page_9_finish + gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 9); + } else { + // Go to page_8_error + gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 8); + } +} + +static void check_account_validation(GtkWidget *page) { + LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page)); + linphone_account_creator_set_test_validation_cb(creator, linphone_gtk_test_account_validation_cb, page); + linphone_account_creator_test_validation(creator); +} + +static void linphone_gtk_assistant_closed(GtkWidget *w) { + linphone_gtk_close_assistant(); +} + +static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page) { + int pagenum = gtk_assistant_get_current_page(GTK_ASSISTANT(assistant)); + + switch (pagenum) { + case 5: + create_account(assistant); + break; + case 7: + check_account_validation(assistant); + break; + case 9: + { + LinphoneAddress *identity; + LinphoneAuthInfo *info; + LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(assistant); + LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(linphone_gtk_get_core()); + char *identity_str = ms_strdup_printf("sip:%s@%s", linphone_account_creator_get_username(creator), linphone_account_creator_get_domain(creator)); + + linphone_proxy_config_set_identity(cfg, identity_str); + linphone_proxy_config_set_server_addr(cfg, linphone_account_creator_get_domain(creator)); + linphone_proxy_config_set_route(cfg, linphone_account_creator_get_route(creator)); + linphone_proxy_config_enable_publish(cfg, FALSE); + linphone_proxy_config_enable_register(cfg, TRUE); + + if (strcmp(linphone_account_creator_get_domain(creator), "sip.linphone.org") == 0) { + linphone_proxy_config_enable_avpf(cfg,TRUE); + // If account created on sip.linphone.org, we configure linphone to use TLS by default + if (linphone_core_sip_transport_supported(linphone_gtk_get_core(), LinphoneTransportTls)) { + LinphoneAddress *addr = linphone_address_new(linphone_proxy_config_get_server_addr(cfg)); + char *tmp; + linphone_address_set_transport(addr, LinphoneTransportTls); + tmp = linphone_address_as_string(addr); + linphone_proxy_config_set_server_addr(cfg, tmp); + linphone_proxy_config_set_route(cfg, tmp); + ms_free(tmp); + linphone_address_destroy(addr); + } + linphone_core_set_stun_server(linphone_gtk_get_core(), "stun.linphone.org"); + linphone_core_set_firewall_policy(linphone_gtk_get_core(), LinphonePolicyUseIce); + } + + identity = linphone_address_new(linphone_proxy_config_get_identity(cfg)); + info = linphone_auth_info_new(linphone_address_get_username(identity), NULL, + linphone_account_creator_get_password(creator), NULL, NULL, linphone_address_get_domain(identity)); + linphone_core_add_auth_info(linphone_gtk_get_core(), info); + linphone_address_destroy(identity); + + if (linphone_core_add_proxy_config(linphone_gtk_get_core(), cfg) != -1) { + linphone_core_set_default_proxy(linphone_gtk_get_core(), cfg); + linphone_gtk_load_identities(); + } + gtk_assistant_commit(GTK_ASSISTANT(assistant)); + } + break; + default: + break; + } +} + +static gint destroy_assistant(GtkWidget* w){ + gtk_widget_destroy(w); + the_assistant = NULL; + return FALSE; +} + +static int linphone_gtk_assistant_forward(int curpage, gpointer data) { + GtkWidget *w = GTK_WIDGET(data); + GtkWidget *box = gtk_assistant_get_nth_page(GTK_ASSISTANT(w), curpage); + LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(w); + + switch (curpage) { + case 0: + curpage = 1; // Go to page_1_choice + break; + case 1: + { + GtkWidget *create_button = (GtkWidget*)g_object_get_data(G_OBJECT(box), "create_account"); + GtkWidget *setup_linphone_account = (GtkWidget*)g_object_get_data(G_OBJECT(box), "setup_linphone_account"); + GtkWidget *setup_account = (GtkWidget*)g_object_get_data(G_OBJECT(box), "setup_account"); + GtkWidget *config_uri = (GtkWidget*)g_object_get_data(G_OBJECT(box), "config-uri"); + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(create_button))) { + curpage = 4; // Go to page_4_linphone_account_creation_configuration + } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_linphone_account))) { + curpage = 3; // Go to page_3_linphone_account_configuration + } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_account))) { + curpage = 2; // Go to page_2_external_account_configuration + } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(config_uri))) { + /* Destroy the assistant and popup config-uri dialog */ + gtk_widget_hide(w); + linphone_gtk_set_configuration_uri(); + curpage = 0; + g_idle_add((GSourceFunc)destroy_assistant, w); + } + } + break; + case 2: + linphone_account_creator_set_username(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username")))); + linphone_account_creator_set_domain(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain")))); + linphone_account_creator_set_route(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "proxy")))); + linphone_account_creator_set_password(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "password")))); + curpage = 9; // Go to page_9_finish + break; + case 3: + linphone_account_creator_set_username(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username")))); + linphone_account_creator_set_domain(creator, "sip.linphone.org"); + linphone_account_creator_set_route(creator, "sip.linphone.org"); + linphone_account_creator_set_password(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "password")))); + curpage = 9; // Go to page_9_finish + break; + case 4: + linphone_account_creator_set_username(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "username")))); + linphone_account_creator_set_password(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "password")))); + linphone_account_creator_set_email(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "email")))); + linphone_account_creator_set_subscribe(creator, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(box), "newsletter")))); + curpage = 5; // Go to page_5_linphone_account_creation_in_progress + break; + case 6: + curpage = 7; // Go to page_7_linphone_account_validation_check_in_progress + break; + default: + break; + } + return curpage; +} + +static GtkWidget * create_intro_page(void) { + GtkWidget *vbox = gtk_vbox_new(FALSE, 2); + GtkWidget *label = gtk_label_new(_("Welcome!\nThis assistant will help you to use a SIP account for your calls.")); + gtk_box_pack_start(GTK_BOX (vbox), label, TRUE, TRUE, 2); + g_object_set_data(G_OBJECT(vbox), "label", label); gtk_widget_show_all(vbox); return vbox; } -static GtkWidget *create_setup_signin_choice(){ - GtkWidget *vbox=gtk_vbox_new(FALSE,2); - GtkWidget *t1=gtk_radio_button_new_with_label(NULL,_("Create an account on linphone.org")); - GtkWidget *t2=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1),_("I have already a linphone.org account and I just want to use it")); - GtkWidget *t3=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1),_("I have already a sip account and I just want to use it")); - GtkWidget *t4=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1),_("I want to specify a remote configuration URI")); +static GtkWidget * create_choice_page(void) { + GtkWidget *vbox = gtk_vbox_new(FALSE, 2); + GtkWidget *t1 = gtk_radio_button_new_with_label(NULL, _("Create an account on linphone.org")); + GtkWidget *t2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1), _("I have already a linphone.org account and I just want to use it")); + GtkWidget *t3 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1), _("I have already a sip account and I just want to use it")); + GtkWidget *t4 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(t1), _("I want to specify a remote configuration URI")); - gtk_box_pack_start (GTK_BOX (vbox), t1, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (vbox), t2, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (vbox), t3, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (vbox), t4, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX (vbox), t1, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX (vbox), t2, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX (vbox), t3, TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX (vbox), t4, TRUE, TRUE, 2); gtk_widget_show_all(vbox); - g_object_set_data(G_OBJECT(vbox),"create_account",t1); - g_object_set_data(G_OBJECT(vbox),"setup_linphone_account",t2); - g_object_set_data(G_OBJECT(vbox),"setup_account",t3); - g_object_set_data(G_OBJECT(vbox),"config-uri",t4); + g_object_set_data(G_OBJECT(vbox), "create_account", t1); + g_object_set_data(G_OBJECT(vbox), "setup_linphone_account", t2); + g_object_set_data(G_OBJECT(vbox), "setup_account", t3); + g_object_set_data(G_OBJECT(vbox), "config-uri", t4); return vbox; } -static int all_account_information_entered(GtkWidget *w) { - GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username")); - GtkEntry* domain = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"domain")); +static int external_account_configuration_complete(GtkWidget *w) { + GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w), "username")); + GtkEntry* domain = GTK_ENTRY(g_object_get_data(G_OBJECT(w), "domain")); - if (gtk_entry_get_text_length(username) > 0 && - gtk_entry_get_text_length(domain) > 0 && - g_regex_match_simple("^[a-zA-Z0-9]+[a-zA-Z0-9.\\-_]{2,}$", gtk_entry_get_text(username), 0, 0) && - g_regex_match_simple("^(sip:)?([a-zA-Z0-9]+([\\.-][a-zA-Z0-9]+)*)$", gtk_entry_get_text(domain), 0, 0)) { + if ((gtk_entry_get_text_length(username) > 0) + && (gtk_entry_get_text_length(domain) > 0) + && (g_regex_match_simple("^[a-zA-Z0-9]+[a-zA-Z0-9.\\-_]{2,}$", gtk_entry_get_text(username), 0, 0)) + && (g_regex_match_simple("^(sip:)?([a-zA-Z0-9]+([\\.-][a-zA-Z0-9]+)*)$", gtk_entry_get_text(domain), 0, 0))) { return 1; } return 0; } -static void account_informations_changed(GtkEntry *entry, GtkWidget *w) { - GtkWidget *assistant=gtk_widget_get_toplevel(w); - gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w, - all_account_information_entered(w)>0); +static void external_account_configuration_changed(GtkEntry *entry, GtkWidget *w) { + GtkWidget *assistant = gtk_widget_get_toplevel(w); + gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), w, external_account_configuration_complete(w) > 0); } -static void linphone_account_informations_changed(GtkEntry *entry, GtkWidget *w) { - GtkWidget *assistant=gtk_widget_get_toplevel(w); - GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"username")); - - gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),w, - gtk_entry_get_text_length(username) > 0); -} - -static GtkWidget *create_linphone_account_informations_page() { - GtkWidget *vbox=gtk_table_new(3, 2, TRUE); - GtkWidget *label=gtk_label_new(_("Enter your linphone.org username")); - - GdkColor color; - GtkWidget *labelEmpty; - GtkWidget *labelUsername; - GtkWidget *entryUsername; - GtkWidget *labelPassword; - GtkWidget *entryPassword; - - gdk_color_parse ("red", &color); - labelEmpty=gtk_label_new(NULL); - gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color); - - labelUsername=gtk_label_new(_("Username:")); - entryUsername=gtk_entry_new(); - labelPassword=gtk_label_new(_("Password:")); - entryPassword=gtk_entry_new(); - gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE); - - gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1); - gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2); - gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 1, 2); - gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3); - gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3); - - gtk_widget_show_all(vbox); - g_object_set_data(G_OBJECT(vbox),"username",entryUsername); - g_object_set_data(G_OBJECT(vbox),"password",entryPassword); - g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty); - g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)linphone_account_informations_changed,vbox); - return vbox; -} - -static GtkWidget *create_account_informations_page() { - GtkWidget *vbox=gtk_table_new(6, 2, FALSE); - GtkWidget *label=gtk_label_new(_("Enter your account informations")); - +static GtkWidget * create_external_account_configuration_page(void) { + GtkWidget *vbox = gtk_table_new(6, 2, FALSE); + GtkWidget *label = gtk_label_new(_("Enter your account information")); GdkColor color; GtkWidget *labelEmpty; GtkWidget *labelUsername; @@ -131,19 +260,19 @@ static GtkWidget *create_account_informations_page() { GtkWidget *entryUsername; GtkWidget *entryDomain; GtkWidget *entryRoute; - gdk_color_parse ("red", &color); - labelEmpty=gtk_label_new(NULL); - gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color); - labelUsername=gtk_label_new(_("Username*")); - labelPassword=gtk_label_new(_("Password*")); - entryPassword=gtk_entry_new(); + gdk_color_parse("red", &color); + labelEmpty = gtk_label_new(NULL); + gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color); + labelUsername = gtk_label_new(_("Username*")); + labelPassword = gtk_label_new(_("Password*")); + entryPassword = gtk_entry_new(); gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE); - labelDomain=gtk_label_new(_("Domain*")); - labelProxy=gtk_label_new(_("Proxy")); - entryUsername=gtk_entry_new(); - entryDomain=gtk_entry_new(); - entryRoute=gtk_entry_new(); + labelDomain = gtk_label_new(_("Domain*")); + labelProxy = gtk_label_new(_("Proxy")); + entryUsername = gtk_entry_new(); + entryDomain = gtk_entry_new(); + entryRoute = gtk_entry_new(); gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1); gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2); @@ -157,190 +286,191 @@ static GtkWidget *create_account_informations_page() { gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmpty, 0, 2, 5, 6); gtk_widget_show_all(vbox); - g_object_set_data(G_OBJECT(vbox),"username",entryUsername); - g_object_set_data(G_OBJECT(vbox),"password",entryPassword); - g_object_set_data(G_OBJECT(vbox),"domain",entryDomain); - g_object_set_data(G_OBJECT(vbox),"proxy",entryRoute); - g_object_set_data(G_OBJECT(vbox),"errorstring",labelEmpty); - g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_informations_changed,vbox); - g_signal_connect(G_OBJECT(entryDomain),"changed",(GCallback)account_informations_changed,vbox); - g_signal_connect(G_OBJECT(entryRoute),"changed",(GCallback)account_informations_changed,vbox); + g_object_set_data(G_OBJECT(vbox), "username", entryUsername); + g_object_set_data(G_OBJECT(vbox), "password", entryPassword); + g_object_set_data(G_OBJECT(vbox), "domain", entryDomain); + g_object_set_data(G_OBJECT(vbox), "proxy", entryRoute); + g_object_set_data(G_OBJECT(vbox), "errorstring", labelEmpty); + g_signal_connect(G_OBJECT(entryUsername), "changed", (GCallback)external_account_configuration_changed, vbox); + g_signal_connect(G_OBJECT(entryDomain), "changed", (GCallback)external_account_configuration_changed, vbox); + g_signal_connect(G_OBJECT(entryRoute), "changed", (GCallback)external_account_configuration_changed, vbox); return vbox; } -static int create_account(GtkWidget *page) { - LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page)); - LinphoneProxyConfig *res=linphone_account_creator_validate(creator); - if (res) { - if (!g_regex_match_simple("^sip:[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}@sip.linphone.org$",creator->username, 0, 0)) { - gchar identity[128]; - g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", creator->username); - linphone_account_creator_set_username(creator, identity); - linphone_account_creator_set_domain(creator, "sip:sip.linphone.org"); - } +static void linphone_account_configuration_changed(GtkEntry *entry, GtkWidget *w) { + GtkWidget *assistant = gtk_widget_get_toplevel(w); + GtkEntry* username = GTK_ENTRY(g_object_get_data(G_OBJECT(w), "username")); + gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), w, gtk_entry_get_text_length(username) > 0); +} + +static GtkWidget * create_linphone_account_configuration_page(void) { + GtkWidget *vbox = gtk_table_new(3, 2, TRUE); + GtkWidget *label = gtk_label_new(_("Enter your linphone.org username")); + GdkColor color; + GtkWidget *labelEmpty; + GtkWidget *labelUsername; + GtkWidget *entryUsername; + GtkWidget *labelPassword; + GtkWidget *entryPassword; + + gdk_color_parse("red", &color); + labelEmpty = gtk_label_new(NULL); + gtk_widget_modify_fg(labelEmpty, GTK_STATE_NORMAL, &color); + + labelUsername = gtk_label_new(_("Username:")); + entryUsername = gtk_entry_new(); + labelPassword = gtk_label_new(_("Password:")); + entryPassword = gtk_entry_new(); + gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE); + + gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 2, 0, 1); + gtk_table_attach_defaults(GTK_TABLE(vbox), labelUsername, 0, 1, 1, 2); + gtk_table_attach_defaults(GTK_TABLE(vbox), entryUsername, 1, 2, 1, 2); + gtk_table_attach_defaults(GTK_TABLE(vbox), labelPassword, 0, 1, 2, 3); + gtk_table_attach_defaults(GTK_TABLE(vbox), entryPassword, 1, 2, 2, 3); + + gtk_widget_show_all(vbox); + g_object_set_data(G_OBJECT(vbox), "username", entryUsername); + g_object_set_data(G_OBJECT(vbox), "password", entryPassword); + g_object_set_data(G_OBJECT(vbox), "errorstring", labelEmpty); + g_signal_connect(G_OBJECT(entryUsername), "changed", (GCallback)linphone_account_configuration_changed, vbox); + return vbox; +} + +static int linphone_account_creation_configuration_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; } return 0; } -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; - } - return 0; -} - -static void account_email_changed(GtkEntry *entry, GtkWidget *w) { - // Verifying if email entered is correct, and if form is correctly filled, let the user go next page - - GtkEntry* email = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"email")); - GtkImage* isEmailOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"emailOk")); - 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)) { - GdkPixbuf *ok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "ok")); - g_object_set_data(G_OBJECT(w),"is_email_correct",GINT_TO_POINTER(1)); - gtk_image_set_from_pixbuf(isEmailOk, ok); - } - else { - GdkPixbuf *notok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "notok")); - 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, - is_account_information_correct(w)>0); -} - -static void account_password_changed(GtkEntry *entry, GtkWidget *w) { - // Verifying if passwords entered match, and if form is correctly filled, let the user go next page - - GtkEntry* password = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"password")); - GtkImage* isPasswordOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w),"passwordOk")); - GtkEntry* password_confirm = GTK_ENTRY(g_object_get_data(G_OBJECT(w),"password_confirm")); - GtkWidget *assistant=gtk_widget_get_toplevel(w); - GtkLabel* passwordError = GTK_LABEL(g_object_get_data(G_OBJECT(w),"error")); - - 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) { - GdkPixbuf *ok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "ok")); - 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 { - GdkPixbuf *notok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "notok")); - if (gtk_entry_get_text_length(password) < PASSWORD_MIN_SIZE) { - gtk_label_set_text(passwordError, "Password is too short !"); - } - 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 !"); - } - 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) { +static gboolean update_interface_with_username_availability(void *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")); + 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) { - GdkPixbuf *ok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "ok")); - g_object_set_data(G_OBJECT(w),"is_username_available",GINT_TO_POINTER(1)); - gtk_image_set_from_pixbuf(isUsernameOk, ok); + GdkPixbuf *ok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "ok_pixbuf")); + g_object_set_data(G_OBJECT(w), "is_username_available", GINT_TO_POINTER(1)); + gtk_image_set_from_pixbuf(isUsernameOk, ok_pixbuf); gtk_label_set_text(usernameError, ""); - } - else { - GdkPixbuf *notok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "notok")); + } else { + GdkPixbuf *nok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "nok_pixbuf")); 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); + g_object_set_data(G_OBJECT(w), "is_username_available", GINT_TO_POINTER(0)); + gtk_image_set_from_pixbuf(isUsernameOk, nok_pixbuf); } - - gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),GTK_WIDGET(w), - is_account_information_correct(GTK_WIDGET(w))>0); - + gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), GTK_WIDGET(w), linphone_account_creation_configuration_correct(GTK_WIDGET(w)) > 0); return FALSE; } -void* check_username_availability(void* 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)); +static void linphone_gtk_test_account_existence_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, void *user_data) { + GtkWidget *w = (GtkWidget *)user_data; + int account_existing = (status == LinphoneAccountCreatorOk) ? 0 : 1; + 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 gboolean start_check_username_availability_thread(GtkWidget *w) { -#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 +static gboolean check_username_availability(void *w) { + LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(GTK_WIDGET(w))); g_object_set_data(G_OBJECT(w), "usernameAvailabilityTimerID", GUINT_TO_POINTER(0)); + linphone_account_creator_set_test_existence_cb(creator, linphone_gtk_test_account_existence_cb, w); + linphone_account_creator_test_existence(creator); return FALSE; } -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 +static void linphone_account_creation_username_changed(GtkEntry *entry, GtkWidget *w) { 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")); + 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")); - LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant); + LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(assistant); linphone_account_creator_set_username(creator, gtk_entry_get_text(username)); linphone_account_creator_set_domain(creator, "sip.linphone.org"); + linphone_account_creator_set_route(creator, "sip.linphone.org"); if (g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) { guint timerID = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(w), "usernameAvailabilityTimerID")); if (timerID > 0) { g_source_remove(timerID); } - timerID = g_timeout_add(500, start_check_username_availability_thread, w); + timerID = g_timeout_add(500, (GSourceFunc)check_username_availability, w); g_object_set_data(G_OBJECT(w), "usernameAvailabilityTimerID", GUINT_TO_POINTER(timerID)); - } - else { - GdkPixbuf *notok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "notok")); + } else { + GdkPixbuf *nok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "nok_pixbuf")); if (gtk_entry_get_text_length(username) < LOGIN_MIN_SIZE) { gtk_label_set_text(usernameError, "Username is too short"); - } - else if (!g_regex_match_simple("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{3,}$", gtk_entry_get_text(username), 0, 0)) { + } 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"); } - 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); + g_object_set_data(G_OBJECT(w), "is_username_available", GINT_TO_POINTER(0)); + gtk_image_set_from_pixbuf(isUsernameOk, nok_pixbuf); + gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), w, linphone_account_creation_configuration_correct(w) > 0); } } -static GtkWidget *create_account_information_page() { - GtkWidget *vbox=gtk_table_new(7, 3, FALSE); - GdkPixbuf *notok = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "notok")); - GtkWidget *label=gtk_label_new(_("(*) Required fields")); - GtkWidget *labelUsername=gtk_label_new(_("Username: (*)")); - GtkWidget *isUsernameOk=gtk_image_new_from_pixbuf(notok); - GtkWidget *labelPassword=gtk_label_new(_("Password: (*)")); - GtkWidget *isPasswordOk=gtk_image_new_from_pixbuf(notok); - GtkWidget *labelEmail=gtk_label_new(_("Email: (*)")); - GtkWidget *isEmailOk=gtk_image_new_from_pixbuf(notok); - GtkWidget *labelPassword2=gtk_label_new(_("Confirm your password: (*)")); - GtkWidget *entryUsername=gtk_entry_new(); - GtkWidget *entryPassword=gtk_entry_new(); +static void linphone_account_creation_email_changed(GtkEntry *entry, GtkWidget *w) { + GtkEntry* email = GTK_ENTRY(g_object_get_data(G_OBJECT(w), "email")); + GtkImage* isEmailOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w), "emailOk")); + 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)) { + GdkPixbuf *ok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "ok_pixbuf")); + g_object_set_data(G_OBJECT(w), "is_email_correct", GINT_TO_POINTER(1)); + gtk_image_set_from_pixbuf(isEmailOk, ok_pixbuf); + } else { + GdkPixbuf *nok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "nok_pixbuf")); + g_object_set_data(G_OBJECT(w), "is_email_correct", GINT_TO_POINTER(0)); + gtk_image_set_from_pixbuf(isEmailOk, nok_pixbuf); + } + gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), w, linphone_account_creation_configuration_correct(w) > 0); +} + +static void linphone_account_creation_password_changed(GtkEntry *entry, GtkWidget *w) { + GtkEntry* password = GTK_ENTRY(g_object_get_data(G_OBJECT(w), "password")); + GtkImage* isPasswordOk = GTK_IMAGE(g_object_get_data(G_OBJECT(w), "passwordOk")); + GtkEntry* password_confirm = GTK_ENTRY(g_object_get_data(G_OBJECT(w), "password_confirm")); + GtkWidget *assistant = gtk_widget_get_toplevel(w); + GtkLabel* passwordError = GTK_LABEL(g_object_get_data(G_OBJECT(w), "error")); + + 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)) { + GdkPixbuf *ok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "ok_pixbuf")); + g_object_set_data(G_OBJECT(w), "is_password_correct", GINT_TO_POINTER(1)); + gtk_image_set_from_pixbuf(isPasswordOk, ok_pixbuf); + gtk_label_set_text(passwordError, ""); + } else { + GdkPixbuf *nok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "nok_pixbuf")); + if (gtk_entry_get_text_length(password) < PASSWORD_MIN_SIZE) { + gtk_label_set_text(passwordError, "Password is too short !"); + } 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 !"); + } + g_object_set_data(G_OBJECT(w), "is_password_correct", GINT_TO_POINTER(0)); + gtk_image_set_from_pixbuf(isPasswordOk, nok_pixbuf); + } + gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), w, linphone_account_creation_configuration_correct(w) > 0); +} + +static GtkWidget * create_linphone_account_creation_configuration_page(void) { + GtkWidget *vbox = gtk_table_new(7, 3, FALSE); + GdkPixbuf *nok_pixbuf = GDK_PIXBUF(g_object_get_data(G_OBJECT(the_assistant), "nok_pixbuf")); + GtkWidget *label = gtk_label_new(_("(*) Required fields")); + GtkWidget *labelUsername = gtk_label_new(_("Username: (*)")); + GtkWidget *isUsernameOk = gtk_image_new_from_pixbuf(nok_pixbuf); + GtkWidget *labelPassword = gtk_label_new(_("Password: (*)")); + GtkWidget *isPasswordOk = gtk_image_new_from_pixbuf(nok_pixbuf); + GtkWidget *labelEmail = gtk_label_new(_("Email: (*)")); + GtkWidget *isEmailOk = gtk_image_new_from_pixbuf(nok_pixbuf); + GtkWidget *labelPassword2 = gtk_label_new(_("Confirm your password: (*)")); + GtkWidget *entryUsername = gtk_entry_new(); + GtkWidget *entryPassword = gtk_entry_new(); GtkWidget *entryEmail; GtkWidget *entryPassword2; GtkWidget *checkNewsletter; @@ -348,22 +478,23 @@ static GtkWidget *create_account_information_page() { GtkWidget *passwordVbox1; GtkWidget *passwordVbox2; GdkColor color; - gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE); - entryEmail=gtk_entry_new(); - entryPassword2=gtk_entry_new(); - gtk_entry_set_visibility(GTK_ENTRY(entryPassword2), FALSE); - checkNewsletter=gtk_check_button_new_with_label(_("Keep me informed with linphone updates")); - gdk_color_parse ("red", &color); - labelError=gtk_label_new(NULL); + gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE); + entryEmail = gtk_entry_new(); + entryPassword2 = gtk_entry_new(); + gtk_entry_set_visibility(GTK_ENTRY(entryPassword2), FALSE); + checkNewsletter = gtk_check_button_new_with_label(_("Keep me informed with linphone updates")); + + gdk_color_parse("red", &color); + labelError = gtk_label_new(NULL); gtk_widget_modify_fg(labelError, GTK_STATE_NORMAL, &color); - passwordVbox1=gtk_vbox_new(FALSE,2); - passwordVbox2=gtk_vbox_new(FALSE,2); - gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword, TRUE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (passwordVbox1), labelPassword2, TRUE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword, TRUE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (passwordVbox2), entryPassword2, TRUE, FALSE, 2); + passwordVbox1 = gtk_vbox_new(FALSE, 2); + passwordVbox2 = gtk_vbox_new(FALSE, 2); + gtk_box_pack_start(GTK_BOX (passwordVbox1), labelPassword, TRUE, FALSE, 2); + gtk_box_pack_start(GTK_BOX (passwordVbox1), labelPassword2, TRUE, FALSE, 2); + gtk_box_pack_start(GTK_BOX (passwordVbox2), entryPassword, TRUE, FALSE, 2); + gtk_box_pack_start(GTK_BOX (passwordVbox2), entryPassword2, TRUE, FALSE, 2); gtk_table_attach_defaults(GTK_TABLE(vbox), label, 0, 3, 0, 1); gtk_table_attach_defaults(GTK_TABLE(vbox), labelEmail, 0, 1, 1, 2); @@ -379,310 +510,159 @@ static GtkWidget *create_account_information_page() { gtk_table_attach_defaults(GTK_TABLE(vbox), checkNewsletter, 0, 3, 6, 7); gtk_widget_show_all(vbox); - g_object_set_data(G_OBJECT(vbox),"username",entryUsername); - g_object_set_data(G_OBJECT(vbox),"password",entryPassword); - g_object_set_data(G_OBJECT(vbox),"email",entryEmail); - g_object_set_data(G_OBJECT(vbox),"usernameOk",isUsernameOk); - g_object_set_data(G_OBJECT(vbox),"passwordOk",isPasswordOk); - g_object_set_data(G_OBJECT(vbox),"emailOk",isEmailOk); - g_object_set_data(G_OBJECT(vbox),"password_confirm",entryPassword2); - g_object_set_data(G_OBJECT(vbox),"newsletter",checkNewsletter); - g_object_set_data(G_OBJECT(vbox),"error",labelError); - g_signal_connect(G_OBJECT(entryUsername),"changed",(GCallback)account_username_changed,vbox); - g_signal_connect(G_OBJECT(entryPassword),"changed",(GCallback)account_password_changed,vbox); - g_signal_connect(G_OBJECT(entryEmail),"changed",(GCallback)account_email_changed,vbox); - g_signal_connect(G_OBJECT(entryPassword2),"changed",(GCallback)account_password_changed,vbox); + g_object_set_data(G_OBJECT(vbox), "username", entryUsername); + g_object_set_data(G_OBJECT(vbox), "password", entryPassword); + g_object_set_data(G_OBJECT(vbox), "email", entryEmail); + g_object_set_data(G_OBJECT(vbox), "usernameOk", isUsernameOk); + g_object_set_data(G_OBJECT(vbox), "passwordOk", isPasswordOk); + g_object_set_data(G_OBJECT(vbox), "emailOk", isEmailOk); + g_object_set_data(G_OBJECT(vbox), "password_confirm", entryPassword2); + g_object_set_data(G_OBJECT(vbox), "newsletter", checkNewsletter); + g_object_set_data(G_OBJECT(vbox), "error", labelError); + g_signal_connect(G_OBJECT(entryUsername), "changed", (GCallback)linphone_account_creation_username_changed, vbox); + g_signal_connect(G_OBJECT(entryPassword), "changed", (GCallback)linphone_account_creation_password_changed, vbox); + g_signal_connect(G_OBJECT(entryEmail), "changed", (GCallback)linphone_account_creation_email_changed, vbox); + g_signal_connect(G_OBJECT(entryPassword2), "changed", (GCallback)linphone_account_creation_password_changed, vbox); return vbox; } -/* -static GtkWidget *create_confirmation_page(){ - GtkWidget *vbox=gtk_vbox_new(FALSE,2); - GtkWidget *label=gtk_label_new(NULL); - gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2); - g_object_set_data(G_OBJECT(vbox),"label",label); - gtk_widget_show_all(vbox); - return vbox; -} -*/ - -static GtkWidget *create_error_page(){ - GtkWidget *vbox=gtk_table_new(2, 1, FALSE); - GtkWidget *label=gtk_label_new(_("Error, account not validated, username already used or server unreachable.\nPlease go back and try again.")); - - gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100); - - g_object_set_data(G_OBJECT(vbox),"label",label); - gtk_widget_show_all(vbox); - return vbox; -} - -static GtkWidget *create_finish_page(){ - GtkWidget *vbox=gtk_vbox_new(FALSE,2); - GtkWidget *label=gtk_label_new(_("Thank you. Your account is now configured and ready for use.")); +static GtkWidget * create_linphone_account_creation_in_progress_page(void) { + GtkWidget *vbox = gtk_vbox_new(FALSE, 2); + GtkWidget *label = gtk_label_new(_("Your account is being created, please wait.")); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2); gtk_widget_show_all(vbox); return vbox; } -static GtkWidget *wait_for_activation() { - GtkWidget *vbox=gtk_table_new(2, 1, FALSE); - GtkWidget *label=gtk_label_new(_("Please validate your account by clicking on the link we just sent you by email.\n" - "Then come back here and press Next button.")); - +static GtkWidget * create_linphone_account_validation_wait_page(void) { + GtkWidget *vbox = gtk_table_new(2, 1, FALSE); + GtkWidget *label = gtk_label_new(_("Please validate your account by clicking on the link we just sent you by email.\n" + "Then come back here and press Next button.")); gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100); - - g_object_set_data(G_OBJECT(vbox),"label",label); + g_object_set_data(G_OBJECT(vbox), "label", label); gtk_widget_show_all(vbox); return vbox; } -static int is_account_validated(GtkWidget *page) { - LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(gtk_widget_get_toplevel(page)); - return linphone_account_creator_test_validation(creator); +static GtkWidget * create_linphone_account_validation_check_in_progress_page(void) { + GtkWidget *vbox = gtk_vbox_new(FALSE, 2); + GtkWidget *label = gtk_label_new(_("Checking if your account is been validated, please wait.")); + gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2); + gtk_widget_show_all(vbox); + return vbox; } -static void linphone_gtk_assistant_closed(GtkWidget *w){ - linphone_gtk_close_assistant(); +static GtkWidget * create_error_page(void) { + GtkWidget *vbox = gtk_table_new(2, 1, FALSE); + GtkWidget *label = gtk_label_new(_("Error, account not validated, username already used or server unreachable.\nPlease go back and try again.")); + gtk_table_attach(GTK_TABLE(vbox), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 100); + g_object_set_data(G_OBJECT(vbox), "label", label); + gtk_widget_show_all(vbox); + return vbox; } -static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page){ - int pagenum=gtk_assistant_get_current_page(GTK_ASSISTANT(assistant)); - - if (pagenum == 5) { - gtk_assistant_commit(GTK_ASSISTANT(assistant)); - } else if (pagenum == gtk_assistant_get_n_pages(GTK_ASSISTANT(assistant)) - 1) { - LinphoneAddress *identity; - LinphoneAuthInfo *info; - // Saving the account and making it default - LinphoneAccountCreator *creator=linphone_gtk_assistant_get_creator(assistant); - LinphoneProxyConfig *cfg=linphone_proxy_config_new(); - linphone_proxy_config_set_identity(cfg, creator->username); - linphone_proxy_config_set_server_addr(cfg, creator->domain); - linphone_proxy_config_set_route(cfg, creator->route); - linphone_proxy_config_set_expires(cfg, 3600); - linphone_proxy_config_enable_publish(cfg, FALSE); - linphone_proxy_config_enable_register(cfg, TRUE); - - identity = linphone_address_new(creator->username); - info=linphone_auth_info_new(linphone_address_get_username(identity), NULL, creator->password, NULL, NULL, linphone_address_get_domain(identity)); - linphone_core_add_auth_info(linphone_gtk_get_core(),info); - linphone_address_destroy(identity); - - if (strcmp(creator->domain, "sip:sip.linphone.org") == 0) { - linphone_proxy_config_enable_avpf(cfg,TRUE); - // If account created on sip.linphone.org, we configure linphone to use TLS by default - if (linphone_core_sip_transport_supported(linphone_gtk_get_core(),LinphoneTransportTls)) { - LinphoneAddress *addr=linphone_address_new(creator->domain); - char *tmp; - linphone_address_set_transport(addr, LinphoneTransportTls); - tmp=linphone_address_as_string(addr); - linphone_proxy_config_set_server_addr(cfg,tmp); - linphone_proxy_config_set_route(cfg,tmp); - ms_free(tmp); - linphone_address_destroy(addr); - } - linphone_core_set_stun_server(linphone_gtk_get_core(), "stun.linphone.org"); - linphone_core_set_firewall_policy(linphone_gtk_get_core(), LinphonePolicyUseIce); - } - - if (linphone_core_add_proxy_config(linphone_gtk_get_core(),cfg)==-1) - return; - - linphone_core_set_default_proxy(linphone_gtk_get_core(),cfg); - linphone_gtk_load_identities(); - - - } +static GtkWidget * create_finish_page(void) { + GtkWidget *vbox = gtk_vbox_new(FALSE, 2); + GtkWidget *label = gtk_label_new(_("Thank you. Your account is now configured and ready for use.")); + gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 2); + gtk_widget_show_all(vbox); + return vbox; } -static gint destroy_assistant(GtkWidget* w){ - gtk_widget_destroy(w); - the_assistant = NULL; - return FALSE; -} - -static int linphone_gtk_assistant_forward(int curpage, gpointer data){ - GtkWidget *w=(GtkWidget*)data; - GtkWidget *box=gtk_assistant_get_nth_page(GTK_ASSISTANT(w),curpage); - if (curpage==1){ - GtkWidget *create_button=(GtkWidget*)g_object_get_data(G_OBJECT(box),"create_account"); - GtkWidget *setup_linphone_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_linphone_account"); - GtkWidget *setup_account=(GtkWidget*)g_object_get_data(G_OBJECT(box),"setup_account"); - GtkWidget *config_uri=(GtkWidget*)g_object_get_data(G_OBJECT(box),"config-uri"); - - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(create_button))) { - curpage += 3; // Going to P33 - } - else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_linphone_account))) { - curpage += 2; // Going to P32 - } - else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setup_account))) { - curpage += 1; // Going to P31 - } - else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(config_uri))) { - /*destroy the assistant and popup config-uri dialog*/ - gtk_widget_hide(w); - linphone_gtk_set_configuration_uri(); - curpage=0; - g_idle_add((GSourceFunc)destroy_assistant,w); - } - } - else if (curpage == 2) { // Account's informations entered - LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w); - gchar identity[128]; - gchar proxy[128]; - g_snprintf(identity, sizeof(identity), "sip:%s@%s", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username"))), gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain")))); - - g_snprintf(proxy, sizeof(proxy), "sip:%s", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"domain")))); - - linphone_account_creator_set_username(c, identity); - linphone_account_creator_set_domain(c, proxy); - linphone_account_creator_set_route(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"proxy")))); - linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password")))); - curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page - } - else if (curpage == 3) { // Linphone Account's informations entered - LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w); - gchar identity[128]; - g_snprintf(identity, sizeof(identity), "sip:%s@sip.linphone.org", gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username")))); - linphone_account_creator_set_username(c, identity); - linphone_account_creator_set_domain(c, "sip:sip.linphone.org"); - linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password")))); - curpage = gtk_assistant_get_n_pages(GTK_ASSISTANT(w)) - 1; // Going to the last page - } - else if (curpage == 4) { // Password & Email entered - LinphoneAccountCreator *c=linphone_gtk_assistant_get_creator(w); - linphone_account_creator_set_username(c, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"username")))); - linphone_account_creator_set_password(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"password")))); - linphone_account_creator_set_email(c,gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box),"email")))); - linphone_account_creator_set_suscribe(c,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(box),"newsletter")))); - if (create_account(w) == 1) { - curpage += 1; - } else { // Error when attempting to create the account - curpage += 2; - } - } - else if (curpage == 5) { // Waiting for account validation - if (is_account_validated(w) == 1) { - curpage += 2; // Going to the last page - } else { - curpage += 1; - } - } - else { - curpage += 1; - } - return curpage; -} - -static LinphoneAccountCreator * linphone_gtk_assistant_init(GtkWidget *w){ - const MSList *elem; - LinphoneCore *lc=linphone_gtk_get_core(); - for(elem=linphone_core_get_sip_setups(lc);elem!=NULL;elem=elem->next){ - SipSetup *ss=(SipSetup*)elem->data; - if (sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_ACCOUNT_MANAGER){ - LinphoneAccountCreator *creator=linphone_account_creator_new(lc,ss->name); - g_object_set_data(G_OBJECT(w),"creator",creator); - return creator; - } - } - return NULL; -} - -static LinphoneAccountCreator *linphone_gtk_assistant_get_creator(GtkWidget*w){ - return (LinphoneAccountCreator*)g_object_get_data(G_OBJECT(w),"creator"); -} - -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){ +void linphone_gtk_show_assistant(GtkWidget *parent) { GtkWidget *w; - GtkWidget *p1; - GtkWidget *p2; - GtkWidget *p31; - GtkWidget *p32; - GtkWidget *p33; - //GtkWidget *confirm; - GtkWidget *validate; - GtkWidget *error; - GtkWidget *end; - GdkPixbuf *ok; - GdkPixbuf *notok; - if(the_assistant!=NULL) - return; - w=the_assistant=gtk_assistant_new(); + GtkWidget *page_0_intro; + GtkWidget *page_1_choice; + GtkWidget *page_2_external_account_configuration; + GtkWidget *page_3_linphone_account_configuration; + GtkWidget *page_4_linphone_account_creation_configuration; + GtkWidget *page_5_linphone_account_creation_in_progress; + GtkWidget *page_6_linphone_account_validation_wait; + GtkWidget *page_7_linphone_account_validation_check_in_progress; + GtkWidget *page_8_error; + GtkWidget *page_9_finish; + GdkPixbuf *ok_pixbuf; + GdkPixbuf *nok_pixbuf; + + if (the_assistant != NULL) return; + + w = the_assistant = gtk_assistant_new(); gtk_window_set_resizable (GTK_WINDOW(w), FALSE); - gtk_window_set_title(GTK_WINDOW(w),_("SIP account configuration assistant")); + gtk_window_set_title(GTK_WINDOW(w), _("SIP account configuration assistant")); - ok = create_pixbuf(linphone_gtk_get_ui_config("ok","ok.png")); - g_object_set_data_full(G_OBJECT(the_assistant), "ok", ok, g_object_unref); - notok = create_pixbuf(linphone_gtk_get_ui_config("notok","notok.png")); - g_object_set_data_full(G_OBJECT(the_assistant), "notok", notok, g_object_unref); + ok_pixbuf = create_pixbuf(linphone_gtk_get_ui_config("ok", "ok.png")); + g_object_set_data_full(G_OBJECT(the_assistant), "ok_pixbuf", ok_pixbuf, g_object_unref); + nok_pixbuf = create_pixbuf(linphone_gtk_get_ui_config("notok", "notok.png")); + g_object_set_data_full(G_OBJECT(the_assistant), "nok_pixbuf", nok_pixbuf, g_object_unref); - p1=create_intro(); - p2=create_setup_signin_choice(); - p31=create_account_informations_page(); - p32=create_linphone_account_informations_page(); - p33=create_account_information_page(); - //confirm=create_confirmation_page(); - validate=wait_for_activation(); - error=create_error_page(); - end=create_finish_page(); + page_0_intro = create_intro_page(); + page_1_choice = create_choice_page(); + page_2_external_account_configuration = create_external_account_configuration_page(); + page_3_linphone_account_configuration = create_linphone_account_configuration_page(); + page_4_linphone_account_creation_configuration = create_linphone_account_creation_configuration_page(); + page_5_linphone_account_creation_in_progress = create_linphone_account_creation_in_progress_page(); + page_6_linphone_account_validation_wait = create_linphone_account_validation_wait_page(); + page_7_linphone_account_validation_check_in_progress = create_linphone_account_validation_check_in_progress_page(); + page_8_error = create_error_page(); + page_9_finish = create_finish_page(); linphone_gtk_assistant_init(w); - gtk_assistant_append_page(GTK_ASSISTANT(w),p1); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),p1,GTK_ASSISTANT_PAGE_INTRO); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),p1,_("Welcome to the account setup assistant")); - gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p1,TRUE); - gtk_assistant_append_page(GTK_ASSISTANT(w),p2); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),p2,GTK_ASSISTANT_PAGE_CONTENT); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),p2,_("Account setup assistant")); - gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p2,TRUE); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_0_intro); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_0_intro, GTK_ASSISTANT_PAGE_INTRO); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_0_intro, _("Welcome to the account setup assistant")); + gtk_assistant_set_page_complete(GTK_ASSISTANT(w), page_0_intro, TRUE); - gtk_assistant_append_page(GTK_ASSISTANT(w),p31); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),p31,GTK_ASSISTANT_PAGE_CONFIRM); - gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p31,FALSE); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),p31,_("Configure your account (step 1/1)")); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_1_choice); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_1_choice, GTK_ASSISTANT_PAGE_CONTENT); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_1_choice, _("Account setup assistant")); + gtk_assistant_set_page_complete(GTK_ASSISTANT(w), page_1_choice, TRUE); - gtk_assistant_append_page(GTK_ASSISTANT(w),p32); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),p32,GTK_ASSISTANT_PAGE_CONFIRM); - gtk_assistant_set_page_complete(GTK_ASSISTANT(w),p32,FALSE); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),p32,_("Enter your sip username (step 1/1)")); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_2_external_account_configuration); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_2_external_account_configuration, GTK_ASSISTANT_PAGE_CONFIRM); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_2_external_account_configuration, _("Configure your account (step 1/1)")); - gtk_assistant_append_page(GTK_ASSISTANT(w),p33); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),p33,GTK_ASSISTANT_PAGE_CONFIRM); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),p33,_("Enter account information (step 1/2)")); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_3_linphone_account_configuration); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_3_linphone_account_configuration, GTK_ASSISTANT_PAGE_CONFIRM); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_3_linphone_account_configuration, _("Enter your sip username (step 1/1)")); - /*gtk_assistant_append_page(GTK_ASSISTANT(w),confirm); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),confirm,GTK_ASSISTANT_PAGE_CONFIRM); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),confirm,_("Confirmation (step 2/2)")); - gtk_assistant_set_page_complete(GTK_ASSISTANT(w),confirm,TRUE);*/ + gtk_assistant_append_page(GTK_ASSISTANT(w), page_4_linphone_account_creation_configuration); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_4_linphone_account_creation_configuration, GTK_ASSISTANT_PAGE_CONFIRM); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_4_linphone_account_creation_configuration, _("Enter account information (step 1/2)")); - gtk_assistant_append_page(GTK_ASSISTANT(w),validate); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),validate,GTK_ASSISTANT_PAGE_CONTENT); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),validate,_("Validation (step 2/2)")); - gtk_assistant_set_page_complete(GTK_ASSISTANT(w),validate,TRUE); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_5_linphone_account_creation_in_progress); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_5_linphone_account_creation_in_progress, GTK_ASSISTANT_PAGE_PROGRESS); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_5_linphone_account_creation_in_progress, _("Account creation in progress")); - gtk_assistant_append_page(GTK_ASSISTANT(w),error); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),error,GTK_ASSISTANT_PAGE_CONTENT); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),error,_("Error")); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_6_linphone_account_validation_wait); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_6_linphone_account_validation_wait, GTK_ASSISTANT_PAGE_CONTENT); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_6_linphone_account_validation_wait, _("Validation (step 2/2)")); + gtk_assistant_set_page_complete(GTK_ASSISTANT(w), page_6_linphone_account_validation_wait, TRUE); - gtk_assistant_append_page(GTK_ASSISTANT(w),end); - gtk_assistant_set_page_type(GTK_ASSISTANT(w),end,GTK_ASSISTANT_PAGE_SUMMARY); - gtk_assistant_set_page_title(GTK_ASSISTANT(w),end,_("Terminating")); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_7_linphone_account_validation_check_in_progress); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_7_linphone_account_validation_check_in_progress, GTK_ASSISTANT_PAGE_PROGRESS); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_7_linphone_account_validation_check_in_progress, _("Account validation check in progress")); - gtk_assistant_set_forward_page_func(GTK_ASSISTANT(w),linphone_gtk_assistant_forward,w,NULL); - g_signal_connect(G_OBJECT(w),"close",(GCallback)linphone_gtk_assistant_closed,NULL); - g_signal_connect(G_OBJECT(w),"cancel",(GCallback)linphone_gtk_assistant_closed,NULL); - g_signal_connect(G_OBJECT(w),"prepare",(GCallback)linphone_gtk_assistant_prepare,NULL); + gtk_assistant_append_page(GTK_ASSISTANT(w), page_8_error); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_8_error, GTK_ASSISTANT_PAGE_CONTENT); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_8_error, _("Error")); + + gtk_assistant_append_page(GTK_ASSISTANT(w), page_9_finish); + gtk_assistant_set_page_type(GTK_ASSISTANT(w), page_9_finish, GTK_ASSISTANT_PAGE_SUMMARY); + gtk_assistant_set_page_title(GTK_ASSISTANT(w), page_9_finish, _("Terminating")); + + gtk_assistant_set_forward_page_func(GTK_ASSISTANT(w), linphone_gtk_assistant_forward, w, NULL); + g_signal_connect(G_OBJECT(w), "close", (GCallback)linphone_gtk_assistant_closed, NULL); + g_signal_connect(G_OBJECT(w), "cancel", (GCallback)linphone_gtk_assistant_closed, NULL); + g_signal_connect(G_OBJECT(w), "prepare", (GCallback)linphone_gtk_assistant_prepare, NULL); + + gtk_window_set_transient_for(GTK_WINDOW(the_assistant), GTK_WINDOW(linphone_gtk_get_main_window())); gtk_widget_show(w); } +void linphone_gtk_close_assistant(void) { + if (the_assistant == NULL) return; + gtk_widget_destroy(the_assistant); + the_assistant = NULL; +}