From: Kwangyoun Kim Date: Wed, 29 Jun 2016 11:25:36 +0000 (+0900) Subject: Add wifi network state check X-Git-Tag: submit/tizen/20160630.050431^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f5b29da23e9756eea9f8339b0c2dfde90a9d031;hp=f260118f15753797656664505e5849dbad5e1fa9;p=platform%2Fcore%2Fuifw%2Flibttssmt.git Add wifi network state check Add back button for cancel download Change-Id: I482a15e5033a01138e995a7fa2ffd11d071c705a --- diff --git a/packaging/libttssmt.spec b/packaging/libttssmt.spec index f477ca0..0816d3f 100644 --- a/packaging/libttssmt.spec +++ b/packaging/libttssmt.spec @@ -21,6 +21,7 @@ BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(efl-extension) BuildRequires: pkgconfig(capi-web-url-download) +BuildRequires: pkgconfig(capi-network-wifi) provides : libsmt.so @@ -58,4 +59,4 @@ cp %{_builddir}/%{name}-%{version}/LICENSE.Flora %{buildroot}%{TZ_SYS_RO_SHARE}/ %{TZ_SYS_RO_SHARE}/voice/tts/1.0/engine-info/ttssmt-info.xml %{TZ_SYS_RO_SHARE}/license/%{name} %{TZ_SYS_RO_APP}/org.tizen.ttssmt-setting/bin/ttssmt-setting -%{TZ_SYS_RO_PACKAGES}/org.tizen.ttssmt-setting.xml \ No newline at end of file +%{TZ_SYS_RO_PACKAGES}/org.tizen.ttssmt-setting.xml diff --git a/setting-app/CMakeLists.txt b/setting-app/CMakeLists.txt index 44dda22..5cce164 100644 --- a/setting-app/CMakeLists.txt +++ b/setting-app/CMakeLists.txt @@ -6,6 +6,7 @@ INCLUDE(FindPkgConfig) pkg_check_modules(pkgs_setting REQUIRED appcore-efl elementary ecore-imf eina ecore ecore-input evas edje glib-2.0 capi-base-common aul capi-appfw-application efl-extension vconf vconf-internal-keys capi-web-url-download libxml-2.0 + capi-network-wifi ) FOREACH(flag ${pkgs_setting_CFLAGS}) diff --git a/setting-app/org.tizen.ttssmt-setting.xml b/setting-app/org.tizen.ttssmt-setting.xml index 17b9b3d..8082dfa 100644 --- a/setting-app/org.tizen.ttssmt-setting.xml +++ b/setting-app/org.tizen.ttssmt-setting.xml @@ -9,5 +9,6 @@ http://tizen.org/privilege/internet http://tizen.org/privilege/download + http://tizen.org/privilege/network.get diff --git a/setting-app/src/ttssmt_setting_main.c b/setting-app/src/ttssmt_setting_main.c index ee2474d..7fdb77a 100644 --- a/setting-app/src/ttssmt_setting_main.c +++ b/setting-app/src/ttssmt_setting_main.c @@ -138,6 +138,8 @@ static Elm_Genlist_Item_Class *g_itc_button_1line = NULL; static appdata_s *g_ad; +static int g_download_id; + typedef struct { char* language; int type; @@ -342,6 +344,14 @@ static Evas_Object * __genlist_content_get(void *data, Evas_Object *obj, const c return NULL; } +static void __hide_progress_popup() +{ + if (NULL != g_ad->progress_popup) { + evas_object_del(g_ad->progress_popup); + g_ad->progress_popup = NULL; + } +} + static void __progress_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { if (NULL != g_ad->progress_popup) { @@ -353,10 +363,18 @@ static void __progress_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void static void __progress_popup_back_cb(void *data, Evas_Object *obj, void *event_info) { + dlog_print(DLOG_INFO, LOG_TAG, "Cancel by back button"); + int ret; + ret = download_cancel(g_download_id); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to download cancel"); + } + + __hide_progress_popup(); return; } -static void __show_progress_popup(bool failed) +static void __show_progress_popup(bool failed, const char* msg) { if (NULL != g_ad->progress_popup) { evas_object_del(g_ad->progress_popup); @@ -369,7 +387,11 @@ static void __show_progress_popup(bool failed) elm_object_part_text_set(popup, "title,text", "Downloading"); if (failed) { - elm_object_part_text_set(popup, "default", "Fail to download language pack."); + if (NULL != msg) { + elm_object_part_text_set(popup, "default", msg); + } else { + elm_object_part_text_set(popup, "default", "Fail to download language pack."); + } elm_popup_timeout_set(popup, 2.0); } else { @@ -437,18 +459,8 @@ static void __show_delete_popup() evas_object_show(popup); } -static void __hide_progress_popup() +static void __remove_temp_file(int idx) { - if (NULL != g_ad->progress_popup) { - evas_object_del(g_ad->progress_popup); - g_ad->progress_popup = NULL; - } -} - -static void* __download_completed_cb(void *user_data) -{ - intptr_t pidx = (intptr_t)user_data; - int idx = (int)pidx; char cmd[1024] = {'\0',}; //char* data_path = app_get_data_path(); const char* data_path = TTS_ENGINE_DATA_PATH; @@ -459,6 +471,13 @@ static void* __download_completed_cb(void *user_data) char filepath[1024] = {'\0',}; snprintf(filepath, 1024, "%s/%s.tar.gz", data_path, item_data[idx][2]); remove(filepath); +} + +static void* __download_completed_cb(void *user_data) +{ + intptr_t pidx = (intptr_t)user_data; + int idx = (int)pidx; + __remove_temp_file(idx); /* TODO */ tts_config_voice_s *voice = (tts_config_voice_s *)calloc(1, sizeof(tts_config_voice_s)); @@ -476,19 +495,39 @@ static void* __download_completed_cb(void *user_data) __hide_progress_popup(); elm_genlist_item_update(g_ad->selected_lang); + wifi_deinitialize(); + return NULL; } static void* __download_failed_cb(void *user_data) { - __hide_progress_popup(); - __show_progress_popup(true); + intptr_t pidx = (intptr_t)user_data; + int idx = (int)pidx; + __remove_temp_file(idx); + + __show_progress_popup(true, NULL); elm_genlist_item_update(g_ad->selected_lang); + + wifi_deinitialize(); + + return NULL; +} + +static void* __download_canceled_cb(void *user_data) +{ + intptr_t pidx = (intptr_t)user_data; + int idx = (int)pidx; + __remove_temp_file(idx); + + wifi_deinitialize(); + return NULL; } static void __download_state_changed_cb(int download_id, download_state_e state, void *user_data) { + dlog_print(DLOG_INFO, LOG_TAG, "State (%d)", state); if (DOWNLOAD_STATE_COMPLETED == state) { dlog_print(DLOG_INFO, LOG_TAG, "===== Download Completed"); ecore_main_loop_thread_safe_call_sync(__download_completed_cb, user_data); @@ -497,11 +536,28 @@ static void __download_state_changed_cb(int download_id, download_state_e state, dlog_print(DLOG_INFO, LOG_TAG, "===== Download Failed"); ecore_main_loop_thread_safe_call_sync(__download_failed_cb, user_data); download_destroy(download_id); + } else if (DOWNLOAD_STATE_CANCELED == state) { + dlog_print(DLOG_INFO, LOG_TAG, "===== Download Canceled"); + ecore_main_loop_thread_safe_call_sync(__download_canceled_cb, user_data); + download_destroy(download_id); } dlog_print(DLOG_INFO, LOG_TAG, "====="); } +static void __wifi_conn_changed_cb(wifi_connection_state_e state, wifi_ap_h ap, void* user_data) +{ + if (WIFI_CONNECTION_STATE_CONNECTED != state) { + dlog_print(DLOG_INFO, LOG_TAG, "Wifi disconnected"); + int ret; + ret = download_cancel(g_download_id); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to download cancel(%d)", ret); + } + __show_progress_popup(true, "Network ERROR - Check wifi connection"); + } +} + static void __lang_item_clicked_cb(void *data, Evas_Object *obj, void *event_info) { Elm_Object_Item *item = (Elm_Object_Item *)event_info; @@ -515,53 +571,100 @@ static void __lang_item_clicked_cb(void *data, Evas_Object *obj, void *event_inf /* download */ if (false == __installed_lang(idx)) { dlog_print(DLOG_INFO, LOG_TAG, ">> Download <<"); - download_error_e error; + + __remove_temp_file(idx); + + int ret; + + ret = wifi_initialize(); + if (WIFI_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to wifi init(%d)", ret); + } + + wifi_connection_state_e state; + ret = wifi_get_connection_state(&state); + if (WIFI_ERROR_NONE != ret) { + __show_progress_popup(true, "Network ERROR - Check wifi connection(%d)", ret); + wifi_deinitialize(); + return; + } + + if (WIFI_CONNECTION_STATE_CONNECTED != state) { + dlog_print(DLOG_ERROR, LOG_TAG, "Wifi Disconnected"); + __show_progress_popup(true, "Network ERROR - Check wifi connection"); + wifi_deinitialize(); + return; + } + + ret = wifi_set_connection_state_changed_cb(__wifi_conn_changed_cb, (void *)pidx); + if (WIFI_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set wifi state changed cb(%d)", ret); + __show_progress_popup(true, "Network ERROR - Check wifi connection"); + wifi_deinitialize(); + return; + } + int download_id; + ret = download_create(&download_id); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to download create(%d)", ret); + __show_progress_popup(true, NULL); + wifi_deinitialize(); + return; + } - error = download_create(&download_id); - if (DOWNLOAD_ERROR_NONE != error) { - dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] create"); - __show_progress_popup(true); + ret = download_set_network_type(download_id, DOWNLOAD_NETWORK_WIFI); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set network type(%d)", ret); + __show_progress_popup(true, "Network ERROR - Check wifi connection"); + download_destroy(download_id); + wifi_deinitialize(); return; } - error = download_set_state_changed_cb(download_id, __download_state_changed_cb, (void *)pidx); - if (DOWNLOAD_ERROR_NONE != error) { - dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] set state cb"); - __show_progress_popup(true); + + ret = download_set_state_changed_cb(download_id, __download_state_changed_cb, (void *)pidx); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set state cb(%d)", ret); + __show_progress_popup(true, NULL); download_destroy(download_id); + wifi_deinitialize(); return; } char url[1024] = {'\0',}; snprintf(url, 1024, "http://download.tizen.org/releases/resources/voice/tts/smt-language-pack/%s.tar.gz", item_data[idx][2]); - error = download_set_url(download_id, url); - if (DOWNLOAD_ERROR_NONE != error) { - dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] set url"); - __show_progress_popup(true); + ret = download_set_url(download_id, url); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set url(%d)", ret); + __show_progress_popup(true, NULL); download_destroy(download_id); + wifi_deinitialize(); return; } //char *data_path = app_get_data_path(); const char *data_path = TTS_ENGINE_DATA_PATH; - error = download_set_destination(download_id, data_path); - if (DOWNLOAD_ERROR_NONE != error) { - dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] set destination"); - __show_progress_popup(true); + ret = download_set_destination(download_id, data_path); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to set destination(%d)", ret); + __show_progress_popup(true, NULL); download_destroy(download_id); + wifi_deinitialize(); return; } //free(data_path); - error = download_start(download_id); - if (DOWNLOAD_ERROR_NONE != error) { - dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] start"); - __show_progress_popup(true); + ret = download_start(download_id); + if (DOWNLOAD_ERROR_NONE != ret) { + dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] Fail to start(%d)", ret); + __show_progress_popup(true, NULL); download_destroy(download_id); + wifi_deinitialize(); return; } - __show_progress_popup(false); + g_download_id = download_id; + __show_progress_popup(false, NULL); dlog_print(DLOG_INFO, LOG_TAG, "<< End >>"); } else { diff --git a/setting-app/src/ttssmt_setting_main.h b/setting-app/src/ttssmt_setting_main.h index efd4cd9..1974cb6 100644 --- a/setting-app/src/ttssmt_setting_main.h +++ b/setting-app/src/ttssmt_setting_main.h @@ -27,6 +27,7 @@ extern "C" { #include #include #include +#include #include #ifdef LOG_TAG