From dba5a2337a86db8a29fc358fc677d0c29590e526 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 12 Feb 2014 16:58:12 +0100 Subject: [PATCH] gtk app remote provisioning in progress --- coreapi/linphonecore.h | 22 +++++++++++++++++++++- coreapi/remote_provisioning.c | 15 ++++++++++++--- gtk/config-fetching.c | 32 +++++++++++++++++++++++++++++++- gtk/linphone.h | 6 +++++- gtk/main.c | 14 ++++++++++++-- 5 files changed, 81 insertions(+), 8 deletions(-) diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 28d459d15..fd042589e 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -2280,9 +2280,29 @@ typedef struct _LinphoneContactProvider LinphoneContactProvider; typedef void (*ContactSearchCallback)( LinphoneContactSearch* id, MSList* friends, void* data ); -/** Remote provisioning +/* + * Remote provisioning */ +/** + * Set URI where to download xml configuration file at startup. + * This can also be set from configuration file or factory config file, from [misc] section, item "config-uri". + * Calling this function does not load the configuration. It will write the value into configuration so that configuration + * from remote URI will take place at next LinphoneCore start. + * @param lc the linphone core + * @param uri the http or https uri to use in order to download the configuration. + * @ingroup initializing +**/ +LINPHONE_PUBLIC void linphone_core_set_provisioning_uri(LinphoneCore *lc, const char*uri); + +/** + * Get provisioning URI. + * @param lc the linphone core + * @return the provisioning URI. + * @ingroup initializing +**/ +LINPHONE_PUBLIC const char* linphone_core_get_provisioning_uri(const LinphoneCore *lc); + typedef void (*ConfiguringCallback)(LinphoneCore *lc, LinphoneConfiguringState state, const char *message); /** diff --git a/coreapi/remote_provisioning.c b/coreapi/remote_provisioning.c index fe4269a66..127dce956 100644 --- a/coreapi/remote_provisioning.c +++ b/coreapi/remote_provisioning.c @@ -16,8 +16,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "linphonecore.h" -#include "bellesip_sal/sal_impl.h" +#include "private.h" #include "xml2lpc.h" #define XML2LPC_CALLBACK_BUFFER_SIZE 1024 @@ -137,4 +136,14 @@ static void linphone_remote_provisioning_download(LinphoneCore *lc, const char * void linphone_remote_provisioning_download_and_apply(LinphoneCore *lc, const char *remote_provisioning_uri, ConfiguringCallback cb) { linphone_callback = cb; linphone_remote_provisioning_download(lc, remote_provisioning_uri); -} \ No newline at end of file +} + +void linphone_core_set_provisioning_uri(LinphoneCore *lc, const char*uri){ + if (linphone_core_ready(lc)){ + lp_config_set_string(lc->config,"misc","config-uri",uri); + } +} + +const char*linphone_core_get_provisioning_uri(const LinphoneCore *lc){ + return lp_config_get_string(lc->config,"misc","config-uri",NULL); +} diff --git a/gtk/config-fetching.c b/gtk/config-fetching.c index b9ce5cb70..cec611814 100644 --- a/gtk/config-fetching.c +++ b/gtk/config-fetching.c @@ -23,6 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void linphone_gtk_set_configuration_uri(GtkWidget *item){ GtkWidget *w=linphone_gtk_create_window("config-uri"); + GtkWidget *entry=linphone_gtk_get_widget(w,"uri_entry"); + const char *uri=linphone_core_get_provisioning_uri(linphone_gtk_get_core()); + gtk_entry_set_text(GTK_ENTRY(entry),uri); gtk_widget_show(w); } @@ -30,8 +33,9 @@ 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){ + if (uri && strcmp(uri,"https://")!=0){/*not just the hint text*/ /*set provisionning uri to the core*/ + linphone_core_set_provisioning_uri(linphone_gtk_get_core(),uri); gtk_widget_destroy(w); } @@ -46,3 +50,29 @@ void linphone_gtk_config_uri_cancel(GtkWidget *button){ gtk_widget_destroy(w); } +GtkWidget * linphone_gtk_show_config_fetching(void){ + LinphoneCore *lc=linphone_gtk_get_core(); + GtkWidget *w=linphone_gtk_create_window("provisioning-fetch"); + g_message("Fetching started"); + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(w),_("fetching from %s"),linphone_core_get_provisioning_uri(lc)); +#if GTK_CHECK_VERSION(2,20,0) + { + GtkWidget *spinner=gtk_spinner_new(); + gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(w),spinner); + } +#endif + gtk_widget_show(w); + return w; +} + +void linphone_gtk_close_config_fetching(GtkWidget *w, LinphoneConfiguringState state){ + LinphoneCore *lc=linphone_gtk_get_core(); + gtk_widget_destroy(w); + g_message("Fetching finished"); + if (state==LinphoneConfiguringFailed){ + GtkWidget *msg=gtk_message_dialog_new(NULL,0,GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,_("Downloading of remote configuration from %s failed."), + linphone_core_get_provisioning_uri(lc)); + gtk_widget_show(msg); + } +} + diff --git a/gtk/linphone.h b/gtk/linphone.h index 8f996244c..c1d4323ca 100644 --- a/gtk/linphone.h +++ b/gtk/linphone.h @@ -165,4 +165,8 @@ 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 +void linphone_gtk_schedule_restart(void); + +GtkWidget * linphone_gtk_show_config_fetching(void); +void linphone_gtk_close_config_fetching(GtkWidget *w, LinphoneConfiguringState state); + diff --git a/gtk/main.c b/gtk/main.c index 8cc3a2790..691c52b9a 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -90,6 +90,7 @@ gchar *linphone_logfile=NULL; static gboolean workaround_gtk_entry_chinese_bug=FALSE; static gchar *custom_config_file=NULL; static gboolean restart=FALSE; +static GtkWidget *config_fetching_dialog=NULL; static GOptionEntry linphone_options[]={ { @@ -1248,7 +1249,8 @@ static void linphone_gtk_display_status(LinphoneCore *lc, const char *status){ } static void linphone_gtk_configuring_status(LinphoneCore *lc, LinphoneConfiguringState status, const char *message) { - + if (config_fetching_dialog) linphone_gtk_close_config_fetching(config_fetching_dialog, status); + config_fetching_dialog=NULL; } static void linphone_gtk_display_message(LinphoneCore *lc, const char *msg){ @@ -1362,8 +1364,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 LinphoneGlobalStartup: + the_core=lc; + break; + case LinphoneGlobalConfiguring: + if (linphone_core_get_provisioning_uri(lc)){ + config_fetching_dialog=linphone_gtk_show_config_fetching(); + } + break; case LinphoneGlobalOn: - if (the_core) linphone_gtk_init_ui(); + linphone_gtk_init_ui(); break; default: break;