From bddbdc7cd8913f3e3e6c13cace5010452900c890 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 12 Feb 2014 14:25:34 +0100 Subject: [PATCH] provisioning in gtk app in progress --- coreapi/bellesip_sal/sal_impl.c | 5 +- gtk/Makefile.am | 4 +- gtk/config-fetching.c | 48 +++++++++++++ gtk/config-uri.ui | 99 ++++++++++++++++++++++++++ gtk/linphone.h | 1 + gtk/main.c | 121 +++++++++++++++++++++----------- gtk/main.ui | 10 +++ 7 files changed, 244 insertions(+), 44 deletions(-) create mode 100644 gtk/config-fetching.c create mode 100644 gtk/config-uri.ui diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index dce0bb184..70f04673c 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -140,7 +140,10 @@ void sal_process_authentication(SalOp *op) { } sal_remove_pending_auth(op->base.root,op); }else { - ms_message("No auth info found for [%s]",sal_op_get_from(op)); + belle_sip_header_from_t *from=belle_sip_message_get_header_by_type(response,belle_sip_header_from_t); + char *tmp=belle_sip_object_to_string(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from))); + ms_message("No auth info found for [%s]",tmp); + belle_sip_free(tmp); sal_add_pending_auth(op->base.root,op); if (is_within_dialog) { diff --git a/gtk/Makefile.am b/gtk/Makefile.am index f9240eb02..1d1be276f 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -12,7 +12,8 @@ UI_FILES= about.ui \ waiting.ui \ dscp_settings.ui \ call_statistics.ui \ - ldap.ui + ldap.ui \ + config-uri.ui PIXMAPS= \ stock_people.png @@ -49,6 +50,7 @@ linphone_SOURCES= \ loginframe.c \ singleinstance.c \ conference.c \ + config-fetching.c \ linphone.h if BUILD_WIZARD linphone_SOURCES+= \ diff --git a/gtk/config-fetching.c b/gtk/config-fetching.c new file mode 100644 index 000000000..b9ce5cb70 --- /dev/null +++ b/gtk/config-fetching.c @@ -0,0 +1,48 @@ +/* +linphone, gtk-glade interface. +Copyright (C) 2008 Simon MORLAT (simon.morlat@linphone.org) + +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 "linphone.h" +#include "lpconfig.h" + + +void linphone_gtk_set_configuration_uri(GtkWidget *item){ + GtkWidget *w=linphone_gtk_create_window("config-uri"); + gtk_widget_show(w); +} + +void linphone_gtk_config_uri_changed(GtkWidget *button){ + GtkWidget *w=gtk_widget_get_toplevel(button); + GtkWidget *entry=linphone_gtk_get_widget(w,"uri_entry"); + const char *uri=gtk_entry_get_text(GTK_ENTRY(entry)); + if (uri){ + /*set provisionning uri to the core*/ + gtk_widget_destroy(w); + } + + if (uri){ + linphone_gtk_schedule_restart(); + gtk_main_quit(); + } +} + +void linphone_gtk_config_uri_cancel(GtkWidget *button){ + GtkWidget *w=gtk_widget_get_toplevel(button); + gtk_widget_destroy(w); +} + diff --git a/gtk/config-uri.ui b/gtk/config-uri.ui new file mode 100644 index 000000000..5e864743e --- /dev/null +++ b/gtk/config-uri.ui @@ -0,0 +1,99 @@ + + + + + + False + 5 + Specifying a remote configuration URI + dialog + + + True + False + 2 + + + True + False + end + + + gtk-undo + True + True + True + False + True + + + + False + False + 0 + + + + + gtk-ok + True + True + True + False + True + + + + False + False + 1 + + + + + False + True + end + 0 + + + + + True + False + This dialog allows to set an http or https address when configuration is to be fetched at startup. +Please enter or modify the configuration URI below. After clicking OK, Linphone will restart automatically in order to fetch and take into account the new configuration. + True + 80 + + + True + True + 1 + + + + + True + True + + https:// + False + False + True + True + + + True + True + 2 + + + + + + button2 + button1 + + + diff --git a/gtk/linphone.h b/gtk/linphone.h index 024e6348a..8f996244c 100644 --- a/gtk/linphone.h +++ b/gtk/linphone.h @@ -165,3 +165,4 @@ void linphone_gtk_monitor_usb(void); void linphone_gtk_unmonitor_usb(void); gchar *linphone_gtk_get_record_path(const LinphoneAddress *address, gboolean is_conference); +void linphone_gtk_schedule_restart(void); \ No newline at end of file diff --git a/gtk/main.c b/gtk/main.c index 761342ee6..8cc3a2790 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -53,6 +53,7 @@ static LinphoneCore *the_core=NULL; static GtkWidget *the_ui=NULL; static LinphoneLDAPContactProvider* ldap_provider = NULL; +static void linphone_gtk_global_state_changed(LinphoneCore *lc, LinphoneGlobalState state, const char*str); static void linphone_gtk_registration_state_changed(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState rs, const char *msg); static void linphone_gtk_notify_recv(LinphoneCore *lc, LinphoneFriend * fid); static void linphone_gtk_new_unknown_subscriber(LinphoneCore *lc, LinphoneFriend *lf, const char *url); @@ -72,6 +73,7 @@ static gboolean linphone_gtk_auto_answer(LinphoneCall *call); void linphone_gtk_status_icon_set_blinking(gboolean val); void _linphone_gtk_enable_video(gboolean val); void linphone_gtk_on_uribar_changed(GtkEditable *uribar, gpointer user_data); +static void linphone_gtk_init_ui(void); #ifndef HAVE_GTK_OSX static gint main_window_x=0; @@ -87,6 +89,7 @@ static char *progpath=NULL; gchar *linphone_logfile=NULL; static gboolean workaround_gtk_entry_chinese_bug=FALSE; static gchar *custom_config_file=NULL; +static gboolean restart=FALSE; static GOptionEntry linphone_options[]={ { @@ -250,11 +253,16 @@ void linphone_gtk_set_ldap(LinphoneLDAPContactProvider* ldap) : NULL; } +void linphone_gtk_schedule_restart(void){ + restart=TRUE; +} + static void linphone_gtk_init_liblinphone(const char *config_file, const char *factory_config_file, const char *db_file) { LinphoneCoreVTable vtable={0}; gchar *secrets_file=linphone_gtk_get_config_file(SECRETS_FILE); + vtable.global_state_changed=linphone_gtk_global_state_changed; vtable.call_state_changed=linphone_gtk_call_state_changed; vtable.registration_state_changed=linphone_gtk_registration_state_changed; vtable.notify_presence_received=linphone_gtk_notify_recv; @@ -1352,6 +1360,16 @@ void linphone_gtk_notify(LinphoneCall *call, const char *msg){ } } +static void linphone_gtk_global_state_changed(LinphoneCore *lc, LinphoneGlobalState state, const char*str){ + switch(state){ + case LinphoneGlobalOn: + if (the_core) linphone_gtk_init_ui(); + break; + default: + break; + } +} + static void on_call_updated_response(GtkWidget *dialog, gint responseid, LinphoneCall *call){ if (linphone_call_get_state(call)==LinphoneCallUpdatedByRemote){ LinphoneCore *lc=linphone_call_get_core(call); @@ -2044,23 +2062,29 @@ 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); + linphone_gtk_log_uninit(); +} + static void linphone_gtk_quit(void){ static gboolean quit_done=FALSE; if (!quit_done){ quit_done=TRUE; - 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_quit_core(); linphone_gtk_uninit_instance(); - linphone_gtk_destroy_log_window(); - linphone_core_destroy(the_core); - linphone_gtk_log_uninit(); #ifdef HAVE_NOTIFY notify_uninit(); #endif + gtk_widget_destroy(the_ui); + the_ui=NULL; gdk_threads_leave(); } } @@ -2080,11 +2104,34 @@ static gboolean on_block_termination(void){ } #endif +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 + +#ifndef HAVE_GTK_OSX + linphone_gtk_init_status_icon(); +#endif + if (!iconified){ + linphone_gtk_show_main_window(); + linphone_gtk_check_soundcards(); + } + if (linphone_gtk_get_ui_config_int("update_check_menu",0)==0) + linphone_gtk_check_for_new_version(); + linphone_gtk_monitor_usb(); +} + int main(int argc, char *argv[]){ char *config_file; const char *factory_config_file; const char *lang; GtkSettings *settings; + const char *icon_path=LINPHONE_ICON; GdkPixbuf *pbuf; const char *app_name="Linphone"; LpConfig *factory; @@ -2188,14 +2235,11 @@ int main(int argc, char *argv[]){ factory=lp_config_new(NULL); lp_config_read_file(factory,factory_config_file); app_name=lp_config_get_string(factory,"GtkUi","title","Linphone"); + icon_path=lp_config_get_string(factory,"GtkUi","icon",LINPHONE_ICON); } - - if (linphone_gtk_init_instance(app_name, addr_to_call) == FALSE){ - g_warning("Another running instance of linphone has been detected. It has been woken-up."); - g_warning("This instance is going to exit now."); - gdk_threads_leave(); - return 0; - } + g_set_application_name(app_name); + pbuf=create_pixbuf(icon_path); + if (pbuf!=NULL) gtk_window_set_default_icon(pbuf); add_pixmap_directory("pixmaps"); add_pixmap_directory(PACKAGE_DATA_DIR "/pixmaps/linphone"); @@ -2208,45 +2252,38 @@ int main(int argc, char *argv[]){ g_signal_connect(G_OBJECT(theMacApp),"NSApplicationBlockTermination",(GCallback)on_block_termination,NULL); #endif +core_start: + if (linphone_gtk_init_instance(app_name, addr_to_call) == FALSE){ + g_warning("Another running instance of linphone has been detected. It has been woken-up."); + g_warning("This instance is going to exit now."); + gdk_threads_leave(); + return 0; + } + the_ui=linphone_gtk_create_window("main"); g_object_set_data(G_OBJECT(the_ui),"is_created",GINT_TO_POINTER(FALSE)); linphone_gtk_create_log_window(); linphone_core_enable_logs_with_cb(linphone_gtk_log_handler); - + db_file=linphone_gtk_message_storage_get_db_file(NULL); + linphone_gtk_init_liblinphone(config_file, factory_config_file, db_file); - - g_set_application_name(app_name); - pbuf=create_pixbuf(linphone_gtk_get_ui_config("icon",LINPHONE_ICON)); - if (pbuf!=NULL) gtk_window_set_default_icon(pbuf); - + /* do not lower timeouts under 30 ms because it exhibits a bug on gtk+/win32, with cpu running 20% all the time...*/ gtk_timeout_add(30,(GtkFunction)linphone_gtk_iterate,(gpointer)linphone_gtk_get_core()); - gtk_timeout_add(30,(GtkFunction)linphone_gtk_check_logs,(gpointer)NULL); - 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 - -#ifndef HAVE_GTK_OSX - linphone_gtk_init_status_icon(); -#endif - if (!iconified){ - linphone_gtk_show_main_window(); - linphone_gtk_check_soundcards(); - } - if (linphone_gtk_get_ui_config_int("update_check_menu",0)==0) - linphone_gtk_check_for_new_version(); - linphone_gtk_monitor_usb(); + gtk_timeout_add(30,(GtkFunction)linphone_gtk_check_logs,(gpointer)linphone_gtk_get_core()); + + if (linphone_core_get_global_state(the_core)==LinphoneGlobalOn) linphone_gtk_init_ui(); gtk_main(); linphone_gtk_quit(); + + if (restart){ + restart=FALSE; + goto core_start; + } #ifndef HAVE_GTK_OSX /*workaround a bug on win32 that makes status icon still present in the systray even after program exit.*/ gtk_status_icon_set_visible(icon,FALSE); diff --git a/gtk/main.ui b/gtk/main.ui index 05461b6fc..96d3e11c0 100644 --- a/gtk/main.ui +++ b/gtk/main.ui @@ -858,6 +858,16 @@ + + + True + False + False + Set configuration URI + True + + + gtk-disconnect